import{r as V,j as de,a as Ya,R as it,b as Qa}from"./vendor-react.js?v=1775123024591";import{V as Os,W as Za,X as ec,Y as tc,Z as nc,$ as fo,a0 as po,a1 as Rs,a2 as rc,a3 as sc,a4 as mo,a5 as ic}from"./vendor-common.js?v=1775123024591";function go(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let s=t.child(r),i=e.child(r);if(s==i){n+=s.nodeSize;continue}if(!s.sameMarkup(i))return n;if(s.isText&&s.text!=i.text){for(let o=0;s.text[o]==i.text[o];o++)n++;return n}if(s.content.size||i.content.size){let o=go(s.content,i.content,n+1);if(o!=null)return o}n+=s.nodeSize}}function yo(t,e,n,r){for(let s=t.childCount,i=e.childCount;;){if(s==0||i==0)return s==i?null:{a:n,b:r};let o=t.child(--s),l=e.child(--i),a=o.nodeSize;if(o==l){n-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:n,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,s+l,i||null,o)!==!1&&a.content.size){let d=l+1;a.nodesBetween(Math.max(0,e-d),Math.min(a.content.size,n-d),r,s+d)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,s){let i="",o=!0;return this.nodesBetween(e,n,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,n-a):l.isLeaf?s?typeof s=="function"?s(l):s:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:i+=r),i+=c},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,s=this.content.slice(),i=0;for(n.isText&&n.sameMarkup(r)&&(s[s.length-1]=n.withText(n.text+r.text),i=1);ie)for(let i=0,o=0;oe&&((on)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,n-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,n-o-1))),r.push(l),s+=l.nodeSize),o=a}return new b(r,s)}cutByIndex(e,n){return e==n?b.empty:e==0&&n==this.content.length?this:new b(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let s=this.content.slice(),i=this.size+n.nodeSize-r.nodeSize;return s[e]=n,new b(s,i)}addToStart(e){return new b([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new b(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let s=this.child(n),i=r+s.nodeSize;if(i>=e)return i==e?tn(n+1,i):tn(n,r);r=i}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return b.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new b(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return b.empty;let n,r=0;for(let s=0;sthis.type.rank&&(n||(n=e.slice(0,s)),n.push(this),r=!0),n&&n.push(i)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-s.type.rank),n}};P.none=[];class Sn extends Error{}class x{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=ko(this.content,e+this.openStart,n);return r&&new x(r,this.openStart,this.openEnd)}removeBetween(e,n){return new x(bo(this.content,e+this.openStart,n+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,n){if(!n)return x.empty;let r=n.openStart||0,s=n.openEnd||0;if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(b.fromJSON(e,n.content),r,s)}static maxOpen(e,n=!0){let r=0,s=0;for(let i=e.firstChild;i&&!i.isLeaf&&(n||!i.type.spec.isolating);i=i.firstChild)r++;for(let i=e.lastChild;i&&!i.isLeaf&&(n||!i.type.spec.isolating);i=i.lastChild)s++;return new x(e,r,s)}}x.empty=new x(b.empty,0,0);function bo(t,e,n){let{index:r,offset:s}=t.findIndex(e),i=t.maybeChild(r),{index:o,offset:l}=t.findIndex(n);if(s==e||i.isText){if(l!=n&&!t.child(o).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(r,i.copy(bo(i.content,e-s-1,n-s-1)))}function ko(t,e,n,r){let{index:s,offset:i}=t.findIndex(e),o=t.maybeChild(s);if(i==e||o.isText)return r&&!r.canReplace(s,s,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=ko(o.content,e-i-1,n,o);return l&&t.replaceChild(s,o.copy(l))}function oc(t,e,n){if(n.openStart>t.depth)throw new Sn("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Sn("Inconsistent open depths");return wo(t,e,n,0)}function wo(t,e,n,r){let s=t.index(r),i=t.node(r);if(s==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Lt(t,e,n,r){let s=(e||t).node(n),i=0,o=e?e.index(n):s.childCount;t&&(i=t.index(n),t.depth>n?i++:t.textOffset&&(et(t.nodeAfter,r),i++));for(let l=i;ls&&kr(t,e,s+1),o=r.depth>s&&kr(n,r,s+1),l=[];return Lt(null,t,s,l),i&&o&&e.index(s)==n.index(s)?(xo(i,o),et(tt(i,So(t,e,n,r,s+1)),l)):(i&&et(tt(i,Cn(t,e,s+1)),l),Lt(e,n,s,l),o&&et(tt(o,Cn(n,r,s+1)),l)),Lt(r,null,s,l),new b(l)}function Cn(t,e,n){let r=[];if(Lt(null,t,n,r),t.depth>n){let s=kr(t,e,n+1);et(tt(s,Cn(t,e,n+1)),r)}return Lt(e,null,n,r),new b(r)}function lc(t,e){let n=e.depth-t.openStart,s=e.node(n).copy(t.content);for(let i=n-1;i>=0;i--)s=e.node(i).copy(b.from(s));return{start:s.resolveNoCache(t.openStart+n),end:s.resolveNoCache(s.content.size-t.openEnd-n)}}class Ht{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.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,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],s=e.child(n);return r?e.child(n).cut(r):s}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],s=n==0?0:this.path[n*3-1]+1;for(let i=0;i0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Mn(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&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],s=0,i=n;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(i),c=i-a;if(r.push(o,l,s+a),!c||(o=o.child(l),o.isText))break;i=c-1,s+=a+1}return new Ht(n,r,i)}static resolveCached(e,n){let r=Ds.get(e);if(r)for(let i=0;ie&&this.nodesBetween(e,n,i=>(r.isInSet(i.marks)&&(s=!0),!s)),s}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()+")"),Co(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=b.empty,s=0,i=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,s,i),l=o&&o.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let a=s;an.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n 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(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let s=b.fromJSON(e,n.content),i=e.nodeType(n.type).create(n.attrs,s,r);return i.type.checkAttrs(i.attrs),i}}ge.prototype.text=void 0;class vn extends ge{constructor(e,n,r,s){if(super(e,n,null,s),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Co(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new vn(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new vn(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Co(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class ot{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new uc(e,n);if(r.next==null)return ot.empty;let s=Mo(r);r.next&&r.err("Unexpected trailing text");let i=bc(yc(s));return kc(i,r),i}matchType(e){for(let n=0;nc.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 n(r){e.push(r);for(let s=0;s{let i=s+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return i}).join(` `)}}ot.empty=new ot(!0);class uc{constructor(e,n){this.string=e,this.nodeTypes=n,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 Mo(t){let e=[];do e.push(hc(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function hc(t){let e=[];do e.push(fc(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function fc(t){let e=gc(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=pc(t,e);else break;return e}function Is(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function pc(t,e){let n=Is(t),r=n;return t.eat(",")&&(t.next!="}"?r=Is(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function mc(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let s=[];for(let i in n){let o=n[i];o.isInGroup(e)&&s.push(o)}return s.length==0&&t.err("No node type or group '"+e+"' found"),s}function gc(t){if(t.eat("(")){let e=Mo(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=mc(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function yc(t){let e=[[]];return s(i(t,0),n()),e;function n(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function s(o,l){o.forEach(a=>a.to=l)}function i(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(i(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=i(o.exprs[a],l);if(a==o.exprs.length-1)return c;s(c,l=n())}else if(o.type=="star"){let a=n();return r(l,a),s(i(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=n();return s(i(o.expr,l),a),s(i(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(i(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{t[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let d=0;d{c||s.push([l,c=[]]),c.indexOf(d)==-1&&c.push(d)})})});let i=e[r.join(",")]=new ot(r.indexOf(t.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:Eo(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ge(this,this.computeAttrs(e),b.from(n),P.setFrom(r))}createChecked(e=null,n,r){return n=b.from(n),this.checkContent(n),new ge(this,this.computeAttrs(e),n,P.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=b.from(n),n.size){let o=this.contentMatch.fillBefore(n);if(!o)return null;n=o.append(n)}let s=this.contentMatch.matchFragment(n),i=s&&s.fillBefore(b.empty,!0);return i?new ge(this,e,n.append(i),P.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[i]=new Oo(i,n,o));let s=n.spec.topNode||"doc";if(!r[s])throw new RangeError("Schema is missing its top node type ('"+s+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let i in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function wc(t,e,n){let r=n.split("|");return s=>{let i=s===null?"null":typeof s;if(r.indexOf(i)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${i}`)}}class xc{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?wc(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Pn{constructor(e,n,r,s){this.name=e,this.rank=n,this.schema=r,this.spec=s,this.attrs=No(e,s.attrs),this.excluded=null;let i=To(this.attrs);this.instance=i?new P(this,i):null}create(e=null){return!e&&this.instance?this.instance:new P(this,Eo(this.attrs,e))}static compile(e,n){let r=Object.create(null),s=0;return e.forEach((i,o)=>r[i]=new Pn(i,s++,n,o)),r}removeFromSet(e){for(var n=0;n-1}}class Ro{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let s in e)n[s]=e[s];n.nodes=Os.from(e.nodes),n.marks=Os.from(e.marks||{}),this.nodes=Ls.compile(this.spec.nodes,this),this.marks=Pn.compile(this.spec.marks,this);let r=Object.create(null);for(let s in this.nodes){if(s in this.marks)throw new RangeError(s+" can not be both a node and a mark");let i=this.nodes[s],o=i.spec.content||"",l=i.spec.marks;if(i.contentMatch=r[o]||(r[o]=ot.parse(o,this.nodes)),i.inlineContent=i.contentMatch.inlineContent,i.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!i.isInline||!i.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=i}i.markSet=l=="_"?null:l?zs(this,l.split(" ")):l==""||!i.inlineContent?[]:null}for(let s in this.marks){let i=this.marks[s],o=i.spec.excludes;i.excluded=o==null?[i]:o==""?[]:zs(this,o.split(" "))}this.nodeFromJSON=s=>ge.fromJSON(this,s),this.markFromJSON=s=>P.fromJSON(this,s),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,s){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ls){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(n,r,s)}text(e,n){let r=this.nodes.text;return new vn(r,r.defaultAttrs,e,P.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function zs(t,e){let n=[];for(let r=0;r-1)&&n.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function Sc(t){return t.tag!=null}function Cc(t){return t.style!=null}class Ne{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(s=>{if(Sc(s))this.tags.push(s);else if(Cc(s)){let i=/[^=]*/.exec(s.style)[0];r.indexOf(i)<0&&r.push(i),this.styles.push(s)}}),this.normalizeLists=!this.tags.some(s=>{if(!/^(ul|ol)\b/.test(s.tag)||!s.node)return!1;let i=e.nodes[s.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new $s(this,n,!1);return r.addAll(e,P.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new $s(this,n,!0);return r.addAll(e,P.none,n.from,n.to),x.maxOpen(r.finish())}matchTag(e,n,r){for(let s=r?this.tags.indexOf(r)+1:0;se.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(o.getAttrs){let a=o.getAttrs(n);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let n=[];function r(s){let i=s.priority==null?50:s.priority,o=0;for(;o{r(o=Hs(o)),o.mark||o.ignore||o.clearMark||(o.mark=s)})}for(let s in e.nodes){let i=e.nodes[s].spec.parseDOM;i&&i.forEach(o=>{r(o=Hs(o)),o.node||o.ignore||o.mark||(o.node=s)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Ne(e,Ne.schemaRules(e)))}}const Do={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},Mc={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Io={ol:!0,ul:!0},Ft=1,wr=2,zt=4;function Bs(t,e,n){return e!=null?(e?Ft:0)|(e==="full"?wr:0):t&&t.whitespace=="pre"?Ft|wr:n&~zt}class nn{constructor(e,n,r,s,i,o){this.type=e,this.attrs=n,this.marks=r,this.solid=s,this.options=o,this.content=[],this.activeMarks=P.none,this.match=i||(o&zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(b.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,s;return(s=r.findWrapping(e.type))?(this.match=r,s):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ft)){let r=this.content[this.content.length-1],s;if(r&&r.isText&&(s=/[ \t\r\n\u000c]+$/.exec(r.text))){let i=r;r.text.length==s[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-s[0].length))}}let n=b.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(b.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Do.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class $s{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let s=n.topNode,i,o=Bs(null,n.preserveWhitespace,0)|(r?zt:0);s?i=new nn(s.type,s.attrs,P.none,!0,n.topMatch||s.type.contentMatch,o):r?i=new nn(null,null,P.none,!0,null,o):i=new nn(e.schema.topNodeType,null,P.none,!0,null,o),this.nodes=[i],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,s=this.top,i=s.options&wr?"full":this.localPreserveWS||(s.options&Ft)>0,{schema:o}=this.parser;if(i==="full"||s.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i)if(i==="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)):n=n.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return n}addElementByRule(e,n,r,s){let i,o;if(n.node)if(o=this.parser.schema.nodes[n.node],o.isLeaf)this.insertNode(o.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let a=this.enter(o,n.attrs||null,r,n.preserveWhitespace);a&&(i=!0,r=a)}else{let a=this.parser.schema.marks[n.mark];r=r.concat(a.create(n.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(s)this.addElement(e,r,s);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r,!1));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}i&&this.sync(l)&&this.open--}addAll(e,n,r,s){let i=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=s==null?null:e.childNodes[s];o!=l;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o,n);this.findAtPoint(e,i)}findPlace(e,n,r){let s,i;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!s||s.length>c.length+l)&&(s=c,i=a,!c.length))break;if(a.solid){if(r)break;l+=2}}if(!s)return null;this.sync(i);for(let o=0;o(o.type?o.type.allowsMarkType(c.type):Fs(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new nn(e,n,a,s,null,l)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].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 n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=Ft)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let s=r.length-1;s>=0;s--)e+=r[s].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,s=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),i=-(r?r.depth+1:0)+(s?0:1),o=(l,a)=>{for(;l>=0;l--){let c=n[l];if(c==""){if(l==n.length-1||l==0)continue;for(;a>=i;a--)if(o(l-1,a))return!0;return!1}else{let d=a>0||a==0&&s?this.nodes[a].type:r&&a>=i?r.node(a-i).type:null;if(!d||d.name!=c&&!d.isInGroup(c))return!1;a--}}return!0};return o(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function vc(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Io.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Tc(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Hs(t){let e={};for(let n in t)e[n]=t[n];return e}function Fs(t,e){let n=e.schema.nodes;for(let r in n){let s=n[r];if(!s.allowsMarkType(t))continue;let i=[],o=l=>{i.push(l);for(let a=0;a{if(i.length||o.marks.length){let l=0,a=0;for(;l=0;s--){let i=this.serializeMark(e.marks[s],e.isInline,n);i&&((i.contentDOM||i.dom).appendChild(r),r=i.dom)}return r}serializeMark(e,n,r={}){let s=this.marks[e.type.name];return s&&mn(Qn(r),s(e,n),null,e.attrs)}static renderSpec(e,n,r=null,s){return mn(e,n,r,s)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new ft(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Vs(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Vs(e.marks)}}function Vs(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Qn(t){return t.document||window.document}const _s=new WeakMap;function Ec(t){let e=_s.get(t);return e===void 0&&_s.set(t,e=Ac(t)),e}function Ac(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let s=0;s-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=s.indexOf(" ");o>0&&(n=s.slice(0,o),s=s.slice(o+1));let l,a=n?t.createElementNS(n,s):t.createElement(s),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 h=u.indexOf(" ");h>0?a.setAttributeNS(u.slice(0,h),u.slice(h+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:f,contentDOM:p}=mn(t,h,n,r);if(a.appendChild(f),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Po=65535,Lo=Math.pow(2,16);function Nc(t,e){return t+e*Lo}function Ws(t){return t&Po}function Oc(t){return(t-(t&Po))/Lo}const zo=1,Bo=2,gn=4,$o=8;class xr{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&$o)>0}get deletedBefore(){return(this.delInfo&(zo|gn))>0}get deletedAfter(){return(this.delInfo&(Bo|gn))>0}get deletedAcross(){return(this.delInfo&gn)>0}}class ie{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ie.empty)return ie.empty}recover(e){let n=0,r=Ws(e);if(!this.inverted)for(let s=0;se)break;let c=this.ranges[l+i],d=this.ranges[l+o],u=a+c;if(e<=u){let h=c?e==a?-1:e==u?1:n:n,f=a+s+(h<0?0:d);if(r)return f;let p=e==(n<0?a:u)?null:Nc(l/3,e-a),m=e==a?Bo:e==u?zo:gn;return(n<0?e!=a:e!=u)&&(m|=$o),new xr(f,m,p)}s+=d-c}return r?e+s:new xr(e+s,0,null)}touches(e,n){let r=0,s=Ws(n),i=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+i],d=a+c;if(e<=d&&l==s*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let s=0,i=0;s=0;n--){let s=e.getMirror(n);this.appendMap(e._maps[n].invert(),s!=null&&s>n?r-s-1:void 0)}}invert(){let e=new Vt;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ri&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),s),n.openStart,n.openEnd);return j.fromReplace(e,this.from,this.to,i)}invert(){return new me(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new He(n.pos,r.pos,this.mark)}merge(e){return e instanceof He&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new He(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,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new He(n.from,n.to,e.markFromJSON(n.mark))}}te.jsonID("addMark",He);class me extends te{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new x(Ur(n.content,s=>s.mark(this.mark.removeFromSet(s.marks)),e),n.openStart,n.openEnd);return j.fromReplace(e,this.from,this.to,r)}invert(){return new He(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new me(n.pos,r.pos,this.mark)}merge(e){return e instanceof me&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new me(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,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new me(n.from,n.to,e.markFromJSON(n.mark))}}te.jsonID("removeMark",me);class Fe extends te{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return j.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return j.fromReplace(e,this.pos,this.pos+1,new x(b.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let s=0;sr.pos?null:new J(n.pos,r.pos,s,i,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,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new J(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}}te.jsonID("replaceAround",J);function Sr(t,e,n){let r=t.resolve(e),s=n-e,i=r.depth;for(;s>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,s--;if(s>0){let o=r.node(i).maybeChild(r.indexAfter(i));for(;s>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,s--}}return!1}function Rc(t,e,n,r){let s=[],i=[],o,l;t.doc.nodesBetween(e,n,(a,c,d)=>{if(!a.isInline)return;let u=a.marks;if(!r.isInSet(u)&&d.type.allowsMarkType(r.type)){let h=Math.max(c,e),f=Math.min(c+a.nodeSize,n),p=r.addToSet(u);for(let m=0;mt.step(a)),i.forEach(a=>t.step(a))}function Dc(t,e,n,r){let s=[],i=0;t.doc.nodesBetween(e,n,(o,l)=>{if(!o.isInline)return;i++;let a=null;if(r instanceof Pn){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,n);for(let d=0;dt.step(new me(o.from,o.to,o.style)))}function Jr(t,e,n,r=n.contentMatch,s=!0){let i=t.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)t.step(o[a])}function Ic(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function At(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,s=0,i=0;;--r){let o=t.$from.node(r),l=t.$from.index(r)+s,a=t.$to.indexAfter(r)-i;if(rn;p--)m||r.index(p)>0?(m=!0,d=b.from(r.node(p).copy(d)),u++):a--;let h=b.empty,f=0;for(let p=i,m=!1;p>n;p--)m||s.after(p+1)=0;o--){if(r.size){let l=n[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=b.from(n[o].type.create(n[o].attrs,r))}let s=e.start,i=e.end;t.step(new J(s,i,s,i,new x(r,0,0),n.length,!0))}function $c(t,e,n,r,s){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=t.steps.length;t.doc.nodesBetween(e,n,(o,l)=>{let a=typeof s=="function"?s(o):s;if(o.isTextblock&&!o.hasMarkup(r,a)&&Hc(t.doc,t.mapping.slice(i).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let f=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);f&&!p?c=!1:!f&&p&&(c=!0)}c===!1&&Fo(t,o,l,i),Jr(t,t.mapping.slice(i).map(l,1),r,void 0,c===null);let d=t.mapping.slice(i),u=d.map(l,1),h=d.map(l+o.nodeSize,1);return t.step(new J(u,h,u+1,h-1,new x(b.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Ho(t,o,l,i),!1}})}function Ho(t,e,n,r){e.forEach((s,i)=>{if(s.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(s.text);){let a=t.mapping.slice(r).map(n+1+i+o.index);t.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Fo(t,e,n,r){e.forEach((s,i)=>{if(s.type==s.type.schema.linebreakReplacement){let o=t.mapping.slice(r).map(n+1+i);t.replaceWith(o,o+1,e.type.schema.text(` `))}})}function Hc(t,e,n){let r=t.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,n)}function Fc(t,e,n,r,s){let i=t.doc.nodeAt(e);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let o=n.create(r,null,s||i.marks);if(i.isLeaf)return t.replaceWith(e,e+i.nodeSize,o);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new J(e,e+i.nodeSize,e+1,e+i.nodeSize-1,new x(b.from(o),0,0),1,!0))}function Oe(t,e,n=1,r){let s=t.resolve(e),i=s.depth-n,o=r&&r[r.length-1]||s.parent;if(i<0||s.parent.type.spec.isolating||!s.parent.canReplace(s.index(),s.parent.childCount)||!o.type.validContent(s.parent.content.cutByIndex(s.index(),s.parent.childCount)))return!1;for(let c=s.depth-1,d=n-2;c>i;c--,d--){let u=s.node(c),h=s.index(c);if(u.type.spec.isolating)return!1;let f=u.content.cutByIndex(h,u.childCount),p=r&&r[d+1];p&&(f=f.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[d]||u;if(!u.canReplace(h+1,u.childCount)||!m.type.validContent(f))return!1}let l=s.indexAfter(i),a=r&&r[0];return s.node(i).canReplaceWith(l,l,a?a.type:s.node(i+1).type)}function Vc(t,e,n=1,r){let s=t.doc.resolve(e),i=b.empty,o=b.empty;for(let l=s.depth,a=s.depth-n,c=n-1;l>a;l--,c--){i=b.from(s.node(l).copy(i));let d=r&&r[c];o=b.from(d?d.type.create(d.attrs,o):s.node(l).copy(o))}t.step(new K(e,e,new x(i.append(o),n,n),!0))}function Ue(t,e){let n=t.resolve(e),r=n.index();return Vo(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function _c(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let s=0;s0?(i=r.node(s+1),l++,o=r.node(s).maybeChild(l)):(i=r.node(s).maybeChild(l-1),o=r.node(s+1)),i&&!i.isTextblock&&Vo(i,o)&&r.node(s).canReplace(l,l+1))return e;if(s==0)break;e=n<0?r.before(s):r.after(s)}}function Wc(t,e,n){let r=null,{linebreakReplacement:s}=t.doc.type.schema,i=t.doc.resolve(e-n),o=i.node().type;if(s&&o.inlineContent){let d=o.whitespace=="pre",u=!!o.contentMatch.matchType(s);d&&!u?r=!1:!d&&u&&(r=!0)}let l=t.steps.length;if(r===!1){let d=t.doc.resolve(e+n);Fo(t,d.node(),d.before(),l)}o.inlineContent&&Jr(t,e+n-1,o,i.node().contentMatchAt(i.index()),r==null);let a=t.mapping.slice(l),c=a.map(e-n);if(t.step(new K(c,a.map(e+n,-1),x.empty,!0)),r===!0){let d=t.doc.resolve(c);Ho(t,d.node(),d.before(),t.steps.length)}return t}function jc(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let s=r.depth-1;s>=0;s--){let i=r.index(s);if(r.node(s).canReplaceWith(i,i,n))return r.before(s+1);if(i>0)return null}if(r.parentOffset==r.parent.content.size)for(let s=r.depth-1;s>=0;s--){let i=r.indexAfter(s);if(r.node(s).canReplaceWith(i,i,n))return r.after(s+1);if(i=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(i==1)d=c.canReplace(a,a,s);else{let u=c.contentMatchAt(a).findWrapping(s.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 zn(t,e,n=e,r=x.empty){if(e==n&&!r.size)return null;let s=t.resolve(e),i=t.resolve(n);return Wo(s,i,r)?new K(e,n,r):new qc(s,i,r).fit()}function Wo(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class qc{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=b.empty;for(let s=0;s<=e.depth;s++){let i=e.node(s);this.frontier.push({type:i.type,match:i.contentMatchAt(e.indexAfter(s))})}for(let s=e.depth;s>0;s--)this.placed=b.from(e.node(s).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(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,s=this.close(e<0?this.$to:r.doc.resolve(e));if(!s)return null;let i=this.placed,o=r.depth,l=s.depth;for(;o&&l&&i.childCount==1;)i=i.firstChild.content,o--,l--;let a=new x(i,o,l);return e>-1?new J(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new K(r.pos,s.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,s=this.unplaced.openEnd;r1&&(s=0),i.type.spec.isolating&&s<=r){e=r;break}n=i.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let s,i=null;r?(i=er(this.unplaced.content,r-1).firstChild,s=i.content):s=this.unplaced.content;let o=s.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],d,u=null;if(n==1&&(o?c.matchType(o.type)||(u=c.fillBefore(b.from(o),!1)):i&&a.compatibleContent(i.type)))return{sliceDepth:r,frontierDepth:l,parent:i,inject:u};if(n==2&&o&&(d=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:i,wrap:d};if(i&&c.matchType(i.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,s=er(e,n);return!s.childCount||s.firstChild.isLeaf?!1:(this.unplaced=new x(e,n+1,Math.max(r,s.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,s=er(e,n);if(s.childCount<=1&&n>0){let i=e.size-n<=n+s.size;this.unplaced=new x(Ot(e,n-1,1),n-1,i?n-1:r)}else this.unplaced=new x(Ot(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:s,wrap:i}){for(;this.depth>n;)this.closeFrontierNode();if(i)for(let m=0;m1||a==0||m.content.size)&&(u=g,d.push(jo(m.mark(h.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?f:-1)))}let p=c==l.childCount;p||(f=-1),this.placed=Rt(this.placed,n,b.from(d)),this.frontier[n].match=u,p&&f<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&s==this.$to.end(--r);)++s;return s}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:s}=this.frontier[n],i=n=0;l--){let{match:a,type:c}=this.frontier[l],d=tr(e,l,c,a,!0);if(!d||d.childCount)continue e}return{depth:n,fit:o,move:i?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Rt(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let s=e.node(r),i=s.type.contentMatch.fillBefore(s.content,!0,e.index(r));this.openFrontierNode(s.type,s.attrs,i)}return e}openFrontierNode(e,n=null,r){let s=this.frontier[this.depth];s.match=s.match.matchType(e),this.placed=Rt(this.placed,this.depth,b.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(b.empty,!0);n.childCount&&(this.placed=Rt(this.placed,this.frontier.length,n))}}function Ot(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Ot(t.firstChild.content,e-1,n)))}function Rt(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Rt(t.lastChild.content,e-1,n)))}function er(t,e){for(let n=0;n1&&(r=r.replaceChild(0,jo(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(b.empty,!0)))),t.copy(r)}function tr(t,e,n,r,s){let i=t.node(e),o=s?t.indexAfter(e):t.index(e);if(o==i.childCount&&!n.compatibleContent(i.type))return null;let l=r.fillBefore(i.content,!0,o);return l&&!Kc(n,i.content,o)?l:null}function Kc(t,e,n){for(let r=n;r0;h--,f--){let p=s.node(h).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(h)>-1?l=h:s.before(h)==f&&o.splice(1,0,-h)}let a=o.indexOf(l),c=[],d=r.openStart;for(let h=r.content,f=0;;f++){let p=h.firstChild;if(c.push(p),f==r.openStart)break;h=p.content}for(let h=d-1;h>=0;h--){let f=c[h],p=Uc(f.type);if(p&&!f.sameMarkup(s.node(Math.abs(l)-1)))d=h;else if(p||!f.type.isTextblock)break}for(let h=r.openStart;h>=0;h--){let f=(h+d+1)%(r.openStart+1),p=c[f];if(p)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>u));h--){let f=o[h];f<0||(e=s.before(f),n=i.after(f))}}function qo(t,e,n,r,s){if(er){let i=s.contentMatchAt(0),o=i.fillBefore(t).append(t);t=o.append(i.matchFragment(o).fillBefore(b.empty,!0))}return t}function Xc(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let s=jc(t.doc,e,r.type);s!=null&&(e=n=s)}t.replaceRange(e,n,new x(b.from(r),0,0))}function Gc(t,e,n){let r=t.doc.resolve(e),s=t.doc.resolve(n),i=Ko(r,s);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),s.indexAfter(l-1))))return t.delete(r.before(l),s.after(l))}for(let o=1;o<=r.depth&&o<=s.depth;o++)if(e-r.start(o)==r.depth-o&&n>r.end(o)&&s.end(o)-n!=s.depth-o&&r.start(o-1)==s.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),s.index(o-1)))return t.delete(r.before(o),n);t.delete(e,n)}function Ko(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let s=r;s>=0;s--){let i=t.start(s);if(ie.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(i==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==i-1)&&n.push(s)}return n}class kt extends te{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return j.fail("No node at attribute step's position");let r=Object.create(null);for(let i in n.attrs)r[i]=n.attrs[i];r[this.attr]=this.value;let s=n.type.create(r,null,n.marks);return j.fromReplace(e,this.pos,this.pos+1,new x(b.from(s),0,n.isLeaf?0:1))}getMap(){return ie.empty}invert(e){return new kt(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new kt(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new kt(n.pos,n.attr,n.value)}}te.jsonID("attr",kt);class _t extends te{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let s in e.attrs)n[s]=e.attrs[s];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return j.ok(r)}getMap(){return ie.empty}invert(e){return new _t(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new _t(n.attr,n.value)}}te.jsonID("docAttr",_t);let xt=class extends Error{};xt=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};xt.prototype=Object.create(Error.prototype);xt.prototype.constructor=xt;xt.prototype.name="TransformError";class Gr{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Vt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new xt(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r{e=Math.min(e,l),n=Math.max(n,a)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=x.empty){let s=zn(this.doc,e,n,r);return s&&this.step(s),this}replaceWith(e,n,r){return this.replace(e,n,new x(b.from(r),0,0))}delete(e,n){return this.replace(e,n,x.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return Jc(this,e,n,r),this}replaceRangeWith(e,n,r){return Xc(this,e,n,r),this}deleteRange(e,n){return Gc(this,e,n),this}lift(e,n){return Pc(this,e,n),this}join(e,n=1){return Wc(this,e,n),this}wrap(e,n){return Bc(this,e,n),this}setBlockType(e,n=e,r,s=null){return $c(this,e,n,r,s),this}setNodeMarkup(e,n,r=null,s){return Fc(this,e,n,r,s),this}setNodeAttribute(e,n,r){return this.step(new kt(e,n,r)),this}setDocAttribute(e,n){return this.step(new _t(e,n)),this}addNodeMark(e,n){return this.step(new Fe(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof P)n.isInSet(r.marks)&&this.step(new lt(e,n));else{let s=r.marks,i,o=[];for(;i=n.isInSet(s);)o.push(new lt(e,i)),s=i.removeFromSet(s);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,n=1,r){return Vc(this,e,n,r),this}addMark(e,n,r){return Rc(this,e,n,r),this}removeMark(e,n,r){return Dc(this,e,n,r),this}clearIncompatible(e,n,r){return Jr(this,e,n,r),this}}const nr=Object.create(null);let N=class{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Uo(e.min(n),e.max(n))]}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 n=0;n=0;i--){let o=n<0?gt(e.node(0),e.node(i),e.before(i+1),e.index(i),n,r):gt(e.node(0),e.node(i),e.after(i+1),e.index(i)+1,n,r);if(o)return o}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new le(e.node(0))}static atStart(e){return gt(e,e,0,0,1)||new le(e)}static atEnd(e){return gt(e,e,e.content.size,e.childCount,-1)||new le(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=nr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in nr)throw new RangeError("Duplicate use of selection JSON ID "+e);return nr[e]=n,n.prototype.jsonID=e,n}getBookmark(){return E.between(this.$anchor,this.$head).getBookmark()}};N.prototype.visible=!0;class Uo{constructor(e,n){this.$from=e,this.$to=n}}let qs=!1;function Ks(t){!qs&&!t.parent.inlineContent&&(qs=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class E extends N{constructor(e,n=e){Ks(e),Ks(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return N.near(r);let s=e.resolve(n.map(this.anchor));return new E(s.parent.inlineContent?s:r,r)}replace(e,n=x.empty){if(super.replace(e,n),n==x.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 Bn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new E(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let s=e.resolve(n);return new this(s,r==n?s:e.resolve(r))}static between(e,n,r){let s=e.pos-n.pos;if((!r||s)&&(r=s>=0?1:-1),!n.parent.inlineContent){let i=N.findFrom(n,r,!0)||N.findFrom(n,-r,!0);if(i)n=i.$head;else return N.near(n,r)}return e.parent.inlineContent||(s==0?e=n:(e=(N.findFrom(e,-r,!0)||N.findFrom(e,r,!0)).$anchor,e.pos0?0:1);s>0?o=0;o+=s){let l=e.child(o);if(l.isAtom){if(!i&&T.isSelectable(l))return T.create(t,n-(s<0?l.nodeSize:0))}else{let a=gt(t,l,n+s,s<0?l.childCount:0,s,i);if(a)return a}n+=l.nodeSize*s}return null}function Us(t,e,n){let r=t.steps.length-1;if(r{o==null&&(o=d)}),t.setSelection(N.near(t.doc.resolve(o),n))}const Js=1,rn=2,Xs=4;class Qc extends Gr{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|=rn,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&rn)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~rn,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(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,n,r){let s=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(s.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let i=this.storedMarks;if(!i){let o=this.doc.resolve(n);i=r==n?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,s.text(e,i)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(N.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,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|=Xs,this}get scrolledIntoView(){return(this.updated&Xs)>0}}function Gs(t,e){return!e||!t?t:t.bind(e)}class Dt{constructor(e,n,r){this.name=e,this.init=Gs(n.init,r),this.apply=Gs(n.apply,r)}}const Zc=[new Dt("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Dt("selection",{init(t,e){return t.selection||N.atStart(e.doc)},apply(t){return t.selection}}),new Dt("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Dt("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class rr{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Zc.slice(),n&&n.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 Dt(r.key,r.spec.state,r))})}}class bt{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,n=-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 s=e[r],i=s.spec.state;i&&i.toJSON&&(n[r]=i.toJSON.call(s,this[s.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let s=new rr(e.schema,e.plugins),i=new bt(s);return s.fields.forEach(o=>{if(o.name=="doc")i.doc=ge.fromJSON(e.schema,n.doc);else if(o.name=="selection")i.selection=N.fromJSON(i.doc,n.selection);else if(o.name=="storedMarks")n.storedMarks&&(i.storedMarks=n.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(n,l)){i[o.name]=c.fromJSON.call(a,e,n[l],i);return}}i[o.name]=o.init(e,i)}}),i}}function Jo(t,e,n){for(let r in t){let s=t[r];s instanceof Function?s=s.bind(e):r=="handleDOMEvents"&&(s=Jo(s,e,{})),n[r]=s}return n}class B{constructor(e){this.spec=e,this.props={},e.props&&Jo(e.props,this,this.props),this.key=e.key?e.key.key:Xo("plugin")}getState(e){return e[this.key]}}const sr=Object.create(null);function Xo(t){return t in sr?t+"$"+ ++sr[t]:(sr[t]=0,t+"$")}class _{constructor(e="key"){this.key=Xo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Qr=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function Go(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const Yo=(t,e,n)=>{let r=Go(t,n);if(!r)return!1;let s=Zr(r);if(!s){let o=r.blockRange(),l=o&&At(o);return l==null?!1:(e&&e(t.tr.lift(o,l).scrollIntoView()),!0)}let i=s.nodeBefore;if(ol(t,s,e,-1))return!0;if(r.parent.content.size==0&&(St(i,"end")||T.isSelectable(i)))for(let o=r.depth;;o--){let l=zn(t.doc,r.before(o),r.after(o),x.empty);if(l&&l.slice.size1)break}return i.isAtom&&s.depth==r.depth-1?(e&&e(t.tr.delete(s.pos-i.nodeSize,s.pos).scrollIntoView()),!0):!1},ed=(t,e,n)=>{let r=Go(t,n);if(!r)return!1;let s=Zr(r);return s?Qo(t,s,e):!1},td=(t,e,n)=>{let r=el(t,n);if(!r)return!1;let s=es(r);return s?Qo(t,s,e):!1};function Qo(t,e,n){let r=e.nodeBefore,s=r,i=e.pos-1;for(;!s.isTextblock;i--){if(s.type.spec.isolating)return!1;let d=s.lastChild;if(!d)return!1;s=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=zn(t.doc,i,a,x.empty);if(!c||c.from!=i||c instanceof K&&c.slice.size>=a-i)return!1;if(n){let d=t.tr.step(c);d.setSelection(E.create(d.doc,i)),n(d.scrollIntoView())}return!0}function St(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}const Zo=(t,e,n)=>{let{$head:r,empty:s}=t.selection,i=r;if(!s)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;i=Zr(r)}let o=i&&i.nodeBefore;return!o||!T.isSelectable(o)?!1:(e&&e(t.tr.setSelection(T.create(t.doc,i.pos-o.nodeSize)).scrollIntoView()),!0)};function Zr(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function el(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=el(t,n);if(!r)return!1;let s=es(r);if(!s)return!1;let i=s.nodeAfter;if(ol(t,s,e,1))return!0;if(r.parent.content.size==0&&(St(i,"start")||T.isSelectable(i))){let o=zn(t.doc,r.before(),r.after(),x.empty);if(o&&o.slice.size{let{$head:r,empty:s}=t.selection,i=r;if(!s)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let n=t.selection,r=n instanceof T,s;if(r){if(n.node.isTextblock||!Ue(t.doc,n.from))return!1;s=n.from}else if(s=Ln(t.doc,n.from,-1),s==null)return!1;if(e){let i=t.tr.join(s);r&&i.setSelection(T.create(i.doc,s-t.doc.resolve(s).nodeBefore.nodeSize)),e(i.scrollIntoView())}return!0},rd=(t,e)=>{let n=t.selection,r;if(n instanceof T){if(n.node.isTextblock||!Ue(t.doc,n.to))return!1;r=n.to}else if(r=Ln(t.doc,n.to,1),r==null)return!1;return e&&e(t.tr.join(r).scrollIntoView()),!0},sd=(t,e)=>{let{$from:n,$to:r}=t.selection,s=n.blockRange(r),i=s&&At(s);return i==null?!1:(e&&e(t.tr.lift(s,i).scrollIntoView()),!0)},rl=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` `).scrollIntoView()),!0)};function ts(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let s=n.node(-1),i=n.indexAfter(-1),o=ts(s.contentMatchAt(i));if(!o||!s.canReplaceWith(i,i,o))return!1;if(e){let l=n.after(),a=t.tr.replaceWith(l,l,o.createAndFill());a.setSelection(N.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},sl=(t,e)=>{let n=t.selection,{$from:r,$to:s}=n;if(n instanceof le||r.parent.inlineContent||s.parent.inlineContent)return!1;let i=ts(s.parent.contentMatchAt(s.indexAfter()));if(!i||!i.isTextblock)return!1;if(e){let o=(!r.parentOffset&&s.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let i=n.before();if(Oe(t.doc,i))return e&&e(t.tr.split(i).scrollIntoView()),!0}let r=n.blockRange(),s=r&&At(r);return s==null?!1:(e&&e(t.tr.lift(r,s).scrollIntoView()),!0)};function od(t){return(e,n)=>{let{$from:r,$to:s}=e.selection;if(e.selection instanceof T&&e.selection.node.isBlock)return!r.parentOffset||!Oe(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let i=[],o,l,a=!1,c=!1;for(let f=r.depth;;f--)if(r.node(f).isBlock){a=r.end(f)==r.pos+(r.depth-f),c=r.start(f)==r.pos-(r.depth-f),l=ts(r.node(f-1).contentMatchAt(r.indexAfter(f-1))),i.unshift(a&&l?{type:l}:null),o=f;break}else{if(f==1)return!1;i.unshift(null)}let d=e.tr;(e.selection instanceof E||e.selection instanceof le)&&d.deleteSelection();let u=d.mapping.map(r.pos),h=Oe(d.doc,u,i.length,i);if(h||(i[0]=l?{type:l}:null,h=Oe(d.doc,u,i.length,i)),!h)return!1;if(d.split(u,i.length,i),!a&&c&&r.node(o).type!=l){let f=d.mapping.map(r.before(o)),p=d.doc.resolve(f);l&&r.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&d.setNodeMarkup(d.mapping.map(r.before(o)),l)}return n&&n(d.scrollIntoView()),!0}}const ld=od(),ad=(t,e)=>{let{$from:n,to:r}=t.selection,s,i=n.sharedDepth(r);return i==0?!1:(s=n.before(i),e&&e(t.tr.setSelection(T.create(t.doc,s))),!0)};function cd(t,e,n){let r=e.nodeBefore,s=e.nodeAfter,i=e.index();return!r||!s||!r.type.compatibleContent(s.type)?!1:!r.content.size&&e.parent.canReplace(i-1,i)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(i,i+1)||!(s.isTextblock||Ue(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function ol(t,e,n,r){let s=e.nodeBefore,i=e.nodeAfter,o,l,a=s.type.spec.isolating||i.type.spec.isolating;if(!a&&cd(t,e,n))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=s.contentMatchAt(s.childCount)).findWrapping(i.type))&&l.matchType(o[0]||i.type).validEnd){if(n){let f=e.pos+i.nodeSize,p=b.empty;for(let y=o.length-1;y>=0;y--)p=b.from(o[y].create(null,p));p=b.from(s.copy(p));let m=t.tr.step(new J(e.pos-1,f,e.pos,f,new x(p,1,0),o.length,!0)),g=m.doc.resolve(f+2*o.length);g.nodeAfter&&g.nodeAfter.type==s.type&&Ue(m.doc,g.pos)&&m.join(g.pos),n(m.scrollIntoView())}return!0}let d=i.type.spec.isolating||r>0&&a?null:N.findFrom(e,1),u=d&&d.$from.blockRange(d.$to),h=u&&At(u);if(h!=null&&h>=e.depth)return n&&n(t.tr.lift(u,h).scrollIntoView()),!0;if(c&&St(i,"start",!0)&&St(s,"end")){let f=s,p=[];for(;p.push(f),!f.isTextblock;)f=f.lastChild;let m=i,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(f.canReplace(f.childCount,f.childCount,m.content)){if(n){let y=b.empty;for(let w=p.length-1;w>=0;w--)y=b.from(p[w].copy(y));let k=t.tr.step(new J(e.pos-p.length,e.pos+i.nodeSize,e.pos+g,e.pos+i.nodeSize-g,new x(y,p.length,0),0,!0));n(k.scrollIntoView())}return!0}}return!1}function ll(t){return function(e,n){let r=e.selection,s=t<0?r.$from:r.$to,i=s.depth;for(;s.node(i).isInline;){if(!i)return!1;i--}return s.node(i).isTextblock?(n&&n(e.tr.setSelection(E.create(e.doc,t<0?s.start(i):s.end(i)))),!0):!1}}const dd=ll(-1),ud=ll(1);function hd(t,e=null){return function(n,r){let{$from:s,$to:i}=n.selection,o=s.blockRange(i),l=o&&Xr(o,t,e);return l?(r&&r(n.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Ys(t,e=null){return function(n,r){let s=!1;for(let i=0;i{if(s)return!1;if(!(!a.isTextblock||a.hasMarkup(t,e)))if(a.type==t)s=!0;else{let d=n.doc.resolve(c),u=d.index();s=d.parent.canReplaceWith(u,u+1,t)}})}if(!s)return!1;if(r){let i=n.tr;for(let o=0;o=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);i=new Mn(a,a,e.depth),e.endIndex=0;d--)i=b.from(n[d].type.create(n[d].attrs,i));t.step(new J(e.start-(r?2:0),e.end,e.start,e.end,new x(i,0,0),n.length,!0));let o=0;for(let d=0;do.childCount>0&&o.firstChild.type==t);return i?n?r.node(i.depth-1).type==t?yd(e,n,t,i):bd(e,n,i):!0:!1}}function yd(t,e,n,r){let s=t.tr,i=r.end,o=r.$to.end(r.depth);im;p--)f-=s.child(p).nodeSize,r.delete(f-1,f+1);let i=r.doc.resolve(n.start),o=i.nodeAfter;if(r.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,a=n.endIndex==s.childCount,c=i.node(-1),d=i.index(-1);if(!c.canReplace(d+(l?0:1),d+1,o.content.append(a?b.empty:b.from(s))))return!1;let u=i.pos,h=u+o.nodeSize;return r.step(new J(u-(l?1:0),h+(a?1:0),u+1,h-1,new x((l?b.empty:b.from(s.copy(b.empty))).append(a?b.empty:b.from(s.copy(b.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function kd(t){return function(e,n){let{$from:r,$to:s}=e.selection,i=r.blockRange(s,c=>c.childCount>0&&c.firstChild.type==t);if(!i)return!1;let o=i.startIndex;if(o==0)return!1;let l=i.parent,a=l.child(o-1);if(a.type!=t)return!1;if(n){let c=a.lastChild&&a.lastChild.type==l.type,d=b.from(c?t.create():null),u=new x(b.from(t.create(null,b.from(l.type.create(null,d)))),c?3:1,0),h=i.start,f=i.end;n(e.tr.step(new J(h-(c?3:1),f,h,f,u,1,!0)).scrollIntoView())}return!0}}const G=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Ct=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let Cr=null;const Ee=function(t,e,n){let r=Cr||(Cr=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},wd=function(){Cr=null},at=function(t,e,n,r){return n&&(Qs(t,e,n,r,-1)||Qs(t,e,n,r,1))},xd=/^(img|br|input|textarea|hr)$/i;function Qs(t,e,n,r,s){for(var i;;){if(t==n&&e==r)return!0;if(e==(s<0?0:ce(t))){let o=t.parentNode;if(!o||o.nodeType!=1||Xt(t)||xd.test(t.nodeName)||t.contentEditable=="false")return!1;e=G(t)+(s<0?0:1),t=o}else if(t.nodeType==1){let o=t.childNodes[e+(s<0?-1:0)];if(o.nodeType==1&&o.contentEditable=="false")if(!((i=o.pmViewDesc)===null||i===void 0)&&i.ignoreForSelection)e+=s;else return!1;else t=o,e=s<0?ce(t):0}else return!1}}function ce(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Sd(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=ce(t)}else if(t.parentNode&&!Xt(t))e=G(t),t=t.parentNode;else return null}}function Cd(t,e){for(;;){if(t.nodeType==3&&e2),ae=Mt||(ke?/Mac/.test(ke.platform):!1),dl=ke?/Win/.test(ke.platform):!1,Ae=/Android \d/.test(Je),Gt=!!Zs&&"webkitFontSmoothing"in Zs.documentElement.style,Ed=Gt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ad(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function ve(t,e){return typeof t=="number"?t:t[e]}function Nd(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function ei(t,e,n){let r=t.someProp("scrollThreshold")||0,s=t.someProp("scrollMargin")||5,i=t.dom.ownerDocument;for(let o=n||t.dom;o;){if(o.nodeType!=1){o=Ct(o);continue}let l=o,a=l==i.body,c=a?Ad(i):Nd(l),d=0,u=0;if(e.topc.bottom-ve(r,"bottom")&&(u=e.bottom-e.top>c.bottom-c.top?e.top+ve(s,"top")-c.top:e.bottom-c.bottom+ve(s,"bottom")),e.leftc.right-ve(r,"right")&&(d=e.right-c.right+ve(s,"right")),d||u)if(a)i.defaultView.scrollBy(d,u);else{let f=l.scrollLeft,p=l.scrollTop;u&&(l.scrollTop+=u),d&&(l.scrollLeft+=d);let m=l.scrollLeft-f,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let h=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(h))break;o=h=="absolute"?o.offsetParent:Ct(o)}}function Od(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,s;for(let i=(e.left+e.right)/2,o=n+1;o=n-20){r=l,s=a.top;break}}return{refDOM:r,refTop:s,stack:ul(t.dom)}}function ul(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Ct(r));return e}function Rd({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;hl(n,r==0?0:r-e)}function hl(t,e){for(let n=0;n=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=d,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!n&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(i=u+1)}}return!n&&a&&(n=a,s=c,r=0),n&&n.nodeType==3?Id(n,s):!n||r&&n.nodeType==1?{node:t,offset:i}:fl(n,s)}function Id(t,e){let n=t.nodeValue.length,r=document.createRange(),s;for(let i=0;i=(o.left+o.right)/2?1:0)};break}}return r.detach(),s||{node:t,offset:0}}function rs(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function Pd(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(o.left+o.right)/2?1:-1}return t.docView.posFromDOM(r,s,i)}function zd(t,e,n,r){let s=-1;for(let i=e,o=!1;i!=t.dom;){let l=t.docView.nearestDesc(i,!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?s=l.posBefore:(!o&&a.right-1?s:t.docView.posFromDOM(e,n,-1)}function pl(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&s++}let c;Gt&&s&&r.nodeType==1&&(c=r.childNodes[s-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&s--,r==t.dom&&s==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(s==0||r.nodeType!=1||r.childNodes[s-1].nodeName!="BR")&&(l=zd(t,r,s,e))}l==null&&(l=Ld(t,o,e));let a=t.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function ti(t){return t.top=0&&s==r.nodeValue.length?(a--,d=1):n<0?a--:c++,Nt(Pe(Ee(r,a,c),d),d<0)}if(!t.state.doc.resolve(e-(i||0)).parent.inlineContent){if(i==null&&s&&(n<0||s==ce(r))){let a=r.childNodes[s-1];if(a.nodeType==1)return ir(a.getBoundingClientRect(),!1)}if(i==null&&s=0)}if(i==null&&s&&(n<0||s==ce(r))){let a=r.childNodes[s-1],c=a.nodeType==3?Ee(a,ce(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Nt(Pe(c,1),!1)}if(i==null&&s=0)}function Nt(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function ir(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function gl(t,e,n){let r=t.state,s=t.root.activeElement;r!=e&&t.updateState(e),s!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),s!=t.dom&&s&&s.focus()}}function Hd(t,e,n){let r=e.selection,s=n=="up"?r.$from:r.$to;return gl(t,e,()=>{let{node:i}=t.docView.domFromPos(s.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(i,!0);if(!l)break;if(l.node.isBlock){i=l.contentDOM||l.dom;break}i=l.dom.parentNode}let o=ml(t,s.pos,1);for(let l=i.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Ee(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cd.top+1&&(n=="up"?o.top-d.top>(d.bottom-o.top)*2:d.bottom-o.bottom>(o.bottom-d.top)*2))return!1}}return!0})}const Fd=/[\u0590-\u08ac]/;function Vd(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let s=r.parentOffset,i=!s,o=s==r.parent.content.size,l=t.domSelection();return l?!Fd.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?i:o:gl(t,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:d,anchorOffset:u}=t.domSelectionRange(),h=l.caretBidiLevel;l.modify("move",n,"character");let f=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:p,focusOffset:m}=t.domSelectionRange(),g=p&&!f.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(d,u),a&&(a!=d||c!=u)&&l.extend&&l.extend(a,c)}catch{}return h!=null&&(l.caretBidiLevel=h),g}):r.pos==r.start()||r.pos==r.end()}let ni=null,ri=null,si=!1;function _d(t,e,n){return ni==e&&ri==n?si:(ni=e,ri=n,si=n=="up"||n=="down"?Hd(t,e,n):Vd(t,e,n))}const he=0,ii=1,Ye=2,we=3;class Yt{constructor(e,n,r,s){this.parent=e,this.children=n,this.dom=r,this.contentDOM=s,this.dirty=he,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nG(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let i=e;;i=i.parentNode){if(i==this.dom){s=!1;break}if(i.previousSibling)break}if(s==null&&n==e.childNodes.length)for(let i=e;;i=i.parentNode){if(i==this.dom){s=!0;break}if(i.nextSibling)break}}return s??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,s=e;s;s=s.parentNode){let i=this.getDesc(s),o;if(i&&(!n||i.node))if(r&&(o=i.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return i}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let s=e;s;s=s.parentNode){let i=this.getDesc(s);if(i)return i.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||o instanceof bl){s=e-i;break}i=l}if(s)return this.children[r].domFromPos(s-this.children[r].border,n);for(let i;r&&!(i=this.children[r-1]).size&&i instanceof yl&&i.side>=0;r--);if(n<=0){let i,o=!0;for(;i=r?this.children[r-1]:null,!(!i||i.dom.parentNode==this.contentDOM);r--,o=!1);return i&&n&&o&&!i.border&&!i.domAtom?i.domFromPos(i.size,n):{node:this.contentDOM,offset:i?G(i.dom)+1:0}}else{let i,o=!0;for(;i=r=d&&n<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,d);e=o;for(let u=l;u>0;u--){let h=this.children[u-1];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(1)){s=G(h.dom)+1;break}e-=h.size}s==-1&&(s=0)}if(s>-1&&(c>n||l==this.children.length-1)){n=c;for(let d=l+1;dp&&on){let p=l;l=a,a=p}let f=document.createRange();f.setEnd(a.node,a.offset),f.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,s=0;s=r:er){let l=r+i.border,a=o-i.border;if(e>=l&&n<=a){this.dirty=e==r||n==o?Ye:ii,e==l&&n==a&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=we:i.markDirty(e-l,n-l);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Ye:we}r=o}this.dirty=Ye}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Ye:ii;n.dirty{if(!i)return s;if(i.parent)return i.parent.posBeforeChild(i)})),!n.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=n,this.widget=n,i=this}matchesWidget(e){return this.dirty==he&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(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 Wd extends Yt{constructor(e,n,r,s){super(e,[],n,null),this.textDOM=r,this.text=s}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class ct extends Yt{constructor(e,n,r,s,i){super(e,[],r,s),this.mark=n,this.spec=i}static create(e,n,r,s){let i=s.nodeViews[n.type.name],o=i&&i(n,s,r);return(!o||!o.dom)&&(o=ft.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new ct(e,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&we||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=we&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=he){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(i=Ar(i,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,s),d=c&&c.dom,u=c&&c.contentDOM;if(n.isText){if(!d)d=document.createTextNode(n.text);else if(d.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else d||({dom:d,contentDOM:u}=ft.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!u&&!n.isText&&d.nodeName!="BR"&&(d.hasAttribute("contenteditable")||(d.contentEditable="false"),n.type.spec.draggable&&(d.draggable=!0));let h=d;return d=xl(d,r,n),c?a=new jd(e,n,r,s,d,u||null,h,c,i,o+1):n.isText?new Hn(e,n,r,s,d,h,i):new We(e,n,r,s,d,u||null,h,i,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 n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>b.empty)}return e}matchesNode(e,n,r){return this.dirty==he&&e.eq(this.node)&&Tn(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,s=n,i=e.composing?this.localCompositionInfo(e,n):null,o=i&&i.pos>-1?i:null,l=i&&i.pos<0,a=new Kd(this,o&&o.node,e);Xd(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,s)},(c,d,u,h)=>{a.syncToMarks(c.marks,r,e,h);let f;a.findNodeMatch(c,d,u,h)||l&&e.state.selection.from>s&&e.state.selection.to-1&&a.updateNodeAt(c,d,u,f,e)||a.updateNextNode(c,d,u,e,h,s)||a.addNode(c,d,u,e,s),s+=c.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Ye)&&(o&&this.protectLocalComposition(e,o),kl(this.contentDOM,this.children,e),Mt&&Gd(this.dom))}localCompositionInfo(e,n){let{from:r,to:s}=e.state.selection;if(!(e.state.selection instanceof E)||rn+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let o=i.nodeValue,l=Yd(this.node.content,o,r-n,s-n);return l<0?null:{node:i,pos:l,text:o}}else return{node:i,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:s}){if(this.getDesc(n))return;let i=n;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let o=new Wd(this,i,n,s);e.input.compositionNodes.push(o),this.children=Ar(this.children,r,r+s.length,e,o)}update(e,n,r,s){return this.dirty==we||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,s),!0)}updateInner(e,n,r,s){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=he}updateOuterDeco(e){if(Tn(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=wl(this.dom,this.nodeDOM,Er(this.outerDeco,this.node,n),Er(e,this.node,n)),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 oi(t,e,n,r,s){xl(r,e,t);let i=new We(void 0,t,e,n,r,r,r,s,0);return i.contentDOM&&i.updateChildren(s,0),i}class Hn extends We{constructor(e,n,r,s,i,o,l){super(e,n,r,s,i,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,n,r,s){return this.dirty==we||this.dirty!=he&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=he||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=e,this.dirty=he,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let s=this.node.cut(e,n),i=document.createTextNode(s.text);return new Hn(this.parent,s,this.outerDeco,this.innerDeco,i,i,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=we)}get domAtom(){return!1}isText(e){return this.node.text==e}}class bl extends Yt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==he&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class jd extends We{constructor(e,n,r,s,i,o,l,a,c,d){super(e,n,r,s,i,o,l,c,d),this.spec=a}update(e,n,r,s){if(this.dirty==we)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,n,r);return i&&this.updateInner(e,n,r,s),i}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,s){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,s)}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 kl(t,e,n){let r=t.firstChild,s=!1;for(let i=0;i>1,l=Math.min(o,e.length);for(;i-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let d=ct.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,d),this.top=d,this.changed=!0}this.index=0,o++}}findNodeMatch(e,n,r,s){let i=-1,o;if(s>=this.preMatch.index&&(o=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&o.matchesNode(e,n,r))i=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=n.children[r-1];if(c instanceof ct)n=c,r=c.children.length;else{l=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(s-1))break;--s,i.set(l,s),o.push(l)}}return{index:s,matched:i,matches:o.reverse()}}function Jd(t,e){return t.type.side-e.type.side}function Xd(t,e,n,r){let s=e.locals(t),i=0;if(s.length==0){for(let c=0;ci;)l.push(s[o++]);let p=i+h.nodeSize;if(h.isText){let g=p;o!g.inline):l.slice();r(h,m,e.forChild(i,h),f),i=p}}function Gd(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function Yd(t,e,n,r){for(let s=0,i=0;s=n){if(i>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=n)return l+c;if(n==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Ar(t,e,n,r,s){let i=[];for(let o=0,l=0;o=n||d<=e?i.push(a):(cn&&i.push(a.slice(n-c,a.size,r)))}return i}function ss(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let s=t.docView.nearestDesc(n.focusNode),i=s&&s.size==0,o=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if($n(n)){for(a=o;s&&!s.node;)s=s.parent;let u=s.node;if(s&&u.isAtom&&T.isSelectable(u)&&s.parent&&!(u.isInline&&Md(n.focusNode,n.focusOffset,s.dom))){let h=s.posBefore;c=new T(o==h?l:r.resolve(h))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let u=o,h=o;for(let f=0;f{(n.anchorNode!=r||n.anchorOffset!=s)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Sl(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function Zd(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,G(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&se&&_e<=11&&(n.disabled=!0,n.disabled=!1)}function Cl(t,e){if(e instanceof T){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(ui(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else ui(t)}function ui(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function is(t,e,n,r){return t.someProp("createSelectionBetween",s=>s(t,e,n))||E.between(e,n,r)}function hi(t){return t.editable&&!t.hasFocus()?!1:Ml(t)}function Ml(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function eu(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return at(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Nr(t,e){let{$anchor:n,$head:r}=t.selection,s=e>0?n.max(r):n.min(r),i=s.parent.inlineContent?s.depth?t.doc.resolve(e>0?s.after():s.before()):null:s;return i&&N.findFrom(i,e)}function Le(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function fi(t,e,n){let r=t.state.selection;if(r instanceof E)if(n.indexOf("s")>-1){let{$head:s}=r,i=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let o=t.state.doc.resolve(s.pos+i.nodeSize*(e<0?-1:1));return Le(t,new E(r.$anchor,o))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let s=Nr(t.state,e);return s&&s instanceof T?Le(t,s):!1}else if(!(ae&&n.indexOf("m")>-1)){let s=r.$head,i=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter,o;if(!i||i.isText)return!1;let l=e<0?s.pos-i.nodeSize:s.pos;return i.isAtom||(o=t.docView.descAt(l))&&!o.contentDOM?T.isSelectable(i)?Le(t,new T(e<0?t.state.doc.resolve(s.pos-i.nodeSize):s)):Gt?Le(t,new E(t.state.doc.resolve(e<0?l:l+i.nodeSize))):!1:!1}}else return!1;else{if(r instanceof T&&r.node.isInline)return Le(t,new E(e>0?r.$to:r.$from));{let s=Nr(t.state,e);return s?Le(t,s):!1}}}function En(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function $t(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function mt(t,e){return e<0?tu(t):nu(t)}function tu(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let s,i,o=!1;for(ue&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let l=n.childNodes[r-1];if($t(l,-1))s=n,i=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(vl(n))break;{let l=n.previousSibling;for(;l&&$t(l,-1);)s=n.parentNode,i=G(l),l=l.previousSibling;if(l)n=l,r=En(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}o?Or(t,n,r):s&&Or(t,s,i)}function nu(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let s=En(n),i,o;for(;;)if(r{t.state==s&&Re(t)},50)}function pi(t,e){let n=t.state.doc.resolve(e);if(!(Y||dl)&&n.parent.inlineContent){let s=t.coordsAtPos(e);if(e>n.start()){let i=t.coordsAtPos(e-1),o=(i.top+i.bottom)/2;if(o>s.top&&o1)return i.lefts.top&&o1)return i.left>s.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function mi(t,e,n){let r=t.state.selection;if(r instanceof E&&!r.empty||n.indexOf("s")>-1||ae&&n.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let o=Nr(t.state,e);if(o&&o instanceof T)return Le(t,o)}if(!s.parent.inlineContent){let o=e<0?s:i,l=r instanceof le?N.near(o,e):N.findFrom(o,e);return l?Le(t,l):!1}return!1}function gi(t,e){if(!(t.state.selection instanceof E))return!0;let{$head:n,$anchor:r,empty:s}=t.state.selection;if(!n.sameParent(r))return!0;if(!s)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let i=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let o=t.state.tr;return e<0?o.delete(n.pos-i.nodeSize,n.pos):o.delete(n.pos,n.pos+i.nodeSize),t.dispatch(o),!0}return!1}function yi(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function iu(t){if(!Z||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;yi(t,r,"true"),setTimeout(()=>yi(t,r,"false"),20)}return!1}function ou(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function lu(t,e){let n=e.keyCode,r=ou(e);if(n==8||ae&&n==72&&r=="c")return gi(t,-1)||mt(t,-1);if(n==46&&!e.shiftKey||ae&&n==68&&r=="c")return gi(t,1)||mt(t,1);if(n==13||n==27)return!0;if(n==37||ae&&n==66&&r=="c"){let s=n==37?pi(t,t.state.selection.from)=="ltr"?-1:1:-1;return fi(t,s,r)||mt(t,s)}else if(n==39||ae&&n==70&&r=="c"){let s=n==39?pi(t,t.state.selection.from)=="ltr"?1:-1:1;return fi(t,s,r)||mt(t,s)}else{if(n==38||ae&&n==80&&r=="c")return mi(t,-1,r)||mt(t,-1);if(n==40||ae&&n==78&&r=="c")return iu(t)||mi(t,1,r)||mt(t,1);if(r==(ae?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function ls(t,e){t.someProp("transformCopied",f=>{e=f(e,t)});let n=[],{content:r,openStart:s,openEnd:i}=e;for(;s>1&&i>1&&r.childCount==1&&r.firstChild.childCount==1;){s--,i--;let f=r.firstChild;n.push(f.type.name,f.attrs!=f.type.defaultAttrs?f.attrs:null),r=f.content}let o=t.someProp("clipboardSerializer")||ft.fromSchema(t.state.schema),l=Rl(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,d,u=0;for(;c&&c.nodeType==1&&(d=Ol[c.nodeName.toLowerCase()]);){for(let f=d.length-1;f>=0;f--){let p=l.createElement(d[f]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),u++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${s} ${i}${u?` -${u}`:""} ${JSON.stringify(n)}`);let h=t.someProp("clipboardTextSerializer",f=>f(e,t))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:h,slice:e}}function Tl(t,e,n,r,s){let i=s.parent.type.spec.code,o,l;if(!n&&!e)return null;let a=!!e&&(r||i||!n);if(a){if(t.someProp("transformPastedText",h=>{e=h(e,i||r,t)}),i)return l=new x(b.from(t.state.schema.text(e.replace(/\r\n?/g,` `))),0,0),t.someProp("transformPasted",h=>{l=h(l,t,!0)}),l;let u=t.someProp("clipboardTextParser",h=>h(e,s,r,t));if(u)l=u;else{let h=s.marks(),{schema:f}=t.state,p=ft.fromSchema(f);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(f.text(m,h)))})}}else t.someProp("transformPastedHTML",u=>{n=u(n,t)}),o=uu(n),Gt&&hu(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 h=o.firstChild;for(;h&&h.nodeType!=1;)h=h.nextSibling;if(!h)break;o=h}if(l||(l=(t.someProp("clipboardParser")||t.someProp("domParser")||Ne.fromSchema(t.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||d),context:s,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!au.test(h.parentNode.nodeName)?{ignore:!0}:null}})),d)l=fu(bi(l,+d[1],+d[2]),d[4]);else if(l=x.maxOpen(cu(l.content,s),!0),l.openStart||l.openEnd){let u=0,h=0;for(let f=l.content.firstChild;u{l=u(l,t,a)}),l}const au=/^(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 cu(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let s=e.node(n).contentMatchAt(e.index(n)),i,o=[];if(t.forEach(l=>{if(!o)return;let a=s.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&i.length&&Al(a,i,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Nl(o[o.length-1],i.length));let d=El(l,a);o.push(d),s=s.matchType(d.type),i=a}}),o)return b.from(o)}return t}function El(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,b.from(t));return t}function Al(t,e,n,r,s){if(s1&&(i=0),s=n&&(l=e<0?o.contentMatchAt(0).fillBefore(l,i<=s).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(b.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(l))}function bi(t,e,n){return en})),lr.createHTML(t)):t}function uu(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Rl().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),s;if((s=r&&Ol[r[1].toLowerCase()])&&(t=s.map(i=>"<"+i+">").join("")+t+s.map(i=>"").reverse().join("")),n.innerHTML=du(t),s)for(let i=0;i=0;l-=2){let a=n.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;s=b.from(a.create(r[l+1],s)),i++,o++}return new x(s,i,o)}const ne={},re={},pu={touchstart:!0,touchmove:!0};class mu{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 gu(t){for(let e in ne){let n=ne[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{bu(t,r)&&!as(t,r)&&(t.editable||!(r.type in re))&&n(t,r)},pu[e]?{passive:!0}:void 0)}Z&&t.dom.addEventListener("input",()=>null),Dr(t)}function Ve(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function yu(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Dr(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>as(t,r))})}function as(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function bu(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function ku(t,e){!as(t,e)&&ne[e.type]&&(t.editable||!(e.type in re))&&ne[e.type](t,e)}re.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!Il(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(Ae&&Y&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),Mt&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",s=>s(t,Ge(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||lu(t,n)?n.preventDefault():Ve(t,"key")};re.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};re.keypress=(t,e)=>{let n=e;if(Il(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||ae&&n.metaKey)return;if(t.someProp("handleKeyPress",s=>s(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof E)||!r.$from.sameParent(r.$to)){let s=String.fromCharCode(n.charCode),i=()=>t.state.tr.insertText(s).scrollIntoView();!/[\r\n]/.test(s)&&!t.someProp("handleTextInput",o=>o(t,r.$from.pos,r.$to.pos,s,i))&&t.dispatch(i()),n.preventDefault()}};function Fn(t){return{left:t.clientX,top:t.clientY}}function wu(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function cs(t,e,n,r,s){if(r==-1)return!1;let i=t.state.doc.resolve(r);for(let o=i.depth+1;o>0;o--)if(t.someProp(e,l=>o>i.depth?l(t,n,i.nodeAfter,i.before(o),s,!0):l(t,n,i.node(o),i.before(o),s,!1)))return!0;return!1}function wt(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",!0),t.dispatch(r)}function xu(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&T.isSelectable(r)?(wt(t,new T(n)),!0):!1}function Su(t,e){if(e==-1)return!1;let n=t.state.selection,r,s;n instanceof T&&(r=n.node);let i=t.state.doc.resolve(e);for(let o=i.depth+1;o>0;o--){let l=o>i.depth?i.nodeAfter:i.node(o);if(T.isSelectable(l)){r&&n.$from.depth>0&&o>=n.$from.depth&&i.before(n.$from.depth+1)==n.$from.pos?s=i.before(n.$from.depth):s=i.before(o);break}}return s!=null?(wt(t,T.create(t.state.doc,s)),!0):!1}function Cu(t,e,n,r,s){return cs(t,"handleClickOn",e,n,r)||t.someProp("handleClick",i=>i(t,e,r))||(s?Su(t,n):xu(t,n))}function Mu(t,e,n,r){return cs(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",s=>s(t,e,r))}function vu(t,e,n,r){return cs(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",s=>s(t,e,r))||Tu(t,n,r)}function Tu(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(wt(t,E.create(r,0,r.content.size)),!0):!1;let s=r.resolve(e);for(let i=s.depth+1;i>0;i--){let o=i>s.depth?s.nodeAfter:s.node(i),l=s.before(i);if(o.inlineContent)wt(t,E.create(r,l+1,l+1+o.content.size));else if(T.isSelectable(o))wt(t,T.create(r,l));else continue;return!0}}function ds(t){return An(t)}const Dl=ae?"metaKey":"ctrlKey";ne.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=ds(t),s=Date.now(),i="singleClick";s-t.input.lastClick.time<500&&wu(n,t.input.lastClick)&&!n[Dl]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?i="doubleClick":t.input.lastClick.type=="doubleClick"&&(i="tripleClick")),t.input.lastClick={time:s,x:n.clientX,y:n.clientY,type:i,button:n.button};let o=t.posAtCoords(Fn(n));o&&(i=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Eu(t,o,n,!!r)):(i=="doubleClick"?Mu:vu)(t,o.pos,o.inside,n)?n.preventDefault():Ve(t,"pointer"))};class Eu{constructor(e,n,r,s){this.view=e,this.pos=n,this.event=r,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Dl],this.allowDefault=r.shiftKey;let i,o;if(n.inside>-1)i=e.state.doc.nodeAt(n.inside),o=n.inside;else{let d=e.state.doc.resolve(n.pos);i=d.parent,o=d.depth?d.before():0}const l=s?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&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof T&&c.from<=o&&c.to>o)&&(this.mightDrag={node:i,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ue&&!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)),Ve(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(()=>Re(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(Fn(e))),this.updateAllowDefault(e),this.allowDefault||!n?Ve(this.view,"pointer"):Cu(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Z&&this.mightDrag&&!this.mightDrag.node.isAtom||Y&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(wt(this.view,N.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):Ve(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ve(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)}}ne.touchstart=t=>{t.input.lastTouch=Date.now(),ds(t),Ve(t,"pointer")};ne.touchmove=t=>{t.input.lastTouch=Date.now(),Ve(t,"pointer")};ne.contextmenu=t=>ds(t);function Il(t,e){return t.composing?!0:Z&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const Au=Ae?5e3:-1;re.compositionstart=re.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof E&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||Y&&dl&&Nu(t)))t.markCursor=t.state.storedMarks||n.marks(),An(t,!0),t.markCursor=null;else if(An(t,!e.selection.empty),ue&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let s=r.focusNode,i=r.focusOffset;s&&s.nodeType==1&&i!=0;){let o=i<0?s.lastChild:s.childNodes[i-1];if(!o)break;if(o.nodeType==3){let l=t.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else s=o,i=-1}}t.input.composing=!0}Pl(t,Au)};function Nu(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}re.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Pl(t,20))};function Pl(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>An(t),e))}function Ll(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Ru());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Ou(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=Sd(e.focusNode,e.focusOffset),r=Cd(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let s=r.pmViewDesc,i=t.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!s||!s.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let o=n.pmViewDesc;if(!(!o||!o.isText(n.nodeValue)))return r}}return n||r}function Ru(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function An(t,e=!1){if(!(Ae&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Ll(t),e||t.docView&&t.docView.dirty){let n=ss(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function Du(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),s=document.createRange();s.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(s),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const Wt=se&&_e<15||Mt&&Ed<604;ne.copy=re.cut=(t,e)=>{let n=e,r=t.state.selection,s=n.type=="cut";if(r.empty)return;let i=Wt?null:n.clipboardData,o=r.content(),{dom:l,text:a}=ls(t,o);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):Du(t,l),s&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Iu(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function Pu(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let s=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?jt(t,r.value,null,s,e):jt(t,r.textContent,r.innerHTML,s,e)},50)}function jt(t,e,n,r,s){let i=Tl(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",a=>a(t,s,i||x.empty)))return!0;if(!i)return!1;let o=Iu(i),l=o?t.state.tr.replaceSelectionWith(o,r):t.state.tr.replaceSelection(i);return t.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function zl(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}re.paste=(t,e)=>{let n=e;if(t.composing&&!Ae)return;let r=Wt?null:n.clipboardData,s=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&jt(t,zl(r),r.getData("text/html"),s,n)?n.preventDefault():Pu(t,n)};class Bl{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const Lu=ae?"altKey":"ctrlKey";function $l(t,e){let n=t.someProp("dragCopies",r=>!r(e));return n??!e[Lu]}ne.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let s=t.state.selection,i=s.empty?null:t.posAtCoords(Fn(n)),o;if(!(i&&i.pos>=s.from&&i.pos<=(s instanceof T?s.to-1:s.to))){if(r&&r.mightDrag)o=T.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let u=t.docView.nearestDesc(n.target,!0);u&&u.node.type.spec.draggable&&u!=t.docView&&(o=T.create(t.state.doc,u.posBefore))}}let l=(o||t.state.selection).content(),{dom:a,text:c,slice:d}=ls(t,l);(!n.dataTransfer.files.length||!Y||cl>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Wt?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Wt||n.dataTransfer.setData("text/plain",c),t.dragging=new Bl(d,$l(t,n),o)};ne.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};re.dragover=re.dragenter=(t,e)=>e.preventDefault();re.drop=(t,e)=>{try{zu(t,e,t.dragging)}finally{t.dragging=null}};function zu(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(Fn(e));if(!r)return;let s=t.state.doc.resolve(r.pos),i=n&&n.slice;i?t.someProp("transformPasted",f=>{i=f(i,t,!1)}):i=Tl(t,zl(e.dataTransfer),Wt?null:e.dataTransfer.getData("text/html"),!1,s);let o=!!(n&&$l(t,e));if(t.someProp("handleDrop",f=>f(t,e,i||x.empty,o))){e.preventDefault();return}if(!i)return;e.preventDefault();let l=i?_o(t.state.doc,s.pos,i):s.pos;l==null&&(l=s.pos);let a=t.state.tr;if(o){let{node:f}=n;f?f.replace(a):a.deleteSelection()}let c=a.mapping.map(l),d=i.openStart==0&&i.openEnd==0&&i.content.childCount==1,u=a.doc;if(d?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(u))return;let h=a.doc.resolve(c);if(d&&T.isSelectable(i.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new T(h));else{let f=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,y)=>f=y),a.setSelection(is(t,h,a.doc.resolve(f)))}t.focus(),t.dispatch(a.setMeta("uiEvent","drop"))}ne.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Re(t)},20))};ne.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};ne.beforeinput=(t,e)=>{if(Y&&Ae&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",i=>i(t,Ge(8,"Backspace")))))return;let{$cursor:s}=t.state.selection;s&&s.pos>0&&t.dispatch(t.state.tr.delete(s.pos-1,s.pos).scrollIntoView())},50)}};for(let t in re)ne[t]=re[t];function qt(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Nn{constructor(e,n){this.toDOM=e,this.spec=n||nt,this.side=this.spec.side||0}map(e,n,r,s){let{pos:i,deleted:o}=e.mapResult(n.from+s,this.side<0?-1:1);return o?null:new U(i-r,i-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&&qt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class je{constructor(e,n){this.attrs=e,this.spec=n||nt}map(e,n,r,s){let i=e.map(n.from+s,this.spec.inclusiveStart?-1:1)-r,o=e.map(n.to+s,this.spec.inclusiveEnd?1:-1)-r;return i>=o?null:new U(i,o,this)}valid(e,n){return n.from=e&&(!i||i(l.spec))&&r.push(l.copy(l.from+s,l.to+s))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,n-l,r,s+l,i)}}map(e,n,r){return this==Q||e.maps.length==0?this:this.mapInner(e,n,0,0,r||nt)}mapInner(e,n,r,s,i){let o;for(let l=0;l{let c=a+r,d;if(d=Fl(n,l,c)){for(s||(s=this.children.slice());il&&u.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let i=e+1,o=i+n.content.size;for(let l=0;li&&a.type instanceof je){let c=Math.max(i,a.from)-i,d=Math.min(o,a.to)-i;cs.map(e,n,nt));return Be.from(r)}forChild(e,n){if(n.isLeaf)return L.empty;let r=[];for(let s=0;sn instanceof L)?e:e.reduce((n,r)=>n.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let n=0;n{let g=m-p-(f-h);for(let y=0;yk+d-u)continue;let w=l[y]+d-u;f>=w?l[y+1]=h<=w?-2:-1:h>=d&&g&&(l[y]+=g,l[y+1]+=g)}u+=g}),d=n.maps[c].map(d,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let h=n.map(t[c+1]+i,-1),f=h-s,{index:p,offset:m}=r.content.findIndex(u),g=r.maybeChild(p);if(g&&m==u&&m+g.nodeSize==f){let y=l[c+2].mapInner(n,g,d+1,t[c]+i+1,o);y!=Q?(l[c]=u,l[c+1]=f,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=$u(l,t,e,n,s,i,o),d=On(c,r,0,o);e=d.local;for(let u=0;un&&o.to{let c=Fl(t,l,a+n);if(c){i=!0;let d=On(c,l,n+a+1,r);d!=Q&&s.push(a,a+l.nodeSize,d)}});let o=Hl(i?Vl(t):t,-n).sort(rt);for(let l=0;l0;)e++;t.splice(e,0,n)}function ar(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=Q&&e.push(r)}),t.cursorWrapper&&e.push(L.create(t.state.doc,[t.cursorWrapper.deco])),Be.from(e)}const Hu={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Fu=se&&_e<=11;class Vu{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 _u{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Vu,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let s=0;ss.type=="childList"&&s.removedNodes.length||s.type=="characterData"&&s.oldValue.length>s.target.nodeValue.length)?this.flushSoon():Z&&e.composing&&r.some(s=>s.type=="childList"&&s.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Fu&&(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,Hu)),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 n=0;nthis.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(hi(this.view)){if(this.suppressingSelectionUpdates)return Re(this.view);if(se&&_e<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&at(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 n=new Set,r;for(let i=e.focusNode;i;i=Ct(i))n.add(i);for(let i=e.anchorNode;i;i=Ct(i))if(n.has(i)){r=i;break}let s=r&&this.view.docView.nearestDesc(r);if(s&&s.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 n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&hi(e)&&!this.ignoreSelectionChange(r),i=-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(ue&&a.length){let d=a.filter(u=>u.nodeName=="BR");if(d.length==2){let[u,h]=d;u.parentNode&&u.parentNode.parentNode==h.parentNode?h.remove():u.remove()}else{let{focusNode:u}=this.currentSelection;for(let h of d){let f=h.parentNode;f&&f.nodeName=="LI"&&(!u||qu(e,u)!=f)&&h.remove()}}}let c=null;i<0&&s&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||s)&&(i>-1&&(e.docView.markDirty(i,o),Wu(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Ku(e,a)),this.handleDOMChange(i,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Re(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.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;ds;g--){let y=r.childNodes[g-1],k=y.pmViewDesc;if(y.nodeName=="BR"&&!k){i=g;break}if(!k||k.size)break}let u=t.state.doc,h=t.someProp("domParser")||Ne.fromSchema(t.state.schema),f=u.resolve(o),p=null,m=h.parse(r,{topNode:f.parent,topMatch:f.parent.contentMatchAt(f.index()),topOpen:!0,from:s,to:i,preserveWhitespace:f.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Ju,context:f});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Ju(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Z&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Z&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Xu=/^(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 Gu(t,e,n,r,s){let i=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let v=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,O=ss(t,v);if(O&&!t.state.selection.eq(O)){if(Y&&Ae&&t.input.lastKeyCode===13&&Date.now()-100Ce(t,Ge(13,"Enter"))))return;let R=t.state.tr.setSelection(O);v=="pointer"?R.setMeta("pointer",!0):v=="key"&&R.scrollIntoView(),i&&R.setMeta("composition",i),t.dispatch(R)}return}let o=t.state.doc.resolve(e),l=o.sharedDepth(n);e=o.before(l+1),n=t.state.doc.resolve(n).after(l+1);let a=t.state.selection,c=Uu(t,e,n),d=t.state.doc,u=d.slice(c.from,c.to),h,f;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Ae)&&s.some(v=>v.nodeType==1&&!Xu.test(v.nodeName))&&(!p||p.endA>=p.endB)&&t.someProp("handleKeyDown",v=>v(t,Ge(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof E&&!a.empty&&a.$head.sameParent(a.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let v=Mi(t,t.state.doc,c.sel);if(v&&!v.eq(t.state.selection)){let O=t.state.tr.setSelection(v);i&&O.setMeta("composition",i),t.dispatch(O)}}return}t.state.selection.fromt.state.selection.from&&p.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?p.start=t.state.selection.from:p.endA=t.state.selection.to-2&&t.state.selection.to<=c.to&&(p.endB+=t.state.selection.to-p.endA,p.endA=t.state.selection.to)),se&&_e<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)=="  "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),y=d.resolve(p.start),k=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((Mt&&t.input.lastIOSEnter>Date.now()-225&&(!k||s.some(v=>v.nodeName=="DIV"||v.nodeName=="P"))||!k&&m.posv(t,Ge(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>p.start&&Qu(d,p.start,p.endA,m,g)&&t.someProp("handleKeyDown",v=>v(t,Ge(8,"Backspace")))){Ae&&Y&&t.domObserver.suppressSelectionUpdates();return}Y&&p.endB==p.start&&(t.input.lastChromeDelete=Date.now()),Ae&&!k&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(v){return v(t,Ge(13,"Enter"))})},20));let w=p.start,S=p.endA,C=v=>{let O=v||t.state.tr.replace(w,S,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let R=Mi(t,O.doc,c.sel);R&&!(Y&&t.composing&&R.empty&&(p.start!=p.endB||t.input.lastChromeDeleteRe(t),20));let v=C(t.state.tr.delete(w,S)),O=d.resolve(p.start).marksAcross(d.resolve(p.endA));O&&v.ensureMarks(O),t.dispatch(v)}else if(p.endA==p.endB&&(A=Yu(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let v=C(t.state.tr);A.type=="add"?v.addMark(w,S,A.mark):v.removeMark(w,S,A.mark),t.dispatch(v)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let v=m.parent.textBetween(m.parentOffset,g.parentOffset),O=()=>C(t.state.tr.insertText(v,w,S));t.someProp("handleTextInput",R=>R(t,w,S,v,O))||t.dispatch(O())}else t.dispatch(C());else t.dispatch(C())}function Mi(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:is(t,e.resolve(n.anchor),e.resolve(n.head))}function Yu(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,s=n,i=r,o,l,a;for(let d=0;dd.mark(l.addToSet(d.marks));else if(s.length==0&&i.length==1)l=i[0],o="remove",a=d=>d.mark(l.removeFromSet(d.marks));else return null;let c=[];for(let d=0;dn||cr(o,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,s++,e=!1;if(n){let i=t.node(r).maybeChild(t.indexAfter(r));for(;i&&!i.isLeaf;)i=i.firstChild,s++}return s}function Zu(t,e,n,r,s){let i=t.findDiffStart(e,n);if(i==null)return null;let{a:o,b:l}=t.findDiffEnd(e,n+t.size,n+e.size);if(s=="end"){let a=Math.max(0,i-Math.min(o,l));r-=o+a-i}if(o=o?i-r:0;i-=a,i&&i=l?i-r:0;i-=a,i&&i=56320&&e<=57343&&n>=55296&&n<=56319}class _l{constructor(e,n){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 mu,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Oi),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=Ai(this),Ei(this),this.nodeViews=Ni(this),this.docView=oi(this.state.doc,Ti(this),ar(this),this.dom,this),this.domObserver=new _u(this,(r,s,i,o)=>Gu(this,r,s,i,o)),this.domObserver.start(),gu(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Dr(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Oi),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let s=this.state,i=!1,o=!1;e.storedMarks&&this.composing&&(Ll(this),o=!0),this.state=e;let l=s.plugins!=e.plugins||this._props.plugins!=n.plugins;if(l||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let f=Ni(this);th(f,this.nodeViews)&&(this.nodeViews=f,i=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&Dr(this),this.editable=Ai(this),Ei(this);let a=ar(this),c=Ti(this),d=s.plugins!=e.plugins&&!s.doc.eq(e.doc)?"reset":e.scrollToSelection>s.scrollToSelection?"to selection":"preserve",u=i||!this.docView.matchesNode(e.doc,c,a);(u||!e.selection.eq(s.selection))&&(o=!0);let h=d=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Od(this);if(o){this.domObserver.stop();let f=u&&(se||Y)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&eh(s.selection,e.selection);if(u){let p=Y?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Ou(this)),(i||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=oi(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(f=!0)}f||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&eu(this))?Re(this,f):(Cl(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),!((r=this.dragging)===null||r===void 0)&&r.node&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),d=="reset"?this.dom.scrollTop=0:d=="to selection"?this.scrollToSelection():h&&Rd(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof T){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&ei(this,n.getBoundingClientRect(),e)}else ei(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 n=0;n0&&this.state.doc.nodeAt(i))==r.node&&(s=i)}this.dragging=new Bl(e.slice,e.move,s<0?void 0:T.create(this.state.doc,s))}someProp(e,n){let r=this._props&&this._props[e],s;if(r!=null&&(s=n?n(r):r))return s;for(let o=0;on.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Bd(this,e)}coordsAtPos(e,n=1){return ml(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let s=this.docView.posFromDOM(e,n,r);if(s==null)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(e,n){return _d(this,n||this.state,e)}pasteHTML(e,n){return jt(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return jt(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return ls(this,e)}destroy(){this.docView&&(yu(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,wd())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ku(this,e)}domSelectionRange(){let e=this.domSelection();return e?Z&&this.root.nodeType===11&&vd(this.dom.ownerDocument)==this.dom&&ju(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}_l.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Ti(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[U.node(0,t.state.doc.content.size,e)]}function Ei(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:U.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Ai(t){return!t.someProp("editable",e=>e(t.state)===!1)}function eh(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Ni(t){let e=Object.create(null);function n(r){for(let s in r)Object.prototype.hasOwnProperty.call(e,s)||(e[s]=r[s])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function th(t,e){let n=0,r=0;for(let s in t){if(t[s]!=e[s])return!0;n++}for(let s in e)r++;return n!=r}function Oi(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}const nh=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),rh=typeof navigator<"u"&&/Win/.test(navigator.platform);function sh(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,s,i,o;for(let l=0;l{for(var n in e)lh(t,n,{get:e[n],enumerable:!0})};function Vn(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:s}=n,{storedMarks:i}=n;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 i},get selection(){return r},get doc(){return s},get tr(){return r=n.selection,s=n.doc,i=n.storedMarks,n}}}var _n=class{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:e,state:n}=this,{view:r}=e,{tr:s}=n,i=this.buildProps(s);return Object.fromEntries(Object.entries(t).map(([o,l])=>[o,(...c)=>{const d=l(...c)(i);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,e=!0){const{rawCommands:n,editor:r,state:s}=this,{view:i}=r,o=[],l=!!t,a=t||s.tr,c=()=>(!l&&e&&!a.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(a),o.every(u=>u===!0)),d={...Object.fromEntries(Object.entries(n).map(([u,h])=>[u,(...p)=>{const m=this.buildProps(a,e),g=h(...p)(m);return o.push(g),d}])),run:c};return d}createCan(t){const{rawCommands:e,state:n}=this,r=!1,s=t||n.tr,i=this.buildProps(s,r);return{...Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...c)=>a(...c)({...i,dispatch:void 0})])),chain:()=>this.createChain(s,r)}}buildProps(t,e=!0){const{rawCommands:n,editor:r,state:s}=this,{view:i}=r,o={tr:t,editor:r,view:i,state:Vn({state:s,transaction:t}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(t,e),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(n).map(([l,a])=>[l,(...c)=>a(...c)(o)]))}};return o}},fe={};ps(fe,{blur:()=>ah,clearContent:()=>ch,clearNodes:()=>dh,command:()=>uh,createParagraphNear:()=>hh,cut:()=>fh,deleteCurrentNode:()=>ph,deleteNode:()=>mh,deleteRange:()=>gh,deleteSelection:()=>yh,enter:()=>bh,exitCode:()=>kh,extendMarkRange:()=>wh,first:()=>xh,focus:()=>Ch,forEach:()=>Mh,insertContent:()=>vh,insertContentAt:()=>Ah,joinBackward:()=>Rh,joinDown:()=>Oh,joinForward:()=>Dh,joinItemBackward:()=>Ih,joinItemForward:()=>Ph,joinTextblockBackward:()=>Lh,joinTextblockForward:()=>zh,joinUp:()=>Nh,keyboardShortcut:()=>$h,lift:()=>Hh,liftEmptyBlock:()=>Fh,liftListItem:()=>Vh,newlineInCode:()=>_h,resetAttributes:()=>Wh,scrollIntoView:()=>jh,selectAll:()=>qh,selectNodeBackward:()=>Kh,selectNodeForward:()=>Uh,selectParentNode:()=>Jh,selectTextblockEnd:()=>Xh,selectTextblockStart:()=>Gh,setContent:()=>Yh,setMark:()=>bf,setMeta:()=>kf,setNode:()=>wf,setNodeSelection:()=>xf,setTextDirection:()=>Sf,setTextSelection:()=>Cf,sinkListItem:()=>Mf,splitBlock:()=>vf,splitListItem:()=>Tf,toggleList:()=>Ef,toggleMark:()=>Af,toggleNode:()=>Nf,toggleWrap:()=>Of,undoInputRule:()=>Rf,unsetAllMarks:()=>Df,unsetMark:()=>If,unsetTextDirection:()=>Pf,updateAttributes:()=>Lf,wrapIn:()=>zf,wrapInList:()=>Bf});var ah=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),ch=(t=!0)=>({commands:e})=>e.setContent("",{emitUpdate:t}),dh=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:s}=r;return n&&s.forEach(({$from:i,$to:o})=>{t.doc.nodesBetween(i.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:d}=e,u=c.resolve(d.map(a)),h=c.resolve(d.map(a+l.nodeSize)),f=u.blockRange(h);if(!f)return;const p=At(f);if(l.type.isTextblock){const{defaultType:m}=u.parent.contentMatchAt(u.index());e.setNodeMarkup(f.start,m)}(p||p===0)&&e.lift(f,p)})}),!0},uh=t=>e=>t(e),hh=()=>({state:t,dispatch:e})=>sl(t,e),fh=(t,e)=>({editor:n,tr:r})=>{const{state:s}=n,i=s.doc.slice(t.from,t.to);r.deleteRange(t.from,t.to);const o=r.mapping.map(e);return r.insert(o,i.content),r.setSelection(new E(r.doc.resolve(Math.max(o-1,0)))),!0},ph=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const s=t.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===r.type){if(e){const l=s.before(i),a=s.after(i);t.delete(l,a).scrollIntoView()}return!0}return!1};function q(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}var mh=t=>({tr:e,state:n,dispatch:r})=>{const s=q(t,n.schema),i=e.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===s){if(r){const a=i.before(o),c=i.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},gh=t=>({tr:e,dispatch:n})=>{const{from:r,to:s}=t;return n&&e.delete(r,s),!0},yh=()=>({state:t,dispatch:e})=>Qr(t,e),bh=()=>({commands:t})=>t.keyboardShortcut("Enter"),kh=()=>({state:t,dispatch:e})=>id(t,e);function ms(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function Rn(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(s=>n.strict?e[s]===t[s]:ms(e[s])?e[s].test(t[s]):e[s]===t[s]):!0}function Wl(t,e,n={}){return t.find(r=>r.type===e&&Rn(Object.fromEntries(Object.keys(n).map(s=>[s,r.attrs[s]])),n))}function Ri(t,e,n={}){return!!Wl(t,e,n)}function gs(t,e,n){var r;if(!t||!e)return;let s=t.parent.childAfter(t.parentOffset);if((!s.node||!s.node.marks.some(d=>d.type===e))&&(s=t.parent.childBefore(t.parentOffset)),!s.node||!s.node.marks.some(d=>d.type===e)||(n=n||((r=s.node.marks[0])==null?void 0:r.attrs),!Wl([...s.node.marks],e,n)))return;let o=s.index,l=t.start()+s.offset,a=o+1,c=l+s.node.nodeSize;for(;o>0&&Ri([...t.parent.child(o-1).marks],e,n);)o-=1,l-=t.parent.child(o).nodeSize;for(;a({tr:n,state:r,dispatch:s})=>{const i=De(t,r.schema),{doc:o,selection:l}=n,{$from:a,from:c,to:d}=l;if(s){const u=gs(a,i,e);if(u&&u.from<=c&&u.to>=d){const h=E.create(o,u.from,u.to);n.setSelection(h)}}return!0},xh=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r({editor:n,view:r,tr:s,dispatch:i})=>{e={scrollIntoView:!0,...e};const o=()=>{(Kt()||Ir())&&r.dom.focus(),Sh()&&!Kt()&&!Ir()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&t===null||t===!1)return!0}catch{return!1}if(i&&t===null&&!jl(n.state.selection))return o(),!0;const l=ql(s.doc,t)||n.state.selection,a=n.state.selection.eq(l);return i&&(a||s.setSelection(l),a&&s.storedMarks&&s.setStoredMarks(s.storedMarks),o()),!0},Mh=(t,e)=>n=>t.every((r,s)=>e(r,{...n,index:s})),vh=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),Kl=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const r=e[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?t.removeChild(r):r.nodeType===1&&Kl(r)}return t};function It(t){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`${t}`,n=new window.DOMParser().parseFromString(e,"text/html").body;return Kl(n)}function Ut(t,e,n){if(t instanceof ge||t instanceof b)return t;n={slice:!0,parseOptions:{},...n};const r=typeof t=="object"&&t!==null,s=typeof t=="string";if(r)try{if(Array.isArray(t)&&t.length>0)return b.fromArray(t.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(t);return n.errorOnInvalidContent&&o.check(),o}catch(i){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:i});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",i),Ut("",e,n)}if(s){if(n.errorOnInvalidContent){let o=!1,l="";const a=new Ro({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(n.slice?Ne.fromSchema(a).parseSlice(It(t),n.parseOptions):Ne.fromSchema(a).parse(It(t),n.parseOptions),n.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const i=Ne.fromSchema(e);return n.slice?i.parseSlice(It(t),n.parseOptions).content:i.parse(It(t),n.parseOptions)}return Ut("",e,n)}function Th(t,e,n){const r=t.steps.length-1;if(r{o===0&&(o=d)}),t.setSelection(N.near(t.doc.resolve(o),n))}var Eh=t=>!("type"in t),Ah=(t,e,n)=>({tr:r,dispatch:s,editor:i})=>{var o;if(s){n={parseOptions:i.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l;const a=g=>{i.emit("contentError",{editor:i,error:g,disableCollaboration:()=>{"collaboration"in i.storage&&typeof i.storage.collaboration=="object"&&i.storage.collaboration&&(i.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!i.options.enableContentCheck&&i.options.emitContentError)try{Ut(e,i.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(g){a(g)}try{l=Ut(e,i.schema,{parseOptions:c,errorOnInvalidContent:(o=n.errorOnInvalidContent)!=null?o:i.options.enableContentCheck})}catch(g){return a(g),!1}let{from:d,to:u}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},h=!0,f=!0;if((Eh(l)?l:[l]).forEach(g=>{g.check(),h=h?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),d===u&&f){const{parent:g}=r.doc.resolve(d);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(d-=1,u+=1)}let m;if(h){if(Array.isArray(e))m=e.map(g=>g.text||"").join("");else if(e instanceof b){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;const g=r.doc.resolve(d),y=g.node(),k=g.parentOffset===0,w=y.isText||y.isTextblock,S=y.content.size>0;k&&w&&S&&(d=Math.max(0,d-1)),r.replaceWith(d,u,m)}n.updateSelection&&Th(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:m}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:m})}return!0},Nh=()=>({state:t,dispatch:e})=>nd(t,e),Oh=()=>({state:t,dispatch:e})=>rd(t,e),Rh=()=>({state:t,dispatch:e})=>Yo(t,e),Dh=()=>({state:t,dispatch:e})=>tl(t,e),Ih=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Ln(t.doc,t.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},Ph=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Ln(t.doc,t.selection.$from.pos,1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},Lh=()=>({state:t,dispatch:e})=>ed(t,e),zh=()=>({state:t,dispatch:e})=>td(t,e);function Ul(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Bh(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,s,i,o;for(let l=0;l({editor:e,view:n,tr:r,dispatch:s})=>{const i=Bh(t).split(/-(?!$)/),o=i.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{n.someProp("handleKeyDown",c=>c(n,l))});return a==null||a.steps.forEach(c=>{const d=c.map(r.mapping);d&&s&&r.maybeStep(d)}),!0};function qe(t,e,n={}){const{from:r,to:s,empty:i}=t.selection,o=e?q(e,t.schema):null,l=[];t.doc.nodesBetween(r,s,(u,h)=>{if(u.isText)return;const f=Math.max(r,h),p=Math.min(s,h+u.nodeSize);l.push({node:u,from:f,to:p})});const a=s-r,c=l.filter(u=>o?o.name===u.node.type.name:!0).filter(u=>Rn(u.node.attrs,n,{strict:!1}));return i?!!c.length:c.reduce((u,h)=>u+h.to-h.from,0)>=a}var Hh=(t,e={})=>({state:n,dispatch:r})=>{const s=q(t,n.schema);return qe(n,s,e)?sd(n,r):!1},Fh=()=>({state:t,dispatch:e})=>il(t,e),Vh=t=>({state:e,dispatch:n})=>{const r=q(t,e.schema);return gd(r)(e,n)},_h=()=>({state:t,dispatch:e})=>rl(t,e);function Wn(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function Di(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,s)=>(n.includes(s)||(r[s]=t[s]),r),{})}var Wh=(t,e)=>({tr:n,state:r,dispatch:s})=>{let i=null,o=null;const l=Wn(typeof t=="string"?t:t.name,r.schema);if(!l)return!1;l==="node"&&(i=q(t,r.schema)),l==="mark"&&(o=De(t,r.schema));let a=!1;return n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,u)=>{i&&i===d.type&&(a=!0,s&&n.setNodeMarkup(u,void 0,Di(d.attrs,e))),o&&d.marks.length&&d.marks.forEach(h=>{o===h.type&&(a=!0,s&&n.addMark(u,u+d.nodeSize,o.create(Di(h.attrs,e))))})})}),a},jh=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),qh=()=>({tr:t,dispatch:e})=>{if(e){const n=new le(t.doc);t.setSelection(n)}return!0},Kh=()=>({state:t,dispatch:e})=>Zo(t,e),Uh=()=>({state:t,dispatch:e})=>nl(t,e),Jh=()=>({state:t,dispatch:e})=>ad(t,e),Xh=()=>({state:t,dispatch:e})=>ud(t,e),Gh=()=>({state:t,dispatch:e})=>dd(t,e);function Pr(t,e,n={},r={}){return Ut(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var Yh=(t,{errorOnInvalidContent:e,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:s,tr:i,dispatch:o,commands:l})=>{const{doc:a}=i;if(r.preserveWhitespace!=="full"){const c=Pr(t,s.schema,r,{errorOnInvalidContent:e??s.options.enableContentCheck});return o&&i.replaceWith(0,a.content.size,c).setMeta("preventUpdate",!n),!0}return o&&i.setMeta("preventUpdate",!n),l.insertContentAt({from:0,to:a.content.size},t,{parseOptions:r,errorOnInvalidContent:e??s.options.enableContentCheck})};function Jl(t,e){const n=De(e,t.schema),{from:r,to:s,empty:i}=t.selection,o=[];i?(t.storedMarks&&o.push(...t.storedMarks),o.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,s,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===n.name);return l?{...l.attrs}:{}}function Xl(t,e){const n=new Gr(t);return e.forEach(r=>{r.steps.forEach(s=>{n.step(s)})}),n}function Qh(t){for(let e=0;e{n(s)&&r.push({node:s,pos:i})}),r}function Gl(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function jn(t){return e=>Gl(e.$from,t)}function M(t,e,n){return t.config[e]===void 0&&t.parent?M(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?M(t.parent,e,n):null}):t.config[e]}function qn(t){return t.map(e=>{const n={name:e.name,options:e.options,storage:e.storage},r=M(e,"addExtensions",n);return r?[e,...qn(r())]:e}).flat(10)}function ys(t,e){const n=ft.fromSchema(e).serializeFragment(t),s=document.implementation.createHTMLDocument().createElement("div");return s.appendChild(n),s.innerHTML}function Yl(t){return typeof t=="function"}function D(t,e=void 0,...n){return Yl(t)?e?t.bind(e)(...n):t(...n):t}function ef(t={}){return Object.keys(t).length===0&&t.constructor===Object}function vt(t){const e=t.filter(s=>s.type==="extension"),n=t.filter(s=>s.type==="node"),r=t.filter(s=>s.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Ql(t){const e=[],{nodeExtensions:n,markExtensions:r}=vt(t),s=[...n,...r],i={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return t.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage,extensions:s},a=M(o,"addGlobalAttributes",l);if(!a)return;a().forEach(d=>{d.types.forEach(u=>{Object.entries(d.attributes).forEach(([h,f])=>{e.push({type:u,name:h,attribute:{...i,...f}})})})})}),s.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=M(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([d,u])=>{const h={...i,...u};typeof(h==null?void 0:h.default)=="function"&&(h.default=h.default()),h!=null&&h.isRequired&&(h==null?void 0:h.default)===void 0&&delete h.default,e.push({type:o.name,name:d,attribute:h})})}),e}function I(...t){return t.filter(e=>!!e).reduce((e,n)=>{const r={...e};return Object.entries(n).forEach(([s,i])=>{if(!r[s]){r[s]=i;return}if(s==="class"){const l=i?String(i).split(" "):[],a=r[s]?r[s].split(" "):[],c=l.filter(d=>!a.includes(d));r[s]=[...a,...c].join(" ")}else if(s==="style"){const l=i?i.split(";").map(d=>d.trim()).filter(Boolean):[],a=r[s]?r[s].split(";").map(d=>d.trim()).filter(Boolean):[],c=new Map;a.forEach(d=>{const[u,h]=d.split(":").map(f=>f.trim());c.set(u,h)}),l.forEach(d=>{const[u,h]=d.split(":").map(f=>f.trim());c.set(u,h)}),r[s]=Array.from(c.entries()).map(([d,u])=>`${d}: ${u}`).join("; ")}else r[s]=i}),r},{})}function Tt(t,e){return e.filter(n=>n.type===t.type.name).filter(n=>n.attribute.rendered).map(n=>n.attribute.renderHTML?n.attribute.renderHTML(t.attrs)||{}:{[n.name]:t.attrs[n.name]}).reduce((n,r)=>I(n,r),{})}function tf(t){return typeof t!="string"?t:t.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(t):t==="true"?!0:t==="false"?!1:t}function Ii(t,e){return"style"in t?t:{...t,getAttrs:n=>{const r=t.getAttrs?t.getAttrs(n):t.attrs;if(r===!1)return!1;const s=e.reduce((i,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(n):tf(n.getAttribute(o.name));return l==null?i:{...i,[o.name]:l}},{});return{...r,...s}}}}function Pi(t){return Object.fromEntries(Object.entries(t).filter(([e,n])=>e==="attrs"&&ef(n)?!1:n!=null))}function Li(t){var e,n;const r={};return!((e=t==null?void 0:t.attribute)!=null&&e.isRequired)&&"default"in((t==null?void 0:t.attribute)||{})&&(r.default=t.attribute.default),((n=t==null?void 0:t.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=t.attribute.validate),[t.name,r]}function Zl(t,e){var n;const r=Ql(t),{nodeExtensions:s,markExtensions:i}=vt(t),o=(n=s.find(c=>M(c,"topNode")))==null?void 0:n.name,l=Object.fromEntries(s.map(c=>{const d=r.filter(y=>y.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},h=t.reduce((y,k)=>{const w=M(k,"extendNodeSchema",u);return{...y,...w?w(c):{}}},{}),f=Pi({...h,content:D(M(c,"content",u)),marks:D(M(c,"marks",u)),group:D(M(c,"group",u)),inline:D(M(c,"inline",u)),atom:D(M(c,"atom",u)),selectable:D(M(c,"selectable",u)),draggable:D(M(c,"draggable",u)),code:D(M(c,"code",u)),whitespace:D(M(c,"whitespace",u)),linebreakReplacement:D(M(c,"linebreakReplacement",u)),defining:D(M(c,"defining",u)),isolating:D(M(c,"isolating",u)),attrs:Object.fromEntries(d.map(Li))}),p=D(M(c,"parseHTML",u));p&&(f.parseDOM=p.map(y=>Ii(y,d)));const m=M(c,"renderHTML",u);m&&(f.toDOM=y=>m({node:y,HTMLAttributes:Tt(y,d)}));const g=M(c,"renderText",u);return g&&(f.toText=g),[c.name,f]})),a=Object.fromEntries(i.map(c=>{const d=r.filter(g=>g.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},h=t.reduce((g,y)=>{const k=M(y,"extendMarkSchema",u);return{...g,...k?k(c):{}}},{}),f=Pi({...h,inclusive:D(M(c,"inclusive",u)),excludes:D(M(c,"excludes",u)),group:D(M(c,"group",u)),spanning:D(M(c,"spanning",u)),code:D(M(c,"code",u)),attrs:Object.fromEntries(d.map(Li))}),p=D(M(c,"parseHTML",u));p&&(f.parseDOM=p.map(g=>Ii(g,d)));const m=M(c,"renderHTML",u);return m&&(f.toDOM=g=>m({mark:g,HTMLAttributes:Tt(g,d)})),[c.name,f]}));return new Ro({topNode:o,nodes:l,marks:a})}function nf(t){const e=t.filter((n,r)=>t.indexOf(n)!==r);return Array.from(new Set(e))}function Dn(t){return t.sort((n,r)=>{const s=M(n,"priority")||100,i=M(r,"priority")||100;return s>i?-1:sr.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(r=>`'${r}'`).join(", ")}]. This can lead to issues.`),e}function rf(t,e){const n=bs(t);return Zl(n,e)}function sf(t,e){const n=rf(e),r=It(t);return Ne.fromSchema(n).parse(r).toJSON()}function ea(t,e,n){const{from:r,to:s}=e,{blockSeparator:i=` `,textSerializers:o={}}=n||{};let l="";return t.nodesBetween(r,s,(a,c,d,u)=>{var h;a.isBlock&&c>r&&(l+=i);const f=o==null?void 0:o[a.type.name];if(f)return d&&(l+=f({node:a,pos:c,parent:d,index:u,range:e})),!1;a.isText&&(l+=(h=a==null?void 0:a.text)==null?void 0:h.slice(Math.max(r,c)-c,s-c))}),l}function of(t,e){const n={from:0,to:t.content.size};return ea(t,n,e)}function ta(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}function lf(t,e){const n=q(e,t.schema),{from:r,to:s}=t.selection,i=[];t.doc.nodesBetween(r,s,l=>{i.push(l)});const o=i.reverse().find(l=>l.type.name===n.name);return o?{...o.attrs}:{}}function na(t,e){const n=Wn(typeof e=="string"?e:e.name,t.schema);return n==="node"?lf(t,e):n==="mark"?Jl(t,e):{}}function af(t,e=JSON.stringify){const n={};return t.filter(r=>{const s=e(r);return Object.prototype.hasOwnProperty.call(n,s)?!1:n[s]=!0})}function cf(t){const e=af(t);return e.length===1?e:e.filter((n,r)=>!e.filter((i,o)=>o!==r).some(i=>n.oldRange.from>=i.oldRange.from&&n.oldRange.to<=i.oldRange.to&&n.newRange.from>=i.newRange.from&&n.newRange.to<=i.newRange.to))}function ra(t){const{mapping:e,steps:n}=t,r=[];return e.maps.forEach((s,i)=>{const o=[];if(s.ranges.length)s.forEach((l,a)=>{o.push({from:l,to:a})});else{const{from:l,to:a}=n[i];if(l===void 0||a===void 0)return;o.push({from:l,to:a})}o.forEach(({from:l,to:a})=>{const c=e.slice(i).map(l,-1),d=e.slice(i).map(a),u=e.invert().map(c,-1),h=e.invert().map(d);r.push({oldRange:{from:u,to:h},newRange:{from:c,to:d}})})}),cf(r)}function ks(t,e,n){const r=[];return t===e?n.resolve(t).marks().forEach(s=>{const i=n.resolve(t),o=gs(i,s.type);o&&r.push({mark:s,...o})}):n.nodesBetween(t,e,(s,i)=>{!s||(s==null?void 0:s.nodeSize)===void 0||r.push(...s.marks.map(o=>({from:i,to:i+s.nodeSize,mark:o})))}),r}var df=(t,e,n,r=20)=>{const s=t.doc.resolve(n);let i=r,o=null;for(;i>0&&o===null;){const l=s.node(i);(l==null?void 0:l.type.name)===e?o=l:i-=1}return[o,i]};function sn(t,e){return e.nodes[t]||e.marks[t]||null}function yn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const s=t.find(i=>i.type===e&&i.name===r);return s?s.attribute.keepOnSplit:!1}))}var uf=(t,e=500)=>{let n="";const r=t.parentOffset;return t.parent.nodesBetween(Math.max(0,r-e),r,(s,i,o,l)=>{var a,c;const d=((c=(a=s.type.spec).toText)==null?void 0:c.call(a,{node:s,pos:i,parent:o,index:l}))||s.textContent||"%leaf%";n+=s.isAtom&&!s.isText?d:d.slice(0,Math.max(0,r-i))}),n};function Lr(t,e,n={}){const{empty:r,ranges:s}=t.selection,i=e?De(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(u=>i?i.name===u.type.name:!0).find(u=>Rn(u.attrs,n,{strict:!1}));let o=0;const l=[];if(s.forEach(({$from:u,$to:h})=>{const f=u.pos,p=h.pos;t.doc.nodesBetween(f,p,(m,g)=>{if(!m.isText&&!m.marks.length)return;const y=Math.max(f,g),k=Math.min(p,g+m.nodeSize),w=k-y;o+=w,l.push(...m.marks.map(S=>({mark:S,from:y,to:k})))})}),o===0)return!1;const a=l.filter(u=>i?i.name===u.mark.type.name:!0).filter(u=>Rn(u.mark.attrs,n,{strict:!1})).reduce((u,h)=>u+h.to-h.from,0),c=l.filter(u=>i?u.mark.type!==i&&u.mark.type.excludes(i):!0).reduce((u,h)=>u+h.to-h.from,0);return(a>0?a+c:a)>=o}function hf(t,e,n={}){if(!e)return qe(t,null,n)||Lr(t,null,n);const r=Wn(e,t.schema);return r==="node"?qe(t,e,n):r==="mark"?Lr(t,e,n):!1}var ff=(t,e)=>{const{$from:n,$to:r,$anchor:s}=t.selection;if(e){const i=jn(l=>l.type.name===e)(t.selection);if(!i)return!1;const o=t.doc.resolve(i.pos+1);return s.pos+1===o.end()}return!(r.parentOffset{const{$from:e,$to:n}=t.selection;return!(e.parentOffset>0||e.pos!==n.pos)};function zi(t,e){return Array.isArray(e)?e.some(n=>(typeof n=="string"?n:n.name)===t.name):e}function Bi(t,e){const{nodeExtensions:n}=vt(e),r=n.find(o=>o.name===t);if(!r)return!1;const s={name:r.name,options:r.options,storage:r.storage},i=D(M(r,"group",s));return typeof i!="string"?!1:i.split(" ").includes("list")}function Kn(t,{checkChildren:e=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if(t.type.name==="hardBreak")return!0;if(t.isText)return/^\s*$/m.test((r=t.text)!=null?r:"")}if(t.isText)return!t.text;if(t.isAtom||t.isLeaf)return!1;if(t.content.childCount===0)return!0;if(e){let s=!0;return t.content.forEach(i=>{s!==!1&&(Kn(i,{ignoreWhitespace:n,checkChildren:e})||(s=!1))}),s}return!1}function sa(t){return t instanceof T}var ia=class oa{constructor(e){this.position=e}static fromJSON(e){return new oa(e.position)}toJSON(){return{position:this.position}}};function mf(t,e){const n=e.mapping.mapResult(t.position);return{position:new ia(n.pos),mapResult:n}}function gf(t){return new ia(t)}function yf(t,e,n){var r;const{selection:s}=e;let i=null;if(jl(s)&&(i=s.$cursor),i){const l=(r=t.storedMarks)!=null?r:i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(l)||!l.some(c=>c.type.excludes(n)))}const{ranges:o}=s;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(l.pos,a.pos,(d,u,h)=>{if(c)return!1;if(d.isInline){const f=!h||h.type.allowsMarkType(n),p=!!n.isInSet(d.marks)||!d.marks.some(m=>m.type.excludes(n));c=f&&p}return!c}),c})}var bf=(t,e={})=>({tr:n,state:r,dispatch:s})=>{const{selection:i}=n,{empty:o,ranges:l}=i,a=De(t,r.schema);if(s)if(o){const c=Jl(r,a);n.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const d=c.$from.pos,u=c.$to.pos;r.doc.nodesBetween(d,u,(h,f)=>{const p=Math.max(f,d),m=Math.min(f+h.nodeSize,u);h.marks.find(y=>y.type===a)?h.marks.forEach(y=>{a===y.type&&n.addMark(p,m,a.create({...y.attrs,...e}))}):n.addMark(p,m,a.create(e))})});return yf(r,n,a)},kf=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),wf=(t,e={})=>({state:n,dispatch:r,chain:s})=>{const i=q(t,n.schema);let o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),i.isTextblock?s().command(({commands:l})=>Ys(i,{...o,...e})(n)?!0:l.clearNodes()).command(({state:l})=>Ys(i,{...o,...e})(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},xf=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,s=Ze(t,0,r.content.size),i=T.create(r,s);e.setSelection(i)}return!0},Sf=(t,e)=>({tr:n,state:r,dispatch:s})=>{const{selection:i}=r;let o,l;return typeof e=="number"?(o=e,l=e):e&&"from"in e&&"to"in e?(o=e.from,l=e.to):(o=i.from,l=i.to),s&&n.doc.nodesBetween(o,l,(a,c)=>{a.isText||n.setNodeMarkup(c,void 0,{...a.attrs,dir:t})}),!0},Cf=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:s,to:i}=typeof t=="number"?{from:t,to:t}:t,o=E.atStart(r).from,l=E.atEnd(r).to,a=Ze(s,o,l),c=Ze(i,o,l),d=E.create(r,a,c);e.setSelection(d)}return!0},Mf=t=>({state:e,dispatch:n})=>{const r=q(t,e.schema);return kd(r)(e,n)};function $i(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(s=>e==null?void 0:e.includes(s.type.name));t.tr.ensureMarks(r)}}var vf=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:s})=>{const{selection:i,doc:o}=e,{$from:l,$to:a}=i,c=s.extensionManager.attributes,d=yn(c,l.node().type.name,l.node().attrs);if(i instanceof T&&i.node.isBlock)return!l.parentOffset||!Oe(o,l.pos)?!1:(r&&(t&&$i(n,s.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const u=a.parentOffset===a.parent.content.size,h=l.depth===0?void 0:Qh(l.node(-1).contentMatchAt(l.indexAfter(-1)));let f=u&&h?[{type:h,attrs:d}]:void 0,p=Oe(e.doc,e.mapping.map(l.pos),1,f);if(!f&&!p&&Oe(e.doc,e.mapping.map(l.pos),1,h?[{type:h}]:void 0)&&(p=!0,f=h?[{type:h,attrs:d}]:void 0),r){if(p&&(i instanceof E&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,f),h&&!u&&!l.parentOffset&&l.parent.type!==h)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,h)&&e.setNodeMarkup(e.mapping.map(l.before()),h)}t&&$i(n,s.extensionManager.splittableMarks),e.scrollIntoView()}return p},Tf=(t,e={})=>({tr:n,state:r,dispatch:s,editor:i})=>{var o;const l=q(t,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 h=i.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(s){let y=b.empty;const k=a.index(-1)?1:a.index(-2)?2:3;for(let O=a.depth-k;O>=a.depth-3;O-=1)y=b.from(a.node(O).copy(y));const w=a.indexAfter(-1){if(v>-1)return!1;O.isTextblock&&O.content.size===0&&(v=R+1)}),v>-1&&n.setSelection(E.near(n.doc.resolve(v))),n.scrollIntoView()}return!0}const f=c.pos===a.end()?u.contentMatchAt(0).defaultType:null,p={...yn(h,u.type.name,u.attrs),...e},m={...yn(h,a.node().type.name,a.node().attrs),...e};n.delete(a.pos,c.pos);const g=f?[{type:l,attrs:p},{type:f,attrs:m}]:[{type:l,attrs:p}];if(!Oe(n.doc,a.pos,2))return!1;if(s){const{selection:y,storedMarks:k}=r,{splittableMarks:w}=i.extensionManager,S=k||y.$to.parentOffset&&y.$from.marks();if(n.split(a.pos,2,g).scrollIntoView(),!S||!s)return!0;const C=S.filter(A=>w.includes(A.type.name));n.ensureMarks(C)}return!0},ur=(t,e)=>{const n=jn(o=>o.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const s=t.doc.nodeAt(r);return n.node.type===(s==null?void 0:s.type)&&Ue(t.doc,n.pos)&&t.join(n.pos),!0},hr=(t,e)=>{const n=jn(o=>o.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const s=t.doc.nodeAt(r);return n.node.type===(s==null?void 0:s.type)&&Ue(t.doc,r)&&t.join(r),!0},Ef=(t,e,n,r={})=>({editor:s,tr:i,state:o,dispatch:l,chain:a,commands:c,can:d})=>{const{extensions:u,splittableMarks:h}=s.extensionManager,f=q(t,o.schema),p=q(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:k}=m,w=y.blockRange(k),S=g||m.$to.parentOffset&&m.$from.marks();if(!w)return!1;const C=jn(A=>Bi(A.type.name,u))(m);if(w.depth>=1&&C&&w.depth-C.depth<=1){if(C.node.type===f)return c.liftListItem(p);if(Bi(C.node.type.name,u)&&f.validContent(C.node.content)&&l)return a().command(()=>(i.setNodeMarkup(C.pos,f),!0)).command(()=>ur(i,f)).command(()=>hr(i,f)).run()}return!n||!S||!l?a().command(()=>d().wrapInList(f,r)?!0:c.clearNodes()).wrapInList(f,r).command(()=>ur(i,f)).command(()=>hr(i,f)).run():a().command(()=>{const A=d().wrapInList(f,r),v=S.filter(O=>h.includes(O.type.name));return i.ensureMarks(v),A?!0:c.clearNodes()}).wrapInList(f,r).command(()=>ur(i,f)).command(()=>hr(i,f)).run()},Af=(t,e={},n={})=>({state:r,commands:s})=>{const{extendEmptyMarkRange:i=!1}=n,o=De(t,r.schema);return Lr(r,o,e)?s.unsetMark(o,{extendEmptyMarkRange:i}):s.setMark(o,e)},Nf=(t,e,n={})=>({state:r,commands:s})=>{const i=q(t,r.schema),o=q(e,r.schema),l=qe(r,i,n);let a;return r.selection.$anchor.sameParent(r.selection.$head)&&(a=r.selection.$anchor.parent.attrs),l?s.setNode(o,a):s.setNode(i,{...a,...n})},Of=(t,e={})=>({state:n,commands:r})=>{const s=q(t,n.schema);return qe(n,s,e)?r.lift(s):r.wrapIn(s,e)},Rf=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(i.text){const a=o.doc.resolve(i.from).marks();o.replaceWith(i.from,i.to,t.schema.text(i.text,a))}else o.delete(i.from,i.to)}return!0}}return!1},Df=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:s}=n;return r||e&&s.forEach(i=>{t.removeMark(i.$from.pos,i.$to.pos)}),!0},If=(t,e={})=>({tr:n,state:r,dispatch:s})=>{var i;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=n,a=De(t,r.schema),{$from:c,empty:d,ranges:u}=l;if(!s)return!0;if(d&&o){let{from:h,to:f}=l;const p=(i=c.marks().find(g=>g.type===a))==null?void 0:i.attrs,m=gs(c,a,p);m&&(h=m.from,f=m.to),n.removeMark(h,f,a)}else u.forEach(h=>{n.removeMark(h.$from.pos,h.$to.pos,a)});return n.removeStoredMark(a),!0},Pf=t=>({tr:e,state:n,dispatch:r})=>{const{selection:s}=n;let i,o;return typeof t=="number"?(i=t,o=t):t&&"from"in t&&"to"in t?(i=t.from,o=t.to):(i=s.from,o=s.to),r&&e.doc.nodesBetween(i,o,(l,a)=>{if(l.isText)return;const c={...l.attrs};delete c.dir,e.setNodeMarkup(a,void 0,c)}),!0},Lf=(t,e={})=>({tr:n,state:r,dispatch:s})=>{let i=null,o=null;const l=Wn(typeof t=="string"?t:t.name,r.schema);if(!l)return!1;l==="node"&&(i=q(t,r.schema)),l==="mark"&&(o=De(t,r.schema));let a=!1;return n.selection.ranges.forEach(c=>{const d=c.$from.pos,u=c.$to.pos;let h,f,p,m;n.selection.empty?r.doc.nodesBetween(d,u,(g,y)=>{i&&i===g.type&&(a=!0,p=Math.max(y,d),m=Math.min(y+g.nodeSize,u),h=y,f=g)}):r.doc.nodesBetween(d,u,(g,y)=>{y=d&&y<=u&&(i&&i===g.type&&(a=!0,s&&n.setNodeMarkup(y,void 0,{...g.attrs,...e})),o&&g.marks.length&&g.marks.forEach(k=>{if(o===k.type&&(a=!0,s)){const w=Math.max(y,d),S=Math.min(y+g.nodeSize,u);n.addMark(w,S,o.create({...k.attrs,...e}))}}))}),f&&(h!==void 0&&s&&n.setNodeMarkup(h,void 0,{...f.attrs,...e}),o&&f.marks.length&&f.marks.forEach(g=>{o===g.type&&s&&n.addMark(p,m,o.create({...g.attrs,...e}))}))}),a},zf=(t,e={})=>({state:n,dispatch:r})=>{const s=q(t,n.schema);return hd(s,e)(n,r)},Bf=(t,e={})=>({state:n,dispatch:r})=>{const s=q(t,n.schema);return fd(s,e)(n,r)},$f=class{constructor(){this.callbacks={}}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this}emit(t,...e){const n=this.callbacks[t];return n&&n.forEach(r=>r.apply(this,e)),this}off(t,e){const n=this.callbacks[t];return n&&(e?this.callbacks[t]=n.filter(r=>r!==e):delete this.callbacks[t]),this}once(t,e){const n=(...r)=>{this.off(t,n),e.apply(this,r)};return this.on(t,n)}removeAllListeners(){this.callbacks={}}},Qt=class{constructor(t){var e;this.find=t.find,this.handler=t.handler,this.undoable=(e=t.undoable)!=null?e:!0}},Hf=(t,e)=>{if(ms(e))return e.exec(t);const n=e(t);if(!n)return null;const r=[n.text];return r.index=n.index,r.input=t,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r};function on(t){var e;const{editor:n,from:r,to:s,text:i,rules:o,plugin:l}=t,{view:a}=n;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.marks.find(h=>h.type.spec.code))return!1;let d=!1;const u=uf(c)+i;return o.forEach(h=>{if(d)return;const f=Hf(u,h.find);if(!f)return;const p=a.state.tr,m=Vn({state:a.state,transaction:p}),g={from:r-(f[0].length-i.length),to:s},{commands:y,chain:k,can:w}=new _n({editor:n,state:m});h.handler({state:m,range:g,match:f,commands:y,chain:k,can:w})===null||!p.steps.length||(h.undoable&&p.setMeta(l,{transform:p,from:r,to:s,text:i}),a.dispatch(p),d=!0)}),d}function Ff(t){const{editor:e,rules:n}=t,r=new B({state:{init(){return null},apply(s,i,o){const l=s.getMeta(r);if(l)return l;const a=s.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:d}=a;typeof d=="string"?d=d:d=ys(b.from(d),o.schema);const{from:u}=a,h=u+d.length;on({editor:e,from:u,to:h,text:d,rules:n,plugin:r})}),s.selectionSet||s.docChanged?null:i}},props:{handleTextInput(s,i,o,l){return on({editor:e,from:i,to:o,text:l,rules:n,plugin:r})},handleDOMEvents:{compositionend:s=>(setTimeout(()=>{const{$cursor:i}=s.state.selection;i&&on({editor:e,from:i.pos,to:i.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(s,i){if(i.key!=="Enter")return!1;const{$cursor:o}=s.state.selection;return o?on({editor:e,from:o.pos,to:o.pos,text:` `,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function Vf(t){return Object.prototype.toString.call(t).slice(8,-1)}function ln(t){return Vf(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function la(t,e){const n={...t};return ln(t)&&ln(e)&&Object.keys(e).forEach(r=>{ln(e[r])&&ln(t[r])?n[r]=la(t[r],e[r]):n[r]=e[r]}),n}var ws=class{constructor(t={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...t},this.name=this.config.name}get options(){return{...D(M(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...D(M(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(t={}){const e=this.extend({...this.config,addOptions:()=>la(this.options,t)});return e.name=this.name,e.parent=this.parent,e}extend(t={}){const e=new this.constructor({...this.config,...t});return e.parent=this,this.child=e,e.name="name"in t?t.name:e.parent.name,e}},xe=class aa extends ws{constructor(){super(...arguments),this.type="mark"}static create(e={}){const n=typeof e=="function"?e():e;return new aa(n)}static handleExit({editor:e,mark:n}){const{tr:r}=e.state,s=e.state.selection.$from;if(s.pos===s.end()){const o=s.marks();if(!!!o.find(c=>(c==null?void 0:c.type.name)===n.name))return!1;const a=o.find(c=>(c==null?void 0:c.type.name)===n.name);return a&&r.removeStoredMark(a),r.insertText(" ",s.pos),e.view.dispatch(r),!0}return!1}configure(e){return super.configure(e)}extend(e){const n=typeof e=="function"?e():e;return super.extend(n)}};function _f(t){return typeof t=="number"}var Wf=class{constructor(t){this.find=t.find,this.handler=t.handler}},jf=(t,e,n)=>{if(ms(e))return[...t.matchAll(e)];const r=e(t,n);return r?r.map(s=>{const i=[s.text];return i.index=s.index,i.input=t,i.data=s.data,s.replaceWith&&(s.text.includes(s.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),i.push(s.replaceWith)),i}):[]};function qf(t){const{editor:e,state:n,from:r,to:s,rule:i,pasteEvent:o,dropEvent:l}=t,{commands:a,chain:c,can:d}=new _n({editor:e,state:n}),u=[];return n.doc.nodesBetween(r,s,(f,p)=>{var m,g,y,k,w;if((g=(m=f.type)==null?void 0:m.spec)!=null&&g.code||!(f.isText||f.isTextblock||f.isInline))return;const S=(w=(k=(y=f.content)==null?void 0:y.size)!=null?k:f.nodeSize)!=null?w:0,C=Math.max(r,p),A=Math.min(s,p+S);if(C>=A)return;const v=f.isText?f.text||"":f.textBetween(C-p,A-p,void 0,"");jf(v,i.find,o).forEach(R=>{if(R.index===void 0)return;const Ce=C+R.index+1,Xn=Ce+R[0].length,en={from:n.tr.mapping.map(Ce),to:n.tr.mapping.map(Xn)},Gn=i.handler({state:n,range:en,match:R,commands:a,chain:c,can:d,pasteEvent:o,dropEvent:l});u.push(Gn)})}),u.every(f=>f!==null)}var an=null,Kf=t=>{var e;const n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=n.clipboardData)==null||e.setData("text/html",t),n};function Uf(t){const{editor:e,rules:n}=t;let r=null,s=!1,i=!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:h,rule:f,pasteEvt:p})=>{const m=d.tr,g=Vn({state:d,transaction:m});if(!(!qf({editor:e,state:g,from:Math.max(u-1,0),to:h.b-1,rule:f,pasteEvent:p,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 n.map(d=>new B({view(u){const h=p=>{var m;r=(m=u.dom.parentElement)!=null&&m.contains(p.target)?u.dom.parentElement:null,r&&(an=e)},f=()=>{an&&(an=null)};return window.addEventListener("dragstart",h),window.addEventListener("dragend",f),{destroy(){window.removeEventListener("dragstart",h),window.removeEventListener("dragend",f)}}},props:{handleDOMEvents:{drop:(u,h)=>{if(i=r===u.dom.parentElement,l=h,!i){const f=an;f!=null&&f.isEditable&&setTimeout(()=>{const p=f.state.selection;p&&f.commands.deleteRange({from:p.from,to:p.to})},10)}return!1},paste:(u,h)=>{var f;const p=(f=h.clipboardData)==null?void 0:f.getData("text/html");return o=h,s=!!(p!=null&&p.includes("data-pm-slice")),!1}}},appendTransaction:(u,h,f)=>{const p=u[0],m=p.getMeta("uiEvent")==="paste"&&!s,g=p.getMeta("uiEvent")==="drop"&&!i,y=p.getMeta("applyPasteRules"),k=!!y;if(!m&&!g&&!k)return;if(k){let{text:C}=y;typeof C=="string"?C=C:C=ys(b.from(C),f.schema);const{from:A}=y,v=A+C.length,O=Kf(C);return a({rule:d,state:f,from:A,to:{b:v},pasteEvt:O})}const w=h.doc.content.findDiffStart(f.doc.content),S=h.doc.content.findDiffEnd(f.doc.content);if(!(!_f(w)||!S||w===S.b))return a({rule:d,state:f,from:w,to:S,pasteEvt:o})}}))}var Un=class{constructor(t,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=t,this.extensions=bs(t),this.schema=Zl(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((t,e)=>{const n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:sn(e.name,this.schema)},r=M(e,"addCommands",n);return r?{...t,...r()}:t},{})}get plugins(){const{editor:t}=this;return Dn([...this.extensions].reverse()).flatMap(r=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:t,type:sn(r.name,this.schema)},i=[],o=M(r,"addKeyboardShortcuts",s);let l={};if(r.type==="mark"&&M(r,"exitable",s)&&(l.ArrowRight=()=>xe.handleExit({editor:t,mark:r})),o){const h=Object.fromEntries(Object.entries(o()).map(([f,p])=>[f,()=>p({editor:t})]));l={...l,...h}}const a=oh(l);i.push(a);const c=M(r,"addInputRules",s);if(zi(r,t.options.enableInputRules)&&c){const h=c();if(h&&h.length){const f=Ff({editor:t,rules:h}),p=Array.isArray(f)?f:[f];i.push(...p)}}const d=M(r,"addPasteRules",s);if(zi(r,t.options.enablePasteRules)&&d){const h=d();if(h&&h.length){const f=Uf({editor:t,rules:h});i.push(...f)}}const u=M(r,"addProseMirrorPlugins",s);if(u){const h=u();i.push(...h)}return i})}get attributes(){return Ql(this.extensions)}get nodeViews(){const{editor:t}=this,{nodeExtensions:e}=vt(this.extensions);return Object.fromEntries(e.filter(n=>!!M(n,"addNodeView")).map(n=>{const r=this.attributes.filter(a=>a.type===n.name),s={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:q(n.name,this.schema)},i=M(n,"addNodeView",s);if(!i)return[];const o=i();if(!o)return[];const l=(a,c,d,u,h)=>{const f=Tt(a,r);return o({node:a,view:c,getPos:d,decorations:u,innerDecorations:h,editor:t,extension:n,HTMLAttributes:f})};return[n.name,l]}))}dispatchTransaction(t){const{editor:e}=this;return Dn([...this.extensions].reverse()).reduceRight((r,s)=>{const i={name:s.name,options:s.options,storage:this.editor.extensionStorage[s.name],editor:e,type:sn(s.name,this.schema)},o=M(s,"dispatchTransaction",i);return o?l=>{o.call(i,{transaction:l,next:r})}:r},t)}get markViews(){const{editor:t}=this,{markExtensions:e}=vt(this.extensions);return Object.fromEntries(e.filter(n=>!!M(n,"addMarkView")).map(n=>{const r=this.attributes.filter(l=>l.type===n.name),s={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:De(n.name,this.schema)},i=M(n,"addMarkView",s);if(!i)return[];const o=(l,a,c)=>{const d=Tt(l,r);return i()({mark:l,view:a,inline:c,editor:t,extension:n,HTMLAttributes:d,updateAttributes:u=>{ap(l,t,u)}})};return[n.name,o]}))}setupExtensions(){const t=this.extensions;this.editor.extensionStorage=Object.fromEntries(t.map(e=>[e.name,e.storage])),t.forEach(e=>{var n;const r={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:sn(e.name,this.schema)};e.type==="mark"&&((n=D(M(e,"keepOnSplit",r)))==null||n)&&this.splittableMarks.push(e.name);const s=M(e,"onBeforeCreate",r),i=M(e,"onCreate",r),o=M(e,"onUpdate",r),l=M(e,"onSelectionUpdate",r),a=M(e,"onTransaction",r),c=M(e,"onFocus",r),d=M(e,"onBlur",r),u=M(e,"onDestroy",r);s&&this.editor.on("beforeCreate",s),i&&this.editor.on("create",i),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)})}};Un.resolve=bs;Un.sort=Dn;Un.flatten=qn;var Jf={};ps(Jf,{ClipboardTextSerializer:()=>da,Commands:()=>ua,Delete:()=>ha,Drop:()=>fa,Editable:()=>pa,FocusEvents:()=>ga,Keymap:()=>ya,Paste:()=>ba,Tabindex:()=>ka,TextDirection:()=>wa,focusEventsPluginKey:()=>ma});var $=class ca extends ws{constructor(){super(...arguments),this.type="extension"}static create(e={}){const n=typeof e=="function"?e():e;return new ca(n)}configure(e){return super.configure(e)}extend(e){const n=typeof e=="function"?e():e;return super.extend(n)}},da=$.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new B({key:new _("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:s}=e,{ranges:i}=s,o=Math.min(...i.map(d=>d.$from.pos)),l=Math.max(...i.map(d=>d.$to.pos)),a=ta(n);return ea(r,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),ua=$.create({name:"commands",addCommands(){return{...fe}}}),ha=$.create({name:"delete",onUpdate({transaction:t,appendedTransactions:e}){var n,r,s;const i=()=>{var o,l,a,c;if((c=(a=(l=(o=this.editor.options.coreExtensionOptions)==null?void 0:o.delete)==null?void 0:l.filterTransaction)==null?void 0:a.call(l,t))!=null?c:t.getMeta("y-sync$"))return;const d=Xl(t.before,[t,...e]);ra(d).forEach(f=>{d.mapping.mapResult(f.oldRange.from).deletedAfter&&d.mapping.mapResult(f.oldRange.to).deletedBefore&&d.before.nodesBetween(f.oldRange.from,f.oldRange.to,(p,m)=>{const g=m+p.nodeSize-2,y=f.oldRange.from<=m&&g<=f.oldRange.to;this.editor.emit("delete",{type:"node",node:p,from:m,to:g,newFrom:d.mapping.map(m),newTo:d.mapping.map(g),deletedRange:f.oldRange,newRange:f.newRange,partial:!y,editor:this.editor,transaction:t,combinedTransform:d})})});const h=d.mapping;d.steps.forEach((f,p)=>{var m,g;if(f instanceof me){const y=h.slice(p).map(f.from,-1),k=h.slice(p).map(f.to),w=h.invert().map(y,-1),S=h.invert().map(k),C=(m=d.doc.nodeAt(y-1))==null?void 0:m.marks.some(v=>v.eq(f.mark)),A=(g=d.doc.nodeAt(k))==null?void 0:g.marks.some(v=>v.eq(f.mark));this.editor.emit("delete",{type:"mark",mark:f.mark,from:f.from,to:f.to,deletedRange:{from:w,to:S},newRange:{from:y,to:k},partial:!!(A||C),editor:this.editor,transaction:t,combinedTransform:d})}})};(s=(r=(n=this.editor.options.coreExtensionOptions)==null?void 0:n.delete)==null?void 0:r.async)==null||s?setTimeout(i,0):i()}}),fa=$.create({name:"drop",addProseMirrorPlugins(){return[new B({key:new _("tiptapDrop"),props:{handleDrop:(t,e,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:r})}}})]}}),pa=$.create({name:"editable",addProseMirrorPlugins(){return[new B({key:new _("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ma=new _("focusEvents"),ga=$.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new B({key:ma,props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),ya=$.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:d,$anchor:u}=a,{pos:h,parent:f}=u,p=u.parent.isTextblock&&h>0?l.doc.resolve(h-1):u,m=p.parent.type.spec.isolating,g=u.pos-u.parentOffset,y=m&&p.parent.childCount===1?g===u.pos:N.atStart(c).from===h;return!d||!f.type.isTextblock||f.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:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},s={...r},i={...r,"Ctrl-h":t,"Alt-Backspace":t,"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 Kt()||Ul()?i:s},addProseMirrorPlugins(){return[new B({key:new _("clearDocument"),appendTransaction:(t,e,n)=>{if(t.some(m=>m.getMeta("composition")))return;const r=t.some(m=>m.docChanged)&&!e.doc.eq(n.doc),s=t.some(m=>m.getMeta("preventClearDocument"));if(!r||s)return;const{empty:i,from:o,to:l}=e.selection,a=N.atStart(e.doc).from,c=N.atEnd(e.doc).to;if(i||!(o===a&&l===c)||!Kn(n.doc))return;const h=n.tr,f=Vn({state:n,transaction:h}),{commands:p}=new _n({editor:this.editor,state:f});if(p.clearNodes(),!!h.steps.length)return h}})]}}),ba=$.create({name:"paste",addProseMirrorPlugins(){return[new B({key:new _("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}}),ka=$.create({name:"tabindex",addProseMirrorPlugins(){return[new B({key:new _("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),wa=$.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:t}=vt(this.extensions);return[{types:t.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const n=e.getAttribute("dir");return n&&(n==="ltr"||n==="rtl"||n==="auto")?n:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new B({key:new _("textDirection"),props:{attributes:()=>{const t=this.options.direction;return t?{dir:t}:{}}}})]}}),Xf=class Pt{constructor(e,n,r=!1,s=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=n,this.currentNode=s}get name(){return this.node.type.name}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:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let n=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}n=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:n,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),n=this.resolvedPos.doc.resolve(e);return new Pt(n,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 Pt(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 Pt(e,this.editor)}get children(){const e=[];return this.node.content.forEach((n,r)=>{const s=n.isBlock&&!n.isTextblock,i=n.isAtom&&!n.isText,o=n.isInline,l=this.pos+r+(i?0:1);if(l<0||l>this.resolvedPos.doc.nodeSize-2)return;const a=this.resolvedPos.doc.resolve(l);if(!s&&!o&&a.depth<=this.depth)return;const c=new Pt(a,this.editor,s,s||o?n:null);s&&(c.actualDepth=this.depth+1),e.push(c)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,n={}){let r=null,s=this.parent;for(;s&&!r;){if(s.node.type.name===e)if(Object.keys(n).length>0){const i=s.node.attrs,o=Object.keys(n);for(let l=0;l{r&&s.length>0||(o.node.type.name===e&&i.every(a=>n[a]===o.node.attrs[a])&&s.push(o),!(r&&s.length>0)&&(s=s.concat(o.querySelectorAll(e,n,r))))}),s}setAttribute(e){const{tr:n}=this.editor.state;n.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(n)}},Gf=`.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; }`;function Yf(t,e,n){const r=document.querySelector("style[data-tiptap-style]");if(r!==null)return r;const s=document.createElement("style");return e&&s.setAttribute("nonce",e),s.setAttribute("data-tiptap-style",""),s.innerHTML=t,document.getElementsByTagName("head")[0].appendChild(s),s}var Qf=class extends $f{constructor(t={}){super(),this.css=null,this.className="tiptap",this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<"u"?document.createElement("div"):null,content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:r})=>{throw r},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:mf,createMappablePosition:gf},this.setOptions(t),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("mount",this.options.onMount),this.on("unmount",this.options.onUnmount),this.on("contentError",this.options.onContentError),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:r,slice:s,moved:i})=>this.options.onDrop(r,s,i)),this.on("paste",({event:r,slice:s})=>this.options.onPaste(r,s)),this.on("delete",this.options.onDelete);const e=this.createDoc(),n=ql(e,this.options.autofocus);this.editorState=bt.create({doc:e,schema:this.schema,selection:n||void 0}),this.options.element&&this.mount(this.options.element)}mount(t){if(typeof document>"u")throw new Error("[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.");this.createView(t),this.emit("mount",{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){const t=this.editorView.dom;t!=null&&t.editor&&delete t.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove=="function"?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(t){console.warn("Failed to remove CSS element:",t)}this.css=null,this.emit("unmount",{editor:this})}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&&typeof document<"u"&&(this.css=Yf(Gf,this.options.injectNonce))}setOptions(t={}){this.options={...this.options,...t},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(t,e=!0){this.setOptions({editable:t}),e&&this.emit("update",{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:t=>{this.editorState=t},dispatch:t=>{this.dispatchTransaction(t)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(t,e)=>{if(this.editorView)return this.editorView[e];if(e==="state")return this.editorState;if(e in t)return Reflect.get(t,e);throw new Error(`[tiptap error]: The editor view is not available. Cannot access view['${e}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(t,e){const n=Yl(e)?e(t,[...this.state.plugins]):[...this.state.plugins,t],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(t){if(this.isDestroyed)return;const e=this.state.plugins;let n=e;if([].concat(t).forEach(s=>{const i=typeof s=="string"?`${s}$`:s.key;n=n.filter(o=>!o.key.startsWith(i))}),e.length===n.length)return;const r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var t,e;const r=[...this.options.enableCoreExtensions?[pa,da.configure({blockSeparator:(e=(t=this.options.coreExtensionOptions)==null?void 0:t.clipboardTextSerializer)==null?void 0:e.blockSeparator}),ua,ga,ya,ka,fa,ba,ha,wa.configure({direction:this.options.textDirection})].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 Un(r,this)}createCommandManager(){this.commandManager=new _n({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let t;try{t=Pr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(e.message))throw e;this.emit("contentError",{editor:this,error:e,disableCollaboration:()=>{"collaboration"in this.storage&&typeof this.storage.collaboration=="object"&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(n=>n.name!=="collaboration"),this.createExtensionManager()}}),t=Pr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return t}createView(t){const{editorProps:e,enableExtensionDispatchTransaction:n}=this.options,r=e.dispatchTransaction||this.dispatchTransaction.bind(this),s=n?this.extensionManager.dispatchTransaction(r):r;this.editorView=new _l(t,{...e,attributes:{role:"textbox",...e==null?void 0:e.attributes},dispatchTransaction:s,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.prependClass(),this.injectCSS();const o=this.view.dom;o.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(t){this.isCapturingTransaction=!0,t(),this.isCapturingTransaction=!1;const e=this.capturedTransaction;return this.capturedTransaction=null,e}dispatchTransaction(t){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=t;return}t.steps.forEach(c=>{var d;return(d=this.capturedTransaction)==null?void 0:d.step(c)});return}const{state:e,transactions:n}=this.state.applyTransaction(t),r=!this.state.selection.eq(e.selection),s=n.includes(t),i=this.state;if(this.emit("beforeTransaction",{editor:this,transaction:t,nextState:e}),!s)return;this.view.updateState(e),this.emit("transaction",{editor:this,transaction:t,appendedTransactions:n.slice(1)}),r&&this.emit("selectionUpdate",{editor:this,transaction:t});const o=n.findLast(c=>c.getMeta("focus")||c.getMeta("blur")),l=o==null?void 0:o.getMeta("focus"),a=o==null?void 0:o.getMeta("blur");l&&this.emit("focus",{editor:this,event:l.event,transaction:o}),a&&this.emit("blur",{editor:this,event:a.event,transaction:o}),!(t.getMeta("preventUpdate")||!n.some(c=>c.docChanged)||i.doc.eq(e.doc))&&this.emit("update",{editor:this,transaction:t,appendedTransactions:n.slice(1)})}getAttributes(t){return na(this.state,t)}isActive(t,e){const n=typeof t=="string"?t:null,r=typeof t=="string"?e:t;return hf(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return ys(this.state.doc.content,this.schema)}getText(t){const{blockSeparator:e=` `,textSerializers:n={}}=t||{};return of(this.state.doc,{blockSeparator:e,textSerializers:{...ta(this.schema),...n}})}get isEmpty(){return Kn(this.state.doc)}destroy(){this.emit("destroy"),this.unmount(),this.removeAllListeners()}get isDestroyed(){var t,e;return(e=(t=this.editorView)==null?void 0:t.isDestroyed)!=null?e:!0}$node(t,e){var n;return((n=this.$doc)==null?void 0:n.querySelector(t,e))||null}$nodes(t,e){var n;return((n=this.$doc)==null?void 0:n.querySelectorAll(t,e))||null}$pos(t){const e=this.state.doc.resolve(t);return new Xf(e,this)}get $doc(){return this.$pos(0)}};function dt(t){return new Qt({find:t.find,handler:({state:e,range:n,match:r})=>{const s=D(t.getAttributes,void 0,r);if(s===!1||s===null)return null;const{tr:i}=e,o=r[r.length-1],l=r[0];if(o){const a=l.search(/\S/),c=n.from+l.indexOf(o),d=c+o.length;if(ks(n.from,n.to,e.doc).filter(f=>f.mark.type.excluded.find(m=>m===t.type&&m!==f.mark.type)).filter(f=>f.to>c).length)return null;dn.from&&i.delete(n.from+a,c);const h=n.from+a+o.length;i.addMark(n.from+a,h,t.type.create(s||{})),i.removeStoredMark(t.type)}},undoable:t.undoable})}function xa(t){return new Qt({find:t.find,handler:({state:e,range:n,match:r})=>{const s=D(t.getAttributes,void 0,r)||{},{tr:i}=e,o=n.from;let l=n.to;const a=t.type.create(s);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];i.insertText(u,o+r[0].length-1),i.replaceWith(d,l,a)}else if(r[0]){const c=t.type.isInline?o:o-1;i.insert(c,t.type.create(s)).delete(i.mapping.map(o),i.mapping.map(l))}i.scrollIntoView()},undoable:t.undoable})}function zr(t){return new Qt({find:t.find,handler:({state:e,range:n,match:r})=>{const s=e.doc.resolve(n.from),i=D(t.getAttributes,void 0,r)||{};if(!s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),t.type))return null;e.tr.delete(n.from,n.to).setBlockType(n.from,n.from,t.type,i)},undoable:t.undoable})}function W(t){return new Qt({find:t.find,handler:({state:e,range:n,match:r})=>{let s=t.replace,i=n.from;const o=n.to;if(r[1]){const l=r[0].lastIndexOf(r[1]);s+=r[0].slice(l+r[1].length),i+=l;const a=i-o;a>0&&(s=r[0].slice(l-a,l)+s,i=o)}e.tr.insertText(s,i,o)},undoable:t.undoable})}function Et(t){return new Qt({find:t.find,handler:({state:e,range:n,match:r,chain:s})=>{const i=D(t.getAttributes,void 0,r)||{},o=e.tr.delete(n.from,n.to),a=o.doc.resolve(n.from).blockRange(),c=a&&Xr(a,t.type,i);if(!c)return null;if(o.wrap(a,c),t.keepMarks&&t.editor){const{selection:u,storedMarks:h}=e,{splittableMarks:f}=t.editor.extensionManager,p=h||u.$to.parentOffset&&u.$from.marks();if(p){const m=p.filter(g=>f.includes(g.type.name));o.ensureMarks(m)}}if(t.keepAttributes){const u=t.type.name==="bulletList"||t.type.name==="orderedList"?"listItem":"taskList";s().updateAttributes(u,i).run()}const d=o.doc.resolve(n.from-1).nodeBefore;d&&d.type===t.type&&Ue(o.doc,n.from-1)&&(!t.joinPredicate||t.joinPredicate(r,d))&&o.join(n.from-1)},undoable:t.undoable})}var Zf=t=>"touches"in t,ep=class{constructor(t){this.directions=["bottom-left","bottom-right","top-left","top-right"],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:"",wrapper:"",handle:"",resizing:""},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=l=>{if(!this.isResizing||!this.activeHandle)return;const a=l.clientX-this.startX,c=l.clientY-this.startY;this.handleResize(a,c)},this.handleTouchMove=l=>{if(!this.isResizing||!this.activeHandle)return;const a=l.touches[0];if(!a)return;const c=a.clientX-this.startX,d=a.clientY-this.startY;this.handleResize(c,d)},this.handleMouseUp=()=>{if(!this.isResizing)return;const l=this.element.offsetWidth,a=this.element.offsetHeight;this.onCommit(l,a),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState="false",this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp)},this.handleKeyDown=l=>{l.key==="Shift"&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=l=>{l.key==="Shift"&&(this.isShiftKeyPressed=!1)};var e,n,r,s,i,o;this.node=t.node,this.editor=t.editor,this.element=t.element,this.contentElement=t.contentElement,this.getPos=t.getPos,this.onResize=t.onResize,this.onCommit=t.onCommit,this.onUpdate=t.onUpdate,(e=t.options)!=null&&e.min&&(this.minSize={...this.minSize,...t.options.min}),(n=t.options)!=null&&n.max&&(this.maxSize=t.options.max),(r=t==null?void 0:t.options)!=null&&r.directions&&(this.directions=t.options.directions),(s=t.options)!=null&&s.preserveAspectRatio&&(this.preserveAspectRatio=t.options.preserveAspectRatio),(i=t.options)!=null&&i.className&&(this.classNames={container:t.options.className.container||"",wrapper:t.options.className.wrapper||"",handle:t.options.className.handle||"",resizing:t.options.className.resizing||""}),(o=t.options)!=null&&o.createCustomHandle&&(this.createCustomHandle=t.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on("update",this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){var t;return(t=this.contentElement)!=null?t:null}handleEditorUpdate(){const t=this.editor.isEditable;t!==this.lastEditableState&&(this.lastEditableState=t,t?t&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(t,e,n){return t.type!==this.node.type?!1:(this.node=t,this.onUpdate?this.onUpdate(t,e,n):!0)}destroy(){this.isResizing&&(this.container.dataset.resizeState="false",this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off("update",this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){const t=document.createElement("div");return t.dataset.resizeContainer="",t.dataset.node=this.node.type.name,t.style.display="flex",this.classNames.container&&(t.className=this.classNames.container),t.appendChild(this.wrapper),t}createWrapper(){const t=document.createElement("div");return t.style.position="relative",t.style.display="block",t.dataset.resizeWrapper="",this.classNames.wrapper&&(t.className=this.classNames.wrapper),t.appendChild(this.element),t}createHandle(t){const e=document.createElement("div");return e.dataset.resizeHandle=t,e.style.position="absolute",this.classNames.handle&&(e.className=this.classNames.handle),e}positionHandle(t,e){const n=e.includes("top"),r=e.includes("bottom"),s=e.includes("left"),i=e.includes("right");n&&(t.style.top="0"),r&&(t.style.bottom="0"),s&&(t.style.left="0"),i&&(t.style.right="0"),(e==="top"||e==="bottom")&&(t.style.left="0",t.style.right="0"),(e==="left"||e==="right")&&(t.style.top="0",t.style.bottom="0")}attachHandles(){this.directions.forEach(t=>{let e;this.createCustomHandle?e=this.createCustomHandle(t):e=this.createHandle(t),e instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${t}") did not return an HTMLElement. Falling back to default handle.`),e=this.createHandle(t)),this.createCustomHandle||this.positionHandle(e,t),e.addEventListener("mousedown",n=>this.handleResizeStart(n,t)),e.addEventListener("touchstart",n=>this.handleResizeStart(n,t)),this.handleMap.set(t,e),this.wrapper.appendChild(e)})}removeHandles(){this.handleMap.forEach(t=>t.remove()),this.handleMap.clear()}applyInitialSize(){const t=this.node.attrs.width,e=this.node.attrs.height;t?(this.element.style.width=`${t}px`,this.initialWidth=t):this.initialWidth=this.element.offsetWidth,e?(this.element.style.height=`${e}px`,this.initialHeight=e):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(t,e){t.preventDefault(),t.stopPropagation(),this.isResizing=!0,this.activeHandle=e,Zf(t)?(this.startX=t.touches[0].clientX,this.startY=t.touches[0].clientY):(this.startX=t.clientX,this.startY=t.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState="true",this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("touchmove",this.handleTouchMove),document.addEventListener("mouseup",this.handleMouseUp),document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keyup",this.handleKeyUp)}handleResize(t,e){if(!this.activeHandle)return;const n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:s}=this.calculateNewDimensions(this.activeHandle,t,e),i=this.applyConstraints(r,s,n);this.element.style.width=`${i.width}px`,this.element.style.height=`${i.height}px`,this.onResize&&this.onResize(i.width,i.height)}calculateNewDimensions(t,e,n){let r=this.startWidth,s=this.startHeight;const i=t.includes("right"),o=t.includes("left"),l=t.includes("bottom"),a=t.includes("top");return i?r=this.startWidth+e:o&&(r=this.startWidth-e),l?s=this.startHeight+n:a&&(s=this.startHeight-n),(t==="right"||t==="left")&&(r=this.startWidth+(i?e:-e)),(t==="top"||t==="bottom")&&(s=this.startHeight+(l?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,s,t):{width:r,height:s}}applyConstraints(t,e,n){var r,s,i,o;if(!n){let c=Math.max(this.minSize.width,t),d=Math.max(this.minSize.height,e);return(r=this.maxSize)!=null&&r.width&&(c=Math.min(this.maxSize.width,c)),(s=this.maxSize)!=null&&s.height&&(d=Math.min(this.maxSize.height,d)),{width:c,height:d}}let l=t,a=e;return lthis.maxSize.width&&(l=this.maxSize.width,a=l/this.aspectRatio),(o=this.maxSize)!=null&&o.height&&a>this.maxSize.height&&(a=this.maxSize.height,l=a*this.aspectRatio),{width:l,height:a}}applyAspectRatio(t,e,n){const r=n==="left"||n==="right",s=n==="top"||n==="bottom";return r?{width:t,height:t/this.aspectRatio}:s?{width:e*this.aspectRatio,height:e}:{width:t,height:t/this.aspectRatio}}};function tp(t,e){const{selection:n}=t,{$from:r}=n;if(n instanceof T){const i=r.index();return r.parent.canReplaceWith(i,i+1,e)}let s=r.depth;for(;s>=0;){const i=r.index(s);if(r.node(s).contentMatchAt(i).matchType(e))return!0;s-=1}return!1}var np={};ps(np,{createAtomBlockMarkdownSpec:()=>rp,createBlockMarkdownSpec:()=>sp,createInlineMarkdownSpec:()=>lp,parseAttributes:()=>xs,parseIndentedBlocks:()=>Br,renderNestedMarkdownContent:()=>Cs,serializeAttributes:()=>Ss});function xs(t){if(!(t!=null&&t.trim()))return{};const e={},n=[],r=t.replace(/["']([^"']*)["']/g,c=>(n.push(c),`__QUOTED_${n.length-1}__`)),s=r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);if(s){const c=s.map(d=>d.trim().slice(1));e.class=c.join(" ")}const i=r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);i&&(e.id=i[1]);const o=/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;Array.from(r.matchAll(o)).forEach(([,c,d])=>{var u;const h=parseInt(((u=d.match(/__QUOTED_(\d+)__/))==null?void 0:u[1])||"0",10),f=n[h];f&&(e[c]=f.slice(1,-1))});const a=r.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,"").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,"").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,"").trim();return a&&a.split(/\s+/).filter(Boolean).forEach(d=>{d.match(/^[a-zA-Z][\w-]*$/)&&(e[d]=!0)}),e}function Ss(t){if(!t||Object.keys(t).length===0)return"";const e=[];return t.class&&String(t.class).split(/\s+/).filter(Boolean).forEach(r=>e.push(`.${r}`)),t.id&&e.push(`#${t.id}`),Object.entries(t).forEach(([n,r])=>{n==="class"||n==="id"||(r===!0?e.push(n):r!==!1&&r!=null&&e.push(`${n}="${String(r)}"`))}),e.join(" ")}function rp(t){const{nodeName:e,name:n,parseAttributes:r=xs,serializeAttributes:s=Ss,defaultAttributes:i={},requiredAttributes:o=[],allowedAttributes:l}=t,a=n||e,c=d=>{if(!l)return d;const u={};return l.forEach(h=>{h in d&&(u[h]=d[h])}),u};return{parseMarkdown:(d,u)=>{const h={...i,...d.attributes};return u.createNode(e,h,[])},markdownTokenizer:{name:e,level:"block",start(d){var u;const h=new RegExp(`^:::${a}(?:\\s|$)`,"m"),f=(u=d.match(h))==null?void 0:u.index;return f!==void 0?f:-1},tokenize(d,u,h){const f=new RegExp(`^:::${a}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),p=d.match(f);if(!p)return;const m=p[1]||"",g=r(m);if(!o.find(k=>!(k in g)))return{type:e,raw:p[0],attributes:g}}},renderMarkdown:d=>{const u=c(d.attrs||{}),h=s(u),f=h?` {${h}}`:"";return`:::${a}${f} :::`}}}function sp(t){const{nodeName:e,name:n,getContent:r,parseAttributes:s=xs,serializeAttributes:i=Ss,defaultAttributes:o={},content:l="block",allowedAttributes:a}=t,c=n||e,d=u=>{if(!a)return u;const h={};return a.forEach(f=>{f in u&&(h[f]=u[f])}),h};return{parseMarkdown:(u,h)=>{let f;if(r){const m=r(u);f=typeof m=="string"?[{type:"text",text:m}]:m}else l==="block"?f=h.parseChildren(u.tokens||[]):f=h.parseInline(u.tokens||[]);const p={...o,...u.attributes};return h.createNode(e,p,f)},markdownTokenizer:{name:e,level:"block",start(u){var h;const f=new RegExp(`^:::${c}`,"m"),p=(h=u.match(f))==null?void 0:h.index;return p!==void 0?p:-1},tokenize(u,h,f){var p;const m=new RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),g=u.match(m);if(!g)return;const[y,k=""]=g,w=s(k);let S=1;const C=y.length;let A="";const v=/^:::([\w-]*)(\s.*)?/gm,O=u.slice(C);for(v.lastIndex=0;;){const R=v.exec(O);if(R===null)break;const Ce=R.index,Xn=R[1];if(!((p=R[2])!=null&&p.endsWith(":::"))){if(Xn)S+=1;else if(S-=1,S===0){const en=O.slice(0,Ce);A=en.trim();const Gn=u.slice(0,C+Ce+R[0].length);let Ie=[];if(A)if(l==="block")for(Ie=f.blockTokens(en),Ie.forEach(Me=>{Me.text&&(!Me.tokens||Me.tokens.length===0)&&(Me.tokens=f.inlineTokens(Me.text))});Ie.length>0;){const Me=Ie[Ie.length-1];if(Me.type==="paragraph"&&(!Me.text||Me.text.trim()===""))Ie.pop();else break}else Ie=f.inlineTokens(A);return{type:e,raw:Gn,attributes:w,content:A,tokens:Ie}}}}}},renderMarkdown:(u,h)=>{const f=d(u.attrs||{}),p=i(f),m=p?` {${p}}`:"",g=h.renderChildren(u.content||[],` `);return`:::${c}${m} ${g} :::`}}}function ip(t){if(!t.trim())return{};const e={},n=/(\w+)=(?:"([^"]*)"|'([^']*)')/g;let r=n.exec(t);for(;r!==null;){const[,s,i,o]=r;e[s]=i||o,r=n.exec(t)}return e}function op(t){return Object.entries(t).filter(([,e])=>e!=null).map(([e,n])=>`${e}="${n}"`).join(" ")}function lp(t){const{nodeName:e,name:n,getContent:r,parseAttributes:s=ip,serializeAttributes:i=op,defaultAttributes:o={},selfClosing:l=!1,allowedAttributes:a}=t,c=n||e,d=h=>{if(!a)return h;const f={};return a.forEach(p=>{const m=typeof p=="string"?p:p.name,g=typeof p=="string"?void 0:p.skipIfDefault;if(m in h){const y=h[m];if(g!==void 0&&y===g)return;f[m]=y}}),f},u=c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return{parseMarkdown:(h,f)=>{const p={...o,...h.attributes};if(l)return f.createNode(e,p);const m=r?r(h):h.content||"";return m?f.createNode(e,p,[f.createTextNode(m)]):f.createNode(e,p,[])},markdownTokenizer:{name:e,level:"inline",start(h){const f=l?new RegExp(`\\[${u}\\s*[^\\]]*\\]`):new RegExp(`\\[${u}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${u}\\]`),p=h.match(f),m=p==null?void 0:p.index;return m!==void 0?m:-1},tokenize(h,f,p){const m=l?new RegExp(`^\\[${u}\\s*([^\\]]*)\\]`):new RegExp(`^\\[${u}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${u}\\]`),g=h.match(m);if(!g)return;let y="",k="";if(l){const[,S]=g;k=S}else{const[,S,C]=g;k=S,y=C||""}const w=s(k.trim());return{type:e,raw:g[0],content:y.trim(),attributes:w}}},renderMarkdown:h=>{let f="";r?f=r(h):h.content&&h.content.length>0&&(f=h.content.filter(y=>y.type==="text").map(y=>y.text).join(""));const p=d(h.attrs||{}),m=i(p),g=m?` ${m}`:"";return l?`[${c}${g}]`:`[${c}${g}]${f}[/${c}]`}}}function Br(t,e,n){var r,s,i,o;const l=t.split(` `),a=[];let c="",d=0;const u=e.baseIndentSize||2;for(;d0)break;if(h.trim()===""){d+=1,c=`${c}${h} `;continue}else return}const p=e.extractItemData(f),{indentLevel:m,mainContent:g}=p;c=`${c}${h} `;const y=[g];for(d+=1;dCe.trim()!=="");if(v===-1)break;if((((s=(r=l[d+1+v].match(/^(\s*)/))==null?void 0:r[1])==null?void 0:s.length)||0)>m){y.push(C),c=`${c}${C} `,d+=1;continue}else break}if((((o=(i=C.match(/^(\s*)/))==null?void 0:i[1])==null?void 0:o.length)||0)>m)y.push(C),c=`${c}${C} `,d+=1;else break}let k;const w=y.slice(1);if(w.length>0){const C=w.map(A=>A.slice(m+u)).join(` `);C.trim()&&(e.customNestedParser?k=e.customNestedParser(C):k=n.blockTokens(C))}const S=e.createToken(p,k);a.push(S)}if(a.length!==0)return{items:a,raw:c}}function Cs(t,e,n,r){if(!t||!Array.isArray(t.content))return"";const s=typeof n=="function"?n(r):n,[i,...o]=t.content,l=e.renderChildren([i]),a=[`${s}${l}`];return o&&o.length>0&&o.forEach(c=>{const d=e.renderChildren([c]);if(d){const u=d.split(` `).map(h=>h?e.indent(h):"").join(` `);a.push(u)}}),a.join(` `)}function ap(t,e,n={}){const{state:r}=e,{doc:s,tr:i}=r,o=t;s.descendants((l,a)=>{const c=i.mapping.map(a),d=i.mapping.map(a)+l.nodeSize;let u=null;if(l.marks.forEach(f=>{if(f!==o)return!1;u=f}),!u)return;let h=!1;if(Object.keys(n).forEach(f=>{n[f]!==u.attrs[f]&&(h=!0)}),h){const f=t.type.create({...t.attrs,...n});i.removeMark(c,d,t.type),i.addMark(c,d,f)}}),i.docChanged&&e.view.dispatch(i)}var X=class Sa extends ws{constructor(){super(...arguments),this.type="node"}static create(e={}){const n=typeof e=="function"?e():e;return new Sa(n)}configure(e){return super.configure(e)}extend(e){const n=typeof e=="function"?e():e;return super.extend(n)}},cp=class{constructor(t,e,n){this.isDragging=!1,this.component=t,this.editor=e.editor,this.options={stopEvent:null,ignoreMutation:null,...n},this.extension=e.extension,this.node=e.node,this.decorations=e.decorations,this.innerDecorations=e.innerDecorations,this.view=e.view,this.HTMLAttributes=e.HTMLAttributes,this.getPos=e.getPos,this.mount()}mount(){}get dom(){return this.editor.view.dom}get contentDOM(){return null}onDragStart(t){var e,n,r,s,i,o,l;const{view:a}=this.editor,c=t.target,d=c.nodeType===3?(e=c.parentElement)==null?void 0:e.closest("[data-drag-handle]"):c.closest("[data-drag-handle]");if(!this.dom||(n=this.contentDOM)!=null&&n.contains(c)||!d)return;let u=0,h=0;if(this.dom!==d){const k=this.dom.getBoundingClientRect(),w=d.getBoundingClientRect(),S=(s=t.offsetX)!=null?s:(r=t.nativeEvent)==null?void 0:r.offsetX,C=(o=t.offsetY)!=null?o:(i=t.nativeEvent)==null?void 0:i.offsetY;u=w.x-k.x+S,h=w.y-k.y+C}const f=this.dom.cloneNode(!0);try{const k=this.dom.getBoundingClientRect();f.style.width=`${Math.round(k.width)}px`,f.style.height=`${Math.round(k.height)}px`,f.style.boxSizing="border-box",f.style.pointerEvents="none"}catch{}let p=null;try{p=document.createElement("div"),p.style.position="absolute",p.style.top="-9999px",p.style.left="-9999px",p.style.pointerEvents="none",p.appendChild(f),document.body.appendChild(p),(l=t.dataTransfer)==null||l.setDragImage(f,u,h)}finally{p&&setTimeout(()=>{try{p==null||p.remove()}catch{}},0)}const m=this.getPos();if(typeof m!="number")return;const g=T.create(a.state.doc,m),y=a.state.tr.setSelection(g);a.dispatch(y)}stopEvent(t){var e;if(!this.dom)return!1;if(typeof this.options.stopEvent=="function")return this.options.stopEvent({event:t});const n=t.target;if(!(this.dom.contains(n)&&!((e=this.contentDOM)!=null&&e.contains(n))))return!1;const s=t.type.startsWith("drag"),i=t.type==="drop";if((["INPUT","BUTTON","SELECT","TEXTAREA"].includes(n.tagName)||n.isContentEditable)&&!i&&!s)return!0;const{isEditable:l}=this.editor,{isDragging:a}=this,c=!!this.node.type.spec.draggable,d=T.isSelectable(this.node),u=t.type==="copy",h=t.type==="paste",f=t.type==="cut",p=t.type==="mousedown";if(!c&&d&&s&&t.target===this.dom&&t.preventDefault(),c&&s&&!a&&t.target===this.dom)return t.preventDefault(),!1;if(c&&l&&!a&&p){const m=n.closest("[data-drag-handle]");m&&(this.dom===m||this.dom.contains(m))&&(this.isDragging=!0,document.addEventListener("dragend",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("drop",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("mouseup",()=>{this.isDragging=!1},{once:!0}))}return!(a||i||u||h||f||p&&d)}ignoreMutation(t){return!this.dom||!this.contentDOM?!0:typeof this.options.ignoreMutation=="function"?this.options.ignoreMutation({mutation:t}):this.node.isLeaf||this.node.isAtom?!0:t.type==="selection"||this.dom.contains(t.target)&&t.type==="childList"&&(Kt()||Ir())&&this.editor.isFocused&&[...Array.from(t.addedNodes),...Array.from(t.removedNodes)].every(n=>n.isContentEditable)?!1:this.contentDOM===t.target&&t.type==="attributes"?!0:!this.contentDOM.contains(t.target)}updateAttributes(t){this.editor.commands.command(({tr:e})=>{const n=this.getPos();return typeof n!="number"?!1:(e.setNodeMarkup(n,void 0,{...this.node.attrs,...t}),!0)})}deleteNode(){const t=this.getPos();if(typeof t!="number")return;const e=t+this.node.nodeSize;this.editor.commands.deleteRange({from:t,to:e})}};function Ke(t){return new Wf({find:t.find,handler:({state:e,range:n,match:r,pasteEvent:s})=>{const i=D(t.getAttributes,void 0,r,s);if(i===!1||i===null)return null;const{tr:o}=e,l=r[r.length-1],a=r[0];let c=n.to;if(l){const d=a.search(/\S/),u=n.from+a.indexOf(l),h=u+l.length;if(ks(n.from,n.to,e.doc).filter(p=>p.mark.type.excluded.find(g=>g===t.type&&g!==p.mark.type)).filter(p=>p.to>u).length)return null;hn.from&&o.delete(n.from+d,u),c=n.from+d+l.length,o.addMark(n.from+d,c,t.type.create(i||{})),o.removeStoredMark(t.type)}}})}var dp=(...t)=>e=>{t.forEach(n=>{typeof n=="function"?n(e):n&&(n.current=e)})},up=({contentComponent:t})=>{const e=fo.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getServerSnapshot);return de.jsx(de.Fragment,{children:Object.values(e)})};function hp(){const t=new Set;let e={};return{subscribe(n){return t.add(n),()=>{t.delete(n)}},getSnapshot(){return e},getServerSnapshot(){return e},setRenderer(n,r){e={...e,[n]:Qa.createPortal(r.reactElement,r.element,n)},t.forEach(s=>s())},removeRenderer(n){const r={...e};delete r[n],e=r,t.forEach(s=>s())}}}var fp=class extends it.Component{constructor(t){var e;super(t),this.editorContentRef=it.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!((e=t.editor)!=null&&e.contentComponent)}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){var t;const e=this.props.editor;if(e&&!e.isDestroyed&&((t=e.view.dom)!=null&&t.parentNode)){if(e.contentComponent)return;const n=this.editorContentRef.current;n.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:n}),e.contentComponent=hp(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(r=>r.hasContentComponentInitialized?r:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){var t;const e=this.props.editor;if(e){this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null;try{if(!((t=e.view.dom)!=null&&t.parentNode))return;const n=document.createElement("div");n.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:n})}catch{}}}render(){const{editor:t,innerRef:e,...n}=this.props;return de.jsxs(de.Fragment,{children:[de.jsx("div",{ref:dp(e,this.editorContentRef),...n}),(t==null?void 0:t.contentComponent)&&de.jsx(up,{contentComponent:t.contentComponent})]})}},pp=V.forwardRef((t,e)=>{const n=it.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[t.editor]);return it.createElement(fp,{key:n,innerRef:e,...t})}),mp=it.memo(pp),gp=typeof window<"u"?V.useLayoutEffect:V.useEffect,yp=class{constructor(t){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=t,this.lastSnapshot={editor:t,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}watch(t){if(this.editor=t,this.editor){const e=()=>{this.transactionNumber+=1,this.subscribers.forEach(r=>r())},n=this.editor;return n.on("transaction",e),()=>{n.off("transaction",e)}}}};function bp(t){var e;const[n]=V.useState(()=>new yp(t.editor)),r=tc.useSyncExternalStoreWithSelector(n.subscribe,n.getSnapshot,n.getServerSnapshot,t.selector,(e=t.equalityFn)!=null?e:nc);return gp(()=>n.watch(t.editor),[t.editor,n]),V.useDebugValue(r),r}var kp=!1,$r=typeof window>"u",wp=$r||!!(typeof window<"u"&&window.next),xp=class Ca{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId="",this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(n=>n())}getInitialEditor(){return this.options.current.immediatelyRender===void 0?$r||wp?null:this.createEditor():(this.options.current.immediatelyRender,this.options.current.immediatelyRender?this.createEditor():null)}createEditor(){const e={...this.options.current,onBeforeCreate:(...r)=>{var s,i;return(i=(s=this.options.current).onBeforeCreate)==null?void 0:i.call(s,...r)},onBlur:(...r)=>{var s,i;return(i=(s=this.options.current).onBlur)==null?void 0:i.call(s,...r)},onCreate:(...r)=>{var s,i;return(i=(s=this.options.current).onCreate)==null?void 0:i.call(s,...r)},onDestroy:(...r)=>{var s,i;return(i=(s=this.options.current).onDestroy)==null?void 0:i.call(s,...r)},onFocus:(...r)=>{var s,i;return(i=(s=this.options.current).onFocus)==null?void 0:i.call(s,...r)},onSelectionUpdate:(...r)=>{var s,i;return(i=(s=this.options.current).onSelectionUpdate)==null?void 0:i.call(s,...r)},onTransaction:(...r)=>{var s,i;return(i=(s=this.options.current).onTransaction)==null?void 0:i.call(s,...r)},onUpdate:(...r)=>{var s,i;return(i=(s=this.options.current).onUpdate)==null?void 0:i.call(s,...r)},onContentError:(...r)=>{var s,i;return(i=(s=this.options.current).onContentError)==null?void 0:i.call(s,...r)},onDrop:(...r)=>{var s,i;return(i=(s=this.options.current).onDrop)==null?void 0:i.call(s,...r)},onPaste:(...r)=>{var s,i;return(i=(s=this.options.current).onPaste)==null?void 0:i.call(s,...r)},onDelete:(...r)=>{var s,i;return(i=(s=this.options.current).onDelete)==null?void 0:i.call(s,...r)}};return new Qf(e)}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,n){return Object.keys(e).every(r=>["onCreate","onBeforeCreate","onDestroy","onUpdate","onTransaction","onFocus","onBlur","onSelectionUpdate","onContentError","onDrop","onPaste"].includes(r)?!0:r==="extensions"&&e.extensions&&n.extensions?e.extensions.length!==n.extensions.length?!1:e.extensions.every((s,i)=>{var o;return s===((o=n.extensions)==null?void 0:o[i])}):e[r]===n[r])}onRender(e){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&e.length===0?Ca.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(e),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((r,s)=>r===e[s]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){const e=this.instanceId,n=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){n&&n.setOptions(this.options.current);return}n&&!n.isDestroyed&&(n.destroy(),this.instanceId===e&&this.setEditor(null))},1)}};function By(t={},e=[]){const n=V.useRef(t);n.current=t;const[r]=V.useState(()=>new xp(n)),s=fo.useSyncExternalStore(r.subscribe,r.getEditor,r.getServerSnapshot);return V.useDebugValue(s),V.useEffect(r.onRender(e)),bp({editor:s,selector:({transactionNumber:i})=>t.shouldRerenderOnTransaction===!1||t.shouldRerenderOnTransaction===void 0?null:t.immediatelyRender&&i===0?0:i+1}),s}var Ms=V.createContext({editor:null});Ms.Consumer;var $y=()=>V.useContext(Ms),Ma=V.createContext({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),Sp=()=>V.useContext(Ma),Hy=it.forwardRef((t,e)=>{const{onDragStart:n}=Sp(),r=t.as||"div";return de.jsx(r,{...t,ref:e,"data-node-view-wrapper":"",onDragStart:n,style:{whiteSpace:"normal",...t.style}})});function Hi(t){return!!(typeof t=="function"&&t.prototype&&t.prototype.isReactComponent)}function Fi(t){return!!(typeof t=="object"&&t.$$typeof&&(t.$$typeof.toString()==="Symbol(react.forward_ref)"||t.$$typeof.description==="react.forward_ref"))}function Cp(t){return!!(typeof t=="object"&&t.$$typeof&&(t.$$typeof.toString()==="Symbol(react.memo)"||t.$$typeof.description==="react.memo"))}function Mp(t){if(Hi(t)||Fi(t))return!0;if(Cp(t)){const e=t.type;if(e)return Hi(e)||Fi(e)}return!1}function vp(){try{if(V.version)return parseInt(V.version.split(".")[0],10)>=19}catch{}return!1}var Tp=class{constructor(t,{editor:e,props:n={},as:r="div",className:s=""}){this.ref=null,this.destroyed=!1,this.id=Math.floor(Math.random()*4294967295).toString(),this.component=t,this.editor=e,this.props=n,this.element=document.createElement(r),this.element.classList.add("react-renderer"),s&&this.element.classList.add(...s.split(" ")),this.editor.isInitialized?Ya.flushSync(()=>{this.render()}):queueMicrotask(()=>{this.destroyed||this.render()})}render(){var t;if(this.destroyed)return;const e=this.component,n=this.props,r=this.editor,s=vp(),i=Mp(e),o={...n};o.ref&&!(s||i)&&delete o.ref,!o.ref&&(s||i)&&(o.ref=l=>{this.ref=l}),this.reactElement=de.jsx(e,{...o}),(t=r==null?void 0:r.contentComponent)==null||t.setRenderer(this.id,this)}updateProps(t={}){this.destroyed||(this.props={...this.props,...t},this.render())}destroy(){var t;this.destroyed=!0;const e=this.editor;(t=e==null?void 0:e.contentComponent)==null||t.removeRenderer(this.id);try{this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}catch{}}updateAttributes(t){Object.keys(t).forEach(e=>{this.element.setAttribute(e,t[e])})}};it.createContext({markViewContentRef:()=>{}});var Ep=class extends cp{constructor(t,e,n){if(super(t,e,n),this.selectionRafId=null,this.cachedExtensionWithSyncedStorage=null,!this.node.isLeaf){this.options.contentDOMElementTag?this.contentDOMElement=document.createElement(this.options.contentDOMElementTag):this.contentDOMElement=document.createElement(this.node.isInline?"span":"div"),this.contentDOMElement.dataset.nodeViewContentReact="",this.contentDOMElement.dataset.nodeViewWrapper="",this.contentDOMElement.style.whiteSpace="inherit";const r=this.dom.querySelector("[data-node-view-content]");if(!r)return;r.appendChild(this.contentDOMElement)}}get extensionWithSyncedStorage(){if(!this.cachedExtensionWithSyncedStorage){const t=this.editor,e=this.extension;this.cachedExtensionWithSyncedStorage=new Proxy(e,{get(n,r,s){var i;return r==="storage"?(i=t.storage[e.name])!=null?i:{}:Reflect.get(n,r,s)}})}return this.cachedExtensionWithSyncedStorage}mount(){const t={editor:this.editor,node:this.node,decorations:this.decorations,innerDecorations:this.innerDecorations,view:this.view,selected:!1,extension:this.extensionWithSyncedStorage,HTMLAttributes:this.HTMLAttributes,getPos:()=>this.getPos(),updateAttributes:(a={})=>this.updateAttributes(a),deleteNode:()=>this.deleteNode(),ref:V.createRef()};if(!this.component.displayName){const a=c=>c.charAt(0).toUpperCase()+c.substring(1);this.component.displayName=a(this.extension.name)}const r={onDragStart:this.onDragStart.bind(this),nodeViewContentRef:a=>{a&&this.contentDOMElement&&a.firstChild!==this.contentDOMElement&&(a.hasAttribute("data-node-view-wrapper")&&a.removeAttribute("data-node-view-wrapper"),a.appendChild(this.contentDOMElement))}},s=this.component,i=V.memo(a=>de.jsx(Ma.Provider,{value:r,children:V.createElement(s,a)}));i.displayName="ReactNodeView";let o=this.node.isInline?"span":"div";this.options.as&&(o=this.options.as);const{className:l=""}=this.options;this.handleSelectionUpdate=this.handleSelectionUpdate.bind(this),this.renderer=new Tp(i,{editor:this.editor,props:t,as:o,className:`node-${this.node.type.name} ${l}`.trim()}),this.editor.on("selectionUpdate",this.handleSelectionUpdate),this.updateElementAttributes()}get dom(){var t;if(this.renderer.element.firstElementChild&&!((t=this.renderer.element.firstElementChild)!=null&&t.hasAttribute("data-node-view-wrapper")))throw Error("Please use the NodeViewWrapper component for your node view.");return this.renderer.element}get contentDOM(){return this.node.isLeaf?null:this.contentDOMElement}handleSelectionUpdate(){this.selectionRafId&&(cancelAnimationFrame(this.selectionRafId),this.selectionRafId=null),this.selectionRafId=requestAnimationFrame(()=>{this.selectionRafId=null;const{from:t,to:e}=this.editor.state.selection,n=this.getPos();if(typeof n=="number")if(t<=n&&e>=n+this.node.nodeSize){if(this.renderer.props.selected)return;this.selectNode()}else{if(!this.renderer.props.selected)return;this.deselectNode()}})}update(t,e,n){const r=s=>{this.renderer.updateProps(s),typeof this.options.attrs=="function"&&this.updateElementAttributes()};if(t.type!==this.node.type)return!1;if(typeof this.options.update=="function"){const s=this.node,i=this.decorations,o=this.innerDecorations;return this.node=t,this.decorations=e,this.innerDecorations=n,this.options.update({oldNode:s,oldDecorations:i,newNode:t,newDecorations:e,oldInnerDecorations:o,innerDecorations:n,updateProps:()=>r({node:t,decorations:e,innerDecorations:n,extension:this.extensionWithSyncedStorage})})}return t===this.node&&this.decorations===e&&this.innerDecorations===n||(this.node=t,this.decorations=e,this.innerDecorations=n,r({node:t,decorations:e,innerDecorations:n,extension:this.extensionWithSyncedStorage})),!0}selectNode(){this.renderer.updateProps({selected:!0}),this.renderer.element.classList.add("ProseMirror-selectednode")}deselectNode(){this.renderer.updateProps({selected:!1}),this.renderer.element.classList.remove("ProseMirror-selectednode")}destroy(){this.renderer.destroy(),this.editor.off("selectionUpdate",this.handleSelectionUpdate),this.contentDOMElement=null,this.selectionRafId&&(cancelAnimationFrame(this.selectionRafId),this.selectionRafId=null)}updateElementAttributes(){if(this.options.attrs){let t={};if(typeof this.options.attrs=="function"){const e=this.editor.extensionManager.attributes,n=Tt(this.node,e);t=this.options.attrs({node:this.node,HTMLAttributes:n})}else t=this.options.attrs;this.renderer.updateAttributes(t)}}};function Fy(t,e){return n=>n.editor.contentComponent?new Ep(t,n,e):{}}var vs=V.createContext({get editor(){throw new Error("useTiptap must be used within a provider")}});vs.displayName="TiptapContext";var Ap=()=>V.useContext(vs);function va({editor:t,instance:e,children:n}){const r=t??e;if(!r)throw new Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");const s=V.useMemo(()=>({editor:r}),[r]),i=V.useMemo(()=>({editor:r}),[r]);return de.jsx(Ms.Provider,{value:i,children:de.jsx(vs.Provider,{value:s,children:n})})}va.displayName="Tiptap";function Ta({...t}){const{editor:e}=Ap();return de.jsx(mp,{editor:e,...t})}Ta.displayName="Tiptap.Content";Object.assign(va,{Content:Ta});var In=(t,e)=>{if(t==="slot")return 0;if(t instanceof Function)return t(e);const{children:n,...r}=e??{};if(t==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[t,r,n]},Np=/^\s*>\s$/,Op=X.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:t}){return In("blockquote",{...I(this.options.HTMLAttributes,t),children:In("slot",{})})},parseMarkdown:(t,e)=>e.createNode("blockquote",void 0,e.parseChildren(t.tokens||[])),renderMarkdown:(t,e)=>{if(!t.content)return"";const n=">",r=[];return t.content.forEach(s=>{const l=e.renderChildren([s]).split(` `).map(a=>a.trim()===""?n:`${n} ${a}`);r.push(l.join(` `))}),r.join(` ${n} `)},addCommands(){return{setBlockquote:()=>({commands:t})=>t.wrapIn(this.name),toggleBlockquote:()=>({commands:t})=>t.toggleWrap(this.name),unsetBlockquote:()=>({commands:t})=>t.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[Et({find:Np,type:this.type})]}}),Rp=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,Dp=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,Ip=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Pp=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,Lp=xe.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:t=>t.type.name===this.name},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}]},renderHTML({HTMLAttributes:t}){return In("strong",{...I(this.options.HTMLAttributes,t),children:In("slot",{})})},markdownTokenName:"strong",parseMarkdown:(t,e)=>e.applyMark("bold",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`**${e.renderChildren(t)}**`,addCommands(){return{setBold:()=>({commands:t})=>t.setMark(this.name),toggleBold:()=>({commands:t})=>t.toggleMark(this.name),unsetBold:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[dt({find:Rp,type:this.type}),dt({find:Ip,type:this.type})]},addPasteRules(){return[Ke({find:Dp,type:this.type}),Ke({find:Pp,type:this.type})]}}),zp=/(^|[^`])`([^`]+)`(?!`)$/,Bp=/(^|[^`])`([^`]+)`(?!`)/g,$p=xe.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:t}){return["code",I(this.options.HTMLAttributes,t),0]},markdownTokenName:"codespan",parseMarkdown:(t,e)=>e.applyMark("code",[{type:"text",text:t.text||""}]),renderMarkdown:(t,e)=>t.content?`\`${e.renderChildren(t.content)}\``:"",addCommands(){return{setCode:()=>({commands:t})=>t.setMark(this.name),toggleCode:()=>({commands:t})=>t.toggleMark(this.name),unsetCode:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[dt({find:zp,type:this.type})]},addPasteRules(){return[Ke({find:Bp,type:this.type})]}}),fr=4,Hp=/^```([a-z]+)?[\s\n]$/,Fp=/^~~~([a-z]+)?[\s\n]$/,Vp=X.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:fr,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:t=>{var e;const{languageClassPrefix:n}=this.options;if(!n)return null;const i=[...((e=t.firstElementChild)==null?void 0:e.classList)||[]].filter(o=>o.startsWith(n)).map(o=>o.replace(n,""))[0];return i||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:t,HTMLAttributes:e}){return["pre",I(this.options.HTMLAttributes,e),["code",{class:t.attrs.language?this.options.languageClassPrefix+t.attrs.language:null},0]]},markdownTokenName:"code",parseMarkdown:(t,e)=>{var n;return((n=t.raw)==null?void 0:n.startsWith("```"))===!1&&t.codeBlockStyle!=="indented"?[]:e.createNode("codeBlock",{language:t.lang||null},t.text?[e.createTextNode(t.text)]:[])},renderMarkdown:(t,e)=>{var n;let r="";const s=((n=t.attrs)==null?void 0:n.language)||"";return t.content?r=[`\`\`\`${s}`,e.renderChildren(t.content),"```"].join(` `):r=`\`\`\`${s} \`\`\``,r},addCommands(){return{setCodeBlock:t=>({commands:e})=>e.setNode(this.name,t),toggleCodeBlock:t=>({commands:e})=>e.toggleNode(this.name,"paragraph",t)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:t,$anchor:e}=this.editor.state.selection,n=e.pos===1;return!t||e.parent.type.name!==this.name?!1:n||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:t})=>{var e;if(!this.options.enableTabIndentation)return!1;const n=(e=this.options.tabSize)!=null?e:fr,{state:r}=t,{selection:s}=r,{$from:i,empty:o}=s;if(i.parent.type!==this.type)return!1;const l=" ".repeat(n);return o?t.commands.insertContent(l):t.commands.command(({tr:a})=>{const{from:c,to:d}=s,f=r.doc.textBetween(c,d,` `,` `).split(` `).map(p=>l+p).join(` `);return a.replaceWith(c,d,r.schema.text(f)),!0})},"Shift-Tab":({editor:t})=>{var e;if(!this.options.enableTabIndentation)return!1;const n=(e=this.options.tabSize)!=null?e:fr,{state:r}=t,{selection:s}=r,{$from:i,empty:o}=s;return i.parent.type!==this.type?!1:o?t.commands.command(({tr:l})=>{var a;const{pos:c}=i,d=i.start(),u=i.end(),f=r.doc.textBetween(d,u,` `,` `).split(` `);let p=0,m=0;const g=c-d;for(let A=0;A=g){p=A;break}m+=f[A].length+1}const k=((a=f[p].match(/^ */))==null?void 0:a[0])||"",w=Math.min(k.length,n);if(w===0)return!0;let S=d;for(let A=0;A{const{from:a,to:c}=s,h=r.doc.textBetween(a,c,` `,` `).split(` `).map(f=>{var p;const m=((p=f.match(/^ */))==null?void 0:p[0])||"",g=Math.min(m.length,n);return f.slice(g)}).join(` `);return l.replaceWith(a,c,r.schema.text(h)),!0})},Enter:({editor:t})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=t,{selection:n}=e,{$from:r,empty:s}=n;if(!s||r.parent.type!==this.type)return!1;const i=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` `);return!i||!o?!1:t.chain().command(({tr:l})=>(l.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:t})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=t,{selection:n,doc:r}=e,{$from:s,empty:i}=n;if(!i||s.parent.type!==this.type||!(s.parentOffset===s.parent.nodeSize-2))return!1;const l=s.after();return l===void 0?!1:r.nodeAt(l)?t.commands.command(({tr:c})=>(c.setSelection(N.near(r.resolve(l))),!0)):t.commands.exitCode()}}},addInputRules(){return[zr({find:Hp,type:this.type,getAttributes:t=>({language:t[1]})}),zr({find:Fp,type:this.type,getAttributes:t=>({language:t[1]})})]},addProseMirrorPlugins(){return[new B({key:new _("codeBlockVSCodeHandler"),props:{handlePaste:(t,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const n=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;if(!n||!i)return!1;const{tr:o,schema:l}=t.state,a=l.text(n.replace(/\r\n?/g,` `));return o.replaceSelectionWith(this.type.create({language:i},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),t.dispatch(o),!0}}})]}}),_p=X.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(t,e)=>t.content?e.renderChildren(t.content,` `):""}),Wp=X.create({name:"hardBreak",markdownTokenName:"br",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:t}){return["br",I(this.options.HTMLAttributes,t)]},renderText(){return` `},renderMarkdown:()=>` `,parseMarkdown:()=>({type:"hardBreak"}),addCommands(){return{setHardBreak:()=>({commands:t,chain:e,state:n,editor:r})=>t.first([()=>t.exitCode(),()=>t.command(()=>{const{selection:s,storedMarks:i}=n;if(s.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,a=i||s.$to.parentOffset&&s.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:d})=>{if(d&&a&&o){const u=a.filter(h=>l.includes(h.type.name));c.ensureMarks(u)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),jp=X.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(t=>({tag:`h${t}`,attrs:{level:t}}))},renderHTML({node:t,HTMLAttributes:e}){return[`h${this.options.levels.includes(t.attrs.level)?t.attrs.level:this.options.levels[0]}`,I(this.options.HTMLAttributes,e),0]},parseMarkdown:(t,e)=>e.createNode("heading",{level:t.depth||1},e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>{var n;const r=(n=t.attrs)!=null&&n.level?parseInt(t.attrs.level,10):1,s="#".repeat(r);return t.content?`${s} ${e.renderChildren(t.content)}`:""},addCommands(){return{setHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.setNode(this.name,t):!1,toggleHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.toggleNode(this.name,"paragraph",t):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((t,e)=>({...t,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(t=>zr({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${t}})\\s$`),type:this.type,getAttributes:{level:t}}))}}),Ea=X.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{},nextNodeType:"paragraph"}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",I(this.options.HTMLAttributes,t)]},markdownTokenName:"hr",parseMarkdown:(t,e)=>e.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:t,state:e})=>{if(!tp(e,e.schema.nodes[this.name]))return!1;const{selection:n}=e,{$to:r}=n,s=t();return sa(n)?s.insertContentAt(r.pos,{type:this.name}):s.insertContent({type:this.name}),s.command(({state:i,tr:o,dispatch:l})=>{if(l){const{$to:a}=o.selection,c=a.end();if(a.nodeAfter)a.nodeAfter.isTextblock?o.setSelection(E.create(o.doc,a.pos+1)):a.nodeAfter.isBlock?o.setSelection(T.create(o.doc,a.pos)):o.setSelection(E.create(o.doc,a.pos));else{const d=i.schema.nodes[this.options.nextNodeType]||a.parent.type.contentMatch.defaultType,u=d==null?void 0:d.create();u&&(o.insert(c,u),o.setSelection(E.create(o.doc,c+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[xa({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Vy=Ea,qp=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Kp=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Up=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Jp=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Xp=xe.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:t=>t.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:t=>t.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:t}){return["em",I(this.options.HTMLAttributes,t),0]},addCommands(){return{setItalic:()=>({commands:t})=>t.setMark(this.name),toggleItalic:()=>({commands:t})=>t.toggleMark(this.name),unsetItalic:()=>({commands:t})=>t.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(t,e)=>e.applyMark("italic",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`*${e.renderChildren(t)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[dt({find:qp,type:this.type}),dt({find:Up,type:this.type})]},addPasteRules(){return[Ke({find:Kp,type:this.type}),Ke({find:Jp,type:this.type})]}}),Ts="[\0-   ᠎ -\u2029  ]",Gp=new RegExp(Ts),Yp=new RegExp(`${Ts}$`),Qp=new RegExp(Ts,"g");function Zp(t){return t.length===1?t[0].isLink:t.length===3&&t[1].isLink?["()","[]"].includes(t[0].value+t[2].value):!1}function em(t){return new B({key:new _("autolink"),appendTransaction:(e,n,r)=>{const s=e.some(c=>c.docChanged)&&!n.doc.eq(r.doc),i=e.some(c=>c.getMeta("preventAutolink"));if(!s||i)return;const{tr:o}=r,l=Xl(n.doc,[...e]);if(ra(l).forEach(({newRange:c})=>{const d=Zh(r.doc,c,f=>f.isTextblock);let u,h;if(d.length>1)u=d[0],h=r.doc.textBetween(u.pos,u.pos+u.node.nodeSize,void 0," ");else if(d.length){const f=r.doc.textBetween(c.from,c.to," "," ");if(!Yp.test(f))return;u=d[0],h=r.doc.textBetween(u.pos,c.to,void 0," ")}if(u&&h){const f=h.split(Gp).filter(Boolean);if(f.length<=0)return!1;const p=f[f.length-1],m=u.pos+h.lastIndexOf(p);if(!p)return!1;const g=rc(p).map(y=>y.toObject(t.defaultProtocol));if(!Zp(g))return!1;g.filter(y=>y.isLink).map(y=>({...y,from:m+y.start+1,to:m+y.end+1})).filter(y=>r.schema.marks.code?!r.doc.rangeHasMark(y.from,y.to,r.schema.marks.code):!0).filter(y=>t.validate(y.value)).filter(y=>t.shouldAutoLink(y.value)).forEach(y=>{ks(y.from,y.to,r.doc).some(k=>k.mark.type===t.type)||o.addMark(y.from,y.to,t.type.create({href:y.href}))})}}),!!o.steps.length)return o}})}function tm(t){return new B({key:new _("handleClickLink"),props:{handleClick:(e,n,r)=>{var s,i;if(r.button!==0||!e.editable)return!1;let o=null;if(r.target instanceof HTMLAnchorElement)o=r.target;else{const a=r.target;if(!a)return!1;const c=t.editor.view.dom;o=a.closest("a"),o&&!c.contains(o)&&(o=null)}if(!o)return!1;let l=!1;if(t.enableClickSelection&&(l=t.editor.commands.extendMarkRange(t.type.name)),t.openOnClick){const a=na(e.state,t.type.name),c=(s=o.href)!=null?s:a.href,d=(i=o.target)!=null?i:a.target;c&&(window.open(c,d),l=!0)}return l}}})}function nm(t){return new B({key:new _("handlePasteLink"),props:{handlePaste:(e,n,r)=>{const{shouldAutoLink:s}=t,{state:i}=e,{selection:o}=i,{empty:l}=o;if(l)return!1;let a="";r.content.forEach(d=>{a+=d.textContent});const c=po(a,{defaultProtocol:t.defaultProtocol}).find(d=>d.isLink&&d.value===a);return!a||!c||s!==void 0&&!s(c.value)?!1:t.editor.commands.setMark(t.type,{href:c.href})}}})}function Xe(t,e){const n=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(r=>{const s=typeof r=="string"?r:r.scheme;s&&n.push(s)}),!t||t.replace(Qp,"").match(new RegExp(`^(?:(?:${n.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var rm=xe.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(t=>{if(typeof t=="string"){Rs(t);return}Rs(t.scheme,t.optionalSlashes)})},onDestroy(){sc()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(t,e)=>!!Xe(t,e.protocols),validate:t=>!!t,shouldAutoLink:t=>{const e=/^[a-z][a-z0-9+.-]*:\/\//i.test(t),n=/^[a-z][a-z0-9+.-]*:/i.test(t);if(e||n&&!t.includes("@"))return!0;const s=(t.includes("@")?t.split("@").pop():t).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(s)||!/\./.test(s))}}},addAttributes(){return{href:{default:null,parseHTML(t){return t.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:"a[href]",getAttrs:t=>{const e=t.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:n=>!!Xe(n,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:t}){return this.options.isAllowedUri(t.href,{defaultValidate:e=>!!Xe(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",I(this.options.HTMLAttributes,t),0]:["a",I(this.options.HTMLAttributes,{...t,href:""}),0]},markdownTokenName:"link",parseMarkdown:(t,e)=>e.applyMark("link",e.parseInline(t.tokens||[]),{href:t.href,title:t.title||null}),renderMarkdown:(t,e)=>{var n,r,s,i;const o=(r=(n=t.attrs)==null?void 0:n.href)!=null?r:"",l=(i=(s=t.attrs)==null?void 0:s.title)!=null?i:"",a=e.renderChildren(t);return l?`[${a}](${o} "${l}")`:`[${a}](${o})`},addCommands(){return{setLink:t=>({chain:e})=>{const{href:n}=t;return this.options.isAllowedUri(n,{defaultValidate:r=>!!Xe(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,t).setMeta("preventAutolink",!0).run():!1},toggleLink:t=>({chain:e})=>{const{href:n}=t||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:r=>!!Xe(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:e().toggleMark(this.name,t,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:t})=>t().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[Ke({find:t=>{const e=[];if(t){const{protocols:n,defaultProtocol:r}=this.options,s=po(t).filter(i=>i.isLink&&this.options.isAllowedUri(i.value,{defaultValidate:o=>!!Xe(o,n),protocols:n,defaultProtocol:r}));s.length&&s.forEach(i=>{this.options.shouldAutoLink(i.value)&&e.push({text:i.value,data:{href:i.href},index:i.start})})}return e},type:this.type,getAttributes:t=>{var e;return{href:(e=t.data)==null?void 0:e.href}}})]},addProseMirrorPlugins(){const t=[],{protocols:e,defaultProtocol:n}=this.options;return this.options.autolink&&t.push(em({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:r=>this.options.isAllowedUri(r,{defaultValidate:s=>!!Xe(s,e),protocols:e,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),t.push(tm({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&t.push(nm({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),t}}),sm=Object.defineProperty,im=(t,e)=>{for(var n in e)sm(t,n,{get:e[n],enumerable:!0})},om="listItem",Vi="textStyle",_i=/^\s*([-+*])\s$/,Aa=X.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:t}){return["ul",I(this.options.HTMLAttributes,t),0]},markdownTokenName:"list",parseMarkdown:(t,e)=>t.type!=="list"||t.ordered?[]:{type:"bulletList",content:t.items?e.parseChildren(t.items):[]},renderMarkdown:(t,e)=>t.content?e.renderChildren(t.content,` `):"",markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:t,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(om,this.editor.getAttributes(Vi)).run():t.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let t=Et({find:_i,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Et({find:_i,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(Vi),editor:this.editor})),[t]}}),Na=X.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:t}){return["li",I(this.options.HTMLAttributes,t),0]},markdownTokenName:"list_item",parseMarkdown:(t,e)=>{if(t.type!=="list_item")return[];let n=[];if(t.tokens&&t.tokens.length>0)if(t.tokens.some(s=>s.type==="paragraph"))n=e.parseChildren(t.tokens);else{const s=t.tokens[0];if(s&&s.type==="text"&&s.tokens&&s.tokens.length>0){if(n=[{type:"paragraph",content:e.parseInline(s.tokens)}],t.tokens.length>1){const o=t.tokens.slice(1),l=e.parseChildren(o);n.push(...l)}}else n=e.parseChildren(t.tokens)}return n.length===0&&(n=[{type:"paragraph",content:[]}]),{type:"listItem",content:n}},renderMarkdown:(t,e,n)=>Cs(t,e,r=>{var s,i;return r.parentType==="bulletList"?"- ":r.parentType==="orderedList"?`${(((i=(s=r.meta)==null?void 0:s.parentAttrs)==null?void 0:i.start)||1)+r.index}. `:"- "},n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),lm={};im(lm,{findListItemPos:()=>Zt,getNextListDepth:()=>Es,handleBackspace:()=>Hr,handleDelete:()=>Fr,hasListBefore:()=>Oa,hasListItemAfter:()=>am,hasListItemBefore:()=>Ra,listItemHasSubList:()=>Da,nextListIsDeeper:()=>Ia,nextListIsHigher:()=>Pa});var Zt=(t,e)=>{const{$from:n}=e.selection,r=q(t,e.schema);let s=null,i=n.depth,o=n.pos,l=null;for(;i>0&&l===null;)s=n.node(i),s.type===r?l=i:(i-=1,o-=1);return l===null?null:{$pos:e.doc.resolve(o),depth:l}},Es=(t,e)=>{const n=Zt(t,e);if(!n)return!1;const[,r]=df(e,t,n.$pos.pos+4);return r},Oa=(t,e,n)=>{const{$anchor:r}=t.selection,s=Math.max(0,r.pos-2),i=t.doc.resolve(s).node();return!(!i||!n.includes(i.type.name))},Ra=(t,e)=>{var n;const{$anchor:r}=e.selection,s=e.doc.resolve(r.pos-2);return!(s.index()===0||((n=s.nodeBefore)==null?void 0:n.type.name)!==t)},Da=(t,e,n)=>{if(!n)return!1;const r=q(t,e.schema);let s=!1;return n.descendants(i=>{i.type===r&&(s=!0)}),s},Hr=(t,e,n)=>{if(t.commands.undoInputRule())return!0;if(t.state.selection.from!==t.state.selection.to)return!1;if(!qe(t.state,e)&&Oa(t.state,e,n)){const{$anchor:l}=t.state.selection,a=t.state.doc.resolve(l.before()-1),c=[];a.node().descendants((h,f)=>{h.type.name===e&&c.push({node:h,pos:f})});const d=c.at(-1);if(!d)return!1;const u=t.state.doc.resolve(a.start()+d.pos+1);return t.chain().cut({from:l.start()-1,to:l.end()+1},u.end()).joinForward().run()}if(!qe(t.state,e)||!pf(t.state))return!1;const r=Zt(e,t.state);if(!r)return!1;const i=t.state.doc.resolve(r.$pos.pos-2).node(r.depth),o=Da(e,t.state,i);return Ra(e,t.state)&&!o?t.commands.joinItemBackward():t.chain().liftListItem(e).run()},Ia=(t,e)=>{const n=Es(t,e),r=Zt(t,e);return!r||!n?!1:n>r.depth},Pa=(t,e)=>{const n=Es(t,e),r=Zt(t,e);return!r||!n?!1:n{if(!qe(t.state,e)||!ff(t.state,e))return!1;const{selection:n}=t.state,{$from:r,$to:s}=n;return!n.empty&&r.sameParent(s)?!1:Ia(e,t.state)?t.chain().focus(t.state.selection.from+4).lift(e).joinBackward().run():Pa(e,t.state)?t.chain().joinForward().joinBackward().run():t.commands.joinItemForward()},am=(t,e)=>{var n;const{$anchor:r}=e.selection,s=e.doc.resolve(r.pos-r.parentOffset-2);return!(s.index()===s.parent.childCount-1||((n=s.nodeAfter)==null?void 0:n.type.name)!==t)},La=$.create({name:"listKeymap",addOptions(){return{listTypes:[{itemName:"listItem",wrapperNames:["bulletList","orderedList"]},{itemName:"taskItem",wrapperNames:["taskList"]}]}},addKeyboardShortcuts(){return{Delete:({editor:t})=>{let e=!1;return this.options.listTypes.forEach(({itemName:n})=>{t.state.schema.nodes[n]!==void 0&&Fr(t,n)&&(e=!0)}),e},"Mod-Delete":({editor:t})=>{let e=!1;return this.options.listTypes.forEach(({itemName:n})=>{t.state.schema.nodes[n]!==void 0&&Fr(t,n)&&(e=!0)}),e},Backspace:({editor:t})=>{let e=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{t.state.schema.nodes[n]!==void 0&&Hr(t,n,r)&&(e=!0)}),e},"Mod-Backspace":({editor:t})=>{let e=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{t.state.schema.nodes[n]!==void 0&&Hr(t,n,r)&&(e=!0)}),e}}}}),Wi=/^(\s*)(\d+)\.\s+(.*)$/,cm=/^\s/;function dm(t){const e=[];let n=0,r=0;for(;ne;)h.push(t[u]),u+=1;if(h.length>0){const f=Math.min(...h.map(m=>m.indent)),p=za(h,f,n);c.push({type:"list",ordered:!0,start:h[0].number,items:p,raw:h.map(m=>m.raw).join(` `)})}s.push({type:"list_item",raw:o.raw,tokens:c}),i=u}else i+=1}return s}function um(t,e){return t.map(n=>{if(n.type!=="list_item")return e.parseChildren([n])[0];const r=[];return n.tokens&&n.tokens.length>0&&n.tokens.forEach(s=>{if(s.type==="paragraph"||s.type==="list"||s.type==="blockquote"||s.type==="code")r.push(...e.parseChildren([s]));else if(s.type==="text"&&s.tokens){const i=e.parseChildren([s]);r.push({type:"paragraph",content:i})}else{const i=e.parseChildren([s]);i.length>0&&r.push(...i)}}),{type:"listItem",content:r}})}var hm="listItem",ji="textStyle",qi=/^(\d+)\.\s$/,Ba=X.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:t=>t.hasAttribute("start")?parseInt(t.getAttribute("start")||"",10):1},type:{default:null,parseHTML:t=>t.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:t}){const{start:e,...n}=t;return e===1?["ol",I(this.options.HTMLAttributes,n),0]:["ol",I(this.options.HTMLAttributes,t),0]},markdownTokenName:"list",parseMarkdown:(t,e)=>{if(t.type!=="list"||!t.ordered)return[];const n=t.start||1,r=t.items?um(t.items,e):[];return n!==1?{type:"orderedList",attrs:{start:n},content:r}:{type:"orderedList",content:r}},renderMarkdown:(t,e)=>t.content?e.renderChildren(t.content,` `):"",markdownTokenizer:{name:"orderedList",level:"block",start:t=>{const e=t.match(/^(\s*)(\d+)\.\s+/),n=e==null?void 0:e.index;return n!==void 0?n:-1},tokenize:(t,e,n)=>{var r;const s=t.split(` `),[i,o]=dm(s);if(i.length===0)return;const l=za(i,0,n);return l.length===0?void 0:{type:"list",ordered:!0,start:((r=i[0])==null?void 0:r.number)||1,items:l,raw:s.slice(0,o).join(` `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:t,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(hm,this.editor.getAttributes(ji)).run():t.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let t=Et({find:qi,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Et({find:qi,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(ji)}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1],editor:this.editor})),[t]}}),fm=/^\s*(\[([( |x])?\])\s$/,pm=X.create({name:"taskItem",addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:"taskList",a11y:void 0}},content(){return this.options.nested?"paragraph block*":"paragraph+"},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:t=>{const e=t.getAttribute("data-checked");return e===""||e==="true"},renderHTML:t=>({"data-checked":t.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:t,HTMLAttributes:e}){return["li",I(this.options.HTMLAttributes,e,{"data-type":this.name}),["label",["input",{type:"checkbox",checked:t.attrs.checked?"checked":null}],["span"]],["div",0]]},parseMarkdown:(t,e)=>{const n=[];if(t.tokens&&t.tokens.length>0?n.push(e.createNode("paragraph",{},e.parseInline(t.tokens))):t.text?n.push(e.createNode("paragraph",{},[e.createNode("text",{text:t.text})])):n.push(e.createNode("paragraph",{},[])),t.nestedTokens&&t.nestedTokens.length>0){const r=e.parseChildren(t.nestedTokens);n.push(...r)}return e.createNode("taskItem",{checked:t.checked||!1},n)},renderMarkdown:(t,e)=>{var n;const s=`- [${(n=t.attrs)!=null&&n.checked?"x":" "}] `;return Cs(t,e,s)},addKeyboardShortcuts(){const t={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...t,Tab:()=>this.editor.commands.sinkListItem(this.name)}:t},addNodeView(){return({node:t,HTMLAttributes:e,getPos:n,editor:r})=>{const s=document.createElement("li"),i=document.createElement("label"),o=document.createElement("span"),l=document.createElement("input"),a=document.createElement("div"),c=u=>{var h,f;l.ariaLabel=((f=(h=this.options.a11y)==null?void 0:h.checkboxLabel)==null?void 0:f.call(h,u,l.checked))||`Task item checkbox for ${u.textContent||"empty task item"}`};c(t),i.contentEditable="false",l.type="checkbox",l.addEventListener("mousedown",u=>u.preventDefault()),l.addEventListener("change",u=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){l.checked=!l.checked;return}const{checked:h}=u.target;r.isEditable&&typeof n=="function"&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:f})=>{const p=n();if(typeof p!="number")return!1;const m=f.doc.nodeAt(p);return f.setNodeMarkup(p,void 0,{...m==null?void 0:m.attrs,checked:h}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(t,h)||(l.checked=!l.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([u,h])=>{s.setAttribute(u,h)}),s.dataset.checked=t.attrs.checked,l.checked=t.attrs.checked,i.append(l,o),s.append(i,a),Object.entries(e).forEach(([u,h])=>{s.setAttribute(u,h)});let d=new Set(Object.keys(e));return{dom:s,contentDOM:a,update:u=>{if(u.type!==this.type)return!1;s.dataset.checked=u.attrs.checked,l.checked=u.attrs.checked,c(u);const h=r.extensionManager.attributes,f=Tt(u,h),p=new Set(Object.keys(f)),m=this.options.HTMLAttributes;return d.forEach(g=>{p.has(g)||(g in m?s.setAttribute(g,m[g]):s.removeAttribute(g))}),Object.entries(f).forEach(([g,y])=>{y==null?g in m?s.setAttribute(g,m[g]):s.removeAttribute(g):s.setAttribute(g,y)}),d=p,!0}}}},addInputRules(){return[Et({find:fm,type:this.type,getAttributes:t=>({checked:t[t.length-1]==="x"})})]}}),mm=X.create({name:"taskList",addOptions(){return{itemTypeName:"taskItem",HTMLAttributes:{}}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:t}){return["ul",I(this.options.HTMLAttributes,t,{"data-type":this.name}),0]},parseMarkdown:(t,e)=>e.createNode("taskList",{},e.parseChildren(t.items||[])),renderMarkdown:(t,e)=>t.content?e.renderChildren(t.content,` `):"",markdownTokenizer:{name:"taskList",level:"block",start(t){var e;const n=(e=t.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:e.index;return n!==void 0?n:-1},tokenize(t,e,n){const r=i=>{const o=Br(i,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:l=>({indentLevel:l[1].length,mainContent:l[4],checked:l[3].toLowerCase()==="x"}),createToken:(l,a)=>({type:"taskItem",raw:"",mainContent:l.mainContent,indentLevel:l.indentLevel,checked:l.checked,text:l.mainContent,tokens:n.inlineTokens(l.mainContent),nestedTokens:a}),customNestedParser:r},n);return o?[{type:"taskList",raw:o.raw,items:o.items}]:n.blockTokens(i)},s=Br(t,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:i=>({indentLevel:i[1].length,mainContent:i[4],checked:i[3].toLowerCase()==="x"}),createToken:(i,o)=>({type:"taskItem",raw:"",mainContent:i.mainContent,indentLevel:i.indentLevel,checked:i.checked,text:i.mainContent,tokens:n.inlineTokens(i.mainContent),nestedTokens:o}),customNestedParser:r},n);if(s)return{type:"taskList",raw:s.raw,items:s.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:t})=>t.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});$.create({name:"listKit",addExtensions(){const t=[];return this.options.bulletList!==!1&&t.push(Aa.configure(this.options.bulletList)),this.options.listItem!==!1&&t.push(Na.configure(this.options.listItem)),this.options.listKeymap!==!1&&t.push(La.configure(this.options.listKeymap)),this.options.orderedList!==!1&&t.push(Ba.configure(this.options.orderedList)),this.options.taskItem!==!1&&t.push(pm.configure(this.options.taskItem)),this.options.taskList!==!1&&t.push(mm.configure(this.options.taskList)),t}});var Ki=" ",gm=" ",ym=X.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",I(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];if(n.length===1&&n[0].type==="image")return e.parseChildren([n[0]]);const r=e.parseInline(n);return r.length===1&&r[0].type==="text"&&(r[0].text===Ki||r[0].text===gm)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,r)},renderMarkdown:(t,e)=>{if(!t)return"";const n=Array.isArray(t.content)?t.content:[];return n.length===0?Ki:e.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),bm=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,km=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,wm=xe.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",I(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[dt({find:bm,type:this.type})]},addPasteRules(){return[Ke({find:km,type:this.type})]}}),xm=X.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),Sm=xe.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",I(this.options.HTMLAttributes,t),0]},parseMarkdown(t,e){return e.applyMark(this.name||"underline",e.parseInline(t.tokens||[]))},renderMarkdown(t,e){return`++${e.renderChildren(t)}++`},markdownTokenizer:{name:"underline",level:"inline",start(t){return t.indexOf("++")},tokenize(t,e,n){const s=/^(\+\+)([\s\S]+?)(\+\+)/.exec(t);if(!s)return;const i=s[2].trim();return{type:"underline",raw:s[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function Cm(t={}){return new B({view(e){return new Mm(e,t)}})}class Mm{constructor(e,n){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=n.width)!==null&&r!==void 0?r:1,this.color=n.color===!1?void 0:n.color||"black",this.class=n.class,this.handlers=["dragover","dragend","drop","dragleave"].map(s=>{let i=o=>{this[s](o)};return e.dom.addEventListener(s,i),{name:s,handler:i}})}destroy(){this.handlers.forEach(({name:e,handler:n})=>this.editorView.dom.removeEventListener(e,n))}update(e,n){this.cursorPos!=null&&n.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),n=!e.parent.inlineContent,r,s=this.editorView.dom,i=s.getBoundingClientRect(),o=i.width/s.offsetWidth,l=i.height/s.offsetHeight;if(n){let u=e.nodeBefore,h=e.nodeAfter;if(u||h){let f=this.editorView.nodeDOM(this.cursorPos-(u?u.nodeSize:0));if(f){let p=f.getBoundingClientRect(),m=u?p.bottom:p.top;u&&h&&(m=(m+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let g=this.width/2*l;r={left:p.left,right:p.right,top:m-g,bottom:m+g}}}}if(!r){let u=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*o;r={left:u.left-h,right:u.left+h,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",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n);let c,d;if(!a||a==document.body&&getComputedStyle(a).position=="static")c=-pageXOffset,d=-pageYOffset;else{let u=a.getBoundingClientRect(),h=u.width/a.offsetWidth,f=u.height/a.offsetHeight;c=u.left-a.scrollLeft*h,d=u.top-a.scrollTop*f}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 n=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=n&&n.inside>=0&&this.editorView.state.doc.nodeAt(n.inside),s=r&&r.type.spec.disableDropCursor,i=typeof s=="function"?s(this.editorView,n,e):s;if(n&&!i){let o=n.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=_o(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)}}class H extends N{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return H.valid(r)?new H(r):N.near(r)}content(){return x.empty}eq(e){return e instanceof H&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new H(e.resolve(n.pos))}getBookmark(){return new As(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!vm(e)||!Tm(e))return!1;let r=n.type.spec.allowGapCursor;if(r!=null)return r;let s=n.contentMatchAt(e.index()).defaultType;return s&&s.isTextblock}static findGapCursorFrom(e,n,r=!1){e:for(;;){if(!r&&H.valid(e))return e;let s=e.pos,i=null;for(let o=e.depth;;o--){let l=e.node(o);if(n>0?e.indexAfter(o)0){i=l.child(n>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;s+=n;let a=e.doc.resolve(s);if(H.valid(a))return a}for(;;){let o=n>0?i.firstChild:i.lastChild;if(!o){if(i.isAtom&&!i.isText&&!T.isSelectable(i)){e=e.doc.resolve(s+i.nodeSize*n),r=!1;continue e}break}i=o,s+=n;let l=e.doc.resolve(s);if(H.valid(l))return l}return null}}}H.prototype.visible=!1;H.findFrom=H.findGapCursorFrom;N.jsonID("gapcursor",H);class As{constructor(e){this.pos=e}map(e){return new As(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return H.valid(n)?new H(n):N.near(n)}}function $a(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function vm(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),r=t.node(e);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let s=r.child(n-1);;s=s.lastChild){if(s.childCount==0&&!s.inlineContent||$a(s.type))return!0;if(s.inlineContent)return!1}}return!0}function Tm(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),r=t.node(e);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let s=r.child(n);;s=s.firstChild){if(s.childCount==0&&!s.inlineContent||$a(s.type))return!0;if(s.inlineContent)return!1}}return!0}function Em(){return new B({props:{decorations:Rm,createSelectionBetween(t,e,n){return e.pos==n.pos&&H.valid(n)?new H(n):null},handleClick:Nm,handleKeyDown:Am,handleDOMEvents:{beforeinput:Om}}})}const Am=fs({ArrowLeft:cn("horiz",-1),ArrowRight:cn("horiz",1),ArrowUp:cn("vert",-1),ArrowDown:cn("vert",1)});function cn(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,s,i){let o=r.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof E){if(!i.endOfTextblock(n)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let c=H.findGapCursorFrom(l,e,a);return c?(s&&s(r.tr.setSelection(new H(c))),!0):!1}}function Nm(t,e,n){if(!t||!t.editable)return!1;let r=t.state.doc.resolve(e);if(!H.valid(r))return!1;let s=t.posAtCoords({left:n.clientX,top:n.clientY});return s&&s.inside>-1&&T.isSelectable(t.state.doc.nodeAt(s.inside))?!1:(t.dispatch(t.state.tr.setSelection(new H(r))),!0)}function Om(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof H))return!1;let{$from:n}=t.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!r)return!1;let s=b.empty;for(let o=r.length-1;o>=0;o--)s=b.from(r[o].createAndFill(null,s));let i=t.state.tr.replace(n.pos,n.pos,new x(s,0,0));return i.setSelection(E.near(i.doc.resolve(n.pos+1))),t.dispatch(i),!1}function Rm(t){if(!(t.selection instanceof H))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(t.doc,[U.widget(t.selection.head,e,{key:"gapcursor"})])}const Dm=500;class pe{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let s,i;n&&(s=this.remapping(r,this.items.length),i=s.maps.length);let o=e.tr,l,a,c=[],d=[];return this.items.forEach((u,h)=>{if(!u.step){s||(s=this.remapping(r,h+1),i=s.maps.length),i--,d.push(u);return}if(s){d.push(new be(u.map));let f=u.step.map(s.slice(i)),p;f&&o.maybeStep(f).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new be(p,void 0,void 0,c.length+d.length))),i--,p&&s.appendMap(p,i)}else o.maybeStep(u.step);if(u.selection)return l=s?u.selection.map(s.slice(i)):u.selection,a=new pe(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,n,r,s){let i=[],o=this.eventCount,l=this.items,a=!s&&l.length?l.get(l.length-1):null;for(let d=0;dPm&&(l=Im(l,c),o-=c),new pe(l.append(i),o)}remapping(e,n){let r=new Vt;return this.items.forEach((s,i)=>{let o=s.mirrorOffset!=null&&i-s.mirrorOffset>=e?r.maps.length-s.mirrorOffset:void 0;r.appendMap(s.map,o)},e,n),r}addMaps(e){return this.eventCount==0?this:new pe(this.items.append(e.map(n=>new be(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let r=[],s=Math.max(0,this.items.length-n),i=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},s);let a=n;this.items.forEach(h=>{let f=i.getMirror(--a);if(f==null)return;o=Math.min(o,f);let p=i.maps[f];if(h.step){let m=e.steps[f].invert(e.docs[f]),g=h.selection&&h.selection.map(i.slice(a+1,f));g&&l++,r.push(new be(p,m,g))}else r.push(new be(p))},s);let c=[];for(let h=n;hDm&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),r=n.maps.length,s=[],i=0;return this.items.forEach((o,l)=>{if(l>=e)s.push(o),o.selection&&i++;else if(o.step){let a=o.step.map(n.slice(r)),c=a&&a.getMap();if(r--,c&&n.appendMap(c,r),a){let d=o.selection&&o.selection.map(n.slice(r));d&&i++;let u=new be(c.invert(),a,d),h,f=s.length-1;(h=s.length&&s[f].merge(u))?s[f]=h:s.push(u)}}else o.map&&r--},this.items.length,0),new pe(mo.from(s.reverse()),i)}}pe.empty=new pe(mo.empty,0);function Im(t,e){let n;return t.forEach((r,s)=>{if(r.selection&&e--==0)return n=s,!1}),t.slice(n)}class be{constructor(e,n,r,s){this.map=e,this.step=n,this.selection=r,this.mirrorOffset=s}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new be(n.getMap().invert(),n,this.selection)}}}class ze{constructor(e,n,r,s,i){this.done=e,this.undone=n,this.prevRanges=r,this.prevTime=s,this.prevComposition=i}}const Pm=20;function Lm(t,e,n,r){let s=n.getMeta(st),i;if(s)return s.historyState;n.getMeta($m)&&(t=new ze(t.done,t.undone,null,0,-1));let o=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(o&&o.getMeta(st))return o.getMeta(st).redo?new ze(t.done.addTransform(n,void 0,r,bn(e)),t.undone,Ui(n.mapping.maps),t.prevTime,t.prevComposition):new ze(t.done,t.undone.addTransform(n,void 0,r,bn(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=n.getMeta("composition"),a=t.prevTime==0||!o&&t.prevComposition!=l&&(t.prevTime<(n.time||0)-r.newGroupDelay||!zm(n,t.prevRanges)),c=o?pr(t.prevRanges,n.mapping):Ui(n.mapping.maps);return new ze(t.done.addTransform(n,a?e.selection.getBookmark():void 0,r,bn(e)),pe.empty,c,n.time,l??t.prevComposition)}else return(i=n.getMeta("rebased"))?new ze(t.done.rebased(n,i),t.undone.rebased(n,i),pr(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new ze(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),pr(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function zm(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((r,s)=>{for(let i=0;i=e[i]&&(n=!0)}),n}function Ui(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((r,s,i,o)=>e.push(i,o));return e}function pr(t,e){if(!t)return null;let n=[];for(let r=0;r{let s=st.getState(n);if(!s||(t?s.undone:s.done).eventCount==0)return!1;if(r){let i=Bm(s,n,t);i&&r(e?i.scrollIntoView():i)}return!0}}const Fa=Ha(!1,!0),Va=Ha(!0,!0);$.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:t=>t.length,wordCounter:t=>t.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc;if(((t==null?void 0:t.mode)||this.options.mode)==="textSize"){const r=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(r)}return e.nodeSize},this.storage.words=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc,n=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let t=!1;return[new B({key:new _("characterCount"),appendTransaction:(e,n,r)=>{if(t)return;const s=this.options.limit;if(s==null||s===0){t=!0;return}const i=this.storage.characters({node:r.doc});if(i>s){const o=i-s,l=0,a=o;console.warn(`[CharacterCount] Initial content exceeded limit of ${s} characters. Content was automatically trimmed.`);const c=r.tr.deleteRange(l,a);return t=!0,c}t=!0},filterTransaction:(e,n)=>{const r=this.options.limit;if(!e.docChanged||r===0||r===null||r===void 0)return!0;const s=this.storage.characters({node:n.doc}),i=this.storage.characters({node:e.doc});if(i<=r||s>r&&i>r&&i<=s)return!0;if(s>r&&i>r&&i>s||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=i-r,c=l-a,d=l;return e.deleteRange(c,d),!(this.storage.characters({node:e.doc})>r)}})]}});var Fm=$.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[Cm(this.options)]}});$.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new B({key:new _("focus"),props:{decorations:({doc:t,selection:e})=>{const{isEditable:n,isFocused:r}=this.editor,{anchor:s}=e,i=[];if(!n||!r)return L.create(t,[]);let o=0;this.options.mode==="deepest"&&t.descendants((a,c)=>{if(a.isText)return;if(!(s>=c&&s<=c+a.nodeSize-1))return!1;o+=1});let l=0;return t.descendants((a,c)=>{if(a.isText||!(s>=c&&s<=c+a.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&o-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";i.push(U.node(c,c+a.nodeSize,{class:this.options.className}))}),L.create(t,i)}}})]}});var Vm=$.create({name:"gapCursor",addProseMirrorPlugins(){return[Em()]},extendNodeSchema(t){var e;const n={name:t.name,options:t.options,storage:t.storage};return{allowGapCursor:(e=D(M(t,"allowGapCursor",n)))!=null?e:null}}}),Xi="placeholder";function _m(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}$.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Xi,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const t=this.options.dataAttribute?`data-${_m(this.options.dataAttribute)}`:`data-${Xi}`;return[new B({key:new _("placeholder"),props:{decorations:({doc:e,selection:n})=>{const r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:s}=n,i=[];if(!r)return null;const o=this.editor.isEmpty;return e.descendants((l,a)=>{const c=s>=a&&s<=a+l.nodeSize,d=!l.isLeaf&&Kn(l);if((c||!this.options.showOnlyCurrent)&&d){const u=[this.options.emptyNodeClass];o&&u.push(this.options.emptyEditorClass);const h=U.node(a,a+l.nodeSize,{class:u.join(" "),[t]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:a,hasAnchor:c}):this.options.placeholder});i.push(h)}return this.options.includeChildren}),L.create(e,i)}}})]}});var _y=$.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:t,options:e}=this;return[new B({key:new _("selection"),props:{decorations(n){return n.selection.empty||t.isFocused||!t.isEditable||sa(n.selection)||t.view.dragging?null:L.create(n.doc,[U.inline(n.selection.from,n.selection.to,{class:e.className})])}}})]}});function Gi({types:t,node:e}){return e&&Array.isArray(t)&&t.includes(e.type)||(e==null?void 0:e.type)===t}var Wm=$.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var t;const e=new _(this.name),n=this.options.node||((t=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:t.name)||"paragraph",r=Object.entries(this.editor.schema.nodes).map(([,s])=>s).filter(s=>(this.options.notAfter||[]).concat(n).includes(s.name));return[new B({key:e,appendTransaction:(s,i,o)=>{const{doc:l,tr:a,schema:c}=o,d=e.getState(o),u=l.content.size,h=c.nodes[n];if(d)return a.insert(u,h.create())},state:{init:(s,i)=>{const o=i.tr.doc.lastChild;return!Gi({node:o,types:r})},apply:(s,i)=>{if(!s.docChanged||s.getMeta("__uniqueIDTransaction"))return i;const o=s.doc.lastChild;return!Gi({node:o,types:r})}}})]}}),jm=$.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>Fa(t,e),redo:()=>({state:t,dispatch:e})=>Va(t,e)}},addProseMirrorPlugins(){return[Hm(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()}}}),Wy=$.create({name:"starterKit",addExtensions(){var t,e,n,r;const s=[];return this.options.bold!==!1&&s.push(Lp.configure(this.options.bold)),this.options.blockquote!==!1&&s.push(Op.configure(this.options.blockquote)),this.options.bulletList!==!1&&s.push(Aa.configure(this.options.bulletList)),this.options.code!==!1&&s.push($p.configure(this.options.code)),this.options.codeBlock!==!1&&s.push(Vp.configure(this.options.codeBlock)),this.options.document!==!1&&s.push(_p.configure(this.options.document)),this.options.dropcursor!==!1&&s.push(Fm.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&s.push(Vm.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&s.push(Wp.configure(this.options.hardBreak)),this.options.heading!==!1&&s.push(jp.configure(this.options.heading)),this.options.undoRedo!==!1&&s.push(jm.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&s.push(Ea.configure(this.options.horizontalRule)),this.options.italic!==!1&&s.push(Xp.configure(this.options.italic)),this.options.listItem!==!1&&s.push(Na.configure(this.options.listItem)),this.options.listKeymap!==!1&&s.push(La.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&s.push(rm.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&s.push(Ba.configure(this.options.orderedList)),this.options.paragraph!==!1&&s.push(ym.configure(this.options.paragraph)),this.options.strike!==!1&&s.push(wm.configure(this.options.strike)),this.options.text!==!1&&s.push(xm.configure(this.options.text)),this.options.underline!==!1&&s.push(Sm.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&s.push(Wm.configure((r=this.options)==null?void 0:r.trailingNode)),s}}),jy=$.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:t=>{const e=t.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:t=>t.textAlign?{style:`text-align: ${t.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:t=>({commands:e})=>this.options.alignments.includes(t)?this.options.types.map(n=>e.updateAttributes(n,{textAlign:t})).some(n=>n):!1,unsetTextAlign:()=>({commands:t})=>this.options.types.map(e=>t.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:t=>({editor:e,commands:n})=>this.options.alignments.includes(t)?e.isActive({textAlign:t})?n.unsetTextAlign():n.setTextAlign(t):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),qm=t=>W({find:/--$/,replace:t??"—"}),Km=t=>W({find:/\.\.\.$/,replace:t??"…"}),Um=t=>W({find:/(?:^|[\s{[(<'"\u2018\u201C])(")$/,replace:t??"“"}),Jm=t=>W({find:/"$/,replace:t??"”"}),Xm=t=>W({find:/(?:^|[\s{[(<'"\u2018\u201C])(')$/,replace:t??"‘"}),Gm=t=>W({find:/'$/,replace:t??"’"}),Ym=t=>W({find:/<-$/,replace:t??"←"}),Qm=t=>W({find:/->$/,replace:t??"→"}),Zm=t=>W({find:/\(c\)$/,replace:t??"©"}),eg=t=>W({find:/\(tm\)$/,replace:t??"™"}),tg=t=>W({find:/\(sm\)$/,replace:t??"℠"}),ng=t=>W({find:/\(r\)$/,replace:t??"®"}),rg=t=>W({find:/(?:^|\s)(1\/2)\s$/,replace:t??"½"}),sg=t=>W({find:/\+\/-$/,replace:t??"±"}),ig=t=>W({find:/!=$/,replace:t??"≠"}),og=t=>W({find:/<<$/,replace:t??"«"}),lg=t=>W({find:/>>$/,replace:t??"»"}),ag=t=>W({find:/\d+\s?([*x])\s?\d+$/,replace:t??"×"}),cg=t=>W({find:/\^2$/,replace:t??"²"}),dg=t=>W({find:/\^3$/,replace:t??"³"}),ug=t=>W({find:/(?:^|\s)(1\/4)\s$/,replace:t??"¼"}),hg=t=>W({find:/(?:^|\s)(3\/4)\s$/,replace:t??"¾"}),qy=$.create({name:"typography",addOptions(){return{closeDoubleQuote:"”",closeSingleQuote:"’",copyright:"©",ellipsis:"…",emDash:"—",laquo:"«",leftArrow:"←",multiplication:"×",notEqual:"≠",oneHalf:"½",oneQuarter:"¼",openDoubleQuote:"“",openSingleQuote:"‘",plusMinus:"±",raquo:"»",registeredTrademark:"®",rightArrow:"→",servicemark:"℠",superscriptThree:"³",superscriptTwo:"²",threeQuarters:"¾",trademark:"™"}},addInputRules(){const t=[];return this.options.emDash!==!1&&t.push(qm(this.options.emDash)),this.options.ellipsis!==!1&&t.push(Km(this.options.ellipsis)),this.options.openDoubleQuote!==!1&&t.push(Um(this.options.openDoubleQuote)),this.options.closeDoubleQuote!==!1&&t.push(Jm(this.options.closeDoubleQuote)),this.options.openSingleQuote!==!1&&t.push(Xm(this.options.openSingleQuote)),this.options.closeSingleQuote!==!1&&t.push(Gm(this.options.closeSingleQuote)),this.options.leftArrow!==!1&&t.push(Ym(this.options.leftArrow)),this.options.rightArrow!==!1&&t.push(Qm(this.options.rightArrow)),this.options.copyright!==!1&&t.push(Zm(this.options.copyright)),this.options.trademark!==!1&&t.push(eg(this.options.trademark)),this.options.servicemark!==!1&&t.push(tg(this.options.servicemark)),this.options.registeredTrademark!==!1&&t.push(ng(this.options.registeredTrademark)),this.options.oneHalf!==!1&&t.push(rg(this.options.oneHalf)),this.options.plusMinus!==!1&&t.push(sg(this.options.plusMinus)),this.options.notEqual!==!1&&t.push(ig(this.options.notEqual)),this.options.laquo!==!1&&t.push(og(this.options.laquo)),this.options.raquo!==!1&&t.push(lg(this.options.raquo)),this.options.multiplication!==!1&&t.push(ag(this.options.multiplication)),this.options.superscriptTwo!==!1&&t.push(cg(this.options.superscriptTwo)),this.options.superscriptThree!==!1&&t.push(dg(this.options.superscriptThree)),this.options.oneQuarter!==!1&&t.push(ug(this.options.oneQuarter)),this.options.threeQuarters!==!1&&t.push(hg(this.options.threeQuarters)),t}}),fg=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,pg=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,Ky=xe.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:t=>t.getAttribute("data-color")||t.style.backgroundColor,renderHTML:t=>t.color?{"data-color":t.color,style:`background-color: ${t.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:t}){return["mark",I(this.options.HTMLAttributes,t),0]},renderMarkdown:(t,e)=>`==${e.renderChildren(t)}==`,parseMarkdown:(t,e)=>e.applyMark("highlight",e.parseInline(t.tokens||[])),markdownTokenizer:{name:"highlight",level:"inline",start:t=>t.indexOf("=="),tokenize(t,e,n){const s=/^(==)([^=]+)(==)/.exec(t);if(s){const i=s[2].trim(),o=n.inlineTokens(i);return{type:"highlight",raw:s[0],text:i,tokens:o}}}},addCommands(){return{setHighlight:t=>({commands:e})=>e.setMark(this.name,t),toggleHighlight:t=>({commands:e})=>e.toggleMark(this.name,t),unsetHighlight:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[dt({find:fg,type:this.type})]},addPasteRules(){return[Ke({find:pg,type:this.type})]}}),Uy=xe.create({name:"subscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sub"},{style:"vertical-align",getAttrs(t){return t!=="sub"?!1:null}}]},renderHTML({HTMLAttributes:t}){return["sub",I(this.options.HTMLAttributes,t),0]},addCommands(){return{setSubscript:()=>({commands:t})=>t.setMark(this.name),toggleSubscript:()=>({commands:t})=>t.toggleMark(this.name),unsetSubscript:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-,":()=>this.editor.commands.toggleSubscript()}}}),Jy=xe.create({name:"superscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sup"},{style:"vertical-align",getAttrs(t){return t!=="super"?!1:null}}]},renderHTML({HTMLAttributes:t}){return["sup",I(this.options.HTMLAttributes,t),0]},addCommands(){return{setSuperscript:()=>({commands:t})=>t.setMark(this.name),toggleSuperscript:()=>({commands:t})=>t.toggleMark(this.name),unsetSuperscript:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-.":()=>this.editor.commands.toggleSuperscript()}}});let Vr,_r;if(typeof WeakMap<"u"){let t=new WeakMap;Vr=e=>t.get(e),_r=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;Vr=r=>{for(let s=0;s(n==10&&(n=0),t[n++]=r,t[n++]=s)}var F=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e=n){(i||(i=[])).push({type:"overlong_rowspan",pos:d,n:y-w});break}const S=s+w*e;for(let C=0;Cr&&(i+=c.attrs.colspan)}}for(let o=0;o1&&(n=!0)}e==-1?e=i:e!=i&&(e=Math.max(e,i))}return e}function yg(t,e,n){t.problems||(t.problems=[]);const r={};for(let s=0;s0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function kg(t){for(let e=t.depth;e>0;e--){const n=t.node(e).type.spec.tableRole;if(n==="cell"||n==="header_cell")return t.node(e)}return null}function ye(t){const e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function Jn(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const n=ut(e.$head)||wg(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function wg(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function Wr(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function xg(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function Ns(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function _a(t,e,n){const r=t.node(-1),s=F.get(r),i=t.start(-1),o=s.nextCell(t.pos-i,e,n);return o==null?null:t.node(0).resolve(i+o)}function ht(t,e,n=1){const r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(s=>s>0)||(r.colwidth=null)),r}function Wa(t,e,n=1){const r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let s=0;sd!=n.pos-i);a.unshift(n.pos-i);const c=a.map(d=>{const u=r.nodeAt(d);if(!u)throw new RangeError(`No cell with offset ${d} found`);const h=i+d+1;return new Uo(l.resolve(h),l.resolve(h+u.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){const r=e.resolve(n.map(this.$anchorCell.pos)),s=e.resolve(n.map(this.$headCell.pos));if(Wr(r)&&Wr(s)&&Ns(r,s)){const i=this.$anchorCell.node(-1)!=r.node(-1);return i&&this.isRowSelection()?Te.rowSelection(r,s):i&&this.isColSelection()?Te.colSelection(r,s):new Te(r,s)}return E.between(r,s)}content(){const e=this.$anchorCell.node(-1),n=F.get(e),r=this.$anchorCell.start(-1),s=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),i={},o=[];for(let a=s.top;a0||g>0){let y=p.attrs;if(m>0&&(y=ht(y,0,m)),g>0&&(y=ht(y,y.colspan-g,g)),f.lefts.bottom){const y={...p.attrs,rowspan:Math.min(f.bottom,s.bottom)-Math.max(f.top,s.top)};f.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,s=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,s)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){const r=e.node(-1),s=F.get(r),i=e.start(-1),o=s.findCell(e.pos-i),l=s.findCell(n.pos-i),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(i+s.map[o.left])),l.bottom0&&(n=a.resolve(i+s.map[l.left])),o.bottom0)return!1;const o=s+this.$anchorCell.nodeAfter.attrs.colspan,l=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==n.width}eq(e){return e instanceof Te&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){const r=e.node(-1),s=F.get(r),i=e.start(-1),o=s.findCell(e.pos-i),l=s.findCell(n.pos-i),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(i+s.map[o.top*s.width])),l.right0&&(n=a.resolve(i+s.map[l.top*s.width])),o.right{e.push(U.node(r,r+n.nodeSize,{class:"selectedCell"}))}),L.create(t.doc,e)}function vg({$from:t,$to:e}){if(t.pos==e.pos||t.pos=0&&!(t.after(s+1)=0&&!(e.before(i+1)>e.start(i));i--,r--);return n==r&&/row|table/.test(t.node(s).type.spec.tableRole)}function Tg({$from:t,$to:e}){let n,r;for(let s=t.depth;s>0;s--){const i=t.node(s);if(i.type.spec.tableRole==="cell"||i.type.spec.tableRole==="header_cell"){n=i;break}}for(let s=e.depth;s>0;s--){const i=e.node(s);if(i.type.spec.tableRole==="cell"||i.type.spec.tableRole==="header_cell"){r=i;break}}return n!==r&&e.parentOffset===0}function Eg(t,e,n){const r=(e||t).selection,s=(e||t).doc;let i,o;if(r instanceof T&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")i=z.create(s,r.from);else if(o=="row"){const l=s.resolve(r.from+1);i=z.rowSelection(l,l)}else if(!n){const l=F.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];i=z.create(s,a+1,c)}}else r instanceof E&&vg(r)?i=E.create(s,r.from):r instanceof E&&Tg(r)&&(i=E.create(s,r.$from.start(),r.$from.end()));return i&&(e||(e=t.tr)).setSelection(i),e}const Ag=new _("fix-tables");function qa(t,e,n,r){const s=t.childCount,i=e.childCount;e:for(let o=0,l=0;o{s.type.spec.tableRole=="table"&&(n=Ng(t,s,i,n))};return e?e.doc!=t.doc&&qa(e.doc,t.doc,0,r):t.doc.descendants(r),n}function Ng(t,e,n,r){const s=F.get(e);if(!s.problems)return r;r||(r=t.tr);const i=[];for(let a=0;a0){let f="cell";d.firstChild&&(f=d.firstChild.type.spec.tableRole);const p=[];for(let g=0;g0?-1:0;Sg(e,r,s+i)&&(i=s==0||s==e.width?null:0);for(let o=0;o0&&s0&&e.map[l-1]==a||s0?-1:0;Pg(e,r,s+l)&&(l=s==0||s==e.height?null:0);for(let c=0,d=e.width*s;c0&&s0&&u==e.map[d-e.width]){const h=n.nodeAt(u).attrs;t.setNodeMarkup(t.mapping.slice(l).map(u+r),null,{...h,rowspan:h.rowspan-1}),c+=h.colspan-1}else if(s0&&n[i]==n[i-1]||r.right0&&n[s]==n[s-t]||r.bottom0){const d=a+1+c.content.size,u=Yi(c)?a+1:d;i.replaceWith(u+r.tableStart,d+r.tableStart,l)}i.setSelection(new z(i.doc.resolve(a+r.tableStart))),e(i)}return!0}function Zi(t,e){const n=ee(t.schema);return Fg(({node:r})=>n[r.type.spec.tableRole])(t,e)}function Fg(t){return(e,n)=>{const r=e.selection;let s,i;if(r instanceof z){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;s=r.$anchorCell.nodeAfter,i=r.$anchorCell.pos}else{var o;if(s=kg(r.$from),!s)return!1;i=(o=ut(r.$from))===null||o===void 0?void 0:o.pos}if(s==null||i==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(n){let l=s.attrs;const a=[],c=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});const d=Se(e),u=e.tr;for(let f=0;f{o.attrs[t]!==e&&i.setNodeMarkup(l,null,{...o.attrs,[t]:e})}):i.setNodeMarkup(s.pos,null,{...s.nodeAfter.attrs,[t]:e}),r(i)}return!0}}function _g(t){return function(e,n){if(!ye(e))return!1;if(n){const r=ee(e.schema),s=Se(e),i=e.tr,o=s.map.cellsInRect(t=="column"?{left:s.left,top:0,right:s.right,bottom:s.map.height}:t=="row"?{left:0,top:s.top,right:s.map.width,bottom:s.bottom}:s),l=o.map(a=>s.table.nodeAt(a));for(let a=0;a{const f=h+i.tableStart,p=o.doc.nodeAt(f);p&&o.setNodeMarkup(f,u,p.attrs)}),r(o)}return!0}}Jt("row",{useDeprecatedLogic:!0});Jt("column",{useDeprecatedLogic:!0});const Wg=Jt("cell",{useDeprecatedLogic:!0});function jg(t,e){if(e<0){const n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,s=t.before();r>=0;r--){const i=t.node(-1).child(r),o=i.lastChild;if(o)return s-1-o.nodeSize;s-=i.nodeSize}}else{if(t.index()0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function dn(t,e){const n=t.selection;if(!(n instanceof z))return!1;if(e){const r=t.tr,s=ee(t.schema).cell.createAndFill().content;n.forEachCell((i,o)=>{i.content.eq(s)||r.replace(r.mapping.map(o+1),r.mapping.map(o+i.nodeSize-1),new x(s,0,0))}),r.docChanged&&e(r)}return!0}function Kg(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;const s=e.child(0),i=s.type.spec.tableRole,o=s.type.schema,l=[];if(i=="row")for(let a=0;a=0;o--){const{rowspan:l,colspan:a}=i.child(o).attrs;for(let c=s;c=e.length&&e.push(b.empty),n[s]r&&(h=h.type.createChecked(ht(h.attrs,h.attrs.colspan,d+h.attrs.colspan-r),h.content)),c.push(h),d+=h.attrs.colspan;for(let f=1;fs&&(u=u.type.create({...u.attrs,rowspan:Math.max(1,s-u.attrs.rowspan)},u.content)),a.push(u)}i.push(b.from(a))}n=i,e=s}return{width:t,height:e,rows:n}}function Xg(t,e,n,r,s,i,o){const l=t.doc.type.schema,a=ee(l);let c,d;if(s>e.width)for(let u=0,h=0;ue.height){const u=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:n.nodeAt(e.map[m+p]).type==a.header_cell;u.push(g?d||(d=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const h=a.row.create(null,b.from(u)),f=[];for(let p=e.height;p{if(!s)return!1;const i=n.selection;if(i instanceof z)return kn(n,r,N.near(i.$headCell,e));if(t!="horiz"&&!i.empty)return!1;const o=Xa(s,t,e);if(o==null)return!1;if(t=="horiz")return kn(n,r,N.near(n.doc.resolve(i.head+e),e));{const l=n.doc.resolve(o),a=_a(l,t,e);let c;return a?c=N.near(a,1):e<0?c=N.near(n.doc.resolve(l.before(-1)),-1):c=N.near(n.doc.resolve(l.after(-1)),1),kn(n,r,c)}}}function hn(t,e){return(n,r,s)=>{if(!s)return!1;const i=n.selection;let o;if(i instanceof z)o=i;else{const a=Xa(s,t,e);if(a==null)return!1;o=new z(n.doc.resolve(a))}const l=_a(o.$headCell,t,e);return l?kn(n,r,new z(o.$anchorCell,l)):!1}}function Yg(t,e){const n=t.state.doc,r=ut(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new z(r))),!0):!1}function Qg(t,e,n){if(!ye(t.state))return!1;let r=Kg(n);const s=t.state.selection;if(s instanceof z){r||(r={width:1,height:1,rows:[b.from(jr(ee(t.state.schema).cell,n))]});const i=s.$anchorCell.node(-1),o=s.$anchorCell.start(-1),l=F.get(i).rectBetween(s.$anchorCell.pos-o,s.$headCell.pos-o);return r=Jg(r,l.right-l.left,l.bottom-l.top),so(t.state,t.dispatch,o,l,r),!0}else if(r){const i=Jn(t.state),o=i.start(-1);return so(t.state,t.dispatch,o,F.get(i.node(-1)).findCell(i.pos-o),r),!0}else return!1}function Zg(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;const r=io(t,e.target);let s;if(e.shiftKey&&t.state.selection instanceof z)i(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(s=ut(t.state.selection.$anchor))!=null&&((n=gr(t,e))===null||n===void 0?void 0:n.pos)!=s.pos)i(s,e),e.preventDefault();else if(!r)return;function i(a,c){let d=gr(t,c);const u=$e.getState(t.state)==null;if(!d||!Ns(a,d))if(u)d=a;else return;const h=new z(a,d);if(u||!t.state.selection.eq(h)){const f=t.state.tr.setSelection(h);u&&f.setMeta($e,a.pos),t.dispatch(f)}}function o(){t.root.removeEventListener("mouseup",o),t.root.removeEventListener("dragstart",o),t.root.removeEventListener("mousemove",l),$e.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta($e,-1))}function l(a){const c=a,d=$e.getState(t.state);let u;if(d!=null)u=t.state.doc.resolve(d);else if(io(t,c.target)!=r&&(u=gr(t,e),!u))return o();u&&i(u,c)}t.root.addEventListener("mouseup",o),t.root.addEventListener("dragstart",o),t.root.addEventListener("mousemove",l)}function Xa(t,e,n){if(!(t.state.selection instanceof E))return null;const{$head:r}=t.state.selection;for(let s=r.depth-1;s>=0;s--){const i=r.node(s);if((n<0?r.index(s):r.indexAfter(s))!=(n<0?0:i.childCount))return null;if(i.type.spec.tableRole=="cell"||i.type.spec.tableRole=="header_cell"){const o=r.before(s),l=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(l)?o:null}}return null}function io(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function gr(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:s}=n;return r>=0&&ut(t.state.doc.resolve(r))||ut(t.state.doc.resolve(s))}var ey=class{constructor(e,n){this.node=e,this.defaultCellMinWidth=n,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${n}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),qr(e,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,qr(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function qr(t,e,n,r,s,i){let o=0,l=!0,a=e.firstChild;const c=t.firstChild;if(c){for(let u=0,h=0;unew r(u,n,h)),new ny(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=oe.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{ry(o,l,t,s)},mouseleave:o=>{sy(o)},mousedown:(o,l)=>{iy(o,l,e,n)}},decorations:o=>{const l=oe.getState(o);if(l&&l.activeHandle>-1)return dy(o,l.activeHandle)},nodeViews:{}}});return i}var ny=class wn{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){const n=this,r=e.getMeta(oe);if(r&&r.setHandle!=null)return new wn(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new wn(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let s=e.mapping.map(n.activeHandle,-1);return Wr(e.doc.resolve(s))||(s=-1),new wn(s,n.dragging)}return n}};function ry(t,e,n,r){if(!t.editable)return;const s=oe.getState(t.state);if(s&&!s.dragging){const i=ly(e.target);let o=-1;if(i){const{left:l,right:a}=i.getBoundingClientRect();e.clientX-l<=n?o=oo(t,e,"left",n):a-e.clientX<=n&&(o=oo(t,e,"right",n))}if(o!=s.activeHandle){if(!r&&o!==-1){const l=t.state.doc.resolve(o),a=l.node(-1),c=F.get(a),d=l.start(-1);if(c.colCount(l.pos-d)+l.nodeAfter.attrs.colspan-1==c.width-1)return}Ga(t,o)}}}function sy(t){if(!t.editable)return;const e=oe.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Ga(t,-1)}function iy(t,e,n,r){var s;if(!t.editable)return!1;const i=(s=t.dom.ownerDocument.defaultView)!==null&&s!==void 0?s:window,o=oe.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=t.state.doc.nodeAt(o.activeHandle),a=oy(t,o.activeHandle,l.attrs);t.dispatch(t.state.tr.setMeta(oe,{setDragging:{startX:e.clientX,startWidth:a}}));function c(u){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",d);const h=oe.getState(t.state);h!=null&&h.dragging&&(ay(t,h.activeHandle,lo(h.dragging,u,n)),t.dispatch(t.state.tr.setMeta(oe,{setDragging:null})))}function d(u){if(!u.which)return c(u);const h=oe.getState(t.state);if(h&&h.dragging){const f=lo(h.dragging,u,n);ao(t,h.activeHandle,f,r)}}return ao(t,o.activeHandle,a,r),i.addEventListener("mouseup",c),i.addEventListener("mousemove",d),e.preventDefault(),!0}function oy(t,e,{colspan:n,colwidth:r}){const s=r&&r[r.length-1];if(s)return s;const i=t.domAtPos(e);let o=i.node.childNodes[i.offset].offsetWidth,l=n;if(r)for(let a=0;a{var e,n;const r=t.getAttribute("colwidth"),s=r?r.split(",").map(i=>parseInt(i,10)):null;if(!s){const i=(e=t.closest("table"))==null?void 0:e.querySelectorAll("colgroup > col"),o=Array.from(((n=t.parentElement)==null?void 0:n.children)||[]).indexOf(t);if(o&&o>-1&&i&&i[o]){const l=i[o].getAttribute("width");return l?[parseInt(l,10)]:null}}return s}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:t}){return["td",I(this.options.HTMLAttributes,t),0]}}),fy=X.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:t=>{const e=t.getAttribute("colwidth");return e?e.split(",").map(r=>parseInt(r,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:t}){return["th",I(this.options.HTMLAttributes,t),0]}}),py=X.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:t}){return["tr",I(this.options.HTMLAttributes,t),0]}});function Kr(t,e){return e?["width",`${Math.max(e,t)}px`]:["min-width",`${t}px`]}function co(t,e,n,r,s,i){var o;let l=0,a=!0,c=e.firstChild;const d=t.firstChild;if(d!==null)for(let h=0,f=0;h{const r=t.nodes[n];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),t.cached.tableNodeTypes=e,e}function by(t,e,n,r,s){const i=yy(t),o=[],l=[];for(let c=0;c{const{selection:e}=t.state;if(!ky(e))return!1;let n=0;const r=Gl(e.ranges[0].$from,i=>i.type.name==="table");return r==null||r.node.descendants(i=>{if(i.type.name==="table")return!1;["tableCell","tableHeader"].includes(i.type.name)&&(n+=1)}),n===e.ranges.length?(t.commands.deleteTable(),!0):!1},wy="";function xy(t){return(t||"").replace(/\s+/g," ").trim()}function Sy(t,e,n={}){var r;const s=(r=n.cellLineSeparator)!=null?r:wy;if(!t||!t.content||t.content.length===0)return"";const i=[];t.content.forEach(p=>{const m=[];p.content&&p.content.forEach(g=>{let y="";g.content&&Array.isArray(g.content)&&g.content.length>1?y=g.content.map(C=>e.renderChildren(C)).join(s):y=g.content?e.renderChildren(g.content):"";const k=xy(y),w=g.type==="tableHeader";m.push({text:k,isHeader:w})}),i.push(m)});const o=i.reduce((p,m)=>Math.max(p,m.length),0);if(o===0)return"";const l=new Array(o).fill(0);i.forEach(p=>{var m;for(let g=0;gl[g]&&(l[g]=k),l[g]<3&&(l[g]=3)}});const a=(p,m)=>p+" ".repeat(Math.max(0,m-p.length)),c=i[0],d=c.some(p=>p.isHeader);let u=` `;const h=new Array(o).fill(0).map((p,m)=>d&&c[m]&&c[m].text||"");return u+=`| ${h.map((p,m)=>a(p,l[m])).join(" | ")} | `,u+=`| ${l.map(p=>"-".repeat(Math.max(3,p))).join(" | ")} | `,(d?i.slice(1):i).forEach(p=>{u+=`| ${new Array(o).fill(0).map((m,g)=>a(p[g]&&p[g].text||"",l[g])).join(" | ")} | `}),u}var Cy=Sy,My=X.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,renderWrapper:!1,handleWidth:5,cellMinWidth:25,View:my,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:t,HTMLAttributes:e}){const{colgroup:n,tableWidth:r,tableMinWidth:s}=gy(t,this.options.cellMinWidth),i=e.style;function o(){return i||(r?`width: ${r}`:`min-width: ${s}`)}const l=["table",I(this.options.HTMLAttributes,e,{style:o()}),n,["tbody",0]];return this.options.renderWrapper?["div",{class:"tableWrapper"},l]:l},parseMarkdown:(t,e)=>{const n=[];if(t.header){const r=[];t.header.forEach(s=>{r.push(e.createNode("tableHeader",{},[{type:"paragraph",content:e.parseInline(s.tokens)}]))}),n.push(e.createNode("tableRow",{},r))}return t.rows&&t.rows.forEach(r=>{const s=[];r.forEach(i=>{s.push(e.createNode("tableCell",{},[{type:"paragraph",content:e.parseInline(i.tokens)}]))}),n.push(e.createNode("tableRow",{},s))}),e.createNode("table",void 0,n)},renderMarkdown:(t,e)=>Cy(t,e),addCommands(){return{insertTable:({rows:t=3,cols:e=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:s,editor:i})=>{const o=by(i.schema,t,e,n);if(s){const l=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(E.near(r.doc.resolve(l)))}return!0},addColumnBefore:()=>({state:t,dispatch:e})=>Og(t,e),addColumnAfter:()=>({state:t,dispatch:e})=>Rg(t,e),deleteColumn:()=>({state:t,dispatch:e})=>Ig(t,e),addRowBefore:()=>({state:t,dispatch:e})=>Lg(t,e),addRowAfter:()=>({state:t,dispatch:e})=>zg(t,e),deleteRow:()=>({state:t,dispatch:e})=>$g(t,e),deleteTable:()=>({state:t,dispatch:e})=>qg(t,e),mergeCells:()=>({state:t,dispatch:e})=>Qi(t,e),splitCell:()=>({state:t,dispatch:e})=>Zi(t,e),toggleHeaderColumn:()=>({state:t,dispatch:e})=>Jt("column")(t,e),toggleHeaderRow:()=>({state:t,dispatch:e})=>Jt("row")(t,e),toggleHeaderCell:()=>({state:t,dispatch:e})=>Wg(t,e),mergeOrSplit:()=>({state:t,dispatch:e})=>Qi(t,e)?!0:Zi(t,e),setCellAttribute:(t,e)=>({state:n,dispatch:r})=>Vg(t,e)(n,r),goToNextCell:()=>({state:t,dispatch:e})=>to(1)(t,e),goToPreviousCell:()=>({state:t,dispatch:e})=>to(-1)(t,e),fixTables:()=>({state:t,dispatch:e})=>(e&&Ka(t),!0),setCellSelection:t=>({tr:e,dispatch:n})=>{if(n){const r=z.create(e.doc,t.anchorCell,t.headCell);e.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:fn,"Mod-Backspace":fn,Delete:fn,"Mod-Delete":fn}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[ty({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],uy({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(t){const e={name:t.name,options:t.options,storage:t.storage};return{tableRole:D(M(t,"tableRole",e))}}}),Gy=$.create({name:"tableKit",addExtensions(){const t=[];return this.options.table!==!1&&t.push(My.configure(this.options.table)),this.options.tableCell!==!1&&t.push(hy.configure(this.options.tableCell)),this.options.tableHeader!==!1&&t.push(fy.configure(this.options.tableHeader)),this.options.tableRow!==!1&&t.push(py.configure(this.options.tableRow)),t}});function vy(t,e){const r=e.split(` `).flatMap(s=>[s,""]).map(s=>`${t}${s}`).join(` `);return r.slice(0,r.length-1)}function Ty(t,e){const n=[];return Array.from(t.keys()).forEach(r=>{(!e||!e.marks||!e.marks.map(s=>s.type).includes(r))&&n.push(r)}),n}function Ey(t,e){const n=[];return Array.from(e.entries()).forEach(([r,s])=>{t.has(r)||n.push({type:r,mark:s})}),n}function Ay(t,e,n,r){const s=!n,i=n&&n.type==="text"&&(!n.marks||n.marks.length===0),o=n&&n.type==="text"&&n.marks&&!r(e,new Map(n.marks.map(a=>[a.type,a]))),l=[];if(s||i||o)if(n&&n.type==="text"&&n.marks){const a=new Map(n.marks.map(c=>[c.type,c]));Array.from(t.keys()).forEach(c=>{a.has(c)||l.push(c)})}else(s||i)&&l.push(...Array.from(t.keys()));return l}function Ny(t,e){let n="";return Array.from(t.keys()).reverse().forEach(r=>{const s=t.get(r),i=e(r,s);i&&(n=i+n)}),t.clear(),n}function Oy(t,e,n){let r="";return Array.from(t.entries()).forEach(([s,i])=>{const o=n(s,i);o&&(r+=o),e.set(s,i)}),r}function yr(t){const n=(t.raw||t.text||"").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);return n?{isTask:!0,checked:n[2].toLowerCase()==="x",indentLevel:n[1].length}:{isTask:!1,indentLevel:0}}function pn(t,e){return typeof t!="string"?"json":e}var Ry=class{constructor(t){this.baseExtensions=[],this.extensions=[],this.lastParseResult=null;var e,n,r,s,i;this.markedInstance=(e=t==null?void 0:t.marked)!=null?e:ic,this.lexer=new this.markedInstance.Lexer,this.indentStyle=(r=(n=t==null?void 0:t.indentation)==null?void 0:n.style)!=null?r:"space",this.indentSize=(i=(s=t==null?void 0:t.indentation)==null?void 0:s.size)!=null?i:2,this.baseExtensions=(t==null?void 0:t.extensions)||[],t!=null&&t.markedOptions&&typeof this.markedInstance.setOptions=="function"&&this.markedInstance.setOptions(t.markedOptions),this.registry=new Map,this.nodeTypeRegistry=new Map,t!=null&&t.extensions&&(this.baseExtensions=t.extensions,qn(t.extensions).forEach(l=>this.registerExtension(l,!1))),this.lexer=new this.markedInstance.Lexer}get instance(){return this.markedInstance}get indentCharacter(){return this.indentStyle==="space"?" ":" "}get indentString(){return this.indentCharacter.repeat(this.indentSize)}hasMarked(){return!!this.markedInstance}registerExtension(t,e=!0){var n,r;this.extensions.push(t);const s=t.name,i=M(t,"markdownTokenName")||s,o=M(t,"parseMarkdown"),l=M(t,"renderMarkdown"),a=M(t,"markdownTokenizer"),c=(n=M(t,"markdownOptions"))!=null?n:null,d=(r=c==null?void 0:c.indentsContent)!=null?r:!1,u={tokenName:i,nodeName:s,parseMarkdown:o,renderMarkdown:l,isIndenting:d,tokenizer:a};if(i&&o){const h=this.registry.get(i)||[];h.push(u),this.registry.set(i,h)}if(l){const h=this.nodeTypeRegistry.get(s)||[];h.push(u),this.nodeTypeRegistry.set(s,h)}a&&this.hasMarked()&&(this.registerTokenizer(a),e&&(this.lexer=new this.markedInstance.Lexer))}registerTokenizer(t){if(!this.hasMarked())return;const{name:e,start:n,level:r="inline",tokenize:s}=t,l={inlineTokens:d=>this.lexer.inlineTokens(d),blockTokens:d=>this.lexer.blockTokens(d)};let a;n?a=typeof n=="function"?n:d=>d.indexOf(n):a=d=>{const u=s(d,[],l);return u&&u.raw?d.indexOf(u.raw):-1};const c={name:e,level:r,start:a,tokenizer:(d,u)=>{const h=s(d,u,l);if(h&&h.type)return{...h,type:h.type||e,raw:h.raw||"",tokens:h.tokens||[]}},childTokens:[]};this.markedInstance.use({extensions:[c]})}getHandlersForToken(t){try{return this.registry.get(t)||[]}catch{return[]}}getHandlerForToken(t){const e=this.getHandlersForToken(t);if(e.length>0)return e[0];const n=this.getHandlersForNodeType(t);return n.length>0?n[0]:void 0}getHandlersForNodeType(t){try{return this.nodeTypeRegistry.get(t)||[]}catch{return[]}}serialize(t){return t?Array.isArray(t)?this.renderNodes(t,t):this.renderNodes(t,t):""}parse(t){if(!this.hasMarked())throw new Error("No marked instance available for parsing");const e=this.markedInstance.lexer(t);return{type:"doc",content:this.parseTokens(e)}}parseTokens(t){return t.map(e=>this.parseToken(e)).filter(e=>e!==null).flatMap(e=>Array.isArray(e)?e:[e])}parseToken(t){if(!t.type)return null;if(t.type==="list")return this.parseListToken(t);const e=this.getHandlersForToken(t.type),n=this.createParseHelpers();if(e.find(s=>{if(!s.parseMarkdown)return!1;const i=s.parseMarkdown(t,n),o=this.normalizeParseResult(i);return o&&(!Array.isArray(o)||o.length>0)?(this.lastParseResult=o,!0):!1})&&this.lastParseResult){const s=this.lastParseResult;return this.lastParseResult=null,s}return this.parseFallbackToken(t)}parseListToken(t){if(!t.items||t.items.length===0)return this.parseTokenWithHandlers(t);const e=t.items.some(l=>yr(l).isTask),n=t.items.some(l=>!yr(l).isTask);if(!e||!n||this.getHandlersForToken("taskList").length===0)return this.parseTokenWithHandlers(t);const r=[];let s=[],i=null;for(let l=0;l1&&m.slice(1).join(` `).trim()){const S=m.slice(1),C=S.filter(A=>A.trim());if(C.length>0){const A=Math.min(...C.map(R=>R.length-R.trimStart().length)),O=S.map(R=>R.trim()?R.slice(A):"").join(` `).trim();O&&(k=this.markedInstance.lexer(`${O} `))}}h={type:"taskItem",raw:"",mainContent:y,indentLevel:u,checked:d??!1,text:y,tokens:this.lexer.inlineTokens(y),nestedTokens:k}}const f=c?"taskList":"list";i!==f?(s.length>0&&r.push({type:i,items:s}),s=[h],i=f):s.push(h)}s.length>0&&r.push({type:i,items:s});const o=[];for(let l=0;l0?o:null}parseTokenWithHandlers(t){if(!t.type)return null;const e=this.getHandlersForToken(t.type),n=this.createParseHelpers();if(e.find(s=>{if(!s.parseMarkdown)return!1;const i=s.parseMarkdown(t,n),o=this.normalizeParseResult(i);return o&&(!Array.isArray(o)||o.length>0)?(this.lastParseResult=o,!0):!1})&&this.lastParseResult){const s=this.lastParseResult;return this.lastParseResult=null,s}return this.parseFallbackToken(t)}createParseHelpers(){return{parseInline:t=>this.parseInlineTokens(t),parseChildren:t=>this.parseTokens(t),createTextNode:(t,e)=>({type:"text",text:t,marks:e||void 0}),createNode:(t,e,n)=>{const r={type:t,attrs:e||void 0,content:n||void 0};return(!e||Object.keys(e).length===0)&&delete r.attrs,r},applyMark:(t,e,n)=>({mark:t,content:e,attrs:n&&Object.keys(n).length>0?n:void 0})}}escapeRegex(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}parseInlineTokens(t){var e,n,r,s;const i=[];for(let o=0;o|\/|$)/i);if(!c&&d&&!/\/>$/.test(a)){const h=d[1],f=this.escapeRegex(h),p=new RegExp(`^<\\/\\s*${f}\\b`,"i");let m=-1;const g=[a];for(let y=o+1;y{if(r.type==="text"){const s=r.marks||[],i=n?{type:t,attrs:n}:{type:t};return{...r,marks:[...s,i]}}return{...r,content:r.content?this.applyMarkToContent(t,r.content,n):void 0}})}isMarkResult(t){return t&&typeof t=="object"&&"mark"in t}normalizeParseResult(t){return t?this.isMarkResult(t)?t.content:t:null}parseFallbackToken(t){switch(t.type){case"paragraph":return{type:"paragraph",content:t.tokens?this.parseInlineTokens(t.tokens):[]};case"heading":return{type:"heading",attrs:{level:t.depth||1},content:t.tokens?this.parseInlineTokens(t.tokens):[]};case"text":return{type:"text",text:t.text||""};case"html":return this.parseHTMLToken(t);case"space":return null;default:return t.tokens?this.parseTokens(t.tokens):null}}parseHTMLToken(t){const e=t.text||t.raw||"";if(!e.trim())return null;if(typeof window>"u")return t.block?{type:"paragraph",content:[{type:"text",text:e}]}:{type:"text",text:e};try{const n=sf(e,this.baseExtensions);return n.type==="doc"&&n.content?t.block?n.content:n.content.length===1&&n.content[0].type==="paragraph"&&n.content[0].content?n.content[0].content:n.content:n}catch(n){throw new Error(`Failed to parse HTML in markdown: ${n}`)}}renderNodeToMarkdown(t,e,n=0,r=0){var s;if(t.type==="text")return t.text||"";if(!t.type)return"";const i=this.getHandlerForToken(t.type);if(!i)return"";const o={renderChildren:(c,d)=>{const u=i.isIndenting?r+1:r;return!Array.isArray(c)&&c.content?this.renderNodes(c.content,t,d||"",n,u):this.renderNodes(c,t,d||"",n,u)},indent:c=>this.indentString+c,wrapInBlock:vy},l={index:n,level:r,parentType:e==null?void 0:e.type,meta:{parentAttrs:e==null?void 0:e.attrs}};return((s=i.renderMarkdown)==null?void 0:s.call(i,t,o,l))||""}renderNodes(t,e,n="",r=0,s=0){return Array.isArray(t)?this.renderNodesWithMarkBoundaries(t,e,n,s):t.type?this.renderNodeToMarkdown(t,e,r,s):""}renderNodesWithMarkBoundaries(t,e,n="",r=0){const s=[],i=new Map;return t.forEach((o,l)=>{const a=l[y.type,y])),u=Ey(i,d),h=Ty(d,a);let f="";if(h.length>0){const y=c.match(/(\s+)$/);y&&(f=y[1],c=c.slice(0,-f.length))}h.forEach(y=>{const k=d.get(y),w=this.getMarkClosing(y,k);w&&(c+=w),i.has(y)&&i.delete(y)});let p="";if(u.length>0){const y=c.match(/^(\s+)/);y&&(p=y[1],c=c.slice(p.length))}u.forEach(({type:y,mark:k})=>{const w=this.getMarkOpening(y,k);w&&(c=w+c),h.includes(y)||i.set(y,k)}),c=p+c;const m=Ay(i,d,a,this.markSetsEqual.bind(this));let g="";if(m.length>0){const y=c.match(/(\s+)$/);y&&(g=y[1],c=c.slice(0,-g.length))}m.forEach(y=>{const k=i.get(y),w=this.getMarkClosing(y,k);w&&(c+=w),i.delete(y)}),c+=g,c+=f,s.push(c)}else{const c=new Map(i),d=Ny(i,this.getMarkClosing.bind(this)),u=this.renderNodeToMarkdown(o,e,l,r),h=o.type==="hardBreak"?"":Oy(c,i,this.getMarkOpening.bind(this));s.push(d+u+h)}}),s.join(n)}getMarkOpening(t,e){const n=this.getHandlersForNodeType(t),r=n.length>0?n[0]:void 0;if(!r||!r.renderMarkdown)return"";const s="__TIPTAP_MARKDOWN_PLACEHOLDER__",i={type:t,attrs:e.attrs||{},content:[{type:"text",text:s}]};try{const o=r.renderMarkdown(i,{renderChildren:()=>s,indent:a=>a,wrapInBlock:(a,c)=>a+c},{index:0,level:0,parentType:"text",meta:{}}),l=o.indexOf(s);return l>=0?o.substring(0,l):""}catch(o){throw new Error(`Failed to get mark opening for ${t}: ${o}`)}}getMarkClosing(t,e){const n=this.getHandlersForNodeType(t),r=n.length>0?n[0]:void 0;if(!r||!r.renderMarkdown)return"";const s="__TIPTAP_MARKDOWN_PLACEHOLDER__",i={type:t,attrs:e.attrs||{},content:[{type:"text",text:s}]};try{const o=r.renderMarkdown(i,{renderChildren:()=>s,indent:c=>c,wrapInBlock:(c,d)=>c+d},{index:0,level:0,parentType:"text",meta:{}}),l=o.indexOf(s),a=l+s.length;return l>=0?o.substring(a):""}catch(o){throw new Error(`Failed to get mark closing for ${t}: ${o}`)}}markSetsEqual(t,e){return t.size!==e.size?!1:Array.from(t.keys()).every(n=>e.has(n))}},ho=Ry,Yy=$.create({name:"markdown",addOptions(){return{indentation:{style:"space",size:2},marked:void 0,markedOptions:{}}},addCommands(){return{setContent:(t,e)=>{if(!(e!=null&&e.contentType)||pn(t,e==null?void 0:e.contentType)!=="markdown"||!this.editor.markdown)return fe.setContent(t,e);const r=this.editor.markdown.parse(t);return fe.setContent(r,e)},insertContent:(t,e)=>{if(!(e!=null&&e.contentType)||pn(t,e==null?void 0:e.contentType)!=="markdown"||!this.editor.markdown)return fe.insertContent(t,e);const r=this.editor.markdown.parse(t);return fe.insertContent(r,e)},insertContentAt:(t,e,n)=>{if(!(n!=null&&n.contentType)||pn(e,n==null?void 0:n.contentType)!=="markdown"||!this.editor.markdown)return fe.insertContentAt(t,e,n);const s=this.editor.markdown.parse(e);return fe.insertContentAt(t,s,n)}}},addStorage(){return{manager:new ho({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:[]})}},onBeforeCreate(){if(this.editor.markdown){console.error("[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior.");return}if(this.storage.manager=new ho({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:this.editor.extensionManager.baseExtensions}),this.editor.markdown=this.storage.manager,this.editor.getMarkdown=()=>this.storage.manager.serialize(this.editor.getJSON()),!this.editor.options.contentType||pn(this.editor.options.content,this.editor.options.contentType)!=="markdown")return;if(!this.editor.markdown)throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.');if(this.editor.options.content===void 0||typeof this.editor.options.content!="string")throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.');const e=this.editor.markdown.parse(this.editor.options.content);this.editor.options.content=e}}),Dy=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,Iy=X.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:t}){return["img",I(this.options.HTMLAttributes,t)]},parseMarkdown:(t,e)=>e.createNode("image",{src:t.href,title:t.title,alt:t.text}),renderMarkdown:t=>{var e,n,r,s,i,o;const l=(n=(e=t.attrs)==null?void 0:e.src)!=null?n:"",a=(s=(r=t.attrs)==null?void 0:r.alt)!=null?s:"",c=(o=(i=t.attrs)==null?void 0:i.title)!=null?o:"";return c?`![${a}](${l} "${c}")`:`![${a}](${l})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>"u")return null;const{directions:t,minWidth:e,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize;return({node:s,getPos:i,HTMLAttributes:o,editor:l})=>{const a=document.createElement("img");Object.entries(o).forEach(([u,h])=>{if(h!=null)switch(u){case"width":case"height":break;default:a.setAttribute(u,h);break}}),a.src=o.src;const c=new ep({element:a,editor:l,node:s,getPos:i,onResize:(u,h)=>{a.style.width=`${u}px`,a.style.height=`${h}px`},onCommit:(u,h)=>{const f=i();f!==void 0&&this.editor.chain().setNodeSelection(f).updateAttributes(this.name,{width:u,height:h}).run()},onUpdate:(u,h,f)=>u.type===s.type,options:{directions:t,min:{width:e,height:n},preserveAspectRatio:r===!0}}),d=c.dom;return d.style.visibility="hidden",d.style.pointerEvents="none",a.onload=()=>{d.style.visibility="",d.style.pointerEvents=""},c}},addCommands(){return{setImage:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[xa({find:Dy,type:this.type,getAttributes:t=>{const[,,e,n,r]=t;return{src:n,alt:e,title:r}}})]}}),Qy=Iy;export{le as A,Ms as E,Ky as H,Yy as M,T as N,Fy as R,N as S,E as T,Hy as a,X as b,Vy as c,bp as d,By as e,Wy as f,Gy as g,jy as h,Qy as i,mm as j,pm as k,qy as l,I as m,Jy as n,Uy as o,_y as p,mp as q,$y as u};