(function(ze,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(ze=typeof globalThis<"u"?globalThis:ze||self,L(ze.CpfEditor={}))})(this,(function(ze){"use strict";function L(n){this.content=n}L.prototype={constructor:L,find:function(n){for(var e=0;e>1}},L.from=function(n){if(n instanceof L)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new L(e)};function Fr(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Fr(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function $r(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,d=Math.min(o.text.length,l.text.length);for(;ce&&r(a,i+l,s||null,o)!==!1&&a.content.size){let d=l+1;a.nodesBetween(Math.max(0,e-d),Math.min(a.content.size,t-d),r,i+d)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,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)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new k(r,i)}cutByIndex(e,t){return e==t?k.empty:e==0&&t==this.content.length?this:new k(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new k(i,s)}addToStart(e){return new k([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new k(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let i=this.child(t),s=r+i.nodeSize;if(s>=e)return s==e?Bt(t+1,s):Bt(t,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return k.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new k(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return k.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};P.none=[];class Ft extends Error{}class C{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Vr(this.content,e+this.openStart,t);return r&&new C(r,this.openStart,this.openEnd)}removeBetween(e,t){return new C(Hr(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 C.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new C(k.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new C(e,r,i)}}C.empty=new C(k.empty,0,0);function Hr(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Hr(s.content,e-i-1,t-i-1)))}function Vr(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Vr(o.content,e-s-1,t,o);return l&&n.replaceChild(i,o.copy(l))}function el(n,e,t){if(t.openStart>n.depth)throw new Ft("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Ft("Inconsistent open depths");return _r(n,e,t,0)}function _r(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function ht(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Fe(n.nodeAfter,r),s++));for(let l=s;li&&Tn(n,e,i+1),o=r.depth>i&&Tn(t,r,i+1),l=[];return ht(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(Wr(s,o),Fe($e(s,jr(n,e,t,r,i+1)),l)):(s&&Fe($e(s,$t(n,e,i+1)),l),ht(e,t,i,l),o&&Fe($e(o,$t(t,r,i+1)),l)),ht(r,null,i,l),new k(l)}function $t(n,e,t){let r=[];if(ht(null,n,t,r),n.depth>t){let i=Tn(n,e,t+1);Fe($e(i,$t(n,e,t+1)),r)}return ht(e,null,t,r),new k(r)}function tl(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(k.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class mt{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Ht(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new mt(t,r,s)}static resolveCached(e,t){let r=qr.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Kr(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=k.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let 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 r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=k.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};ke.prototype.text=void 0;class Vt extends ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Kr(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 Vt(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Vt(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 Kr(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class He{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new sl(e,t);if(r.next==null)return He.empty;let i=Jr(r);r.next&&r.err("Unexpected trailing text");let s=fl(ul(i));return pl(s,r),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(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` `)}}He.empty=new He(!0);class sl{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 Jr(n){let e=[];do e.push(ol(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ol(n){let e=[];do e.push(ll(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function ll(n){let e=dl(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=al(n,e);else break;return e}function Ur(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function al(n,e){let t=Ur(n),r=t;return n.eat(",")&&(n.next!="}"?r=Ur(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function cl(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function dl(n){if(n.eat("(")){let e=Jr(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=cl(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function ul(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(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 r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let d=0;d{c||i.push([l,c=[]]),c.indexOf(d)==-1&&c.push(d)})})});let s=e[r.join(",")]=new He(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Zr(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ke(this,this.computeAttrs(e),k.from(t),P.setFrom(r))}createChecked(e=null,t,r){return t=k.from(t),this.checkContent(t),new ke(this,this.computeAttrs(e),t,P.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=k.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(k.empty,!0);return s?new ke(this,e,t.append(s),P.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new Qo(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function hl(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}class ml{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?hl(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class _t{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ei(e,i.attrs),this.excluded=null;let s=Xr(this.attrs);this.instance=s?new P(this,s):null}create(e=null){return!e&&this.instance?this.instance:new P(this,Zr(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new _t(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}}class ni{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=L.from(e.nodes),t.marks=L.from(e.marks||{}),this.nodes=ti.compile(this.spec.nodes,this),this.marks=_t.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=He.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?ri(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==""?[]:ri(this,o.split(" "))}this.nodeFromJSON=i=>ke.fromJSON(this,i),this.markFromJSON=i=>P.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ti){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Vt(r,r.defaultAttrs,e,P.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function ri(n,e){let t=[];for(let r=0;r-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function gl(n){return n.tag!=null}function yl(n){return n.style!=null}class Me{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(gl(i))this.tags.push(i);else if(yl(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new li(this,t,!1);return r.addAll(e,P.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new li(this,t,!0);return r.addAll(e,P.none,t.from,t.to),C.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=ai(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ai(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Me(e,Me.schemaRules(e)))}}const ii={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},bl={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},si={ol:!0,ul:!0},gt=1,Nn=2,yt=4;function oi(n,e,t){return e!=null?(e?gt:0)|(e==="full"?Nn:0):n&&n.whitespace=="pre"?gt|Nn:t&~yt}class Wt{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=P.none,this.match=s||(o&yt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(k.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options>)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=k.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(k.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&&!ii.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class li{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=oi(null,t.preserveWhitespace,0)|(r?yt:0);i?s=new Wt(i.type,i.attrs,P.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Wt(null,null,P.none,!0,null,o):s=new Wt(e.schema.topNodeType,null,P.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,s=i.options&Nn?"full":this.localPreserveWS||(i.options>)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,` `);else if(o.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=r.split(/\r?\n|\r/);for(let a=0;a!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let a=this.enter(o,t.attrs||null,r,t.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,r){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(r)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o(o.type?o.type.allowsMarkType(c.type):ci(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Wt(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=gt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,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 d=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!d||d.name!=c&&!d.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 r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function xl(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&si.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function kl(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ai(n){let e={};for(let t in n)e[t]=n[t];return e}function ci(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let 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(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&jt(On(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return jt(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Ve(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=di(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return di(e.marks)}}function di(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function On(n){return n.document||window.document}const ui=new WeakMap;function Ml(n){let e=ui.get(n);return e===void 0&&ui.set(n,e=Sl(n)),e}function Sl(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],d=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){d=2;for(let u in c)if(c[u]!=null){let f=u.indexOf(" ");f>0?a.setAttributeNS(u.slice(0,f),u.slice(f+1),c[u]):u=="style"&&a.style?a.style.cssText=c[u]:a.setAttribute(u,c[u])}}for(let u=d;ud)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}=jt(n,f,t,r);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const fi=65535,pi=Math.pow(2,16);function Cl(n,e){return n+e*pi}function hi(n){return n&fi}function wl(n){return(n-(n&fi))/pi}const mi=1,gi=2,qt=4,yi=8;class En{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&yi)>0}get deletedBefore(){return(this.delInfo&(mi|qt))>0}get deletedAfter(){return(this.delInfo&(gi|qt))>0}get deletedAcross(){return(this.delInfo&qt)>0}}class te{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&te.empty)return te.empty}recover(e){let t=0,r=hi(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],d=this.ranges[l+o],u=a+c;if(e<=u){let f=c?e==a?-1:e==u?1:t:t,p=a+i+(f<0?0:d);if(r)return p;let h=e==(t<0?a:u)?null:Cl(l/3,e-a),m=e==a?gi:e==u?mi:qt;return(t<0?e!=a:e!=u)&&(m|=yi),new En(p,m,h)}i+=d-c}return r?e+i:new En(e+i,0,null)}touches(e,t){let r=0,i=hi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+s],d=a+c;if(e<=d&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new bt;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return B.fromReplace(e,this.from,this.to,s)}invert(){return new ce(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Se(t.pos,r.pos,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Se(t.from,t.to,e.markFromJSON(t.mark))}}J.jsonID("addMark",Se);class ce extends J{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new C(In(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return B.fromReplace(e,this.from,this.to,r)}invert(){return new Se(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new ce(t.pos,r.pos,this.mark)}merge(e){return e instanceof ce&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ce(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 ce(t.from,t.to,e.markFromJSON(t.mark))}}J.jsonID("removeMark",ce);class Ce extends J{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return B.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return B.fromReplace(e,this.pos,this.pos+1,new C(k.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new H(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new H(t.from,t.to,t.gapFrom,t.gapTo,C.fromJSON(e,t.slice),t.insert,!!t.structure)}}J.jsonID("replaceAround",H);function vn(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Tl(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,d)=>{if(!a.isInline)return;let u=a.marks;if(!r.isInSet(u)&&d.type.allowsMarkType(r.type)){let f=Math.max(c,e),p=Math.min(c+a.nodeSize,t),h=r.addToSet(u);for(let m=0;mn.step(a)),s.forEach(a=>n.step(a))}function Nl(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof _t){let c=o.marks,d;for(;d=r.isInSet(c);)(a||(a=[])).push(d),c=d.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let d=0;dn.step(new ce(o.from,o.to,o.style)))}function Dn(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)n.step(o[a])}function Ol(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Qe(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,s=0;;--r){let o=n.$from.node(r),l=n.$from.index(r)+i,a=n.$to.indexAfter(r)-s;if(rt;h--)m||r.index(h)>0?(m=!0,d=k.from(r.node(h).copy(d)),u++):a--;let f=k.empty,p=0;for(let h=s,m=!1;h>t;h--)m||i.after(h+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=k.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new H(i,s,i,s,new C(r,0,0),t.length,!0))}function Dl(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&Pl(n.doc,n.mapping.slice(s).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&ki(n,o,l,s),Dn(n,n.mapping.slice(s).map(l,1),r,void 0,c===null);let d=n.mapping.slice(s),u=d.map(l,1),f=d.map(l+o.nodeSize,1);return n.step(new H(u,f,u+1,f-1,new C(k.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&xi(n,o,l,s),!1}})}function xi(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function ki(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` `))}})}function Pl(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Rl(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new H(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new C(k.from(o),0,0),1,!0))}function me(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,d=t-2;c>s;c--,d--){let u=i.node(c),f=i.index(c);if(u.type.spec.isolating)return!1;let p=u.content.cutByIndex(f,u.childCount),h=r&&r[d+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[d]||u;if(!u.canReplace(f+1,u.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Ll(n,e,t=1,r){let i=n.doc.resolve(e),s=k.empty,o=k.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=k.from(i.node(l).copy(s));let d=r&&r[c];o=k.from(d?d.type.create(d.attrs,o):i.node(l).copy(o))}n.step(new $(e,e,new C(s.append(o),t,t),!0))}function we(n,e){let t=n.resolve(e),r=t.index();return Mi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Bl(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Mi(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function zl(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let d=o.whitespace=="pre",u=!!o.contentMatch.matchType(i);d&&!u?r=!1:!d&&u&&(r=!0)}let l=n.steps.length;if(r===!1){let d=n.doc.resolve(e+t);ki(n,d.node(),d.before(),l)}o.inlineContent&&Dn(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new $(c,a.map(e+t,-1),C.empty,!0)),r===!0){let d=n.doc.resolve(c);xi(n,d.node(),d.before(),n.steps.length)}return n}function Fl(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),d=!1;if(s==1)d=c.canReplace(a,a,i);else{let u=c.contentMatchAt(a).findWrapping(i.firstChild.type);d=u&&c.canReplaceWith(a,a,u[0])}if(d)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Jt(n,e,t=e,r=C.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ci(i,s,r)?new $(e,t,r):new $l(i,s,r).fit()}function Ci(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class $l{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=k.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=k.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,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new C(s,o,l);return e>-1?new H(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new $(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Rn(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],d,u=null;if(t==1&&(o?c.matchType(o.type)||(u=c.fillBefore(k.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:u};if(t==2&&o&&(d=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:d};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Rn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new C(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Rn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new C(xt(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new C(xt(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(u=g,d.push(wi(m.mark(f.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let h=c==l.childCount;h||(p=-1),this.placed=kt(this.placed,t,k.from(d)),this.frontier[t].match=u,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:c}=this.frontier[l],d=Ln(e,l,c,a,!0);if(!d||d.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=kt(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=kt(this.placed,this.depth,k.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(k.empty,!0);t.childCount&&(this.placed=kt(this.placed,this.frontier.length,t))}}function xt(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(xt(n.firstChild.content,e-1,t)))}function kt(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(kt(n.lastChild.content,e-1,t)))}function Rn(n,e){for(let t=0;t1&&(r=r.replaceChild(0,wi(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(k.empty,!0)))),n.copy(r)}function Ln(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Hl(t,s.content,o)?l:null}function Hl(n,e,t){for(let r=t;r0;f--,p--){let h=i.node(f).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==p&&o.splice(1,0,-f)}let a=o.indexOf(l),c=[],d=r.openStart;for(let f=r.content,p=0;;p++){let h=f.firstChild;if(c.push(h),p==r.openStart)break;f=h.content}for(let f=d-1;f>=0;f--){let p=c[f],h=Vl(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))d=f;else if(h||!p.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let p=(f+d+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>u));f--){let p=o[f];p<0||(e=i.before(p),t=s.after(p))}}function Ti(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(k.empty,!0))}return n}function Wl(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Fl(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new C(k.from(r),0,0))}function jl(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ni(r,i);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function Ni(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class et extends J{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return B.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return B.fromReplace(e,this.pos,this.pos+1,new C(k.from(i),0,t.isLeaf?0:1))}getMap(){return te.empty}invert(e){return new et(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 et(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 et(t.pos,t.attr,t.value)}}J.jsonID("attr",et);class Mt extends J{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return B.ok(r)}getMap(){return te.empty}invert(e){return new Mt(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 Mt(t.attr,t.value)}}J.jsonID("docAttr",Mt);let tt=class extends Error{};tt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},tt.prototype=Object.create(Error.prototype),tt.prototype.constructor=tt,tt.prototype.name="TransformError";class ql{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new bt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new tt(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}changedRange(){let e=1e9,t=-1e9;for(let r=0;r{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=C.empty){let i=Jt(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new C(k.from(r),0,0))}delete(e,t){return this.replace(e,t,C.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return _l(this,e,t,r),this}replaceRangeWith(e,t,r){return Wl(this,e,t,r),this}deleteRange(e,t){return jl(this,e,t),this}lift(e,t){return El(this,e,t),this}join(e,t=1){return zl(this,e,t),this}wrap(e,t){return vl(this,e,t),this}setBlockType(e,t=e,r,i=null){return Dl(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Rl(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new et(e,t,r)),this}setDocAttribute(e,t){return this.step(new Mt(e,t)),this}addNodeMark(e,t){return this.step(new Ce(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof P)t.isInSet(r.marks)&&this.step(new _e(e,t));else{let i=r.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new _e(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,r){return Ll(this,e,t,r),this}addMark(e,t,r){return Tl(this,e,t,r),this}removeMark(e,t,r){return Nl(this,e,t,r),this}clearIncompatible(e,t,r){return Dn(this,e,t,r),this}}const Bn=Object.create(null);class I{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Kl(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?nt(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):nt(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new ne(e.node(0))}static atStart(e){return nt(e,e,0,0,1)||new ne(e)}static atEnd(e){return nt(e,e,e.content.size,e.childCount,-1)||new ne(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Bn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Bn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Bn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return E.between(this.$anchor,this.$head).getBookmark()}}I.prototype.visible=!0;class Kl{constructor(e,t){this.$from=e,this.$to=t}}let Oi=!1;function Ei(n){!Oi&&!n.parent.inlineContent&&(Oi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class E extends I{constructor(e,t=e){Ei(e),Ei(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return I.near(r);let i=e.resolve(t.map(this.anchor));return new E(i.parent.inlineContent?i:r,r)}replace(e,t=C.empty){if(super.replace(e,t),t==C.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof E&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ut(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 E(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=I.findFrom(t,r,!0)||I.findFrom(t,-r,!0);if(s)t=s.$head;else return I.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(I.findFrom(e,-r,!0)||I.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&O.isSelectable(l))return O.create(n,t-(i<0?l.nodeSize:0))}else{let a=nt(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Ai(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=d)}),n.setSelection(I.near(n.doc.resolve(o),t))}const Ii=1,Gt=2,vi=4;class Ul extends ql{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|=Gt,this}ensureMarks(e){return P.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&Gt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Gt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||P.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(I.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|=vi,this}get scrolledIntoView(){return(this.updated&vi)>0}}function Di(n,e){return!e||!n?n:n.bind(e)}class St{constructor(e,t,r){this.name=e,this.init=Di(t.init,r),this.apply=Di(t.apply,r)}}const Gl=[new St("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new St("selection",{init(n,e){return n.selection||I.atStart(e.doc)},apply(n){return n.selection}}),new St("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new St("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Fn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Gl.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new St(r.key,r.spec.state,r))})}}class rt{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Fn(e.schema,e.plugins),s=new rt(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=I.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[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 Pi(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Pi(i,e,{})),t[r]=i}return t}class X{constructor(e){this.spec=e,this.props={},e.props&&Pi(e.props,this,this.props),this.key=e.key?e.key.key:Ri("plugin")}getState(e){return e[this.key]}}const $n=Object.create(null);function Ri(n){return n in $n?n+"$"+ ++$n[n]:($n[n]=0,n+"$")}class de{constructor(e="key"){this.key=Ri(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const W=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},it=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Hn=null;const ge=function(n,e,t){let r=Hn||(Hn=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Yl=function(){Hn=null},We=function(n,e,t,r){return t&&(Li(n,e,t,r,-1)||Li(n,e,t,r,1))},Xl=/^(img|br|input|textarea|hr)$/i;function Li(n,e,t,r,i){for(var s;;){if(n==t&&e==r)return!0;if(e==(i<0?0:re(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Ct(n)||Xl.test(n.nodeName)||n.contentEditable=="false")return!1;e=W(n)+(i<0?0:1),n=o}else if(n.nodeType==1){let o=n.childNodes[e+(i<0?-1:0)];if(o.nodeType==1&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else n=o,e=i<0?re(n):0}else return!1}}function re(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Zl(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=re(n)}else if(n.parentNode&&!Ct(n))e=W(n),n=n.parentNode;else return null}}function Ql(n,e){for(;;){if(n.nodeType==3&&e2),se=st||(ue?/Mac/.test(ue.platform):!1),$i=ue?/Win/.test(ue.platform):!1,ye=/Android \d/.test(Te),wt=!!Bi&&"webkitFontSmoothing"in Bi.documentElement.style,ra=wt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ia(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function be(n,e){return typeof n=="number"?n:n[e]}function sa(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Hi(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;){if(o.nodeType!=1){o=it(o);continue}let l=o,a=l==s.body,c=a?ia(s):sa(l),d=0,u=0;if(e.topc.bottom-be(r,"bottom")&&(u=e.bottom-e.top>c.bottom-c.top?e.top+be(i,"top")-c.top:e.bottom-c.bottom+be(i,"bottom")),e.leftc.right-be(r,"right")&&(d=e.right-c.right+be(i,"right")),d||u)if(a)s.defaultView.scrollBy(d,u);else{let p=l.scrollLeft,h=l.scrollTop;u&&(l.scrollTop+=u),d&&(l.scrollLeft+=d);let m=l.scrollLeft-p,g=l.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let f=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:it(o)}}function oa(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Vi(n.dom)}}function Vi(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=it(r));return e}function la({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;_i(t,r==0?0:r-e)}function _i(n,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=d,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=u+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?ca(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Wi(t,i)}function ca(n,e){let t=n.nodeValue.length,r=document.createRange(),i;for(let s=0;s=(o.left+o.right)/2?1:0)};break}}return r.detach(),i||{node:n,offset:0}}function jn(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function da(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function fa(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function ji(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;wt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=fa(n,r,i,e))}l==null&&(l=ua(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function qi(n){return n.top=0&&i==r.nodeValue.length?(a--,d=1):t<0?a--:c++,Tt(Oe(ge(r,a,c),d),d<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return qn(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==re(r))){let a=r.childNodes[i-1],c=a.nodeType==3?ge(a,re(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Tt(Oe(c,1),!1)}if(s==null&&i=0)}function Tt(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function qn(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Ji(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function ma(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Ji(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Ki(n,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=ge(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cd.top+1&&(t=="up"?o.top-d.top>(d.bottom-o.top)*2:d.bottom-o.bottom>(o.bottom-d.top)*2))return!1}}return!0})}const ga=/[\u0590-\u08ac]/;function ya(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!ga.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Ji(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:d,anchorOffset:u}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&c==m;try{l.collapse(d,u),a&&(a!=d||c!=u)&&l.extend&&l.extend(a,c)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}let Ui=null,Gi=null,Yi=!1;function ba(n,e,t){return Ui==e&&Gi==t?Yi:(Ui=e,Gi=t,Yi=t=="up"||t=="down"?ma(n,e,t):ya(n,e,t))}const oe=0,Xi=1,qe=2,fe=3;class Nt{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=oe,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tW(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof es){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Zi&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?W(s.dom)+1:0}}else{let s,o=!0;for(;s=r=d&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,d);e=o;for(let u=l;u>0;u--){let f=this.children[u-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=W(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let d=l+1;dh&&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 r=0,i=0;i=r:er){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?qe:Xi,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=fe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?qe:fe}r=o}this.dirty=qe}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?qe:Xi;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==oe&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class xa extends Nt{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Ke extends Nt{constructor(e,t,r,i,s){super(e,[],r,i),this.mark=t,this.spec=s}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Ve.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Ke(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&fe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=fe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=oe){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Jn(s,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),d=c&&c.dom,u=c&&c.contentDOM;if(t.isText){if(!d)d=document.createTextNode(t.text);else if(d.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else d||({dom:d,contentDOM:u}=Ve.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!u&&!t.isText&&d.nodeName!="BR"&&(d.hasAttribute("contenteditable")||(d.contentEditable="false"),t.type.spec.draggable&&(d.draggable=!0));let f=d;return d=rs(d,r,t),c?a=new ka(e,t,r,i,d,u||null,f,c,s,o+1):t.isText?new Xt(e,t,r,i,d,f,s):new Ee(e,t,r,i,d,u||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>k.empty)}return e}matchesNode(e,t,r){return this.dirty==oe&&e.eq(this.node)&&Zt(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new Sa(this,o&&o.node,e);Ta(this.node,this.innerDeco,(c,d,u)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e,d):c.type.side>=0&&!u&&a.syncToMarks(d==this.node.childCount?P.none:this.node.child(d).marks,r,e,d),a.placeWidget(c,e,i)},(c,d,u,f)=>{a.syncToMarks(c.marks,r,e,f);let p;a.findNodeMatch(c,d,u,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,d,u,p,e)||a.updateNextNode(c,d,u,e,f,i)||a.addNode(c,d,u,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==qe)&&(o&&this.protectLocalComposition(e,o),ts(this.contentDOM,this.children,e),st&&Na(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof E)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Oa(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new xa(this,s,t,i);e.input.compositionNodes.push(o),this.children=Jn(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==fe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=oe}updateOuterDeco(e){if(Zt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=ns(this.dom,this.nodeDOM,Kn(this.outerDeco,this.node,t),Kn(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Qi(n,e,t,r,i){rs(r,e,n);let s=new Ee(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Xt extends Ee{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==fe||this.dirty!=oe&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=oe||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=oe,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new Xt(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=fe)}get domAtom(){return!1}isText(e){return this.node.text==e}}class es extends Nt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==oe&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class ka extends Ee{constructor(e,t,r,i,s,o,l,a,c,d){super(e,t,r,i,s,o,l,c,d),this.spec=a}update(e,t,r,i){if(this.dirty==fe)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function ts(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,l=Math.min(o,e.length);for(;s-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let d=Ke.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,d),this.top=d,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof Ke)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function wa(n,e){return n.type.side-e.type.side}function Ta(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let c=0;cs;)l.push(i[o++]);let h=s+f.nodeSize;if(f.isText){let g=h;o!g.inline):l.slice();r(f,m,e.forChild(s,f),p),s=h}}function Na(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Oa(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Jn(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||d<=e?s.push(a):(ct&&s.push(a.slice(t-c,a.size,r)))}return s}function Un(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if(Yt(t)){for(a=o;i&&!i.node;)i=i.parent;let u=i.node;if(i&&u.isAtom&&O.isSelectable(u)&&i.parent&&!(u.isInline&&ea(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;c=new O(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let u=o,f=o;for(let p=0;p{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!ss(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Aa(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,W(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&ee&&Ne<=11&&(t.disabled=!0,t.disabled=!1)}function ds(n,e){if(e instanceof O){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(us(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else us(n)}function us(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Yn(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||E.between(e,t,r)}function fs(n){return n.editable&&!n.hasFocus()?!1:ps(n)}function ps(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Ia(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return We(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Xn(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&I.findFrom(s,e)}function Ae(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function hs(n,e,t){let r=n.state.selection;if(r instanceof E)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ae(n,new E(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xn(n.state,e);return i&&i instanceof O?Ae(n,i):!1}else if(!(se&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?O.isSelectable(s)?Ae(n,new O(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):wt?Ae(n,new E(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof O&&r.node.isInline)return Ae(n,new E(e>0?r.$to:r.$from));{let i=Xn(n.state,e);return i?Ae(n,i):!1}}}function Qt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Et(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function lt(n,e){return e<0?va(n):Da(n)}function va(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ie&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Et(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(ms(t))break;{let l=t.previousSibling;for(;l&&Et(l,-1);)i=t.parentNode,s=W(l),l=l.previousSibling;if(l)t=l,r=Qt(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Zn(n,t,r):i&&Zn(n,i,s)}function Da(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Qt(t),s,o;for(;;)if(r{n.state==i&&xe(n)},50)}function gs(n,e){let t=n.state.doc.resolve(e);if(!(j||$i)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ys(n,e,t){let r=n.state.selection;if(r instanceof E&&!r.empty||t.indexOf("s")>-1||se&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Xn(n.state,e);if(o&&o instanceof O)return Ae(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof ne?I.near(o,e):I.findFrom(o,e);return l?Ae(n,l):!1}return!1}function bs(n,e){if(!(n.state.selection instanceof E))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function xs(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function La(n){if(!U||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;xs(n,r,"true"),setTimeout(()=>xs(n,r,"false"),20)}return!1}function Ba(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function za(n,e){let t=e.keyCode,r=Ba(e);if(t==8||se&&t==72&&r=="c")return bs(n,-1)||lt(n,-1);if(t==46&&!e.shiftKey||se&&t==68&&r=="c")return bs(n,1)||lt(n,1);if(t==13||t==27)return!0;if(t==37||se&&t==66&&r=="c"){let i=t==37?gs(n,n.state.selection.from)=="ltr"?-1:1:-1;return hs(n,i,r)||lt(n,i)}else if(t==39||se&&t==70&&r=="c"){let i=t==39?gs(n,n.state.selection.from)=="ltr"?1:-1:1;return hs(n,i,r)||lt(n,i)}else{if(t==38||se&&t==80&&r=="c")return ys(n,-1,r)||lt(n,-1);if(t==40||se&&t==78&&r=="c")return La(n)||ys(n,1,r)||lt(n,1);if(r==(se?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Qn(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let o=n.someProp("clipboardSerializer")||Ve.fromSchema(n.state.schema),l=Os(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,d,u=0;for(;c&&c.nodeType==1&&(d=Ts[c.nodeName.toLowerCase()]);){for(let p=d.length-1;p>=0;p--){let h=l.createElement(d[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),u++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${u?` -${u}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:f,slice:e}}function ks(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(r||s||!t);if(a){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return l=new C(k.from(n.state.schema.text(e.replace(/\r\n?/g,` `))),0,0),n.someProp("transformPasted",f=>{l=f(l,n,!0)}),l;let u=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(u)l=u;else{let f=i.marks(),{schema:p}=n.state,h=Ve.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,f)))})}}else n.someProp("transformPastedHTML",u=>{t=u(t,n)}),o=Va(t),wt&&_a(o);let c=o&&o.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let u=+d[3];u>0;u--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Me.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||d),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Fa.test(f.parentNode.nodeName)?{ignore:!0}:null}})),d)l=Wa(ws(l,+d[1],+d[2]),d[4]);else if(l=C.maxOpen($a(l.content,i),!0),l.openStart||l.openEnd){let u=0,f=0;for(let p=l.content.firstChild;u{l=u(l,n,a)}),l}const Fa=/^(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 $a(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&Ss(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Cs(o[o.length-1],s.length));let d=Ms(l,a);o.push(d),i=i.matchType(d.type),s=a}}),o)return k.from(o)}return n}function Ms(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,k.from(n));return n}function Ss(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(k.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ws(n,e,t){return et})),tr.createHTML(n)):n}function Va(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Os().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Ts[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=Ha(n),i)for(let s=0;s=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=k.from(a.create(r[l+1],i)),s++,o++}return new C(i,s,o)}const Z={},Q={},ja={touchstart:!0,touchmove:!0};class qa{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Ka(n){for(let e in Z){let t=Z[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Ua(n,r)&&!rr(n,r)&&(n.editable||!(r.type in Q))&&t(n,r)},ja[e]?{passive:!0}:void 0)}U&&n.dom.addEventListener("input",()=>null),nr(n)}function Ie(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Ja(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function nr(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>rr(n,r))})}function rr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Ua(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Ga(n,e){!rr(n,e)&&Z[e.type]&&(n.editable||!(e.type in Q))&&Z[e.type](n,e)}Q.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!As(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(ye&&j&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),st&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,je(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||za(n,t)?t.preventDefault():Ie(n,"key")},Q.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},Q.keypress=(n,e)=>{let t=e;if(As(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||se&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof E)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i,s))&&n.dispatch(s()),t.preventDefault()}};function en(n){return{left:n.clientX,top:n.clientY}}function Ya(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function ir(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function at(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function Xa(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&O.isSelectable(r)?(at(n,new O(t)),!0):!1}function Za(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof O&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(O.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(at(n,O.create(n.state.doc,i)),!0):!1}function Qa(n,e,t,r,i){return ir(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?Za(n,t):Xa(n,t))}function ec(n,e,t,r){return ir(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function tc(n,e,t,r){return ir(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||nc(n,t,r)}function nc(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(at(n,E.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)at(n,E.create(r,l+1,l+1+o.content.size));else if(O.isSelectable(o))at(n,O.create(r,l));else continue;return!0}}function sr(n){return tn(n)}const Es=se?"metaKey":"ctrlKey";Z.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=sr(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Ya(t,n.input.lastClick)&&!t[Es]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button};let o=n.posAtCoords(en(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new rc(n,o,t,!!r)):(s=="doubleClick"?ec:tc)(n,o.pos,o.inside,t)?t.preventDefault():Ie(n,"pointer"))};class rc{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Es],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let d=e.state.doc.resolve(t.pos);s=d.parent,o=d.depth?d.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof O&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ie&&!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)),Ie(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(()=>xe(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(en(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ie(this.view,"pointer"):Qa(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||U&&this.mightDrag&&!this.mightDrag.node.isAtom||j&&!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)?(at(this.view,I.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Ie(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ie(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)}}Z.touchstart=n=>{n.input.lastTouch=Date.now(),sr(n),Ie(n,"pointer")},Z.touchmove=n=>{n.input.lastTouch=Date.now(),Ie(n,"pointer")},Z.contextmenu=n=>sr(n);function As(n,e){return n.composing?!0:U&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const ic=ye?5e3:-1;Q.compositionstart=Q.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof E&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||j&&$i&&sc(n)))n.markCursor=n.state.storedMarks||t.marks(),tn(n,!0),n.markCursor=null;else if(tn(n,!e.selection.empty),ie&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Is(n,ic)};function sc(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}Q.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Is(n,20))};function Is(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>tn(n),e))}function vs(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=lc());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function oc(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Zl(e.focusNode,e.focusOffset),r=Ql(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function lc(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function tn(n,e=!1){if(!(ye&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),vs(n),e||n.docView&&n.docView.dirty){let t=Un(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function ac(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const At=ee&&Ne<15||st&&ra<604;Z.copy=Q.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=At?null:t.clipboardData,o=r.content(),{dom:l,text:a}=Qn(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):ac(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function cc(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function dc(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?It(n,r.value,null,i,e):It(n,r.textContent,r.innerHTML,i,e)},50)}function It(n,e,t,r,i){let s=ks(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,s||C.empty)))return!0;if(!s)return!1;let o=cc(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Ds(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Q.paste=(n,e)=>{let t=e;if(n.composing&&!ye)return;let r=At?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&It(n,Ds(r),r.getData("text/html"),i,t)?t.preventDefault():dc(n,t)};class Ps{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const uc=se?"altKey":"ctrlKey";function Rs(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[uc]}Z.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(en(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof O?i.to-1:i.to))){if(r&&r.mightDrag)o=O.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let u=n.docView.nearestDesc(t.target,!0);u&&u.node.type.spec.draggable&&u!=n.docView&&(o=O.create(n.state.doc,u.posBefore))}}let l=(o||n.state.selection).content(),{dom:a,text:c,slice:d}=Qn(n,l);(!t.dataTransfer.files.length||!j||Fi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(At?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",At||t.dataTransfer.setData("text/plain",c),n.dragging=new Ps(d,Rs(n,t),o)},Z.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},Q.dragover=Q.dragenter=(n,e)=>e.preventDefault(),Q.drop=(n,e)=>{try{fc(n,e,n.dragging)}finally{n.dragging=null}};function fc(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(en(e));if(!r)return;let i=n.state.doc.resolve(r.pos),s=t&&t.slice;s?n.someProp("transformPasted",p=>{s=p(s,n,!1)}):s=ks(n,Ds(e.dataTransfer),At?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Rs(n,e));if(n.someProp("handleDrop",p=>p(n,e,s||C.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Si(n.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=n.state.tr;if(o){let{node:p}=t;p?p.replace(a):a.deleteSelection()}let c=a.mapping.map(l),d=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,u=a.doc;if(d?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(u))return;let f=a.doc.resolve(c);if(d&&O.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new O(f));else{let p=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((h,m,g,y)=>p=y),a.setSelection(Yn(n,f,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Z.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&xe(n)},20))},Z.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)},Z.beforeinput=(n,e)=>{if(j&&ye&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,je(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Q)Z[n]=Q[n];function vt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class nn{constructor(e,t){this.toDOM=e,this.spec=t||Ue,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new le(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof nn&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&vt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class ve{constructor(e,t){this.attrs=e,this.spec=t||Ue}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new le(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==G||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Ue)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let c=a+r,d;if(d=Bs(t,l,c)){for(i||(i=this.children.slice());sl&&u.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof ve){let c=Math.max(s,a.from)-s,d=Math.min(o,a.to)-s;ci.map(e,t,Ue));return De.from(r)}forChild(e,t){if(t.isLeaf)return z.empty;let r=[];for(let i=0;it instanceof z)?e:e.reduce((t,r)=>t.concat(r instanceof z?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-h-(p-f);for(let y=0;yx+d-u)continue;let b=l[y]+d-u;p>=b?l[y+1]=f<=b?-2:-1:f>=d&&g&&(l[y]+=g,l[y+1]+=g)}u+=g}),d=t.maps[c].map(d,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let f=t.map(n[c+1]+s,-1),p=f-i,{index:h,offset:m}=r.content.findIndex(u),g=r.maybeChild(h);if(g&&m==u&&m+g.nodeSize==p){let y=l[c+2].mapInner(t,g,d+1,n[c]+s+1,o);y!=G?(l[c]=u,l[c+1]=p,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=hc(l,n,e,t,i,s,o),d=rn(c,r,0,o);e=d.local;for(let u=0;ut&&o.to{let c=Bs(n,l,a+t);if(c){s=!0;let d=rn(c,l,t+a+1,r);d!=G&&i.push(a,a+l.nodeSize,d)}});let o=Ls(s?zs(n):n,-t).sort(Ge);for(let l=0;l0;)e++;n.splice(e,0,t)}function ar(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=G&&e.push(r)}),n.cursorWrapper&&e.push(z.create(n.state.doc,[n.cursorWrapper.deco])),De.from(e)}const mc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},gc=ee&&Ne<=11;class yc{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 bc{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new yc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():U&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),gc&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,mc)),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(fs(this.view)){if(this.suppressingSelectionUpdates)return xe(this.view);if(ee&&Ne<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&We(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=it(s))t.add(s);for(let s=e.anchorNode;s;s=it(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&fs(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let d=0;dd.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let d of a)if(d.nodeName=="BR"&&d.parentNode){let u=d.nextSibling;u&&u.nodeType==1&&u.contentEditable=="false"&&d.parentNode.removeChild(d)}}else if(ie&&a.length){let d=a.filter(u=>u.nodeName=="BR");if(d.length==2){let[u,f]=d;u.parentNode&&u.parentNode.parentNode==f.parentNode?f.remove():u.remove()}else{let{focusNode:u}=this.currentSelection;for(let f of d){let p=f.parentNode;p&&p.nodeName=="LI"&&(!u||Mc(e,u)!=p)&&f.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),xc(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Sc(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||xe(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let d=0;di;g--){let y=r.childNodes[g-1],x=y.pmViewDesc;if(y.nodeName=="BR"&&!x){s=g;break}if(!x||x.size)break}let u=n.state.doc,f=n.someProp("domParser")||Me.fromSchema(n.state.schema),p=u.resolve(o),h=null,m=f.parse(r,{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:wc,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),h={anchor:g+o,head:y+o}}return{doc:m,sel:h,from:o,to:l}}function wc(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(U&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||U&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Tc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Nc(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let w=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,A=Un(n,w);if(A&&!n.state.selection.eq(A)){if(j&&ye&&n.input.lastKeyCode===13&&Date.now()-100he(n,je(13,"Enter"))))return;let D=n.state.tr.setSelection(A);w=="pointer"?D.setMeta("pointer",!0):w=="key"&&D.scrollIntoView(),s&&D.setMeta("composition",s),n.dispatch(D)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=Cc(n,e,t),d=n.state.doc,u=d.slice(c.from,c.to),f,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ye)&&i.some(w=>w.nodeType==1&&!Tc.test(w.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",w=>w(n,je(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof E&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let w=_s(n,n.state.doc,c.sel);if(w&&!w.eq(n.state.selection)){let A=n.state.tr.setSelection(w);s&&A.setMeta("composition",s),n.dispatch(A)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),ee&&Ne<=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),y=d.resolve(h.start),x=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=h.endA;if((st&&n.input.lastIOSEnter>Date.now()-225&&(!x||i.some(w=>w.nodeName=="DIV"||w.nodeName=="P"))||!x&&m.posw(n,je(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&Ec(d,h.start,h.endA,m,g)&&n.someProp("handleKeyDown",w=>w(n,je(8,"Backspace")))){ye&&j&&n.domObserver.suppressSelectionUpdates();return}j&&h.endB==h.start&&(n.input.lastChromeDelete=Date.now()),ye&&!x&&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(()=>{n.someProp("handleKeyDown",function(w){return w(n,je(13,"Enter"))})},20));let b=h.start,M=h.endA,S=w=>{let A=w||n.state.tr.replace(b,M,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let D=_s(n,A.doc,c.sel);D&&!(j&&n.composing&&D.empty&&(h.start!=h.endB||n.input.lastChromeDeletexe(n),20));let w=S(n.state.tr.delete(b,M)),A=d.resolve(h.start).marksAcross(d.resolve(h.endA));A&&w.ensureMarks(A),n.dispatch(w)}else if(h.endA==h.endB&&(N=Oc(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let w=S(n.state.tr);N.type=="add"?w.addMark(b,M,N.mark):w.removeMark(b,M,N.mark),n.dispatch(w)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let w=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>S(n.state.tr.insertText(w,b,M));n.someProp("handleTextInput",D=>D(n,b,M,w,A))||n.dispatch(A())}else n.dispatch(S());else n.dispatch(S())}function _s(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Yn(n,e.resolve(t.anchor),e.resolve(t.head))}function Oc(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,a;for(let d=0;dd.mark(l.addToSet(d.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=d=>d.mark(l.removeFromSet(d.marks));else return null;let c=[];for(let d=0;dt||cr(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ac(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o=o?s-r:0;s-=a,s&&s=l?s-r:0;s-=a,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}class js{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 qa,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Gs),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=Js(this),Ks(this),this.nodeViews=Us(this),this.docView=Qi(this.state.doc,qs(this),ar(this),this.dom,this),this.domObserver=new bc(this,(r,i,s,o)=>Nc(this,r,i,s,o)),this.domObserver.start(),Ka(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&&nr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Gs),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(vs(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=Us(this);vc(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&nr(this),this.editable=Js(this),Ks(this);let a=ar(this),c=qs(this),d=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",u=s||!this.docView.matchesNode(e.doc,c,a);(u||!e.selection.eq(i.selection))&&(o=!0);let f=d=="preserve"&&o&&this.dom.style.overflowAnchor==null&&oa(this);if(o){this.domObserver.stop();let p=u&&(ee||j)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ic(i.selection,e.selection);if(u){let h=j?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=oc(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Qi(e.doc,c,a,this.dom,this)),h&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ia(this))?xe(this,p):(ds(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),d=="reset"?this.dom.scrollTop=0:d=="to selection"?this.scrollToSelection():f&&la(f)}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 O){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Hi(this,t.getBoundingClientRect(),e)}else Hi(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new Ps(e.slice,e.move,i<0?void 0:O.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return pa(this,e)}coordsAtPos(e,t=1){return Ki(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ba(this,t||this.state,e)}pasteHTML(e,t){return It(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return It(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Qn(this,e)}destroy(){this.docView&&(Ja(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],ar(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Yl())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Ga(this,e)}domSelectionRange(){let e=this.domSelection();return e?U&&this.root.nodeType===11&&ta(this.dom.ownerDocument)==this.dom&&kc(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}js.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function qs(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[le.node(0,n.state.doc.content.size,e)]}function Ks(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:le.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Js(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ic(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Us(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function vc(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Gs(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var Pe={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:"'"},sn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Dc=typeof navigator<"u"&&/Mac/.test(navigator.platform),Pc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),q=0;q<10;q++)Pe[48+q]=Pe[96+q]=String(q);for(var q=1;q<=24;q++)Pe[q+111]="F"+q;for(var q=65;q<=90;q++)Pe[q]=String.fromCharCode(q+32),sn[q]=String.fromCharCode(q);for(var dr in Pe)sn.hasOwnProperty(dr)||(sn[dr]=Pe[dr]);function Rc(n){var e=Dc&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Pc&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?sn:Pe)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Lc=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Bc=typeof navigator<"u"&&/Win/.test(navigator.platform);function zc(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;ln.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Xs(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Zs=(n,e,t)=>{let r=Xs(n,t);if(!r)return!1;let i=pr(r);if(!i){let o=r.blockRange(),l=o&&Qe(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(lo(n,i,e,-1))return!0;if(r.parent.content.size==0&&(dt(s,"end")||O.isSelectable(s)))for(let o=r.depth;;o--){let l=Jt(n.doc,r.before(o),r.after(o),C.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},Hc=(n,e,t)=>{let r=Xs(n,t);if(!r)return!1;let i=pr(r);return i?Qs(n,i,e):!1},Vc=(n,e,t)=>{let r=to(n,t);if(!r)return!1;let i=hr(r);return i?Qs(n,i,e):!1};function Qs(n,e,t){let r=e.nodeBefore,i=r,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let d=i.lastChild;if(!d)return!1;i=d}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let d=l.firstChild;if(!d)return!1;l=d}let c=Jt(n.doc,s,a,C.empty);if(!c||c.from!=s||c instanceof $&&c.slice.size>=a-s)return!1;if(t){let d=n.tr.step(c);d.setSelection(E.create(d.doc,s)),t(d.scrollIntoView())}return!0}function dt(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}const eo=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=pr(r)}let o=s&&s.nodeBefore;return!o||!O.isSelectable(o)?!1:(e&&e(n.tr.setSelection(O.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function pr(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function to(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=to(n,t);if(!r)return!1;let i=hr(r);if(!i)return!1;let s=i.nodeAfter;if(lo(n,i,e,1))return!0;if(r.parent.content.size==0&&(dt(s,"start")||O.isSelectable(s))){let o=Jt(n.doc,r.before(),r.after(),C.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof O,i;if(r){if(t.node.isTextblock||!we(n.doc,t.from))return!1;i=t.from}else if(i=Kt(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(O.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Wc=(n,e)=>{let t=n.selection,r;if(t instanceof O){if(t.node.isTextblock||!we(n.doc,t.to))return!1;r=t.to}else if(r=Kt(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jc=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&Qe(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},io=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` `).scrollIntoView()),!0)};function mr(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=mr(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(I.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},so=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof ne||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=mr(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(me(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Qe(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Kc(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof O&&e.selection.node.isBlock)return!r.parentOffset||!me(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){a=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),l=mr(r.node(p-1).contentMatchAt(r.indexAfter(p-1))),s.unshift(a&&l?{type:l}:null),o=p;break}else{if(p==1)return!1;s.unshift(null)}let d=e.tr;(e.selection instanceof E||e.selection instanceof ne)&&d.deleteSelection();let u=d.mapping.map(r.pos),f=me(d.doc,u,s.length,s);if(f||(s[0]=l?{type:l}:null,f=me(d.doc,u,s.length,s)),!f)return!1;if(d.split(u,s.length,s),!a&&c&&r.node(o).type!=l){let p=d.mapping.map(r.before(o)),h=d.doc.resolve(p);l&&r.node(o-1).canReplaceWith(h.index(),h.index()+1,l)&&d.setNodeMarkup(d.mapping.map(r.before(o)),l)}return t&&t(d.scrollIntoView()),!0}}const Jc=Kc(),Uc=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(O.create(n.doc,i))),!0)};function Gc(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||we(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function lo(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Gc(n,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=k.empty;for(let y=o.length-1;y>=0;y--)h=k.from(o[y].create(null,h));h=k.from(i.copy(h));let m=n.tr.step(new H(e.pos-1,p,e.pos,p,new C(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 d=s.type.spec.isolating||r>0&&a?null:I.findFrom(e,1),u=d&&d.$from.blockRange(d.$to),f=u&&Qe(u);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(u,f).scrollIntoView()),!0;if(c&&dt(s,"start",!0)&&dt(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 y=k.empty;for(let b=h.length-1;b>=0;b--)y=k.from(h[b].copy(y));let x=n.tr.step(new H(e.pos-h.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new C(y,h.length,0),0,!0));t(x.scrollIntoView())}return!0}}return!1}function ao(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(E.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}const Yc=ao(-1),Xc=ao(1);function Zc(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Pn(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function co(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let d=t.doc.resolve(c),u=d.index();i=d.parent.canReplaceWith(u,u+1,n)}})}if(!i)return!1;if(r){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 Ht(a,a,e.depth),e.endIndex=0;d--)s=k.from(t[d].type.create(t[d].attrs,s));n.step(new H(e.start-(r?2:0),e.end,e.start,e.end,new C(s,0,0),t.length,!0));let o=0;for(let d=0;do.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?rd(e,t,n,s):id(e,t,s):!0:!1}}function rd(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;h--)p-=i.child(h).nodeSize,r.delete(p-1,p+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),d=s.index(-1);if(!c.canReplace(d+(l?0:1),d+1,o.content.append(a?k.empty:k.from(i))))return!1;let u=s.pos,f=u+o.nodeSize;return r.step(new H(u-(l?1:0),f+(a?1:0),u+1,f-1,new C((l?k.empty:k.from(i.copy(k.empty))).append(a?k.empty:k.from(i.copy(k.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function sd(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);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!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,d=k.from(c?n.create():null),u=new C(k.from(n.create(null,k.from(l.type.create(null,d)))),c?3:1,0),f=s.start,p=s.end;t(e.tr.step(new H(f-(c?3:1),p,f,p,u,1,!0)).scrollIntoView())}return!0}}function on(n){const{state:e,transaction:t}=n;let{selection:r}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=t.selection,i=t.doc,s=t.storedMarks,t}}}class ln{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:r}=this,{view:i}=t,{tr:s}=r,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...d)=>{const u=a(...d)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,d=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(r).map(([f,p])=>[f,(...m)=>{const g=this.buildProps(c,t),y=p(...m)(g);return l.push(y),u}])),run:d};return u}createCan(e){const{rawCommands:t,state:r}=this,i=!1,s=e||r.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...d)=>c(...d)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:on({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([a,c])=>[a,(...d)=>c(...d)(l)]))}};return l}}class od{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const r=this.callbacks[e];return r&&r.forEach(i=>i.apply(this,t)),this}off(e,t){const r=this.callbacks[e];return r&&(t?this.callbacks[e]=r.filter(i=>i!==t):delete this.callbacks[e]),this}once(e,t){const r=(...i)=>{this.off(e,r),t.apply(this,i)};return this.on(e,r)}removeAllListeners(){this.callbacks={}}}function T(n,e,t){return n.config[e]===void 0&&n.parent?T(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?T(n.parent,e,t):null}):n.config[e]}function an(n){const e=n.filter(i=>i.type==="extension"),t=n.filter(i=>i.type==="node"),r=n.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:r}}function uo(n){const e=[],{nodeExtensions:t,markExtensions:r}=an(n),i=[...t,...r],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return n.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage,extensions:i},a=T(o,"addGlobalAttributes",l);if(!a)return;a().forEach(d=>{d.types.forEach(u=>{Object.entries(d.attributes).forEach(([f,p])=>{e.push({type:u,name:f,attribute:{...s,...p}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=T(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([d,u])=>{const f={...s,...u};typeof(f==null?void 0:f.default)=="function"&&(f.default=f.default()),f!=null&&f.isRequired&&(f==null?void 0:f.default)===void 0&&delete f.default,e.push({type:o.name,name:d,attribute:f})})}),e}function V(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}function F(...n){return n.filter(e=>!!e).reduce((e,t)=>{const r={...e};return Object.entries(t).forEach(([i,s])=>{if(!r[i]){r[i]=s;return}if(i==="class"){const l=s?String(s).split(" "):[],a=r[i]?r[i].split(" "):[],c=l.filter(d=>!a.includes(d));r[i]=[...a,...c].join(" ")}else if(i==="style"){const l=s?s.split(";").map(d=>d.trim()).filter(Boolean):[],a=r[i]?r[i].split(";").map(d=>d.trim()).filter(Boolean):[],c=new Map;a.forEach(d=>{const[u,f]=d.split(":").map(p=>p.trim());c.set(u,f)}),l.forEach(d=>{const[u,f]=d.split(":").map(p=>p.trim());c.set(u,f)}),r[i]=Array.from(c.entries()).map(([d,u])=>`${d}: ${u}`).join("; ")}else r[i]=s}),r},{})}function yr(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,r)=>F(t,r),{})}function fo(n){return typeof n=="function"}function v(n,e=void 0,...t){return fo(n)?e?n.bind(e)(...t):n(...t):n}function ld(n={}){return Object.keys(n).length===0&&n.constructor===Object}function ad(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function po(n,e){return"style"in n?n:{...n,getAttrs:t=>{const r=n.getAttrs?n.getAttrs(t):n.attrs;if(r===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):ad(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...r,...i}}}}function ho(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&ld(t)?!1:t!=null))}function cd(n,e){var t;const r=uo(n),{nodeExtensions:i,markExtensions:s}=an(n),o=(t=i.find(c=>T(c,"topNode")))===null||t===void 0?void 0:t.name,l=Object.fromEntries(i.map(c=>{const d=r.filter(y=>y.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((y,x)=>{const b=T(x,"extendNodeSchema",u);return{...y,...b?b(c):{}}},{}),p=ho({...f,content:v(T(c,"content",u)),marks:v(T(c,"marks",u)),group:v(T(c,"group",u)),inline:v(T(c,"inline",u)),atom:v(T(c,"atom",u)),selectable:v(T(c,"selectable",u)),draggable:v(T(c,"draggable",u)),code:v(T(c,"code",u)),whitespace:v(T(c,"whitespace",u)),linebreakReplacement:v(T(c,"linebreakReplacement",u)),defining:v(T(c,"defining",u)),isolating:v(T(c,"isolating",u)),attrs:Object.fromEntries(d.map(y=>{var x;return[y.name,{default:(x=y==null?void 0:y.attribute)===null||x===void 0?void 0:x.default}]}))}),h=v(T(c,"parseHTML",u));h&&(p.parseDOM=h.map(y=>po(y,d)));const m=T(c,"renderHTML",u);m&&(p.toDOM=y=>m({node:y,HTMLAttributes:yr(y,d)}));const g=T(c,"renderText",u);return g&&(p.toText=g),[c.name,p]})),a=Object.fromEntries(s.map(c=>{const d=r.filter(g=>g.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((g,y)=>{const x=T(y,"extendMarkSchema",u);return{...g,...x?x(c):{}}},{}),p=ho({...f,inclusive:v(T(c,"inclusive",u)),excludes:v(T(c,"excludes",u)),group:v(T(c,"group",u)),spanning:v(T(c,"spanning",u)),code:v(T(c,"code",u)),attrs:Object.fromEntries(d.map(g=>{var y;return[g.name,{default:(y=g==null?void 0:g.attribute)===null||y===void 0?void 0:y.default}]}))}),h=v(T(c,"parseHTML",u));h&&(p.parseDOM=h.map(g=>po(g,d)));const m=T(c,"renderHTML",u);return m&&(p.toDOM=g=>m({mark:g,HTMLAttributes:yr(g,d)})),[c.name,p]}));return new ni({topNode:o,nodes:l,marks:a})}function br(n,e){return e.nodes[n]||e.marks[n]||null}function mo(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function xr(n,e){const t=Ve.fromSchema(e).serializeFragment(n),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}const dd=(n,e=500)=>{let t="";const r=n.parentOffset;return n.parent.nodesBetween(Math.max(0,r-e),r,(i,s,o,l)=>{var a,c;const d=((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+=i.isAtom&&!i.isText?d:d.slice(0,Math.max(0,r-s))}),t};function kr(n){return Object.prototype.toString.call(n)==="[object RegExp]"}class cn{constructor(e){this.find=e.find,this.handler=e.handler}}const ud=(n,e)=>{if(kr(e))return e.exec(n);const t=e(n);if(!t)return null;const r=[t.text];return r.index=t.index,r.input=n,r.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(t.replaceWith)),r};function dn(n){var e;const{editor:t,from:r,to:i,text:s,rules:o,plugin:l}=n,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(r);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(f=>f.type.spec.code))return!1;let d=!1;const u=dd(c)+s;return o.forEach(f=>{if(d)return;const p=ud(u,f.find);if(!p)return;const h=a.state.tr,m=on({state:a.state,transaction:h}),g={from:r-(p[0].length-s.length),to:i},{commands:y,chain:x,can:b}=new ln({editor:t,state:m});f.handler({state:m,range:g,match:p,commands:y,chain:x,can:b})===null||!h.steps.length||(h.setMeta(l,{transform:h,from:r,to:i,text:s}),a.dispatch(h),d=!0)}),d}function fd(n){const{editor:e,rules:t}=n,r=new X({state:{init(){return null},apply(i,s,o){const l=i.getMeta(r);if(l)return l;const a=i.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:d}=a;typeof d=="string"?d=d:d=xr(k.from(d),o.schema);const{from:u}=a,f=u+d.length;dn({editor:e,from:u,to:f,text:d,rules:t,plugin:r})}),i.selectionSet||i.docChanged?null:s}},props:{handleTextInput(i,s,o,l){return dn({editor:e,from:s,to:o,text:l,rules:t,plugin:r})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&dn({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:r})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?dn({editor:e,from:o.pos,to:o.pos,text:` `,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function pd(n){return Object.prototype.toString.call(n).slice(8,-1)}function un(n){return pd(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function fn(n,e){const t={...n};return un(n)&&un(e)&&Object.keys(e).forEach(r=>{un(e[r])&&un(n[r])?t[r]=fn(n[r],e[r]):t[r]=e[r]}),t}class Re{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&&Object.keys(e.defaultOptions).length>0&&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=v(T(this,"addOptions",{name:this.name}))),this.storage=v(T(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Re(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>fn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Re(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(T(t,"addOptions",{name:t.name})),t.storage=v(T(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:r}=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&&r.removeStoredMark(a),r.insertText(" ",i.pos),e.view.dispatch(r),!0}return!1}}function hd(n){return typeof n=="number"}class md{constructor(e){this.find=e.find,this.handler=e.handler}}const gd=(n,e,t)=>{if(kr(e))return[...n.matchAll(e)];const r=e(n,t);return r?r.map(i=>{const s=[i.text];return s.index=i.index,s.input=n,s.data=i.data,i.replaceWith&&(i.text.includes(i.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(i.replaceWith)),s}):[]};function yd(n){const{editor:e,state:t,from:r,to:i,rule:s,pasteEvent:o,dropEvent:l}=n,{commands:a,chain:c,can:d}=new ln({editor:e,state:t}),u=[];return t.doc.nodesBetween(r,i,(p,h)=>{if(!p.isTextblock||p.type.spec.code)return;const m=Math.max(r,h),g=Math.min(i,h+p.content.size),y=p.textBetween(m-h,g-h,void 0,"");gd(y,s.find,o).forEach(b=>{if(b.index===void 0)return;const M=m+b.index+1,S=M+b[0].length,N={from:t.tr.mapping.map(M),to:t.tr.mapping.map(S)},w=s.handler({state:t,range:N,match:b,commands:a,chain:c,can:d,pasteEvent:o,dropEvent:l});u.push(w)})}),u.every(p=>p!==null)}let pn=null;const bd=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)===null||e===void 0||e.setData("text/html",n),t};function xd(n){const{editor:e,rules:t}=n;let r=null,i=!1,s=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const a=({state:d,from:u,to:f,rule:p,pasteEvt:h})=>{const m=d.tr,g=on({state:d,transaction:m});if(!(!yd({editor:e,state:g,from:Math.max(u-1,0),to:f.b-1,rule:p,pasteEvent:h,dropEvent:l})||!m.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,m}};return t.map(d=>new X({view(u){const f=h=>{var m;r=!((m=u.dom.parentElement)===null||m===void 0)&&m.contains(h.target)?u.dom.parentElement:null,r&&(pn=e)},p=()=>{pn&&(pn=null)};return window.addEventListener("dragstart",f),window.addEventListener("dragend",p),{destroy(){window.removeEventListener("dragstart",f),window.removeEventListener("dragend",p)}}},props:{handleDOMEvents:{drop:(u,f)=>{if(s=r===u.dom.parentElement,l=f,!s){const p=pn;p!=null&&p.isEditable&&setTimeout(()=>{const h=p.state.selection;h&&p.commands.deleteRange({from:h.from,to:h.to})},10)}return!1},paste:(u,f)=>{var p;const h=(p=f.clipboardData)===null||p===void 0?void 0:p.getData("text/html");return o=f,i=!!(h!=null&&h.includes("data-pm-slice")),!1}}},appendTransaction:(u,f,p)=>{const h=u[0],m=h.getMeta("uiEvent")==="paste"&&!i,g=h.getMeta("uiEvent")==="drop"&&!s,y=h.getMeta("applyPasteRules"),x=!!y;if(!m&&!g&&!x)return;if(x){let{text:S}=y;typeof S=="string"?S=S:S=xr(k.from(S),p.schema);const{from:N}=y,w=N+S.length,A=bd(S);return a({rule:d,state:p,from:N,to:{b:w},pasteEvt:A})}const b=f.doc.content.findDiffStart(p.doc.content),M=f.doc.content.findDiffEnd(p.doc.content);if(!(!hd(b)||!M||b===M.b))return a({rule:d,state:p,from:b,to:M,pasteEvt:o})}}))}function kd(n){const e=n.filter((t,r)=>n.indexOf(t)!==r);return Array.from(new Set(e))}class ut{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=ut.resolve(e),this.schema=cd(this.extensions,t),this.setupExtensions()}static resolve(e){const t=ut.sort(ut.flatten(e)),r=kd(t.map(i=>i.name));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{const r={name:t.name,options:t.options,storage:t.storage},i=T(t,"addExtensions",r);return i?[t,...this.flatten(i())]:t}).flat(10)}static sort(e){return e.sort((r,i)=>{const s=T(r,"priority")||100,o=T(i,"priority")||100;return s>o?-1:s{const r={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:br(t.name,this.schema)},i=T(t,"addCommands",r);return i?{...e,...i()}:e},{})}get plugins(){const{editor:e}=this,t=ut.sort([...this.extensions].reverse()),r=[],i=[],s=t.map(o=>{const l={name:o.name,options:o.options,storage:o.storage,editor:e,type:br(o.name,this.schema)},a=[],c=T(o,"addKeyboardShortcuts",l);let d={};if(o.type==="mark"&&T(o,"exitable",l)&&(d.ArrowRight=()=>Re.handleExit({editor:e,mark:o})),c){const m=Object.fromEntries(Object.entries(c()).map(([g,y])=>[g,()=>y({editor:e})]));d={...d,...m}}const u=$c(d);a.push(u);const f=T(o,"addInputRules",l);mo(o,e.options.enableInputRules)&&f&&r.push(...f());const p=T(o,"addPasteRules",l);mo(o,e.options.enablePasteRules)&&p&&i.push(...p());const h=T(o,"addProseMirrorPlugins",l);if(h){const m=h();a.push(...m)}return a}).flat();return[fd({editor:e,rules:r}),...xd({editor:e,rules:i}),...s]}get attributes(){return uo(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=an(this.extensions);return Object.fromEntries(t.filter(r=>!!T(r,"addNodeView")).map(r=>{const i=this.attributes.filter(a=>a.type===r.name),s={name:r.name,options:r.options,storage:r.storage,editor:e,type:V(r.name,this.schema)},o=T(r,"addNodeView",s);if(!o)return[];const l=(a,c,d,u,f)=>{const p=yr(a,i);return o()({node:a,view:c,getPos:d,decorations:u,innerDecorations:f,editor:e,extension:r,HTMLAttributes:p})};return[r.name,l]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const r={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:br(e.name,this.schema)};e.type==="mark"&&(!((t=v(T(e,"keepOnSplit",r)))!==null&&t!==void 0)||t)&&this.splittableMarks.push(e.name);const i=T(e,"onBeforeCreate",r),s=T(e,"onCreate",r),o=T(e,"onUpdate",r),l=T(e,"onSelectionUpdate",r),a=T(e,"onTransaction",r),c=T(e,"onFocus",r),d=T(e,"onBlur",r),u=T(e,"onDestroy",r);i&&this.editor.on("beforeCreate",i),s&&this.editor.on("create",s),o&&this.editor.on("update",o),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),c&&this.editor.on("focus",c),d&&this.editor.on("blur",d),u&&this.editor.on("destroy",u)})}}class Y{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&&Object.keys(e.defaultOptions).length>0&&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=v(T(this,"addOptions",{name:this.name}))),this.storage=v(T(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Y(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>fn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Y({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(T(t,"addOptions",{name:t.name})),t.storage=v(T(t,"addStorage",{name:t.name,options:t.options})),t}}function go(n,e,t){const{from:r,to:i}=e,{blockSeparator:s=` `,textSerializers:o={}}=t||{};let l="";return n.nodesBetween(r,i,(a,c,d,u)=>{var f;a.isBlock&&c>r&&(l+=s);const p=o==null?void 0:o[a.type.name];if(p)return d&&(l+=p({node:a,pos:c,parent:d,index:u,range:e})),!1;a.isText&&(l+=(f=a==null?void 0:a.text)===null||f===void 0?void 0:f.slice(Math.max(r,c)-c,i-c))}),l}function yo(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Md=Y.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new X({key:new de("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:r,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(d=>d.$from.pos)),l=Math.max(...s.map(d=>d.$to.pos)),a=yo(t);return go(r,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),Sd=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),Cd=(n=!1)=>({commands:e})=>e.setContent("",n),wd=()=>({state:n,tr:e,dispatch:t})=>{const{selection:r}=e,{ranges:i}=r;return t&&i.forEach(({$from:s,$to:o})=>{n.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:d}=e,u=c.resolve(d.map(a)),f=c.resolve(d.map(a+l.nodeSize)),p=u.blockRange(f);if(!p)return;const h=Qe(p);if(l.type.isTextblock){const{defaultType:m}=u.parent.contentMatchAt(u.index());e.setNodeMarkup(p.start,m)}(h||h===0)&&e.lift(p,h)})}),!0},Td=n=>e=>n(e),Nd=()=>({state:n,dispatch:e})=>so(n,e),Od=(n,e)=>({editor:t,tr:r})=>{const{state:i}=t,s=i.doc.slice(n.from,n.to);r.deleteRange(n.from,n.to);const o=r.mapping.map(e);return r.insert(o,s.content),r.setSelection(new E(r.doc.resolve(Math.max(o-1,0)))),!0},Ed=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,r=t.$anchor.node();if(r.content.size>0)return!1;const i=n.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r.type){if(e){const l=i.before(s),a=i.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1},Ad=n=>({tr:e,state:t,dispatch:r})=>{const i=V(n,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(r){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},Id=n=>({tr:e,dispatch:t})=>{const{from:r,to:i}=n;return t&&e.delete(r,i),!0},vd=()=>({state:n,dispatch:e})=>fr(n,e),Dd=()=>({commands:n})=>n.keyboardShortcut("Enter"),Pd=()=>({state:n,dispatch:e})=>qc(n,e);function hn(n,e,t={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>t.strict?e[i]===n[i]:kr(e[i])?e[i].test(n[i]):e[i]===n[i]):!0}function bo(n,e,t={}){return n.find(r=>r.type===e&&hn(Object.fromEntries(Object.keys(t).map(i=>[i,r.attrs[i]])),t))}function xo(n,e,t={}){return!!bo(n,e,t)}function Mr(n,e,t){var r;if(!n||!e)return;let i=n.parent.childAfter(n.parentOffset);if((!i.node||!i.node.marks.some(d=>d.type===e))&&(i=n.parent.childBefore(n.parentOffset)),!i.node||!i.node.marks.some(d=>d.type===e)||(t=t||((r=i.node.marks[0])===null||r===void 0?void 0:r.attrs),!bo([...i.node.marks],e,t)))return;let o=i.index,l=n.start()+i.offset,a=o+1,c=l+i.node.nodeSize;for(;o>0&&xo([...n.parent.child(o-1).marks],e,t);)o-=1,l-=n.parent.child(o).nodeSize;for(;a({tr:t,state:r,dispatch:i})=>{const s=Le(n,r.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:d}=l;if(i){const u=Mr(a,s,e);if(u&&u.from<=c&&u.to>=d){const f=E.create(o,u.from,u.to);t.setSelection(f)}}return!0},Ld=n=>e=>{const t=typeof n=="function"?n(e):n;for(let r=0;r({editor:t,view:r,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{(mn()||So())&&r.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(r.focus(),Bd()&&!mn()&&!So()&&r.dom.focus({preventScroll:!0}))})};if(r.hasFocus()&&n===null||n===!1)return!0;if(s&&n===null&&!ko(t.state.selection))return o(),!0;const l=Mo(i.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Fd=(n,e)=>t=>n.every((r,i)=>e(r,{...t,index:i})),$d=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),Co=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const r=e[t];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?n.removeChild(r):r.nodeType===1&&Co(r)}return n};function gn(n){const e=`${n}`,t=new window.DOMParser().parseFromString(e,"text/html").body;return Co(t)}function Dt(n,e,t){if(n instanceof ke||n instanceof k)return n;t={slice:!0,parseOptions:{},...t};const r=typeof n=="object"&&n!==null,i=typeof n=="string";if(r)try{if(Array.isArray(n)&&n.length>0)return k.fromArray(n.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(n);return t.errorOnInvalidContent&&o.check(),o}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),Dt("",e,t)}if(i){if(t.errorOnInvalidContent){let o=!1,l="";const a=new ni({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,l=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?Me.fromSchema(a).parseSlice(gn(n),t.parseOptions):Me.fromSchema(a).parse(gn(n),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Me.fromSchema(e);return t.slice?s.parseSlice(gn(n),t.parseOptions).content:s.parse(gn(n),t.parseOptions)}return Dt("",e,t)}function Hd(n,e,t){const r=n.steps.length-1;if(r{o===0&&(o=d)}),n.setSelection(I.near(n.doc.resolve(o),t))}const Vd=n=>!("type"in n),_d=(n,e,t)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;const a=g=>{s.emit("contentError",{editor:s,error:g,disableCollaboration:()=>{s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...t.parseOptions};if(!t.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{Dt(e,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(g){a(g)}try{l=Dt(e,s.schema,{parseOptions:c,errorOnInvalidContent:(o=t.errorOnInvalidContent)!==null&&o!==void 0?o:s.options.enableContentCheck})}catch(g){return a(g),!1}let{from:d,to:u}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},f=!0,p=!0;if((Vd(l)?l:[l]).forEach(g=>{g.check(),f=f?g.isText&&g.marks.length===0:!1,p=p?g.isBlock:!1}),d===u&&p){const{parent:g}=r.doc.resolve(d);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(d-=1,u+=1)}let m;if(f){if(Array.isArray(e))m=e.map(g=>g.text||"").join("");else if(e instanceof k){let g="";e.forEach(y=>{y.text&&(g+=y.text)}),m=g}else typeof e=="object"&&e&&e.text?m=e.text:m=e;r.insertText(m,d,u)}else m=l,r.replaceWith(d,u,m);t.updateSelection&&Hd(r,r.steps.length-1,-1),t.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:m}),t.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:m})}return!0},Wd=()=>({state:n,dispatch:e})=>_c(n,e),jd=()=>({state:n,dispatch:e})=>Wc(n,e),qd=()=>({state:n,dispatch:e})=>Zs(n,e),Kd=()=>({state:n,dispatch:e})=>no(n,e),Jd=()=>({state:n,dispatch:e,tr:t})=>{try{const r=Kt(n.doc,n.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},Ud=()=>({state:n,dispatch:e,tr:t})=>{try{const r=Kt(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},Gd=()=>({state:n,dispatch:e})=>Hc(n,e),Yd=()=>({state:n,dispatch:e})=>Vc(n,e);function wo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Xd(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let r,i,s,o;for(let l=0;l({editor:e,view:t,tr:r,dispatch:i})=>{const s=Xd(n).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 d=c.map(r.mapping);d&&i&&r.maybeStep(d)}),!0};function Pt(n,e,t={}){const{from:r,to:i,empty:s}=n.selection,o=e?V(e,n.schema):null,l=[];n.doc.nodesBetween(r,i,(u,f)=>{if(u.isText)return;const p=Math.max(r,f),h=Math.min(i,f+u.nodeSize);l.push({node:u,from:p,to:h})});const a=i-r,c=l.filter(u=>o?o.name===u.node.type.name:!0).filter(u=>hn(u.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((u,f)=>u+f.to-f.from,0)>=a}const Qd=(n,e={})=>({state:t,dispatch:r})=>{const i=V(n,t.schema);return Pt(t,i,e)?jc(t,r):!1},eu=()=>({state:n,dispatch:e})=>oo(n,e),tu=n=>({state:e,dispatch:t})=>{const r=V(n,e.schema);return nd(r)(e,t)},nu=()=>({state:n,dispatch:e})=>io(n,e);function yn(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function To(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((r,i)=>(t.includes(i)||(r[i]=n[i]),r),{})}const ru=(n,e)=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null;const l=yn(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=V(n,r.schema)),l==="mark"&&(o=Le(n,r.schema)),i&&t.selection.ranges.forEach(a=>{r.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,d)=>{s&&s===c.type&&t.setNodeMarkup(d,void 0,To(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(u=>{o===u.type&&t.addMark(d,d+c.nodeSize,o.create(To(u.attrs,e)))})})}),!0):!1},iu=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),su=()=>({tr:n,dispatch:e})=>{if(e){const t=new ne(n.doc);n.setSelection(t)}return!0},ou=()=>({state:n,dispatch:e})=>eo(n,e),lu=()=>({state:n,dispatch:e})=>ro(n,e),au=()=>({state:n,dispatch:e})=>Uc(n,e),cu=()=>({state:n,dispatch:e})=>Xc(n,e),du=()=>({state:n,dispatch:e})=>Yc(n,e);function Sr(n,e,t={},r={}){return Dt(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:r.errorOnInvalidContent})}const uu=(n,e=!1,t={},r={})=>({editor:i,tr:s,dispatch:o,commands:l})=>{var a,c;const{doc:d}=s;if(t.preserveWhitespace!=="full"){const u=Sr(n,i.schema,t,{errorOnInvalidContent:(a=r.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});return o&&s.replaceWith(0,d.content.size,u).setMeta("preventUpdate",!e),!0}return o&&s.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:d.content.size},n,{parseOptions:t,errorOnInvalidContent:(c=r.errorOnInvalidContent)!==null&&c!==void 0?c:i.options.enableContentCheck})};function No(n,e){const t=Le(e,n.schema),{from:r,to:i,empty:s}=n.selection,o=[];s?(n.storedMarks&&o.push(...n.storedMarks),o.push(...n.selection.$head.marks())):n.doc.nodesBetween(r,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function fu(n){for(let e=0;e0;t-=1){const r=n.node(t);if(e(r))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:r}}}function Cr(n){return e=>pu(e.$from,n)}function hu(n,e){const t={from:0,to:n.content.size};return go(n,t,e)}function mu(n,e){const t=V(e,n.schema),{from:r,to:i}=n.selection,s=[];n.doc.nodesBetween(r,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function gu(n,e){const t=yn(typeof e=="string"?e:e.name,n.schema);return t==="node"?mu(n,e):t==="mark"?No(n,e):{}}function Oo(n,e,t){const r=[];return n===e?t.resolve(n).marks().forEach(i=>{const s=t.resolve(n),o=Mr(s,i.type);o&&r.push({mark:i,...o})}):t.nodesBetween(n,e,(i,s)=>{!i||(i==null?void 0:i.nodeSize)===void 0||r.push(...i.marks.map(o=>({from:s,to:s+i.nodeSize,mark:o})))}),r}function bn(n,e,t){return Object.fromEntries(Object.entries(t).filter(([r])=>{const i=n.find(s=>s.type===e&&s.name===r);return i?i.attribute.keepOnSplit:!1}))}function wr(n,e,t={}){const{empty:r,ranges:i}=n.selection,s=e?Le(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(u=>s?s.name===u.type.name:!0).find(u=>hn(u.attrs,t,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:u,$to:f})=>{const p=u.pos,h=f.pos;n.doc.nodesBetween(p,h,(m,g)=>{if(!m.isText&&!m.marks.length)return;const y=Math.max(p,g),x=Math.min(h,g+m.nodeSize),b=x-y;o+=b,l.push(...m.marks.map(M=>({mark:M,from:y,to:x})))})}),o===0)return!1;const a=l.filter(u=>s?s.name===u.mark.type.name:!0).filter(u=>hn(u.mark.attrs,t,{strict:!1})).reduce((u,f)=>u+f.to-f.from,0),c=l.filter(u=>s?u.mark.type!==s&&u.mark.type.excludes(s):!0).reduce((u,f)=>u+f.to-f.from,0);return(a>0?a+c:a)>=o}function yu(n,e,t={}){if(!e)return Pt(n,null,t)||wr(n,null,t);const r=yn(e,n.schema);return r==="node"?Pt(n,e,t):r==="mark"?wr(n,e,t):!1}function Eo(n,e){const{nodeExtensions:t}=an(e),r=t.find(o=>o.name===n);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},s=v(T(r,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function Tr(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var r;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((r=n.text)!==null&&r!==void 0?r:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let i=!0;return n.content.forEach(s=>{i!==!1&&(Tr(s,{ignoreWhitespace:t,checkChildren:e})||(i=!1))}),i}return!1}function bu(n){return n instanceof O}function xu(n,e,t){var r;const{selection:i}=e;let s=null;if(ko(i)&&(s=i.$cursor),s){const l=(r=n.storedMarks)!==null&&r!==void 0?r: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?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(d,u,f)=>{if(c)return!1;if(d.isInline){const p=!f||f.type.allowsMarkType(t),h=!!t.isInSet(d.marks)||!d.marks.some(m=>m.type.excludes(t));c=p&&h}return!c}),c})}const ku=(n,e={})=>({tr:t,state:r,dispatch:i})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=Le(n,r.schema);if(i)if(o){const c=No(r,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const d=c.$from.pos,u=c.$to.pos;r.doc.nodesBetween(d,u,(f,p)=>{const h=Math.max(p,d),m=Math.min(p+f.nodeSize,u);f.marks.find(y=>y.type===a)?f.marks.forEach(y=>{a===y.type&&t.addMark(h,m,a.create({...y.attrs,...e}))}):t.addMark(h,m,a.create(e))})});return xu(r,t,a)},Mu=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),Su=(n,e={})=>({state:t,dispatch:r,chain:i})=>{const s=V(n,t.schema);let o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),s.isTextblock?i().command(({commands:l})=>co(s,{...o,...e})(t)?!0:l.clearNodes()).command(({state:l})=>co(s,{...o,...e})(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Cu=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,i=Ye(n,0,r.content.size),s=O.create(r,i);e.setSelection(s)}return!0},wu=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,{from:i,to:s}=typeof n=="number"?{from:n,to:n}:n,o=E.atStart(r).from,l=E.atEnd(r).to,a=Ye(i,o,l),c=Ye(s,o,l),d=E.create(r,a,c);e.setSelection(d)}return!0},Tu=n=>({state:e,dispatch:t})=>{const r=V(n,e.schema);return sd(r)(e,t)};function Ao(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const r=t.filter(i=>e==null?void 0:e.includes(i.type.name));n.tr.ensureMarks(r)}}const Nu=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:r,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,d=bn(c,l.node().type.name,l.node().attrs);if(s instanceof O&&s.node.isBlock)return!l.parentOffset||!me(o,l.pos)?!1:(r&&(n&&Ao(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const u=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:fu(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=u&&f?[{type:f,attrs:d}]:void 0,h=me(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!h&&me(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(h=!0,p=f?[{type:f,attrs:d}]:void 0),r){if(h&&(s instanceof E&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,p),f&&!u&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}n&&Ao(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return h},Ou=(n,e={})=>({tr:t,state:r,dispatch:i,editor:s})=>{var o;const l=V(n,r.schema),{$from:a,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||a.depth<2||!a.sameParent(c))return!1;const u=a.node(-1);if(u.type!==l)return!1;const f=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(i){let y=k.empty;const x=a.index(-1)?1:a.index(-2)?2:3;for(let A=a.depth-x;A>=a.depth-3;A-=1)y=k.from(a.node(A).copy(y));const b=a.indexAfter(-1){if(w>-1)return!1;A.isTextblock&&A.content.size===0&&(w=D+1)}),w>-1&&t.setSelection(E.near(t.doc.resolve(w))),t.scrollIntoView()}return!0}const p=c.pos===a.end()?u.contentMatchAt(0).defaultType:null,h={...bn(f,u.type.name,u.attrs),...e},m={...bn(f,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,c.pos);const g=p?[{type:l,attrs:h},{type:p,attrs:m}]:[{type:l,attrs:h}];if(!me(t.doc,a.pos,2))return!1;if(i){const{selection:y,storedMarks:x}=r,{splittableMarks:b}=s.extensionManager,M=x||y.$to.parentOffset&&y.$from.marks();if(t.split(a.pos,2,g).scrollIntoView(),!M||!i)return!0;const S=M.filter(N=>b.includes(N.type.name));t.ensureMarks(S)}return!0},Nr=(n,e)=>{const t=Cr(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(r===void 0)return!0;const i=n.doc.nodeAt(r);return t.node.type===(i==null?void 0:i.type)&&we(n.doc,t.pos)&&n.join(t.pos),!0},Or=(n,e)=>{const t=Cr(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(t.start).after(t.depth);if(r===void 0)return!0;const i=n.doc.nodeAt(r);return t.node.type===(i==null?void 0:i.type)&&we(n.doc,r)&&n.join(r),!0};var Eu=Object.freeze({__proto__:null,blur:Sd,clearContent:Cd,clearNodes:wd,command:Td,createParagraphNear:Nd,cut:Od,deleteCurrentNode:Ed,deleteNode:Ad,deleteRange:Id,deleteSelection:vd,enter:Dd,exitCode:Pd,extendMarkRange:Rd,first:Ld,focus:zd,forEach:Fd,insertContent:$d,insertContentAt:_d,joinBackward:qd,joinDown:jd,joinForward:Kd,joinItemBackward:Jd,joinItemForward:Ud,joinTextblockBackward:Gd,joinTextblockForward:Yd,joinUp:Wd,keyboardShortcut:Zd,lift:Qd,liftEmptyBlock:eu,liftListItem:tu,newlineInCode:nu,resetAttributes:ru,scrollIntoView:iu,selectAll:su,selectNodeBackward:ou,selectNodeForward:lu,selectParentNode:au,selectTextblockEnd:cu,selectTextblockStart:du,setContent:uu,setMark:ku,setMeta:Mu,setNode:Su,setNodeSelection:Cu,setTextSelection:wu,sinkListItem:Tu,splitBlock:Nu,splitListItem:Ou,toggleList:(n,e,t,r={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:c,can:d})=>{const{extensions:u,splittableMarks:f}=i.extensionManager,p=V(n,o.schema),h=V(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:x}=m,b=y.blockRange(x),M=g||m.$to.parentOffset&&m.$from.marks();if(!b)return!1;const S=Cr(N=>Eo(N.type.name,u))(m);if(b.depth>=1&&S&&b.depth-S.depth<=1){if(S.node.type===p)return c.liftListItem(h);if(Eo(S.node.type.name,u)&&p.validContent(S.node.content)&&l)return a().command(()=>(s.setNodeMarkup(S.pos,p),!0)).command(()=>Nr(s,p)).command(()=>Or(s,p)).run()}return!t||!M||!l?a().command(()=>d().wrapInList(p,r)?!0:c.clearNodes()).wrapInList(p,r).command(()=>Nr(s,p)).command(()=>Or(s,p)).run():a().command(()=>{const N=d().wrapInList(p,r),w=M.filter(A=>f.includes(A.type.name));return s.ensureMarks(w),N?!0:c.clearNodes()}).wrapInList(p,r).command(()=>Nr(s,p)).command(()=>Or(s,p)).run()},toggleMark:(n,e={},t={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:s=!1}=t,o=Le(n,r.schema);return wr(r,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},toggleNode:(n,e,t={})=>({state:r,commands:i})=>{const s=V(n,r.schema),o=V(e,r.schema),l=Pt(r,s,t);let a;return r.selection.$anchor.sameParent(r.selection.$head)&&(a=r.selection.$anchor.parent.attrs),l?i.setNode(o,a):i.setNode(s,{...a,...t})},toggleWrap:(n,e={})=>({state:t,commands:r})=>{const i=V(n,t.schema);return Pt(t,i,e)?r.lift(i):r.wrapIn(i,e)},undoInputRule:()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let r=0;r=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,n.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},unsetAllMarks:()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:r,ranges:i}=t;return r||e&&i.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},unsetMark:(n,e={})=>({tr:t,state:r,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Le(n,r.schema),{$from:c,empty:d,ranges:u}=l;if(!i)return!0;if(d&&o){let{from:f,to:p}=l;const h=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=Mr(c,a,h);m&&(f=m.from,p=m.to),t.removeMark(f,p,a)}else u.forEach(f=>{t.removeMark(f.$from.pos,f.$to.pos,a)});return t.removeStoredMark(a),!0},updateAttributes:(n,e={})=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null;const l=yn(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=V(n,r.schema)),l==="mark"&&(o=Le(n,r.schema)),i&&t.selection.ranges.forEach(a=>{const c=a.$from.pos,d=a.$to.pos;let u,f,p,h;t.selection.empty?r.doc.nodesBetween(c,d,(m,g)=>{s&&s===m.type&&(p=Math.max(g,c),h=Math.min(g+m.nodeSize,d),u=g,f=m)}):r.doc.nodesBetween(c,d,(m,g)=>{g=c&&g<=d&&(s&&s===m.type&&t.setNodeMarkup(g,void 0,{...m.attrs,...e}),o&&m.marks.length&&m.marks.forEach(y=>{if(o===y.type){const x=Math.max(g,c),b=Math.min(g+m.nodeSize,d);t.addMark(x,b,o.create({...y.attrs,...e}))}}))}),f&&(u!==void 0&&t.setNodeMarkup(u,void 0,{...f.attrs,...e}),o&&f.marks.length&&f.marks.forEach(m=>{o===m.type&&t.addMark(p,h,o.create({...m.attrs,...e}))}))}),!0):!1},wrapIn:(n,e={})=>({state:t,dispatch:r})=>{const i=V(n,t.schema);return Zc(i,e)(t,r)},wrapInList:(n,e={})=>({state:t,dispatch:r})=>{const i=V(n,t.schema);return Qc(i,e)(t,r)}});const Au=Y.create({name:"commands",addCommands(){return{...Eu}}}),Iu=Y.create({name:"drop",addProseMirrorPlugins(){return[new X({key:new de("tiptapDrop"),props:{handleDrop:(n,e,t,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:r})}}})]}}),vu=Y.create({name:"editable",addProseMirrorPlugins(){return[new X({key:new de("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Du=new de("focusEvents"),Pu=Y.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new X({key:Du,props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const r=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,t)=>{n.isFocused=!1;const r=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),Ru=Y.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:d,$anchor:u}=a,{pos:f,parent:p}=u,h=u.parent.isTextblock&&f>0?l.doc.resolve(f-1):u,m=h.parent.type.spec.isolating,g=u.pos-u.parentOffset,y=m&&h.parent.childCount===1?g===u.pos:I.atStart(c).from===f;return!d||!p.type.isTextblock||p.textContent.length||!y||y&&u.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},s={...r,"Ctrl-h":n,"Alt-Backspace":n,"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 mn()||wo()?s:i},addProseMirrorPlugins(){return[new X({key:new de("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(m=>m.getMeta("composition")))return;const r=n.some(m=>m.docChanged)&&!e.doc.eq(t.doc),i=n.some(m=>m.getMeta("preventClearDocument"));if(!r||i)return;const{empty:s,from:o,to:l}=e.selection,a=I.atStart(e.doc).from,c=I.atEnd(e.doc).to;if(s||!(o===a&&l===c)||!Tr(t.doc))return;const f=t.tr,p=on({state:t,transaction:f}),{commands:h}=new ln({editor:this.editor,state:p});if(h.clearNodes(),!!f.steps.length)return f}})]}}),Lu=Y.create({name:"paste",addProseMirrorPlugins(){return[new X({key:new de("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),Bu=Y.create({name:"tabindex",addProseMirrorPlugins(){return[new X({key:new de("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Xe{get name(){return this.node.type.name}constructor(e,t,r=!1,i=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=t,this.currentNode=i}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,r=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:t,to:r},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new Xe(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new Xe(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new Xe(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,r)=>{const i=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,o=this.pos+r+(s?0:1);if(o<0||o>this.resolvedPos.doc.nodeSize-2)return;const l=this.resolvedPos.doc.resolve(o);if(!i&&l.depth<=this.depth)return;const a=new Xe(l,this.editor,i,i?t:null);i&&(a.actualDepth=this.depth+1),e.push(new Xe(l,this.editor,i,i?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let r=null,i=this.parent;for(;i&&!r;){if(i.node.type.name===e)if(Object.keys(t).length>0){const s=i.node.attrs,o=Object.keys(t);for(let l=0;l{r&&i.length>0||(o.node.type.name===e&&s.every(a=>t[a]===o.node.attrs[a])&&i.push(o),!(r&&i.length>0)&&(i=i.concat(o.querySelectorAll(e,t,r))))}),i}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}const zu=`.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: 0 !important; height: 0 !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 Fu(n,e,t){const r=document.querySelector("style[data-tiptap-style]");if(r!==null)return r;const i=document.createElement("style");return e&&i.setAttribute("nonce",e),i.setAttribute("data-tiptap-style",""),i.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(i),i}class $u extends od{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:t})=>{throw t},onPaste:()=>null,onDrop:()=>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.on("contentError",this.options.onContentError),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),this.on("drop",({event:t,slice:r,moved:i})=>this.options.onDrop(t,r,i)),this.on("paste",({event:t,slice:r})=>this.options.onPaste(t,r)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},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=Fu(zu,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,t=!0){this.setOptions({editable:e}),t&&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 r=fo(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let r=t;if([].concat(e).forEach(s=>{const o=typeof s=="string"?`${s}$`:s.key;r=r.filter(l=>!l.key.startsWith(o))}),t.length===r.length)return;const i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}createExtensionManager(){var e,t;const i=[...this.options.enableCoreExtensions?[vu,Md.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),Au,Pu,Ru,Bu,Iu,Lu].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s==null?void 0:s.type));this.extensionManager=new ut(i,this)}createCommandManager(){this.commandManager=new ln({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=Sr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(o){if(!(o instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(o.message))throw o;this.emit("contentError",{editor:this,error:o,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(l=>l.name!=="collaboration"),this.createExtensionManager()}}),t=Sr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=Mo(t,this.options.autofocus);this.view=new js(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...(e=this.options.editorProps)===null||e===void 0?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:rt.create({doc:t,selection:r||void 0})});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews(),this.prependClass();const s=this.view.dom;s.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;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),r=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),r&&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 gu(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,i=typeof e=="string"?t:e;return yu(this.state,r,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return xr(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=` `,textSerializers:r={}}=e||{};return hu(this.state.doc,{blockSeparator:t,textSerializers:{...yo(this.schema),...r}})}get isEmpty(){return Tr(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(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelector(e,t))||null}$nodes(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new Xe(t,this)}get $doc(){return this.$pos(0)}}function ft(n){return new cn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=v(n.getAttributes,void 0,r);if(i===!1||i===null)return null;const{tr:s}=e,o=r[r.length-1],l=r[0];if(o){const a=l.search(/\S/),c=t.from+l.indexOf(o),d=c+o.length;if(Oo(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(m=>m===n.type&&m!==p.mark.type)).filter(p=>p.to>c).length)return null;dt.from&&s.delete(t.from+a,c);const f=t.from+a+o.length;s.addMark(t.from+a,f,n.type.create(i||{})),s.removeStoredMark(n.type)}}})}function Hu(n){return new cn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=v(n.getAttributes,void 0,r)||{},{tr:s}=e,o=t.from;let l=t.to;const a=n.type.create(i);if(r[1]){const c=r[0].lastIndexOf(r[1]);let d=o+c;d>l?d=l:l=d+r[1].length;const u=r[0][r[0].length-1];s.insertText(u,o+r[0].length-1),s.replaceWith(d,l,a)}else if(r[0]){const c=n.type.isInline?o:o-1;s.insert(c,n.type.create(i)).delete(s.mapping.map(o),s.mapping.map(l))}s.scrollIntoView()}})}function Er(n){return new cn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=e.doc.resolve(t.from),s=v(n.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,s)}})}function Rt(n){return new cn({find:n.find,handler:({state:e,range:t,match:r,chain:i})=>{const s=v(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),a=o.doc.resolve(t.from).blockRange(),c=a&&Pn(a,n.type,s);if(!c)return null;if(o.wrap(a,c),n.keepMarks&&n.editor){const{selection:u,storedMarks:f}=e,{splittableMarks:p}=n.editor.extensionManager,h=f||u.$to.parentOffset&&u.$from.marks();if(h){const m=h.filter(g=>p.includes(g.type.name));o.ensureMarks(m)}}if(n.keepAttributes){const u=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";i().updateAttributes(u,s).run()}const d=o.doc.resolve(t.from-1).nodeBefore;d&&d.type===n.type&&we(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,d))&&o.join(t.from-1)}})}class K{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&&Object.keys(e.defaultOptions).length>0&&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=v(T(this,"addOptions",{name:this.name}))),this.storage=v(T(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new K(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>fn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new K(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(T(t,"addOptions",{name:t.name})),t.storage=v(T(t,"addStorage",{name:t.name,options:t.options})),t}}function pt(n){return new md({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:i})=>{const s=v(n.getAttributes,void 0,r,i);if(s===!1||s===null)return null;const{tr:o}=e,l=r[r.length-1],a=r[0];let c=t.to;if(l){const d=a.search(/\S/),u=t.from+a.indexOf(l),f=u+l.length;if(Oo(t.from,t.to,e.doc).filter(h=>h.mark.type.excluded.find(g=>g===n.type&&g!==h.mark.type)).filter(h=>h.to>u).length)return null;ft.from&&o.delete(t.from+d,u),c=t.from+d+l.length,o.addMark(t.from+d,c,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}function Vu(n,e){const{selection:t}=n,{$from:r}=t;if(t instanceof O){const s=r.index();return r.parent.canReplaceWith(s,s+1,e)}let i=r.depth;for(;i>=0;){const s=r.index(i);if(r.node(i).contentMatchAt(s).matchType(e))return!0;i-=1}return!1}const _u=/^\s*>\s$/,Wu=K.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setBlockquote:()=>({commands:n})=>n.wrapIn(this.name),toggleBlockquote:()=>({commands:n})=>n.toggleWrap(this.name),unsetBlockquote:()=>({commands:n})=>n.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[Rt({find:_u,type:this.type})]}}),ju=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,qu=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,Ku=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Ju=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,Io=Re.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return["strong",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[ft({find:ju,type:this.type}),ft({find:Ku,type:this.type})]},addPasteRules(){return[pt({find:qu,type:this.type}),pt({find:Ju,type:this.type})]}}),Uu="listItem",vo="textStyle",Do=/^\s*([-+*])\s$/,Gu=K.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:n}){return["ul",F(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleBulletList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Uu,this.editor.getAttributes(vo)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=Rt({find:Do,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=Rt({find:Do,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(vo),editor:this.editor})),[n]}}),Yu=/(^|[^`])`([^`]+)`(?!`)/,Xu=/(^|[^`])`([^`]+)`(?!`)/g,Zu=Re.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setCode:()=>({commands:n})=>n.setMark(this.name),toggleCode:()=>({commands:n})=>n.toggleMark(this.name),unsetCode:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[ft({find:Yu,type:this.type})]},addPasteRules(){return[pt({find:Xu,type:this.type})]}}),Qu=/^```([a-z]+)?[\s\n]$/,ef=/^~~~([a-z]+)?[\s\n]$/,tf=K.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:n=>{var e;const{languageClassPrefix:t}=this.options,s=[...((e=n.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(o=>o.startsWith(t)).map(o=>o.replace(t,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",F(this.options.HTMLAttributes,e),["code",{class:n.attrs.language?this.options.languageClassPrefix+n.attrs.language:null},0]]},addCommands(){return{setCodeBlock:n=>({commands:e})=>e.setNode(this.name,n),toggleCodeBlock:n=>({commands:e})=>e.toggleNode(this.name,"paragraph",n)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:n,$anchor:e}=this.editor.state.selection,t=e.pos===1;return!n||e.parent.type.name!==this.name?!1:t||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:n})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=n,{selection:t}=e,{$from:r,empty:i}=t;if(!i||r.parent.type!==this.type)return!1;const s=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` `);return!s||!o?!1:n.chain().command(({tr:l})=>(l.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:n})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=n,{selection:t,doc:r}=e,{$from:i,empty:s}=t;if(!s||i.parent.type!==this.type||!(i.parentOffset===i.parent.nodeSize-2))return!1;const l=i.after();return l===void 0?!1:r.nodeAt(l)?n.commands.command(({tr:c})=>(c.setSelection(I.near(r.resolve(l))),!0)):n.commands.exitCode()}}},addInputRules(){return[Er({find:Qu,type:this.type,getAttributes:n=>({language:n[1]})}),Er({find:ef,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new X({key:new de("codeBlockVSCodeHandler"),props:{handlePaste:(n,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const t=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=i==null?void 0:i.mode;if(!t||!s)return!1;const{tr:o,schema:l}=n.state,a=l.text(t.replace(/\r\n?/g,` `));return o.replaceSelectionWith(this.type.create({language:s},a)),o.selection.$from.parent.type!==this.type&&o.setSelection(E.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.setMeta("paste",!0),n.dispatch(o),!0}}})]}}),nf=K.create({name:"doc",topNode:!0,content:"block+"});function rf(n={}){return new X({view(e){return new sf(e,n)}})}class sf{constructor(e,t){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=t.width)!==null&&r!==void 0?r:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,r,i=this.editorView.dom,s=i.getBoundingClientRect(),o=s.width/i.offsetWidth,l=s.height/i.offsetHeight;if(t){let u=e.nodeBefore,f=e.nodeAfter;if(u||f){let p=this.editorView.nodeDOM(this.cursorPos-(u?u.nodeSize:0));if(p){let h=p.getBoundingClientRect(),m=u?h.bottom:h.top;u&&f&&(m=(m+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let g=this.width/2*l;r={left:h.left,right:h.right,top:m-g,bottom:m+g}}}}if(!r){let u=this.editorView.coordsAtPos(this.cursorPos),f=this.width/2*o;r={left:u.left-f,right:u.left+f,top:u.top,bottom:u.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let c,d;if(!a||a==document.body&&getComputedStyle(a).position=="static")c=-pageXOffset,d=-pageYOffset;else{let u=a.getBoundingClientRect(),f=u.width/a.offsetWidth,p=u.height/a.offsetHeight;c=u.left-a.scrollLeft*f,d=u.top-a.scrollTop*p}this.element.style.left=(r.left-c)/o+"px",this.element.style.top=(r.top-d)/l+"px",this.element.style.width=(r.right-r.left)/o+"px",this.element.style.height=(r.bottom-r.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Si(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const of=Y.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[rf(this.options)]}});class R extends I{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return R.valid(r)?new R(r):I.near(r)}content(){return C.empty}eq(e){return e instanceof R&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new R(e.resolve(t.pos))}getBookmark(){return new Ar(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!lf(e)||!af(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&R.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(R.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!O.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(R.valid(l))return l}return null}}}R.prototype.visible=!1,R.findFrom=R.findGapCursorFrom,I.jsonID("gapcursor",R);class Ar{constructor(e){this.pos=e}map(e){return new Ar(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return R.valid(t)?new R(t):I.near(t)}}function Po(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function lf(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||Po(i.type))return!0;if(i.inlineContent)return!1}}return!0}function af(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||Po(i.type))return!0;if(i.inlineContent)return!1}}return!0}function cf(){return new X({props:{decorations:pf,createSelectionBetween(n,e,t){return e.pos==t.pos&&R.valid(t)?new R(t):null},handleClick:uf,handleKeyDown:df,handleDOMEvents:{beforeinput:ff}}})}const df=Ys({ArrowLeft:xn("horiz",-1),ArrowRight:xn("horiz",1),ArrowUp:xn("vert",-1),ArrowDown:xn("vert",1)});function xn(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof E){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let c=R.findGapCursorFrom(l,e,a);return c?(i&&i(r.tr.setSelection(new R(c))),!0):!1}}function uf(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!R.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&O.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new R(r))),!0)}function ff(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof R))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=k.empty;for(let o=r.length-1;o>=0;o--)i=k.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new C(i,0,0));return s.setSelection(E.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function pf(n){if(!(n.selection instanceof R))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",z.create(n.doc,[le.widget(n.selection.head,e,{key:"gapcursor"})])}const hf=Y.create({name:"gapCursor",addProseMirrorPlugins(){return[cf()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=v(T(n,"allowGapCursor",t)))!==null&&e!==void 0?e:null}}}),mf=K.create({name:"hardBreak",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",F(this.options.HTMLAttributes,n)]},renderText(){return` `},addCommands(){return{setHardBreak:()=>({commands:n,chain:e,state:t,editor:r})=>n.first([()=>n.exitCode(),()=>n.command(()=>{const{selection:i,storedMarks:s}=t;if(i.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,a=s||i.$to.parentOffset&&i.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:d})=>{if(d&&a&&o){const u=a.filter(f=>l.includes(f.type.name));c.ensureMarks(u)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),gf=K.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(n=>({tag:`h${n}`,attrs:{level:n}}))},renderHTML({node:n,HTMLAttributes:e}){return[`h${this.options.levels.includes(n.attrs.level)?n.attrs.level:this.options.levels[0]}`,F(this.options.HTMLAttributes,e),0]},addCommands(){return{setHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.setNode(this.name,n):!1,toggleHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.toggleNode(this.name,"paragraph",n):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((n,e)=>({...n,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(n=>Er({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}});var kn=200,_=function(){};_.prototype.append=function(e){return e.length?(e=_.from(e),!this.length&&e||e.length=t?_.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},_.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},_.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)},_.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i},_.from=function(e){return e instanceof _?e:e&&e.length?new Ro(e):_.empty};var Ro=(function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=kn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=kn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(_);_.empty=new Ro([]);var yf=(function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e})(_);const bf=500;class ae{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],d=[];return this.items.forEach((u,f)=>{if(!u.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,d.push(u);return}if(i){d.push(new pe(u.map));let p=u.step.map(i.slice(s)),h;p&&o.maybeStep(p).doc&&(h=o.mapping.maps[o.mapping.maps.length-1],c.push(new pe(h,void 0,void 0,c.length+d.length))),s--,h&&i.appendMap(h,s)}else o.maybeStep(u.step);if(u.selection)return l=i?u.selection.map(i.slice(s)):u.selection,a=new ae(this.items.slice(0,r).append(d.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let d=0;dkf&&(l=xf(l,c),o-=c),new ae(l.append(s),o)}remapping(e,t){let r=new bt;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new ae(this.items.append(e.map(t=>new pe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let a=t;this.items.forEach(f=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let h=s.maps[p];if(f.step){let m=e.steps[p].invert(e.docs[p]),g=f.selection&&f.selection.map(s.slice(a+1,p));g&&l++,r.push(new pe(h,m,g))}else r.push(new pe(h))},i);let c=[];for(let f=t;fbf&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let d=o.selection&&o.selection.map(t.slice(r));d&&s++;let u=new pe(c.invert(),a,d),f,p=i.length-1;(f=i.length&&i[p].merge(u))?i[p]=f:i.push(u)}}else o.map&&r--},this.items.length,0),new ae(_.from(i.reverse()),s)}}ae.empty=new ae(_.empty,0);function xf(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}class pe{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new pe(t.getMap().invert(),t,this.selection)}}}class Be{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}}const kf=20;function Mf(n,e,t,r){let i=t.getMeta(Ze),s;if(i)return i.historyState;t.getMeta(wf)&&(n=new Be(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Ze))return o.getMeta(Ze).redo?new Be(n.done.addTransform(t,void 0,r,Mn(e)),n.undone,Lo(t.mapping.maps),n.prevTime,n.prevComposition):new Be(n.done,n.undone.addTransform(t,void 0,r,Mn(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Sf(t,n.prevRanges)),c=o?Ir(n.prevRanges,t.mapping):Lo(t.mapping.maps);return new Be(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,Mn(e)),ae.empty,c,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Be(n.done.rebased(t,s),n.undone.rebased(t,s),Ir(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Be(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Ir(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Sf(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function Lo(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,s,o)=>e.push(s,o));return e}function Ir(n,e){if(!n)return null;let t=[];for(let r=0;r{let i=Ze.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Cf(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}const Fo=zo(!1,!0),$o=zo(!0,!0),Nf=Y.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Fo(n,e),redo:()=>({state:n,dispatch:e})=>$o(n,e)}},addProseMirrorPlugins(){return[Tf(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Of=K.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",F(this.options.HTMLAttributes,n)]},addCommands(){return{setHorizontalRule:()=>({chain:n,state:e})=>{if(!Vu(e,e.schema.nodes[this.name]))return!1;const{selection:t}=e,{$from:r,$to:i}=t,s=n();return r.parentOffset===0?s.insertContentAt({from:Math.max(r.pos-1,0),to:i.pos},{type:this.name}):bu(t)?s.insertContentAt(i.pos,{type:this.name}):s.insertContent({type:this.name}),s.command(({tr:o,dispatch:l})=>{var a;if(l){const{$to:c}=o.selection,d=c.end();if(c.nodeAfter)c.nodeAfter.isTextblock?o.setSelection(E.create(o.doc,c.pos+1)):c.nodeAfter.isBlock?o.setSelection(O.create(o.doc,c.pos)):o.setSelection(E.create(o.doc,c.pos));else{const u=(a=c.parent.type.contentMatch.defaultType)===null||a===void 0?void 0:a.create();u&&(o.insert(d,u),o.setSelection(E.create(o.doc,d+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Hu({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Ef=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Af=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,If=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,vf=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Df=Re.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[ft({find:Ef,type:this.type}),ft({find:If,type:this.type})]},addPasteRules(){return[pt({find:Af,type:this.type}),pt({find:vf,type:this.type})]}}),Pf=K.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",F(this.options.HTMLAttributes,n),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)}}}),Rf="listItem",Ho="textStyle",Vo=/^(\d+)\.\s$/,Lf=K.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:n=>n.hasAttribute("start")?parseInt(n.getAttribute("start")||"",10):1},type:{default:null,parseHTML:n=>n.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:n}){const{start:e,...t}=n;return e===1?["ol",F(this.options.HTMLAttributes,t),0]:["ol",F(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleOrderedList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Rf,this.editor.getAttributes(Ho)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=Rt({find:Vo,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(n=Rt({find:Vo,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(Ho)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),Bf=K.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),zf=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Ff=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,$f=Re.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["s",F(this.options.HTMLAttributes,n),0]},addCommands(){return{setStrike:()=>({commands:n})=>n.setMark(this.name),toggleStrike:()=>({commands:n})=>n.toggleMark(this.name),unsetStrike:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[ft({find:zf,type:this.type})]},addPasteRules(){return[pt({find:Ff,type:this.type})]}}),Hf=K.create({name:"text",group:"inline"}),Vf=Y.create({name:"starterKit",addExtensions(){const n=[];return this.options.bold!==!1&&n.push(Io.configure(this.options.bold)),this.options.blockquote!==!1&&n.push(Wu.configure(this.options.blockquote)),this.options.bulletList!==!1&&n.push(Gu.configure(this.options.bulletList)),this.options.code!==!1&&n.push(Zu.configure(this.options.code)),this.options.codeBlock!==!1&&n.push(tf.configure(this.options.codeBlock)),this.options.document!==!1&&n.push(nf.configure(this.options.document)),this.options.dropcursor!==!1&&n.push(of.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&n.push(hf.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&n.push(mf.configure(this.options.hardBreak)),this.options.heading!==!1&&n.push(gf.configure(this.options.heading)),this.options.history!==!1&&n.push(Nf.configure(this.options.history)),this.options.horizontalRule!==!1&&n.push(Of.configure(this.options.horizontalRule)),this.options.italic!==!1&&n.push(Df.configure(this.options.italic)),this.options.listItem!==!1&&n.push(Pf.configure(this.options.listItem)),this.options.orderedList!==!1&&n.push(Lf.configure(this.options.orderedList)),this.options.paragraph!==!1&&n.push(Bf.configure(this.options.paragraph)),this.options.strike!==!1&&n.push($f.configure(this.options.strike)),this.options.text!==!1&&n.push(Hf.configure(this.options.text)),n}}),_o="cpfImage";function Dr(n){const e=n.fileName||n.alt||"图片",t=[];n.sizeText&&t.push(n.sizeText);const r=t.length?`(${t.join(",")})`:"";let i="";return n.price!=null&&Number(n.price)>0&&(i+=` ${Number(n.price)} 金币`),n.purchased&&(i+=" 已购买"),e+r+i}const _f=K.create({name:_o,group:"block",draggable:!0,addOptions(){return{uploadImage:null,basePath:"",onAssetPriceChange:null,openPriceModal:null}},addAttributes(){return{src:{required:!0,parseHTML:n=>n.getAttribute("src")||n.getAttribute("href")||"",renderHTML:n=>({src:n.src})},storage:{default:"/res/",parseHTML:n=>n.getAttribute("storage")||"/res/",renderHTML:n=>({storage:n.storage})},origin:{required:!0,parseHTML:n=>n.getAttribute("origin")||"",renderHTML:n=>({origin:n.origin})},local:{default:"1",parseHTML:n=>n.getAttribute("local")||"1",renderHTML:n=>({local:n.local})},alt:{default:"upload image",parseHTML:n=>n.getAttribute("alt")||"upload image",renderHTML:n=>({alt:n.alt})},class:{default:"lazy",parseHTML:n=>n.getAttribute("class")||"lazy",renderHTML:n=>({class:n.class})},dataOriginal:{default:null,parseHTML:n=>n.getAttribute("data-original")||n.getAttribute("src"),renderHTML:n=>n.dataOriginal?{"data-original":n.dataOriginal}:{}},style:{default:"display:block;",parseHTML:n=>n.getAttribute("style")||"display:block;",renderHTML:n=>({style:n.style})},price:{default:0,parseHTML:n=>Number(n.getAttribute("data-price"))||0,renderHTML:n=>({})},purchased:{default:!1,parseHTML:n=>n.getAttribute("data-purchased")==="true",renderHTML:()=>({})},fileName:{default:"",parseHTML:()=>"",renderHTML:()=>({})},sizeText:{default:"",parseHTML:()=>"",renderHTML:()=>({})},productId:{default:"",parseHTML:n=>n.getAttribute("data-product-id")||"",renderHTML:n=>n.productId?{"data-product-id":n.productId}:{}},mode:{default:"",parseHTML:n=>n.getAttribute("data-mode")||"",renderHTML:n=>n.mode?{"data-mode":n.mode}:{}},assetHref:{default:"",parseHTML:()=>"",renderHTML:()=>({})},assetOrigin:{default:"",parseHTML:()=>"",renderHTML:()=>({})}}},parseHTML(){return[{tag:"img[origin]"},{tag:'a.post-attachment[data-asset="image"]',getAttrs:n=>{const e=n.getAttribute("href"),t=n.getAttribute("data-origin")||"";if(!e)return!1;const r=n.querySelector("span"),i=r?r.textContent:"";return{src:e,origin:t||"images/pasted",storage:"/res/",local:"1",alt:"upload image",class:"lazy",dataOriginal:e,style:"display:block;",price:Number(n.getAttribute("data-price"))||0,purchased:n.getAttribute("data-purchased")==="true",fileName:i||"图片"}}}]},renderHTML({node:n,HTMLAttributes:e}){const t=Number(n.attrs.price)||0,r=!!n.attrs.purchased,i=n.attrs.mode||"";if(t>0||r||i==="reply"){const o=n.attrs.productId?"#":n.attrs.src||"#",l=Dr(n.attrs),a={href:o,class:"post-attachment post-attachment--image","data-asset":"image",...n.attrs.origin&&!n.attrs.productId?{"data-origin":n.attrs.origin}:{},"data-price":String(t),"data-purchased":r?"true":"false",...n.attrs.productId?{"data-product-id":n.attrs.productId}:{},...i?{"data-mode":i}:{},target:"_blank",rel:"nofollow noopener noreferrer"};return["a",F(a),["i",{class:"ri-attachment-2","aria-hidden":"true"}],["span",{},l]]}const s={...e,src:n.attrs.src,storage:n.attrs.storage||"/res/",origin:n.attrs.origin,local:n.attrs.local||"1",alt:n.attrs.alt||"upload image",class:n.attrs.class||"lazy","data-original":n.attrs.dataOriginal||n.attrs.src,style:n.attrs.style||"display:block;"};return["img",F(s)]},addNodeView(){return({node:n,getPos:e,editor:t})=>{const{onAssetPriceChange:r,openPriceModal:i}=this.options;let s=n;const o=document.createElement("div");o.className="cpf-asset cpf-asset--image";const l=document.createElement("span");l.className="cpf-asset__type",l.innerHTML='';const a=document.createElement("div");a.className="cpf-asset__body";const c=document.createElement("div");c.className="cpf-asset__controls";const d=document.createElement("button");d.type="button",d.className="cpf-asset__price-btn";const u=document.createElement("button");u.type="button",u.className="cpf-asset__price-btn",u.textContent="回复可见",o.appendChild(l),o.appendChild(a),c.appendChild(d),c.appendChild(u),o.appendChild(c);function f(m){s=m,a.innerHTML="";const g=Number(m.attrs.price)||0,y=!!m.attrs.purchased,x=m.attrs.mode||"",b=g>0||x==="paid"||y,M=!b&&x==="reply";if(b||M){const S=m.attrs.src||"#",N=Dr(m.attrs),w=document.createElement("a");w.href=S,w.className="post-attachment post-attachment--image",w.setAttribute("data-asset","image"),w.setAttribute("data-origin",m.attrs.origin||""),w.setAttribute("data-price",String(g)),w.setAttribute("data-purchased",y?"true":"false"),w.setAttribute("target","_blank"),w.setAttribute("rel","nofollow noopener noreferrer");const A=document.createElement("i");A.className="ri-attachment-2",A.setAttribute("aria-hidden","true");const D=document.createElement("span");D.textContent=N,w.appendChild(A),w.appendChild(D),a.appendChild(w),w.addEventListener("click",he=>{he.preventDefault()})}else{const S=document.createElement("img");S.setAttribute("src",m.attrs.src||""),S.setAttribute("storage",m.attrs.storage||"/res/"),S.setAttribute("origin",m.attrs.origin||""),S.setAttribute("local",m.attrs.local||"1"),S.setAttribute("alt",m.attrs.alt||"upload image"),S.className=m.attrs.class||"lazy",S.setAttribute("data-original",m.attrs.dataOriginal||m.attrs.src||""),S.setAttribute("style",m.attrs.style||"display:block;"),a.appendChild(S)}b?(d.textContent="修改价格",u.textContent="改为回复可见"):M?(d.textContent="改为付费",u.textContent="取消回复可见"):(d.textContent="设置价格",u.textContent="回复可见")}function p(m){const g=typeof e=="function"?e():e;if(typeof g!="number")return;const{state:y,view:x}=t,b=y.doc.nodeAt(g);if(!b||b.type.name!==_o)return;const M=y.tr.setNodeMarkup(g,b.type,m);x.dispatch(M),t.commands.focus()}function h(){const m=typeof i=="function"?i:null;if(!m){p({...s.attrs});return}m({type:"image",currentPrice:Number(s.attrs.price)||0,label:Dr(s.attrs)}).then(g=>{if(!g)return;const y=g.price,x=s.attrs.mode||"";let b={...s.attrs,price:y,mode:y>0?"paid":x==="reply"?"reply":""};const M=b.assetHref||(b.src&&b.src!=="#"?b.src:""),S={mode:b.mode||"",href:M,origin:b.origin||"",price:y,productId:b.productId||""};typeof r=="function"?Promise.resolve(r("image",{payload:S,price:y,productId:b.productId||""})).then(N=>{N&&N.productId&&(b={...b,productId:String(N.productId),src:"#",dataOriginal:""})}).finally(()=>p(b)):p(b)})}return d.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),h()}),u.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation();const g=Number(s.attrs.price)||0,y=s.attrs.mode||"";let x;!y&&g===0?x={...s.attrs,price:0,mode:"reply"}:y==="reply"?x={...s.attrs,price:0,mode:""}:x={...s.attrs,price:0,mode:"reply"};const b=x.assetHref||(x.src&&x.src!=="#"?x.src:""),M={mode:x.mode||"",href:b,origin:x.origin||"",price:x.price||0,productId:x.productId||""};typeof r=="function"?Promise.resolve(r("image",{payload:M,price:x.price||0,productId:x.productId||""})).then(S=>{S&&S.productId&&(x={...x,productId:String(S.productId)})}).finally(()=>p(x)):p(x)}),f(s),{dom:o,update(m){return m.type.name!==s.type.name?!1:(f(m),!0)},ignoreMutation(){return!0},stopEvent(m){return c.contains(m.target)}}}}}),Wo="cpfAttachment";function Pr(n){if(n.label)return n.label;const e=n.fileName||"附件",t=[];n.typeLabel&&t.push(n.typeLabel),n.sizeText&&t.push(n.sizeText);const r=t.length?`(${t.join(",")})`:"";let i="";return n.price!=null&&Number(n.price)>0&&(i+=` ${Number(n.price)} 金币`),n.purchased&&(i+=" 已购买"),e+r+i}const Wf=K.create({name:Wo,group:"inline",inline:!0,atom:!0,addOptions(){return{uploadFile:null,basePath:"",onAssetPriceChange:null,openPriceModal:null}},addAttributes(){return{href:{required:!0,parseHTML:n=>n.getAttribute("href")||"",renderHTML:n=>({href:n.href})},fileName:{default:"附件",parseHTML:()=>"",renderHTML:()=>({})},typeLabel:{default:"",parseHTML:()=>"",renderHTML:()=>({})},sizeText:{default:"",parseHTML:()=>"",renderHTML:()=>({})},price:{default:0,parseHTML:n=>Number(n.getAttribute("data-price"))||0,renderHTML:n=>({"data-price":String(n.price??0)})},purchased:{default:!1,parseHTML:n=>n.getAttribute("data-purchased")==="true",renderHTML:n=>({"data-purchased":n.purchased?"true":"false"})},productId:{default:"",parseHTML:n=>n.getAttribute("data-product-id")||"",renderHTML:n=>n.productId?{"data-product-id":n.productId}:{}},label:{default:"",parseHTML:n=>n.querySelector("span")&&n.querySelector("span").textContent||"",renderHTML:()=>({})},mode:{default:"",parseHTML:n=>n.getAttribute("data-mode")||"",renderHTML:n=>n.mode?{"data-mode":n.mode}:{}},assetHref:{default:"",parseHTML:()=>"",renderHTML:()=>({})},assetOrigin:{default:"",parseHTML:()=>"",renderHTML:()=>({})}}},parseHTML(){return[{tag:"a.post-attachment"}]},renderHTML({node:n,HTMLAttributes:e}){const t=Pr(n.attrs),r={...e,href:n.attrs.href,class:"post-attachment","data-price":String(n.attrs.price??0),"data-purchased":n.attrs.purchased?"true":"false",...n.attrs.productId?{"data-product-id":n.attrs.productId}:{},...n.attrs.mode?{"data-mode":n.attrs.mode}:{},target:"_blank",rel:"nofollow noopener noreferrer"};return["a",F(r),["i",{class:"ri-attachment-2","aria-hidden":"true"}],["span",{},t]]},addNodeView(){return({node:n,getPos:e,editor:t})=>{const{onAssetPriceChange:r,openPriceModal:i}=this.options;let s=n;const o=document.createElement("div");o.className="cpf-asset cpf-asset--attachment";const l=document.createElement("span");l.className="cpf-asset__type",l.innerHTML='';const a=document.createElement("div");a.className="cpf-asset__body";const c=document.createElement("div");c.className="cpf-asset__controls";const d=document.createElement("button");d.type="button",d.className="cpf-asset__price-btn";const u=document.createElement("button");u.type="button",u.className="cpf-asset__price-btn",u.textContent="回复可见",o.appendChild(l),o.appendChild(a),c.appendChild(d),c.appendChild(u),o.appendChild(c);function f(m){s=m;const g=Pr(m.attrs);a.innerHTML="";const y=document.createElement("a");y.href=m.attrs.href||"#",y.className="post-attachment",y.setAttribute("target","_blank"),y.setAttribute("rel","nofollow noopener noreferrer"),y.setAttribute("data-price",String(m.attrs.price??0)),y.setAttribute("data-purchased",m.attrs.purchased?"true":"false");const x=document.createElement("i");x.className="ri-attachment-2",x.setAttribute("aria-hidden","true");const b=document.createElement("span");b.textContent=g,y.appendChild(x),y.appendChild(b),a.appendChild(y),y.addEventListener("click",A=>{A.preventDefault()});const M=Number(m.attrs.price)||0,S=m.attrs.mode||"",N=M>0||S==="paid";N?(d.textContent="修改价格",u.textContent="改为回复可见"):!N&&S==="reply"?(d.textContent="改为付费",u.textContent="取消回复可见"):(d.textContent="设置价格",u.textContent="回复可见")}function p(m){const g=typeof e=="function"?e():e;if(typeof g!="number")return;const{state:y,view:x}=t,b=y.doc.nodeAt(g);if(!b||b.type.name!==Wo)return;const M=y.tr.setNodeMarkup(g,b.type,m);x.dispatch(M),t.commands.focus()}function h(){const m=typeof i=="function"?i:null;if(!m){p({...s.attrs});return}m({type:"file",currentPrice:Number(s.attrs.price)??0,label:Pr(s.attrs)}).then(g=>{if(!g)return;const y=g.price,x=s.attrs.mode||"";let b={...s.attrs,price:y,mode:y>0?"paid":x==="reply"?"reply":""};const M=b.assetHref||(b.href&&b.href!=="#"?b.href:""),S={mode:b.mode||"",href:M,origin:b.assetOrigin||"",price:y,productId:b.productId||""};typeof r=="function"?Promise.resolve(r("file",{payload:S,price:y,productId:b.productId||""})).then(N=>{N&&N.productId&&(b={...b,productId:String(N.productId),href:"#"})}).finally(()=>p(b)):p(b)})}return d.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),h()}),u.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation();const g=Number(s.attrs.price)??0,y=s.attrs.mode||"";let x;!y&&g===0?x={...s.attrs,price:0,mode:"reply"}:y==="reply"?x={...s.attrs,price:0,mode:""}:x={...s.attrs,price:0,mode:"reply"};const b=x.assetHref||(x.href&&x.href!=="#"?x.href:""),M={mode:x.mode||"",href:b,origin:x.assetOrigin||"",price:x.price||0,productId:x.productId||""};typeof r=="function"?Promise.resolve(r("file",{payload:M,price:x.price||0,productId:x.productId||""})).then(S=>{S&&S.productId&&(x={...x,productId:String(S.productId),href:"#"})}).finally(()=>p(x)):p(x)}),f(s),{dom:o,update(m){return m.type.name!==s.type.name?!1:(f(m),!0)},ignoreMutation(){return!0},stopEvent(m){return c.contains(m.target)}}}}}),Rr="cpfPaidTextBlock";function jo(n){const e=Number(n.price)||0;return e>0?`付费可见 ${e} 金币`:"回复后可见"}const jf=K.create({name:Rr,group:"block",addOptions(){return{onAssetPriceChange:null,openPriceModal:null}},addAttributes(){return{content:{default:"",parseHTML:n=>n.getAttribute("data-content")||"",renderHTML:n=>n.content!=null?{"data-content":n.content}:{}},price:{default:0,parseHTML:n=>{const e=n.getAttribute("data-price");return e!=null&&Number(e)||0},renderHTML:n=>{const e=Number(n.price)||0;return{"data-price":String(e)}}},productId:{default:"",parseHTML:n=>n.getAttribute("data-product-id")||"",renderHTML:n=>n.productId?{"data-product-id":n.productId}:{}},mode:{default:"reply",parseHTML:n=>n.getAttribute("data-mode")||"reply",renderHTML:n=>n.mode?{"data-mode":n.mode}:{}}}},parseHTML(){return[{tag:"div.cpf-paid-text-block"}]},renderHTML({node:n,HTMLAttributes:e}){const t=jo(n.attrs),r={class:"cpf-paid-text-block post-attachment","data-price":String(n.attrs.price??0),"data-product-id":n.attrs.productId||"","data-mode":n.attrs.mode||"reply"},i=n.attrs.productId?{}:{"data-content":n.attrs.content||""};return["div",F(e,r,i),["i",{class:"ri-file-text-line","aria-hidden":"true"}],["span",{},t]]},addNodeView(){return({node:n,getPos:e,editor:t})=>{const{onAssetPriceChange:r,openPriceModal:i}=this.options;let s=n;const o=document.createElement("div");o.className="cpf-asset cpf-asset--text";const l=document.createElement("span");l.className="cpf-asset__type",l.innerHTML='';const a=document.createElement("div");a.className="cpf-asset__body";const c=document.createElement("div");c.className="cpf-asset__controls";const d=document.createElement("button");d.type="button",d.className="cpf-asset__price-btn";const u=document.createElement("button");u.type="button",u.className="cpf-asset__price-btn",u.textContent="取消回复可见",o.appendChild(l),o.appendChild(a),c.appendChild(d),c.appendChild(u),o.appendChild(c);function f(){const g=typeof e=="function"?e():e;if(typeof g!="number")return;const{state:y,view:x}=t,b=y.doc.nodeAt(g);if(!b||b.type.name!==Rr)return;const M=String(b.attrs.content||""),S=y.tr.replaceWith(g,g+b.nodeSize,M?y.schema.text(M):null);x.dispatch(S),t.commands.focus()}function p(g){s=g,a.innerHTML="";const y=jo(g.attrs),x=document.createElement("span");x.className="cpf-paid-text-block__label",x.textContent=y,a.appendChild(x);const M=(Number(g.attrs.price)||0)===0;d.textContent=M?"改为付费":"修改价格",u.textContent=M?"取消回复可见":"改为回复可见",u.style.display=""}function h(g){const y=typeof e=="function"?e():e;if(typeof y!="number")return;const{state:x,view:b}=t,M=x.doc.nodeAt(y);if(!M||M.type.name!==Rr)return;const S=x.tr.setNodeMarkup(y,M.type,g);b.dispatch(S),t.commands.focus()}function m(){const g=typeof i=="function"?i:null;if(!g){h({...s.attrs});return}const y=s.attrs.content||"";g({type:"text",currentPrice:Number(s.attrs.price)||0,textPreview:y}).then(x=>{if(!x)return;const b=x.price;let M={...s.attrs,price:b,mode:b>0?"paid":"reply"};const S={mode:M.mode||"",text:y,price:b,productId:M.productId||""};typeof r=="function"?Promise.resolve(r("text",{payload:S,price:b,productId:M.productId||""})).then(N=>{N&&N.productId&&(M={...M,productId:String(N.productId)})}).finally(()=>h(M)):h(M)})}return d.addEventListener("click",g=>{g.preventDefault(),g.stopPropagation(),m()}),u.addEventListener("click",g=>{if(g.preventDefault(),g.stopPropagation(),(Number(s.attrs.price)||0)===0){f();return}let x={...s.attrs,price:0,mode:"reply"};const b=s.attrs.content||"",M={mode:x.mode||"",text:b,price:0,productId:x.productId||""};typeof r=="function"?Promise.resolve(r("text",{payload:M,price:0,productId:x.productId||""})).then(S=>{S&&S.productId&&(x={...x,productId:String(S.productId)})}).finally(()=>h(x)):h(x)}),p(s),{dom:o,update(g){return g.type.name!==s.type.name?!1:(p(g),!0)},ignoreMutation(){return!0},stopEvent(g){return c.contains(g.target)}}}}}),qf=["src","storage","origin","local","alt","class","data-original","style"],Lr=/!\[([^\]]*)\]\((https?:\/\/[^\s)]+)\)/g,Sn=/\*\*([^*]+)\*\*/g;function Kf(n){const e=[];function t(r){if(!r)return;if(r.nodeType===3){const s=(r.textContent||"").replace(/\u00a0/g," ");s&&e.push({type:"text",value:s});return}if(r.nodeType!==1)return;if((r.tagName||"").toUpperCase()==="IMG"){const s=r.getAttribute("src")||"";if(!s)return;const o={src:s};if(qf.forEach(l=>{const a=r.getAttribute(l);a!=null&&(o[l]=a)}),!o.origin&&s)try{const a=new URL(s,"https://x").pathname||"",c=a.split("/").filter(Boolean);o.origin=c.length?c.slice(-2).join("/"):a.replace(/^\//,"")||"images/pasted"}catch{o.origin="images/pasted"}e.push({type:"image",attrs:o});return}for(let s=0;s0&&r.push(n.nodes.hardBreak.create()),t[i]&&r.push(n.text(t[i]));return n.node("paragraph",null,r)}function Uf(n,e){const t=String(e||""),r=[],i=n.marks.bold;let s=0,o;for(Sn.lastIndex=0;o=Sn.exec(t);){const[a,c]=o,d=t.slice(s,o.index);if(d&&r.push(n.text(d)),c){const u=i?[i.create()]:[];r.push(n.text(c,u))}else r.push(n.text(a));s=o.index+a.length}const l=t.slice(s);return l&&r.push(n.text(l)),r}function Ko(n,e){const t=String(e||"").split(/\r?\n\s*\r?\n/g).map(r=>r.trim()).filter(Boolean);return t.length===0?[]:t.map(r=>{const i=r.split(/\r\n|\r|\n/),s=[];for(let o=0;o0&&s.push(n.nodes.hardBreak.create());const l=Uf(n,i[o]);l.length&&s.push(...l)}return n.node("paragraph",null,s)})}function Gf(n){if(!n)return"images/pasted";try{const t=new URL(n,"https://x").pathname||"",r=t.split("/").filter(Boolean);return r.length?r.slice(-2).join("/"):t.replace(/^\//,"")||"images/pasted"}catch{return"images/pasted"}}function Jo(n,e){const t=n.nodes.cpfImage;return!t||!(e!=null&&e.src)?null:t.create({src:e.src,storage:e.storage||"/res/",origin:e.origin||Gf(e.src),local:e.local||"1",alt:e.alt||"upload image",class:e.class||"lazy",dataOriginal:e["data-original"]||e.src,style:e.style||"display:block;"})}function Yf(n,e){const t=String(e||""),r=Lr.test(t),i=Sn.test(t),s=/\r?\n\s*\r?\n/.test(t);if(!r&&!i&&!s)return null;Lr.lastIndex=0,Sn.lastIndex=0;const o=[];let l=0,a;for(;a=Lr.exec(t);){const[d,u,f]=a,p=t.slice(l,a.index);p&&o.push(...Ko(n,p));const h=Jo(n,{src:f,alt:u||"upload image"});h&&o.push(h),l=a.index+d.length}const c=t.slice(l);return c&&o.push(...Ko(n,c)),o.length===0?null:new C(k.from(o),0,0)}function Xf(n,e){const t=document.createElement("div");t.innerHTML=e||"";const r=Kf(t),i=[];for(const s of r)if(s.type==="text")i.push(qo(n,s.value));else if(s.type==="image"){const o=Jo(n,s.attrs);o&&i.push(o)}return i.length===0?null:new C(k.from(i),0,0)}const Zf=Y.create({name:"pasteWhitelist",addProseMirrorPlugins(){const e=this.editor.schema;return[new X({props:{handlePaste(t,r){var o,l,a,c;const i=(l=(o=r.clipboardData)==null?void 0:o.getData)==null?void 0:l.call(o,"text/html"),s=(c=(a=r.clipboardData)==null?void 0:a.getData)==null?void 0:c.call(a,"text/plain");if(i&&Jf(i))try{const d=Xf(e,i);if(d&&d.content.size)return r.preventDefault(),t.dispatch(t.state.tr.replaceSelection(d)),!0}catch{}if(s!=null&&s!==""){const d=Yf(e,s);if(d&&d.content.size)return r.preventDefault(),t.dispatch(t.state.tr.replaceSelection(d)),!0;r.preventDefault();const u=qo(e,String(s)),f=new C(k.from(u),0,0);return t.dispatch(t.state.tr.replaceSelection(f)),!0}return!1}}})]}});function Qf(n){const e=document.createElement("div");e.className="cpf-price-modal-overlay",e.style.cssText=` position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.45); `;const t=document.createElement("div");t.className="cpf-price-modal",t.style.cssText=` min-width: 280px; max-width: 90vw; padding: 16px 20px; background: #fff; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); `;const r=document.createElement("div");r.className="cpf-price-modal__title",r.style.cssText="font-size: 15px; font-weight: 600; margin-bottom: 12px;",r.textContent="设置价格";const i=document.createElement("div");i.className="cpf-price-modal__preview",i.style.cssText="font-size: 12px; color: #6b7280; margin-bottom: 10px; max-height: 60px; overflow: auto; word-break: break-all;";const s=document.createElement("div");s.className="cpf-price-modal__row",s.style.cssText="display: flex; align-items: center; gap: 8px; margin-bottom: 16px;";const o=document.createElement("label");o.style.cssText="font-size: 13px; white-space: nowrap;",o.textContent="金币";const l=document.createElement("input");l.type="number",l.min="0",l.step="1",l.placeholder="0",l.className="cpf-price-modal__input",l.style.cssText=` flex: 1; padding: 6px 10px; font-size: 14px; border: 1px solid #d1d5db; border-radius: 4px; box-sizing: border-box; `,s.appendChild(o),s.appendChild(l);const a=document.createElement("div");a.className="cpf-price-modal__actions",a.style.cssText="display: flex; justify-content: flex-end; gap: 8px;";const c=document.createElement("button");c.type="button",c.textContent="取消",c.className="cpf-price-modal__btn cpf-price-modal__btn--cancel",c.style.cssText=` padding: 6px 14px; font-size: 13px; border: 1px solid #d1d5db; border-radius: 4px; background: #fff; cursor: pointer; `;const d=document.createElement("button");d.type="button",d.textContent="确定",d.className="cpf-price-modal__btn cpf-price-modal__btn--submit",d.style.cssText=` padding: 6px 14px; font-size: 13px; border: none; border-radius: 4px; background: #2563eb; color: #fff; cursor: pointer; `,a.appendChild(c),a.appendChild(d),t.appendChild(r),t.appendChild(i),t.appendChild(s),t.appendChild(a),e.appendChild(t),n.appendChild(e);let u=null;function f(){e.style.display="none",e.onclick=null,u=null}function p(h){const{type:m="image",currentPrice:g=0,label:y="",textPreview:x=""}=h||{};return r.textContent=g>0?"修改价格":"设置价格",l.value=g>0?String(g):"",m==="text"&&x?(i.style.display="block",i.textContent="内容预览:"+(x.length>80?x.slice(0,80)+"…":x)):y?(i.style.display="block",i.textContent=y):i.style.display="none",e.style.display="flex",l.focus(),new Promise(b=>{u=N=>{u=null,b(N)};const M=()=>{const N=String(l.value||"").trim(),w=N===""?0:Math.max(0,parseInt(N,10)||0);u({price:w}),f()},S=()=>{u(null),f()};e.onclick=N=>{N.target===e&&S()},c.onclick=S,d.onclick=M,l.onkeydown=N=>{N.key==="Enter"&&M(),N.key==="Escape"&&S()}})}return{openPriceModal:p,destroy(){c.onclick=null,d.onclick=null,l.onkeydown=null,e.parentNode&&e.parentNode.removeChild(e)}}}function Uo(n){if(!n||typeof n!="string")return"";let e=n.trim().replace(/^\/+/,"");const t=e.indexOf("?");return t>=0&&(e=e.slice(0,t)),e.toLowerCase().startsWith("res/")&&(e=e.slice(4)),e}function Go(n,e,t=""){const r=n&&typeof n=="string"?n.trim():"";if(r&&(/\/\//.test(r)||r.startsWith("http")))return r;const i=e&&typeof e=="string"?e.trim():"";if(!i)return"";const s=i.startsWith("/")?i:`/${i}`,o=t&&typeof t=="string"?t.trim().replace(/\/+$/,""):"";return typeof window<"u"&&window.location&&window.location.origin?`${window.location.origin}${o?`/${o.replace(/^\//,"")}`:""}${s}`.replace(/([^:]\/)\/+/g,"$1"):`${o}${s}`.replace(/([^:]\/)\/+/g,"$1")}function ep(n,e="post-image"){const t=typeof n=="string"?n.trim():"";if(!t||t==="#")return t;try{const r=new URL(t,typeof window<"u"&&window.location&&window.location.origin?window.location.origin:"https://example.invalid");return r.searchParams.has("w")||r.searchParams.set("w",e),r.toString()}catch{return/[?&]w=/.test(t)?t:`${t}${t.includes("?")?"&":"?"}w=${e}`}}function Yo(n){const e=Number(n);if(!Number.isFinite(e)||e<=0)return"";const t=e/1024;return t<1024?`${t.toFixed(1).replace(/\.0$/,"")} KB`:`${(t/1024).toFixed(1).replace(/\.0$/,"")} MB`}function tp(n){return!n||typeof n!="string"?"":n.replace(/^\./,"").toUpperCase()}const np="publish-editor-toolbar",Xo="publish-editor";function rp(n){const e=n.features||{},t=[Vf.configure({blockquote:!1,bulletList:!1,codeBlock:!1,heading:!1,horizontalRule:!1,listItem:!1,orderedList:!1}),Zf];return e.bold!==!1&&t.push(Io),t.push(jf.configure({onAssetPriceChange:n.onAssetPriceChange,openPriceModal:n.openPriceModal})),e.image!==!1&&t.push(_f.configure({uploadImage:n.uploadImage,basePath:n.basePath??"",onAssetPriceChange:n.onAssetPriceChange,openPriceModal:n.openPriceModal})),e.attachment!==!1&&t.push(Wf.configure({uploadFile:n.uploadFile,basePath:n.basePath??"",onAssetPriceChange:n.onAssetPriceChange,openPriceModal:n.openPriceModal})),t}function ip(n,e,t){const r=e.features||{},i=document.createElement("div");if(i.className=np,r.image!==!1){const s=document.createElement("button");s.type="button",s.className="cpf-editor-btn",s.innerHTML='插入图片',s.addEventListener("click",()=>sp(t,e)),i.appendChild(s)}if(r.attachment!==!1){const s=document.createElement("button");s.type="button",s.className="cpf-editor-btn",s.innerHTML='插入附件',s.addEventListener("click",()=>op(t,e)),i.appendChild(s)}n.appendChild(i)}function sp(n,e){const t=e.uploadImage;if(typeof t!="function")return;const r=document.createElement("input");r.type="file",r.accept="image/*",r.onchange=async()=>{const i=r.files&&r.files[0];if(r.value="",!(!i||!n.current))try{const s=await t(i),o=s&&(s.data||s),l=o&&o.path||"",a=o&&o.cdnUrl||"",c=e.basePath??"",d=Uo(l),u=ep(Go(a,l,c)||"#"),f=o&&o.ext_data||o&&o.extData||{},p=o&&o.price!=null?Number(o.price):0,h=!!(o&&o.purchased),m=Yo(f.size),g=f.oriName||i.name||"图片";n.current.chain().focus().insertContent({type:"cpfImage",attrs:{src:u,origin:d,storage:"/res/",local:"1",alt:"upload image",class:"lazy",dataOriginal:u,style:"display:block;",price:p,purchased:h,fileName:g,sizeText:m,assetHref:u,assetOrigin:d}}).run()}catch(s){typeof e.onUploadError=="function"&&e.onUploadError(s,"image")}},r.click()}function op(n,e){const t=e.uploadFile;if(typeof t!="function")return;const r=document.createElement("input");r.type="file",r.onchange=async()=>{const i=r.files&&r.files[0];if(r.value="",!(!i||!n.current))try{const s=await t(i),o=s&&(s.data||s),l=o&&o.path||"",a=o&&o.cdnUrl||"",c=e.basePath??"",d=Go(a,l,c)||"#",u=o&&o.ext_data||o&&o.extData||{},f=u.oriName||i.name||"附件",p=Yo(u.size),h=tp(u.ext),m=o&&o.price!=null?Number(o.price):0,g=!!(o&&o.purchased);n.current.chain().focus().insertContent({type:"cpfAttachment",attrs:{href:d,fileName:f,typeLabel:h,sizeText:p,price:m,purchased:g,assetHref:d,assetOrigin:Uo(l)}}).run()}catch(s){typeof e.onUploadError=="function"&&e.onUploadError(s,"file")}},r.click()}function Zo(n){const e=typeof n.el=="string"?document.querySelector(n.el):n.el;if(!e)throw new Error("CpfEditor: options.el is required and must be a selector or element.");const t={change:[]},r={current:null},i=document.createElement("div");i.className="cpf-editor",e.innerHTML="",e.appendChild(i);const s=document.createElement("style");s.textContent=` .cpf-editor { position: relative; } .cpf-editor .publish-editor img { max-width: min(400px, 85%); width: auto; height: auto; display: block; } .cpf-editor__header { position: relative; } .cpf-asset { position: relative; margin: 6px 0; padding: 8px 10px; border-radius: 6px; background: var(--cpf-asset-bg, #f0f2f5); box-sizing: border-box; } .cpf-asset__type { display: inline-block; margin-bottom: 4px; color: #6b7280; } .cpf-asset__type i { font-size: 14px; } .cpf-asset__body { margin-bottom: 6px; } .cpf-asset__controls { display: inline-flex; align-items: center; gap: 6px; } .cpf-asset__price-btn { font-size: 12px; padding: 3px 10px; border-radius: 4px; border: 1px solid #ddd; background: #fff; cursor: pointer; } .cpf-selection-menu { position: absolute; z-index: 20; display: inline-flex; gap: 4px; padding: 4px 6px; border-radius: 4px; background: rgba(17, 24, 39, 0.92); color: #fff; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); font-size: 12px; } .cpf-selection-menu button { padding: 2px 6px; border-radius: 3px; border: none; background: transparent; color: inherit; cursor: pointer; white-space: nowrap; } .cpf-selection-menu button:hover { background: rgba(255, 255, 255, 0.12); } .cpf-asset--text .cpf-paid-text-block__label { font-size: 13px; color: #374151; } `,i.appendChild(s);const o=document.createElement("div");o.className="cpf-editor__header",ip(o,n,r),i.appendChild(o);const l=document.createElement("div");l.className=Xo,i.appendChild(l);const a=Qf(i),c={...n,openPriceModal:a.openPriceModal},d=new $u({element:l,extensions:rp(c),content:n.initialContent??"",editorProps:{attributes:{class:Xo,"data-placeholder":n.placeholder??"请输入正文内容"}},onUpdate:({editor:b})=>{t.change.forEach(M=>M(b.getHTML()))}});r.current=d;const u=document.createElement("div");u.className="cpf-selection-menu",u.style.display="none";const f=document.createElement("span");f.className="cpf-selection-menu__hint",f.textContent="二选一",f.style.cssText="font-size: 11px; color: rgba(255,255,255,0.75); align-self: center; margin-right: 4px;";const p=document.createElement("button");p.type="button",p.textContent="回复后可见";const h=document.createElement("button");h.type="button",h.textContent="付费可见",u.appendChild(f),u.appendChild(p),u.appendChild(h),i.appendChild(u);function m(){u.style.display="none"}function g(){const b=d.state.selection;if(!b||b.empty||b instanceof O){m();return}const{from:M,to:S}=b,N=d.view,w=N.coordsAtPos(M),A=N.coordsAtPos(S),D={left:(w.left+A.left)/2,top:Math.min(w.top,A.top)},he=i.getBoundingClientRect();u.style.display="inline-flex",u.style.position="absolute";const Cn=u.getBoundingClientRect(),Lt=D.top-he.top-Cn.height-8,ap=D.left-he.left-Cn.width/2;u.style.top=`${Math.max(Lt,0)}px`,u.style.left=`${Math.max(ap,0)}px`}d.on("selectionUpdate",()=>{const b=d.state.selection;!b||b.empty||b instanceof O?m():g()}),document.addEventListener("click",b=>{i.contains(b.target)||m()});function y(){const{state:b,view:M}=d,{from:S,to:N}=b.selection;if(S===N)return"";const w=window.getSelection&&window.getSelection();if(w&&w.rangeCount>0){const D=w.getRangeAt(0);if(M.dom.contains(D.commonAncestorContainer))return D.toString()||""}return b.doc.textBetween(S,N," ")||""}function x(b,M){const{from:S,to:N}=M||d.state.selection;S==null||N==null||S===N||d.chain().focus().deleteRange({from:S,to:N}).insertContentAt(S,{type:"cpfPaidTextBlock",attrs:b}).run()}return p.addEventListener("click",b=>{b.preventDefault(),b.stopPropagation();const M=d.state.selection;if(!M||M.empty||M instanceof O)return;const S=y();if(!S)return;const N={from:M.from,to:M.to};x({content:S,price:0,productId:"",mode:"reply"},N),m()}),h.addEventListener("click",b=>{b.preventDefault(),b.stopPropagation();const M=d.state.selection;if(!M||M.empty||M instanceof O)return;const S=y();if(!S)return;const N={from:M.from,to:M.to};a.openPriceModal({type:"text",currentPrice:0,textPreview:S}).then(w=>{if(!w){m();return}const A=w.price,D=n.onAssetPriceChange,he={content:S,price:A,productId:"",mode:"paid"};if(typeof D=="function"){const Cn={mode:"paid",text:S,price:A};Promise.resolve(D("text",{payload:Cn,price:A,productId:""})).then(Lt=>{Lt&&Lt.productId&&(he.productId=String(Lt.productId))}).finally(()=>{x(he,N),m()})}else x(he,N),m()})}),{getHTML:()=>d.getHTML(),setHTML:b=>d.commands.setContent(b??"",!1),on(b,M){b==="change"&&typeof M=="function"&&t.change.push(M)},destroy(){a.destroy(),d.destroy(),r.current=null,i.parentNode&&i.parentNode.removeChild(i)}}}function lp(n){const e=Zo(n);return{getHTML:()=>e.getHTML(),setHTML:t=>e.setHTML(t),on:(t,r)=>e.on(t,r),destroy:()=>e.destroy()}}ze.create=lp,ze.createEditor=Zo,Object.defineProperty(ze,Symbol.toStringTag,{value:"Module"})})); //# sourceMappingURL=cpf-editor.umd.cjs.map