import{R as ge,ba as Bl,r as G,bR as zl,c$ as Fl,j as Hl}from"./main-239552ae.js";import{r as Mi,f as Wr,a as Vl}from"./linkify.es-ff711e62.js";import{H as $l,j as _l,t as jl,x as Wl,c as Kl,p as Jl,s as ql,b as Ul,r as Gl,a as Yl,d as Xl,e as Zl}from"./c-ea92d14f.js";function ee(n){this.content=n}ee.prototype={constructor:ee,find:function(n){for(var e=0;e>1}};ee.from=function(n){if(n instanceof ee)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ee(e)};function $s(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=$s(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function _s(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,u=Math.min(o.text.length,l.text.length);for(;ce&&r(a,i+l,s||null,o)!==!1&&a.content.size){let u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),r,i+u)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{l.isText?(s+=l.text.slice(Math.max(e,a)-a,t-a),o=!r):l.isLeaf?(i?s+=typeof i=="function"?i(l):i:l.type.spec.leafText&&(s+=l.type.spec.leafText(l)),o=!r):!o&&l.isBlock&&(s+=r,o=!0)},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new b(r,i)}cutByIndex(e,t){return e==t?b.empty:e==0&&t==this.content.length?this:new b(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new b(i,s)}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 t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?hn(r+1,o):hn(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return b.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new b(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return b.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};F.none=[];class Sn extends Error{}class M{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Ws(this.content,e+this.openStart,t);return r&&new M(r,this.openStart,this.openEnd)}removeBetween(e,t){return new M(js(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return M.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new M(b.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new M(e,r,i)}}M.empty=new M(b.empty,0,0);function js(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(js(s.content,e-i-1,t-i-1)))}function Ws(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ws(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function Ql(n,e,t){if(t.openStart>n.depth)throw new Sn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Sn("Inconsistent open depths");return Ks(n,e,t,0)}function Ks(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Wt(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(dt(n.nodeAfter,r),s++));for(let l=s;li&&Tr(n,e,i+1),o=r.depth>i&&Tr(t,r,i+1),l=[];return Wt(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(Js(s,o),dt(ft(s,qs(n,e,t,r,i+1)),l)):(s&&dt(ft(s,wn(n,e,i+1)),l),Wt(e,t,i,l),o&&dt(ft(o,wn(t,r,i+1)),l)),Wt(r,null,i,l),new b(l)}function wn(n,e,t){let r=[];if(Wt(null,n,t,r),n.depth>t){let i=Tr(n,e,t+1);dt(ft(i,wn(n,e,t+1)),r)}return Wt(e,null,t,r),new b(r)}function ea(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(b.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class Ut{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Cn(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new Ut(t,r,s)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Us(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=b.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=b.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};ht.prototype.text=void 0;class Tn extends ht{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Us(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Tn(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Tn(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Us(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class yt{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new ra(e,t);if(r.next==null)return yt.empty;let i=Gs(r);r.next&&r.err("Unexpected trailing text");let s=ua(ca(i));return da(s,r),s}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` `)}}yt.empty=new yt(!0);class ra{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function Gs(n){let e=[];do e.push(ia(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ia(n){let e=[];do e.push(sa(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function sa(n){let e=aa(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=oa(n,e);else break;return e}function Si(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function oa(n,e){let t=Si(n),r=t;return n.eat(",")&&(n.next!="}"?r=Si(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function la(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function aa(n){if(n.eat("(")){let e=Gs(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=la(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function ca(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[r.join(",")]=new yt(r.indexOf(n.length-1)>-1);for(let o=0;o-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new eo(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};class fa{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class zn{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Qs(i.attrs),this.excluded=null;let s=Xs(this.attrs);this.instance=s?new F(this,s):null}create(e=null){return!e&&this.instance?this.instance:new F(this,Zs(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new zn(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}}class ha{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ee.from(e.nodes),t.marks=ee.from(e.marks||{}),this.nodes=Ci.compile(this.spec.nodes,this),this.marks=zn.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;s.contentMatch=r[o]||(r[o]=yt.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.markSet=l=="_"?null:l?Ti(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Ti(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ci){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Tn(r,r.defaultAttrs,e,F.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return ht.fromJSON(this,e)}markFromJSON(e){return F.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Ti(n,e){let t=[];for(let r=0;r-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}class Rt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new Oi(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Oi(this,t,!0);return r.addAll(e,t.from,t.to),M.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=Ni(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=Ni(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Rt(e,Rt.schemaRules(e)))}}const to={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},pa={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},no={ol:!0,ul:!0},En=1,On=2,Kt=4;function Ei(n,e,t){return e!=null?(e?En:0)|(e==="full"?On:0):n&&n.whitespace=="pre"?En|On:t&~Kt}class pn{constructor(e,t,r,i,s,o,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=F.none,this.stashMarks=[],this.match=o||(l&Kt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(b.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&En)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=b.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(b.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,r=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` `))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=F.none,r=F.none;for(let i=0;i{o.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,r]}addElementByRule(e,t,r){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,r){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=r==null?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,r=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(r);for(let i=0;ithis.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let u=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!u||u.name!=c&&u.groups.indexOf(c)==-1)return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let t=ka(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}}function ma(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&no.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function ga(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ya(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function Ni(n){let e={};for(let t in n)e[t]=n[t];return e}function ba(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Ie.renderSpec(rr(r),i(e,t))}static renderSpec(e,t,r=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(r=i.slice(0,s),i=i.slice(s+1));let o,l=r?e.createElementNS(r,i):e.createElement(i),a=t[1],c=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){c=2;for(let u in a)if(a[u]!=null){let d=u.indexOf(" ");d>0?l.setAttributeNS(u.slice(0,d),u.slice(d+1),a[u]):l.setAttribute(u,a[u])}}for(let u=c;uc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:h}=Ie.renderSpec(e,d,r);if(l.appendChild(f),h){if(o)throw new RangeError("Multiple content holes");o=h}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Ie(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Ai(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Ai(e.marks)}}function Ai(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function rr(n){return n.document||window.document}const ro=65535,io=Math.pow(2,16);function xa(n,e){return n+e*io}function vi(n){return n&ro}function Ma(n){return(n-(n&ro))/io}const so=1,oo=2,bn=4,lo=8;class Or{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&lo)>0}get deletedBefore(){return(this.delInfo&(so|bn))>0}get deletedAfter(){return(this.delInfo&(oo|bn))>0}get deletedAcross(){return(this.delInfo&bn)>0}}class ye{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ye.empty)return ye.empty}recover(e){let t=0,r=vi(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],u=this.ranges[l+o],d=a+c;if(e<=d){let f=c?e==a?-1:e==d?1:t:t,h=a+i+(f<0?0:u);if(r)return h;let p=e==(t<0?a:d)?null:xa(l/3,e-a),m=e==a?oo:e==d?so:bn;return(t<0?e!=a:e!=d)&&(m|=lo),new Or(h,m,p)}i+=u-c}return r?e+i:new Or(e+i,0,null)}touches(e,t){let r=0,i=vi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+s],u=a+c;if(e<=u&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new At;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return K.fromReplace(e,this.from,this.to,s)}invert(){return new Re(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new qe(t.pos,r.pos,this.mark)}merge(e){return e instanceof qe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new qe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new qe(t.from,t.to,e.markFromJSON(t.mark))}}le.jsonID("addMark",qe);class Re extends le{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new M(Kr(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return K.fromReplace(e,this.from,this.to,r)}invert(){return new qe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Re(t.pos,r.pos,this.mark)}merge(e){return e instanceof Re&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Re(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Re(t.from,t.to,e.markFromJSON(t.mark))}}le.jsonID("removeMark",Re);class Ue extends le{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return K.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return K.fromReplace(e,this.pos,this.pos+1,new M(b.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new Y(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Y(t.from,t.to,t.gapFrom,t.gapTo,M.fromJSON(e,t.slice),t.insert,!!t.structure)}}le.jsonID("replaceAround",Y);function Nr(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Sa(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,u)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&u.type.allowsMarkType(r.type)){let f=Math.max(c,e),h=Math.min(c+a.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(a)),s.forEach(a=>n.step(a))}function wa(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof zn){let c=o.marks,u;for(;u=r.isInSet(c);)(a||(a=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let u=0;un.step(new Re(o.from,o.to,o.style)))}function Ca(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)n.step(s[l])}function Ta(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Ht(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,u=b.from(r.node(p).copy(u)),d++):a--;let f=b.empty,h=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=b.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new Y(i,s,i,s,new M(r,0,0),t.length,!0))}function va(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{if(o.isTextblock&&!o.hasMarkup(r,i)&&Da(n.doc,n.mapping.slice(s).map(l),r)){n.clearIncompatible(n.mapping.slice(s).map(l,1),r);let a=n.mapping.slice(s),c=a.map(l,1),u=a.map(l+o.nodeSize,1);return n.step(new Y(c,u,c+1,u-1,new M(b.from(r.create(i,null,o.marks)),0,0),1,!0)),!1}})}function Da(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Ia(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Y(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new M(b.from(o),0,0),1,!0))}function vt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=t-2;c>s;c--,u--){let d=i.node(c),f=i.index(c);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=r&&r[u+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[u]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(h))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Ra(n,e,t=1,r){let i=n.doc.resolve(e),s=b.empty,o=b.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=b.from(i.node(l).copy(s));let u=r&&r[c];o=b.from(u?u.type.create(u.attrs,o):i.node(l).copy(o))}n.step(new te(e,e,new M(s.append(o),t,t),!0))}function nt(n,e){let t=n.resolve(e),r=t.index();return ao(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function ao(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Fn(n,e,t=-1){let r=n.resolve(e);for(let i=r.depth;;i--){let s,o,l=r.index(i);if(i==r.depth?(s=r.nodeBefore,o=r.nodeAfter):t>0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&ao(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function La(n,e,t){let r=new te(e-t,e+t,M.empty,!0);n.step(r)}function Pa(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),u=!1;if(s==1)u=c.canReplace(a,a,i);else{let d=c.contentMatchAt(a).findWrapping(i.firstChild.type);u=d&&c.canReplaceWith(a,a,d[0])}if(u)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function qr(n,e,t=e,r=M.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return uo(i,s,r)?new te(e,t,r):new Ba(i,s,r).fit()}function uo(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class Ba{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=b.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=b.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new M(s,o,l);return e>-1?new Y(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new te(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=sr(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],u,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(b.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(u=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:u};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=sr(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new M(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=sr(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new M($t(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new M($t(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(d=g,u.push(fo(m.mark(f.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?h:-1)))}let p=c==l.childCount;p||(h=-1),this.placed=_t(this.placed,t,b.from(u)),this.frontier[t].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:c}=this.frontier[l],u=or(e,l,c,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=_t(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=_t(this.placed,this.depth,b.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(b.empty,!0);t.childCount&&(this.placed=_t(this.placed,this.frontier.length,t))}}function $t(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy($t(n.firstChild.content,e-1,t)))}function _t(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(_t(n.lastChild.content,e-1,t)))}function sr(n,e){for(let t=0;t1&&(r=r.replaceChild(0,fo(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(b.empty,!0)))),n.copy(r)}function or(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!za(t,s.content,o)?l:null}function za(n,e,t){for(let r=t;r0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==h&&o.splice(1,0,-f)}let a=o.indexOf(l),c=[],u=r.openStart;for(let f=r.content,h=0;;h++){let p=f.firstChild;if(c.push(p),h==r.openStart)break;f=p.content}for(let f=u-1;f>=0;f--){let h=c[f],p=Fa(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))u=f;else if(p||!h.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let h=(f+u+1)%(r.openStart+1),p=c[h];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let h=o[f];h<0||(e=i.before(h),t=s.after(h))}}function ho(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(b.empty,!0))}return n}function Va(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Pa(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new M(b.from(r),0,0))}function $a(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=po(r,i);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o)return n.delete(r.before(o),t);n.delete(e,t)}function po(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class Dt extends le{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return K.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return K.fromReplace(e,this.pos,this.pos+1,new M(b.from(i),0,t.isLeaf?0:1))}getMap(){return ye.empty}invert(e){return new Dt(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Dt(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Dt(t.pos,t.attr,t.value)}}le.jsonID("attr",Dt);class Gt extends le{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return K.ok(r)}getMap(){return ye.empty}invert(e){return new Gt(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Gt(t.attr,t.value)}}le.jsonID("docAttr",Gt);let Pt=class extends Error{};Pt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Pt.prototype=Object.create(Error.prototype);Pt.prototype.constructor=Pt;Pt.prototype.name="TransformError";class mo{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new At}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Pt(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=M.empty){let i=qr(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new M(b.from(r),0,0))}delete(e,t){return this.replace(e,t,M.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Ha(this,e,t,r),this}replaceRangeWith(e,t,r){return Va(this,e,t,r),this}deleteRange(e,t){return $a(this,e,t),this}lift(e,t){return Ea(this,e,t),this}join(e,t=1){return La(this,e,t),this}wrap(e,t){return Aa(this,e,t),this}setBlockType(e,t=e,r,i=null){return va(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Ia(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Dt(e,t,r)),this}setDocAttribute(e,t){return this.step(new Gt(e,t)),this}addNodeMark(e,t){return this.step(new Ue(e,t)),this}removeNodeMark(e,t){if(!(t instanceof F)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Lt(e,t)),this}split(e,t=1,r){return Ra(this,e,t,r),this}addMark(e,t,r){return Sa(this,e,t,r),this}removeMark(e,t,r){return wa(this,e,t,r),this}clearIncompatible(e,t,r){return Ca(this,e,t,r),this}}const lr=Object.create(null);class D{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new _a(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Tt(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Tt(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new xe(e.node(0))}static atStart(e){return Tt(e,e,0,0,1)||new xe(e)}static atEnd(e){return Tt(e,e,e.content.size,e.childCount,-1)||new xe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=lr[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in lr)throw new RangeError("Duplicate use of selection JSON ID "+e);return lr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}}D.prototype.visible=!0;class _a{constructor(e,t){this.$from=e,this.$to=t}}let Ii=!1;function Ri(n){!Ii&&!n.parent.inlineContent&&(Ii=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class A extends D{constructor(e,t=e){Ri(e),Ri(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return D.near(r);let i=e.resolve(t.map(this.anchor));return new A(i.parent.inlineContent?i:r,r)}replace(e,t=M.empty){if(super.replace(e,t),t==M.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof A&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Hn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new A(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=D.findFrom(t,r,!0)||D.findFrom(t,-r,!0);if(s)t=s.$head;else return D.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(D.findFrom(e,-r,!0)||D.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&T.isSelectable(l))return T.create(n,t-(i<0?l.nodeSize:0))}else{let a=Tt(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Li(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=u)}),n.setSelection(D.near(n.doc.resolve(o),t))}const Pi=1,mn=2,Bi=4;class Wa extends mo{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|=mn,this}ensureMarks(e){return F.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&mn)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~mn,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||F.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(D.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Bi,this}get scrolledIntoView(){return(this.updated&Bi)>0}}function zi(n,e){return!e||!n?n:n.bind(e)}class jt{constructor(e,t,r){this.name=e,this.init=zi(t.init,r),this.apply=zi(t.apply,r)}}const Ka=[new jt("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new jt("selection",{init(n,e){return n.selection||D.atStart(e.doc)},apply(n){return n.selection}}),new jt("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new jt("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class ar{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ka.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new jt(r.key,r.spec.state,r))})}}class Ot{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new ar(e.schema,e.plugins),s=new Ot(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ht.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=D.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function go(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=go(i,e,{})),t[r]=i}return t}class ae{constructor(e){this.spec=e,this.props={},e.props&&go(e.props,this,this.props),this.key=e.key?e.key.key:yo("plugin")}getState(e){return e[this.key]}}const cr=Object.create(null);function yo(n){return n in cr?n+"$"+ ++cr[n]:(cr[n]=0,n+"$")}class Se{constructor(e="key"){this.key=yo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const ce=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Yt=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Fi=null;const Fe=function(n,e,t){let r=Fi||(Fi=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},bt=function(n,e,t,r){return t&&(Hi(n,e,t,r,-1)||Hi(n,e,t,r,1))},Ja=/^(img|br|input|textarea|hr)$/i;function Hi(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:De(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Gr(n)||Ja.test(n.nodeName)||n.contentEditable=="false")return!1;e=ce(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?De(n):0}else return!1}}function De(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function qa(n,e,t){for(let r=e==0,i=e==De(n);r||i;){if(n==t)return!0;let s=ce(n);if(n=n.parentNode,!n)return!1;r=r&&s==0,i=i&&s==De(n)}}function Gr(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Vn=function(n){return n.focusNode&&bt(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function lt(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Ua(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Ga(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:r.startOffset}}}const Le=typeof navigator<"u"?navigator:null,Vi=typeof document<"u"?document:null,rt=Le&&Le.userAgent||"",Ar=/Edge\/(\d+)/.exec(rt),bo=/MSIE \d/.exec(rt),vr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(rt),pe=!!(bo||vr||Ar),Xe=bo?document.documentMode:vr?+vr[1]:Ar?+Ar[1]:0,Ne=!pe&&/gecko\/(\d+)/i.test(rt);Ne&&+(/Firefox\/(\d+)/.exec(rt)||[0,0])[1];const Dr=!pe&&/Chrome\/(\d+)/.exec(rt),oe=!!Dr,Ya=Dr?+Dr[1]:0,ue=!pe&&!!Le&&/Apple Computer/.test(Le.vendor),Bt=ue&&(/Mobile\/\w+/.test(rt)||!!Le&&Le.maxTouchPoints>2),ke=Bt||(Le?/Mac/.test(Le.platform):!1),Xa=Le?/Win/.test(Le.platform):!1,Ee=/Android \d/.test(rt),on=!!Vi&&"webkitFontSmoothing"in Vi.documentElement.style,Za=on?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Qa(n){return{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ze(n,e){return typeof n=="number"?n:n[e]}function ec(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function $i(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Yt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?Qa(s):ec(l),u=0,d=0;if(e.topc.bottom-ze(r,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+ze(i,"top")-c.top:e.bottom-c.bottom+ze(i,"bottom")),e.leftc.right-ze(r,"right")&&(u=e.right-c.right+ze(i,"right")),u||d)if(a)s.defaultView.scrollBy(u,d);else{let f=l.scrollLeft,h=l.scrollTop;d&&(l.scrollTop+=d),u&&(l.scrollLeft+=u);let p=l.scrollLeft-f,m=l.scrollTop-h;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function tc(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:ko(n.dom)}}function ko(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Yt(r));return e}function nc({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;xo(t,r==0?0:r-e)}function xo(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=u,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?ic(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Mo(t,i)}function ic(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function Yr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function sc(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function lc(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!o||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:n.docView.posFromDOM(e,t,-1)}function So(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;on&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=lc(n,r,i,e))}l==null&&(l=oc(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function _i(n){return n.top=0&&i==r.nodeValue.length?(a--,u=1):t<0?a--:c++,Vt(je(Fe(r,a,c),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==De(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return ur(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==De(r))){let a=r.childNodes[i-1],c=a.nodeType==3?Fe(a,De(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Vt(je(c,1),!1)}if(s==null&&i=0)}function Vt(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function ur(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Co(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function uc(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Co(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=wo(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Fe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cu.top+1&&(t=="up"?o.top-u.top>(u.bottom-o.top)*2:u.bottom-o.bottom>(o.bottom-u.top)*2))return!1}}return!0})}const dc=/[\u0590-\u08ac]/;function fc(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return!dc.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Co(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let h=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(u,d),a&&(a!=u||c!=d)&&l.extend&&l.extend(a,c)}catch{}return f!=null&&(l.caretBidiLevel=f),g})}let ji=null,Wi=null,Ki=!1;function hc(n,e,t){return ji==e&&Wi==t?Ki:(ji=e,Wi=t,Ki=t=="up"||t=="down"?uc(n,e,t):fc(n,e,t))}const Me=0,Ji=1,at=2,Pe=3;class ln{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Me,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tce(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof Eo){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof To&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?ce(s.dom)+1:0}}else{let s,o=!0;for(;s=r=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=ce(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;uh&&ot){let h=l;l=a,a=h}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,t){for(let r=0,i=0;i=r:er){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?at:Ji,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Pe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?at:Pe}r=o}this.dirty=at}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?at:Ji;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Me&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class pc extends ln{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class kt extends ln{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Ie.renderSpec(document,t.type.spec.toDOM(t,r))),new kt(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Pe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Me){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Lr(s,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),u=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:d}=Ie.renderSpec(document,t.type.spec.toDOM(t)));!d&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let f=u;return u=Ao(u,r,t),c?a=new mc(e,t,r,i,u,d||null,f,c,s,o+1):t.isText?new $n(e,t,r,i,u,f,s):new Ze(e,t,r,i,u,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>b.empty)}return e}matchesNode(e,t,r){return this.dirty==Me&&e.eq(this.node)&&Rr(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new yc(this,o&&o.node,e);xc(this.node,this.innerDeco,(c,u,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!d&&a.syncToMarks(u==this.node.childCount?F.none:this.node.child(u).marks,r,e),a.placeWidget(c,e,i)},(c,u,d,f)=>{a.syncToMarks(c.marks,r,e);let h;a.findNodeMatch(c,u,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,u,d,h,e)||a.updateNextNode(c,u,d,e,f,i)||a.addNode(c,u,d,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==at)&&(o&&this.protectLocalComposition(e,o),Oo(this.contentDOM,this.children,e),Bt&&Mc(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.domSelectionRange(),o=Sc(s.focusNode,s.focusOffset);if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let l=o.nodeValue,a=wc(this.node.content,l,r-t,i-t);return a<0?null:{node:o,pos:a,text:l}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new pc(this,s,t,i);e.input.compositionNodes.push(o),this.children=Lr(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Pe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Me}updateOuterDeco(e){if(Rr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=No(this.dom,this.nodeDOM,Ir(this.outerDeco,this.node,t),Ir(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}function qi(n,e,t,r,i){Ao(r,e,n);let s=new Ze(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class $n extends Ze{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Pe||this.dirty!=Me&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Me||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Me,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new $n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Pe)}get domAtom(){return!1}}class Eo extends ln{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Me&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class mc extends Ze{constructor(e,t,r,i,s,o,l,a,c,u){super(e,t,r,i,s,o,l,c,u),this.spec=a}update(e,t,r,i){if(this.dirty==Pe)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Oo(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=kt.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof kt)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function kc(n,e){return n.type.side-e.type.side}function xc(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let c=0;cs;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),h),s=p}}function Mc(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Sc(n,e){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0){if(n.childNodes.length>e&&n.childNodes[e].nodeType==3)return n.childNodes[e];n=n.childNodes[e-1],e=De(n)}else if(n.nodeType==1&&e=t){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Lr(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||u<=e?s.push(a):(ct&&s.push(a.slice(t-c,a.size,r)))}return s}function Xr(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if(Vn(t)){for(a=l;i&&!i.node;)i=i.parent;let u=i.node;if(i&&u.isAtom&&T.isSelectable(u)&&i.parent&&!(u.isInline&&qa(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new T(o==d?l:r.resolve(d))}}else{let u=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(u<0)return null;a=r.resolve(u)}if(!c){let u=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!vo(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Tc(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,ce(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&pe&&Xe<=11&&(r.disabled=!0,r.disabled=!1)}function Do(n,e){if(e instanceof T){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Zi(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Zi(n)}function Zi(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Zr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Qi(n){return n.editable&&!n.hasFocus()?!1:Io(n)}function Io(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Ec(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return bt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Pr(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&D.findFrom(s,e)}function We(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function es(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return We(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Pr(n.state,e);return i&&i instanceof T?We(n,i):!1}else if(!(ke&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?T.isSelectable(s)?We(n,new T(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):on?We(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof T&&r.node.isInline)return We(n,new A(e>0?r.$to:r.$from));{let i=Pr(n.state,e);return i?We(n,i):!1}}}function Nn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function qt(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function wt(n,e){return e<0?Oc(n):Nc(n)}function Oc(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(Ne&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(qt(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Ro(t))break;{let l=t.previousSibling;for(;l&&qt(l,-1);)i=t.parentNode,s=ce(l),l=l.previousSibling;if(l)t=l,r=Nn(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Br(n,t,r):i&&Br(n,i,s)}function Nc(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Nn(t),s,o;for(;;)if(r{n.state==i&&He(n)},50)}function ts(n,e){let t=n.state.doc.resolve(e);if(!(oe||Xa)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ns(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ke&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Pr(n.state,e);if(o&&o instanceof T)return We(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof xe?D.near(o,e):D.findFrom(o,e);return l?We(n,l):!1}return!1}function rs(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function is(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Dc(n){if(!ue||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;is(n,r,"true"),setTimeout(()=>is(n,r,"false"),20)}return!1}function Ic(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Rc(n,e){let t=e.keyCode,r=Ic(e);if(t==8||ke&&t==72&&r=="c")return rs(n,-1)||wt(n,-1);if(t==46&&!e.shiftKey||ke&&t==68&&r=="c")return rs(n,1)||wt(n,1);if(t==13||t==27)return!0;if(t==37||ke&&t==66&&r=="c"){let i=t==37?ts(n,n.state.selection.from)=="ltr"?-1:1:-1;return es(n,i,r)||wt(n,i)}else if(t==39||ke&&t==70&&r=="c"){let i=t==39?ts(n,n.state.selection.from)=="ltr"?1:-1:1;return es(n,i,r)||wt(n,i)}else{if(t==38||ke&&t==80&&r=="c")return ns(n,-1,r)||wt(n,-1);if(t==40||ke&&t==78&&r=="c")return Dc(n)||ns(n,1,r)||wt(n,1);if(r==(ke?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Lo(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let h=r.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let o=n.someProp("clipboardSerializer")||Ie.fromSchema(n.state.schema),l=Vo(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,u,d=0;for(;c&&c.nodeType==1&&(u=Ho[c.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let p=l.createElement(u[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:f}}function Po(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(r||s||!t);if(a){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new M(b.from(n.state.schema.text(e.replace(/\r\n?/g,` `))),0,0):M.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:h}=n.state,p=Ie.fromSchema(h);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(h.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=Bc(t),on&&zc(o);let c=o&&o.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let d=+u[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Rt.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Lc.test(f.parentNode.nodeName)?{ignore:!0}:null}})),u)l=Fc(ss(l,+u[1],+u[2]),u[4]);else if(l=M.maxOpen(Pc(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let h=l.content.firstChild;d{l=d(l,n)}),l}const Lc=/^(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 Pc(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&zo(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Fo(o[o.length-1],s.length));let u=Bo(l,a);o.push(u),i=i.matchType(u.type),s=a}}),o)return b.from(o)}return n}function Bo(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,b.from(n));return n}function zo(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(b.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ss(n,e,t){return e]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Vo().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Ho[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=n,i)for(let s=0;s=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=b.from(a.create(r[l+1],i)),s++,o++}return new M(i,s,o)}const de={},fe={},Hc={touchstart:!0,touchmove:!0};class Vc{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function $c(n){for(let e in de){let t=de[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{jc(n,r)&&!Qr(n,r)&&(n.editable||!(r.type in fe))&&t(n,r)},Hc[e]?{passive:!0}:void 0)}ue&&n.dom.addEventListener("input",()=>null),Fr(n)}function Ge(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function _c(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Fr(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Qr(n,r))})}function Qr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function jc(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Wc(n,e){!Qr(n,e)&&de[e.type]&&(n.editable||!(e.type in fe))&&de[e.type](n,e)}fe.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!_o(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Ee&&oe&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Bt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,lt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Rc(n,t)?t.preventDefault():Ge(n,"key")};fe.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};fe.keypress=(n,e)=>{let t=e;if(_o(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ke&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function _n(n){return{left:n.clientX,top:n.clientY}}function Kc(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function ei(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function It(n,e,t){n.focused||n.focus();let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Jc(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&T.isSelectable(r)?(It(n,new T(t),"pointer"),!0):!1}function qc(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof T&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(T.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(It(n,T.create(n.state.doc,i),"pointer"),!0):!1}function Uc(n,e,t,r,i){return ei(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?qc(n,t):Jc(n,t))}function Gc(n,e,t,r){return ei(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Yc(n,e,t,r){return ei(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Xc(n,t,r)}function Xc(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(It(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)It(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(T.isSelectable(o))It(n,T.create(r,l),"pointer");else continue;return!0}}function ti(n){return An(n)}const $o=ke?"metaKey":"ctrlKey";de.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ti(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Kc(t,n.input.lastClick)&&!t[$o]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(_n(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Zc(n,o,t,!!r)):(s=="doubleClick"?Gc:Yc)(n,o.pos,o.inside,t)?t.preventDefault():Ge(n,"pointer"))};class Zc{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[$o],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,o=u.depth?u.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof T&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ne&&!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)),Ge(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(()=>He(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(_n(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ge(this.view,"pointer"):Uc(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ue&&this.mightDrag&&!this.mightDrag.node.isAtom||oe&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(It(this.view,D.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Ge(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ge(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)}}de.touchstart=n=>{n.input.lastTouch=Date.now(),ti(n),Ge(n,"pointer")};de.touchmove=n=>{n.input.lastTouch=Date.now(),Ge(n,"pointer")};de.contextmenu=n=>ti(n);function _o(n,e){return n.composing?!0:ue&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const Qc=Ee?5e3:-1;fe.compositionstart=fe.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),An(n,!0),n.markCursor=null;else if(An(n),Ne&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){n.domSelection().collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}jo(n,Qc)};fe.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,jo(n,20))};function jo(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>An(n),e))}function Wo(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=eu());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function eu(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function An(n,e=!1){if(!(Ee&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Wo(n),e||n.docView&&n.docView.dirty){let t=Xr(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):n.updateState(n.state),!0}return!1}}function tu(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const Xt=pe&&Xe<15||Bt&&Za<604;de.copy=fe.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Xt?null:t.clipboardData,o=r.content(),{dom:l,text:a}=Lo(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):tu(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function nu(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ru(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Zt(n,r.value,null,i,e):Zt(n,r.textContent,r.innerHTML,i,e)},50)}function Zt(n,e,t,r,i){let s=Po(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,s||M.empty)))return!0;if(!s)return!1;let o=nu(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Ko(n){let e=n.getData("text/html")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}fe.paste=(n,e)=>{let t=e;if(n.composing&&!Ee)return;let r=Xt?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Zt(n,Ko(r),r.getData("text/html"),i,t)?t.preventDefault():ru(n,t)};class iu{constructor(e,t){this.slice=e,this.move=t}}const Jo=ke?"altKey":"ctrlKey";de.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(_n(t));if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof T?i.to-1:i.to))){if(r&&r.mightDrag)n.dispatch(n.state.tr.setSelection(T.create(n.state.doc,r.mightDrag.pos)));else if(t.target&&t.target.nodeType==1){let c=n.docView.nearestDesc(t.target,!0);c&&c.node.type.spec.draggable&&c!=n.docView&&n.dispatch(n.state.tr.setSelection(T.create(n.state.doc,c.posBefore)))}}let o=n.state.selection.content(),{dom:l,text:a}=Lo(n,o);t.dataTransfer.clearData(),t.dataTransfer.setData(Xt?"Text":"text/html",l.innerHTML),t.dataTransfer.effectAllowed="copyMove",Xt||t.dataTransfer.setData("text/plain",a),n.dragging=new iu(o,!t[Jo])};de.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};fe.dragover=fe.dragenter=(n,e)=>e.preventDefault();fe.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(_n(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Po(n,Ko(t.dataTransfer),Xt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Jo]);if(n.someProp("handleDrop",p=>p(n,t,o||M.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?co(n.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=n.state.tr;l&&c.deleteSelection();let u=c.mapping.map(a),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=c.doc;if(d?c.replaceRangeWith(u,u,o.content.firstChild):c.replaceRange(u,u,o),c.doc.eq(f))return;let h=c.doc.resolve(u);if(d&&T.isSelectable(o.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new T(h));else{let p=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,S)=>p=S),c.setSelection(Zr(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};de.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&He(n)},20))};de.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};de.beforeinput=(n,e)=>{if(oe&&Ee&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,lt(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in fe)de[n]=fe[n];function Qt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class vn{constructor(e,t){this.toDOM=e,this.spec=t||pt,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new be(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof vn&&(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 Qe{constructor(e,t){this.attrs=e,this.spec=t||pt}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new be(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==se||e.maps.length==0?this:this.mapInner(e,t,0,0,r||pt)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let c=a+r,u;if(u=Uo(t,l,c)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof Qe){let c=Math.max(s,a.from)-s,u=Math.min(o,a.to)-s;ci.map(e,t,pt));return Je.from(r)}forChild(e,t){if(t.isLeaf)return W.empty;let r=[];for(let i=0;it instanceof W)?e:e.reduce((t,r)=>t.concat(r instanceof W?r:r.members),[]))}}}function su(n,e,t,r,i,s,o){let l=n.slice();for(let c=0,u=s;c{let g=m-p-(h-f);for(let y=0;yS+u-d)continue;let R=l[y]+u-d;h>=R?l[y+1]=f<=R?-2:-1:p>=i&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let f=t.map(n[c+1]+s,-1),h=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==h){let y=l[c+2].mapInner(t,g,u+1,n[c]+s+1,o);y!=se?(l[c]=d,l[c+1]=h,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=ou(l,n,e,t,i,s,o),u=Dn(c,r,0,o);e=u.local;for(let d=0;dt&&o.to{let c=Uo(n,l,a+t);if(c){s=!0;let u=Dn(c,l,t+a+1,r);u!=se&&i.push(a,a+l.nodeSize,u)}});let o=qo(s?Go(n):n,-t).sort(mt);for(let l=0;l0;)e++;n.splice(e,0,t)}function fr(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=se&&e.push(r)}),n.cursorWrapper&&e.push(W.create(n.state.doc,[n.cursorWrapper.deco])),Je.from(e)}const lu={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},au=pe&&Xe<=11;class cu{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 uu{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new cu,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),au&&(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,lu)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Qi(this.view)){if(this.suppressingSelectionUpdates)return He(this.view);if(pe&&Xe<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&bt(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Yt(s))t.add(s);for(let s=e.anchorNode;s;s=Yt(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Qi(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let u=0;u1){let u=a.filter(d=>d.nodeName=="BR");if(u.length==2){let d=u[0],f=u[1];d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),du(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||He(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;ui;g--){let y=r.childNodes[g-1],S=y.pmViewDesc;if(y.nodeName=="BR"&&!S){s=g;break}if(!S||S.size)break}let d=n.state.doc,f=n.someProp("domParser")||Rt.fromSchema(n.state.schema),h=d.resolve(o),p=null,m=f.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:pu,context:h});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 pu(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(ue&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||ue&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const mu=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function gu(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let O=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Ce=Xr(n,O);if(Ce&&!n.state.selection.eq(Ce)){if(oe&&Ee&&n.input.lastKeyCode===13&&Date.now()-100Yn(n,lt(13,"Enter"))))return;let st=n.state.tr.setSelection(Ce);O=="pointer"?st.setMeta("pointer",!0):O=="key"&&st.scrollIntoView(),s&&st.setMeta("composition",s),n.dispatch(st)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=hu(n,e,t),u=n.state.doc,d=u.slice(c.from,c.to),f,h;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Ee)&&i.some(O=>O.nodeType==1&&!mu.test(O.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",O=>O(n,lt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof A&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let O=ds(n,n.state.doc,c.sel);if(O&&!O.eq(n.state.selection)){let Ce=n.state.tr.setSelection(O);s&&Ce.setMeta("composition",s),n.dispatch(Ce)}}return}if(oe&&n.cursorWrapper&&c.sel&&c.sel.anchor==n.cursorWrapper.deco.from&&c.sel.head==c.sel.anchor){let O=p.endB-p.start;c.sel={anchor:c.sel.anchor+O,head:c.sel.anchor+O}}n.input.domChangeCount++,n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),pe&&Xe<=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=u.resolve(p.start),S=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,R;if((Bt&&n.input.lastIOSEnter>Date.now()-225&&(!S||i.some(O=>O.nodeName=="DIV"||O.nodeName=="P"))||!S&&m.posO(n,lt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&bu(u,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",O=>O(n,lt(8,"Backspace")))){Ee&&oe&&n.domObserver.suppressSelectionUpdates();return}oe&&Ee&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Ee&&!S&&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(()=>{n.someProp("handleKeyDown",function(O){return O(n,lt(13,"Enter"))})},20));let P=p.start,V=p.endA,B,re,Ae;if(S){if(m.pos==g.pos)pe&&Xe<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>He(n),20)),B=n.state.tr.delete(P,V),re=u.resolve(p.start).marksAcross(u.resolve(p.endA));else if(p.endA==p.endB&&(Ae=yu(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))B=n.state.tr,Ae.type=="add"?B.addMark(P,V,Ae.mark):B.removeMark(P,V,Ae.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let O=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Ce=>Ce(n,P,V,O)))return;B=n.state.tr.insertText(O,P,V)}}if(B||(B=n.state.tr.replace(P,V,c.doc.slice(p.start-c.from,p.endB-c.from))),c.sel){let O=ds(n,B.doc,c.sel);O&&!(oe&&Ee&&n.composing&&O.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:Zr(n,e.resolve(t.anchor),e.resolve(t.head))}function yu(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,a;for(let u=0;uu.mark(l.addToSet(u.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;ut||hr(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function ku(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o=o?s-r:0;s-=a,l=s+(l-o),o=s}else if(l=l?s-r:0;s-=a,o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}class xu{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Vc,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(gs),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=ps(this),hs(this),this.nodeViews=ms(this),this.docView=qi(this.state.doc,fs(this),fr(this),this.dom,this),this.domObserver=new uu(this,(r,i,s,o)=>gu(this,r,i,s,o)),this.domObserver.start(),$c(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Fr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(gs),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let r=this.state,i=!1,s=!1;e.storedMarks&&this.composing&&(Wo(this),s=!0),this.state=e;let o=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(o||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let f=ms(this);Su(f,this.nodeViews)&&(this.nodeViews=f,i=!0)}(o||t.handleDOMEvents!=this._props.handleDOMEvents)&&Fr(this),this.editable=ps(this),hs(this);let l=fr(this),a=fs(this),c=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",u=i||!this.docView.matchesNode(e.doc,a,l);(u||!e.selection.eq(r.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&tc(this);if(s){this.domObserver.stop();let f=u&&(pe||oe)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&Mu(r.selection,e.selection);if(u){let h=oe?this.trackWrites=this.domSelectionRange().focusNode:null;(i||!this.docView.update(e.doc,a,l,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=qi(e.doc,a,l,this.dom,this)),h&&!this.trackWrites&&(f=!0)}f||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ec(this))?He(this,f):(Do(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&nc(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof T){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$i(this,t.getBoundingClientRect(),e)}else $i(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;tt.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ac(this,e)}coordsAtPos(e,t=1){return wo(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return hc(this,t||this.state,e)}pasteHTML(e,t){return Zt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Zt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(_c(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],fr(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Wc(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return ue&&this.root.nodeType===11&&Ua(this.dom.ownerDocument)==this.dom?fu(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function fs(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[be.node(0,n.state.doc.content.size,e)]}function hs(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:be.widget(n.state.selection.head,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function ps(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Mu(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function ms(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Su(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function gs(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var tt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},In={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},wu=typeof navigator<"u"&&/Mac/.test(navigator.platform),Cu=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var ne=0;ne<10;ne++)tt[48+ne]=tt[96+ne]=String(ne);for(var ne=1;ne<=24;ne++)tt[ne+111]="F"+ne;for(var ne=65;ne<=90;ne++)tt[ne]=String.fromCharCode(ne+32),In[ne]=String.fromCharCode(ne);for(var pr in tt)In.hasOwnProperty(pr)||(In[pr]=tt[pr]);function Tu(n){var e=wu&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Cu&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?In:tt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Eu=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Ou(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=tt[r.keyCode])&&s!=i){let l=e[mr(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const vu=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Du(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Iu=(n,e,t)=>{let r=Du(n,t);if(!r)return!1;let i=Xo(r);if(!i){let o=r.blockRange(),l=o&&Ht(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(!s.type.spec.isolating&&el(n,i,e))return!0;if(r.parent.content.size==0&&(zt(s,"end")||T.isSelectable(s))){let o=qr(n.doc,r.before(),r.after(),M.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Xo(r)}let o=s&&s.nodeBefore;return!o||!T.isSelectable(o)?!1:(e&&e(n.tr.setSelection(T.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Xo(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Lu(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Lu(n,t);if(!r)return!1;let i=Zo(r);if(!i)return!1;let s=i.nodeAfter;if(el(n,i,e))return!0;if(r.parent.content.size==0&&(zt(s,"start")||T.isSelectable(s))){let o=qr(n.doc,r.before(),r.after(),M.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof T,i;if(r){if(t.node.isTextblock||!nt(n.doc,t.from))return!1;i=t.from}else if(i=Fn(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(T.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Fu=(n,e)=>{let t=n.selection,r;if(t instanceof T){if(t.node.isTextblock||!nt(n.doc,t.to))return!1;r=t.to}else if(r=Fn(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},Hu=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&Ht(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Vu=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` `).scrollIntoView()),!0)};function Qo(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Qo(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(D.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},_u=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof xe||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Qo(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(vt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Ht(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)},Wu=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(T.create(n.doc,i))),!0)};function Ku(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||nt(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function el(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s,o;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Ku(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(s=(o=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&o.matchType(s[0]||i.type).validEnd){if(t){let d=e.pos+i.nodeSize,f=b.empty;for(let m=s.length-1;m>=0;m--)f=b.from(s[m].create(null,f));f=b.from(r.copy(f));let h=n.tr.step(new Y(e.pos-1,d,e.pos,d,new M(f,1,0),s.length,!0)),p=d+2*s.length;nt(h.doc,p)&&h.join(p),t(h.scrollIntoView())}return!0}let a=D.findFrom(e,1),c=a&&a.$from.blockRange(a.$to),u=c&&Ht(c);if(u!=null&&u>=e.depth)return t&&t(n.tr.lift(c,u).scrollIntoView()),!0;if(l&&zt(i,"start",!0)&&zt(r,"end")){let d=r,f=[];for(;f.push(d),!d.isTextblock;)d=d.lastChild;let h=i,p=1;for(;!h.isTextblock;h=h.firstChild)p++;if(d.canReplace(d.childCount,d.childCount,h.content)){if(t){let m=b.empty;for(let y=f.length-1;y>=0;y--)m=b.from(f[y].copy(m));let g=n.tr.step(new Y(e.pos-f.length,e.pos+i.nodeSize,e.pos+p,e.pos+i.nodeSize-p,new M(m,f.length,0),0,!0));t(g.scrollIntoView())}return!0}}return!1}function tl(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}const Ju=tl(-1),qu=tl(1);function Uu(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Jr(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ys(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let u=t.doc.resolve(c),d=u.index();i=u.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let u=t.doc.resolve(o.start-2);a=new Cn(u,u,o.depth),o.endIndex=0;u--)s=b.from(t[u].type.create(t[u].attrs,s));n.step(new Y(e.start-(r?2:0),e.end,e.start,e.end,new M(s,0,0),t.length,!0));let o=0;for(let u=0;uo.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?Zu(e,t,n,s):Qu(e,t,s):!0:!1}}function Zu(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)h-=i.child(p).nodeSize,r.delete(h-1,h+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),u=s.index(-1);if(!c.canReplace(u+(l?0:1),u+1,o.content.append(a?b.empty:b.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new Y(d-(l?1:0),f+(a?1:0),d+1,f-1,new M((l?b.empty:b.from(i.copy(b.empty))).append(a?b.empty:b.from(i.copy(b.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function ed(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,u=b.from(c?n.create():null),d=new M(b.from(n.create(null,b.from(l.type.create(null,u)))),c?3:1,0),f=s.start,h=s.end;t(e.tr.step(new Y(f-(c?3:1),h,f,h,d,1,!0)).scrollIntoView())}return!0}}function jn(n){const{state:e,transaction:t}=n;let{selection:r}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=t.selection,i=t.doc,s=t.storedMarks,t}}}class Wn{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:r}=this,{view:i}=t,{tr:s}=r,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...u)=>{const d=a(...u)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,u=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(r).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,t),y=h(...m)(g);return l.push(y),d}])),run:u};return d}createCan(e){const{rawCommands:t,state:r}=this,i=!1,s=e||r.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...u)=>c(...u)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:jn({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([a,c])=>[a,(...u)=>c(...u)(l)]))}};return l}}class td{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const r=this.callbacks[e];return r&&r.forEach(i=>i.apply(this,t)),this}off(e,t){const r=this.callbacks[e];return r&&(t?this.callbacks[e]=r.filter(i=>i!==t):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}}function w(n,e,t){return n.config[e]===void 0&&n.parent?w(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?w(n.parent,e,t):null}):n.config[e]}function Kn(n){const e=n.filter(i=>i.type==="extension"),t=n.filter(i=>i.type==="node"),r=n.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:r}}function nl(n){const e=[],{nodeExtensions:t,markExtensions:r}=Kn(n),i=[...t,...r],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return n.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=w(o,"addGlobalAttributes",l);if(!a)return;a().forEach(u=>{u.types.forEach(d=>{Object.entries(u.attributes).forEach(([f,h])=>{e.push({type:d,name:f,attribute:{...s,...h}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=w(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([u,d])=>{const f={...s,...d};typeof(f==null?void 0:f.default)=="function"&&(f.default=f.default()),f!=null&&f.isRequired&&(f==null?void 0:f.default)===void 0&&delete f.default,e.push({type:o.name,name:u,attribute:f})})}),e}function Z(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}function H(...n){return n.filter(e=>!!e).reduce((e,t)=>{const r={...e};return Object.entries(t).forEach(([i,s])=>{if(!r[i]){r[i]=s;return}if(i==="class"){const l=s?s.split(" "):[],a=r[i]?r[i].split(" "):[],c=l.filter(u=>!a.includes(u));r[i]=[...a,...c].join(" ")}else i==="style"?r[i]=[r[i],s].join("; "):r[i]=s}),r},{})}function Hr(n,e){return e.filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,r)=>H(t,r),{})}function rl(n){return typeof n=="function"}function v(n,e=void 0,...t){return rl(n)?e?n.bind(e)(...t):n(...t):n}function nd(n={}){return Object.keys(n).length===0&&n.constructor===Object}function rd(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function bs(n,e){return n.style?n:{...n,getAttrs:t=>{const r=n.getAttrs?n.getAttrs(t):n.attrs;if(r===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):rd(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...r,...i}}}}function ks(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&nd(t)?!1:t!=null))}function id(n,e){var t;const r=nl(n),{nodeExtensions:i,markExtensions:s}=Kn(n),o=(t=i.find(c=>w(c,"topNode")))===null||t===void 0?void 0:t.name,l=Object.fromEntries(i.map(c=>{const u=r.filter(y=>y.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((y,S)=>{const R=w(S,"extendNodeSchema",d);return{...y,...R?R(c):{}}},{}),h=ks({...f,content:v(w(c,"content",d)),marks:v(w(c,"marks",d)),group:v(w(c,"group",d)),inline:v(w(c,"inline",d)),atom:v(w(c,"atom",d)),selectable:v(w(c,"selectable",d)),draggable:v(w(c,"draggable",d)),code:v(w(c,"code",d)),defining:v(w(c,"defining",d)),isolating:v(w(c,"isolating",d)),attrs:Object.fromEntries(u.map(y=>{var S;return[y.name,{default:(S=y==null?void 0:y.attribute)===null||S===void 0?void 0:S.default}]}))}),p=v(w(c,"parseHTML",d));p&&(h.parseDOM=p.map(y=>bs(y,u)));const m=w(c,"renderHTML",d);m&&(h.toDOM=y=>m({node:y,HTMLAttributes:Hr(y,u)}));const g=w(c,"renderText",d);return g&&(h.toText=g),[c.name,h]})),a=Object.fromEntries(s.map(c=>{const u=r.filter(g=>g.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((g,y)=>{const S=w(y,"extendMarkSchema",d);return{...g,...S?S(c):{}}},{}),h=ks({...f,inclusive:v(w(c,"inclusive",d)),excludes:v(w(c,"excludes",d)),group:v(w(c,"group",d)),spanning:v(w(c,"spanning",d)),code:v(w(c,"code",d)),attrs:Object.fromEntries(u.map(g=>{var y;return[g.name,{default:(y=g==null?void 0:g.attribute)===null||y===void 0?void 0:y.default}]}))}),p=v(w(c,"parseHTML",d));p&&(h.parseDOM=p.map(g=>bs(g,u)));const m=w(c,"renderHTML",d);return m&&(h.toDOM=g=>m({mark:g,HTMLAttributes:Hr(g,u)})),[c.name,h]}));return new ha({topNode:o,nodes:l,marks:a})}function gr(n,e){return e.nodes[n]||e.marks[n]||null}function xs(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}const sd=(n,e=500)=>{let t="";const r=n.parentOffset;return n.parent.nodesBetween(Math.max(0,r-e),r,(i,s,o,l)=>{var a,c;const u=((c=(a=i.type.spec).toText)===null||c===void 0?void 0:c.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";t+=u.slice(0,Math.max(0,r-s))}),t};function ii(n){return Object.prototype.toString.call(n)==="[object RegExp]"}class Jn{constructor(e){this.find=e.find,this.handler=e.handler}}const od=(n,e)=>{if(ii(e))return e.exec(n);const t=e(n);if(!t)return null;const r=[t.text];return r.index=t.index,r.input=n,r.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(t.replaceWith)),r};function yr(n){var e;const{editor:t,from:r,to:i,text:s,rules:o,plugin:l}=n,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(r);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(f=>f.type.spec.code))return!1;let u=!1;const d=sd(c)+s;return o.forEach(f=>{if(u)return;const h=od(d,f.find);if(!h)return;const p=a.state.tr,m=jn({state:a.state,transaction:p}),g={from:r-(h[0].length-s.length),to:i},{commands:y,chain:S,can:R}=new Wn({editor:t,state:m});f.handler({state:m,range:g,match:h,commands:y,chain:S,can:R})===null||!p.steps.length||(p.setMeta(l,{transform:p,from:r,to:i,text:s}),a.dispatch(p),u=!0)}),u}function ld(n){const{editor:e,rules:t}=n,r=new ae({state:{init(){return null},apply(i,s){const o=i.getMeta(r);return o||(i.selectionSet||i.docChanged?null:s)}},props:{handleTextInput(i,s,o,l){return yr({editor:e,from:s,to:o,text:l,rules:t,plugin:r})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&yr({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:r})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?yr({editor:e,from:o.pos,to:o.pos,text:` `,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function ad(n){return typeof n=="number"}class cd{constructor(e){this.find=e.find,this.handler=e.handler}}const ud=(n,e)=>{if(ii(e))return[...n.matchAll(e)];const t=e(n);return t?t.map(r=>{const i=[r.text];return i.index=r.index,i.input=n,i.data=r.data,r.replaceWith&&(r.text.includes(r.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),i.push(r.replaceWith)),i}):[]};function dd(n){const{editor:e,state:t,from:r,to:i,rule:s,pasteEvent:o,dropEvent:l}=n,{commands:a,chain:c,can:u}=new Wn({editor:e,state:t}),d=[];return t.doc.nodesBetween(r,i,(h,p)=>{if(!h.isTextblock||h.type.spec.code)return;const m=Math.max(r,p),g=Math.min(i,p+h.content.size),y=h.textBetween(m-p,g-p,void 0,"");ud(y,s.find).forEach(R=>{if(R.index===void 0)return;const P=m+R.index+1,V=P+R[0].length,B={from:t.tr.mapping.map(P),to:t.tr.mapping.map(V)},re=s.handler({state:t,range:B,match:R,commands:a,chain:c,can:u,pasteEvent:o,dropEvent:l});d.push(re)})}),d.every(h=>h!==null)}function fd(n){const{editor:e,rules:t}=n;let r=null,i=!1,s=!1,o=new ClipboardEvent("paste"),l=new DragEvent("drop");return t.map(c=>new ae({view(u){const d=f=>{var h;r=!((h=u.dom.parentElement)===null||h===void 0)&&h.contains(f.target)?u.dom.parentElement:null};return window.addEventListener("dragstart",d),{destroy(){window.removeEventListener("dragstart",d)}}},props:{handleDOMEvents:{drop:(u,d)=>(s=r===u.dom.parentElement,l=d,!1),paste:(u,d)=>{var f;const h=(f=d.clipboardData)===null||f===void 0?void 0:f.getData("text/html");return o=d,i=!!(h!=null&&h.includes("data-pm-slice")),!1}}},appendTransaction:(u,d,f)=>{const h=u[0],p=h.getMeta("uiEvent")==="paste"&&!i,m=h.getMeta("uiEvent")==="drop"&&!s;if(!p&&!m)return;const g=d.doc.content.findDiffStart(f.doc.content),y=d.doc.content.findDiffEnd(f.doc.content);if(!ad(g)||!y||g===y.b)return;const S=f.tr,R=jn({state:f,transaction:S});if(!(!dd({editor:e,state:R,from:Math.max(g-1,0),to:y.b-1,rule:c,pasteEvent:o,dropEvent:l})||!S.steps.length))return l=new DragEvent("drop"),o=new ClipboardEvent("paste"),S}}))}function hd(n){const e=n.filter((t,r)=>n.indexOf(t)!==r);return[...new Set(e)]}class Nt{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Nt.resolve(e),this.schema=id(this.extensions,t),this.extensions.forEach(r=>{var i;this.editor.extensionStorage[r.name]=r.storage;const s={name:r.name,options:r.options,storage:r.storage,editor:this.editor,type:gr(r.name,this.schema)};r.type==="mark"&&(!((i=v(w(r,"keepOnSplit",s)))!==null&&i!==void 0)||i)&&this.splittableMarks.push(r.name);const o=w(r,"onBeforeCreate",s);o&&this.editor.on("beforeCreate",o);const l=w(r,"onCreate",s);l&&this.editor.on("create",l);const a=w(r,"onUpdate",s);a&&this.editor.on("update",a);const c=w(r,"onSelectionUpdate",s);c&&this.editor.on("selectionUpdate",c);const u=w(r,"onTransaction",s);u&&this.editor.on("transaction",u);const d=w(r,"onFocus",s);d&&this.editor.on("focus",d);const f=w(r,"onBlur",s);f&&this.editor.on("blur",f);const h=w(r,"onDestroy",s);h&&this.editor.on("destroy",h)})}static resolve(e){const t=Nt.sort(Nt.flatten(e)),r=hd(t.map(i=>i.name));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{const r={name:t.name,options:t.options,storage:t.storage},i=w(t,"addExtensions",r);return i?[t,...this.flatten(i())]:t}).flat(10)}static sort(e){return e.sort((r,i)=>{const s=w(r,"priority")||100,o=w(i,"priority")||100;return s>o?-1:s{const r={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:gr(t.name,this.schema)},i=w(t,"addCommands",r);return i?{...e,...i()}:e},{})}get plugins(){const{editor:e}=this,t=Nt.sort([...this.extensions].reverse()),r=[],i=[],s=t.map(o=>{const l={name:o.name,options:o.options,storage:o.storage,editor:e,type:gr(o.name,this.schema)},a=[],c=w(o,"addKeyboardShortcuts",l);let u={};if(o.type==="mark"&&o.config.exitable&&(u.ArrowRight=()=>he.handleExit({editor:e,mark:o})),c){const m=Object.fromEntries(Object.entries(c()).map(([g,y])=>[g,()=>y({editor:e})]));u={...u,...m}}const d=Au(u);a.push(d);const f=w(o,"addInputRules",l);xs(o,e.options.enableInputRules)&&f&&r.push(...f());const h=w(o,"addPasteRules",l);xs(o,e.options.enablePasteRules)&&h&&i.push(...h());const p=w(o,"addProseMirrorPlugins",l);if(p){const m=p();a.push(...m)}return a}).flat();return[ld({editor:e,rules:r}),...fd({editor:e,rules:i}),...s]}get attributes(){return nl(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=Kn(this.extensions);return Object.fromEntries(t.filter(r=>!!w(r,"addNodeView")).map(r=>{const i=this.attributes.filter(a=>a.type===r.name),s={name:r.name,options:r.options,storage:r.storage,editor:e,type:Z(r.name,this.schema)},o=w(r,"addNodeView",s);if(!o)return[];const l=(a,c,u,d)=>{const f=Hr(a,i);return o()({editor:e,node:a,getPos:u,decorations:d,HTMLAttributes:f,extension:r})};return[r.name,l]}))}}function pd(n){return Object.prototype.toString.call(n).slice(8,-1)}function br(n){return pd(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function qn(n,e){const t={...n};return br(n)&&br(e)&&Object.keys(e).forEach(r=>{br(e[r])?r in n?t[r]=qn(n[r],e[r]):Object.assign(t,{[r]:e[r]}):Object.assign(t,{[r]:e[r]})}),t}class Q{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=v(w(this,"addOptions",{name:this.name}))),this.storage=v(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Q(e)}configure(e={}){const t=this.extend();return t.options=qn(this.options,e),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new Q(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(w(t,"addOptions",{name:t.name})),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}}function il(n,e,t){const{from:r,to:i}=e,{blockSeparator:s=` `,textSerializers:o={}}=t||{};let l="",a=!0;return n.nodesBetween(r,i,(c,u,d,f)=>{var h;const p=o==null?void 0:o[c.type.name];p?(c.isBlock&&!a&&(l+=s,a=!0),d&&(l+=p({node:c,pos:u,parent:d,index:f,range:e}))):c.isText?(l+=(h=c==null?void 0:c.text)===null||h===void 0?void 0:h.slice(Math.max(r,u)-u,i-u),a=!1):c.isBlock&&!a&&(l+=s,a=!0)}),l}function sl(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const md=Q.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new ae({key:new Se("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:r,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),a=sl(t);return il(r,{from:o,to:l},{textSerializers:a})}}})]}}),gd=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),yd=(n=!1)=>({commands:e})=>e.setContent("",n),bd=()=>({state:n,tr:e,dispatch:t})=>{const{selection:r}=e,{ranges:i}=r;return t&&i.forEach(({$from:s,$to:o})=>{n.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:u}=e,d=c.resolve(u.map(a)),f=c.resolve(u.map(a+l.nodeSize)),h=d.blockRange(f);if(!h)return;const p=Ht(h);if(l.type.isTextblock){const{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(h.start,m)}(p||p===0)&&e.lift(h,p)})}),!0},kd=n=>e=>n(e),xd=()=>({state:n,dispatch:e})=>_u(n,e),Md=(n,e)=>({editor:t,tr:r})=>{const{state:i}=t,s=i.doc.slice(n.from,n.to);r.deleteRange(n.from,n.to);const o=r.mapping.map(e);return r.insert(o,s.content),r.setSelection(new A(r.doc.resolve(o-1))),!0},Sd=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,r=t.$anchor.node();if(r.content.size>0)return!1;const i=n.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r.type){if(e){const l=i.before(s),a=i.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1},wd=n=>({tr:e,state:t,dispatch:r})=>{const i=Z(n,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(r){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},Cd=n=>({tr:e,dispatch:t})=>{const{from:r,to:i}=n;return t&&e.delete(r,i),!0},Td=()=>({state:n,dispatch:e})=>vu(n,e),Ed=()=>({commands:n})=>n.keyboardShortcut("Enter"),Od=()=>({state:n,dispatch:e})=>$u(n,e);function Rn(n,e,t={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>t.strict?e[i]===n[i]:ii(e[i])?e[i].test(n[i]):e[i]===n[i]):!0}function Vr(n,e,t={}){return n.find(r=>r.type===e&&Rn(r.attrs,t))}function Nd(n,e,t={}){return!!Vr(n,e,t)}function si(n,e,t={}){if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if(n.parentOffset===r.offset&&r.offset!==0&&(r=n.parent.childBefore(n.parentOffset)),!r.node)return;const i=Vr([...r.node.marks],e,t);if(!i)return;let s=r.index,o=n.start()+r.offset,l=s+1,a=o+r.node.nodeSize;for(Vr([...r.node.marks],e,t);s>0&&i.isInSet(n.parent.child(s-1).marks);)s-=1,o-=n.parent.child(s).nodeSize;for(;l({tr:t,state:r,dispatch:i})=>{const s=it(n,r.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:u}=l;if(i){const d=si(a,s,e);if(d&&d.from<=c&&d.to>=u){const f=A.create(o,d.from,d.to);t.setSelection(f)}}return!0},vd=n=>e=>{const t=typeof n=="function"?n(e):n;for(let r=0;r({editor:t,view:r,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{oi()&&r.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};if(r.hasFocus()&&n===null||n===!1)return!0;if(s&&n===null&&!ol(t.state.selection))return o(),!0;const l=ll(i.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Id=(n,e)=>t=>n.every((r,i)=>e(r,{...t,index:i})),Rd=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e);function Ms(n){const e=`${n}`;return new window.DOMParser().parseFromString(e,"text/html").body}function Ln(n,e,t){if(t={slice:!0,parseOptions:{},...t},typeof n=="object"&&n!==null)try{return Array.isArray(n)&&n.length>0?b.fromArray(n.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(n)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",r),Ln("",e,t)}if(typeof n=="string"){const r=Rt.fromSchema(e);return t.slice?r.parseSlice(Ms(n),t.parseOptions).content:r.parse(Ms(n),t.parseOptions)}return Ln("",e,t)}function Ld(n,e,t){const r=n.steps.length-1;if(r{o===0&&(o=u)}),n.setSelection(D.near(n.doc.resolve(o),t))}const Pd=n=>n.toString().startsWith("<"),Bd=(n,e,t)=>({tr:r,dispatch:i,editor:s})=>{if(i){t={parseOptions:{},updateSelection:!0,...t};const o=Ln(e,s.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions}});if(o.toString()==="<>")return!0;let{from:l,to:a}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},c=!0,u=!0;if((Pd(o)?o:[o]).forEach(f=>{f.check(),c=c?f.isText&&f.marks.length===0:!1,u=u?f.isBlock:!1}),l===a&&u){const{parent:f}=r.doc.resolve(l);f.isTextblock&&!f.type.spec.code&&!f.childCount&&(l-=1,a+=1)}c?Array.isArray(e)?r.insertText(e.map(f=>f.text||"").join(""),l,a):typeof e=="object"&&e&&e.text?r.insertText(e.text,l,a):r.insertText(e,l,a):r.replaceWith(l,a,o),t.updateSelection&&Ld(r,r.steps.length-1,-1)}return!0},zd=()=>({state:n,dispatch:e})=>zu(n,e),Fd=()=>({state:n,dispatch:e})=>Fu(n,e),Hd=()=>({state:n,dispatch:e})=>Iu(n,e),Vd=()=>({state:n,dispatch:e})=>Pu(n,e),$d=()=>({tr:n,state:e,dispatch:t})=>{try{const r=Fn(e.doc,e.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},_d=()=>({state:n,dispatch:e,tr:t})=>{try{const r=Fn(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}};function li(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function jd(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let r,i,s,o;for(let l=0;l({editor:e,view:t,tr:r,dispatch:i})=>{const s=jd(n).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a==null||a.steps.forEach(c=>{const u=c.map(r.mapping);u&&i&&r.maybeStep(u)}),!0};function en(n,e,t={}){const{from:r,to:i,empty:s}=n.selection,o=e?Z(e,n.schema):null,l=[];n.doc.nodesBetween(r,i,(d,f)=>{if(d.isText)return;const h=Math.max(r,f),p=Math.min(i,f+d.nodeSize);l.push({node:d,from:h,to:p})});const a=i-r,c=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>Rn(d.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((d,f)=>d+f.to-f.from,0)>=a}const Kd=(n,e={})=>({state:t,dispatch:r})=>{const i=Z(n,t.schema);return en(t,i,e)?Hu(t,r):!1},Jd=()=>({state:n,dispatch:e})=>ju(n,e),qd=n=>({state:e,dispatch:t})=>{const r=Z(n,e.schema);return Xu(r)(e,t)},Ud=()=>({state:n,dispatch:e})=>Vu(n,e);function Un(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function Ss(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((r,i)=>(t.includes(i)||(r[i]=n[i]),r),{})}const Gd=(n,e)=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null;const l=Un(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=Z(n,r.schema)),l==="mark"&&(o=it(n,r.schema)),i&&t.selection.ranges.forEach(a=>{r.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,u)=>{s&&s===c.type&&t.setNodeMarkup(u,void 0,Ss(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(d=>{o===d.type&&t.addMark(u,u+c.nodeSize,o.create(Ss(d.attrs,e)))})})}),!0):!1},Yd=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Xd=()=>({tr:n,commands:e})=>e.setTextSelection({from:0,to:n.doc.content.size}),Zd=()=>({state:n,dispatch:e})=>Ru(n,e),Qd=()=>({state:n,dispatch:e})=>Bu(n,e),ef=()=>({state:n,dispatch:e})=>Wu(n,e),tf=()=>({state:n,dispatch:e})=>qu(n,e),nf=()=>({state:n,dispatch:e})=>Ju(n,e);function al(n,e,t={}){return Ln(n,e,{slice:!1,parseOptions:t})}const rf=(n,e=!1,t={})=>({tr:r,editor:i,dispatch:s})=>{const{doc:o}=r,l=al(n,i.schema,t);return s&&r.replaceWith(0,o.content.size,l).setMeta("preventUpdate",!e),!0};function an(n,e){const t=it(e,n.schema),{from:r,to:i,empty:s}=n.selection,o=[];s?(n.storedMarks&&o.push(...n.storedMarks),o.push(...n.selection.$head.marks())):n.doc.nodesBetween(r,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function sf(n,e){const t=new mo(n);return e.forEach(r=>{r.steps.forEach(i=>{t.step(i)})}),t}function of(n){for(let e=0;e{e(r)&&t.push({node:r,pos:i})}),t}function lf(n,e,t){const r=[];return n.nodesBetween(e.from,e.to,(i,s)=>{t(i)&&r.push({node:i,pos:s})}),r}function af(n,e){for(let t=n.depth;t>0;t-=1){const r=n.node(t);if(e(r))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:r}}}function ai(n){return e=>af(e.$from,n)}function cf(n,e){const t=Ie.fromSchema(e).serializeFragment(n),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}function uf(n,e){const t={from:0,to:n.content.size};return il(n,t,e)}function df(n,e){const t=Z(e,n.schema),{from:r,to:i}=n.selection,s=[];n.doc.nodesBetween(r,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function cl(n,e){const t=Un(typeof e=="string"?e:e.name,n.schema);return t==="node"?df(n,e):t==="mark"?an(n,e):{}}function ff(n,e=JSON.stringify){const t={};return n.filter(r=>{const i=e(r);return Object.prototype.hasOwnProperty.call(t,i)?!1:t[i]=!0})}function hf(n){const e=ff(n);return e.length===1?e:e.filter((t,r)=>!e.filter((s,o)=>o!==r).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function pf(n){const{mapping:e,steps:t}=n,r=[];return e.maps.forEach((i,s)=>{const o=[];if(i.ranges.length)i.forEach((l,a)=>{o.push({from:l,to:a})});else{const{from:l,to:a}=t[s];if(l===void 0||a===void 0)return;o.push({from:l,to:a})}o.forEach(({from:l,to:a})=>{const c=e.slice(s).map(l,-1),u=e.slice(s).map(a),d=e.invert().map(c,-1),f=e.invert().map(u);r.push({oldRange:{from:d,to:f},newRange:{from:c,to:u}})})}),hf(r)}function ci(n,e,t){const r=[];return n===e?t.resolve(n).marks().forEach(i=>{const s=t.resolve(n-1),o=si(s,i.type);o&&r.push({mark:i,...o})}):t.nodesBetween(n,e,(i,s)=>{r.push(...i.marks.map(o=>({from:s,to:s+i.nodeSize,mark:o})))}),r}function kn(n,e,t){return Object.fromEntries(Object.entries(t).filter(([r])=>{const i=n.find(s=>s.type===e&&s.name===r);return i?i.attribute.keepOnSplit:!1}))}function _r(n,e,t={}){const{empty:r,ranges:i}=n.selection,s=e?it(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>Rn(d.attrs,t,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:d,$to:f})=>{const h=d.pos,p=f.pos;n.doc.nodesBetween(h,p,(m,g)=>{if(!m.isText&&!m.marks.length)return;const y=Math.max(h,g),S=Math.min(p,g+m.nodeSize),R=S-y;o+=R,l.push(...m.marks.map(P=>({mark:P,from:y,to:S})))})}),o===0)return!1;const a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>Rn(d.mark.attrs,t,{strict:!1})).reduce((d,f)=>d+f.to-f.from,0),c=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,f)=>d+f.to-f.from,0);return(a>0?a+c:a)>=o}function mf(n,e,t={}){if(!e)return en(n,null,t)||_r(n,null,t);const r=Un(e,n.schema);return r==="node"?en(n,e,t):r==="mark"?_r(n,e,t):!1}function ws(n,e){const{nodeExtensions:t}=Kn(e),r=t.find(o=>o.name===n);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},s=v(w(r,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function gf(n){var e;const t=(e=n.type.createAndFill())===null||e===void 0?void 0:e.toJSON(),r=n.toJSON();return JSON.stringify(t)===JSON.stringify(r)}function yf(n,e,t){var r;const{selection:i}=e;let s=null;if(ol(i)&&(s=i.$cursor),s){const l=(r=n.storedMarks)!==null&&r!==void 0?r:s.marks();return!!t.isInSet(l)||!l.some(a=>a.type.excludes(t))}const{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(u,d,f)=>{if(c)return!1;if(u.isInline){const h=!f||f.type.allowsMarkType(t),p=!!t.isInSet(u.marks)||!u.marks.some(m=>m.type.excludes(t));c=h&&p}return!c}),c})}const bf=(n,e={})=>({tr:t,state:r,dispatch:i})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=it(n,r.schema);if(i)if(o){const c=an(r,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const u=c.$from.pos,d=c.$to.pos;r.doc.nodesBetween(u,d,(f,h)=>{const p=Math.max(h,u),m=Math.min(h+f.nodeSize,d);f.marks.find(y=>y.type===a)?f.marks.forEach(y=>{a===y.type&&t.addMark(p,m,a.create({...y.attrs,...e}))}):t.addMark(p,m,a.create(e))})});return yf(r,t,a)},kf=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),xf=(n,e={})=>({state:t,dispatch:r,chain:i})=>{const s=Z(n,t.schema);return s.isTextblock?i().command(({commands:o})=>ys(s,e)(t)?!0:o.clearNodes()).command(({state:o})=>ys(s,e)(o,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Mf=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,i=ut(n,0,r.content.size),s=T.create(r,i);e.setSelection(s)}return!0},Sf=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,{from:i,to:s}=typeof n=="number"?{from:n,to:n}:n,o=A.atStart(r).from,l=A.atEnd(r).to,a=ut(i,o,l),c=ut(s,o,l),u=A.create(r,a,c);e.setSelection(u)}return!0},wf=n=>({state:e,dispatch:t})=>{const r=Z(n,e.schema);return ed(r)(e,t)};function Cs(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const r=t.filter(i=>e==null?void 0:e.includes(i.type.name));n.tr.ensureMarks(r)}}const Cf=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:r,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,u=kn(c,l.node().type.name,l.node().attrs);if(s instanceof T&&s.node.isBlock)return!l.parentOffset||!vt(o,l.pos)?!1:(r&&(n&&Cs(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;if(r){const d=a.parentOffset===a.parent.content.size;s instanceof A&&e.deleteSelection();const f=l.depth===0?void 0:of(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&f?[{type:f,attrs:u}]:void 0,p=vt(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!p&&vt(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(p=!0,h=f?[{type:f,attrs:u}]:void 0),p&&(e.split(e.mapping.map(l.pos),1,h),f&&!d&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}n&&Cs(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return!0},Tf=n=>({tr:e,state:t,dispatch:r,editor:i})=>{var s;const o=Z(n,t.schema),{$from:l,$to:a}=t.selection,c=t.selection.node;if(c&&c.isBlock||l.depth<2||!l.sameParent(a))return!1;const u=l.node(-1);if(u.type!==o)return!1;const d=i.extensionManager.attributes;if(l.parent.content.size===0&&l.node(-1).childCount===l.indexAfter(-1)){if(l.depth===2||l.node(-3).type!==o||l.index(-2)!==l.node(-2).childCount-1)return!1;if(r){let g=b.empty;const y=l.index(-1)?1:l.index(-2)?2:3;for(let re=l.depth-y;re>=l.depth-3;re-=1)g=b.from(l.node(re).copy(g));const S=l.indexAfter(-1){if(B>-1)return!1;re.isTextblock&&re.content.size===0&&(B=Ae+1)}),B>-1&&e.setSelection(A.near(e.doc.resolve(B))),e.scrollIntoView()}return!0}const f=a.pos===l.end()?u.contentMatchAt(0).defaultType:null,h=kn(d,u.type.name,u.attrs),p=kn(d,l.node().type.name,l.node().attrs);e.delete(l.pos,a.pos);const m=f?[{type:o,attrs:h},{type:f,attrs:p}]:[{type:o,attrs:h}];if(!vt(e.doc,l.pos,2))return!1;if(r){const{selection:g,storedMarks:y}=t,{splittableMarks:S}=i.extensionManager,R=y||g.$to.parentOffset&&g.$from.marks();if(e.split(l.pos,2,m).scrollIntoView(),!R||!r)return!0;const P=R.filter(V=>S.includes(V.type.name));e.ensureMarks(P)}return!0},kr=(n,e)=>{const t=ai(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(r===void 0)return!0;const i=n.doc.nodeAt(r);return t.node.type===(i==null?void 0:i.type)&&nt(n.doc,t.pos)&&n.join(t.pos),!0},xr=(n,e)=>{const t=ai(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(t.start).after(t.depth);if(r===void 0)return!0;const i=n.doc.nodeAt(r);return t.node.type===(i==null?void 0:i.type)&&nt(n.doc,r)&&n.join(r),!0},Ef=(n,e,t,r={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:c,can:u})=>{const{extensions:d,splittableMarks:f}=i.extensionManager,h=Z(n,o.schema),p=Z(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:S}=m,R=y.blockRange(S),P=g||m.$to.parentOffset&&m.$from.marks();if(!R)return!1;const V=ai(B=>ws(B.type.name,d))(m);if(R.depth>=1&&V&&R.depth-V.depth<=1){if(V.node.type===h)return c.liftListItem(p);if(ws(V.node.type.name,d)&&h.validContent(V.node.content)&&l)return a().command(()=>(s.setNodeMarkup(V.pos,h),!0)).command(()=>kr(s,h)).command(()=>xr(s,h)).run()}return!t||!P||!l?a().command(()=>u().wrapInList(h,r)?!0:c.clearNodes()).wrapInList(h,r).command(()=>kr(s,h)).command(()=>xr(s,h)).run():a().command(()=>{const B=u().wrapInList(h,r),re=P.filter(Ae=>f.includes(Ae.type.name));return s.ensureMarks(re),B?!0:c.clearNodes()}).wrapInList(h,r).command(()=>kr(s,h)).command(()=>xr(s,h)).run()},Of=(n,e={},t={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:s=!1}=t,o=it(n,r.schema);return _r(r,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},Nf=(n,e,t={})=>({state:r,commands:i})=>{const s=Z(n,r.schema),o=Z(e,r.schema);return en(r,s,t)?i.setNode(o):i.setNode(s,t)},Af=(n,e={})=>({state:t,commands:r})=>{const i=Z(n,t.schema);return en(t,i,e)?r.lift(i):r.wrapIn(i,e)},vf=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let r=0;r=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},Df=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:r,ranges:i}=t;return r||e&&i.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},If=(n,e={})=>({tr:t,state:r,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=it(n,r.schema),{$from:c,empty:u,ranges:d}=l;if(!i)return!0;if(u&&o){let{from:f,to:h}=l;const p=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=si(c,a,p);m&&(f=m.from,h=m.to),t.removeMark(f,h,a)}else d.forEach(f=>{t.removeMark(f.$from.pos,f.$to.pos,a)});return t.removeStoredMark(a),!0},Rf=(n,e={})=>({tr:t,state:r,dispatch:i})=>{let s=null,o=null;const l=Un(typeof n=="string"?n:n.name,r.schema);return l?(l==="node"&&(s=Z(n,r.schema)),l==="mark"&&(o=it(n,r.schema)),i&&t.selection.ranges.forEach(a=>{const c=a.$from.pos,u=a.$to.pos;r.doc.nodesBetween(c,u,(d,f)=>{s&&s===d.type&&t.setNodeMarkup(f,void 0,{...d.attrs,...e}),o&&d.marks.length&&d.marks.forEach(h=>{if(o===h.type){const p=Math.max(f,c),m=Math.min(f+d.nodeSize,u);t.addMark(p,m,o.create({...h.attrs,...e}))}})})}),!0):!1},Lf=(n,e={})=>({state:t,dispatch:r})=>{const i=Z(n,t.schema);return Uu(i,e)(t,r)},Pf=(n,e={})=>({state:t,dispatch:r})=>{const i=Z(n,t.schema);return Gu(i,e)(t,r)};var Bf=Object.freeze({__proto__:null,blur:gd,clearContent:yd,clearNodes:bd,command:kd,createParagraphNear:xd,cut:Md,deleteCurrentNode:Sd,deleteNode:wd,deleteRange:Cd,deleteSelection:Td,enter:Ed,exitCode:Od,extendMarkRange:Ad,first:vd,focus:Dd,forEach:Id,insertContent:Rd,insertContentAt:Bd,joinUp:zd,joinDown:Fd,joinBackward:Hd,joinForward:Vd,joinItemBackward:$d,joinItemForward:_d,keyboardShortcut:Wd,lift:Kd,liftEmptyBlock:Jd,liftListItem:qd,newlineInCode:Ud,resetAttributes:Gd,scrollIntoView:Yd,selectAll:Xd,selectNodeBackward:Zd,selectNodeForward:Qd,selectParentNode:ef,selectTextblockEnd:tf,selectTextblockStart:nf,setContent:rf,setMark:bf,setMeta:kf,setNode:xf,setNodeSelection:Mf,setTextSelection:Sf,sinkListItem:wf,splitBlock:Cf,splitListItem:Tf,toggleList:Ef,toggleMark:Of,toggleNode:Nf,toggleWrap:Af,undoInputRule:vf,unsetAllMarks:Df,unsetMark:If,updateAttributes:Rf,wrapIn:Lf,wrapInList:Pf});const zf=Q.create({name:"commands",addCommands(){return{...Bf}}}),Ff=Q.create({name:"editable",addProseMirrorPlugins(){return[new ae({key:new Se("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Hf=Q.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ae({key:new Se("focusEvents"),props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const r=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,t)=>{n.isFocused=!1;const r=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),Vf=Q.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:u,$anchor:d}=a,{pos:f,parent:h}=d,p=d.parent.isTextblock?l.doc.resolve(f-1):d,m=p.parent.type.spec.isolating,g=d.pos-d.parentOffset,y=m&&p.parent.childCount===1?g===d.pos:D.atStart(c).from===f;return!u||!y||!h.type.isTextblock||h.textContent.length?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},s={...r,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return oi()||li()?s:i},addProseMirrorPlugins(){return[new ae({key:new Se("clearDocument"),appendTransaction:(n,e,t)=>{if(!(n.some(p=>p.docChanged)&&!e.doc.eq(t.doc)))return;const{empty:i,from:s,to:o}=e.selection,l=D.atStart(e.doc).from,a=D.atEnd(e.doc).to;if(i||!(s===l&&o===a)||!(t.doc.textBetween(0,t.doc.content.size," "," ").length===0))return;const d=t.tr,f=jn({state:t,transaction:d}),{commands:h}=new Wn({editor:this.editor,state:f});if(h.clearNodes(),!!d.steps.length)return d}})]}}),$f=Q.create({name:"tabindex",addProseMirrorPlugins(){return[new ae({key:new Se("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});var _f=Object.freeze({__proto__:null,ClipboardTextSerializer:md,Commands:zf,Editable:Ff,FocusEvents:Hf,Keymap:Vf,Tabindex:$f});const jf=`.ProseMirror { position: relative; } .ProseMirror { word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; -webkit-font-variant-ligatures: none; font-variant-ligatures: none; font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ } .ProseMirror [contenteditable="false"] { white-space: normal; } .ProseMirror [contenteditable="false"] [contenteditable="true"] { white-space: pre-wrap; } .ProseMirror pre { white-space: pre-wrap; } img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; width: 1px !important; height: 1px !important; } .ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; margin: 0; } .ProseMirror-gapcursor:after { content: ""; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid black; animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; } @keyframes ProseMirror-cursor-blink { to { visibility: hidden; } } .ProseMirror-hideselection *::selection { background: transparent; } .ProseMirror-hideselection *::-moz-selection { background: transparent; } .ProseMirror-hideselection * { caret-color: transparent; } .ProseMirror-focused .ProseMirror-gapcursor { display: block; } .tippy-box[data-animation=fade][data-state=hidden] { opacity: 0 }`;function Wf(n,e,t){const r=document.querySelector(`style[data-tiptap-style${t?`-${t}`:""}]`);if(r!==null)return r;const i=document.createElement("style");return e&&i.setAttribute("nonce",e),i.setAttribute(`data-tiptap-style${t?`-${t}`:""}`,""),i.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(i),i}let Kf=class extends td{constructor(e={}){super(),this.isFocused=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}))},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=Wf(jf,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const r=rl(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:r});this.view.updateState(i)}unregisterPlugin(e){if(this.isDestroyed)return;const t=typeof e=="string"?`${e}$`:e.key,r=this.state.reconfigure({plugins:this.state.plugins.filter(i=>!i.key.startsWith(t))});this.view.updateState(r)}createExtensionManager(){const t=[...this.options.enableCoreExtensions?Object.values(_f):[],...this.options.extensions].filter(r=>["extension","node","mark"].includes(r==null?void 0:r.type));this.extensionManager=new Nt(t,this)}createCommandManager(){this.commandManager=new Wn({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){const e=al(this.options.content,this.schema,this.options.parseOptions),t=ll(e,this.options.autofocus);this.view=new xu(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:Ot.create({doc:e,selection:t||void 0})});const r=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(r),this.createNodeViews(),this.prependClass();const i=this.view.dom;i.editor=this}createNodeViews(){this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var l;return(l=this.capturedTransaction)===null||l===void 0?void 0:l.step(o)});return}const t=this.state.apply(e),r=!this.state.selection.eq(t.selection);this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const i=e.getMeta("focus"),s=e.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:e}),s&&this.emit("blur",{editor:this,event:s.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return cl(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,i=typeof e=="string"?t:e;return mf(this.state,r,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return cf(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=` `,textSerializers:r={}}=e||{};return uf(this.state.doc,{blockSeparator:t,textSerializers:{...sl(this.schema),...r}})}get isEmpty(){return gf(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){this.emit("destroy"),this.view&&this.view.destroy(),this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}};function Ft(n){return new Jn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=v(n.getAttributes,void 0,r);if(i===!1||i===null)return null;const{tr:s}=e,o=r[r.length-1],l=r[0];if(o){const a=l.search(/\S/),c=t.from+l.indexOf(o),u=c+o.length;if(ci(t.from,t.to,e.doc).filter(h=>h.mark.type.excluded.find(m=>m===n.type&&m!==h.mark.type)).filter(h=>h.to>c).length)return null;ut.from&&s.delete(t.from+a,c);const f=t.from+a+o.length;s.addMark(t.from+a,f,n.type.create(i||{})),s.removeStoredMark(n.type)}}})}function ul(n){return new Jn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=v(n.getAttributes,void 0,r)||{},{tr:s}=e,o=t.from;let l=t.to;const a=n.type.create(i);if(r[1]){const c=r[0].lastIndexOf(r[1]);let u=o+c;u>l?u=l:l=u+r[1].length;const d=r[0][r[0].length-1];s.insertText(d,o+r[0].length-1),s.replaceWith(u,l,a)}else r[0]&&s.insert(o-1,n.type.create(i)).delete(s.mapping.map(o),s.mapping.map(l));s.scrollIntoView()}})}function jr(n){return new Jn({find:n.find,handler:({state:e,range:t,match:r})=>{const i=e.doc.resolve(t.from),s=v(n.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,s)}})}function tn(n){return new Jn({find:n.find,handler:({state:e,range:t,match:r,chain:i})=>{const s=v(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),a=o.doc.resolve(t.from).blockRange(),c=a&&Jr(a,n.type,s);if(!c)return null;if(o.wrap(a,c),n.keepMarks&&n.editor){const{selection:d,storedMarks:f}=e,{splittableMarks:h}=n.editor.extensionManager,p=f||d.$to.parentOffset&&d.$from.marks();if(p){const m=p.filter(g=>h.includes(g.type.name));o.ensureMarks(m)}}if(n.keepAttributes){const d=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";i().updateAttributes(d,s).run()}const u=o.doc.resolve(t.from-1).nodeBefore;u&&u.type===n.type&&nt(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,u))&&o.join(t.from-1)}})}class he{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=v(w(this,"addOptions",{name:this.name}))),this.storage=v(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new he(e)}configure(e={}){const t=this.extend();return t.options=qn(this.options,e),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new he(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(w(t,"addOptions",{name:t.name})),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:r}=e.state,i=e.state.selection.$from;if(i.pos===i.end()){const o=i.marks();if(!!!o.find(c=>(c==null?void 0:c.type.name)===t.name))return!1;const a=o.find(c=>(c==null?void 0:c.type.name)===t.name);return a&&r.removeStoredMark(a),r.insertText(" ",i.pos),e.view.dispatch(r),!0}return!1}}class q{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=v(w(this,"addOptions",{name:this.name}))),this.storage=v(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new q(e)}configure(e={}){const t=this.extend();return t.options=qn(this.options,e),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new q(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=v(w(t,"addOptions",{name:t.name})),t.storage=v(w(t,"addStorage",{name:t.name,options:t.options})),t}}function xt(n){return new cd({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:i})=>{const s=v(n.getAttributes,void 0,r,i);if(s===!1||s===null)return null;const{tr:o}=e,l=r[r.length-1],a=r[0];let c=t.to;if(l){const u=a.search(/\S/),d=t.from+a.indexOf(l),f=d+l.length;if(ci(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(g=>g===n.type&&g!==p.mark.type)).filter(p=>p.to>d).length)return null;ft.from&&o.delete(t.from+u,d),c=t.from+u+l.length,o.addMark(t.from+u,c,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}const Jf=({renderers:n})=>ge.createElement(ge.Fragment,null,Object.entries(n).map(([e,t])=>zl.createPortal(t.reactElement,t.element,e)));class qf extends ge.Component{constructor(e){super(e),this.editorContentRef=ge.createRef(),this.initialized=!1,this.state={renderers:{}}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){const{editor:e}=this.props;if(e&&e.options.element){if(e.contentComponent)return;const t=this.editorContentRef.current;t.append(...e.options.element.childNodes),e.setOptions({element:t}),e.contentComponent=this,e.createNodeViews(),this.initialized=!0}}maybeFlushSync(e){this.initialized?Bl.flushSync(e):e()}setRenderer(e,t){this.maybeFlushSync(()=>{this.setState(({renderers:r})=>({renderers:{...r,[e]:t}}))})}removeRenderer(e){this.maybeFlushSync(()=>{this.setState(({renderers:t})=>{const r={...t};return delete r[e],{renderers:r}})})}componentWillUnmount(){const{editor:e}=this.props;if(!e||(this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),e.contentComponent=null,!e.options.element.firstChild))return;const t=document.createElement("div");t.append(...e.options.element.childNodes),e.setOptions({element:t})}render(){const{editor:e,...t}=this.props;return ge.createElement(ge.Fragment,null,ge.createElement("div",{ref:this.editorContentRef,...t}),ge.createElement(Jf,{renderers:this.state.renderers}))}}const Uf=n=>{const e=ge.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[n.editor]);return ge.createElement(qf,{key:e,...n})},Gf=ge.memo(Uf);class Yf extends Kf{constructor(){super(...arguments),this.contentComponent=null}}function Xf(){const[,n]=G.useState(0);return()=>n(e=>e+1)}const Zf=(n={},e=[])=>{const[t,r]=G.useState(null),i=Xf(),{onBeforeCreate:s,onBlur:o,onCreate:l,onDestroy:a,onFocus:c,onSelectionUpdate:u,onTransaction:d,onUpdate:f}=n,h=G.useRef(s),p=G.useRef(o),m=G.useRef(l),g=G.useRef(a),y=G.useRef(c),S=G.useRef(u),R=G.useRef(d),P=G.useRef(f);return G.useEffect(()=>{t&&(s&&(t.off("beforeCreate",h.current),t.on("beforeCreate",s),h.current=s),o&&(t.off("blur",p.current),t.on("blur",o),p.current=o),l&&(t.off("create",m.current),t.on("create",l),m.current=l),a&&(t.off("destroy",g.current),t.on("destroy",a),g.current=a),c&&(t.off("focus",y.current),t.on("focus",c),y.current=c),u&&(t.off("selectionUpdate",S.current),t.on("selectionUpdate",u),S.current=u),d&&(t.off("transaction",R.current),t.on("transaction",d),R.current=d),f&&(t.off("update",P.current),t.on("update",f),P.current=f))},[s,o,l,a,c,u,d,f,t]),G.useEffect(()=>{let V=!0;const B=new Yf(n);return r(B),B.on("transaction",()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{V&&i()})})}),()=>{V=!1}},e),G.useEffect(()=>()=>{t==null||t.destroy()},[t]),t},Qf=G.createContext({editor:null});Qf.Consumer;const eh=G.createContext({onDragStart:void 0}),th=()=>G.useContext(eh);ge.forwardRef((n,e)=>{const{onDragStart:t}=th(),r=n.as||"div";return ge.createElement(r,{...n,ref:e,"data-node-view-wrapper":"",onDragStart:t,style:{whiteSpace:"normal",...n.style}})});const nh=/^\s*>\s$/,rh=q.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setBlockquote:()=>({commands:n})=>n.wrapIn(this.name),toggleBlockquote:()=>({commands:n})=>n.toggleWrap(this.name),unsetBlockquote:()=>({commands:n})=>n.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[tn({find:nh,type:this.type})]}}),ih=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/,sh=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/g,oh=/(?:^|\s)((?:__)((?:[^__]+))(?:__))$/,lh=/(?:^|\s)((?:__)((?:[^__]+))(?:__))/g,ah=he.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return["strong",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Ft({find:ih,type:this.type}),Ft({find:oh,type:this.type})]},addPasteRules(){return[xt({find:sh,type:this.type}),xt({find:lh,type:this.type})]}}),ch=q.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",H(this.options.HTMLAttributes,n),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),Ts=he.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:n=>n.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["span",H(this.options.HTMLAttributes,n),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:n,commands:e})=>{const t=an(n,this.type);return Object.entries(t).some(([,i])=>!!i)?!0:e.unsetMark(this.name)}}}}),Es=/^\s*([-+*])\s$/,uh=q.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:n}){return["ul",H(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleBulletList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(ch.name,this.editor.getAttributes(Ts.name)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=tn({find:Es,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=tn({find:Es,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(Ts.name),editor:this.editor})),[n]}}),dh=/(?:^|\s)((?:`)((?:[^`]+))(?:`))$/,fh=/(?:^|\s)((?:`)((?:[^`]+))(?:`))/g,hh=he.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setCode:()=>({commands:n})=>n.setMark(this.name),toggleCode:()=>({commands:n})=>n.toggleMark(this.name),unsetCode:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Ft({find:dh,type:this.type})]},addPasteRules(){return[xt({find:fh,type:this.type})]}}),ph=/^```([a-z]+)?[\s\n]$/,mh=/^~~~([a-z]+)?[\s\n]$/,dl=q.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:null,parseHTML:n=>{var e;const{languageClassPrefix:t}=this.options,s=[...((e=n.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(o=>o.startsWith(t)).map(o=>o.replace(t,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",H(this.options.HTMLAttributes,e),["code",{class:n.attrs.language?this.options.languageClassPrefix+n.attrs.language:null},0]]},addCommands(){return{setCodeBlock:n=>({commands:e})=>e.setNode(this.name,n),toggleCodeBlock:n=>({commands:e})=>e.toggleNode(this.name,"paragraph",n)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:n,$anchor:e}=this.editor.state.selection,t=e.pos===1;return!n||e.parent.type.name!==this.name?!1:t||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:n})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=n,{selection:t}=e,{$from:r,empty:i}=t;if(!i||r.parent.type!==this.type)return!1;const s=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` `);return!s||!o?!1:n.chain().command(({tr:l})=>(l.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:n})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=n,{selection:t,doc:r}=e,{$from:i,empty:s}=t;if(!s||i.parent.type!==this.type||!(i.parentOffset===i.parent.nodeSize-2))return!1;const l=i.after();return l===void 0||r.nodeAt(l)?!1:n.commands.exitCode()}}},addInputRules(){return[jr({find:ph,type:this.type,getAttributes:n=>({language:n[1]})}),jr({find:mh,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new ae({key:new Se("codeBlockVSCodeHandler"),props:{handlePaste:(n,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const t=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=i==null?void 0:i.mode;if(!t||!s)return!1;const{tr:o}=n.state;return o.replaceSelectionWith(this.type.create({language:s})),o.setSelection(A.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.insertText(t.replace(/\r\n?/g,` `)),o.setMeta("paste",!0),n.dispatch(o),!0}}})]}}),gh=q.create({name:"doc",topNode:!0,content:"block+"});function yh(n={}){return new ae({view(e){return new bh(e,n)}})}class bh{constructor(e,t){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=t.width)!==null&&r!==void 0?r:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,r;if(t){let l=e.nodeBefore,a=e.nodeAfter;if(l||a){let c=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(c){let u=c.getBoundingClientRect(),d=l?u.bottom:u.top;l&&a&&(d=(d+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:u.left,right:u.right,top:d-this.width/2,bottom:d+this.width/2}}}}if(!r){let l=this.editorView.coordsAtPos(this.cursorPos);r={left:l.left-this.width/2,right:l.left+this.width/2,top:l.top,bottom:l.bottom}}let i=this.editorView.dom.offsetParent;this.element||(this.element=i.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let s,o;if(!i||i==document.body&&getComputedStyle(i).position=="static")s=-pageXOffset,o=-pageYOffset;else{let l=i.getBoundingClientRect();s=l.left-i.scrollLeft,o=l.top-i.scrollTop}this.element.style.left=r.left-s+"px",this.element.style.top=r.top-o+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=co(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){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}}const kh=Q.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[yh(this.options)]}});class j extends D{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return j.valid(r)?new j(r):D.near(r)}content(){return M.empty}eq(e){return e instanceof j&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new j(e.resolve(t.pos))}getBookmark(){return new ui(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!xh(e)||!Mh(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&j.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(j.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!T.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(j.valid(l))return l}return null}}}j.prototype.visible=!1;j.findFrom=j.findGapCursorFrom;D.jsonID("gapcursor",j);class ui{constructor(e){this.pos=e}map(e){return new ui(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return j.valid(t)?new j(t):D.near(t)}}function xh(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Mh(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Sh(){return new ae({props:{decorations:Eh,createSelectionBetween(n,e,t){return e.pos==t.pos&&j.valid(t)?new j(t):null},handleClick:Ch,handleKeyDown:wh,handleDOMEvents:{beforeinput:Th}}})}const wh=Yo({ArrowLeft:gn("horiz",-1),ArrowRight:gn("horiz",1),ArrowUp:gn("vert",-1),ArrowDown:gn("vert",1)});function gn(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let c=j.findGapCursorFrom(l,e,a);return c?(i&&i(r.tr.setSelection(new j(c))),!0):!1}}function Ch(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!j.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&T.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new j(r))),!0)}function Th(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof j))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=b.empty;for(let o=r.length-1;o>=0;o--)i=b.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new M(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Eh(n){if(!(n.selection instanceof j))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",W.create(n.doc,[be.widget(n.selection.head,e,{key:"gapcursor"})])}const Oh=Q.create({name:"gapCursor",addProseMirrorPlugins(){return[Sh()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=v(w(n,"allowGapCursor",t)))!==null&&e!==void 0?e:null}}}),Nh=q.create({name:"hardBreak",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",H(this.options.HTMLAttributes,n)]},renderText(){return` `},addCommands(){return{setHardBreak:()=>({commands:n,chain:e,state:t,editor:r})=>n.first([()=>n.exitCode(),()=>n.command(()=>{const{selection:i,storedMarks:s}=t;if(i.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,a=s||i.$to.parentOffset&&i.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:u})=>{if(u&&a&&o){const d=a.filter(f=>l.includes(f.type.name));c.ensureMarks(d)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),Ah=q.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(n=>({tag:`h${n}`,attrs:{level:n}}))},renderHTML({node:n,HTMLAttributes:e}){return[`h${this.options.levels.includes(n.attrs.level)?n.attrs.level:this.options.levels[0]}`,H(this.options.HTMLAttributes,e),0]},addCommands(){return{setHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.setNode(this.name,n):!1,toggleHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.toggleNode(this.name,"paragraph",n):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((n,e)=>({...n,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(n=>jr({find:new RegExp(`^(#{1,${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}});var Pn=200,X=function(){};X.prototype.append=function(e){return e.length?(e=X.from(e),!this.length&&e||e.length=t?X.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};X.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};X.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};X.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};X.from=function(e){return e instanceof X?e:e&&e.length?new fl(e):X.empty};var fl=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Pn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Pn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(X);X.empty=new fl([]);var vh=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(X);const Dh=500;class Oe{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],u=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,u.push(d);return}if(i){u.push(new ve(d.map));let h=d.step.map(i.slice(s)),p;h&&o.maybeStep(h).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new ve(p,void 0,void 0,c.length+u.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,a=new Oe(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;uRh&&(l=Ih(l,c),o-=c),new Oe(l.append(s),o)}remapping(e,t){let r=new At;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new Oe(this.items.append(e.map(t=>new ve(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let a=t;this.items.forEach(f=>{let h=s.getMirror(--a);if(h==null)return;o=Math.min(o,h);let p=s.maps[h];if(f.step){let m=e.steps[h].invert(e.docs[h]),g=f.selection&&f.selection.map(s.slice(a+1,h));g&&l++,r.push(new ve(p,m,g))}else r.push(new ve(p))},i);let c=[];for(let f=t;fDh&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let u=o.selection&&o.selection.map(t.slice(r));u&&s++;let d=new ve(c.invert(),a,u),f,h=i.length-1;(f=i.length&&i[h].merge(d))?i[h]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new Oe(X.from(i.reverse()),s)}}Oe.empty=new Oe(X.empty,0);function Ih(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}class ve{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ve(t.getMap().invert(),t,this.selection)}}}class Ke{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}}const Rh=20;function Lh(n,e,t,r){let i=t.getMeta(et),s;if(i)return i.historyState;t.getMeta(Bh)&&(n=new Ke(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(et))return o.getMeta(et).redo?new Ke(n.done.addTransform(t,void 0,r,xn(e)),n.undone,Os(t.mapping.maps[t.steps.length-1]),n.prevTime,n.prevComposition):new Ke(n.done,n.undone.addTransform(t,void 0,r,xn(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Ph(t,n.prevRanges)),c=o?Mr(n.prevRanges,t.mapping):Os(t.mapping.maps[t.steps.length-1]);return new Ke(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,xn(e)),Oe.empty,c,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Ke(n.done.rebased(t,s),n.undone.rebased(t,s),Mr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ke(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Mr(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Ph(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function Os(n){let e=[];return n.forEach((t,r,i,s)=>e.push(i,s)),e}function Mr(n,e){if(!n)return null;let t=[];for(let r=0;r{let t=et.getState(n);return!t||t.done.eventCount==0?!1:(e&&hl(t,n,e,!1),!0)},ml=(n,e)=>{let t=et.getState(n);return!t||t.undone.eventCount==0?!1:(e&&hl(t,n,e,!0),!0)},Fh=Q.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>pl(n,e),redo:()=>({state:n,dispatch:e})=>ml(n,e)}},addProseMirrorPlugins(){return[zh(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-Z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-Y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Shift-Mod-Z":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Hh=q.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",H(this.options.HTMLAttributes,n)]},addCommands(){return{setHorizontalRule:()=>({chain:n,state:e})=>{const{$to:t}=e.selection,r=n();return t.parentOffset===0?r.insertContentAt(Math.max(t.pos-2,0),{type:this.name}):r.insertContent({type:this.name}),r.command(({tr:i,dispatch:s})=>{var o;if(s){const{$to:l}=i.selection,a=l.end();if(l.nodeAfter)l.nodeAfter.isTextblock?i.setSelection(A.create(i.doc,l.pos+1)):l.nodeAfter.isBlock?i.setSelection(T.create(i.doc,l.pos)):i.setSelection(A.create(i.doc,l.pos));else{const c=(o=l.parent.type.contentMatch.defaultType)===null||o===void 0?void 0:o.create();c&&(i.insert(a,c),i.setSelection(A.create(i.doc,a+1)))}i.scrollIntoView()}return!0}).run()}}},addInputRules(){return[ul({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Vh=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/,$h=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/g,_h=/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/,jh=/(?:^|\s)((?:_)((?:[^_]+))(?:_))/g,Wh=he.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Ft({find:Vh,type:this.type}),Ft({find:_h,type:this.type})]},addPasteRules(){return[xt({find:$h,type:this.type}),xt({find:jh,type:this.type})]}}),Kh=q.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",H(this.options.HTMLAttributes,n),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),Jh=q.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",H(this.options.HTMLAttributes,n),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),As=he.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:n=>n.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["span",H(this.options.HTMLAttributes,n),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:n,commands:e})=>{const t=an(n,this.type);return Object.entries(t).some(([,i])=>!!i)?!0:e.unsetMark(this.name)}}}}),vs=/^(\d+)\.\s$/,qh=q.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:n=>n.hasAttribute("start")?parseInt(n.getAttribute("start")||"",10):1}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:n}){const{start:e,...t}=n;return e===1?["ol",H(this.options.HTMLAttributes,t),0]:["ol",H(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleOrderedList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Jh.name,this.editor.getAttributes(As.name)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=tn({find:vs,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(n=tn({find:vs,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(As.name)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),Uh=q.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Gh=/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/,Yh=/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/g,Xh=he.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["s",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setStrike:()=>({commands:n})=>n.setMark(this.name),toggleStrike:()=>({commands:n})=>n.toggleMark(this.name),unsetStrike:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){const n={};return li()?n["Mod-Shift-s"]=()=>this.editor.commands.toggleStrike():n["Ctrl-Shift-s"]=()=>this.editor.commands.toggleStrike(),n},addInputRules(){return[Ft({find:Gh,type:this.type})]},addPasteRules(){return[xt({find:Yh,type:this.type})]}}),Zh=q.create({name:"text",group:"inline"}),Qh=Q.create({name:"starterKit",addExtensions(){var n,e,t,r,i,s,o,l,a,c,u,d,f,h,p,m,g,y;const S=[];return this.options.blockquote!==!1&&S.push(rh.configure((n=this.options)===null||n===void 0?void 0:n.blockquote)),this.options.bold!==!1&&S.push(ah.configure((e=this.options)===null||e===void 0?void 0:e.bold)),this.options.bulletList!==!1&&S.push(uh.configure((t=this.options)===null||t===void 0?void 0:t.bulletList)),this.options.code!==!1&&S.push(hh.configure((r=this.options)===null||r===void 0?void 0:r.code)),this.options.codeBlock!==!1&&S.push(dl.configure((i=this.options)===null||i===void 0?void 0:i.codeBlock)),this.options.document!==!1&&S.push(gh.configure((s=this.options)===null||s===void 0?void 0:s.document)),this.options.dropcursor!==!1&&S.push(kh.configure((o=this.options)===null||o===void 0?void 0:o.dropcursor)),this.options.gapcursor!==!1&&S.push(Oh.configure((l=this.options)===null||l===void 0?void 0:l.gapcursor)),this.options.hardBreak!==!1&&S.push(Nh.configure((a=this.options)===null||a===void 0?void 0:a.hardBreak)),this.options.heading!==!1&&S.push(Ah.configure((c=this.options)===null||c===void 0?void 0:c.heading)),this.options.history!==!1&&S.push(Fh.configure((u=this.options)===null||u===void 0?void 0:u.history)),this.options.horizontalRule!==!1&&S.push(Hh.configure((d=this.options)===null||d===void 0?void 0:d.horizontalRule)),this.options.italic!==!1&&S.push(Wh.configure((f=this.options)===null||f===void 0?void 0:f.italic)),this.options.listItem!==!1&&S.push(Kh.configure((h=this.options)===null||h===void 0?void 0:h.listItem)),this.options.orderedList!==!1&&S.push(qh.configure((p=this.options)===null||p===void 0?void 0:p.orderedList)),this.options.paragraph!==!1&&S.push(Uh.configure((m=this.options)===null||m===void 0?void 0:m.paragraph)),this.options.strike!==!1&&S.push(Xh.configure((g=this.options)===null||g===void 0?void 0:g.strike)),this.options.text!==!1&&S.push(Zh.configure((y=this.options)===null||y===void 0?void 0:y.text)),S}}),ep=he.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["u",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setUnderline:()=>({commands:n})=>n.setMark(this.name),toggleUnderline:()=>({commands:n})=>n.toggleMark(this.name),unsetUnderline:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function tp(n){return new ae({key:new Se("autolink"),appendTransaction:(e,t,r)=>{const i=e.some(c=>c.docChanged)&&!t.doc.eq(r.doc),s=e.some(c=>c.getMeta("preventAutolink"));if(!i||s)return;const{tr:o}=r,l=sf(t.doc,[...e]);if(pf(l).forEach(({newRange:c})=>{const u=lf(r.doc,c,h=>h.isTextblock);let d,f;if(u.length>1?(d=u[0],f=r.doc.textBetween(d.pos,d.pos+d.node.nodeSize,void 0," ")):u.length&&r.doc.textBetween(c.from,c.to," "," ").endsWith(" ")&&(d=u[0],f=r.doc.textBetween(d.pos,c.to,void 0," ")),d&&f){const h=f.split(" ").filter(g=>g!=="");if(h.length<=0)return!1;const p=h[h.length-1],m=d.pos+f.lastIndexOf(p);if(!p)return!1;Wr(p).filter(g=>g.isLink).map(g=>({...g,from:m+g.start+1,to:m+g.end+1})).filter(g=>r.schema.marks.code?!r.doc.rangeHasMark(g.from,g.to,r.schema.marks.code):!0).filter(g=>n.validate?n.validate(g.value):!0).forEach(g=>{ci(g.from,g.to,r.doc).some(y=>y.mark.type===n.type)||o.addMark(g.from,g.to,n.type.create({href:g.href}))})}}),!!o.steps.length)return o}})}function np(n){return new ae({key:new Se("handleClickLink"),props:{handleClick:(e,t,r)=>{var i,s;if(r.button!==0||r.target.nodeName!=="A")return!1;const l=cl(e.state,n.type.name),a=r.target,c=(i=a==null?void 0:a.href)!==null&&i!==void 0?i:l.href,u=(s=a==null?void 0:a.target)!==null&&s!==void 0?s:l.target;return a&&c?(e.editable&&window.open(c,u),!0):!1}}})}function rp(n){return new ae({key:new Se("handlePasteLink"),props:{handlePaste:(e,t,r)=>{var i;const{state:s}=e,{selection:o}=s,{empty:l}=o;if(l)return!1;let a="";r.content.forEach(p=>{a+=p.textContent});const c=Wr(a).find(p=>p.isLink&&p.value===a);if(!a||!c)return!1;const u=(i=t.clipboardData)===null||i===void 0?void 0:i.getData("text/html"),d=/href="([^"]*)"/,f=u==null?void 0:u.match(d),h=f?f[1]:c.href;return n.editor.commands.setMark(n.type,{href:h}),!0}}})}const ip=he.create({name:"link",priority:1e3,keepOnSplit:!1,onCreate(){this.options.protocols.forEach(n=>{if(typeof n=="string"){Mi(n);return}Mi(n.scheme,n.optionalSlashes)})},onDestroy(){Vl()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,linkOnPaste:!0,autolink:!0,protocols:[],HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},validate:void 0}},addAttributes(){return{href:{default:null},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:'a[href]:not([href *= "javascript:" i])'}]},renderHTML({HTMLAttributes:n}){return["a",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setLink:n=>({chain:e})=>e().setMark(this.name,n).setMeta("preventAutolink",!0).run(),toggleLink:n=>({chain:e})=>e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run(),unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[xt({find:n=>Wr(n).filter(e=>this.options.validate?this.options.validate(e.value):!0).filter(e=>e.isLink).map(e=>({text:e.value,index:e.start,data:e})),type:this.type,getAttributes:(n,e)=>{var t,r;const i=(t=e==null?void 0:e.clipboardData)===null||t===void 0?void 0:t.getData("text/html"),s=/href="([^"]*)"/,o=i==null?void 0:i.match(s);return o?{href:o[1]}:{href:(r=n.data)===null||r===void 0?void 0:r.href}}})]},addProseMirrorPlugins(){const n=[];return this.options.autolink&&n.push(tp({type:this.type,validate:this.options.validate})),this.options.openOnClick&&n.push(np({type:this.type})),this.options.linkOnPaste&&n.push(rp({editor:this.editor,type:this.type})),n}}),sp=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,op=q.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{}}},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}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:n}){return["img",H(this.options.HTMLAttributes,n)]},addCommands(){return{setImage:n=>({commands:e})=>e.insertContent({type:this.name,attrs:n})}},addInputRules(){return[ul({find:sp,type:this.type,getAttributes:n=>{const[,,e,t,r]=n;return{src:t,alt:e,title:r}}})]}}),lp=he.create({name:"superscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sup"},{style:"vertical-align",getAttrs(n){return n!=="super"?!1:null}}]},renderHTML({HTMLAttributes:n}){return["sup",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setSuperscript:()=>({commands:n})=>n.setMark(this.name),toggleSuperscript:()=>({commands:n})=>n.toggleMark(this.name),unsetSuperscript:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-.":()=>this.editor.commands.toggleSuperscript()}}}),ap=he.create({name:"subscript",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"sub"},{style:"vertical-align",getAttrs(n){return n!=="sub"?!1:null}}]},renderHTML({HTMLAttributes:n}){return["sub",H(this.options.HTMLAttributes,n),0]},addCommands(){return{setSubscript:()=>({commands:n})=>n.setMark(this.name),toggleSubscript:()=>({commands:n})=>n.toggleMark(this.name),unsetSubscript:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-,":()=>this.editor.commands.toggleSubscript()}}}),cp=he.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:n=>n.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["span",H(this.options.HTMLAttributes,n),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:n,commands:e})=>{const t=an(n,this.type);return Object.entries(t).some(([,i])=>!!i)?!0:e.unsetMark(this.name)}}}}),up=Q.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:n=>{var e;return(e=n.style.color)===null||e===void 0?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.color?{style:`color: ${n.color}`}:{}}}}]},addCommands(){return{setColor:n=>({chain:e})=>e().setMark("textStyle",{color:n}).run(),unsetColor:()=>({chain:n})=>n().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),dp=Q.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:"left"}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:n=>n.style.textAlign||this.options.defaultAlignment,renderHTML:n=>n.textAlign===this.options.defaultAlignment?{}:{style:`text-align: ${n.textAlign}`}}}}]},addCommands(){return{setTextAlign:n=>({commands:e})=>this.options.alignments.includes(n)?this.options.types.every(t=>e.updateAttributes(t,{textAlign:n})):!1,unsetTextAlign:()=>({commands:n})=>this.options.types.every(e=>n.resetAttributes(e,"textAlign"))}},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")}}});var di={exports:{}};function fi(n){return n instanceof Map?n.clear=n.delete=n.set=function(){throw new Error("map is read-only")}:n instanceof Set&&(n.add=n.clear=n.delete=function(){throw new Error("set is read-only")}),Object.freeze(n),Object.getOwnPropertyNames(n).forEach(function(e){var t=n[e];typeof t=="object"&&!Object.isFrozen(t)&&fi(t)}),n}di.exports=fi;di.exports.default=fi;class Ds{constructor(e){e.data===void 0&&(e.data={}),this.data=e.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function gl(n){return n.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function Ye(n,...e){const t=Object.create(null);for(const r in n)t[r]=n[r];return e.forEach(function(r){for(const i in r)t[i]=r[i]}),t}const fp="",Is=n=>!!n.scope||n.sublanguage&&n.language,hp=(n,{prefix:e})=>{if(n.includes(".")){const t=n.split(".");return[`${e}${t.shift()}`,...t.map((r,i)=>`${r}${"_".repeat(i+1)}`)].join(" ")}return`${e}${n}`};class pp{constructor(e,t){this.buffer="",this.classPrefix=t.classPrefix,e.walk(this)}addText(e){this.buffer+=gl(e)}openNode(e){if(!Is(e))return;let t="";e.sublanguage?t=`language-${e.language}`:t=hp(e.scope,{prefix:this.classPrefix}),this.span(t)}closeNode(e){Is(e)&&(this.buffer+=fp)}value(){return this.buffer}span(e){this.buffer+=``}}const Rs=(n={})=>{const e={children:[]};return Object.assign(e,n),e};class hi{constructor(){this.rootNode=Rs(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){const t=Rs({scope:e});this.add(t),this.stack.push(t)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,t){return typeof t=="string"?e.addText(t):t.children&&(e.openNode(t),t.children.forEach(r=>this._walk(e,r)),e.closeNode(t)),e}static _collapse(e){typeof e!="string"&&e.children&&(e.children.every(t=>typeof t=="string")?e.children=[e.children.join("")]:e.children.forEach(t=>{hi._collapse(t)}))}}class mp extends hi{constructor(e){super(),this.options=e}addKeyword(e,t){e!==""&&(this.openNode(t),this.addText(e),this.closeNode())}addText(e){e!==""&&this.add(e)}addSublanguage(e,t){const r=e.root;r.sublanguage=!0,r.language=t,this.add(r)}toHTML(){return new pp(this,this.options).value()}finalize(){return!0}}function nn(n){return n?typeof n=="string"?n:n.source:null}function yl(n){return Mt("(?=",n,")")}function gp(n){return Mt("(?:",n,")*")}function yp(n){return Mt("(?:",n,")?")}function Mt(...n){return n.map(t=>nn(t)).join("")}function bp(n){const e=n[n.length-1];return typeof e=="object"&&e.constructor===Object?(n.splice(n.length-1,1),e):{}}function pi(...n){return"("+(bp(n).capture?"":"?:")+n.map(r=>nn(r)).join("|")+")"}function bl(n){return new RegExp(n.toString()+"|").exec("").length-1}function kp(n,e){const t=n&&n.exec(e);return t&&t.index===0}const xp=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;function mi(n,{joinWith:e}){let t=0;return n.map(r=>{t+=1;const i=t;let s=nn(r),o="";for(;s.length>0;){const l=xp.exec(s);if(!l){o+=s;break}o+=s.substring(0,l.index),s=s.substring(l.index+l[0].length),l[0][0]==="\\"&&l[1]?o+="\\"+String(Number(l[1])+i):(o+=l[0],l[0]==="("&&t++)}return o}).map(r=>`(${r})`).join(e)}const Mp=/\b\B/,kl="[a-zA-Z]\\w*",gi="[a-zA-Z_]\\w*",xl="\\b\\d+(\\.\\d+)?",Ml="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",Sl="\\b(0b[01]+)",Sp="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",wp=(n={})=>{const e=/^#![ ]*\//;return n.binary&&(n.begin=Mt(e,/.*\b/,n.binary,/\b.*/)),Ye({scope:"meta",begin:e,end:/$/,relevance:0,"on:begin":(t,r)=>{t.index!==0&&r.ignoreMatch()}},n)},rn={begin:"\\\\[\\s\\S]",relevance:0},Cp={scope:"string",begin:"'",end:"'",illegal:"\\n",contains:[rn]},Tp={scope:"string",begin:'"',end:'"',illegal:"\\n",contains:[rn]},Ep={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},Gn=function(n,e,t={}){const r=Ye({scope:"comment",begin:n,end:e,contains:[]},t);r.contains.push({scope:"doctag",begin:"[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});const i=pi("I","a","is","so","us","to","at","if","in","it","on",/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return r.contains.push({begin:Mt(/[ ]+/,"(",i,/[.]?[:]?([.][ ]|[ ])/,"){3}")}),r},Op=Gn("//","$"),Np=Gn("/\\*","\\*/"),Ap=Gn("#","$"),vp={scope:"number",begin:xl,relevance:0},Dp={scope:"number",begin:Ml,relevance:0},Ip={scope:"number",begin:Sl,relevance:0},Rp={begin:/(?=\/[^/\n]*\/)/,contains:[{scope:"regexp",begin:/\//,end:/\/[gimuy]*/,illegal:/\n/,contains:[rn,{begin:/\[/,end:/\]/,relevance:0,contains:[rn]}]}]},Lp={scope:"title",begin:kl,relevance:0},Pp={scope:"title",begin:gi,relevance:0},Bp={begin:"\\.\\s*"+gi,relevance:0},zp=function(n){return Object.assign(n,{"on:begin":(e,t)=>{t.data._beginMatch=e[1]},"on:end":(e,t)=>{t.data._beginMatch!==e[1]&&t.ignoreMatch()}})};var yn=Object.freeze({__proto__:null,MATCH_NOTHING_RE:Mp,IDENT_RE:kl,UNDERSCORE_IDENT_RE:gi,NUMBER_RE:xl,C_NUMBER_RE:Ml,BINARY_NUMBER_RE:Sl,RE_STARTERS_RE:Sp,SHEBANG:wp,BACKSLASH_ESCAPE:rn,APOS_STRING_MODE:Cp,QUOTE_STRING_MODE:Tp,PHRASAL_WORDS_MODE:Ep,COMMENT:Gn,C_LINE_COMMENT_MODE:Op,C_BLOCK_COMMENT_MODE:Np,HASH_COMMENT_MODE:Ap,NUMBER_MODE:vp,C_NUMBER_MODE:Dp,BINARY_NUMBER_MODE:Ip,REGEXP_MODE:Rp,TITLE_MODE:Lp,UNDERSCORE_TITLE_MODE:Pp,METHOD_GUARD:Bp,END_SAME_AS_BEGIN:zp});function Fp(n,e){n.input[n.index-1]==="."&&e.ignoreMatch()}function Hp(n,e){n.className!==void 0&&(n.scope=n.className,delete n.className)}function Vp(n,e){e&&n.beginKeywords&&(n.begin="\\b("+n.beginKeywords.split(" ").join("|")+")(?!\\.)(?=\\b|\\s)",n.__beforeBegin=Fp,n.keywords=n.keywords||n.beginKeywords,delete n.beginKeywords,n.relevance===void 0&&(n.relevance=0))}function $p(n,e){Array.isArray(n.illegal)&&(n.illegal=pi(...n.illegal))}function _p(n,e){if(n.match){if(n.begin||n.end)throw new Error("begin & end are not supported with match");n.begin=n.match,delete n.match}}function jp(n,e){n.relevance===void 0&&(n.relevance=1)}const Wp=(n,e)=>{if(!n.beforeMatch)return;if(n.starts)throw new Error("beforeMatch cannot be used with starts");const t=Object.assign({},n);Object.keys(n).forEach(r=>{delete n[r]}),n.keywords=t.keywords,n.begin=Mt(t.beforeMatch,yl(t.begin)),n.starts={relevance:0,contains:[Object.assign(t,{endsParent:!0})]},n.relevance=0,delete t.beforeMatch},Kp=["of","and","for","in","not","or","if","then","parent","list","value"],Jp="keyword";function wl(n,e,t=Jp){const r=Object.create(null);return typeof n=="string"?i(t,n.split(" ")):Array.isArray(n)?i(t,n):Object.keys(n).forEach(function(s){Object.assign(r,wl(n[s],e,s))}),r;function i(s,o){e&&(o=o.map(l=>l.toLowerCase())),o.forEach(function(l){const a=l.split("|");r[a[0]]=[s,qp(a[0],a[1])]})}}function qp(n,e){return e?Number(e):Up(n)?0:1}function Up(n){return Kp.includes(n.toLowerCase())}const Ls={},gt=n=>{console.error(n)},Ps=(n,...e)=>{console.log(`WARN: ${n}`,...e)},Ct=(n,e)=>{Ls[`${n}/${e}`]||(console.log(`Deprecated as of ${n}. ${e}`),Ls[`${n}/${e}`]=!0)},Bn=new Error;function Cl(n,e,{key:t}){let r=0;const i=n[t],s={},o={};for(let l=1;l<=e.length;l++)o[l+r]=i[l],s[l+r]=!0,r+=bl(e[l-1]);n[t]=o,n[t]._emit=s,n[t]._multi=!0}function Gp(n){if(Array.isArray(n.begin)){if(n.skip||n.excludeBegin||n.returnBegin)throw gt("skip, excludeBegin, returnBegin not compatible with beginScope: {}"),Bn;if(typeof n.beginScope!="object"||n.beginScope===null)throw gt("beginScope must be object"),Bn;Cl(n,n.begin,{key:"beginScope"}),n.begin=mi(n.begin,{joinWith:""})}}function Yp(n){if(Array.isArray(n.end)){if(n.skip||n.excludeEnd||n.returnEnd)throw gt("skip, excludeEnd, returnEnd not compatible with endScope: {}"),Bn;if(typeof n.endScope!="object"||n.endScope===null)throw gt("endScope must be object"),Bn;Cl(n,n.end,{key:"endScope"}),n.end=mi(n.end,{joinWith:""})}}function Xp(n){n.scope&&typeof n.scope=="object"&&n.scope!==null&&(n.beginScope=n.scope,delete n.scope)}function Zp(n){Xp(n),typeof n.beginScope=="string"&&(n.beginScope={_wrap:n.beginScope}),typeof n.endScope=="string"&&(n.endScope={_wrap:n.endScope}),Gp(n),Yp(n)}function Qp(n){function e(o,l){return new RegExp(nn(o),"m"+(n.case_insensitive?"i":"")+(n.unicodeRegex?"u":"")+(l?"g":""))}class t{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(l,a){a.position=this.position++,this.matchIndexes[this.matchAt]=a,this.regexes.push([a,l]),this.matchAt+=bl(l)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);const l=this.regexes.map(a=>a[1]);this.matcherRe=e(mi(l,{joinWith:"|"}),!0),this.lastIndex=0}exec(l){this.matcherRe.lastIndex=this.lastIndex;const a=this.matcherRe.exec(l);if(!a)return null;const c=a.findIndex((d,f)=>f>0&&d!==void 0),u=this.matchIndexes[c];return a.splice(0,c),Object.assign(a,u)}}class r{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(l){if(this.multiRegexes[l])return this.multiRegexes[l];const a=new t;return this.rules.slice(l).forEach(([c,u])=>a.addRule(c,u)),a.compile(),this.multiRegexes[l]=a,a}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(l,a){this.rules.push([l,a]),a.type==="begin"&&this.count++}exec(l){const a=this.getMatcher(this.regexIndex);a.lastIndex=this.lastIndex;let c=a.exec(l);if(this.resumingScanAtSamePosition()&&!(c&&c.index===this.lastIndex)){const u=this.getMatcher(0);u.lastIndex=this.lastIndex+1,c=u.exec(l)}return c&&(this.regexIndex+=c.position+1,this.regexIndex===this.count&&this.considerAll()),c}}function i(o){const l=new r;return o.contains.forEach(a=>l.addRule(a.begin,{rule:a,type:"begin"})),o.terminatorEnd&&l.addRule(o.terminatorEnd,{type:"end"}),o.illegal&&l.addRule(o.illegal,{type:"illegal"}),l}function s(o,l){const a=o;if(o.isCompiled)return a;[Hp,_p,Zp,Wp].forEach(u=>u(o,l)),n.compilerExtensions.forEach(u=>u(o,l)),o.__beforeBegin=null,[Vp,$p,jp].forEach(u=>u(o,l)),o.isCompiled=!0;let c=null;return typeof o.keywords=="object"&&o.keywords.$pattern&&(o.keywords=Object.assign({},o.keywords),c=o.keywords.$pattern,delete o.keywords.$pattern),c=c||/\w+/,o.keywords&&(o.keywords=wl(o.keywords,n.case_insensitive)),a.keywordPatternRe=e(c,!0),l&&(o.begin||(o.begin=/\B|\b/),a.beginRe=e(a.begin),!o.end&&!o.endsWithParent&&(o.end=/\B|\b/),o.end&&(a.endRe=e(a.end)),a.terminatorEnd=nn(a.end)||"",o.endsWithParent&&l.terminatorEnd&&(a.terminatorEnd+=(o.end?"|":"")+l.terminatorEnd)),o.illegal&&(a.illegalRe=e(o.illegal)),o.contains||(o.contains=[]),o.contains=[].concat(...o.contains.map(function(u){return em(u==="self"?o:u)})),o.contains.forEach(function(u){s(u,a)}),o.starts&&s(o.starts,l),a.matcher=i(a),a}if(n.compilerExtensions||(n.compilerExtensions=[]),n.contains&&n.contains.includes("self"))throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return n.classNameAliases=Ye(n.classNameAliases||{}),s(n)}function Tl(n){return n?n.endsWithParent||Tl(n.starts):!1}function em(n){return n.variants&&!n.cachedVariants&&(n.cachedVariants=n.variants.map(function(e){return Ye(n,{variants:null},e)})),n.cachedVariants?n.cachedVariants:Tl(n)?Ye(n,{starts:n.starts?Ye(n.starts):null}):Object.isFrozen(n)?Ye(n):n}var tm="11.6.0";class nm extends Error{constructor(e,t){super(e),this.name="HTMLInjectionError",this.html=t}}const wr=gl,Bs=Ye,zs=Symbol("nomatch"),rm=7,im=function(n){const e=Object.create(null),t=Object.create(null),r=[];let i=!0;const s="Could not find the language '{}', did you forget to load/include a language module?",o={disableAutodetect:!0,name:"Plain text",contains:[]};let l={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",cssSelector:"pre code",languages:null,__emitter:mp};function a(k){return l.noHighlightRe.test(k)}function c(k){let E=k.className+" ";E+=k.parentNode?k.parentNode.className:"";const L=l.languageDetectRe.exec(E);if(L){const $=O(L[1]);return $||(Ps(s.replace("{}",L[1])),Ps("Falling back to no-highlight mode for this block.",k)),$?L[1]:"no-highlight"}return E.split(/\s+/).find($=>a($)||O($))}function u(k,E,L){let $="",J="";typeof E=="object"?($=k,L=E.ignoreIllegals,J=E.language):(Ct("10.7.0","highlight(lang, code, ...args) has been deprecated."),Ct("10.7.0",`Please use highlight(code, options) instead. https://github.com/highlightjs/highlight.js/issues/2277`),J=k,$=E),L===void 0&&(L=!0);const Te={code:$,language:J};cn("before:highlight",Te);const Ve=Te.result?Te.result:d(Te.language,Te.code,L);return Ve.code=Te.code,cn("after:highlight",Ve),Ve}function d(k,E,L,$){const J=Object.create(null);function Te(x,C){return x.keywords[C]}function Ve(){if(!N.keywords){U.addText(_);return}let x=0;N.keywordPatternRe.lastIndex=0;let C=N.keywordPatternRe.exec(_),I="";for(;C;){I+=_.substring(x,C.index);const z=_e.case_insensitive?C[0].toLowerCase():C[0],ie=Te(N,z);if(ie){const[Be,Ll]=ie;if(U.addText(I),I="",J[z]=(J[z]||0)+1,J[z]<=rm&&(fn+=Ll),Be.startsWith("_"))I+=C[0];else{const Pl=_e.classNameAliases[Be]||Be;U.addKeyword(C[0],Pl)}}else I+=C[0];x=N.keywordPatternRe.lastIndex,C=N.keywordPatternRe.exec(_)}I+=_.substring(x),U.addText(I)}function un(){if(_==="")return;let x=null;if(typeof N.subLanguage=="string"){if(!e[N.subLanguage]){U.addText(_);return}x=d(N.subLanguage,_,!0,xi[N.subLanguage]),xi[N.subLanguage]=x._top}else x=h(_,N.subLanguage.length?N.subLanguage:null);N.relevance>0&&(fn+=x.relevance),U.addSublanguage(x._emitter,x.language)}function me(){N.subLanguage!=null?un():Ve(),_=""}function $e(x,C){let I=1;const z=C.length-1;for(;I<=z;){if(!x._emit[I]){I++;continue}const ie=_e.classNameAliases[x[I]]||x[I],Be=C[I];ie?U.addKeyword(Be,ie):(_=Be,Ve(),_=""),I++}}function yi(x,C){return x.scope&&typeof x.scope=="string"&&U.openNode(_e.classNameAliases[x.scope]||x.scope),x.beginScope&&(x.beginScope._wrap?(U.addKeyword(_,_e.classNameAliases[x.beginScope._wrap]||x.beginScope._wrap),_=""):x.beginScope._multi&&($e(x.beginScope,C),_="")),N=Object.create(x,{parent:{value:N}}),N}function bi(x,C,I){let z=kp(x.endRe,I);if(z){if(x["on:end"]){const ie=new Ds(x);x["on:end"](C,ie),ie.isMatchIgnored&&(z=!1)}if(z){for(;x.endsParent&&x.parent;)x=x.parent;return x}}if(x.endsWithParent)return bi(x.parent,C,I)}function Al(x){return N.matcher.regexIndex===0?(_+=x[0],1):(Qn=!0,0)}function vl(x){const C=x[0],I=x.rule,z=new Ds(I),ie=[I.__beforeBegin,I["on:begin"]];for(const Be of ie)if(Be&&(Be(x,z),z.isMatchIgnored))return Al(C);return I.skip?_+=C:(I.excludeBegin&&(_+=C),me(),!I.returnBegin&&!I.excludeBegin&&(_=C)),yi(I,x),I.returnBegin?0:C.length}function Dl(x){const C=x[0],I=E.substring(x.index),z=bi(N,x,I);if(!z)return zs;const ie=N;N.endScope&&N.endScope._wrap?(me(),U.addKeyword(C,N.endScope._wrap)):N.endScope&&N.endScope._multi?(me(),$e(N.endScope,x)):ie.skip?_+=C:(ie.returnEnd||ie.excludeEnd||(_+=C),me(),ie.excludeEnd&&(_=C));do N.scope&&U.closeNode(),!N.skip&&!N.subLanguage&&(fn+=N.relevance),N=N.parent;while(N!==z.parent);return z.starts&&yi(z.starts,x),ie.returnEnd?0:C.length}function Il(){const x=[];for(let C=N;C!==_e;C=C.parent)C.scope&&x.unshift(C.scope);x.forEach(C=>U.openNode(C))}let dn={};function ki(x,C){const I=C&&C[0];if(_+=x,I==null)return me(),0;if(dn.type==="begin"&&C.type==="end"&&dn.index===C.index&&I===""){if(_+=E.slice(C.index,C.index+1),!i){const z=new Error(`0 width match regex (${k})`);throw z.languageName=k,z.badRule=dn.rule,z}return 1}if(dn=C,C.type==="begin")return vl(C);if(C.type==="illegal"&&!L){const z=new Error('Illegal lexeme "'+I+'" for mode "'+(N.scope||"")+'"');throw z.mode=N,z}else if(C.type==="end"){const z=Dl(C);if(z!==zs)return z}if(C.type==="illegal"&&I==="")return 1;if(Zn>1e5&&Zn>C.index*3)throw new Error("potential infinite loop, way more iterations than matches");return _+=I,I.length}const _e=O(k);if(!_e)throw gt(s.replace("{}",k)),new Error('Unknown language: "'+k+'"');const Rl=Qp(_e);let Xn="",N=$||Rl;const xi={},U=new l.__emitter(l);Il();let _="",fn=0,ot=0,Zn=0,Qn=!1;try{for(N.matcher.considerAll();;){Zn++,Qn?Qn=!1:N.matcher.considerAll(),N.matcher.lastIndex=ot;const x=N.matcher.exec(E);if(!x)break;const C=E.substring(ot,x.index),I=ki(C,x);ot=x.index+I}return ki(E.substring(ot)),U.closeAllNodes(),U.finalize(),Xn=U.toHTML(),{language:k,value:Xn,relevance:fn,illegal:!1,_emitter:U,_top:N}}catch(x){if(x.message&&x.message.includes("Illegal"))return{language:k,value:wr(E),illegal:!0,relevance:0,_illegalBy:{message:x.message,index:ot,context:E.slice(ot-100,ot+100),mode:x.mode,resultSoFar:Xn},_emitter:U};if(i)return{language:k,value:wr(E),illegal:!1,relevance:0,errorRaised:x,_emitter:U,_top:N};throw x}}function f(k){const E={value:wr(k),illegal:!1,relevance:0,_top:o,_emitter:new l.__emitter(l)};return E._emitter.addText(k),E}function h(k,E){E=E||l.languages||Object.keys(e);const L=f(k),$=E.filter(O).filter(st).map(me=>d(me,k,!1));$.unshift(L);const J=$.sort((me,$e)=>{if(me.relevance!==$e.relevance)return $e.relevance-me.relevance;if(me.language&&$e.language){if(O(me.language).supersetOf===$e.language)return 1;if(O($e.language).supersetOf===me.language)return-1}return 0}),[Te,Ve]=J,un=Te;return un.secondBest=Ve,un}function p(k,E,L){const $=E&&t[E]||L;k.classList.add("hljs"),k.classList.add(`language-${$}`)}function m(k){let E=null;const L=c(k);if(a(L))return;if(cn("before:highlightElement",{el:k,language:L}),k.children.length>0&&(l.ignoreUnescapedHTML||(console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."),console.warn("https://github.com/highlightjs/highlight.js/wiki/security"),console.warn("The element with unescaped HTML:"),console.warn(k)),l.throwUnescapedHTML))throw new nm("One of your code blocks includes unescaped HTML.",k.innerHTML);E=k;const $=E.textContent,J=L?u($,{language:L,ignoreIllegals:!0}):h($);k.innerHTML=J.value,p(k,L,J.language),k.result={language:J.language,re:J.relevance,relevance:J.relevance},J.secondBest&&(k.secondBest={language:J.secondBest.language,relevance:J.secondBest.relevance}),cn("after:highlightElement",{el:k,result:J,text:$})}function g(k){l=Bs(l,k)}const y=()=>{P(),Ct("10.6.0","initHighlighting() deprecated. Use highlightAll() now.")};function S(){P(),Ct("10.6.0","initHighlightingOnLoad() deprecated. Use highlightAll() now.")}let R=!1;function P(){if(document.readyState==="loading"){R=!0;return}document.querySelectorAll(l.cssSelector).forEach(m)}function V(){R&&P()}typeof window<"u"&&window.addEventListener&&window.addEventListener("DOMContentLoaded",V,!1);function B(k,E){let L=null;try{L=E(n)}catch($){if(gt("Language definition for '{}' could not be registered.".replace("{}",k)),i)gt($);else throw $;L=o}L.name||(L.name=k),e[k]=L,L.rawDefinition=E.bind(null,n),L.aliases&&Ce(L.aliases,{languageName:k})}function re(k){delete e[k];for(const E of Object.keys(t))t[E]===k&&delete t[E]}function Ae(){return Object.keys(e)}function O(k){return k=(k||"").toLowerCase(),e[k]||e[t[k]]}function Ce(k,{languageName:E}){typeof k=="string"&&(k=[k]),k.forEach(L=>{t[L.toLowerCase()]=E})}function st(k){const E=O(k);return E&&!E.disableAutodetect}function Yn(k){k["before:highlightBlock"]&&!k["before:highlightElement"]&&(k["before:highlightElement"]=E=>{k["before:highlightBlock"](Object.assign({block:E.el},E))}),k["after:highlightBlock"]&&!k["after:highlightElement"]&&(k["after:highlightElement"]=E=>{k["after:highlightBlock"](Object.assign({block:E.el},E))})}function Ol(k){Yn(k),r.push(k)}function cn(k,E){const L=k;r.forEach(function($){$[L]&&$[L](E)})}function Nl(k){return Ct("10.7.0","highlightBlock will be removed entirely in v12.0"),Ct("10.7.0","Please use highlightElement now."),m(k)}Object.assign(n,{highlight:u,highlightAuto:h,highlightAll:P,highlightElement:m,highlightBlock:Nl,configure:g,initHighlighting:y,initHighlightingOnLoad:S,registerLanguage:B,unregisterLanguage:re,listLanguages:Ae,getLanguage:O,registerAliases:Ce,autoDetection:st,inherit:Bs,addPlugin:Ol}),n.debugMode=function(){i=!1},n.safeMode=function(){i=!0},n.versionString=tm,n.regex={concat:Mt,lookahead:yl,either:pi,optional:yp,anyNumberOfTimes:gp};for(const k in yn)typeof yn[k]=="object"&&di.exports(yn[k]);return Object.assign(n,yn),n};var sn=im({}),sm=sn;sn.HighlightJS=sn;sn.default=sn;var om=sm;function El(n,e=[]){return n.map(t=>{const r=[...e,...t.properties?t.properties.className:[]];return t.children?El(t.children,r):{text:t.value,classes:r}}).flat()}function Fs(n){return n.value||n.children||[]}function lm(n){return!!om.getLanguage(n)}function Hs({doc:n,name:e,lowlight:t,defaultLanguage:r}){const i=[];return $r(n,s=>s.type.name===e).forEach(s=>{let o=s.pos+1;const l=s.node.attrs.language||r,a=t.listLanguages(),c=l&&(a.includes(l)||lm(l))?Fs(t.highlight(l,s.node.textContent)):Fs(t.highlightAuto(s.node.textContent));El(c).forEach(u=>{const d=o+u.text.length;if(u.classes.length){const f=be.inline(o,d,{class:u.classes.join(" ")});i.push(f)}o=d})}),W.create(n,i)}function am(n){return typeof n=="function"}function cm({name:n,lowlight:e,defaultLanguage:t}){if(!["highlight","highlightAuto","listLanguages"].every(i=>am(e[i])))throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");const r=new ae({key:new Se("lowlight"),state:{init:(i,{doc:s})=>Hs({doc:s,name:n,lowlight:e,defaultLanguage:t}),apply:(i,s,o,l)=>{const a=o.selection.$head.parent.type.name,c=l.selection.$head.parent.type.name,u=$r(o.doc,f=>f.type.name===n),d=$r(l.doc,f=>f.type.name===n);return i.docChanged&&([a,c].includes(n)||d.length!==u.length||i.steps.some(f=>f.from!==void 0&&f.to!==void 0&&u.some(h=>h.pos>=f.from&&h.pos+h.node.nodeSize<=f.to)))?Hs({doc:i.doc,name:n,lowlight:e,defaultLanguage:t}):s.map(i.mapping,i.doc)}},props:{decorations(i){return r.getState(i)}}});return r}const um=dl.extend({addOptions(){var n;return{...(n=this.parent)===null||n===void 0?void 0:n.call(this),lowlight:{},defaultLanguage:null}},addProseMirrorPlugins(){var n;return[...((n=this.parent)===null||n===void 0?void 0:n.call(this))||[],cm({name:this.name,lowlight:this.options.lowlight,defaultLanguage:this.options.defaultLanguage})]}}),dm=Q.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:n=>n.style.backgroundColor.replace(/['"]+/g,""),renderHTML:n=>n.backgroundColor?{style:`background-color: ${n.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:n=>({chain:e})=>e().setMark("textStyle",{backgroundColor:n}).run(),unsetBackgroundColor:()=>({chain:n})=>n().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),fm=Q.create({name:"indent",addOptions:()=>({types:["listItem","paragraph"],minLevel:0,maxLevel:6}),addGlobalAttributes(){return[{types:this.options.types,attributes:{indent:{renderHTML:n=>(n==null?void 0:n.indent)>this.options.minLevel?{"data-indent":n.indent}:null,parseHTML:n=>{const e=Number(n.getAttribute("data-indent"));return e&&e>this.options.minLevel?e:null}}}}]},addCommands(){const n=(r,i,s)=>{var l;const o=(l=r==null?void 0:r.doc)==null?void 0:l.nodeAt(i);if(o){const a=(o.attrs.indent||0)+s,{minLevel:c,maxLevel:u}=this.options,d=au?u:a;if(d!==o.attrs.indent){const{indent:f,...h}=o.attrs,p=d>c?{...h,indent:d}:h;return r.setNodeMarkup(i,o.type,p,o.marks)}}return r},e=(r,i)=>{const{doc:s,selection:o}=r;if(s&&o&&(o instanceof A||o instanceof xe)){const{from:l,to:a}=o;s.nodesBetween(l,a,(c,u)=>this.options.types.includes(c.type.name)?(r=n(r,u,i),!1):!0)}return r},t=r=>()=>({tr:i,state:s,dispatch:o})=>{const{selection:l}=s;return i=i.setSelection(l),i=e(i,r),i.docChanged?(o==null||o(i),!0):!1};return{indent:t(1),outdent:t(-1)}},addKeyboardShortcuts(){return{Tab:({editor:n})=>n.state.selection.to>n.state.selection.from?this.editor.commands.indent():!1,"Shift-Tab":({editor:n})=>n.state.selection.to>n.state.selection.from?this.editor.commands.outdent():!1}}}),hm=q.create({name:"embed",group:"block",atom:!0,addAttributes(){return{allowfullscreen:{default:null},allow:{default:"autoplay; fullscreen; picture-in-picture"},src:{default:null}}},parseHTML(){return[{tag:"iframe"}]},renderHTML({HTMLAttributes:n}){return["iframe",H(this.options.HTMLAttributes,n)]},addCommands(){return{setEmbed:n=>({commands:e})=>e.insertContent({type:this.name,attrs:n})}}}),Vs={},pm="hljs-";function mm(n){const e=$l.newInstance();return n&&s(n),{highlight:t,highlightAuto:r,listLanguages:i,register:s,registerAlias:o,registered:l};function t(a,c,u){const d=u||Vs,f=typeof d.prefix=="string"?d.prefix:pm;if(!e.getLanguage(a))throw new Error("Unknown language: `"+a+"` is not registered");e.configure({__emitter:gm,classPrefix:f});const h=e.highlight(c,{ignoreIllegals:!0,language:a});if(h.errorRaised)throw new Error("Could not highlight with `Highlight.js`",{cause:h.errorRaised});const p=h._emitter.root,m=p.data;return m.language=h.language,m.relevance=h.relevance,p}function r(a,c){const d=(c||Vs).subset||i();let f=-1,h=0,p;for(;++fh&&(h=g.data.relevance,p=g)}return p||{type:"root",children:[],data:{language:void 0,relevance:h}}}function i(){return e.listLanguages()}function s(a,c){if(typeof a=="string")e.registerLanguage(a,c);else{let u;for(u in a)Object.hasOwn(a,u)&&e.registerLanguage(u,a[u])}}function o(a,c){if(typeof a=="string")e.registerAliases(typeof c=="string"?c:[...c],{languageName:a});else{let u;for(u in a)if(Object.hasOwn(a,u)){const d=a[u];e.registerAliases(typeof d=="string"?d:[...d],{languageName:u})}}}function l(a){return!!e.getLanguage(a)}}class gm{constructor(e){this.options=e,this.root={type:"root",children:[],data:{language:void 0,relevance:0}},this.stack=[this.root]}addText(e){if(e==="")return;const t=this.stack[this.stack.length-1],r=t.children[t.children.length-1];r&&r.type==="text"?r.value+=e:t.children.push({type:"text",value:e})}startScope(e){this.openNode(String(e))}endScope(){this.closeNode()}__addSublanguage(e,t){const r=this.stack[this.stack.length-1],i=e.root.children;t?r.children.push({type:"element",tagName:"span",properties:{className:[t]},children:i}):r.children.push(...i)}openNode(e){const t=this,r=e.split(".").map(function(o,l){return l?o+"_".repeat(l):t.options.classPrefix+o}),i=this.stack[this.stack.length-1],s={type:"element",tagName:"span",properties:{className:r},children:[]};i.children.push(s),this.stack.push(s)}closeNode(){this.stack.pop()}finalize(){}toHTML(){return""}}const we=mm();we.register("javascript",_l);we.register("typescript",jl);we.register("html",Wl);we.register("css",Kl);we.register("php",Jl);we.register("shell",ql);we.register("bash",Ul);we.register("ruby",Gl);we.register("python",Yl);we.register("java",Xl);we.register("c",Zl);const ym=q.create({name:"be-info-block",group:"block",content:"inline*",defining:!0,addOptions(){return{types:["important","warning","success"],defaultType:"success"}},addAttributes(){return{type:{default:this.options.defaultType,parseHTML:n=>{for(const e of this.options.types)if(n.classList.contains(e))return e;return this.options.defaultType},renderHTML:n=>({class:n.type})}}},parseHTML(){return[{tag:"div",contentElement:"p",getAttrs:n=>n.classList.contains("info-block")&&null}]},renderHTML({HTMLAttributes:n}){return["div",H(n,{class:"info-block"}),["div",{class:"title"},"Important:"],["p",0]]},addCommands(){return{addInfo:n=>({commands:e})=>e.setNode(this.name,n)}}});function Sm({initialContent:n="",children:e,onLoad:t,onCtrlEnter:r,minHeight:i="min-h-320",autoFocus:s}){const o=Fl(t),l=G.useRef(!1),a=[Qh.configure({codeBlock:!1}),ep,ip.extend({inclusive:!1,validate:{url:u=>/^https?:\/\//.test(u)}}),op,lp,ap,cp,up,dm,fm,um.configure({lowlight:we}),dp.configure({types:["heading","paragraph"]}),ym,hm];r&&a.push(Q.create({addKeyboardShortcuts:()=>({"Cmd-Enter"(){return r(),!0},"Ctrl-Enter"(){return r(),!0}})}));const c=Zf({extensions:a,onFocus:()=>{},autofocus:s,content:n});return G.useEffect(()=>{if(c)return()=>c.destroy()},[c]),c?(c&&o&&!l.current&&(o(c),l.current=!0),e(Hl.jsx(Gf,{className:i,editor:c}),c)):null}export{Sm as default}; //# sourceMappingURL=article-body-editor-9fa9dbcf.js.map