diff --git a/docs/assets/index-CNTZTma4.js b/docs/assets/index-B5SGPZtJ.js similarity index 93% rename from docs/assets/index-CNTZTma4.js rename to docs/assets/index-B5SGPZtJ.js index 1d4abab..198707b 100644 --- a/docs/assets/index-CNTZTma4.js +++ b/docs/assets/index-B5SGPZtJ.js @@ -14,15 +14,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var SS=k,wS=Symbol.for("react.element"),kS=Symbol.for("react.fragment"),vS=Object.prototype.hasOwnProperty,xS=SS.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,CS={key:!0,ref:!0,__self:!0,__source:!0};function Sm(n,e,t){var r,i={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(r in e)vS.call(e,r)&&!CS.hasOwnProperty(r)&&(i[r]=e[r]);if(n&&n.defaultProps)for(r in e=n.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:wS,type:n,key:o,ref:s,props:i,_owner:xS.current}}Xl.Fragment=kS;Xl.jsx=Sm;Xl.jsxs=Sm;um.exports=Xl;var A=um.exports;function pe(n){this.content=n}pe.prototype={constructor:pe,find:function(n){for(var e=0;e>1}};pe.from=function(n){if(n instanceof pe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new pe(e)};function wm(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),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=wm(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function km(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new x(r,i)}cutByIndex(e,t){return e==t?x.empty:e==0&&t==this.content.length?this:new x(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new x(i,o)}addToStart(e){return new x([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new x(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 o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?fs(r+1,s):fs(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return x.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new x(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return x.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(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}}W.none=[];class Dn extends Error{}class v{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=xm(this.content,e+this.openStart,t);return r&&new v(r,this.openStart,this.openEnd)}removeBetween(e,t){return new v(vm(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 v.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 v(x.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new v(e,r,i)}}v.empty=new v(x.empty,0,0);function vm(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(vm(o.content,e-i-1,t-i-1)))}function xm(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=xm(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function NS(n,e,t){if(t.openStart>n.depth)throw new Dn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Dn("Inconsistent open depths");return Cm(n,e,t,0)}function Cm(n,e,t,r){let i=n.index(r),o=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 eo(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Zn(n.nodeAfter,r),o++));for(let l=o;li&&Mu(n,e,i+1),s=r.depth>i&&Mu(t,r,i+1),l=[];return eo(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(Nm(o,s),Zn(er(o,Mm(n,e,t,r,i+1)),l)):(o&&Zn(er(o,pl(n,e,i+1)),l),eo(e,t,i,l),s&&Zn(er(s,pl(t,r,i+1)),l)),eo(r,null,i,l),new x(l)}function pl(n,e,t){let r=[];if(eo(null,n,t,r),n.depth>t){let i=Mu(n,e,t+1);Zn(er(i,pl(n,e,t+1)),r)}return eo(e,null,t,r),new x(r)}function MS(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(x.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class go{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 o=0;o0;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 DS(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,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new go(t,r,o)}static resolveCached(e,t){let r=Ed.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.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()+")"),Em(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=x.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=x.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}}Tt.prototype.text=void 0;class ml extends Tt{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):Em(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 ml(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ml(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 Em(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class or{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new RS(e,t);if(r.next==null)return or.empty;let i=Om(r);r.next&&r.err("Unexpected trailing text");let o=LS(FS(i));return $S(o,r),o}matchType(e){for(let t=0;tu.createAndFill()));for(let u=0;u=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 o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}}or.empty=new or(!0);class RS{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 Om(n){let e=[];do e.push(AS(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function AS(n){let e=[];do e.push(bS(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bS(n){let e=PS(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=IS(n,e);else break;return e}function Od(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function IS(n,e){let t=Od(n),r=t;return n.eat(",")&&(n.next!="}"?r=Od(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function zS(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function PS(n){if(n.eat("(")){let e=Om(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=zS(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 FS(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{n[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new or(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new Im(o,t,s));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 o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function VS(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class BS{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?VS(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class qo{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=bm(e,i.attrs),this.excluded=null;let o=Tm(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,Rm(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new qo(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}}class zm{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=pe.from(e.nodes),t.marks=pe.from(e.marks||{}),this.nodes=Td.compile(this.spec.nodes,this),this.marks=qo.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 o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=or.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Rd(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Rd(this,s.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 Td){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 ml(r,r.defaultAttrs,e,W.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Tt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Rd(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function JS(n){return n.tag!=null}function _S(n){return n.style!=null}class yo{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(JS(i))this.tags.push(i);else if(_S(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new bd(this,t,!1);return r.addAll(e,W.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new bd(this,t,!0);return r.addAll(e,W.none,t.from,t.to),v.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(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Id(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Id(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new yo(e,yo.schemaRules(e)))}}const Pm={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},WS={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Fm={ol:!0,ul:!0},gl=1,yl=2,to=4;function Ad(n,e,t){return e!=null?(e?gl:0)|(e==="full"?yl:0):n&&n.whitespace=="pre"?gl|yl:t&~to}class ds{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=W.none,this.match=o||(s&to?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(x.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&gl)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=x.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(x.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Pm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class bd{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=Ad(null,t.preserveWhitespace,0)|(r?to:0);i?o=new ds(i.type,i.attrs,W.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new ds(null,null,W.none,!0,null,s):o=new ds(e.schema.topNodeType,null,W.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&yl||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&gl)i.options&yl?r=r.replace(/\r\n?/g,` + */var SS=k,wS=Symbol.for("react.element"),kS=Symbol.for("react.fragment"),vS=Object.prototype.hasOwnProperty,xS=SS.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,CS={key:!0,ref:!0,__self:!0,__source:!0};function Sm(n,e,t){var r,i={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(r in e)vS.call(e,r)&&!CS.hasOwnProperty(r)&&(i[r]=e[r]);if(n&&n.defaultProps)for(r in e=n.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:wS,type:n,key:o,ref:s,props:i,_owner:xS.current}}Xl.Fragment=kS;Xl.jsx=Sm;Xl.jsxs=Sm;um.exports=Xl;var A=um.exports;function pe(n){this.content=n}pe.prototype={constructor:pe,find:function(n){for(var e=0;e>1}};pe.from=function(n){if(n instanceof pe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new pe(e)};function wm(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),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=wm(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function km(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,t-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new C(r,i)}cutByIndex(e,t){return e==t?C.empty:e==0&&t==this.content.length?this:new C(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new C(i,o)}addToStart(e){return new C([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new C(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 o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?fs(r+1,s):fs(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return C.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new C(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return C.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(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}}W.none=[];class Dn extends Error{}class v{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=xm(this.content,e+this.openStart,t);return r&&new v(r,this.openStart,this.openEnd)}removeBetween(e,t){return new v(vm(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 v.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 v(C.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new v(e,r,i)}}v.empty=new v(C.empty,0,0);function vm(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(vm(o.content,e-i-1,t-i-1)))}function xm(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=xm(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function NS(n,e,t){if(t.openStart>n.depth)throw new Dn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Dn("Inconsistent open depths");return Cm(n,e,t,0)}function Cm(n,e,t,r){let i=n.index(r),o=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 eo(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Zn(n.nodeAfter,r),o++));for(let l=o;li&&Mu(n,e,i+1),s=r.depth>i&&Mu(t,r,i+1),l=[];return eo(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(Nm(o,s),Zn(er(o,Mm(n,e,t,r,i+1)),l)):(o&&Zn(er(o,pl(n,e,i+1)),l),eo(e,t,i,l),s&&Zn(er(s,pl(t,r,i+1)),l)),eo(r,null,i,l),new C(l)}function pl(n,e,t){let r=[];if(eo(null,n,t,r),n.depth>t){let i=Mu(n,e,t+1);Zn(er(i,pl(n,e,t+1)),r)}return eo(e,null,t,r),new C(r)}function MS(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(C.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class go{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 o=0;o0;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 DS(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,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new go(t,r,o)}static resolveCached(e,t){let r=Ed.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.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()+")"),Em(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=C.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=C.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}}Tt.prototype.text=void 0;class ml extends Tt{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):Em(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 ml(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ml(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 Em(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class or{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new RS(e,t);if(r.next==null)return or.empty;let i=Om(r);r.next&&r.err("Unexpected trailing text");let o=LS(FS(i));return $S(o,r),o}matchType(e){for(let t=0;tu.createAndFill()));for(let u=0;u=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 o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}}or.empty=new or(!0);class RS{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 Om(n){let e=[];do e.push(AS(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function AS(n){let e=[];do e.push(bS(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bS(n){let e=PS(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=IS(n,e);else break;return e}function Od(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function IS(n,e){let t=Od(n),r=t;return n.eat(",")&&(n.next!="}"?r=Od(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function zS(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function PS(n){if(n.eat("(")){let e=Om(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=zS(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 FS(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{n[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new or(r.indexOf(n.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new Im(o,t,s));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 o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function VS(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class BS{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?VS(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class qo{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=bm(e,i.attrs),this.excluded=null;let o=Tm(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,Rm(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new qo(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}}class zm{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=pe.from(e.nodes),t.marks=pe.from(e.marks||{}),this.nodes=Td.compile(this.spec.nodes,this),this.marks=qo.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 o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=or.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Rd(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Rd(this,s.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 Td){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 ml(r,r.defaultAttrs,e,W.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Tt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Rd(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function JS(n){return n.tag!=null}function _S(n){return n.style!=null}class yo{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(JS(i))this.tags.push(i);else if(_S(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new bd(this,t,!1);return r.addAll(e,W.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new bd(this,t,!0);return r.addAll(e,W.none,t.from,t.to),v.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(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Id(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Id(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new yo(e,yo.schemaRules(e)))}}const Pm={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},WS={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Fm={ol:!0,ul:!0},gl=1,yl=2,to=4;function Ad(n,e,t){return e!=null?(e?gl:0)|(e==="full"?yl:0):n&&n.whitespace=="pre"?gl|yl:t&~to}class ds{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=W.none,this.match=o||(s&to?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(C.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&gl)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=C.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Pm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class bd{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=Ad(null,t.preserveWhitespace,0)|(r?to:0);i?o=new ds(i.type,i.attrs,W.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new ds(null,null,W.none,!0,null,s):o=new ds(e.schema.topNodeType,null,W.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&yl||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&gl)i.options&yl?r=r.replace(/\r\n?/g,` `):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;Fm.hasOwnProperty(i)&&this.parser.normalizeLists&&US(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:WS.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,a=this.top,u=this.needsBlock;if(Pm.hasOwnProperty(i))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let c=s&&s.skip?t:this.readStyles(e,t);c&&this.addAll(e,c),l&&this.sync(a),this.needsBlock=u}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(u)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(u.type):zd(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new ds(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;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),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=t[l];if(u==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function US(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Fm.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function HS(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Id(n){let e={};for(let t in n)e[t]=n[t];return e}function zd(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Vs(va(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Vs(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new pi(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Pd(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Pd(e.marks)}}function Pd(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function va(n){return n.document||window.document}const Fd=new WeakMap;function jS(n){let e=Fd.get(n);return e===void 0&&Fd.set(n,e=KS(n)),e}function KS(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let f in u)if(u[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),u[f]):a.setAttribute(f,u[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:h}=Vs(n,d,t,r);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const Lm=65535,$m=Math.pow(2,16);function qS(n,e){return n+e*$m}function Ld(n){return n&Lm}function QS(n){return(n-(n&Lm))/$m}const Vm=1,Bm=2,Bs=4,Jm=8;let $d=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Jm)>0}get deletedBefore(){return(this.delInfo&(Vm|Bs))>0}get deletedAfter(){return(this.delInfo&(Bm|Bs))>0}get deletedAcross(){return(this.delInfo&Bs)>0}},qr=class kr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&kr.empty)return kr.empty}recover(e){let t=0,r=Ld(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:qS(l/3,e-a),m=e==a?Bm:e==f?Vm:Bs;return(t<0?e!=a:e!=f)&&(m|=Jm),new $d(p,m,h)}i+=c-u}return r?e+i:new $d(e+i,0,null)}touches(e,t){let r=0,i=Ld(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,o)}invert(){return new Wm(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 Di(t.pos,r.pos,this.mark)}merge(e){return e instanceof Di&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Di(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 Di(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("addMark",_m);let Wm=class Ti extends Ke{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 v(ef(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,r)}invert(){return new _m(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 Ti(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ti&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ti(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 Ti(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("removeMark",Wm);let Um=class Ri extends Ke{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $e.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $e.fromReplace(e,this.pos,this.pos+1,new v(x.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 Js(t.pos,r.pos,i,o,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 Js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ke.jsonID("replaceAround",Sl);function Ou(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function YS(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nf(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(ro;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function jm(n,e){let t=n.resolve(e),r=t.index();return GS(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function GS(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Km(n,e,t=e,r=v.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return XS(i,o,r)?new tf(e,t,r):new ZS(i,o,r).fit()}function XS(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}let ZS=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=x.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=x.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Sl(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new tf(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ca(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(x.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ca(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Ca(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Ai(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Ai(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=S,c.push(qm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=bi(this.placed,t,x.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,S=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Na(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=bi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=bi(this.placed,this.depth,x.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(x.empty,!0);t.childCount&&(this.placed=bi(this.placed,this.frontier.length,t))}};function Ai(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ai(n.firstChild.content,e-1,t)))}function bi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(bi(n.lastChild.content,e-1,t)))}function Ca(n,e){for(let t=0;t1&&(r=r.replaceChild(0,qm(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(x.empty,!0)))),n.copy(r)}function Na(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!ew(t,o.content,s)?l:null}function ew(n,e,t){for(let r=t;r0}get deletedBefore(){return(this.delInfo&(Gm|Us))>0}get deletedAfter(){return(this.delInfo&(Xm|Us))>0}get deletedAcross(){return(this.delInfo&Us)>0}},Qr=class vr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&vr.empty)return vr.empty}recover(e){let t=0,r=Vd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:nw(l/3,e-a),m=e==a?Xm:e==f?Gm:Us;return(t<0?e!=a:e!=f)&&(m|=Zm),new Du(p,m,h)}i+=c-u}return r?e+i:new Du(e+i,0,null)}touches(e,t){let r=0,i=Vd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=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 Hs;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,o)}invert(){return new Qo(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 zi(t.pos,r.pos,this.mark)}merge(e){return e instanceof zi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new zi(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 zi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("addMark",of);let Qo=class Pi extends qe{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 v(rf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,r)}invert(){return new of(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 Pi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Pi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Pi(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 Pi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("removeMark",Qo);let sf=class Fi extends qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Ve.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Ve.fromReplace(e,this.pos,this.pos+1,new v(x.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 js(t.pos,r.pos,i,o,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 js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};qe.jsonID("replaceAround",dr);function Ru(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ow(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function sw(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Qo(s.from,s.to,s.style)))}function lw(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function aw(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=x.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=x.from(r.node(h).copy(c)),f++):a--;let d=x.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].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=x.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new dr(i,o,i,o,new v(r,0,0),t.length,!0))}function cw(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&fw(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new dr(u,c,u+1,c-1,new v(x.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function fw(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function dw(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new dr(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(x.from(s),0,0),1,!0))}function hw(n,e,t=1,r){let i=n.doc.resolve(e),o=x.empty,s=x.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=x.from(i.node(l).copy(o));let c=r&&r[u];s=x.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new An(e,e,new v(o.append(s),t,t),!0))}function pw(n,e,t){let r=new An(e-t,e+t,v.empty,!0);n.step(r)}function mw(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 o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=x.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new dr(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new An(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ea(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(x.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ea(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Ea(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Li(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Li(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=S,c.push(tg(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=$i(this.placed,t,x.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,S=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Oa(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=$i(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=$i(this.placed,this.depth,x.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(x.empty,!0);t.childCount&&(this.placed=$i(this.placed,this.frontier.length,t))}};function Li(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Li(n.firstChild.content,e-1,t)))}function $i(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy($i(n.lastChild.content,e-1,t)))}function Ea(n,e){for(let t=0;t1&&(r=r.replaceChild(0,tg(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(x.empty,!0)))),n.copy(r)}function Oa(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Sw(t,o.content,s)?l:null}function Sw(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=ww(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function ng(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(x.empty,!0))}return n}function vw(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=mw(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(x.from(r),0,0))}function xw(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=rg(r,i);for(let s=0;s0&&(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 s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function rg(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}let ig=class Ks extends qe{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 Ve.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Ve.fromReplace(e,this.pos,this.pos+1,new v(x.from(i),0,t.isLeaf?0:1))}getMap(){return Qr.empty}invert(e){return new Ks(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 Ks(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 Ks(t.pos,t.attr,t.value)}};qe.jsonID("attr",ig);let Yr=class extends Error{};Yr=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yr.prototype=Object.create(Error.prototype);Yr.prototype.constructor=Yr;Yr.prototype.name="TransformError";let Cw=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new iw}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yr(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=v.empty){let i=gw(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(x.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return kw(this,e,t,r),this}replaceRangeWith(e,t,r){return vw(this,e,t,r),this}deleteRange(e,t){return xw(this,e,t),this}lift(e,t){return aw(this,e,t),this}join(e,t=1){return pw(this,e,t),this}wrap(e,t){return uw(this,e,t),this}setBlockType(e,t=e,r,i=null){return cw(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return dw(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ig(e,t,r)),this}addNodeMark(e,t){return this.step(new sf(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){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 lf(e,t)),this}split(e,t=1,r){return hw(this,e,t,r),this}addMark(e,t,r){return ow(this,e,t,r),this}removeMark(e,t,r){return sw(this,e,t,r),this}clearIncompatible(e,t,r){return lw(this,e,t,r),this}};const Da=Object.create(null);class P{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new og(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;o--){let s=t<0?xr(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):xr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new et(e.node(0))}static atStart(e){return xr(e,e,0,0,1)||new et(e)}static atEnd(e){return xr(e,e,e.content.size,e.childCount,-1)||new et(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Da[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 Da)throw new RangeError("Duplicate use of selection JSON ID "+e);return Da[e]=t,t.prototype.jsonID=e,t}getBookmark(){return $.between(this.$anchor,this.$head).getBookmark()}}P.prototype.visible=!0;class og{constructor(e,t){this.$from=e,this.$to=t}}let Bd=!1;function Jd(n){!Bd&&!n.parent.inlineContent&&(Bd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class $ extends P{constructor(e,t=e){Jd(e),Jd(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 P.near(r);let i=e.resolve(t.map(this.anchor));return new $(i.parent.inlineContent?i:r,r)}replace(e,t=v.empty){if(super.replace(e,t),t==v.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof $&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new $(e.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 o=P.findFrom(t,r,!0)||P.findFrom(t,-r,!0);if(o)t=o.$head;else return P.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(P.findFrom(e,-r,!0)||P.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&I.isSelectable(l))return I.create(n,t-(i<0?l.nodeSize:0))}else{let a=xr(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function _d(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=c)}),n.setSelection(P.near(n.doc.resolve(s),t))}const Wd=1,hs=2,Ud=4;class Mw extends Cw{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|=hs,this}ensureMarks(e){return W.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&hs)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~hs,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)||W.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 o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(P.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|=Ud,this}get scrolledIntoView(){return(this.updated&Ud)>0}}function Hd(n,e){return!e||!n?n:n.bind(e)}class Vi{constructor(e,t,r){this.name=e,this.init=Hd(t.init,r),this.apply=Hd(t.apply,r)}}const Ew=[new Vi("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Vi("selection",{init(n,e){return n.selection||P.atStart(e.doc)},apply(n){return n.selection}}),new Vi("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Vi("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ta{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ew.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 Vi(r.key,r.spec.state,r))})}}class dn{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],o=i.spec.state;o&&o.toJSON&&(t[r]=o.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 Ta(e.schema,e.plugins),o=new dn(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Tt.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=P.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=u.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function sg(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=sg(i,e,{})),t[r]=i}return t}class $t{constructor(e){this.spec=e,this.props={},e.props&&sg(e.props,this,this.props),this.key=e.key?e.key.key:lg("plugin")}getState(e){return e[this.key]}}const Ra=Object.create(null);function lg(n){return n in Ra?n+"$"+ ++Ra[n]:(Ra[n]=0,n+"$")}class Yo{constructor(e="key"){this.key=lg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const ag=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ow(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Dw=(n,e,t)=>{let r=Ow(n,t);if(!r)return!1;let i=ug(r);if(!i){let s=r.blockRange(),l=s&&nf(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"end")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=ug(r)}let s=o&&o.nodeBefore;return!s||!I.isSelectable(s)?!1:(e&&e(n.tr.setSelection(I.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function ug(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 Rw(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Rw(n,t);if(!r)return!1;let i=cg(r);if(!i)return!1;let o=i.nodeAfter;if(fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"start")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function uf(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),o=t.indexAfter(-1),s=uf(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(P.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Pw=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof et||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=uf(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(_s(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nf(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Lw(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof I&&e.selection.node.isBlock)return!r.parentOffset||!_s(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof $||e.selection instanceof et)&&s.deleteSelection();let l=r.depth==0?null:uf(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=o&&l?[{type:l}]:void 0,u=_s(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!u&&_s(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),u=!0),u&&(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l)){let c=s.mapping.map(r.before()),f=s.doc.resolve(c);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}const $w=Lw(),Vw=(n,e)=>(e&&e(n.tr.setSelection(new et(n.doc))),!0);function Bw(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||jm(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function fg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Bw(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let f=e.pos+i.nodeSize,d=x.empty;for(let m=o.length-1;m>=0;m--)d=x.from(o[m].create(null,d));d=x.from(r.copy(d));let p=n.tr.step(new Sl(e.pos-1,f,e.pos,f,new v(d,1,0),o.length,!0)),h=f+2*o.length;jm(p.doc,h)&&p.join(h),t(p.scrollIntoView())}return!0}let a=P.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&nf(u);if(c!=null&&c>=e.depth)return t&&t(n.tr.lift(u,c).scrollIntoView()),!0;if(l&&Gr(i,"start",!0)&&Gr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(t){let m=x.empty;for(let g=d.length-1;g>=0;g--)m=x.from(d[g].copy(m));let S=n.tr.step(new Sl(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new v(m,d.length,0),0,!0));t(S.scrollIntoView())}return!0}}return!1}function dg(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection($.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}const Jw=dg(-1),_w=dg(1);function Ww(n,e,t){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function jd(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!Ww(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},qd=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),jw=typeof navigator<"u"&&/Mac/.test(navigator.platform),Kw=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),qw=jw||qd&&+qd[1]<57;for(var ge=0;ge<10;ge++)It[48+ge]=It[96+ge]=String(ge);for(var ge=1;ge<=24;ge++)It[ge+111]="F"+ge;for(var ge=65;ge<=90;ge++)It[ge]=String.fromCharCode(ge+32),wl[ge]=String.fromCharCode(ge);for(var ba in It)wl.hasOwnProperty(ba)||(wl[ba]=It[ba]);function ff(n){var e=qw&&(n.ctrlKey||n.altKey||n.metaKey)||Kw&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?wl:It)[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 Qw=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Yw(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ia(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const pg=65535,mg=Math.pow(2,16);function Zw(n,e){return n+e*mg}function Qd(n){return n&pg}function ek(n){return(n-(n&pg))/mg}const gg=1,yg=2,qs=4,Sg=8;let Yd=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Sg)>0}get deletedBefore(){return(this.delInfo&(gg|qs))>0}get deletedAfter(){return(this.delInfo&(yg|qs))>0}get deletedAcross(){return(this.delInfo&qs)>0}},Xr=class Cr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Cr.empty)return Cr.empty}recover(e){let t=0,r=Qd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:Zw(l/3,e-a),m=e==a?yg:e==f?gg:qs;return(t<0?e!=a:e!=f)&&(m|=Sg),new Yd(p,m,h)}i+=c-u}return r?e+i:new Yd(e+i,0,null)}touches(e,t){let r=0,i=Qd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,o)}invert(){return new kg(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 Ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ji(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 Ji(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("addMark",wg);let kg=class _i extends Qe{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 v(df(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,r)}invert(){return new wg(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 _i(t.pos,r.pos,this.mark)}merge(e){return e instanceof _i&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _i(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 _i(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("removeMark",kg);let vg=class Wi extends Qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Be.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Be.fromReplace(e,this.pos,this.pos+1,new v(x.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 Qs(t.pos,r.pos,i,o,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 Qs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Qe.jsonID("replaceAround",nk);function bu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function rk(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let o=0;o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}let ik=class Ys extends Qe{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 Be.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Be.fromReplace(e,this.pos,this.pos+1,new v(x.from(i),0,t.isLeaf?0:1))}getMap(){return Xr.empty}invert(e){return new Ys(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 Ys(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 Ys(t.pos,t.attr,t.value)}};Qe.jsonID("attr",ik);let wo=class extends Error{};wo=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};wo.prototype=Object.create(Error.prototype);wo.prototype.constructor=wo;wo.prototype.name="TransformError";const ye=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ko=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Iu=null;const _t=function(n,e,t){let r=Iu||(Iu=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ok=function(){Iu=null},sr=function(n,e,t,r){return t&&(Gd(n,e,t,r,-1)||Gd(n,e,t,r,1))},sk=/^(img|br|input|textarea|hr)$/i;function Gd(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:at(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Go(n)||sk.test(n.nodeName)||n.contentEditable=="false")return!1;e=ye(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?at(n):0}else return!1}}function at(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lk(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=at(n)}else if(n.parentNode&&!Go(n))e=ye(n),n=n.parentNode;else return null}}function ak(n,e){for(;;){if(n.nodeType==3&&e2),ot=Zr||(zt?/Mac/.test(zt.platform):!1),dk=zt?/Win/.test(zt.platform):!1,wt=/Android \d/.test(bn),Xo=!!Xd&&"webkitFontSmoothing"in Xd.documentElement.style,hk=Xo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pk(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Bt(n,e){return typeof n=="number"?n:n[e]}function mk(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 Zd(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=ko(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?pk(o):mk(l),c=0,f=0;if(e.topu.bottom-Bt(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+Bt(i,"top")-u.top:e.bottom-u.bottom+Bt(i,"bottom")),e.leftu.right-Bt(r,"right")&&(c=e.right-u.right+Bt(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gk(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Mg(n.dom)}}function Mg(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ko(r));return e}function yk({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Eg(t,r==0?0:r-e)}function Eg(n,e){for(let t=0;t=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=u,r=0),t&&t.nodeType==3?wk(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Og(t,i)}function wk(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function hf(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function kk(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function xk(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dg(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let u;Xo&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.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=xk(n,r,i,e))}l==null&&(l=vk(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function eh(n){return n.top=0&&i==r.nodeValue.length?(a--,c=1):t<0?a--:u++,Si(nn(_t(r,a,u),c),c<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Pa(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1],u=a.nodeType==3?_t(a,at(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Si(nn(u,1),!1)}if(o==null&&i=0)}function Si(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 Pa(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 Rg(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 Mk(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Rg(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Tg(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=_t(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(t=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const Ek=/[\u0590-\u08ac]/;function Ok(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Ek.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Rg(n,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),S=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),S}):r.pos==r.start()||r.pos==r.end()}let th=null,nh=null,rh=!1;function Dk(n,e,t){return th==e&&nh==t?rh:(th=e,nh=t,rh=t=="up"||t=="down"?Mk(n,e,t):Ok(n,e,t))}const ft=0,ih=1,qn=2,Pt=3;let Zo=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ft,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;tye(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 o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.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 o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}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 o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof Pg){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Ag&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ye(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ye(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;cp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}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+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?qn:ih,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Pt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?qn:Pt}r=s}this.dirty=qn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?qn:ih;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==ft&&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}},Tk=class extends Zo{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}},kl=class Lu extends Zo{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=pi.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Lu(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ft){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Bu(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=pi.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let d=c;return c=$g(c,r,t),u?a=new Rk(e,t,r,i,c,f||null,d,u,o,s+1):t.isText?new Ig(e,t,r,i,c,d,o):new bg(e,t,r,i,c,f||null,d,o,s+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=()=>x.empty)}return e}matchesNode(e,t,r){return this.dirty==ft&&e.eq(this.node)&&Vu(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new bk(this,s&&s.node,e);Pk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==qn)&&(s&&this.protectLocalComposition(e,s),Fg(this.contentDOM,this.children,e),Zr&&Fk(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof $)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Lk(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Tk(this,o,t,i);e.input.compositionNodes.push(s),this.children=Bu(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Pt||!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=ft}updateOuterDeco(e){if(Vu(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Lg(this.dom,this.nodeDOM,$u(this.outerDeco,this.node,t),$u(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 oh(n,e,t,r,i){$g(r,e,n);let o=new Vr(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Ig=class zg extends Vr{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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==Pt||this.dirty!=ft&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ft||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=ft,!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),o=document.createTextNode(i.text);return new zg(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Pt)}get domAtom(){return!1}isText(e){return this.node.text==e}},Pg=class extends Zo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ft&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class Rk extends Vr{constructor(e,t,r,i,o,s,l,a,u,c){super(e,t,r,i,o,s,l,u,c),this.spec=a}update(e,t,r,i){if(this.dirty==Pt)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Fg(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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=kl.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=t.children[r-1];if(u instanceof kl)t=u,r=u.children.length;else{l=u,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function zk(n,e){return n.type.side-e.type.side}function Pk(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let S=h;s!S.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function Fk(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 Lk(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=t)return l+u;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Bu(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||c<=e?o.push(a):(ut&&o.push(a.slice(t-u,a.size,r)))}return o}function pf(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(ea(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&I.isSelectable(c)&&i.parent&&!(c.isInline&&uk(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;u=new I(s==f?l:r.resolve(f))}}else{let c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Vg(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Vk(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,ye(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&We&&Sn<=11&&(r.disabled=!0,r.disabled=!1)}function Bg(n,e){if(e instanceof I){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ch(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ch(n)}function ch(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function mf(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function fh(n){return n.editable&&!n.hasFocus()?!1:Jg(n)}function Jg(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 Bk(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return sr(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ju(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&P.findFrom(o,e)}function rn(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function dh(n,e,t){let r=n.state.selection;if(r instanceof $)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return rn(n,new $(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ju(n.state,e);return i&&i instanceof I?rn(n,i):!1}else if(!(ot&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?I.isSelectable(o)?rn(n,new I(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Xo?rn(n,new $(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof I&&r.node.isInline)return rn(n,new $(e>0?r.$to:r.$from));{let i=Ju(n.state,e);return i?rn(n,i):!1}}}function vl(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ro(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Sr(n,e){return e<0?Jk(n):_k(n)}function Jk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ct&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ro(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(_g(t))break;{let l=t.previousSibling;for(;l&&ro(l,-1);)i=t.parentNode,o=ye(l),l=l.previousSibling;if(l)t=l,r=vl(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?_u(n,t,r):i&&_u(n,i,o)}function _k(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=vl(t),o,s;for(;;)if(r{n.state==i&&qt(n)},50)}function hh(n,e){let t=n.state.doc.resolve(e);if(!(Me||dk)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ph(n,e,t){let r=n.state.selection;if(r instanceof $&&!r.empty||t.indexOf("s")>-1||ot&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ju(n.state,e);if(s&&s instanceof I)return rn(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof et?P.near(s,e):P.findFrom(s,e);return l?rn(n,l):!1}return!1}function mh(n,e){if(!(n.state.selection instanceof $))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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function gh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Hk(n){if(!be||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;gh(n,r,"true"),setTimeout(()=>gh(n,r,"false"),20)}return!1}function jk(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Kk(n,e){let t=e.keyCode,r=jk(e);if(t==8||ot&&t==72&&r=="c")return mh(n,-1)||Sr(n,-1);if(t==46&&!e.shiftKey||ot&&t==68&&r=="c")return mh(n,1)||Sr(n,1);if(t==13||t==27)return!0;if(t==37||ot&&t==66&&r=="c"){let i=t==37?hh(n,n.state.selection.from)=="ltr"?-1:1:-1;return dh(n,i,r)||Sr(n,i)}else if(t==39||ot&&t==70&&r=="c"){let i=t==39?hh(n,n.state.selection.from)=="ltr"?1:-1:1;return dh(n,i,r)||Sr(n,i)}else{if(t==38||ot&&t==80&&r=="c")return ph(n,-1,r)||Sr(n,-1);if(t==40||ot&&t==78&&r=="c")return Hk(n)||ph(n,1,r)||Sr(n,1);if(r==(ot?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Wg(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||pi.fromSchema(n.state.schema),l=Qg(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=qg[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(u)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(u.type):zd(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new ds(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;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),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=t[l];if(u==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function US(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Fm.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function HS(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Id(n){let e={};for(let t in n)e[t]=n[t];return e}function zd(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Vs(va(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Vs(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new pi(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Pd(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Pd(e.marks)}}function Pd(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function va(n){return n.document||window.document}const Fd=new WeakMap;function jS(n){let e=Fd.get(n);return e===void 0&&Fd.set(n,e=KS(n)),e}function KS(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let f in u)if(u[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),u[f]):a.setAttribute(f,u[f])}}for(let f=c;fc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:h}=Vs(n,d,t,r);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const Lm=65535,$m=Math.pow(2,16);function qS(n,e){return n+e*$m}function Ld(n){return n&Lm}function QS(n){return(n-(n&Lm))/$m}const Vm=1,Bm=2,Bs=4,Jm=8;let $d=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Jm)>0}get deletedBefore(){return(this.delInfo&(Vm|Bs))>0}get deletedAfter(){return(this.delInfo&(Bm|Bs))>0}get deletedAcross(){return(this.delInfo&Bs)>0}},qr=class kr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&kr.empty)return kr.empty}recover(e){let t=0,r=Ld(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:qS(l/3,e-a),m=e==a?Bm:e==f?Vm:Bs;return(t<0?e!=a:e!=f)&&(m|=Jm),new $d(p,m,h)}i+=c-u}return r?e+i:new $d(e+i,0,null)}touches(e,t){let r=0,i=Ld(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,o)}invert(){return new Wm(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 Di(t.pos,r.pos,this.mark)}merge(e){return e instanceof Di&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Di(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 Di(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("addMark",_m);let Wm=class Ti extends Ke{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 v(ef(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return $e.fromReplace(e,this.from,this.to,r)}invert(){return new _m(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 Ti(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ti&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ti(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 Ti(t.from,t.to,e.markFromJSON(t.mark))}};Ke.jsonID("removeMark",Wm);let Um=class Ri extends Ke{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $e.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $e.fromReplace(e,this.pos,this.pos+1,new v(C.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 Js(t.pos,r.pos,i,o,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 Js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ke.jsonID("replaceAround",Sl);function Ou(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function YS(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nf(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(ro;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function jm(n,e){let t=n.resolve(e),r=t.index();return GS(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function GS(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Km(n,e,t=e,r=v.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return XS(i,o,r)?new tf(e,t,r):new ZS(i,o,r).fit()}function XS(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}let ZS=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=C.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Sl(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new tf(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ca(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ca(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Ca(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Ai(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Ai(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(qm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=bi(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Na(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=bi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=bi(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=bi(this.placed,this.frontier.length,t))}};function Ai(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ai(n.firstChild.content,e-1,t)))}function bi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(bi(n.lastChild.content,e-1,t)))}function Ca(n,e){for(let t=0;t1&&(r=r.replaceChild(0,qm(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(C.empty,!0)))),n.copy(r)}function Na(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!ew(t,o.content,s)?l:null}function ew(n,e,t){for(let r=t;r0}get deletedBefore(){return(this.delInfo&(Gm|Us))>0}get deletedAfter(){return(this.delInfo&(Xm|Us))>0}get deletedAcross(){return(this.delInfo&Us)>0}},Qr=class vr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&vr.empty)return vr.empty}recover(e){let t=0,r=Vd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:nw(l/3,e-a),m=e==a?Xm:e==f?Gm:Us;return(t<0?e!=a:e!=f)&&(m|=Zm),new Du(p,m,h)}i+=c-u}return r?e+i:new Du(e+i,0,null)}touches(e,t){let r=0,i=Vd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=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 Hs;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,o)}invert(){return new Qo(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 zi(t.pos,r.pos,this.mark)}merge(e){return e instanceof zi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new zi(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 zi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("addMark",of);let Qo=class Pi extends qe{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 v(rf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Ve.fromReplace(e,this.from,this.to,r)}invert(){return new of(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 Pi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Pi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Pi(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 Pi(t.from,t.to,e.markFromJSON(t.mark))}};qe.jsonID("removeMark",Qo);let sf=class Fi extends qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Ve.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Ve.fromReplace(e,this.pos,this.pos+1,new v(C.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 js(t.pos,r.pos,i,o,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 js(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};qe.jsonID("replaceAround",dr);function Ru(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function ow(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function sw(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Qo(s.from,s.to,s.style)))}function lw(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function aw(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=C.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=C.from(r.node(h).copy(c)),f++):a--;let d=C.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].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=C.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new dr(i,o,i,o,new v(r,0,0),t.length,!0))}function cw(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&fw(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new dr(u,c,u+1,c-1,new v(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function fw(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function dw(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new dr(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(C.from(s),0,0),1,!0))}function hw(n,e,t=1,r){let i=n.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new An(e,e,new v(o.append(s),t,t),!0))}function pw(n,e,t){let r=new An(e-t,e+t,v.empty,!0);n.step(r)}function mw(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 o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new dr(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new An(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ea(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ea(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Ea(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(Li(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(Li(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(tg(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=$i(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Oa(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=$i(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=$i(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=$i(this.placed,this.frontier.length,t))}};function Li(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Li(n.firstChild.content,e-1,t)))}function $i(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy($i(n.lastChild.content,e-1,t)))}function Ea(n,e){for(let t=0;t1&&(r=r.replaceChild(0,tg(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(C.empty,!0)))),n.copy(r)}function Oa(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Sw(t,o.content,s)?l:null}function Sw(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=ww(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function ng(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return n}function vw(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=mw(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(C.from(r),0,0))}function xw(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=rg(r,i);for(let s=0;s0&&(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 s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function rg(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}let ig=class Ks extends qe{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 Ve.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Ve.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Qr.empty}invert(e){return new Ks(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 Ks(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 Ks(t.pos,t.attr,t.value)}};qe.jsonID("attr",ig);let Yr=class extends Error{};Yr=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yr.prototype=Object.create(Error.prototype);Yr.prototype.constructor=Yr;Yr.prototype.name="TransformError";let Cw=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new iw}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yr(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=v.empty){let i=gw(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(C.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return kw(this,e,t,r),this}replaceRangeWith(e,t,r){return vw(this,e,t,r),this}deleteRange(e,t){return xw(this,e,t),this}lift(e,t){return aw(this,e,t),this}join(e,t=1){return pw(this,e,t),this}wrap(e,t){return uw(this,e,t),this}setBlockType(e,t=e,r,i=null){return cw(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return dw(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ig(e,t,r)),this}addNodeMark(e,t){return this.step(new sf(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){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 lf(e,t)),this}split(e,t=1,r){return hw(this,e,t,r),this}addMark(e,t,r){return ow(this,e,t,r),this}removeMark(e,t,r){return sw(this,e,t,r),this}clearIncompatible(e,t,r){return lw(this,e,t,r),this}};const Da=Object.create(null);class P{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new og(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;o--){let s=t<0?xr(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):xr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new et(e.node(0))}static atStart(e){return xr(e,e,0,0,1)||new et(e)}static atEnd(e){return xr(e,e,e.content.size,e.childCount,-1)||new et(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Da[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 Da)throw new RangeError("Duplicate use of selection JSON ID "+e);return Da[e]=t,t.prototype.jsonID=e,t}getBookmark(){return $.between(this.$anchor,this.$head).getBookmark()}}P.prototype.visible=!0;class og{constructor(e,t){this.$from=e,this.$to=t}}let Bd=!1;function Jd(n){!Bd&&!n.parent.inlineContent&&(Bd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class $ extends P{constructor(e,t=e){Jd(e),Jd(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 P.near(r);let i=e.resolve(t.map(this.anchor));return new $(i.parent.inlineContent?i:r,r)}replace(e,t=v.empty){if(super.replace(e,t),t==v.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof $&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new $(e.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 o=P.findFrom(t,r,!0)||P.findFrom(t,-r,!0);if(o)t=o.$head;else return P.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(P.findFrom(e,-r,!0)||P.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&I.isSelectable(l))return I.create(n,t-(i<0?l.nodeSize:0))}else{let a=xr(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function _d(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=c)}),n.setSelection(P.near(n.doc.resolve(s),t))}const Wd=1,hs=2,Ud=4;class Mw extends Cw{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|=hs,this}ensureMarks(e){return W.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&hs)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~hs,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)||W.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 o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(P.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|=Ud,this}get scrolledIntoView(){return(this.updated&Ud)>0}}function Hd(n,e){return!e||!n?n:n.bind(e)}class Vi{constructor(e,t,r){this.name=e,this.init=Hd(t.init,r),this.apply=Hd(t.apply,r)}}const Ew=[new Vi("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Vi("selection",{init(n,e){return n.selection||P.atStart(e.doc)},apply(n){return n.selection}}),new Vi("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Vi("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ta{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ew.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 Vi(r.key,r.spec.state,r))})}}class dn{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],o=i.spec.state;o&&o.toJSON&&(t[r]=o.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 Ta(e.schema,e.plugins),o=new dn(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Tt.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=P.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=u.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function sg(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=sg(i,e,{})),t[r]=i}return t}class $t{constructor(e){this.spec=e,this.props={},e.props&&sg(e.props,this,this.props),this.key=e.key?e.key.key:lg("plugin")}getState(e){return e[this.key]}}const Ra=Object.create(null);function lg(n){return n in Ra?n+"$"+ ++Ra[n]:(Ra[n]=0,n+"$")}class Yo{constructor(e="key"){this.key=lg(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const ag=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ow(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Dw=(n,e,t)=>{let r=Ow(n,t);if(!r)return!1;let i=ug(r);if(!i){let s=r.blockRange(),l=s&&nf(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"end")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=ug(r)}let s=o&&o.nodeBefore;return!s||!I.isSelectable(s)?!1:(e&&e(n.tr.setSelection(I.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function ug(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 Rw(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Rw(n,t);if(!r)return!1;let i=cg(r);if(!i)return!1;let o=i.nodeAfter;if(fg(n,i,e))return!0;if(r.parent.content.size==0&&(Gr(o,"start")||I.isSelectable(o))){let s=Km(n.doc,r.before(),r.after(),v.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function uf(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),o=t.indexAfter(-1),s=uf(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(P.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Pw=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof et||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=uf(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(_s(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nf(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Lw(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof I&&e.selection.node.isBlock)return!r.parentOffset||!_s(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof $||e.selection instanceof et)&&s.deleteSelection();let l=r.depth==0?null:uf(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=o&&l?[{type:l}]:void 0,u=_s(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!u&&_s(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),u=!0),u&&(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l)){let c=s.mapping.map(r.before()),f=s.doc.resolve(c);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}t(s.scrollIntoView())}return!0}}const $w=Lw(),Vw=(n,e)=>(e&&e(n.tr.setSelection(new et(n.doc))),!0);function Bw(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||jm(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function fg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Bw(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(t){let f=e.pos+i.nodeSize,d=C.empty;for(let m=o.length-1;m>=0;m--)d=C.from(o[m].create(null,d));d=C.from(r.copy(d));let p=n.tr.step(new Sl(e.pos-1,f,e.pos,f,new v(d,1,0),o.length,!0)),h=f+2*o.length;jm(p.doc,h)&&p.join(h),t(p.scrollIntoView())}return!0}let a=P.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&nf(u);if(c!=null&&c>=e.depth)return t&&t(n.tr.lift(u,c).scrollIntoView()),!0;if(l&&Gr(i,"start",!0)&&Gr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(t){let m=C.empty;for(let g=d.length-1;g>=0;g--)m=C.from(d[g].copy(m));let w=n.tr.step(new Sl(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new v(m,d.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function dg(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection($.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}const Jw=dg(-1),_w=dg(1);function Ww(n,e,t){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(t)}),s)return!0}return!1}function jd(n,e=null){return function(t,r){let{empty:i,$cursor:o,ranges:s}=t.selection;if(i&&!o||!Ww(t.doc,s,n))return!1;if(r)if(o)n.isInSet(t.storedMarks||o.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,a=t.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},qd=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),jw=typeof navigator<"u"&&/Mac/.test(navigator.platform),Kw=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),qw=jw||qd&&+qd[1]<57;for(var ge=0;ge<10;ge++)It[48+ge]=It[96+ge]=String(ge);for(var ge=1;ge<=24;ge++)It[ge+111]="F"+ge;for(var ge=65;ge<=90;ge++)It[ge]=String.fromCharCode(ge+32),wl[ge]=String.fromCharCode(ge);for(var ba in It)wl.hasOwnProperty(ba)||(wl[ba]=It[ba]);function ff(n){var e=qw&&(n.ctrlKey||n.altKey||n.metaKey)||Kw&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?wl:It)[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 Qw=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Yw(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ia(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const pg=65535,mg=Math.pow(2,16);function Zw(n,e){return n+e*mg}function Qd(n){return n&pg}function ek(n){return(n-(n&pg))/mg}const gg=1,yg=2,qs=4,Sg=8;let Yd=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Sg)>0}get deletedBefore(){return(this.delInfo&(gg|qs))>0}get deletedAfter(){return(this.delInfo&(yg|qs))>0}get deletedAcross(){return(this.delInfo&qs)>0}},Xr=class Cr{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Cr.empty)return Cr.empty}recover(e){let t=0,r=Qd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:Zw(l/3,e-a),m=e==a?yg:e==f?gg:qs;return(t<0?e!=a:e!=f)&&(m|=Sg),new Yd(p,m,h)}i+=c-u}return r?e+i:new Yd(e+i,0,null)}touches(e,t){let r=0,i=Qd(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,o)}invert(){return new kg(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 Ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ji(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 Ji(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("addMark",wg);let kg=class _i extends Qe{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 v(df(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Be.fromReplace(e,this.from,this.to,r)}invert(){return new wg(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 _i(t.pos,r.pos,this.mark)}merge(e){return e instanceof _i&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _i(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 _i(t.from,t.to,e.markFromJSON(t.mark))}};Qe.jsonID("removeMark",kg);let vg=class Wi extends Qe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Be.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Be.fromReplace(e,this.pos,this.pos+1,new v(C.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 Qs(t.pos,r.pos,i,o,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 Qs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Qe.jsonID("replaceAround",nk);function bu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function rk(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let o=0;o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}let ik=class Ys extends Qe{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 Be.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Be.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Xr.empty}invert(e){return new Ys(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 Ys(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 Ys(t.pos,t.attr,t.value)}};Qe.jsonID("attr",ik);let wo=class extends Error{};wo=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};wo.prototype=Object.create(Error.prototype);wo.prototype.constructor=wo;wo.prototype.name="TransformError";const ye=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ko=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Iu=null;const _t=function(n,e,t){let r=Iu||(Iu=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ok=function(){Iu=null},sr=function(n,e,t,r){return t&&(Gd(n,e,t,r,-1)||Gd(n,e,t,r,1))},sk=/^(img|br|input|textarea|hr)$/i;function Gd(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:at(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Go(n)||sk.test(n.nodeName)||n.contentEditable=="false")return!1;e=ye(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?at(n):0}else return!1}}function at(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lk(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=at(n)}else if(n.parentNode&&!Go(n))e=ye(n),n=n.parentNode;else return null}}function ak(n,e){for(;;){if(n.nodeType==3&&e2),ot=Zr||(zt?/Mac/.test(zt.platform):!1),dk=zt?/Win/.test(zt.platform):!1,wt=/Android \d/.test(bn),Xo=!!Xd&&"webkitFontSmoothing"in Xd.documentElement.style,hk=Xo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pk(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Bt(n,e){return typeof n=="number"?n:n[e]}function mk(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 Zd(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=ko(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?pk(o):mk(l),c=0,f=0;if(e.topu.bottom-Bt(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+Bt(i,"top")-u.top:e.bottom-u.bottom+Bt(i,"bottom")),e.leftu.right-Bt(r,"right")&&(c=e.right-u.right+Bt(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gk(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Mg(n.dom)}}function Mg(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ko(r));return e}function yk({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Eg(t,r==0?0:r-e)}function Eg(n,e){for(let t=0;t=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=u,r=0),t&&t.nodeType==3?wk(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Og(t,i)}function wk(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function hf(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function kk(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function xk(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dg(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let u;Xo&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.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=xk(n,r,i,e))}l==null&&(l=vk(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function eh(n){return n.top=0&&i==r.nodeValue.length?(a--,c=1):t<0?a--:u++,Si(nn(_t(r,a,u),c),c<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Pa(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==at(r))){let a=r.childNodes[i-1],u=a.nodeType==3?_t(a,at(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Si(nn(u,1),!1)}if(o==null&&i=0)}function Si(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 Pa(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 Rg(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 Mk(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Rg(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Tg(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=_t(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(t=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const Ek=/[\u0590-\u08ac]/;function Ok(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Ek.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Rg(n,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),w=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),w}):r.pos==r.start()||r.pos==r.end()}let th=null,nh=null,rh=!1;function Dk(n,e,t){return th==e&&nh==t?rh:(th=e,nh=t,rh=t=="up"||t=="down"?Mk(n,e,t):Ok(n,e,t))}const ft=0,ih=1,qn=2,Pt=3;let Zo=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ft,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;tye(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 o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.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 o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}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 o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof Pg){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Ag&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ye(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ye(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;cp&&st){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}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+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?qn:ih,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Pt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?qn:Pt}r=s}this.dirty=qn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?qn:ih;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==ft&&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}},Tk=class extends Zo{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}},kl=class Lu extends Zo{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=pi.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Lu(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ft){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Bu(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(t.isText){if(!c)c=document.createTextNode(t.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=pi.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let d=c;return c=$g(c,r,t),u?a=new Rk(e,t,r,i,c,f||null,d,u,o,s+1):t.isText?new Ig(e,t,r,i,c,d,o):new bg(e,t,r,i,c,f||null,d,o,s+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=()=>C.empty)}return e}matchesNode(e,t,r){return this.dirty==ft&&e.eq(this.node)&&Vu(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new bk(this,s&&s.node,e);Pk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==qn)&&(s&&this.protectLocalComposition(e,s),Fg(this.contentDOM,this.children,e),Zr&&Fk(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof $)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Lk(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Tk(this,o,t,i);e.input.compositionNodes.push(s),this.children=Bu(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Pt||!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=ft}updateOuterDeco(e){if(Vu(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Lg(this.dom,this.nodeDOM,$u(this.outerDeco,this.node,t),$u(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 oh(n,e,t,r,i){$g(r,e,n);let o=new Vr(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Ig=class zg extends Vr{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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==Pt||this.dirty!=ft&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ft||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=ft,!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),o=document.createTextNode(i.text);return new zg(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Pt)}get domAtom(){return!1}isText(e){return this.node.text==e}},Pg=class extends Zo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ft&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class Rk extends Vr{constructor(e,t,r,i,o,s,l,a,u,c){super(e,t,r,i,o,s,l,u,c),this.spec=a}update(e,t,r,i){if(this.dirty==Pt)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Fg(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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=kl.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=t.children[r-1];if(u instanceof kl)t=u,r=u.children.length;else{l=u,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function zk(n,e){return n.type.side-e.type.side}function Pk(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let w=h;s!w.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function Fk(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 Lk(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=t)return l+u;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Bu(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||c<=e?o.push(a):(ut&&o.push(a.slice(t-u,a.size,r)))}return o}function pf(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(ea(t)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&I.isSelectable(c)&&i.parent&&!(c.isInline&&uk(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;u=new I(s==f?l:r.resolve(f))}}else{let c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Vg(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Vk(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,ye(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&We&&Sn<=11&&(r.disabled=!0,r.disabled=!1)}function Bg(n,e){if(e instanceof I){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ch(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ch(n)}function ch(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function mf(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function fh(n){return n.editable&&!n.hasFocus()?!1:Jg(n)}function Jg(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 Bk(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return sr(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ju(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&P.findFrom(o,e)}function rn(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function dh(n,e,t){let r=n.state.selection;if(r instanceof $)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return rn(n,new $(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ju(n.state,e);return i&&i instanceof I?rn(n,i):!1}else if(!(ot&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?I.isSelectable(o)?rn(n,new I(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Xo?rn(n,new $(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof I&&r.node.isInline)return rn(n,new $(e>0?r.$to:r.$from));{let i=Ju(n.state,e);return i?rn(n,i):!1}}}function vl(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ro(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Sr(n,e){return e<0?Jk(n):_k(n)}function Jk(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ct&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(ro(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(_g(t))break;{let l=t.previousSibling;for(;l&&ro(l,-1);)i=t.parentNode,o=ye(l),l=l.previousSibling;if(l)t=l,r=vl(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?_u(n,t,r):i&&_u(n,i,o)}function _k(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=vl(t),o,s;for(;;)if(r{n.state==i&&qt(n)},50)}function hh(n,e){let t=n.state.doc.resolve(e);if(!(Me||dk)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ph(n,e,t){let r=n.state.selection;if(r instanceof $&&!r.empty||t.indexOf("s")>-1||ot&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ju(n.state,e);if(s&&s instanceof I)return rn(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof et?P.near(s,e):P.findFrom(s,e);return l?rn(n,l):!1}return!1}function mh(n,e){if(!(n.state.selection instanceof $))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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function gh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Hk(n){if(!be||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;gh(n,r,"true"),setTimeout(()=>gh(n,r,"false"),20)}return!1}function jk(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Kk(n,e){let t=e.keyCode,r=jk(e);if(t==8||ot&&t==72&&r=="c")return mh(n,-1)||Sr(n,-1);if(t==46&&!e.shiftKey||ot&&t==68&&r=="c")return mh(n,1)||Sr(n,1);if(t==13||t==27)return!0;if(t==37||ot&&t==66&&r=="c"){let i=t==37?hh(n,n.state.selection.from)=="ltr"?-1:1:-1;return dh(n,i,r)||Sr(n,i)}else if(t==39||ot&&t==70&&r=="c"){let i=t==39?hh(n,n.state.selection.from)=="ltr"?1:-1:1;return dh(n,i,r)||Sr(n,i)}else{if(t==38||ot&&t==80&&r=="c")return ph(n,-1,r)||Sr(n,-1);if(t==40||ot&&t==78&&r=="c")return Hk(n)||ph(n,1,r)||Sr(n,1);if(r==(ot?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Wg(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||pi.fromSchema(n.state.schema),l=Qg(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=qg[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` -`);return{dom:a,text:d,slice:e}}function Ug(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return e?new v(x.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):v.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,h=pi.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let S=s.appendChild(document.createElement("p"));m&&S.appendChild(h.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=Gk(t),Xo&&Xk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||yo.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!qk.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Zk(yh(l,+c[1],+c[2]),c[4]);else if(l=v.maxOpen(Qk(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,n)}),l}const qk=/^(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 Qk(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&jg(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=Kg(s[s.length-1],o.length));let c=Hg(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return x.from(s)}return n}function Hg(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,x.from(n));return n}function jg(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(x.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function yh(n,e,t){return et}).createHTML(n):n}function Gk(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Qg().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qg[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Yk(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=x.from(a.create(r[l+1],i)),o++,s++}return new v(i,o,s)}const Ie={},ze={},ev={touchstart:!0,touchmove:!0};class tv{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.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function nv(n){for(let e in Ie){let t=Ie[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{iv(n,r)&&!gf(n,r)&&(n.editable||!(r.type in ze))&&t(n,r)},ev[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Uu(n)}function hn(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function rv(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 Uu(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>gf(n,r))})}function gf(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function iv(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 ov(n,e){!gf(n,e)&&Ie[e.type]&&(n.editable||!(e.type in ze))&&Ie[e.type](n,e)}ze.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Gg(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(wt&&Me&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Zr&&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,Kn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Kk(n,t)?t.preventDefault():hn(n,"key")};ze.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ze.keypress=(n,e)=>{let t=e;if(Gg(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ot&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof $)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function ta(n){return{left:n.clientX,top:n.clientY}}function sv(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function yf(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Br(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function lv(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&I.isSelectable(r)?(Br(n,new I(t)),!0):!1}function av(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof I&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(I.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Br(n,I.create(n.state.doc,i)),!0):!1}function uv(n,e,t,r,i){return yf(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?av(n,t):lv(n,t))}function cv(n,e,t,r){return yf(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function fv(n,e,t,r){return yf(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||dv(n,t,r)}function dv(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Br(n,$.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Br(n,$.create(r,l+1,l+1+s.content.size));else if(I.isSelectable(s))Br(n,I.create(r,l));else continue;return!0}}function Sf(n){return xl(n)}const Yg=ot?"metaKey":"ctrlKey";Ie.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Sf(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&sv(t,n.input.lastClick)&&!t[Yg]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(ta(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new hv(n,s,t,!!r)):(o=="doubleClick"?cv:fv)(n,s.pos,s.inside,t)?t.preventDefault():hn(n,"pointer"))};class hv{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[Yg],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let c=e.state.doc.resolve(t.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof I&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ct&&!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)),hn(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(()=>qt(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(ta(e))),this.updateAllowDefault(e),this.allowDefault||!t?hn(this.view,"pointer"):uv(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||Me&&!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)?(Br(this.view,P.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):hn(this.view,"pointer")}move(e){this.updateAllowDefault(e),hn(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)}}Ie.touchstart=n=>{n.input.lastTouch=Date.now(),Sf(n),hn(n,"pointer")};Ie.touchmove=n=>{n.input.lastTouch=Date.now(),hn(n,"pointer")};Ie.contextmenu=n=>Sf(n);function Gg(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const pv=wt?5e3:-1;ze.compositionstart=ze.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof $&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),xl(n,!0),n.markCursor=null;else if(xl(n,!e.selection.empty),Ct&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Xg(n,pv)};ze.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Xg(n,20))};function Xg(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>xl(n),e))}function Zg(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=gv());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function mv(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lk(e.focusNode,e.focusOffset),r=ak(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function gv(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function xl(n,e=!1){if(!(wt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Zg(n),e||n.docView&&n.docView.dirty){let t=pf(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function yv(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 vo=We&&Sn<15||Zr&&hk<604;Ie.copy=ze.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=vo?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Wg(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):yv(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Sv(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function wv(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?xo(n,r.value,null,i,e):xo(n,r.textContent,r.innerHTML,i,e)},50)}function xo(n,e,t,r,i){let o=Ug(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||v.empty)))return!0;if(!o)return!1;let s=Sv(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ey(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ze.paste=(n,e)=>{let t=e;if(n.composing&&!wt)return;let r=vo?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&xo(n,ey(r),r.getData("text/html"),i,t)?t.preventDefault():wv(n,t)};class ty{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const ny=ot?"altKey":"ctrlKey";Ie.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(ta(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof I?i.to-1:i.to))){if(r&&r.mightDrag)s=I.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=I.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:u,slice:c}=Wg(n,l);(!t.dataTransfer.files.length||!Me||Ng>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(vo?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",vo||t.dataTransfer.setData("text/plain",u),n.dragging=new ty(c,!t[ny],s)};Ie.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ze.dragover=ze.dragenter=(n,e)=>e.preventDefault();ze.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(ta(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",h=>{s=h(s,n)}):s=Ug(n,ey(t.dataTransfer),vo?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[ny]);if(n.someProp("handleDrop",h=>h(n,t,s||v.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?rk(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=n.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&I.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new I(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,S,g,y)=>h=y),u.setSelection(mf(n,p,u.doc.resolve(h)))}n.focus(),n.dispatch(u.setMeta("uiEvent","drop"))};Ie.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())&&qt(n)},20))};Ie.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)};Ie.beforeinput=(n,e)=>{if(Me&&wt&&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",o=>o(n,Kn(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 ze)Ie[n]=ze[n];function Co(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 Cl{constructor(e,t){this.toDOM=e,this.spec=t||tr,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Cl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Co(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class wn{constructor(e,t){this.attrs=e,this.spec=t||tr}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new Se(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==Ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||tr)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=oy(t,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof wn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,t,tr));return Mr.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let S=m-h-(p-d);for(let g=0;gy+c-f)continue;let w=l[g]+c-f;p>=w?l[g+1]=d<=w?-2:-1:d>=c&&S&&(l[g]+=S,l[g+1]+=S)}f+=S}),c=t.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=t.map(n[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),S=r.maybeChild(h);if(S&&m==f&&m+S.nodeSize==p){let g=l[u+2].mapInner(t,S,c+1,n[u]+o+1,s);g!=Ce?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=vv(l,n,e,t,i,o,s),c=Nl(u,r,0,s);e=c.local;for(let f=0;ft&&s.to{let u=oy(n,l,a+t);if(u){o=!0;let c=Nl(u,l,t+a+1,r);c!=Ce&&i.push(a,a+l.nodeSize,c)}});let s=iy(o?sy(n):n,-t).sort(nr);for(let l=0;l0;)e++;n.splice(e,0,t)}function La(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=Ce&&e.push(r)}),n.cursorWrapper&&e.push(_.create(n.state.doc,[n.cursorWrapper.deco])),ry.from(e)}const xv={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Cv=We&&Sn<=11;let Nv=class{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 Mv{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Nv,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Cv&&(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,xv)),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(fh(this.view)){if(this.suppressingSelectionUpdates)return qt(this.view);if(We&&Sn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&sr(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 o=e.focusNode;o;o=ko(o))t.add(o);for(let o=e.anchorNode;o;o=ko(o))if(t.has(o)){r=o;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}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&fh(this.view)&&!this.ignoreSelectionChange(e)}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.selectionChanged(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;cf.nodeName=="BR");if(c.length==2){let[f,d]=c;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of c){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||Dv(e,f)!=p)&&d.remove()}}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),Ev(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||qt(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 c=0;ci;S--){let g=r.childNodes[S-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=S;break}if(!y||y.size)break}let f=n.state.doc,d=n.someProp("domParser")||yo.fromSchema(n.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:Rv,context:p});if(u&&u[0].pos!=null){let S=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=S),h={anchor:S+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function Rv(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(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||be&&/^(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 Av=/^(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 bv(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let b=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,z=pf(n,b);if(z&&!n.state.selection.eq(z)){if(Me&&wt&&n.input.lastKeyCode===13&&Date.now()-100Vt(n,Kn(13,"Enter"))))return;let ae=n.state.tr.setSelection(z);b=="pointer"?ae.setMeta("pointer",!0):b=="key"&&ae.scrollIntoView(),o&&ae.setMeta("composition",o),n.dispatch(ae)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,u=Tv(n,e,t),c=n.state.doc,f=c.slice(u.from,u.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||wt)&&i.some(b=>b.nodeType==1&&!Av.test(b.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",b=>b(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof $&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let b=Ch(n,n.state.doc,u.sel);if(b&&!b.eq(n.state.selection)){let z=n.state.tr.setSelection(b);o&&z.setMeta("composition",o),n.dispatch(z)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=u.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=u.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),We&&Sn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),S=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(S)&&m.parent.inlineContent&&g.end()>=h.endA,w;if((Zr&&n.input.lastIOSEnter>Date.now()-225&&(!y||i.some(b=>b.nodeName=="DIV"||b.nodeName=="P"))||!y&&m.posb(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&zv(c,h.start,h.endA,m,S)&&n.someProp("handleKeyDown",b=>b(n,Kn(8,"Backspace")))){wt&&Me&&n.domObserver.suppressSelectionUpdates();return}Me&&wt&&h.endB==h.start&&(n.input.lastAndroidDelete=Date.now()),wt&&!y&&m.start()!=S.start()&&S.parentOffset==0&&m.depth==S.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,S=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{n.someProp("handleKeyDown",function(b){return b(n,Kn(13,"Enter"))})},20));let C=h.start,M=h.endA,N,O,D;if(y){if(m.pos==S.pos)We&&Sn<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>qt(n),20)),N=n.state.tr.delete(C,M),O=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(D=Iv(m.parent.content.cut(m.parentOffset,S.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))N=n.state.tr,D.type=="add"?N.addMark(C,M,D.mark):N.removeMark(C,M,D.mark);else if(m.parent.child(m.index()).isText&&m.index()==S.index()-(S.textOffset?0:1)){let b=m.parent.textBetween(m.parentOffset,S.parentOffset);if(n.someProp("handleTextInput",z=>z(n,C,M,b)))return;N=n.state.tr.insertText(b,C,M)}}if(N||(N=n.state.tr.replace(C,M,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let b=Ch(n,N.doc,u.sel);b&&!(Me&&wt&&n.composing&&b.empty&&(h.start!=h.endB||n.input.lastAndroidDeletee.content.size?null:mf(n,e.resolve(t.anchor),e.resolve(t.head))}function Iv(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;ct||$a(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Pv(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}class Fv{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 tv,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Th),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=Oh(this),Eh(this),this.nodeViews=Dh(this),this.docView=oh(this.state.doc,Mh(this),La(this),this.dom,this),this.domObserver=new Mv(this,(r,i,o,s)=>bv(this,r,i,o,s)),this.domObserver.start(),nv(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&&Uu(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Th),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Zg(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Dh(this);$v(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Uu(this),this.editable=Oh(this),Eh(this);let a=La(this),u=Mh(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gk(this);if(s){this.domObserver.stop();let p=f&&(We||Me)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Lv(i.selection,e.selection);if(f){let h=Me?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=mv(this)),(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=oh(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bk(this))?qt(this,p):(Bg(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&yk(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof I){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Zd(this,t.getBoundingClientRect(),e)}else Zd(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ty(e.slice,e.move,i<0?void 0:I.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ck(this,e)}coordsAtPos(e,t=1){return Tg(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 Dk(this,t||this.state,e)}pasteHTML(e,t){return xo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xo(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(rv(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],La(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ok())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ov(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?be&&this.root.nodeType===11&&ck(this.dom.ownerDocument)==this.dom&&Ov(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Mh(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"),[Se.node(0,n.state.doc.content.size,e)]}function Eh(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:Se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Oh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Lv(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 Dh(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 $v(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 Th(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")}class ee extends P{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return ee.valid(r)?new ee(r):P.near(r)}content(){return v.empty}eq(e){return e instanceof ee&&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 ee(e.resolve(t.pos))}getBookmark(){return new vf(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Vv(e)||!Bv(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&&ee.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(ee.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!I.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(ee.valid(l))return l}return null}}}ee.prototype.visible=!1;ee.findFrom=ee.findGapCursorFrom;P.jsonID("gapcursor",ee);class vf{constructor(e){this.pos=e}map(e){return new vf(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ee.valid(t)?new ee(t):P.near(t)}}function Vv(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 Bv(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 Jv(){return new $t({props:{decorations:Hv,createSelectionBetween(n,e,t){return e.pos==t.pos&&ee.valid(t)?new ee(t):null},handleClick:Wv,handleKeyDown:_v,handleDOMEvents:{beforeinput:Uv}}})}const _v=Xw({ArrowLeft:ps("horiz",-1),ArrowRight:ps("horiz",1),ArrowUp:ps("vert",-1),ArrowDown:ps("vert",1)});function ps(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof $){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=ee.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new ee(u))),!0):!1}}function Wv(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!ee.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&I.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ee(r))),!0)}function Uv(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ee))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=x.empty;for(let s=r.length-1;s>=0;s--)i=x.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new v(i,0,0));return o.setSelection($.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Hv(n){if(!(n.selection instanceof ee))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",_.create(n.doc,[Se.widget(n.selection.head,e,{key:"gapcursor"})])}const ly=65535,ay=Math.pow(2,16);function jv(n,e){return n+e*ay}function Rh(n){return n&ly}function Kv(n){return(n-(n&ly))/ay}const uy=1,cy=2,Gs=4,fy=8;let Ah=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&fy)>0}get deletedBefore(){return(this.delInfo&(uy|Gs))>0}get deletedAfter(){return(this.delInfo&(cy|Gs))>0}get deletedAcross(){return(this.delInfo&Gs)>0}},ei=class Er{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Er.empty)return Er.empty}recover(e){let t=0,r=Rh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:jv(l/3,e-a),m=e==a?cy:e==f?uy:Gs;return(t<0?e!=a:e!=f)&&(m|=fy),new Ah(p,m,h)}i+=c-u}return r?e+i:new Ah(e+i,0,null)}touches(e,t){let r=0,i=Rh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,o)}invert(){return new hy(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 Hi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Hi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Hi(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 Hi(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("addMark",dy);let hy=class ji extends Ye{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 v(xf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,r)}invert(){return new dy(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 ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ji(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 ji(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("removeMark",hy);let py=class Ki extends Ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Je.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Je.fromReplace(e,this.pos,this.pos+1,new v(x.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 Xs(t.pos,r.pos,i,o,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 Xs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ye.jsonID("replaceAround",Qv);function ju(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Yv(n,e,t=null,r=n){let i=Gv(n,e),o=i&&Xv(r,e);return o?i.map(bh).concat({type:e,attrs:t}).concat(o.map(bh)):null}function bh(n){return{type:n,attrs:null}}function Gv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return t.canReplaceWith(r,i,s)?o:null}function Xv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:e).contentMatch;for(let u=r;a&&u0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const rx=500;function ix({rules:n}){let e=new $t({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Ih(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Ih(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function Ih(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-rx),l.parentOffset,null,"")+r;for(let u=0;u{let a=t instanceof Function?t(o):t,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&Yv(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Zv(u.doc,s-1)&&!r&&u.join(s-1),u})}const sx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function lx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ba(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const fx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function dx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ja(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const gy=65535,yy=Math.pow(2,16);function mx(n,e){return n+e*yy}function zh(n){return n&gy}function gx(n){return(n-(n&gy))/yy}const Sy=1,wy=2,el=4,ky=8;class Ku{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&ky)>0}get deletedBefore(){return(this.delInfo&(Sy|el))>0}get deletedAfter(){return(this.delInfo&(wy|el))>0}get deletedAcross(){return(this.delInfo&el)>0}}class Xe{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Xe.empty)return Xe.empty}recover(e){let t=0,r=zh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:mx(l/3,e-a),m=e==a?wy:e==f?Sy:el;return(t<0?e!=a:e!=f)&&(m|=ky),new Ku(p,m,h)}i+=c-u}return r?e+i:new Ku(e+i,0,null)}touches(e,t){let r=0,i=zh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=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 io;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new Dt(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 pn(t.pos,r.pos,this.mark)}merge(e){return e instanceof pn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new pn(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 pn(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("addMark",pn);class Dt extends De{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 v(Cf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new pn(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 Dt(t.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(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 Dt(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("removeMark",Dt);class mn extends De{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return oe.fromReplace(e,this.pos,this.pos+1,new v(x.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 Rt(t.pos,r.pos,i,o,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 Rt(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}}De.jsonID("replaceAround",Rt);function qu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function yx(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function Sx(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Dt(s.from,s.to,s.style)))}function wx(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function kx(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=x.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=x.from(r.node(h).copy(c)),f++):a--;let d=x.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].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=x.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new Rt(i,o,i,o,new v(r,0,0),t.length,!0))}function xx(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Cx(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new Rt(u,c,u+1,c-1,new v(x.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Cx(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Nx(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Rt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(x.from(s),0,0),1,!0))}function Mx(n,e,t=1,r){let i=n.doc.resolve(e),o=x.empty,s=x.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=x.from(i.node(l).copy(o));let c=r&&r[u];s=x.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new Re(e,e,new v(o.append(s),t,t),!0))}function Ex(n,e,t){let r=new Re(e-t,e+t,v.empty,!0);n.step(r)}function Ox(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 o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=x.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Rt(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new Re(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Wa(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(x.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wa(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Wa(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(qi(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(qi(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=S,c.push(xy(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Qi(this.placed,t,x.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,S=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Ua(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=Qi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Qi(this.placed,this.depth,x.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(x.empty,!0);t.childCount&&(this.placed=Qi(this.placed,this.frontier.length,t))}}function qi(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(qi(n.firstChild.content,e-1,t)))}function Qi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Qi(n.lastChild.content,e-1,t)))}function Wa(n,e){for(let t=0;t1&&(r=r.replaceChild(0,xy(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(x.empty,!0)))),n.copy(r)}function Ua(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Rx(t,o.content,s)?l:null}function Rx(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=Ax(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function Cy(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(x.empty,!0))}return n}function Ix(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Ox(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(x.from(r),0,0))}function zx(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ny(r,i);for(let s=0;s0&&(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 s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function Ny(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}class Jr extends De{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 oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return oe.fromReplace(e,this.pos,this.pos+1,new v(x.from(i),0,t.isLeaf?0:1))}getMap(){return Xe.empty}invert(e){return new Jr(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 Jr(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 Jr(t.pos,t.attr,t.value)}}De.jsonID("attr",Jr);class Mo extends De{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 oe.ok(r)}getMap(){return Xe.empty}invert(e){return new Mo(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 Mo(t.attr,t.value)}}De.jsonID("docAttr",Mo);let ni=class extends Error{};ni=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ni.prototype=Object.create(Error.prototype);ni.prototype.constructor=ni;ni.prototype.name="TransformError";class Px{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new io}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ni(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=v.empty){let i=Dx(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(x.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return bx(this,e,t,r),this}replaceRangeWith(e,t,r){return Ix(this,e,t,r),this}deleteRange(e,t){return zx(this,e,t),this}lift(e,t){return kx(this,e,t),this}join(e,t=1){return Ex(this,e,t),this}wrap(e,t){return vx(this,e,t),this}setBlockType(e,t=e,r,i=null){return xx(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Nx(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Jr(e,t,r)),this}setDocAttribute(e,t){return this.step(new Mo(e,t)),this}addNodeMark(e,t){return this.step(new mn(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){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 ti(e,t)),this}split(e,t=1,r){return Mx(this,e,t,r),this}addMark(e,t,r){return yx(this,e,t,r),this}removeMark(e,t,r){return Sx(this,e,t,r),this}clearIncompatible(e,t,r){return wx(this,e,t,r),this}}var Qu,Yu;if(typeof WeakMap<"u"){let n=new WeakMap;Qu=e=>n.get(e),Yu=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;Qu=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var re=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-w});break}const C=i+w*e;for(let M=0;Mr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function $x(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(n);a!=null&&(o[s]=a)}return o}function Fh(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Bx(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Ph(r,e)}],toDOM(r){return["td",Fh(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Ph(r,e)}],toDOM(r){return["th",Fh(r,e),0]}}}}function Ft(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var an=new Yo("selectingCells");function es(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Nf(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function My(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=es(e.$head)||Jx(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Jx(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Gu(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Mf(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ey(n,e,t){const r=n.node(-1),i=re.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}function ri(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var fe=class Jt extends P{constructor(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,t.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=t.pos-o);a.unshift(t.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new og(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Gu(r)&&Gu(i)&&Mf(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Jt.rowSelection(r,i):o&&this.isColSelection()?Jt.colSelection(r,i):new Jt(r,i)}return $.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=re.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||S>0){let g=h.attrs;if(m>0&&(g=ri(g,0,m)),S>0&&(g=ri(g,g.colspan-S,S)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(t=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof Jt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(t=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(Se.node(r,r+t.nodeSize,{class:"selectedCell"}))}),_.create(n.doc,e)}function Ux({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Hx({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function jx(n,e,t){const r=(e||n).selection,i=(e||n).doc;let o,s;if(r instanceof I&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=fe.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=fe.rowSelection(l,l)}else if(!t){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=fe.create(i,a+1,u)}}else r instanceof $&&Ux(r)?o=$.create(i,r.from):r instanceof $&&Hx(r)&&(o=$.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var Kx=new Yo("fix-tables");function Dy(n,e,t,r){const i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=Qx(n,i,o,t))};return e?e.doc!=n.doc&&Dy(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qx(n,e,t,r){const i=re.get(e);if(!i.problems)return r;r||(r=n.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let S=0;S0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(x.empty),t[i]r&&(d=d.type.createChecked(ri(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(x.from(a))}t=o,e=i}return{width:n,height:e,rows:t}}function Zx(n,e,t,r,i,o,s){const l=n.doc.type.schema,a=Ft(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:t.nodeAt(e.map[m+h]).type==a.header_cell;f.push(S?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,x.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=t.selection;if(o instanceof fe)return tl(t,r,P.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;const s=Ty(i,n,e);if(s==null)return!1;if(n=="horiz")return tl(t,r,P.near(t.doc.resolve(o.head+e),e));{const l=t.doc.resolve(s),a=Ey(l,n,e);let u;return a?u=P.near(a,1):e<0?u=P.near(t.doc.resolve(l.before(-1)),-1):u=P.near(t.doc.resolve(l.after(-1)),1),tl(t,r,u)}}}function gs(n,e){return(t,r,i)=>{if(!i)return!1;const o=t.selection;let s;if(o instanceof fe)s=o;else{const a=Ty(i,n,e);if(a==null)return!1;s=new fe(t.doc.resolve(a))}const l=Ey(s.$headCell,n,e);return l?tl(t,r,new fe(s.$anchorCell,l)):!1}}function ys(n,e){const t=n.selection;if(!(t instanceof fe))return!1;if(e){const r=n.tr,i=Ft(n.schema).cell.createAndFill().content;t.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new v(i,0,0))}),r.docChanged&&e(r)}return!0}function tC(n,e){const t=n.state.doc,r=es(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new fe(r))),!0):!1}function nC(n,e,t){if(!Nf(n.state))return!1;let r=Yx(t);const i=n.state.selection;if(i instanceof fe){r||(r={width:1,height:1,rows:[x.from(Xu(Ft(n.state.schema).cell,t))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Xx(r,l.right-l.left,l.bottom-l.top),Vh(n.state,n.dispatch,s,l,r),!0}else if(r){const o=My(n.state),s=o.start(-1);return Vh(n.state,n.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function rC(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=Bh(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof fe)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=es(n.state.selection.$anchor))!=null&&((t=Ha(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Ha(n,u);const f=an.getState(n.state)==null;if(!c||!Mf(a,c))if(f)c=a;else return;const d=new fe(a,c);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(an,a.pos),n.dispatch(p)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",l),an.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(an,-1))}function l(a){const u=a,c=an.getState(n.state);let f;if(c!=null)f=n.state.doc.resolve(c);else if(Bh(n,u.target)!=r&&(f=Ha(n,e),!f))return s();f&&o(f,u)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function Ty(n,e,t){if(!(n.state.selection instanceof $))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Bh(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ha(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?es(n.state.doc.resolve(t.pos)):null}var iC=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Zu(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Zu(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Zu(n,e,t,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=n.firstChild;if(c){for(let f=0,d=0;fnew t(l,e,a),new sC(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=ut.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{lC(o,s,n,e,r)},mouseleave:o=>{aC(o)},mousedown:(o,s)=>{uC(o,s,e)}},decorations:o=>{const s=ut.getState(o);if(s&&s.activeHandle>-1)return mC(o,s.activeHandle)},nodeViews:{}}});return i}var sC=class nl{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(ut);if(r&&r.setHandle!=null)return new nl(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new nl(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Gu(e.doc.resolve(i))||(i=-1),new nl(i,t.dragging)}return t}};function lC(n,e,t,r,i){const o=ut.getState(n.state);if(o&&!o.dragging){const s=fC(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=t?l=Jh(n,e,"left",t):u-e.clientX<=t&&(l=Jh(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=n.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ry(n,l)}}}function aC(n){const e=ut.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ry(n,-1)}function uC(n,e,t){var r;const i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=ut.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=n.state.doc.nodeAt(o.activeHandle),l=cC(n,o.activeHandle,s.attrs);n.dispatch(n.state.tr.setMeta(ut,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=ut.getState(n.state);f!=null&&f.dragging&&(dC(n,f.activeHandle,_h(f.dragging,c,t)),n.dispatch(n.state.tr.setMeta(ut,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=ut.getState(n.state);if(f&&f.dragging){const d=_h(f.dragging,c,t);hC(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function cC(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=n.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=t;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}Ef("row",{useDeprecatedLogic:!0});Ef("column",{useDeprecatedLogic:!0});Ef("cell",{useDeprecatedLogic:!0});function yC({allowTableNodeSelection:n=!1}={}){return new $t({key:an,state:{init(){return null},apply(e,t){const r=e.getMeta(an);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:o}=e.mapping.mapResult(t);return i?null:o}},props:{decorations:Wx,handleDOMEvents:{mousedown:rC},createSelectionBetween(e){return an.getState(e.state)!=null?e.state.selection:null},handleTripleClick:tC,handleKeyDown:eC,handlePaste:nC},appendTransaction(e,t,r){return jx(r,qx(r,t),n)}})}var by={exports:{}},rt={},Iy={exports:{}},zy={};/** +`);return{dom:a,text:d,slice:e}}function Ug(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return e?new v(C.from(n.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):v.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,h=pi.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let w=s.appendChild(document.createElement("p"));m&&w.appendChild(h.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=Gk(t),Xo&&Xk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||yo.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!qk.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Zk(yh(l,+c[1],+c[2]),c[4]);else if(l=v.maxOpen(Qk(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,n)}),l}const qk=/^(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 Qk(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&jg(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=Kg(s[s.length-1],o.length));let c=Hg(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return C.from(s)}return n}function Hg(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,C.from(n));return n}function jg(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(C.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function yh(n,e,t){return et}).createHTML(n):n}function Gk(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Qg().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qg[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Yk(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=C.from(a.create(r[l+1],i)),o++,s++}return new v(i,o,s)}const Ie={},ze={},ev={touchstart:!0,touchmove:!0};class tv{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.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function nv(n){for(let e in Ie){let t=Ie[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{iv(n,r)&&!gf(n,r)&&(n.editable||!(r.type in ze))&&t(n,r)},ev[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Uu(n)}function hn(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function rv(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 Uu(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>gf(n,r))})}function gf(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function iv(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 ov(n,e){!gf(n,e)&&Ie[e.type]&&(n.editable||!(e.type in ze))&&Ie[e.type](n,e)}ze.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Gg(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(wt&&Me&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Zr&&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,Kn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Kk(n,t)?t.preventDefault():hn(n,"key")};ze.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ze.keypress=(n,e)=>{let t=e;if(Gg(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ot&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof $)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function ta(n){return{left:n.clientX,top:n.clientY}}function sv(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function yf(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Br(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function lv(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&I.isSelectable(r)?(Br(n,new I(t)),!0):!1}function av(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof I&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(I.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Br(n,I.create(n.state.doc,i)),!0):!1}function uv(n,e,t,r,i){return yf(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?av(n,t):lv(n,t))}function cv(n,e,t,r){return yf(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function fv(n,e,t,r){return yf(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||dv(n,t,r)}function dv(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Br(n,$.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Br(n,$.create(r,l+1,l+1+s.content.size));else if(I.isSelectable(s))Br(n,I.create(r,l));else continue;return!0}}function Sf(n){return xl(n)}const Yg=ot?"metaKey":"ctrlKey";Ie.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Sf(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&sv(t,n.input.lastClick)&&!t[Yg]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(ta(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new hv(n,s,t,!!r)):(o=="doubleClick"?cv:fv)(n,s.pos,s.inside,t)?t.preventDefault():hn(n,"pointer"))};class hv{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[Yg],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let c=e.state.doc.resolve(t.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof I&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ct&&!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)),hn(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(()=>qt(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(ta(e))),this.updateAllowDefault(e),this.allowDefault||!t?hn(this.view,"pointer"):uv(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||Me&&!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)?(Br(this.view,P.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):hn(this.view,"pointer")}move(e){this.updateAllowDefault(e),hn(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)}}Ie.touchstart=n=>{n.input.lastTouch=Date.now(),Sf(n),hn(n,"pointer")};Ie.touchmove=n=>{n.input.lastTouch=Date.now(),hn(n,"pointer")};Ie.contextmenu=n=>Sf(n);function Gg(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const pv=wt?5e3:-1;ze.compositionstart=ze.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof $&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),xl(n,!0),n.markCursor=null;else if(xl(n,!e.selection.empty),Ct&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Xg(n,pv)};ze.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Xg(n,20))};function Xg(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>xl(n),e))}function Zg(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=gv());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function mv(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lk(e.focusNode,e.focusOffset),r=ak(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function gv(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function xl(n,e=!1){if(!(wt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Zg(n),e||n.docView&&n.docView.dirty){let t=pf(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function yv(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 vo=We&&Sn<15||Zr&&hk<604;Ie.copy=ze.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=vo?null:t.clipboardData,s=r.content(),{dom:l,text:a}=Wg(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):yv(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Sv(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function wv(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?xo(n,r.value,null,i,e):xo(n,r.textContent,r.innerHTML,i,e)},50)}function xo(n,e,t,r,i){let o=Ug(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||v.empty)))return!0;if(!o)return!1;let s=Sv(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ey(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ze.paste=(n,e)=>{let t=e;if(n.composing&&!wt)return;let r=vo?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&xo(n,ey(r),r.getData("text/html"),i,t)?t.preventDefault():wv(n,t)};class ty{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const ny=ot?"altKey":"ctrlKey";Ie.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(ta(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof I?i.to-1:i.to))){if(r&&r.mightDrag)s=I.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=I.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:u,slice:c}=Wg(n,l);(!t.dataTransfer.files.length||!Me||Ng>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(vo?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",vo||t.dataTransfer.setData("text/plain",u),n.dragging=new ty(c,!t[ny],s)};Ie.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ze.dragover=ze.dragenter=(n,e)=>e.preventDefault();ze.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(ta(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",h=>{s=h(s,n)}):s=Ug(n,ey(t.dataTransfer),vo?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[ny]);if(n.someProp("handleDrop",h=>h(n,t,s||v.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?rk(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=n.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&I.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new I(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,w,g,y)=>h=y),u.setSelection(mf(n,p,u.doc.resolve(h)))}n.focus(),n.dispatch(u.setMeta("uiEvent","drop"))};Ie.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())&&qt(n)},20))};Ie.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)};Ie.beforeinput=(n,e)=>{if(Me&&wt&&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",o=>o(n,Kn(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 ze)Ie[n]=ze[n];function Co(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 Cl{constructor(e,t){this.toDOM=e,this.spec=t||tr,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Cl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Co(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class wn{constructor(e,t){this.attrs=e,this.spec=t||tr}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new Se(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==Ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||tr)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=oy(t,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof wn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,t,tr));return Mr.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let w=m-h-(p-d);for(let g=0;gy+c-f)continue;let S=l[g]+c-f;p>=S?l[g+1]=d<=S?-2:-1:d>=c&&w&&(l[g]+=w,l[g+1]+=w)}f+=w}),c=t.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=t.map(n[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),w=r.maybeChild(h);if(w&&m==f&&m+w.nodeSize==p){let g=l[u+2].mapInner(t,w,c+1,n[u]+o+1,s);g!=Ce?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=vv(l,n,e,t,i,o,s),c=Nl(u,r,0,s);e=c.local;for(let f=0;ft&&s.to{let u=oy(n,l,a+t);if(u){o=!0;let c=Nl(u,l,t+a+1,r);c!=Ce&&i.push(a,a+l.nodeSize,c)}});let s=iy(o?sy(n):n,-t).sort(nr);for(let l=0;l0;)e++;n.splice(e,0,t)}function La(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=Ce&&e.push(r)}),n.cursorWrapper&&e.push(_.create(n.state.doc,[n.cursorWrapper.deco])),ry.from(e)}const xv={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Cv=We&&Sn<=11;let Nv=class{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 Mv{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Nv,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Cv&&(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,xv)),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(fh(this.view)){if(this.suppressingSelectionUpdates)return qt(this.view);if(We&&Sn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&sr(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 o=e.focusNode;o;o=ko(o))t.add(o);for(let o=e.anchorNode;o;o=ko(o))if(t.has(o)){r=o;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}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&fh(this.view)&&!this.ignoreSelectionChange(e)}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.selectionChanged(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;cf.nodeName=="BR");if(c.length==2){let[f,d]=c;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of c){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||Dv(e,f)!=p)&&d.remove()}}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),Ev(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||qt(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 c=0;ci;w--){let g=r.childNodes[w-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=w;break}if(!y||y.size)break}let f=n.state.doc,d=n.someProp("domParser")||yo.fromSchema(n.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:Rv,context:p});if(u&&u[0].pos!=null){let w=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=w),h={anchor:w+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function Rv(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(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||be&&/^(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 Av=/^(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 bv(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let b=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,z=pf(n,b);if(z&&!n.state.selection.eq(z)){if(Me&&wt&&n.input.lastKeyCode===13&&Date.now()-100Vt(n,Kn(13,"Enter"))))return;let ae=n.state.tr.setSelection(z);b=="pointer"?ae.setMeta("pointer",!0):b=="key"&&ae.scrollIntoView(),o&&ae.setMeta("composition",o),n.dispatch(ae)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,u=Tv(n,e,t),c=n.state.doc,f=c.slice(u.from,u.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||wt)&&i.some(b=>b.nodeType==1&&!Av.test(b.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",b=>b(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof $&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let b=Ch(n,n.state.doc,u.sel);if(b&&!b.eq(n.state.selection)){let z=n.state.tr.setSelection(b);o&&z.setMeta("composition",o),n.dispatch(z)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=u.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=u.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),We&&Sn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),w=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(w)&&m.parent.inlineContent&&g.end()>=h.endA,S;if((Zr&&n.input.lastIOSEnter>Date.now()-225&&(!y||i.some(b=>b.nodeName=="DIV"||b.nodeName=="P"))||!y&&m.posb(n,Kn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&zv(c,h.start,h.endA,m,w)&&n.someProp("handleKeyDown",b=>b(n,Kn(8,"Backspace")))){wt&&Me&&n.domObserver.suppressSelectionUpdates();return}Me&&wt&&h.endB==h.start&&(n.input.lastAndroidDelete=Date.now()),wt&&!y&&m.start()!=w.start()&&w.parentOffset==0&&m.depth==w.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,w=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{n.someProp("handleKeyDown",function(b){return b(n,Kn(13,"Enter"))})},20));let x=h.start,N=h.endA,M,O,D;if(y){if(m.pos==w.pos)We&&Sn<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>qt(n),20)),M=n.state.tr.delete(x,N),O=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(D=Iv(m.parent.content.cut(m.parentOffset,w.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))M=n.state.tr,D.type=="add"?M.addMark(x,N,D.mark):M.removeMark(x,N,D.mark);else if(m.parent.child(m.index()).isText&&m.index()==w.index()-(w.textOffset?0:1)){let b=m.parent.textBetween(m.parentOffset,w.parentOffset);if(n.someProp("handleTextInput",z=>z(n,x,N,b)))return;M=n.state.tr.insertText(b,x,N)}}if(M||(M=n.state.tr.replace(x,N,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let b=Ch(n,M.doc,u.sel);b&&!(Me&&wt&&n.composing&&b.empty&&(h.start!=h.endB||n.input.lastAndroidDeletee.content.size?null:mf(n,e.resolve(t.anchor),e.resolve(t.head))}function Iv(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;ct||$a(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Pv(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}class Fv{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 tv,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Th),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=Oh(this),Eh(this),this.nodeViews=Dh(this),this.docView=oh(this.state.doc,Mh(this),La(this),this.dom,this),this.domObserver=new Mv(this,(r,i,o,s)=>bv(this,r,i,o,s)),this.domObserver.start(),nv(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&&Uu(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Th),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Zg(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Dh(this);$v(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Uu(this),this.editable=Oh(this),Eh(this);let a=La(this),u=Mh(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gk(this);if(s){this.domObserver.stop();let p=f&&(We||Me)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Lv(i.selection,e.selection);if(f){let h=Me?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=mv(this)),(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=oh(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bk(this))?qt(this,p):(Bg(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&yk(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof I){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Zd(this,t.getBoundingClientRect(),e)}else Zd(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new ty(e.slice,e.move,i<0?void 0:I.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ck(this,e)}coordsAtPos(e,t=1){return Tg(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 Dk(this,t||this.state,e)}pasteHTML(e,t){return xo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xo(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(rv(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],La(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ok())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ov(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?be&&this.root.nodeType===11&&ck(this.dom.ownerDocument)==this.dom&&Ov(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Mh(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"),[Se.node(0,n.state.doc.content.size,e)]}function Eh(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:Se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Oh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Lv(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 Dh(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 $v(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 Th(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")}class ee extends P{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return ee.valid(r)?new ee(r):P.near(r)}content(){return v.empty}eq(e){return e instanceof ee&&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 ee(e.resolve(t.pos))}getBookmark(){return new vf(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Vv(e)||!Bv(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&&ee.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let a=e.doc.resolve(i);if(ee.valid(a))return a}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!I.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,i+=t;let l=e.doc.resolve(i);if(ee.valid(l))return l}return null}}}ee.prototype.visible=!1;ee.findFrom=ee.findGapCursorFrom;P.jsonID("gapcursor",ee);class vf{constructor(e){this.pos=e}map(e){return new vf(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ee.valid(t)?new ee(t):P.near(t)}}function Vv(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 Bv(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 Jv(){return new $t({props:{decorations:Hv,createSelectionBetween(n,e,t){return e.pos==t.pos&&ee.valid(t)?new ee(t):null},handleClick:Wv,handleKeyDown:_v,handleDOMEvents:{beforeinput:Uv}}})}const _v=Xw({ArrowLeft:ps("horiz",-1),ArrowRight:ps("horiz",1),ArrowUp:ps("vert",-1),ArrowDown:ps("vert",1)});function ps(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof $){if(!o.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=ee.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new ee(u))),!0):!1}}function Wv(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!ee.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&I.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ee(r))),!0)}function Uv(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ee))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=C.empty;for(let s=r.length-1;s>=0;s--)i=C.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new v(i,0,0));return o.setSelection($.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Hv(n){if(!(n.selection instanceof ee))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",_.create(n.doc,[Se.widget(n.selection.head,e,{key:"gapcursor"})])}const ly=65535,ay=Math.pow(2,16);function jv(n,e){return n+e*ay}function Rh(n){return n&ly}function Kv(n){return(n-(n&ly))/ay}const uy=1,cy=2,Gs=4,fy=8;let Ah=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&fy)>0}get deletedBefore(){return(this.delInfo&(uy|Gs))>0}get deletedAfter(){return(this.delInfo&(cy|Gs))>0}get deletedAcross(){return(this.delInfo&Gs)>0}},ei=class Er{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Er.empty)return Er.empty}recover(e){let t=0,r=Rh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:jv(l/3,e-a),m=e==a?cy:e==f?uy:Gs;return(t<0?e!=a:e!=f)&&(m|=fy),new Ah(p,m,h)}i+=c-u}return r?e+i:new Ah(e+i,0,null)}touches(e,t){let r=0,i=Rh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,o)}invert(){return new hy(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 Hi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Hi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Hi(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 Hi(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("addMark",dy);let hy=class ji extends Ye{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 v(xf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Je.fromReplace(e,this.from,this.to,r)}invert(){return new dy(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 ji(t.pos,r.pos,this.mark)}merge(e){return e instanceof ji&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ji(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 ji(t.from,t.to,e.markFromJSON(t.mark))}};Ye.jsonID("removeMark",hy);let py=class Ki extends Ye{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Je.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Je.fromReplace(e,this.pos,this.pos+1,new v(C.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 Xs(t.pos,r.pos,i,o,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 Xs(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}};Ye.jsonID("replaceAround",Qv);function ju(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Yv(n,e,t=null,r=n){let i=Gv(n,e),o=i&&Xv(r,e);return o?i.map(bh).concat({type:e,attrs:t}).concat(o.map(bh)):null}function bh(n){return{type:n,attrs:null}}function Gv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.contentMatchAt(r).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return t.canReplaceWith(r,i,s)?o:null}function Xv(n,e){let{parent:t,startIndex:r,endIndex:i}=n,o=t.child(r),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:e).contentMatch;for(let u=r;a&&u0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const rx=500;function ix({rules:n}){let e=new $t({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return Ih(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Ih(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function Ih(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-rx),l.parentOffset,null,"")+r;for(let u=0;u{let a=t instanceof Function?t(o):t,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&Yv(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Zv(u.doc,s-1)&&!r&&u.join(s-1),u})}const sx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function lx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ba(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const fx=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function dx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=It[r.keyCode])&&o!=i){let l=e[Ja(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const gy=65535,yy=Math.pow(2,16);function mx(n,e){return n+e*yy}function zh(n){return n&gy}function gx(n){return(n-(n&gy))/yy}const Sy=1,wy=2,el=4,ky=8;class Ku{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&ky)>0}get deletedBefore(){return(this.delInfo&(Sy|el))>0}get deletedAfter(){return(this.delInfo&(wy|el))>0}get deletedAcross(){return(this.delInfo&el)>0}}class Xe{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Xe.empty)return Xe.empty}recover(e){let t=0,r=zh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:c);if(r)return p;let h=e==(t<0?a:f)?null:mx(l/3,e-a),m=e==a?wy:e==f?Sy:el;return(t<0?e!=a:e!=f)&&(m|=ky),new Ku(p,m,h)}i+=c-u}return r?e+i:new Ku(e+i,0,null)}touches(e,t){let r=0,i=zh(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=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 io;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new Dt(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 pn(t.pos,r.pos,this.mark)}merge(e){return e instanceof pn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new pn(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 pn(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("addMark",pn);class Dt extends De{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 v(Cf(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new pn(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 Dt(t.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(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 Dt(t.from,t.to,e.markFromJSON(t.mark))}}De.jsonID("removeMark",Dt);class mn extends De{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return oe.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return oe.fromReplace(e,this.pos,this.pos+1,new v(C.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 Rt(t.pos,r.pos,i,o,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 Rt(t.from,t.to,t.gapFrom,t.gapTo,v.fromJSON(e,t.slice),t.insert,!!t.structure)}}De.jsonID("replaceAround",Rt);function qu(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function yx(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,t),h=r.addToSet(f);for(let m=0;mn.step(a)),o.forEach(a=>n.step(a))}function Sx(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof qo){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,t);for(let c=0;cn.step(new Dt(s.from,s.to,s.style)))}function wx(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)n.step(o[l])}function kx(n,e,t){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=C.empty,f=0;for(let h=o,m=!1;h>t;h--)m||r.index(h)>0?(m=!0,c=C.from(r.node(h).copy(c)),f++):a--;let d=C.empty,p=0;for(let h=o,m=!1;h>t;h--)m||i.after(h+1)=0;s--){if(r.size){let l=t[s].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=C.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new Rt(i,o,i,o,new v(r,0,0),t.length,!0))}function xx(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&Cx(n.doc,n.mapping.slice(o).map(l),r)){n.clearIncompatible(n.mapping.slice(o).map(l,1),r);let a=n.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return n.step(new Rt(u,c,u+1,c-1,new v(C.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Cx(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Nx(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Rt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(C.from(s),0,0),1,!0))}function Mx(n,e,t=1,r){let i=n.doc.resolve(e),o=C.empty,s=C.empty;for(let l=i.depth,a=i.depth-t,u=t-1;l>a;l--,u--){o=C.from(i.node(l).copy(o));let c=r&&r[u];s=C.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}n.step(new Re(e,e,new v(o.append(s),t,t),!0))}function Ex(n,e,t){let r=new Re(e-t,e+t,v.empty,!0);n.step(r)}function Ox(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 o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o0;i--)this.placed=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new v(o,s,l);return e>-1?new Rt(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new Re(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),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Wa(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(t==1&&(s?u.matchType(s.type)||(f=u.fillBefore(C.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wa(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Wa(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new v(qi(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new v(qi(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=w,c.push(xy(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=Qi(this.placed,t,C.from(c)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,w=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],o=t=0;l--){let{match:a,type:u}=this.frontier[l],c=Ua(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:t,fit:s,move:o?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=Qi(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Qi(this.placed,this.depth,C.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(C.empty,!0);t.childCount&&(this.placed=Qi(this.placed,this.frontier.length,t))}}function qi(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(qi(n.firstChild.content,e-1,t)))}function Qi(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Qi(n.lastChild.content,e-1,t)))}function Wa(n,e){for(let t=0;t1&&(r=r.replaceChild(0,xy(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(C.empty,!0)))),n.copy(r)}function Ua(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Rx(t,o.content,s)?l:null}function Rx(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=Ax(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function Cy(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(C.empty,!0))}return n}function Ix(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Ox(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new v(C.from(r),0,0))}function zx(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ny(r,i);for(let s=0;s0&&(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 s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s)return n.delete(r.before(s),t);n.delete(e,t)}function Ny(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}class Jr extends De{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 oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return oe.fromReplace(e,this.pos,this.pos+1,new v(C.from(i),0,t.isLeaf?0:1))}getMap(){return Xe.empty}invert(e){return new Jr(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 Jr(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 Jr(t.pos,t.attr,t.value)}}De.jsonID("attr",Jr);class Mo extends De{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 oe.ok(r)}getMap(){return Xe.empty}invert(e){return new Mo(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 Mo(t.attr,t.value)}}De.jsonID("docAttr",Mo);let ni=class extends Error{};ni=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ni.prototype=Object.create(Error.prototype);ni.prototype.constructor=ni;ni.prototype.name="TransformError";class Px{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new io}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ni(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=v.empty){let i=Dx(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new v(C.from(r),0,0))}delete(e,t){return this.replace(e,t,v.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return bx(this,e,t,r),this}replaceRangeWith(e,t,r){return Ix(this,e,t,r),this}deleteRange(e,t){return zx(this,e,t),this}lift(e,t){return kx(this,e,t),this}join(e,t=1){return Ex(this,e,t),this}wrap(e,t){return vx(this,e,t),this}setBlockType(e,t=e,r,i=null){return xx(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Nx(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Jr(e,t,r)),this}setDocAttribute(e,t){return this.step(new Mo(e,t)),this}addNodeMark(e,t){return this.step(new mn(e,t)),this}removeNodeMark(e,t){if(!(t instanceof W)){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 ti(e,t)),this}split(e,t=1,r){return Mx(this,e,t,r),this}addMark(e,t,r){return yx(this,e,t,r),this}removeMark(e,t,r){return Sx(this,e,t,r),this}clearIncompatible(e,t,r){return wx(this,e,t,r),this}}var Qu,Yu;if(typeof WeakMap<"u"){let n=new WeakMap;Qu=e=>n.get(e),Yu=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;Qu=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var re=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-S});break}const x=i+S*e;for(let N=0;Nr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function $x(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(n);a!=null&&(o[s]=a)}return o}function Fh(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Bx(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Ph(r,e)}],toDOM(r){return["td",Fh(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Ph(r,e)}],toDOM(r){return["th",Fh(r,e),0]}}}}function Ft(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var an=new Yo("selectingCells");function es(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Nf(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function My(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=es(e.$head)||Jx(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Jx(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Gu(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Mf(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ey(n,e,t){const r=n.node(-1),i=re.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}function ri(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var fe=class Jt extends P{constructor(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,t.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=t.pos-o);a.unshift(t.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new og(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Gu(r)&&Gu(i)&&Mf(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Jt.rowSelection(r,i):o&&this.isColSelection()?Jt.colSelection(r,i):new Jt(r,i)}return $.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=re.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||w>0){let g=h.attrs;if(m>0&&(g=ri(g,0,m)),w>0&&(g=ri(g,g.colspan-w,w)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(t=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof Jt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(t=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(Se.node(r,r+t.nodeSize,{class:"selectedCell"}))}),_.create(n.doc,e)}function Ux({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Hx({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function jx(n,e,t){const r=(e||n).selection,i=(e||n).doc;let o,s;if(r instanceof I&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=fe.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=fe.rowSelection(l,l)}else if(!t){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=fe.create(i,a+1,u)}}else r instanceof $&&Ux(r)?o=$.create(i,r.from):r instanceof $&&Hx(r)&&(o=$.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var Kx=new Yo("fix-tables");function Dy(n,e,t,r){const i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=Qx(n,i,o,t))};return e?e.doc!=n.doc&&Dy(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qx(n,e,t,r){const i=re.get(e);if(!i.problems)return r;r||(r=n.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let w=0;w0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(C.empty),t[i]r&&(d=d.type.createChecked(ri(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(C.from(a))}t=o,e=i}return{width:n,height:e,rows:t}}function Zx(n,e,t,r,i,o,s){const l=n.doc.type.schema,a=Ft(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:t.nodeAt(e.map[m+h]).type==a.header_cell;f.push(w?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,C.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=t.selection;if(o instanceof fe)return tl(t,r,P.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;const s=Ty(i,n,e);if(s==null)return!1;if(n=="horiz")return tl(t,r,P.near(t.doc.resolve(o.head+e),e));{const l=t.doc.resolve(s),a=Ey(l,n,e);let u;return a?u=P.near(a,1):e<0?u=P.near(t.doc.resolve(l.before(-1)),-1):u=P.near(t.doc.resolve(l.after(-1)),1),tl(t,r,u)}}}function gs(n,e){return(t,r,i)=>{if(!i)return!1;const o=t.selection;let s;if(o instanceof fe)s=o;else{const a=Ty(i,n,e);if(a==null)return!1;s=new fe(t.doc.resolve(a))}const l=Ey(s.$headCell,n,e);return l?tl(t,r,new fe(s.$anchorCell,l)):!1}}function ys(n,e){const t=n.selection;if(!(t instanceof fe))return!1;if(e){const r=n.tr,i=Ft(n.schema).cell.createAndFill().content;t.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new v(i,0,0))}),r.docChanged&&e(r)}return!0}function tC(n,e){const t=n.state.doc,r=es(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new fe(r))),!0):!1}function nC(n,e,t){if(!Nf(n.state))return!1;let r=Yx(t);const i=n.state.selection;if(i instanceof fe){r||(r={width:1,height:1,rows:[C.from(Xu(Ft(n.state.schema).cell,t))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Xx(r,l.right-l.left,l.bottom-l.top),Vh(n.state,n.dispatch,s,l,r),!0}else if(r){const o=My(n.state),s=o.start(-1);return Vh(n.state,n.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function rC(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=Bh(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof fe)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=es(n.state.selection.$anchor))!=null&&((t=Ha(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Ha(n,u);const f=an.getState(n.state)==null;if(!c||!Mf(a,c))if(f)c=a;else return;const d=new fe(a,c);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(an,a.pos),n.dispatch(p)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",l),an.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(an,-1))}function l(a){const u=a,c=an.getState(n.state);let f;if(c!=null)f=n.state.doc.resolve(c);else if(Bh(n,u.target)!=r&&(f=Ha(n,e),!f))return s();f&&o(f,u)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function Ty(n,e,t){if(!(n.state.selection instanceof $))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Bh(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ha(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?es(n.state.doc.resolve(t.pos)):null}var iC=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Zu(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Zu(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Zu(n,e,t,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=n.firstChild;if(c){for(let f=0,d=0;fnew t(l,e,a),new sC(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=ut.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{lC(o,s,n,e,r)},mouseleave:o=>{aC(o)},mousedown:(o,s)=>{uC(o,s,e)}},decorations:o=>{const s=ut.getState(o);if(s&&s.activeHandle>-1)return mC(o,s.activeHandle)},nodeViews:{}}});return i}var sC=class nl{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(ut);if(r&&r.setHandle!=null)return new nl(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new nl(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Gu(e.doc.resolve(i))||(i=-1),new nl(i,t.dragging)}return t}};function lC(n,e,t,r,i){const o=ut.getState(n.state);if(o&&!o.dragging){const s=fC(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=t?l=Jh(n,e,"left",t):u-e.clientX<=t&&(l=Jh(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=n.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Ry(n,l)}}}function aC(n){const e=ut.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ry(n,-1)}function uC(n,e,t){var r;const i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=ut.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=n.state.doc.nodeAt(o.activeHandle),l=cC(n,o.activeHandle,s.attrs);n.dispatch(n.state.tr.setMeta(ut,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=ut.getState(n.state);f!=null&&f.dragging&&(dC(n,f.activeHandle,_h(f.dragging,c,t)),n.dispatch(n.state.tr.setMeta(ut,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=ut.getState(n.state);if(f&&f.dragging){const d=_h(f.dragging,c,t);hC(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function cC(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=n.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=t;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}Ef("row",{useDeprecatedLogic:!0});Ef("column",{useDeprecatedLogic:!0});Ef("cell",{useDeprecatedLogic:!0});function yC({allowTableNodeSelection:n=!1}={}){return new $t({key:an,state:{init(){return null},apply(e,t){const r=e.getMeta(an);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:o}=e.mapping.mapResult(t);return i?null:o}},props:{decorations:Wx,handleDOMEvents:{mousedown:rC},createSelectionBetween(e){return an.getState(e.state)!=null?e.state.selection:null},handleTripleClick:tC,handleKeyDown:eC,handlePaste:nC},appendTransaction(e,t,r){return jx(r,qx(r,t),n)}})}var by={exports:{}},rt={},Iy={exports:{}},zy={};/** * @license React * scheduler.production.min.js * @@ -30,7 +30,7 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */(function(n){function e(T,F){var L=T.length;T.push(F);e:for(;0>>1,ue=T[te];if(0>>1;tei(Sa,L))Bni(us,Sa)?(T[te]=us,T[Bn]=L,te=Bn):(T[te]=Sa,T[Vn]=L,te=Vn);else if(Bni(us,L))T[te]=us,T[Bn]=L,te=Bn;else break e}}return F}function i(T,F){var L=T.sortIndex-F.sortIndex;return L!==0?L:T.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();n.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,S=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(T){for(var F=t(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=T)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=t(u)}}function C(T){if(m=!1,w(T),!h)if(t(a)!==null)h=!0,he(M);else{var F=t(u);F!==null&&$n(C,F.startTime-T)}}function M(T,F){h=!1,m&&(m=!1,g(D),D=-1),p=!0;var L=d;try{for(w(F),f=t(a);f!==null&&(!(f.expirationTime>F)||T&&!ae());){var te=f.callback;if(typeof te=="function"){f.callback=null,d=f.priorityLevel;var ue=te(f.expirationTime<=F);F=n.unstable_now(),typeof ue=="function"?f.callback=ue:f===t(a)&&r(a),w(F)}else r(a);f=t(a)}if(f!==null)var as=!0;else{var Vn=t(u);Vn!==null&&$n(C,Vn.startTime-F),as=!1}return as}finally{f=null,d=L,p=!1}}var N=!1,O=null,D=-1,b=5,z=-1;function ae(){return!(n.unstable_now()-zT||125te?(T.sortIndex=L,e(u,T),t(a)===null&&T===t(u)&&(m?(g(D),D=-1):m=!0,$n(C,L-te))):(T.sortIndex=ue,e(a,T),h||p||(h=!0,he(M))),T},n.unstable_shouldYield=ae,n.unstable_wrapCallback=function(T){var F=d;return function(){var L=d;d=F;try{return T.apply(this,arguments)}finally{d=L}}}})(zy);Iy.exports=zy;var SC=Iy.exports;/** + */(function(n){function e(T,F){var L=T.length;T.push(F);e:for(;0>>1,ue=T[te];if(0>>1;tei(Sa,L))Bni(us,Sa)?(T[te]=us,T[Bn]=L,te=Bn):(T[te]=Sa,T[Vn]=L,te=Vn);else if(Bni(us,L))T[te]=us,T[Bn]=L,te=Bn;else break e}}return F}function i(T,F){var L=T.sortIndex-F.sortIndex;return L!==0?L:T.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();n.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,w=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function S(T){for(var F=t(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=T)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=t(u)}}function x(T){if(m=!1,S(T),!h)if(t(a)!==null)h=!0,he(N);else{var F=t(u);F!==null&&$n(x,F.startTime-T)}}function N(T,F){h=!1,m&&(m=!1,g(D),D=-1),p=!0;var L=d;try{for(S(F),f=t(a);f!==null&&(!(f.expirationTime>F)||T&&!ae());){var te=f.callback;if(typeof te=="function"){f.callback=null,d=f.priorityLevel;var ue=te(f.expirationTime<=F);F=n.unstable_now(),typeof ue=="function"?f.callback=ue:f===t(a)&&r(a),S(F)}else r(a);f=t(a)}if(f!==null)var as=!0;else{var Vn=t(u);Vn!==null&&$n(x,Vn.startTime-F),as=!1}return as}finally{f=null,d=L,p=!1}}var M=!1,O=null,D=-1,b=5,z=-1;function ae(){return!(n.unstable_now()-zT||125te?(T.sortIndex=L,e(u,T),t(a)===null&&T===t(u)&&(m?(g(D),D=-1):m=!0,$n(x,L-te))):(T.sortIndex=ue,e(a,T),h||p||(h=!0,he(N))),T},n.unstable_shouldYield=ae,n.unstable_wrapCallback=function(T){var F=d;return function(){var L=d;d=F;try{return T.apply(this,arguments)}finally{d=L}}}})(zy);Iy.exports=zy;var SC=Iy.exports;/** * @license React * react-dom.production.min.js * @@ -42,12 +42,12 @@ `+ja+n}var Ka=!1;function qa(n,e){if(!n||Ka)return"";Ka=!0;var t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(e)if(e=function(){throw Error()},Object.defineProperty(e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(e,[])}catch(u){var r=u}Reflect.construct(n,[],e)}else{try{e.call()}catch(u){r=u}n.call(e.prototype)}else{try{throw Error()}catch(u){r=u}n()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var i=u.stack.split(` `),o=r.stack.split(` `),s=i.length-1,l=o.length-1;1<=s&&0<=l&&i[s]!==o[l];)l--;for(;1<=s&&0<=l;s--,l--)if(i[s]!==o[l]){if(s!==1||l!==1)do if(s--,l--,0>l||i[s]!==o[l]){var a=` -`+i[s].replace(" at new "," at ");return n.displayName&&a.includes("")&&(a=a.replace("",n.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ka=!1,Error.prepareStackTrace=t}return(n=n?n.displayName||n.name:"")?Yi(n):""}function CC(n){switch(n.tag){case 5:return Yi(n.type);case 16:return Yi("Lazy");case 13:return Yi("Suspense");case 19:return Yi("SuspenseList");case 0:case 2:case 15:return n=qa(n.type,!1),n;case 11:return n=qa(n.type.render,!1),n;case 1:return n=qa(n.type,!0),n;default:return""}}function ic(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case Dr:return"Fragment";case Or:return"Portal";case tc:return"Profiler";case Rf:return"StrictMode";case nc:return"Suspense";case rc:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case $y:return(n.displayName||"Context")+".Consumer";case Ly:return(n._context.displayName||"Context")+".Provider";case Af:var e=n.render;return n=n.displayName,n||(n=e.displayName||e.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case bf:return e=n.displayName||null,e!==null?e:ic(n.type)||"Memo";case on:e=n._payload,n=n._init;try{return ic(n(e))}catch{}}return null}function NC(n){var e=n.type;switch(n.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=e.render,n=n.displayName||n.name||"",e.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return ic(e);case 8:return e===Rf?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function Tn(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function By(n){var e=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function MC(n){var e=By(n)?"checked":"value",t=Object.getOwnPropertyDescriptor(n.constructor.prototype,e),r=""+n[e];if(!n.hasOwnProperty(e)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var i=t.get,o=t.set;return Object.defineProperty(n,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(n,e,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){n._valueTracker=null,delete n[e]}}}}function ws(n){n._valueTracker||(n._valueTracker=MC(n))}function Jy(n){if(!n)return!1;var e=n._valueTracker;if(!e)return!0;var t=e.getValue(),r="";return n&&(r=By(n)?n.checked?"true":"false":n.value),n=r,n!==t?(e.setValue(n),!0):!1}function Ml(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function oc(n,e){var t=e.checked;return X({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??n._wrapperState.initialChecked})}function Kh(n,e){var t=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;t=Tn(e.value!=null?e.value:t),n._wrapperState={initialChecked:r,initialValue:t,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function _y(n,e){e=e.checked,e!=null&&Tf(n,"checked",e,!1)}function sc(n,e){_y(n,e);var t=Tn(e.value),r=e.type;if(t!=null)r==="number"?(t===0&&n.value===""||n.value!=t)&&(n.value=""+t):n.value!==""+t&&(n.value=""+t);else if(r==="submit"||r==="reset"){n.removeAttribute("value");return}e.hasOwnProperty("value")?lc(n,e.type,t):e.hasOwnProperty("defaultValue")&&lc(n,e.type,Tn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(n.defaultChecked=!!e.defaultChecked)}function qh(n,e,t){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+n._wrapperState.initialValue,t||e===n.value||(n.value=e),n.defaultValue=e}t=n.name,t!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,t!==""&&(n.name=t)}function lc(n,e,t){(e!=="number"||Ml(n.ownerDocument)!==n)&&(t==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+t&&(n.defaultValue=""+t))}var Gi=Array.isArray;function _r(n,e,t,r){if(n=n.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=ks.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;e.firstChild;)n.appendChild(e.firstChild)}});function Oo(n,e){if(e){var t=n.firstChild;if(t&&t===n.lastChild&&t.nodeType===3){t.nodeValue=e;return}}n.textContent=e}var oo={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},EC=["Webkit","ms","Moz","O"];Object.keys(oo).forEach(function(n){EC.forEach(function(e){e=e+n.charAt(0).toUpperCase()+n.substring(1),oo[e]=oo[n]})});function jy(n,e,t){return e==null||typeof e=="boolean"||e===""?"":t||typeof e!="number"||e===0||oo.hasOwnProperty(n)&&oo[n]?(""+e).trim():e+"px"}function Ky(n,e){n=n.style;for(var t in e)if(e.hasOwnProperty(t)){var r=t.indexOf("--")===0,i=jy(t,e[t],r);t==="float"&&(t="cssFloat"),r?n.setProperty(t,i):n[t]=i}}var OC=X({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function cc(n,e){if(e){if(OC[n]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(E(137,n));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(E(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(E(61))}if(e.style!=null&&typeof e.style!="object")throw Error(E(62))}}function fc(n,e){if(n.indexOf("-")===-1)return typeof e.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var dc=null;function If(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var hc=null,Wr=null,Ur=null;function Gh(n){if(n=rs(n)){if(typeof hc!="function")throw Error(E(280));var e=n.stateNode;e&&(e=sa(e),hc(n.stateNode,n.type,e))}}function qy(n){Wr?Ur?Ur.push(n):Ur=[n]:Wr=n}function Qy(){if(Wr){var n=Wr,e=Ur;if(Ur=Wr=null,Gh(n),e)for(n=0;n>>=0,n===0?32:31-($C(n)/VC|0)|0}var vs=64,xs=4194304;function Xi(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Tl(n,e){var t=n.pendingLanes;if(t===0)return 0;var r=0,i=n.suspendedLanes,o=n.pingedLanes,s=t&268435455;if(s!==0){var l=s&~i;l!==0?r=Xi(l):(o&=s,o!==0&&(r=Xi(o)))}else s=t&~i,s!==0?r=Xi(s):o!==0&&(r=Xi(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=t&16),e=n.entangledLanes,e!==0)for(n=n.entanglements,e&=r;0t;t++)e.push(n);return e}function ts(n,e,t){n.pendingLanes|=e,e!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,e=31-vt(e),n[e]=t}function WC(n,e){var t=n.pendingLanes&~e;n.pendingLanes=e,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=e,n.mutableReadLanes&=e,n.entangledLanes&=e,e=n.entanglements;var r=n.eventTimes;for(n=n.expirationTimes;0=lo),sp=" ",lp=!1;function m0(n,e){switch(n){case"keyup":return yN.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function g0(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var Tr=!1;function wN(n,e){switch(n){case"compositionend":return g0(e);case"keypress":return e.which!==32?null:(lp=!0,sp);case"textInput":return n=e.data,n===sp&&lp?null:n;default:return null}}function kN(n,e){if(Tr)return n==="compositionend"||!Jf&&m0(n,e)?(n=h0(),il=$f=gn=null,Tr=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:t,offset:e-n};n=r}e:{for(;t;){if(t.nextSibling){t=t.nextSibling;break e}t=t.parentNode}t=void 0}t=fp(t)}}function k0(n,e){return n&&e?n===e?!0:n&&n.nodeType===3?!1:e&&e.nodeType===3?k0(n,e.parentNode):"contains"in n?n.contains(e):n.compareDocumentPosition?!!(n.compareDocumentPosition(e)&16):!1:!1}function v0(){for(var n=window,e=Ml();e instanceof n.HTMLIFrameElement;){try{var t=typeof e.contentWindow.location.href=="string"}catch{t=!1}if(t)n=e.contentWindow;else break;e=Ml(n.document)}return e}function _f(n){var e=n&&n.nodeName&&n.nodeName.toLowerCase();return e&&(e==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||e==="textarea"||n.contentEditable==="true")}function TN(n){var e=v0(),t=n.focusedElem,r=n.selectionRange;if(e!==t&&t&&t.ownerDocument&&k0(t.ownerDocument.documentElement,t)){if(r!==null&&_f(t)){if(e=r.start,n=r.end,n===void 0&&(n=e),"selectionStart"in t)t.selectionStart=e,t.selectionEnd=Math.min(n,t.value.length);else if(n=(e=t.ownerDocument||document)&&e.defaultView||window,n.getSelection){n=n.getSelection();var i=t.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!n.extend&&o>r&&(i=r,r=o,o=i),i=dp(t,o);var s=dp(t,r);i&&s&&(n.rangeCount!==1||n.anchorNode!==i.node||n.anchorOffset!==i.offset||n.focusNode!==s.node||n.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),n.removeAllRanges(),o>r?(n.addRange(e),n.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),n.addRange(e)))}}for(e=[],n=t;n=n.parentNode;)n.nodeType===1&&e.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t=document.documentMode,Rr=null,wc=null,uo=null,kc=!1;function hp(n,e,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;kc||Rr==null||Rr!==Ml(r)||(r=Rr,"selectionStart"in r&&_f(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),uo&&Io(uo,r)||(uo=r,r=bl(wc,"onSelect"),0Ir||(n.current=Ec[Ir],Ec[Ir]=null,Ir--)}function H(n,e){Ir++,Ec[Ir]=n.current,n.current=e}var Rn={},Oe=zn(Rn),Ue=zn(!1),lr=Rn;function oi(n,e){var t=n.type.contextTypes;if(!t)return Rn;var r=n.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in t)i[o]=e[o];return r&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=e,n.__reactInternalMemoizedMaskedChildContext=i),i}function He(n){return n=n.childContextTypes,n!=null}function zl(){q(Ue),q(Oe)}function kp(n,e,t){if(Oe.current!==Rn)throw Error(E(168));H(Oe,e),H(Ue,t)}function R0(n,e,t){var r=n.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(E(108,NC(n)||"Unknown",i));return X({},t,r)}function Pl(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||Rn,lr=Oe.current,H(Oe,n),H(Ue,Ue.current),!0}function vp(n,e,t){var r=n.stateNode;if(!r)throw Error(E(169));t?(n=R0(n,e,lr),r.__reactInternalMemoizedMergedChildContext=n,q(Ue),q(Oe),H(Oe,n)):q(Ue),H(Ue,t)}var Ht=null,la=!1,au=!1;function A0(n){Ht===null?Ht=[n]:Ht.push(n)}function JN(n){la=!0,A0(n)}function Pn(){if(!au&&Ht!==null){au=!0;var n=0,e=U;try{var t=Ht;for(U=1;n>=s,i-=s,jt=1<<32-vt(e)+i|t<D?(b=O,O=null):b=O.sibling;var z=d(g,O,w[D],C);if(z===null){O===null&&(O=b);break}n&&O&&z.alternate===null&&e(g,O),y=o(z,y,D),N===null?M=z:N.sibling=z,N=z,O=b}if(D===w.length)return t(g,O),Q&&Hn(g,D),M;if(O===null){for(;DD?(b=O,O=null):b=O.sibling;var ae=d(g,O,z.value,C);if(ae===null){O===null&&(O=b);break}n&&O&&ae.alternate===null&&e(g,O),y=o(ae,y,D),N===null?M=ae:N.sibling=ae,N=ae,O=b}if(z.done)return t(g,O),Q&&Hn(g,D),M;if(O===null){for(;!z.done;D++,z=w.next())z=f(g,z.value,C),z!==null&&(y=o(z,y,D),N===null?M=z:N.sibling=z,N=z);return Q&&Hn(g,D),M}for(O=r(g,O);!z.done;D++,z=w.next())z=p(O,g,D,z.value,C),z!==null&&(n&&z.alternate!==null&&O.delete(z.key===null?D:z.key),y=o(z,y,D),N===null?M=z:N.sibling=z,N=z);return n&&O.forEach(function(Vt){return e(g,Vt)}),Q&&Hn(g,D),M}function S(g,y,w,C){if(typeof w=="object"&&w!==null&&w.type===Dr&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case Ss:e:{for(var M=w.key,N=y;N!==null;){if(N.key===M){if(M=w.type,M===Dr){if(N.tag===7){t(g,N.sibling),y=i(N,w.props.children),y.return=g,g=y;break e}}else if(N.elementType===M||typeof M=="object"&&M!==null&&M.$$typeof===on&&Dp(M)===N.type){t(g,N.sibling),y=i(N,w.props),y.ref=Ni(g,N,w),y.return=g,g=y;break e}t(g,N);break}else e(g,N);N=N.sibling}w.type===Dr?(y=ir(w.props.children,g.mode,C,w.key),y.return=g,g=y):(C=dl(w.type,w.key,w.props,null,g.mode,C),C.ref=Ni(g,y,w),C.return=g,g=C)}return s(g);case Or:e:{for(N=w.key;y!==null;){if(y.key===N)if(y.tag===4&&y.stateNode.containerInfo===w.containerInfo&&y.stateNode.implementation===w.implementation){t(g,y.sibling),y=i(y,w.children||[]),y.return=g,g=y;break e}else{t(g,y);break}else e(g,y);y=y.sibling}y=gu(w,g.mode,C),y.return=g,g=y}return s(g);case on:return N=w._init,S(g,y,N(w._payload),C)}if(Gi(w))return h(g,y,w,C);if(wi(w))return m(g,y,w,C);Ts(g,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,y!==null&&y.tag===6?(t(g,y.sibling),y=i(y,w),y.return=g,g=y):(t(g,y),y=mu(w,g.mode,C),y.return=g,g=y),s(g)):t(g,y)}return S}var li=V0(!0),B0=V0(!1),is={},bt=zn(is),Lo=zn(is),$o=zn(is);function Xn(n){if(n===is)throw Error(E(174));return n}function Gf(n,e){switch(H($o,e),H(Lo,n),H(bt,is),n=e.nodeType,n){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:uc(null,"");break;default:n=n===8?e.parentNode:e,e=n.namespaceURI||null,n=n.tagName,e=uc(e,n)}q(bt),H(bt,e)}function ai(){q(bt),q(Lo),q($o)}function J0(n){Xn($o.current);var e=Xn(bt.current),t=uc(e,n.type);e!==t&&(H(Lo,n),H(bt,t))}function Xf(n){Lo.current===n&&(q(bt),q(Lo))}var Y=zn(0);function Jl(n){for(var e=n;e!==null;){if(e.tag===13){var t=e.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break;for(;e.sibling===null;){if(e.return===null||e.return===n)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var uu=[];function Zf(){for(var n=0;nt?t:4,n(!0);var r=cu.transition;cu.transition={};try{n(!1),e()}finally{U=t,cu.transition=r}}function r1(){return pt().memoizedState}function HN(n,e,t){var r=En(n);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},i1(n))o1(e,t);else if(t=P0(n,e,t,r),t!==null){var i=Ae();xt(t,n,r,i),s1(t,e,r)}}function jN(n,e,t){var r=En(n),i={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(i1(n))o1(e,i);else{var o=n.alternate;if(n.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,t);if(i.hasEagerState=!0,i.eagerState=l,Nt(l,s)){var a=e.interleaved;a===null?(i.next=i,Qf(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}t=P0(n,e,i,r),t!==null&&(i=Ae(),xt(t,n,r,i),s1(t,e,r))}}function i1(n){var e=n.alternate;return n===G||e!==null&&e===G}function o1(n,e){co=_l=!0;var t=n.pending;t===null?e.next=e:(e.next=t.next,t.next=e),n.pending=e}function s1(n,e,t){if(t&4194240){var r=e.lanes;r&=n.pendingLanes,t|=r,e.lanes=t,Pf(n,t)}}var Wl={readContext:ht,useCallback:ve,useContext:ve,useEffect:ve,useImperativeHandle:ve,useInsertionEffect:ve,useLayoutEffect:ve,useMemo:ve,useReducer:ve,useRef:ve,useState:ve,useDebugValue:ve,useDeferredValue:ve,useTransition:ve,useMutableSource:ve,useSyncExternalStore:ve,useId:ve,unstable_isNewReconciler:!1},KN={readContext:ht,useCallback:function(n,e){return Et().memoizedState=[n,e===void 0?null:e],n},useContext:ht,useEffect:Rp,useImperativeHandle:function(n,e,t){return t=t!=null?t.concat([n]):null,al(4194308,4,X0.bind(null,e,n),t)},useLayoutEffect:function(n,e){return al(4194308,4,n,e)},useInsertionEffect:function(n,e){return al(4,2,n,e)},useMemo:function(n,e){var t=Et();return e=e===void 0?null:e,n=n(),t.memoizedState=[n,e],n},useReducer:function(n,e,t){var r=Et();return e=t!==void 0?t(e):e,r.memoizedState=r.baseState=e,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:e},r.queue=n,n=n.dispatch=HN.bind(null,G,n),[r.memoizedState,n]},useRef:function(n){var e=Et();return n={current:n},e.memoizedState=n},useState:Tp,useDebugValue:id,useDeferredValue:function(n){return Et().memoizedState=n},useTransition:function(){var n=Tp(!1),e=n[0];return n=UN.bind(null,n[1]),Et().memoizedState=n,[e,n]},useMutableSource:function(){},useSyncExternalStore:function(n,e,t){var r=G,i=Et();if(Q){if(t===void 0)throw Error(E(407));t=t()}else{if(t=e(),de===null)throw Error(E(349));ur&30||U0(r,e,t)}i.memoizedState=t;var o={value:t,getSnapshot:e};return i.queue=o,Rp(j0.bind(null,r,o,n),[n]),r.flags|=2048,Jo(9,H0.bind(null,r,o,t,e),void 0,null),t},useId:function(){var n=Et(),e=de.identifierPrefix;if(Q){var t=Kt,r=jt;t=(r&~(1<<32-vt(r)-1)).toString(32)+t,e=":"+e+"R"+t,t=Vo++,0")&&(a=a.replace("",n.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ka=!1,Error.prepareStackTrace=t}return(n=n?n.displayName||n.name:"")?Yi(n):""}function CC(n){switch(n.tag){case 5:return Yi(n.type);case 16:return Yi("Lazy");case 13:return Yi("Suspense");case 19:return Yi("SuspenseList");case 0:case 2:case 15:return n=qa(n.type,!1),n;case 11:return n=qa(n.type.render,!1),n;case 1:return n=qa(n.type,!0),n;default:return""}}function ic(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case Dr:return"Fragment";case Or:return"Portal";case tc:return"Profiler";case Rf:return"StrictMode";case nc:return"Suspense";case rc:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case $y:return(n.displayName||"Context")+".Consumer";case Ly:return(n._context.displayName||"Context")+".Provider";case Af:var e=n.render;return n=n.displayName,n||(n=e.displayName||e.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case bf:return e=n.displayName||null,e!==null?e:ic(n.type)||"Memo";case on:e=n._payload,n=n._init;try{return ic(n(e))}catch{}}return null}function NC(n){var e=n.type;switch(n.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=e.render,n=n.displayName||n.name||"",e.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return ic(e);case 8:return e===Rf?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function Tn(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function By(n){var e=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function MC(n){var e=By(n)?"checked":"value",t=Object.getOwnPropertyDescriptor(n.constructor.prototype,e),r=""+n[e];if(!n.hasOwnProperty(e)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var i=t.get,o=t.set;return Object.defineProperty(n,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(n,e,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){n._valueTracker=null,delete n[e]}}}}function ws(n){n._valueTracker||(n._valueTracker=MC(n))}function Jy(n){if(!n)return!1;var e=n._valueTracker;if(!e)return!0;var t=e.getValue(),r="";return n&&(r=By(n)?n.checked?"true":"false":n.value),n=r,n!==t?(e.setValue(n),!0):!1}function Ml(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function oc(n,e){var t=e.checked;return X({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??n._wrapperState.initialChecked})}function Kh(n,e){var t=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;t=Tn(e.value!=null?e.value:t),n._wrapperState={initialChecked:r,initialValue:t,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function _y(n,e){e=e.checked,e!=null&&Tf(n,"checked",e,!1)}function sc(n,e){_y(n,e);var t=Tn(e.value),r=e.type;if(t!=null)r==="number"?(t===0&&n.value===""||n.value!=t)&&(n.value=""+t):n.value!==""+t&&(n.value=""+t);else if(r==="submit"||r==="reset"){n.removeAttribute("value");return}e.hasOwnProperty("value")?lc(n,e.type,t):e.hasOwnProperty("defaultValue")&&lc(n,e.type,Tn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(n.defaultChecked=!!e.defaultChecked)}function qh(n,e,t){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+n._wrapperState.initialValue,t||e===n.value||(n.value=e),n.defaultValue=e}t=n.name,t!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,t!==""&&(n.name=t)}function lc(n,e,t){(e!=="number"||Ml(n.ownerDocument)!==n)&&(t==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+t&&(n.defaultValue=""+t))}var Gi=Array.isArray;function _r(n,e,t,r){if(n=n.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=ks.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;e.firstChild;)n.appendChild(e.firstChild)}});function Oo(n,e){if(e){var t=n.firstChild;if(t&&t===n.lastChild&&t.nodeType===3){t.nodeValue=e;return}}n.textContent=e}var oo={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},EC=["Webkit","ms","Moz","O"];Object.keys(oo).forEach(function(n){EC.forEach(function(e){e=e+n.charAt(0).toUpperCase()+n.substring(1),oo[e]=oo[n]})});function jy(n,e,t){return e==null||typeof e=="boolean"||e===""?"":t||typeof e!="number"||e===0||oo.hasOwnProperty(n)&&oo[n]?(""+e).trim():e+"px"}function Ky(n,e){n=n.style;for(var t in e)if(e.hasOwnProperty(t)){var r=t.indexOf("--")===0,i=jy(t,e[t],r);t==="float"&&(t="cssFloat"),r?n.setProperty(t,i):n[t]=i}}var OC=X({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function cc(n,e){if(e){if(OC[n]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(E(137,n));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(E(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(E(61))}if(e.style!=null&&typeof e.style!="object")throw Error(E(62))}}function fc(n,e){if(n.indexOf("-")===-1)return typeof e.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var dc=null;function If(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var hc=null,Wr=null,Ur=null;function Gh(n){if(n=rs(n)){if(typeof hc!="function")throw Error(E(280));var e=n.stateNode;e&&(e=sa(e),hc(n.stateNode,n.type,e))}}function qy(n){Wr?Ur?Ur.push(n):Ur=[n]:Wr=n}function Qy(){if(Wr){var n=Wr,e=Ur;if(Ur=Wr=null,Gh(n),e)for(n=0;n>>=0,n===0?32:31-($C(n)/VC|0)|0}var vs=64,xs=4194304;function Xi(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Tl(n,e){var t=n.pendingLanes;if(t===0)return 0;var r=0,i=n.suspendedLanes,o=n.pingedLanes,s=t&268435455;if(s!==0){var l=s&~i;l!==0?r=Xi(l):(o&=s,o!==0&&(r=Xi(o)))}else s=t&~i,s!==0?r=Xi(s):o!==0&&(r=Xi(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=t&16),e=n.entangledLanes,e!==0)for(n=n.entanglements,e&=r;0t;t++)e.push(n);return e}function ts(n,e,t){n.pendingLanes|=e,e!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,e=31-vt(e),n[e]=t}function WC(n,e){var t=n.pendingLanes&~e;n.pendingLanes=e,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=e,n.mutableReadLanes&=e,n.entangledLanes&=e,e=n.entanglements;var r=n.eventTimes;for(n=n.expirationTimes;0=lo),sp=" ",lp=!1;function m0(n,e){switch(n){case"keyup":return yN.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function g0(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var Tr=!1;function wN(n,e){switch(n){case"compositionend":return g0(e);case"keypress":return e.which!==32?null:(lp=!0,sp);case"textInput":return n=e.data,n===sp&&lp?null:n;default:return null}}function kN(n,e){if(Tr)return n==="compositionend"||!Jf&&m0(n,e)?(n=h0(),il=$f=gn=null,Tr=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:t,offset:e-n};n=r}e:{for(;t;){if(t.nextSibling){t=t.nextSibling;break e}t=t.parentNode}t=void 0}t=fp(t)}}function k0(n,e){return n&&e?n===e?!0:n&&n.nodeType===3?!1:e&&e.nodeType===3?k0(n,e.parentNode):"contains"in n?n.contains(e):n.compareDocumentPosition?!!(n.compareDocumentPosition(e)&16):!1:!1}function v0(){for(var n=window,e=Ml();e instanceof n.HTMLIFrameElement;){try{var t=typeof e.contentWindow.location.href=="string"}catch{t=!1}if(t)n=e.contentWindow;else break;e=Ml(n.document)}return e}function _f(n){var e=n&&n.nodeName&&n.nodeName.toLowerCase();return e&&(e==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||e==="textarea"||n.contentEditable==="true")}function TN(n){var e=v0(),t=n.focusedElem,r=n.selectionRange;if(e!==t&&t&&t.ownerDocument&&k0(t.ownerDocument.documentElement,t)){if(r!==null&&_f(t)){if(e=r.start,n=r.end,n===void 0&&(n=e),"selectionStart"in t)t.selectionStart=e,t.selectionEnd=Math.min(n,t.value.length);else if(n=(e=t.ownerDocument||document)&&e.defaultView||window,n.getSelection){n=n.getSelection();var i=t.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!n.extend&&o>r&&(i=r,r=o,o=i),i=dp(t,o);var s=dp(t,r);i&&s&&(n.rangeCount!==1||n.anchorNode!==i.node||n.anchorOffset!==i.offset||n.focusNode!==s.node||n.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),n.removeAllRanges(),o>r?(n.addRange(e),n.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),n.addRange(e)))}}for(e=[],n=t;n=n.parentNode;)n.nodeType===1&&e.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t=document.documentMode,Rr=null,wc=null,uo=null,kc=!1;function hp(n,e,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;kc||Rr==null||Rr!==Ml(r)||(r=Rr,"selectionStart"in r&&_f(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),uo&&Io(uo,r)||(uo=r,r=bl(wc,"onSelect"),0Ir||(n.current=Ec[Ir],Ec[Ir]=null,Ir--)}function H(n,e){Ir++,Ec[Ir]=n.current,n.current=e}var Rn={},Oe=zn(Rn),Ue=zn(!1),lr=Rn;function oi(n,e){var t=n.type.contextTypes;if(!t)return Rn;var r=n.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in t)i[o]=e[o];return r&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=e,n.__reactInternalMemoizedMaskedChildContext=i),i}function He(n){return n=n.childContextTypes,n!=null}function zl(){q(Ue),q(Oe)}function kp(n,e,t){if(Oe.current!==Rn)throw Error(E(168));H(Oe,e),H(Ue,t)}function R0(n,e,t){var r=n.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(E(108,NC(n)||"Unknown",i));return X({},t,r)}function Pl(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||Rn,lr=Oe.current,H(Oe,n),H(Ue,Ue.current),!0}function vp(n,e,t){var r=n.stateNode;if(!r)throw Error(E(169));t?(n=R0(n,e,lr),r.__reactInternalMemoizedMergedChildContext=n,q(Ue),q(Oe),H(Oe,n)):q(Ue),H(Ue,t)}var Ht=null,la=!1,au=!1;function A0(n){Ht===null?Ht=[n]:Ht.push(n)}function JN(n){la=!0,A0(n)}function Pn(){if(!au&&Ht!==null){au=!0;var n=0,e=U;try{var t=Ht;for(U=1;n>=s,i-=s,jt=1<<32-vt(e)+i|t<D?(b=O,O=null):b=O.sibling;var z=d(g,O,S[D],x);if(z===null){O===null&&(O=b);break}n&&O&&z.alternate===null&&e(g,O),y=o(z,y,D),M===null?N=z:M.sibling=z,M=z,O=b}if(D===S.length)return t(g,O),Q&&Hn(g,D),N;if(O===null){for(;DD?(b=O,O=null):b=O.sibling;var ae=d(g,O,z.value,x);if(ae===null){O===null&&(O=b);break}n&&O&&ae.alternate===null&&e(g,O),y=o(ae,y,D),M===null?N=ae:M.sibling=ae,M=ae,O=b}if(z.done)return t(g,O),Q&&Hn(g,D),N;if(O===null){for(;!z.done;D++,z=S.next())z=f(g,z.value,x),z!==null&&(y=o(z,y,D),M===null?N=z:M.sibling=z,M=z);return Q&&Hn(g,D),N}for(O=r(g,O);!z.done;D++,z=S.next())z=p(O,g,D,z.value,x),z!==null&&(n&&z.alternate!==null&&O.delete(z.key===null?D:z.key),y=o(z,y,D),M===null?N=z:M.sibling=z,M=z);return n&&O.forEach(function(Vt){return e(g,Vt)}),Q&&Hn(g,D),N}function w(g,y,S,x){if(typeof S=="object"&&S!==null&&S.type===Dr&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case Ss:e:{for(var N=S.key,M=y;M!==null;){if(M.key===N){if(N=S.type,N===Dr){if(M.tag===7){t(g,M.sibling),y=i(M,S.props.children),y.return=g,g=y;break e}}else if(M.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===on&&Dp(N)===M.type){t(g,M.sibling),y=i(M,S.props),y.ref=Ni(g,M,S),y.return=g,g=y;break e}t(g,M);break}else e(g,M);M=M.sibling}S.type===Dr?(y=ir(S.props.children,g.mode,x,S.key),y.return=g,g=y):(x=dl(S.type,S.key,S.props,null,g.mode,x),x.ref=Ni(g,y,S),x.return=g,g=x)}return s(g);case Or:e:{for(M=S.key;y!==null;){if(y.key===M)if(y.tag===4&&y.stateNode.containerInfo===S.containerInfo&&y.stateNode.implementation===S.implementation){t(g,y.sibling),y=i(y,S.children||[]),y.return=g,g=y;break e}else{t(g,y);break}else e(g,y);y=y.sibling}y=gu(S,g.mode,x),y.return=g,g=y}return s(g);case on:return M=S._init,w(g,y,M(S._payload),x)}if(Gi(S))return h(g,y,S,x);if(wi(S))return m(g,y,S,x);Ts(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,y!==null&&y.tag===6?(t(g,y.sibling),y=i(y,S),y.return=g,g=y):(t(g,y),y=mu(S,g.mode,x),y.return=g,g=y),s(g)):t(g,y)}return w}var li=V0(!0),B0=V0(!1),is={},bt=zn(is),Lo=zn(is),$o=zn(is);function Xn(n){if(n===is)throw Error(E(174));return n}function Gf(n,e){switch(H($o,e),H(Lo,n),H(bt,is),n=e.nodeType,n){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:uc(null,"");break;default:n=n===8?e.parentNode:e,e=n.namespaceURI||null,n=n.tagName,e=uc(e,n)}q(bt),H(bt,e)}function ai(){q(bt),q(Lo),q($o)}function J0(n){Xn($o.current);var e=Xn(bt.current),t=uc(e,n.type);e!==t&&(H(Lo,n),H(bt,t))}function Xf(n){Lo.current===n&&(q(bt),q(Lo))}var Y=zn(0);function Jl(n){for(var e=n;e!==null;){if(e.tag===13){var t=e.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break;for(;e.sibling===null;){if(e.return===null||e.return===n)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var uu=[];function Zf(){for(var n=0;nt?t:4,n(!0);var r=cu.transition;cu.transition={};try{n(!1),e()}finally{U=t,cu.transition=r}}function r1(){return pt().memoizedState}function HN(n,e,t){var r=En(n);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},i1(n))o1(e,t);else if(t=P0(n,e,t,r),t!==null){var i=Ae();xt(t,n,r,i),s1(t,e,r)}}function jN(n,e,t){var r=En(n),i={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(i1(n))o1(e,i);else{var o=n.alternate;if(n.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,t);if(i.hasEagerState=!0,i.eagerState=l,Nt(l,s)){var a=e.interleaved;a===null?(i.next=i,Qf(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}t=P0(n,e,i,r),t!==null&&(i=Ae(),xt(t,n,r,i),s1(t,e,r))}}function i1(n){var e=n.alternate;return n===G||e!==null&&e===G}function o1(n,e){co=_l=!0;var t=n.pending;t===null?e.next=e:(e.next=t.next,t.next=e),n.pending=e}function s1(n,e,t){if(t&4194240){var r=e.lanes;r&=n.pendingLanes,t|=r,e.lanes=t,Pf(n,t)}}var Wl={readContext:ht,useCallback:ve,useContext:ve,useEffect:ve,useImperativeHandle:ve,useInsertionEffect:ve,useLayoutEffect:ve,useMemo:ve,useReducer:ve,useRef:ve,useState:ve,useDebugValue:ve,useDeferredValue:ve,useTransition:ve,useMutableSource:ve,useSyncExternalStore:ve,useId:ve,unstable_isNewReconciler:!1},KN={readContext:ht,useCallback:function(n,e){return Et().memoizedState=[n,e===void 0?null:e],n},useContext:ht,useEffect:Rp,useImperativeHandle:function(n,e,t){return t=t!=null?t.concat([n]):null,al(4194308,4,X0.bind(null,e,n),t)},useLayoutEffect:function(n,e){return al(4194308,4,n,e)},useInsertionEffect:function(n,e){return al(4,2,n,e)},useMemo:function(n,e){var t=Et();return e=e===void 0?null:e,n=n(),t.memoizedState=[n,e],n},useReducer:function(n,e,t){var r=Et();return e=t!==void 0?t(e):e,r.memoizedState=r.baseState=e,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:e},r.queue=n,n=n.dispatch=HN.bind(null,G,n),[r.memoizedState,n]},useRef:function(n){var e=Et();return n={current:n},e.memoizedState=n},useState:Tp,useDebugValue:id,useDeferredValue:function(n){return Et().memoizedState=n},useTransition:function(){var n=Tp(!1),e=n[0];return n=UN.bind(null,n[1]),Et().memoizedState=n,[e,n]},useMutableSource:function(){},useSyncExternalStore:function(n,e,t){var r=G,i=Et();if(Q){if(t===void 0)throw Error(E(407));t=t()}else{if(t=e(),de===null)throw Error(E(349));ur&30||U0(r,e,t)}i.memoizedState=t;var o={value:t,getSnapshot:e};return i.queue=o,Rp(j0.bind(null,r,o,n),[n]),r.flags|=2048,Jo(9,H0.bind(null,r,o,t,e),void 0,null),t},useId:function(){var n=Et(),e=de.identifierPrefix;if(Q){var t=Kt,r=jt;t=(r&~(1<<32-vt(r)-1)).toString(32)+t,e=":"+e+"R"+t,t=Vo++,0<\/script>",n=n.removeChild(n.firstChild)):typeof r.is=="string"?n=s.createElement(t,{is:r.is}):(n=s.createElement(t),t==="select"&&(s=n,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):n=s.createElementNS(n,t),n[Ot]=e,n[Fo]=r,m1(n,e,!1,!1),e.stateNode=n;e:{switch(s=fc(t,r),t){case"dialog":K("cancel",n),K("close",n),i=r;break;case"iframe":case"object":case"embed":K("load",n),i=r;break;case"video":case"audio":for(i=0;ici&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304)}else{if(!r)if(n=Jl(s),n!==null){if(e.flags|=128,r=!0,t=n.updateQueue,t!==null&&(e.updateQueue=t,e.flags|=4),Mi(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!Q)return xe(e),null}else 2*ne()-o.renderingStartTime>ci&&t!==1073741824&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(t=o.last,t!==null?t.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=ne(),e.sibling=null,t=Y.current,H(Y,r?t&1|2:t&1),e):(xe(e),null);case 22:case 23:return cd(),r=e.memoizedState!==null,n!==null&&n.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ge&1073741824&&(xe(e),e.subtreeFlags&6&&(e.flags|=8192)):xe(e),null;case 24:return null;case 25:return null}throw Error(E(156,e.tag))}function tM(n,e){switch(Uf(e),e.tag){case 1:return He(e.type)&&zl(),n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 3:return ai(),q(Ue),q(Oe),Zf(),n=e.flags,n&65536&&!(n&128)?(e.flags=n&-65537|128,e):null;case 5:return Xf(e),null;case 13:if(q(Y),n=e.memoizedState,n!==null&&n.dehydrated!==null){if(e.alternate===null)throw Error(E(340));si()}return n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 19:return q(Y),null;case 4:return ai(),null;case 10:return qf(e.type._context),null;case 22:case 23:return cd(),null;case 24:return null;default:return null}}var As=!1,Ne=!1,nM=typeof WeakSet=="function"?WeakSet:Set,R=null;function Lr(n,e){var t=n.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){Z(n,e,r)}else t.current=null}function $c(n,e,t){try{t()}catch(r){Z(n,e,r)}}var Vp=!1;function rM(n,e){if(vc=Rl,n=v0(),_f(n)){if("selectionStart"in n)var t={start:n.selectionStart,end:n.selectionEnd};else e:{t=(t=n.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{t.nodeType,o.nodeType}catch{t=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=n,d=null;t:for(;;){for(var p;f!==t||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===n)break t;if(d===t&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}t=l===-1||a===-1?null:{start:l,end:a}}else t=null}t=t||{start:0,end:0}}else t=null;for(xc={focusedElem:n,selectionRange:t},Rl=!1,R=e;R!==null;)if(e=R,n=e.child,(e.subtreeFlags&1028)!==0&&n!==null)n.return=e,R=n;else for(;R!==null;){e=R;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,S=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:yt(e.type,m),S);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var w=e.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(C){Z(e,e.return,C)}if(n=e.sibling,n!==null){n.return=e.return,R=n;break}R=e.return}return h=Vp,Vp=!1,h}function fo(n,e,t){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&n)===n){var o=i.destroy;i.destroy=void 0,o!==void 0&&$c(e,t,o)}i=i.next}while(i!==r)}}function ca(n,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var t=e=e.next;do{if((t.tag&n)===n){var r=t.create;t.destroy=r()}t=t.next}while(t!==e)}}function Vc(n){var e=n.ref;if(e!==null){var t=n.stateNode;switch(n.tag){case 5:n=t;break;default:n=t}typeof e=="function"?e(n):e.current=n}}function S1(n){var e=n.alternate;e!==null&&(n.alternate=null,S1(e)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(e=n.stateNode,e!==null&&(delete e[Ot],delete e[Fo],delete e[Mc],delete e[VN],delete e[BN])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function w1(n){return n.tag===5||n.tag===3||n.tag===4}function Bp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||w1(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function Bc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.nodeType===8?t.parentNode.insertBefore(n,e):t.insertBefore(n,e):(t.nodeType===8?(e=t.parentNode,e.insertBefore(n,t)):(e=t,e.appendChild(n)),t=t._reactRootContainer,t!=null||e.onclick!==null||(e.onclick=Il));else if(r!==4&&(n=n.child,n!==null))for(Bc(n,e,t),n=n.sibling;n!==null;)Bc(n,e,t),n=n.sibling}function Jc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.insertBefore(n,e):t.appendChild(n);else if(r!==4&&(n=n.child,n!==null))for(Jc(n,e,t),n=n.sibling;n!==null;)Jc(n,e,t),n=n.sibling}var me=null,St=!1;function tn(n,e,t){for(t=t.child;t!==null;)k1(n,e,t),t=t.sibling}function k1(n,e,t){if(At&&typeof At.onCommitFiberUnmount=="function")try{At.onCommitFiberUnmount(na,t)}catch{}switch(t.tag){case 5:Ne||Lr(t,e);case 6:var r=me,i=St;me=null,tn(n,e,t),me=r,St=i,me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?n.parentNode.removeChild(t):n.removeChild(t)):me.removeChild(t.stateNode));break;case 18:me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?lu(n.parentNode,t):n.nodeType===1&&lu(n,t),Ao(n)):lu(me,t.stateNode));break;case 4:r=me,i=St,me=t.stateNode.containerInfo,St=!0,tn(n,e,t),me=r,St=i;break;case 0:case 11:case 14:case 15:if(!Ne&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&$c(t,e,s),i=i.next}while(i!==r)}tn(n,e,t);break;case 1:if(!Ne&&(Lr(t,e),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(l){Z(t,e,l)}tn(n,e,t);break;case 21:tn(n,e,t);break;case 22:t.mode&1?(Ne=(r=Ne)||t.memoizedState!==null,tn(n,e,t),Ne=r):tn(n,e,t);break;default:tn(n,e,t)}}function Jp(n){var e=n.updateQueue;if(e!==null){n.updateQueue=null;var t=n.stateNode;t===null&&(t=n.stateNode=new nM),e.forEach(function(r){var i=dM.bind(null,n,r);t.has(r)||(t.add(r),r.then(i,i))})}}function gt(n,e){var t=e.deletions;if(t!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*oM(r/1960))-r,10n?16:n,yn===null)var r=!1;else{if(n=yn,yn=null,jl=0,B&6)throw Error(E(331));var i=B;for(B|=4,R=n.current;R!==null;){var o=R,s=o.child;if(R.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ane()-ad?rr(n,0):ld|=t),je(n,e)}function D1(n,e){e===0&&(n.mode&1?(e=xs,xs<<=1,!(xs&130023424)&&(xs=4194304)):e=1);var t=Ae();n=Xt(n,e),n!==null&&(ts(n,e,t),je(n,t))}function fM(n){var e=n.memoizedState,t=0;e!==null&&(t=e.retryLane),D1(n,t)}function dM(n,e){var t=0;switch(n.tag){case 13:var r=n.stateNode,i=n.memoizedState;i!==null&&(t=i.retryLane);break;case 19:r=n.stateNode;break;default:throw Error(E(314))}r!==null&&r.delete(e),D1(n,t)}var T1;T1=function(n,e,t){if(n!==null)if(n.memoizedProps!==e.pendingProps||Ue.current)_e=!0;else{if(!(n.lanes&t)&&!(e.flags&128))return _e=!1,ZN(n,e,t);_e=!!(n.flags&131072)}else _e=!1,Q&&e.flags&1048576&&b0(e,Ll,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ul(n,e),n=e.pendingProps;var i=oi(e,Oe.current);jr(e,t),i=td(null,e,r,n,i,t);var o=nd();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,He(r)?(o=!0,Pl(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Yf(e),i.updater=aa,e.stateNode=i,i._reactInternals=e,Ac(e,r,n,t),e=zc(null,e,r,!0,o,t)):(e.tag=0,Q&&o&&Wf(e),Te(null,e,i,t),e=e.child),e;case 16:r=e.elementType;e:{switch(ul(n,e),n=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=pM(r),n=yt(r,n),i){case 0:e=Ic(null,e,r,n,t);break e;case 1:e=Fp(null,e,r,n,t);break e;case 11:e=zp(null,e,r,n,t);break e;case 14:e=Pp(null,e,r,yt(r.type,n),t);break e}throw Error(E(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Ic(n,e,r,i,t);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Fp(n,e,r,i,t);case 3:e:{if(d1(e),n===null)throw Error(E(387));r=e.pendingProps,o=e.memoizedState,i=o.element,F0(n,e),Bl(e,r,null,t);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=ui(Error(E(423)),e),e=Lp(n,e,r,t,i);break e}else if(r!==i){i=ui(Error(E(424)),e),e=Lp(n,e,r,t,i);break e}else for(Ze=Cn(e.stateNode.containerInfo.firstChild),tt=e,Q=!0,kt=null,t=B0(e,null,r,t),e.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(si(),r===i){e=Zt(n,e,t);break e}Te(n,e,r,t)}e=e.child}return e;case 5:return J0(e),n===null&&Dc(e),r=e.type,i=e.pendingProps,o=n!==null?n.memoizedProps:null,s=i.children,Cc(r,i)?s=null:o!==null&&Cc(r,o)&&(e.flags|=32),f1(n,e),Te(n,e,s,t),e.child;case 6:return n===null&&Dc(e),null;case 13:return h1(n,e,t);case 4:return Gf(e,e.stateNode.containerInfo),r=e.pendingProps,n===null?e.child=li(e,null,r,t):Te(n,e,r,t),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),zp(n,e,r,i,t);case 7:return Te(n,e,e.pendingProps,t),e.child;case 8:return Te(n,e,e.pendingProps.children,t),e.child;case 12:return Te(n,e,e.pendingProps.children,t),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H($l,r._currentValue),r._currentValue=s,o!==null)if(Nt(o.value,s)){if(o.children===i.children&&!Ue.current){e=Zt(n,e,t);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Qt(-1,t&-t),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=t,a=o.alternate,a!==null&&(a.lanes|=t),Tc(o.return,t,e),l.lanes|=t;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(E(341));s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),Tc(s,t,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Te(n,e,i.children,t),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,jr(e,t),i=ht(i),r=r(i),e.flags|=1,Te(n,e,r,t),e.child;case 14:return r=e.type,i=yt(r,e.pendingProps),i=yt(r.type,i),Pp(n,e,r,i,t);case 15:return u1(n,e,e.type,e.pendingProps,t);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),ul(n,e),e.tag=1,He(r)?(n=!0,Pl(e)):n=!1,jr(e,t),$0(e,r,i),Ac(e,r,i,t),zc(null,e,r,!0,n,t);case 19:return p1(n,e,t);case 22:return c1(n,e,t)}throw Error(E(156,e.tag))};function R1(n,e){return n0(n,e)}function hM(n,e,t,r){this.tag=n,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ct(n,e,t,r){return new hM(n,e,t,r)}function dd(n){return n=n.prototype,!(!n||!n.isReactComponent)}function pM(n){if(typeof n=="function")return dd(n)?1:0;if(n!=null){if(n=n.$$typeof,n===Af)return 11;if(n===bf)return 14}return 2}function On(n,e){var t=n.alternate;return t===null?(t=ct(n.tag,e,n.key,n.mode),t.elementType=n.elementType,t.type=n.type,t.stateNode=n.stateNode,t.alternate=n,n.alternate=t):(t.pendingProps=e,t.type=n.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=n.flags&14680064,t.childLanes=n.childLanes,t.lanes=n.lanes,t.child=n.child,t.memoizedProps=n.memoizedProps,t.memoizedState=n.memoizedState,t.updateQueue=n.updateQueue,e=n.dependencies,t.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},t.sibling=n.sibling,t.index=n.index,t.ref=n.ref,t}function dl(n,e,t,r,i,o){var s=2;if(r=n,typeof n=="function")dd(n)&&(s=1);else if(typeof n=="string")s=5;else e:switch(n){case Dr:return ir(t.children,i,o,e);case Rf:s=8,i|=8;break;case tc:return n=ct(12,t,e,i|2),n.elementType=tc,n.lanes=o,n;case nc:return n=ct(13,t,e,i),n.elementType=nc,n.lanes=o,n;case rc:return n=ct(19,t,e,i),n.elementType=rc,n.lanes=o,n;case Vy:return da(t,i,o,e);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case Ly:s=10;break e;case $y:s=9;break e;case Af:s=11;break e;case bf:s=14;break e;case on:s=16,r=null;break e}throw Error(E(130,n==null?n:typeof n,""))}return e=ct(s,t,e,i),e.elementType=n,e.type=r,e.lanes=o,e}function ir(n,e,t,r){return n=ct(7,n,r,e),n.lanes=t,n}function da(n,e,t,r){return n=ct(22,n,r,e),n.elementType=Vy,n.lanes=t,n.stateNode={isHidden:!1},n}function mu(n,e,t){return n=ct(6,n,null,e),n.lanes=t,n}function gu(n,e,t){return e=ct(4,n.children!==null?n.children:[],n.key,e),e.lanes=t,e.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},e}function mM(n,e,t,r,i){this.tag=e,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ya(0),this.expirationTimes=Ya(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ya(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function hd(n,e,t,r,i,o,s,l,a){return n=new mM(n,e,t,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=ct(3,null,null,e),n.current=o,o.stateNode=n,o.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Yf(o),n}function gM(n,e,t){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(z1)}catch(n){console.error(n)}}z1(),by.exports=rt;var fi=by.exports,P1,Qp=fi;P1=Qp.createRoot,Qp.hydrateRoot;const yi=k.createContext(null),vM=k.createContext(null),F1=k.createContext(null),zs=new WeakMap;function xM(n){const e=Object.create(null);e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",i=>{if(typeof i=="function"&&(i=i(n.state)),i)for(const o in i)o=="class"?e.class+=" "+i[o]:o=="style"?e.style=(e.style?e.style+";":"")+i[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(i[o]))}),e.translate||(e.translate="no");const t=[Se.node(0,n.state.doc.content.size,e)],r=zs.get(n);return!r||r[0].to!==n.state.doc.content.size||!r[0].type.eq(t[0].type)?(zs.set(n,t),t):r}const CM=[],NM={},jc=_.empty;class fn{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,NM));return fn.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t0;)e++;n.splice(e,0,t)}const yu=new WeakMap;function EM(n,e){const t=[];n.someProp("decorations",s=>{const l=s(n.state);l&&l!=jc&&t.push(l)}),e&&t.push(_.create(n.state.doc,[e]));const r=yu.get(n);if(!r){const s=fn.from(t);return yu.set(n,s),s}let i=0,o=!0;if(r.forEachSet(s=>{t[i++]!==s&&(o=!1)}),i!==t.length&&(o=!1),!o){const s=fn.from(t);return yu.set(n,s),s}return r}const yd=function(n){for(let e=0;;e++)if(n=n.previousSibling,!n)return e},Gp=function(n){const e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},OM=function(n,e,t,r){return t&&(Xp(n,e,t,r,-1)||Xp(n,e,t,r,1))},DM=/^(img|br|input|textarea|hr)$/i;function Xp(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ql(n))){const o=n.parentNode;if(!o||o.nodeType!=1||RM(n)||DM.test(n.nodeName)||n.contentEditable=="false")return!1;e=yd(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Ql(n):0}else return!1}}function Ql(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function TM(n,e,t){for(let r=e==0,i=e==Ql(n);r||i;){if(n==t)return!0;const o=yd(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Ql(n)}return!1}function RM(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 $1=function(n){return n.focusNode&&OM(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)},V1=k.createContext(null);function AM(n,e){const t=k.useContext(V1);k.useLayoutEffect(()=>t(n),e)}function B1(n,e){const{view:t}=k.useContext(yi);AM(()=>{if(t)return n(t)},e&&[t,...e])}const bM=k.forwardRef(function({widget:e,getPos:t,...r},i){const[o,s]=k.useState(!0),l=k.useRef(null);return k.useImperativeHandle(i,()=>l.current,[]),B1(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,yd(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?A.jsx("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function IM(n,e){if(n==e)return!0;for(const t in n)if(n[t]!==e[t])return!1;for(const t in e)if(!(t in n))return!1;return!0}const zM={side:0};class Wo{constructor(e,t){this.Component=e,this.spec=t??zM,this.side=this.spec.side??0}map(e,t,r,i){const{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Wo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&IM(this.spec,e.spec))}destroy(){}}function J1(n,e,t){return new Se(n,n,new Wo(e,t))}function Su(){return Math.floor(Math.random()*0xffffffffffff).toString(16)}const Uo=new Yo("@nytimes/react-prosemirror/reactKeys");function PM(){let n=!1;return new $t({key:Uo,state:{init(e,t){const r={posToKey:new Map,keyToPos:new Map};return t.doc.descendants((i,o)=>{const s=Su();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,t,r,i){if(!e.docChanged||n)return t;const o=e.getMeta(Uo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(t.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=Su()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=Su();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{n=!0},compositionend:()=>{n=!1}}}})}function wu(n,e,t={}){var s;if(e===null)return!1;const r=t.from??n.state.selection.from,i=t.to??n.state.selection.to;if(n.someProp("handleTextInput",l=>l(n,r,i,e)))return!0;const{tr:o}=n.state;if(t.marks&&o.ensureMarks(t.marks),o.insertText(e,r,i),t.bust){const l=n.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=Uo.getState(n.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(Uo,{type:"bustKey",payload:{key:c}})}return n.dispatch(o),!0}function FM(n){let e=null,t=null;return new $t({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&n(J1(i.selection.from,bM,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),t=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return wu(r,e,{bust:!0,marks:t}),e=null,t=null,n(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);wu(r,a,{from:c,to:f})}});break}case"insertText":{wu(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Lt=typeof navigator<"u"?navigator:null,Zp=typeof document<"u"?document:null,Fn=Lt&&Lt.userAgent||"",Kc=/Edge\/(\d+)/.exec(Fn),_1=/MSIE \d/.exec(Fn),qc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Fn),ya=!!(_1||qc||Kc),LM=_1?document.documentMode:qc?+qc[1]:Kc?+Kc[1]:0,W1=!ya&&/gecko\/(\d+)/i.test(Fn),$M=W1&&+(/Firefox\/(\d+)/.exec(Fn)||[0,0])[1],Qc=!ya&&/Chrome\/(\d+)/.exec(Fn),VM=!!Qc,BM=Qc?+Qc[1]:0,U1=!ya&&!!Lt&&/Apple Computer/.test(Lt.vendor),H1=U1&&(/Mobile\/\w+/.test(Fn)||!!Lt&&Lt.maxTouchPoints>2),JM=H1||(Lt?/Mac/.test(Lt.platform):!1),_M=Lt?/Win/.test(Lt.platform):!1,WM=/Android \d/.test(Fn),j1=!!Zp&&"webkitFontSmoothing"in Zp.documentElement.style,UM=j1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ee={ie:ya,ie_version:LM,gecko:W1,gecko_version:$M,chrome:VM,chrome_version:BM,safari:U1,ios:H1,mac:JM,windows:_M,android:WM,webkit:j1,webkit_version:UM};function ku(n){return n.editable&&!n.hasFocus()?!1:HM(n)}function HM(n){var t,r;const 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(((t=e.focusNode)==null?void 0:t.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function jM(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function em(n,e=null){const t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode);const o=i&&i.size==0;let s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if($1(t)){for(a=s;i&&!i.node;)i=i.parent;const f=i.node;if(i&&f.isAtom&&I.isSelectable(f)&&i.parent&&!(f.isInline&&TM(t.focusNode,t.focusOffset,i.dom))){const d=i.posBefore;u=new I(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let p=0;p{(r.anchorNode!=i||r.anchorOffset!=o)&&(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!K1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const sm=Ee.safari||Ee.chrome&&Ee.chrome_version<63;function Ps(n,e=!1){const t=n,r=t.state.selection;if(QM(t,r),!!K1(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ee.chrome){const i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Yl(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)GM(t);else{const{anchor:i,head:o}=r;let s,l;sm&&!(r instanceof $)&&(r.$from.parent.inlineContent||(s=im(t,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=im(t,r.to))),t.docView.setSelection(i,o,t.root,e),sm&&(s&&om(s),l&&om(l)),r.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&XM(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}class ZM{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 eE{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new ZM,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const t=new Set;let r;for(let o=e.focusNode;o;o=Gp(o))t.add(o);for(let o=e.anchorNode;o;o=Gp(o))if(t.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,t=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=em(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),t&&o.setMeta("composition",t),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Ps(e);const t=e.domSelectionRange();this.currentSelection.set(t)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const t=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&ku(e)&&!this.ignoreSelectionChange(t);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(ku(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Ps(this.view);if(Ee.ie&&Ee.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&Yl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}function gr(n,e){return n instanceof jo?1:e instanceof jo?-1:n.getPos()-e.getPos()}const di=0,lm=1,Fs=2,Ho=3;class ss{constructor(e,t,r,i,o){this.parent=e,this.children=t,this.getPos=r,this.dom=i,this.contentDOM=o,this.dirty=di,i.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;tln(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 o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const 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){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof jo){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Sd&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ln(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ln(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;ch&&st){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Fs:lm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ho:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Fs:Ho}r=s}this.dirty=Fs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Fs:lm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>x.empty)}return e}matchesNode(e,t,r){return this.dirty==di&&e.eq(this.node)&&rE(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}get domAtom(){return this.node.isAtom}}class nE extends wd{constructor(e,t,r,i,o,s,l,a){super(e,t,r,i,o,s,l,null,a,()=>!1,()=>{},()=>{})}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!0}inParent(){const 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"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ho)}get domAtom(){return!1}}class jo extends ss{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==di&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function rE(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new $t({key:new Yo("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function oE(){const[n,e]=k.useState(new Map),t=k.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=k.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=k.useMemo(()=>iE(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function q1(){const[,n]=k.useReducer(e=>e+1,0);return n}function sE(n){const e=Object.create(null);function t(r){for(const i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function lE(n,e){let t=0,r=0;for(const i in n){if(n[i]!=e[i])return!0;t++}for(const i in e)r++;return t!=r}function aE(n,e){for(const t of Object.keys(n))if(n[t]!==e[t])return!0;return!1}function am(n){return!n.someProp("editable",e=>e(n.state)===!1)}class uE extends Fv{constructor(e,t){super(e,{state:dn.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new eE(this),this.domObserver.start(),this.editable=am(this),this.docView.dom.replaceChildren(),this.docView=t.docView}get needsRedraw(){if(this.oldProps.state.plugins===this._props.state.plugins&&this._props.plugins===this.oldProps.plugins)return!1;const e=sE(this);return lE(this.nodeViews,e)}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state,this.editable=am(this)}runPendingEffects(){if(aE(this.props,this.oldProps)){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const cE=new zm({nodes:{doc:{content:"text*"},text:{inline:!0}}}),fE=dn.create({schema:cE});function dE(n,e){const[t,r]=k.useState(null),[i,o]=k.useState(null),s=q1(),l=e.defaultState??fE,[a,u]=k.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=oE(),h=k.useCallback(M=>{fi.flushSync(()=>{o(M)})},[]),m=k.useMemo(()=>[...e.plugins??[],f,FM(h)],[e.plugins,f,h]),S=k.useCallback(function(N){fi.flushSync(()=>{e.state||u(O=>O.apply(N)),e.dispatchTransaction&&e.dispatchTransaction.call(this,N)})},[e.dispatchTransaction,e.state]),g=document.createElement("div"),y=k.useRef(new wd(void 0,[],()=>-1,c.doc,[],_.empty,g,null,g,()=>!1,()=>{},()=>{})),w={...e,state:c,plugins:m,dispatchTransaction:S,docView:y.current};return k.useLayoutEffect(()=>()=>{t==null||t.destroy()},[t]),k.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const M=new uE({mount:n},w);r(M),M.dom.addEventListener("compositionend",s);return}}),k.useLayoutEffect(()=>{if(t!=null&&t.needsRedraw){r(null);return}else t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()}),t==null||t.pureSetProps(w),{editor:k.useMemo(()=>({view:t,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,d,p,i]),state:c}}function hE({children:n}){const e=k.useRef(new Set).current,t=k.useRef(new Set).current,r=k.useRef(!1),i=q1(),o=k.useRef(!0),s=k.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=k.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return k.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),k.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),A.jsx(V1.Provider,{value:l,children:n})}const mt=k.createContext({parentRef:{current:void 0},siblingsRef:{current:[]}});function Q1(n,e,t,r,i,o,s,l){const{view:a}=k.useContext(yi),[u,c]=k.useState(!0),f=k.useRef(s),d=k.useRef(()=>!1),p=k.useCallback(C=>{d.current=C},[]),h=k.useRef(()=>{!r.current||!n||(r.current.nodeType==1&&r.current.classList.add("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&(((t==null?void 0:t.current)??r.current).draggable=!0))}),m=k.useRef(()=>{!r.current||!n||r.current.nodeType==1&&(r.current.classList.remove("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&((t==null?void 0:t.current)??r.current).removeAttribute("draggable"))}),S=k.useCallback((C,M)=>{h.current=C,m.current=M},[]),{siblingsRef:g,parentRef:y}=k.useContext(mt),w=k.useRef([]);return k.useLayoutEffect(()=>{const C=g.current;return()=>{if(f.current&&C.includes(f.current)){const M=C.indexOf(f.current);C.splice(M,1)}}},[g]),k.useLayoutEffect(()=>{var M;if(!n||!r.current)return;const C=w.current[0];f.current?(f.current.parent=y.current,f.current.children=w.current,f.current.node=n,f.current.getPos=e,f.current.outerDeco=o,f.current.innerDeco=i,f.current.dom=(t==null?void 0:t.current)??r.current,f.current.dom.pmViewDesc=f.current,f.current.contentDOM=(l==null?void 0:l.current)??f.current.contentDOM??(C==null?void 0:C.dom.parentElement)??null,f.current.nodeDOM=r.current):f.current=new wd(y.current,w.current,e,n,o,i,(t==null?void 0:t.current)??r.current,(C==null?void 0:C.dom.parentElement)??null,r.current,N=>!!d.current(N),()=>h.current(),()=>m.current()),c(f.current.contentDOM!==null),g.current.includes(f.current)||g.current.push(f.current),g.current.sort(gr);for(const N of w.current)if(N.parent=f.current,N instanceof Gl){const O=(M=f.current.contentDOM)==null?void 0:M.firstChild;if(!O)throw new Error("Started a composition but couldn't find the text node it belongs to.");let D=O;for(;D.firstChild;)D=D.firstChild;if(!D||!(D instanceof Text))throw new Error("Started a composition but couldn't find the text node it belongs to.");N.dom=O,N.textDOM=D,N.text=D.data,N.textDOM.pmViewDesc=N,a==null||a.input.compositionNodes.push(N)}return()=>{var N,O,D,b;((N=f.current)==null?void 0:N.children[0])instanceof Gl&&!(a!=null&&a.composing)&&((b=(O=f.current)==null?void 0:O.children[0].dom.parentNode)==null||b.removeChild((D=f.current)==null?void 0:D.children[0].dom))}}),{hasContentDOM:u,childDescriptors:w,nodeViewDescRef:f,setStopEvent:p,setSelectNode:S}}function pE(n,e){return n.type.side-e.type.side}function mE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function gE(){const{view:n}=k.useContext(yi);return n&&Uo.getState(n.state)}var Y1={exports:{}};/*! +`+o.stack}return{value:n,source:e,stack:i,digest:null}}function hu(n,e,t){return{value:n,source:null,stack:t??null,digest:e??null}}function bc(n,e){try{console.error(e.value)}catch(t){setTimeout(function(){throw t})}}var YN=typeof WeakMap=="function"?WeakMap:Map;function l1(n,e,t){t=Qt(-1,t),t.tag=3,t.payload={element:null};var r=e.value;return t.callback=function(){Hl||(Hl=!0,_c=r),bc(n,e)},t}function a1(n,e,t){t=Qt(-1,t),t.tag=3;var r=n.type.getDerivedStateFromError;if(typeof r=="function"){var i=e.value;t.payload=function(){return r(i)},t.callback=function(){bc(n,e)}}var o=n.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(t.callback=function(){bc(n,e),typeof r!="function"&&(Mn===null?Mn=new Set([this]):Mn.add(this));var s=e.stack;this.componentDidCatch(e.value,{componentStack:s!==null?s:""})}),t}function Ap(n,e,t){var r=n.pingCache;if(r===null){r=n.pingCache=new YN;var i=new Set;r.set(e,i)}else i=r.get(e),i===void 0&&(i=new Set,r.set(e,i));i.has(t)||(i.add(t),n=cM.bind(null,n,e,t),e.then(n,n))}function bp(n){do{var e;if((e=n.tag===13)&&(e=n.memoizedState,e=e!==null?e.dehydrated!==null:!0),e)return n;n=n.return}while(n!==null);return null}function Ip(n,e,t,r,i){return n.mode&1?(n.flags|=65536,n.lanes=i,n):(n===e?n.flags|=65536:(n.flags|=128,t.flags|=131072,t.flags&=-52805,t.tag===1&&(t.alternate===null?t.tag=17:(e=Qt(-1,1),e.tag=2,Nn(t,e,1))),t.lanes|=1),n)}var GN=en.ReactCurrentOwner,_e=!1;function Te(n,e,t,r){e.child=n===null?B0(e,null,t,r):li(e,n.child,t,r)}function zp(n,e,t,r,i){t=t.render;var o=e.ref;return jr(e,i),r=td(n,e,t,r,o,i),t=nd(),n!==null&&!_e?(e.updateQueue=n.updateQueue,e.flags&=-2053,n.lanes&=~i,Zt(n,e,i)):(Q&&t&&Wf(e),e.flags|=1,Te(n,e,r,i),e.child)}function Pp(n,e,t,r,i){if(n===null){var o=t.type;return typeof o=="function"&&!dd(o)&&o.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(e.tag=15,e.type=o,u1(n,e,o,r,i)):(n=dl(t.type,null,r,e,e.mode,i),n.ref=e.ref,n.return=e,e.child=n)}if(o=n.child,!(n.lanes&i)){var s=o.memoizedProps;if(t=t.compare,t=t!==null?t:Io,t(s,r)&&n.ref===e.ref)return Zt(n,e,i)}return e.flags|=1,n=On(o,r),n.ref=e.ref,n.return=e,e.child=n}function u1(n,e,t,r,i){if(n!==null){var o=n.memoizedProps;if(Io(o,r)&&n.ref===e.ref)if(_e=!1,e.pendingProps=r=o,(n.lanes&i)!==0)n.flags&131072&&(_e=!0);else return e.lanes=n.lanes,Zt(n,e,i)}return Ic(n,e,t,r,i)}function c1(n,e,t){var r=e.pendingProps,i=r.children,o=n!==null?n.memoizedState:null;if(r.mode==="hidden")if(!(e.mode&1))e.memoizedState={baseLanes:0,cachePool:null,transitions:null},H($r,Ge),Ge|=t;else{if(!(t&1073741824))return n=o!==null?o.baseLanes|t:t,e.lanes=e.childLanes=1073741824,e.memoizedState={baseLanes:n,cachePool:null,transitions:null},e.updateQueue=null,H($r,Ge),Ge|=n,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:t,H($r,Ge),Ge|=r}else o!==null?(r=o.baseLanes|t,e.memoizedState=null):r=t,H($r,Ge),Ge|=r;return Te(n,e,i,t),e.child}function f1(n,e){var t=e.ref;(n===null&&t!==null||n!==null&&n.ref!==t)&&(e.flags|=512,e.flags|=2097152)}function Ic(n,e,t,r,i){var o=He(t)?lr:Oe.current;return o=oi(e,o),jr(e,i),t=td(n,e,t,r,o,i),r=nd(),n!==null&&!_e?(e.updateQueue=n.updateQueue,e.flags&=-2053,n.lanes&=~i,Zt(n,e,i)):(Q&&r&&Wf(e),e.flags|=1,Te(n,e,t,i),e.child)}function Fp(n,e,t,r,i){if(He(t)){var o=!0;Pl(e)}else o=!1;if(jr(e,i),e.stateNode===null)ul(n,e),$0(e,t,r),Ac(e,t,r,i),r=!0;else if(n===null){var s=e.stateNode,l=e.memoizedProps;s.props=l;var a=s.context,u=t.contextType;typeof u=="object"&&u!==null?u=ht(u):(u=He(t)?lr:Oe.current,u=oi(e,u));var c=t.getDerivedStateFromProps,f=typeof c=="function"||typeof s.getSnapshotBeforeUpdate=="function";f||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==r||a!==u)&&Op(e,s,r,u),sn=!1;var d=e.memoizedState;s.state=d,Bl(e,r,s,i),a=e.memoizedState,l!==r||d!==a||Ue.current||sn?(typeof c=="function"&&(Rc(e,t,c,r),a=e.memoizedState),(l=sn||Ep(e,t,l,r,d,a,u))?(f||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(e.flags|=4194308)):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),e.memoizedProps=r,e.memoizedState=a),s.props=r,s.state=a,s.context=u,r=l):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),r=!1)}else{s=e.stateNode,F0(n,e),l=e.memoizedProps,u=e.type===e.elementType?l:yt(e.type,l),s.props=u,f=e.pendingProps,d=s.context,a=t.contextType,typeof a=="object"&&a!==null?a=ht(a):(a=He(t)?lr:Oe.current,a=oi(e,a));var p=t.getDerivedStateFromProps;(c=typeof p=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==f||d!==a)&&Op(e,s,r,a),sn=!1,d=e.memoizedState,s.state=d,Bl(e,r,s,i);var h=e.memoizedState;l!==f||d!==h||Ue.current||sn?(typeof p=="function"&&(Rc(e,t,p,r),h=e.memoizedState),(u=sn||Ep(e,t,u,r,d,h,a)||!1)?(c||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,h,a),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,h,a)),typeof s.componentDidUpdate=="function"&&(e.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(e.flags|=1024)):(typeof s.componentDidUpdate!="function"||l===n.memoizedProps&&d===n.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===n.memoizedProps&&d===n.memoizedState||(e.flags|=1024),e.memoizedProps=r,e.memoizedState=h),s.props=r,s.state=h,s.context=a,r=u):(typeof s.componentDidUpdate!="function"||l===n.memoizedProps&&d===n.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===n.memoizedProps&&d===n.memoizedState||(e.flags|=1024),r=!1)}return zc(n,e,t,r,o,i)}function zc(n,e,t,r,i,o){f1(n,e);var s=(e.flags&128)!==0;if(!r&&!s)return i&&vp(e,t,!1),Zt(n,e,o);r=e.stateNode,GN.current=e;var l=s&&typeof t.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,n!==null&&s?(e.child=li(e,n.child,null,o),e.child=li(e,null,l,o)):Te(n,e,l,o),e.memoizedState=r.state,i&&vp(e,t,!0),e.child}function d1(n){var e=n.stateNode;e.pendingContext?kp(n,e.pendingContext,e.pendingContext!==e.context):e.context&&kp(n,e.context,!1),Gf(n,e.containerInfo)}function Lp(n,e,t,r,i){return si(),Hf(i),e.flags|=256,Te(n,e,t,r),e.child}var Pc={dehydrated:null,treeContext:null,retryLane:0};function Fc(n){return{baseLanes:n,cachePool:null,transitions:null}}function h1(n,e,t){var r=e.pendingProps,i=Y.current,o=!1,s=(e.flags&128)!==0,l;if((l=s)||(l=n!==null&&n.memoizedState===null?!1:(i&2)!==0),l?(o=!0,e.flags&=-129):(n===null||n.memoizedState!==null)&&(i|=1),H(Y,i&1),n===null)return Dc(e),n=e.memoizedState,n!==null&&(n=n.dehydrated,n!==null)?(e.mode&1?n.data==="$!"?e.lanes=8:e.lanes=1073741824:e.lanes=1,null):(s=r.children,n=r.fallback,o?(r=e.mode,o=e.child,s={mode:"hidden",children:s},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=s):o=da(s,r,0,null),n=ir(n,r,t,null),o.return=e,n.return=e,o.sibling=n,e.child=o,e.child.memoizedState=Fc(t),e.memoizedState=Pc,n):od(e,s));if(i=n.memoizedState,i!==null&&(l=i.dehydrated,l!==null))return XN(n,e,s,r,l,i,t);if(o){o=r.fallback,s=e.mode,i=n.child,l=i.sibling;var a={mode:"hidden",children:r.children};return!(s&1)&&e.child!==i?(r=e.child,r.childLanes=0,r.pendingProps=a,e.deletions=null):(r=On(i,a),r.subtreeFlags=i.subtreeFlags&14680064),l!==null?o=On(l,o):(o=ir(o,s,t,null),o.flags|=2),o.return=e,r.return=e,r.sibling=o,e.child=r,r=o,o=e.child,s=n.child.memoizedState,s=s===null?Fc(t):{baseLanes:s.baseLanes|t,cachePool:null,transitions:s.transitions},o.memoizedState=s,o.childLanes=n.childLanes&~t,e.memoizedState=Pc,r}return o=n.child,n=o.sibling,r=On(o,{mode:"visible",children:r.children}),!(e.mode&1)&&(r.lanes=t),r.return=e,r.sibling=null,n!==null&&(t=e.deletions,t===null?(e.deletions=[n],e.flags|=16):t.push(n)),e.child=r,e.memoizedState=null,r}function od(n,e){return e=da({mode:"visible",children:e},n.mode,0,null),e.return=n,n.child=e}function Rs(n,e,t,r){return r!==null&&Hf(r),li(e,n.child,null,t),n=od(e,e.pendingProps.children),n.flags|=2,e.memoizedState=null,n}function XN(n,e,t,r,i,o,s){if(t)return e.flags&256?(e.flags&=-257,r=hu(Error(E(422))),Rs(n,e,s,r)):e.memoizedState!==null?(e.child=n.child,e.flags|=128,null):(o=r.fallback,i=e.mode,r=da({mode:"visible",children:r.children},i,0,null),o=ir(o,i,s,null),o.flags|=2,r.return=e,o.return=e,r.sibling=o,e.child=r,e.mode&1&&li(e,n.child,null,s),e.child.memoizedState=Fc(s),e.memoizedState=Pc,o);if(!(e.mode&1))return Rs(n,e,s,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var l=r.dgst;return r=l,o=Error(E(419)),r=hu(o,r,void 0),Rs(n,e,s,r)}if(l=(s&n.childLanes)!==0,_e||l){if(r=de,r!==null){switch(s&-s){case 4:i=2;break;case 16:i=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|s)?0:i,i!==0&&i!==o.retryLane&&(o.retryLane=i,Xt(n,i),xt(r,n,i,-1))}return fd(),r=hu(Error(E(421))),Rs(n,e,s,r)}return i.data==="$?"?(e.flags|=128,e.child=n.child,e=fM.bind(null,n),i._reactRetry=e,null):(n=o.treeContext,Ze=Cn(i.nextSibling),tt=e,Q=!0,kt=null,n!==null&&(st[lt++]=jt,st[lt++]=Kt,st[lt++]=ar,jt=n.id,Kt=n.overflow,ar=e),e=od(e,r.children),e.flags|=4096,e)}function $p(n,e,t){n.lanes|=e;var r=n.alternate;r!==null&&(r.lanes|=e),Tc(n.return,e,t)}function pu(n,e,t,r,i){var o=n.memoizedState;o===null?n.memoizedState={isBackwards:e,rendering:null,renderingStartTime:0,last:r,tail:t,tailMode:i}:(o.isBackwards=e,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=t,o.tailMode=i)}function p1(n,e,t){var r=e.pendingProps,i=r.revealOrder,o=r.tail;if(Te(n,e,r.children,t),r=Y.current,r&2)r=r&1|2,e.flags|=128;else{if(n!==null&&n.flags&128)e:for(n=e.child;n!==null;){if(n.tag===13)n.memoizedState!==null&&$p(n,t,e);else if(n.tag===19)$p(n,t,e);else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break e;for(;n.sibling===null;){if(n.return===null||n.return===e)break e;n=n.return}n.sibling.return=n.return,n=n.sibling}r&=1}if(H(Y,r),!(e.mode&1))e.memoizedState=null;else switch(i){case"forwards":for(t=e.child,i=null;t!==null;)n=t.alternate,n!==null&&Jl(n)===null&&(i=t),t=t.sibling;t=i,t===null?(i=e.child,e.child=null):(i=t.sibling,t.sibling=null),pu(e,!1,i,t,o);break;case"backwards":for(t=null,i=e.child,e.child=null;i!==null;){if(n=i.alternate,n!==null&&Jl(n)===null){e.child=i;break}n=i.sibling,i.sibling=t,t=i,i=n}pu(e,!0,t,null,o);break;case"together":pu(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function ul(n,e){!(e.mode&1)&&n!==null&&(n.alternate=null,e.alternate=null,e.flags|=2)}function Zt(n,e,t){if(n!==null&&(e.dependencies=n.dependencies),cr|=e.lanes,!(t&e.childLanes))return null;if(n!==null&&e.child!==n.child)throw Error(E(153));if(e.child!==null){for(n=e.child,t=On(n,n.pendingProps),e.child=t,t.return=e;n.sibling!==null;)n=n.sibling,t=t.sibling=On(n,n.pendingProps),t.return=e;t.sibling=null}return e.child}function ZN(n,e,t){switch(e.tag){case 3:d1(e),si();break;case 5:J0(e);break;case 1:He(e.type)&&Pl(e);break;case 4:Gf(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,i=e.memoizedProps.value;H($l,r._currentValue),r._currentValue=i;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(H(Y,Y.current&1),e.flags|=128,null):t&e.child.childLanes?h1(n,e,t):(H(Y,Y.current&1),n=Zt(n,e,t),n!==null?n.sibling:null);H(Y,Y.current&1);break;case 19:if(r=(t&e.childLanes)!==0,n.flags&128){if(r)return p1(n,e,t);e.flags|=128}if(i=e.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),H(Y,Y.current),r)break;return null;case 22:case 23:return e.lanes=0,c1(n,e,t)}return Zt(n,e,t)}var m1,Lc,g1,y1;m1=function(n,e){for(var t=e.child;t!==null;){if(t.tag===5||t.tag===6)n.appendChild(t.stateNode);else if(t.tag!==4&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return;t=t.return}t.sibling.return=t.return,t=t.sibling}};Lc=function(){};g1=function(n,e,t,r){var i=n.memoizedProps;if(i!==r){n=e.stateNode,Xn(bt.current);var o=null;switch(t){case"input":i=oc(n,i),r=oc(n,r),o=[];break;case"select":i=X({},i,{value:void 0}),r=X({},r,{value:void 0}),o=[];break;case"textarea":i=ac(n,i),r=ac(n,r),o=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(n.onclick=Il)}cc(t,r);var s;t=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var l=i[u];for(s in l)l.hasOwnProperty(s)&&(t||(t={}),t[s]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Eo.hasOwnProperty(u)?o||(o=[]):(o=o||[]).push(u,null));for(u in r){var a=r[u];if(l=i!=null?i[u]:void 0,r.hasOwnProperty(u)&&a!==l&&(a!=null||l!=null))if(u==="style")if(l){for(s in l)!l.hasOwnProperty(s)||a&&a.hasOwnProperty(s)||(t||(t={}),t[s]="");for(s in a)a.hasOwnProperty(s)&&l[s]!==a[s]&&(t||(t={}),t[s]=a[s])}else t||(o||(o=[]),o.push(u,t)),t=a;else u==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,l=l?l.__html:void 0,a!=null&&l!==a&&(o=o||[]).push(u,a)):u==="children"?typeof a!="string"&&typeof a!="number"||(o=o||[]).push(u,""+a):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Eo.hasOwnProperty(u)?(a!=null&&u==="onScroll"&&K("scroll",n),o||l===a||(o=[])):(o=o||[]).push(u,a))}t&&(o=o||[]).push("style",t);var u=o;(e.updateQueue=u)&&(e.flags|=4)}};y1=function(n,e,t,r){t!==r&&(e.flags|=4)};function Mi(n,e){if(!Q)switch(n.tailMode){case"hidden":e=n.tail;for(var t=null;e!==null;)e.alternate!==null&&(t=e),e=e.sibling;t===null?n.tail=null:t.sibling=null;break;case"collapsed":t=n.tail;for(var r=null;t!==null;)t.alternate!==null&&(r=t),t=t.sibling;r===null?e||n.tail===null?n.tail=null:n.tail.sibling=null:r.sibling=null}}function xe(n){var e=n.alternate!==null&&n.alternate.child===n.child,t=0,r=0;if(e)for(var i=n.child;i!==null;)t|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=n,i=i.sibling;else for(i=n.child;i!==null;)t|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=n,i=i.sibling;return n.subtreeFlags|=r,n.childLanes=t,e}function eM(n,e,t){var r=e.pendingProps;switch(Uf(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return xe(e),null;case 1:return He(e.type)&&zl(),xe(e),null;case 3:return r=e.stateNode,ai(),q(Ue),q(Oe),Zf(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(n===null||n.child===null)&&(Ds(e)?e.flags|=4:n===null||n.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,kt!==null&&(Hc(kt),kt=null))),Lc(n,e),xe(e),null;case 5:Xf(e);var i=Xn($o.current);if(t=e.type,n!==null&&e.stateNode!=null)g1(n,e,t,r,i),n.ref!==e.ref&&(e.flags|=512,e.flags|=2097152);else{if(!r){if(e.stateNode===null)throw Error(E(166));return xe(e),null}if(n=Xn(bt.current),Ds(e)){r=e.stateNode,t=e.type;var o=e.memoizedProps;switch(r[Ot]=e,r[Fo]=o,n=(e.mode&1)!==0,t){case"dialog":K("cancel",r),K("close",r);break;case"iframe":case"object":case"embed":K("load",r);break;case"video":case"audio":for(i=0;i<\/script>",n=n.removeChild(n.firstChild)):typeof r.is=="string"?n=s.createElement(t,{is:r.is}):(n=s.createElement(t),t==="select"&&(s=n,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):n=s.createElementNS(n,t),n[Ot]=e,n[Fo]=r,m1(n,e,!1,!1),e.stateNode=n;e:{switch(s=fc(t,r),t){case"dialog":K("cancel",n),K("close",n),i=r;break;case"iframe":case"object":case"embed":K("load",n),i=r;break;case"video":case"audio":for(i=0;ici&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304)}else{if(!r)if(n=Jl(s),n!==null){if(e.flags|=128,r=!0,t=n.updateQueue,t!==null&&(e.updateQueue=t,e.flags|=4),Mi(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!Q)return xe(e),null}else 2*ne()-o.renderingStartTime>ci&&t!==1073741824&&(e.flags|=128,r=!0,Mi(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(t=o.last,t!==null?t.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=ne(),e.sibling=null,t=Y.current,H(Y,r?t&1|2:t&1),e):(xe(e),null);case 22:case 23:return cd(),r=e.memoizedState!==null,n!==null&&n.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ge&1073741824&&(xe(e),e.subtreeFlags&6&&(e.flags|=8192)):xe(e),null;case 24:return null;case 25:return null}throw Error(E(156,e.tag))}function tM(n,e){switch(Uf(e),e.tag){case 1:return He(e.type)&&zl(),n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 3:return ai(),q(Ue),q(Oe),Zf(),n=e.flags,n&65536&&!(n&128)?(e.flags=n&-65537|128,e):null;case 5:return Xf(e),null;case 13:if(q(Y),n=e.memoizedState,n!==null&&n.dehydrated!==null){if(e.alternate===null)throw Error(E(340));si()}return n=e.flags,n&65536?(e.flags=n&-65537|128,e):null;case 19:return q(Y),null;case 4:return ai(),null;case 10:return qf(e.type._context),null;case 22:case 23:return cd(),null;case 24:return null;default:return null}}var As=!1,Ne=!1,nM=typeof WeakSet=="function"?WeakSet:Set,R=null;function Lr(n,e){var t=n.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){Z(n,e,r)}else t.current=null}function $c(n,e,t){try{t()}catch(r){Z(n,e,r)}}var Vp=!1;function rM(n,e){if(vc=Rl,n=v0(),_f(n)){if("selectionStart"in n)var t={start:n.selectionStart,end:n.selectionEnd};else e:{t=(t=n.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{t.nodeType,o.nodeType}catch{t=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=n,d=null;t:for(;;){for(var p;f!==t||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===n)break t;if(d===t&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}t=l===-1||a===-1?null:{start:l,end:a}}else t=null}t=t||{start:0,end:0}}else t=null;for(xc={focusedElem:n,selectionRange:t},Rl=!1,R=e;R!==null;)if(e=R,n=e.child,(e.subtreeFlags&1028)!==0&&n!==null)n.return=e,R=n;else for(;R!==null;){e=R;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,w=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:yt(e.type,m),w);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(x){Z(e,e.return,x)}if(n=e.sibling,n!==null){n.return=e.return,R=n;break}R=e.return}return h=Vp,Vp=!1,h}function fo(n,e,t){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&n)===n){var o=i.destroy;i.destroy=void 0,o!==void 0&&$c(e,t,o)}i=i.next}while(i!==r)}}function ca(n,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var t=e=e.next;do{if((t.tag&n)===n){var r=t.create;t.destroy=r()}t=t.next}while(t!==e)}}function Vc(n){var e=n.ref;if(e!==null){var t=n.stateNode;switch(n.tag){case 5:n=t;break;default:n=t}typeof e=="function"?e(n):e.current=n}}function S1(n){var e=n.alternate;e!==null&&(n.alternate=null,S1(e)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(e=n.stateNode,e!==null&&(delete e[Ot],delete e[Fo],delete e[Mc],delete e[VN],delete e[BN])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function w1(n){return n.tag===5||n.tag===3||n.tag===4}function Bp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||w1(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function Bc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.nodeType===8?t.parentNode.insertBefore(n,e):t.insertBefore(n,e):(t.nodeType===8?(e=t.parentNode,e.insertBefore(n,t)):(e=t,e.appendChild(n)),t=t._reactRootContainer,t!=null||e.onclick!==null||(e.onclick=Il));else if(r!==4&&(n=n.child,n!==null))for(Bc(n,e,t),n=n.sibling;n!==null;)Bc(n,e,t),n=n.sibling}function Jc(n,e,t){var r=n.tag;if(r===5||r===6)n=n.stateNode,e?t.insertBefore(n,e):t.appendChild(n);else if(r!==4&&(n=n.child,n!==null))for(Jc(n,e,t),n=n.sibling;n!==null;)Jc(n,e,t),n=n.sibling}var me=null,St=!1;function tn(n,e,t){for(t=t.child;t!==null;)k1(n,e,t),t=t.sibling}function k1(n,e,t){if(At&&typeof At.onCommitFiberUnmount=="function")try{At.onCommitFiberUnmount(na,t)}catch{}switch(t.tag){case 5:Ne||Lr(t,e);case 6:var r=me,i=St;me=null,tn(n,e,t),me=r,St=i,me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?n.parentNode.removeChild(t):n.removeChild(t)):me.removeChild(t.stateNode));break;case 18:me!==null&&(St?(n=me,t=t.stateNode,n.nodeType===8?lu(n.parentNode,t):n.nodeType===1&&lu(n,t),Ao(n)):lu(me,t.stateNode));break;case 4:r=me,i=St,me=t.stateNode.containerInfo,St=!0,tn(n,e,t),me=r,St=i;break;case 0:case 11:case 14:case 15:if(!Ne&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&$c(t,e,s),i=i.next}while(i!==r)}tn(n,e,t);break;case 1:if(!Ne&&(Lr(t,e),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(l){Z(t,e,l)}tn(n,e,t);break;case 21:tn(n,e,t);break;case 22:t.mode&1?(Ne=(r=Ne)||t.memoizedState!==null,tn(n,e,t),Ne=r):tn(n,e,t);break;default:tn(n,e,t)}}function Jp(n){var e=n.updateQueue;if(e!==null){n.updateQueue=null;var t=n.stateNode;t===null&&(t=n.stateNode=new nM),e.forEach(function(r){var i=dM.bind(null,n,r);t.has(r)||(t.add(r),r.then(i,i))})}}function gt(n,e){var t=e.deletions;if(t!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*oM(r/1960))-r,10n?16:n,yn===null)var r=!1;else{if(n=yn,yn=null,jl=0,B&6)throw Error(E(331));var i=B;for(B|=4,R=n.current;R!==null;){var o=R,s=o.child;if(R.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ane()-ad?rr(n,0):ld|=t),je(n,e)}function D1(n,e){e===0&&(n.mode&1?(e=xs,xs<<=1,!(xs&130023424)&&(xs=4194304)):e=1);var t=Ae();n=Xt(n,e),n!==null&&(ts(n,e,t),je(n,t))}function fM(n){var e=n.memoizedState,t=0;e!==null&&(t=e.retryLane),D1(n,t)}function dM(n,e){var t=0;switch(n.tag){case 13:var r=n.stateNode,i=n.memoizedState;i!==null&&(t=i.retryLane);break;case 19:r=n.stateNode;break;default:throw Error(E(314))}r!==null&&r.delete(e),D1(n,t)}var T1;T1=function(n,e,t){if(n!==null)if(n.memoizedProps!==e.pendingProps||Ue.current)_e=!0;else{if(!(n.lanes&t)&&!(e.flags&128))return _e=!1,ZN(n,e,t);_e=!!(n.flags&131072)}else _e=!1,Q&&e.flags&1048576&&b0(e,Ll,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ul(n,e),n=e.pendingProps;var i=oi(e,Oe.current);jr(e,t),i=td(null,e,r,n,i,t);var o=nd();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,He(r)?(o=!0,Pl(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Yf(e),i.updater=aa,e.stateNode=i,i._reactInternals=e,Ac(e,r,n,t),e=zc(null,e,r,!0,o,t)):(e.tag=0,Q&&o&&Wf(e),Te(null,e,i,t),e=e.child),e;case 16:r=e.elementType;e:{switch(ul(n,e),n=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=pM(r),n=yt(r,n),i){case 0:e=Ic(null,e,r,n,t);break e;case 1:e=Fp(null,e,r,n,t);break e;case 11:e=zp(null,e,r,n,t);break e;case 14:e=Pp(null,e,r,yt(r.type,n),t);break e}throw Error(E(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Ic(n,e,r,i,t);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),Fp(n,e,r,i,t);case 3:e:{if(d1(e),n===null)throw Error(E(387));r=e.pendingProps,o=e.memoizedState,i=o.element,F0(n,e),Bl(e,r,null,t);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=ui(Error(E(423)),e),e=Lp(n,e,r,t,i);break e}else if(r!==i){i=ui(Error(E(424)),e),e=Lp(n,e,r,t,i);break e}else for(Ze=Cn(e.stateNode.containerInfo.firstChild),tt=e,Q=!0,kt=null,t=B0(e,null,r,t),e.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(si(),r===i){e=Zt(n,e,t);break e}Te(n,e,r,t)}e=e.child}return e;case 5:return J0(e),n===null&&Dc(e),r=e.type,i=e.pendingProps,o=n!==null?n.memoizedProps:null,s=i.children,Cc(r,i)?s=null:o!==null&&Cc(r,o)&&(e.flags|=32),f1(n,e),Te(n,e,s,t),e.child;case 6:return n===null&&Dc(e),null;case 13:return h1(n,e,t);case 4:return Gf(e,e.stateNode.containerInfo),r=e.pendingProps,n===null?e.child=li(e,null,r,t):Te(n,e,r,t),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),zp(n,e,r,i,t);case 7:return Te(n,e,e.pendingProps,t),e.child;case 8:return Te(n,e,e.pendingProps.children,t),e.child;case 12:return Te(n,e,e.pendingProps.children,t),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H($l,r._currentValue),r._currentValue=s,o!==null)if(Nt(o.value,s)){if(o.children===i.children&&!Ue.current){e=Zt(n,e,t);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=Qt(-1,t&-t),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=t,a=o.alternate,a!==null&&(a.lanes|=t),Tc(o.return,t,e),l.lanes|=t;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(E(341));s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),Tc(s,t,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Te(n,e,i.children,t),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,jr(e,t),i=ht(i),r=r(i),e.flags|=1,Te(n,e,r,t),e.child;case 14:return r=e.type,i=yt(r,e.pendingProps),i=yt(r.type,i),Pp(n,e,r,i,t);case 15:return u1(n,e,e.type,e.pendingProps,t);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:yt(r,i),ul(n,e),e.tag=1,He(r)?(n=!0,Pl(e)):n=!1,jr(e,t),$0(e,r,i),Ac(e,r,i,t),zc(null,e,r,!0,n,t);case 19:return p1(n,e,t);case 22:return c1(n,e,t)}throw Error(E(156,e.tag))};function R1(n,e){return n0(n,e)}function hM(n,e,t,r){this.tag=n,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ct(n,e,t,r){return new hM(n,e,t,r)}function dd(n){return n=n.prototype,!(!n||!n.isReactComponent)}function pM(n){if(typeof n=="function")return dd(n)?1:0;if(n!=null){if(n=n.$$typeof,n===Af)return 11;if(n===bf)return 14}return 2}function On(n,e){var t=n.alternate;return t===null?(t=ct(n.tag,e,n.key,n.mode),t.elementType=n.elementType,t.type=n.type,t.stateNode=n.stateNode,t.alternate=n,n.alternate=t):(t.pendingProps=e,t.type=n.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=n.flags&14680064,t.childLanes=n.childLanes,t.lanes=n.lanes,t.child=n.child,t.memoizedProps=n.memoizedProps,t.memoizedState=n.memoizedState,t.updateQueue=n.updateQueue,e=n.dependencies,t.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},t.sibling=n.sibling,t.index=n.index,t.ref=n.ref,t}function dl(n,e,t,r,i,o){var s=2;if(r=n,typeof n=="function")dd(n)&&(s=1);else if(typeof n=="string")s=5;else e:switch(n){case Dr:return ir(t.children,i,o,e);case Rf:s=8,i|=8;break;case tc:return n=ct(12,t,e,i|2),n.elementType=tc,n.lanes=o,n;case nc:return n=ct(13,t,e,i),n.elementType=nc,n.lanes=o,n;case rc:return n=ct(19,t,e,i),n.elementType=rc,n.lanes=o,n;case Vy:return da(t,i,o,e);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case Ly:s=10;break e;case $y:s=9;break e;case Af:s=11;break e;case bf:s=14;break e;case on:s=16,r=null;break e}throw Error(E(130,n==null?n:typeof n,""))}return e=ct(s,t,e,i),e.elementType=n,e.type=r,e.lanes=o,e}function ir(n,e,t,r){return n=ct(7,n,r,e),n.lanes=t,n}function da(n,e,t,r){return n=ct(22,n,r,e),n.elementType=Vy,n.lanes=t,n.stateNode={isHidden:!1},n}function mu(n,e,t){return n=ct(6,n,null,e),n.lanes=t,n}function gu(n,e,t){return e=ct(4,n.children!==null?n.children:[],n.key,e),e.lanes=t,e.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},e}function mM(n,e,t,r,i){this.tag=e,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ya(0),this.expirationTimes=Ya(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ya(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function hd(n,e,t,r,i,o,s,l,a){return n=new mM(n,e,t,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=ct(3,null,null,e),n.current=o,o.stateNode=n,o.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Yf(o),n}function gM(n,e,t){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(z1)}catch(n){console.error(n)}}z1(),by.exports=rt;var fi=by.exports,P1,Qp=fi;P1=Qp.createRoot,Qp.hydrateRoot;const yi=k.createContext(null),vM=k.createContext(null),F1=k.createContext(null),zs=new WeakMap;function xM(n){const e=Object.create(null);e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",i=>{if(typeof i=="function"&&(i=i(n.state)),i)for(const o in i)o=="class"?e.class+=" "+i[o]:o=="style"?e.style=(e.style?e.style+";":"")+i[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(i[o]))}),e.translate||(e.translate="no");const t=[Se.node(0,n.state.doc.content.size,e)],r=zs.get(n);return!r||r[0].to!==n.state.doc.content.size||!r[0].type.eq(t[0].type)?(zs.set(n,t),t):r}const CM=[],NM={},jc=_.empty;class fn{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,NM));return fn.from(r)}forChild(e,t){if(t.isLeaf)return _.empty;let r=[];for(let i=0;it instanceof _)?e:e.reduce((t,r)=>t.concat(r instanceof _?r:r.members),[]))}}forEachSet(e){for(let t=0;t0;)e++;n.splice(e,0,t)}const yu=new WeakMap;function EM(n,e){const t=[];n.someProp("decorations",s=>{const l=s(n.state);l&&l!=jc&&t.push(l)}),e&&t.push(_.create(n.state.doc,[e]));const r=yu.get(n);if(!r){const s=fn.from(t);return yu.set(n,s),s}let i=0,o=!0;if(r.forEachSet(s=>{t[i++]!==s&&(o=!1)}),i!==t.length&&(o=!1),!o){const s=fn.from(t);return yu.set(n,s),s}return r}const yd=function(n){for(let e=0;;e++)if(n=n.previousSibling,!n)return e},Gp=function(n){const e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},OM=function(n,e,t,r){return t&&(Xp(n,e,t,r,-1)||Xp(n,e,t,r,1))},DM=/^(img|br|input|textarea|hr)$/i;function Xp(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ql(n))){const o=n.parentNode;if(!o||o.nodeType!=1||RM(n)||DM.test(n.nodeName)||n.contentEditable=="false")return!1;e=yd(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Ql(n):0}else return!1}}function Ql(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function TM(n,e,t){for(let r=e==0,i=e==Ql(n);r||i;){if(n==t)return!0;const o=yd(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,i=i&&o==Ql(n)}return!1}function RM(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 $1=function(n){return n.focusNode&&OM(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)},V1=k.createContext(null);function AM(n,e){const t=k.useContext(V1);k.useLayoutEffect(()=>t(n),e)}function B1(n,e){const{view:t}=k.useContext(yi);AM(()=>{if(t)return n(t)},e&&[t,...e])}const bM=k.forwardRef(function({widget:e,getPos:t,...r},i){const[o,s]=k.useState(!0),l=k.useRef(null);return k.useImperativeHandle(i,()=>l.current,[]),B1(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,yd(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?A.jsx("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function IM(n,e){if(n==e)return!0;for(const t in n)if(n[t]!==e[t])return!1;for(const t in e)if(!(t in n))return!1;return!0}const zM={side:0};class Wo{constructor(e,t){this.Component=e,this.spec=t??zM,this.side=this.spec.side??0}map(e,t,r,i){const{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Se(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Wo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&IM(this.spec,e.spec))}destroy(){}}function J1(n,e,t){return new Se(n,n,new Wo(e,t))}function Su(){return Math.floor(Math.random()*0xffffffffffff).toString(16)}const Uo=new Yo("@nytimes/react-prosemirror/reactKeys");function PM(){let n=!1;return new $t({key:Uo,state:{init(e,t){const r={posToKey:new Map,keyToPos:new Map};return t.doc.descendants((i,o)=>{const s=Su();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,t,r,i){if(!e.docChanged||n)return t;const o=e.getMeta(Uo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(t.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=Su()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=Su();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{n=!0},compositionend:()=>{n=!1}}}})}function wu(n,e,t={}){var s;if(e===null)return!1;const r=t.from??n.state.selection.from,i=t.to??n.state.selection.to;if(n.someProp("handleTextInput",l=>l(n,r,i,e)))return!0;const{tr:o}=n.state;if(t.marks&&o.ensureMarks(t.marks),o.insertText(e,r,i),t.bust){const l=n.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=Uo.getState(n.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(Uo,{type:"bustKey",payload:{key:c}})}return n.dispatch(o),!0}function FM(n){let e=null,t=null;return new $t({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&n(J1(i.selection.from,bM,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),t=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return wu(r,e,{bust:!0,marks:t}),e=null,t=null,n(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);wu(r,a,{from:c,to:f})}});break}case"insertText":{wu(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Lt=typeof navigator<"u"?navigator:null,Zp=typeof document<"u"?document:null,Fn=Lt&&Lt.userAgent||"",Kc=/Edge\/(\d+)/.exec(Fn),_1=/MSIE \d/.exec(Fn),qc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Fn),ya=!!(_1||qc||Kc),LM=_1?document.documentMode:qc?+qc[1]:Kc?+Kc[1]:0,W1=!ya&&/gecko\/(\d+)/i.test(Fn),$M=W1&&+(/Firefox\/(\d+)/.exec(Fn)||[0,0])[1],Qc=!ya&&/Chrome\/(\d+)/.exec(Fn),VM=!!Qc,BM=Qc?+Qc[1]:0,U1=!ya&&!!Lt&&/Apple Computer/.test(Lt.vendor),H1=U1&&(/Mobile\/\w+/.test(Fn)||!!Lt&&Lt.maxTouchPoints>2),JM=H1||(Lt?/Mac/.test(Lt.platform):!1),_M=Lt?/Win/.test(Lt.platform):!1,WM=/Android \d/.test(Fn),j1=!!Zp&&"webkitFontSmoothing"in Zp.documentElement.style,UM=j1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ee={ie:ya,ie_version:LM,gecko:W1,gecko_version:$M,chrome:VM,chrome_version:BM,safari:U1,ios:H1,mac:JM,windows:_M,android:WM,webkit:j1,webkit_version:UM};function ku(n){return n.editable&&!n.hasFocus()?!1:HM(n)}function HM(n){var t,r;const 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(((t=e.focusNode)==null?void 0:t.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function jM(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||$.between(e,t,r)}function em(n,e=null){const t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode);const o=i&&i.size==0;let s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if($1(t)){for(a=s;i&&!i.node;)i=i.parent;const f=i.node;if(i&&f.isAtom&&I.isSelectable(f)&&i.parent&&!(f.isInline&&TM(t.focusNode,t.focusOffset,i.dom))){const d=i.posBefore;u=new I(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let p=0;p{(r.anchorNode!=i||r.anchorOffset!=o)&&(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!K1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const sm=Ee.safari||Ee.chrome&&Ee.chrome_version<63;function Ps(n,e=!1){const t=n,r=t.state.selection;if(QM(t,r),!!K1(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Ee.chrome){const i=t.domSelectionRange(),o=t.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&Yl(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)GM(t);else{const{anchor:i,head:o}=r;let s,l;sm&&!(r instanceof $)&&(r.$from.parent.inlineContent||(s=im(t,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=im(t,r.to))),t.docView.setSelection(i,o,t.root,e),sm&&(s&&om(s),l&&om(l)),r.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&XM(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}class ZM{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 eE{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new ZM,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const t=new Set;let r;for(let o=e.focusNode;o;o=Gp(o))t.add(o);for(let o=e.anchorNode;o;o=Gp(o))if(t.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,t=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=em(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),t&&o.setMeta("composition",t),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Ps(e);const t=e.domSelectionRange();this.currentSelection.set(t)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const t=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(t)&&ku(e)&&!this.ignoreSelectionChange(t);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(ku(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Ps(this.view);if(Ee.ie&&Ee.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&Yl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}function gr(n,e){return n instanceof jo?1:e instanceof jo?-1:n.getPos()-e.getPos()}const di=0,lm=1,Fs=2,Ho=3;class ss{constructor(e,t,r,i,o){this.parent=e,this.children=t,this.getPos=r,this.dom=i,this.contentDOM=o,this.dirty=di,i.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;tln(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 o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const 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){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof jo){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Sd&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ln(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&t<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ln(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>t||l==this.children.length-1)){t=u;for(let c=l+1;ch&&st){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?Fs:lm,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ho:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Fs:Ho}r=s}this.dirty=Fs}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){const r=e==1?Fs:lm;t.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){const r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,t,r){return this.dirty==di&&e.eq(this.node)&&rE(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,t,r,i){return!0}get domAtom(){return this.node.isAtom}}class nE extends wd{constructor(e,t,r,i,o,s,l,a){super(e,t,r,i,o,s,l,null,a,()=>!1,()=>{},()=>{})}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!0}inParent(){const 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"}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ho)}get domAtom(){return!1}}class jo extends ss{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==di&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function rE(n,e){if(n.length!=e.length)return!1;for(let t=0;t{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new $t({key:new Yo("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function oE(){const[n,e]=k.useState(new Map),t=k.useCallback((o,s)=>{const l=n.get(o)??[];l.unshift(s),n.has(o)||(n.set(o,l),e(new Map(n)))},[n]),r=k.useCallback((o,s)=>{const l=n.get(o);l==null||l.splice(l.indexOf(s),1)},[n]),i=k.useMemo(()=>iE(n),[n]);return{registerEventListener:t,unregisterEventListener:r,componentEventListenersPlugin:i}}function q1(){const[,n]=k.useReducer(e=>e+1,0);return n}function sE(n){const e=Object.create(null);function t(r){for(const i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function lE(n,e){let t=0,r=0;for(const i in n){if(n[i]!=e[i])return!0;t++}for(const i in e)r++;return t!=r}function aE(n,e){for(const t of Object.keys(n))if(n[t]!==e[t])return!0;return!1}function am(n){return!n.someProp("editable",e=>e(n.state)===!1)}class uE extends Fv{constructor(e,t){super(e,{state:dn.create({schema:t.state.schema,plugins:t.state.plugins}),plugins:t.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=t,this.oldProps={state:t.state},this.state=t.state,this.domObserver.stop(),this.domObserver=new eE(this),this.domObserver.start(),this.editable=am(this),this.docView.dom.replaceChildren(),this.docView=t.docView}get needsRedraw(){if(this.oldProps.state.plugins===this._props.state.plugins&&this._props.plugins===this.oldProps.plugins)return!1;const e=sE(this);return lE(this.nodeViews,e)}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state,this.editable=am(this)}runPendingEffects(){if(aE(this.props,this.oldProps)){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}}update(e){super.update(e),this.oldProps=e}updatePluginViews(e){this.shouldUpdatePluginViews&&super.updatePluginViews(e)}destroy(){this.dom=document.createElement("div"),super.destroy()}}const cE=new zm({nodes:{doc:{content:"text*"},text:{inline:!0}}}),fE=dn.create({schema:cE});function dE(n,e){const[t,r]=k.useState(null),[i,o]=k.useState(null),s=q1(),l=e.defaultState??fE,[a,u]=k.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=oE(),h=k.useCallback(N=>{fi.flushSync(()=>{o(N)})},[]),m=k.useMemo(()=>[...e.plugins??[],f,FM(h)],[e.plugins,f,h]),w=k.useCallback(function(M){fi.flushSync(()=>{e.state||u(O=>O.apply(M)),e.dispatchTransaction&&e.dispatchTransaction.call(this,M)})},[e.dispatchTransaction,e.state]),g=document.createElement("div"),y=k.useRef(new wd(void 0,[],()=>-1,c.doc,[],_.empty,g,null,g,()=>!1,()=>{},()=>{})),S={...e,state:c,plugins:m,dispatchTransaction:w,docView:y.current};return k.useLayoutEffect(()=>()=>{t==null||t.destroy()},[t]),k.useLayoutEffect(()=>{if(t&&t.dom!==n&&r(null),!!n&&!t){const N=new uE({mount:n},S);r(N),N.dom.addEventListener("compositionend",s);return}}),k.useLayoutEffect(()=>{if(t!=null&&t.needsRedraw){r(null);return}else t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()}),t==null||t.pureSetProps(S),{editor:k.useMemo(()=>({view:t,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[t,d,p,i]),state:c}}function hE({children:n}){const e=k.useRef(new Set).current,t=k.useRef(new Set).current,r=k.useRef(!1),i=q1(),o=k.useRef(!0),s=k.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=k.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(t.add(u),s()):u())}},[e,t,s]);return k.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{t.forEach(a=>a()),t.clear()})),k.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),A.jsx(V1.Provider,{value:l,children:n})}const mt=k.createContext({parentRef:{current:void 0},siblingsRef:{current:[]}});function Q1(n,e,t,r,i,o,s,l){const{view:a}=k.useContext(yi),[u,c]=k.useState(!0),f=k.useRef(s),d=k.useRef(()=>!1),p=k.useCallback(x=>{d.current=x},[]),h=k.useRef(()=>{!r.current||!n||(r.current.nodeType==1&&r.current.classList.add("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&(((t==null?void 0:t.current)??r.current).draggable=!0))}),m=k.useRef(()=>{!r.current||!n||r.current.nodeType==1&&(r.current.classList.remove("ProseMirror-selectednode"),(l!=null&&l.current||!n.type.spec.draggable)&&((t==null?void 0:t.current)??r.current).removeAttribute("draggable"))}),w=k.useCallback((x,N)=>{h.current=x,m.current=N},[]),{siblingsRef:g,parentRef:y}=k.useContext(mt),S=k.useRef([]);return k.useLayoutEffect(()=>{const x=g.current;return()=>{if(f.current&&x.includes(f.current)){const N=x.indexOf(f.current);x.splice(N,1)}}},[g]),k.useLayoutEffect(()=>{var N;if(!n||!r.current)return;const x=S.current[0];f.current?(f.current.parent=y.current,f.current.children=S.current,f.current.node=n,f.current.getPos=e,f.current.outerDeco=o,f.current.innerDeco=i,f.current.dom=(t==null?void 0:t.current)??r.current,f.current.dom.pmViewDesc=f.current,f.current.contentDOM=(l==null?void 0:l.current)??f.current.contentDOM??(x==null?void 0:x.dom.parentElement)??null,f.current.nodeDOM=r.current):f.current=new wd(y.current,S.current,e,n,o,i,(t==null?void 0:t.current)??r.current,(x==null?void 0:x.dom.parentElement)??null,r.current,M=>!!d.current(M),()=>h.current(),()=>m.current()),c(f.current.contentDOM!==null),g.current.includes(f.current)||g.current.push(f.current),g.current.sort(gr);for(const M of S.current)if(M.parent=f.current,M instanceof Gl){const O=(N=f.current.contentDOM)==null?void 0:N.firstChild;if(!O)throw new Error("Started a composition but couldn't find the text node it belongs to.");let D=O;for(;D.firstChild;)D=D.firstChild;if(!D||!(D instanceof Text))throw new Error("Started a composition but couldn't find the text node it belongs to.");M.dom=O,M.textDOM=D,M.text=D.data,M.textDOM.pmViewDesc=M,a==null||a.input.compositionNodes.push(M)}return()=>{var M,O,D,b;((M=f.current)==null?void 0:M.children[0])instanceof Gl&&!(a!=null&&a.composing)&&((b=(O=f.current)==null?void 0:O.children[0].dom.parentNode)==null||b.removeChild((D=f.current)==null?void 0:D.children[0].dom))}}),{hasContentDOM:u,childDescriptors:S,nodeViewDescRef:f,setStopEvent:p,setSelectNode:w}}function pE(n,e){return n.type.side-e.type.side}function mE(n,e,t,r){const i=e.locals(n);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function gE(){const{view:n}=k.useContext(yi);return n&&Uo.getState(n.state)}var Y1={exports:{}};/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function kE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const kd=k.memo(k.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return A.jsx(A.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=G1(X1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return k.createElement(s,a,t)}c.push(A.jsx(kd,{outputSpec:d,children:t}))}return k.createElement(s,a,...c)})),Z1=k.memo(k.forwardRef(function({mark:e,getPos:t,children:r},i){const{siblingsRef:o,parentRef:s}=k.useContext(mt),l=k.useRef(void 0),a=k.useRef([]),u=k.useRef(null);k.useImperativeHandle(i,()=>u.current,[]);const c=k.useMemo(()=>{var d,p;return(p=(d=e.type.spec).toDOM)==null?void 0:p.call(d,e,!0)},[e]);if(!c)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);k.useLayoutEffect(()=>{const d=o.current;return()=>{if(l.current&&d.includes(l.current)){const p=d.indexOf(l.current);d.splice(p,1)}}},[o]),k.useLayoutEffect(()=>{if(!u.current)return;const d=a.current[0];l.current?(l.current.parent=s.current,l.current.dom=u.current,l.current.contentDOM=(d==null?void 0:d.dom.parentElement)??u.current,l.current.mark=e,l.current.getPos=()=>t.current()):l.current=new tE(s.current,a.current,()=>t.current(),e,u.current,(d==null?void 0:d.dom.parentElement)??u.current),o.current.includes(l.current)||o.current.push(l.current),o.current.sort(gr);for(const p of a.current)p.parent=l.current});const f=k.useMemo(()=>({parentRef:l,siblingsRef:a}),[a,l]);return A.jsx(kd,{ref:u,outputSpec:c,children:A.jsx(mt.Provider,{value:f,children:r})})}));function vE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(null);return k.useLayoutEffect(()=>{const s=t.current;return()=>{if(i.current&&s.includes(i.current)){const l=s.indexOf(i.current);s.splice(l,1)}}},[t]),B1(s=>{if(!o.current)return;const l=n.type.toDOM;let a=typeof l=="function"?l(s,()=>e.current()):l;if(!n.type.spec.raw){if(a.nodeType!=1){const u=document.createElement("span");u.appendChild(a),a=u}a.contentEditable="false",a.classList.add("ProseMirror-widget")}o.current.firstElementChild!==a&&o.current.replaceChildren(a)}),k.useLayoutEffect(()=>{o.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=o.current):i.current=new Sd(r.current,()=>e.current(),n,o.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))}),A.jsx("span",{ref:o})}const xE=k.createContext(null),CE=k.createContext(null),eS=k.memo(function({outerDeco:e,getPos:t,node:r,innerDeco:i,...o}){const s=k.useRef(null),l=k.useRef(null),a=k.useRef(null),u=k.useRef(()=>t.current()).current,c=k.useRef(r),f=k.useRef(e),d=k.useRef(i),p=k.useRef(null),h=k.useRef(null),{nodeViews:m}=k.useContext(F1),{view:S}=k.useContext(yi);let g=null;const y=m[r.type.name],w=k.useMemo(()=>{var j,he;return(he=(j=r.type.spec).toDOM)==null?void 0:he.call(j,r)},[r]),C=S==null?void 0:S.someProp("nodeViews",j=>j==null?void 0:j[r.type.name]);k.useLayoutEffect(()=>{if(!h.current||!p.current)return;const{dom:j}=h.current;return l.current=p.current,p.current.appendChild(j),()=>{var he,$n;($n=(he=h.current)==null?void 0:he.destroy)==null||$n.call(he)}},[]),k.useLayoutEffect(()=>{if(!C||!h.current)return;const{destroy:j,update:he}=h.current;if(((he==null?void 0:he.call(h.current,r,e,i))??!0)||(j==null||j.call(h.current),!p.current))return;c.current=r,f.current=e,d.current=i,h.current=C(c.current,S,()=>t.current(),f.current,d.current);const{dom:T}=h.current;l.current=p.current,p.current.appendChild(T)},[C,S,i,r,e,t]);const{hasContentDOM:M,childDescriptors:N,setStopEvent:O,setSelectNode:D,nodeViewDescRef:b}=Q1(r,()=>t.current(),s,l,i,e,void 0,a),z={...o,...!M&&{contentEditable:!1}},ae=k.useMemo(()=>({node:r,getPos:u,decorations:e,innerDecorations:i}),[u,i,r,e]);if(y)g=A.jsx(y,{...z,ref:l,nodeProps:ae,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})});else if(C){h.current||(h.current=C(c.current,S,()=>t.current(),f.current,d.current));const{contentDOM:j}=h.current;a.current=j??null,g=k.createElement(r.isInline?"span":"div",{ref:p,contentEditable:!!j,suppressContentEditableWarning:!0},j&&fi.createPortal(A.jsx(mo,{getPos:t,node:r,innerDecorations:i}),j))}else w&&(g=A.jsx(kd,{...z,ref:l,outputSpec:w,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})}));if(!g)throw new Error(`Node spec for ${r.type.name} is missing toDOM`);const Vt=k.cloneElement(e.reduce(vd,g),e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0),Ln=r.marks.reduce((j,he)=>A.jsx(Z1,{getPos:t,mark:he,children:j}),Vt),ls=k.useMemo(()=>({parentRef:b,siblingsRef:N}),[N,b]);return A.jsx(xE.Provider,{value:D,children:A.jsx(CE.Provider,{value:O,children:A.jsx(mt.Provider,{value:ls,children:k.cloneElement(Ln,r.marks.length||e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0)})})})});function NE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null),[o,s]=k.useState(!1);return k.useLayoutEffect(()=>{const l=e.current;return()=>{if(r.current&&l.includes(r.current)){const a=l.indexOf(r.current);l.splice(a,1)}}},[e]),k.useLayoutEffect(()=>{var a;const l=e.current[e.current.length-1];if((Ee.safari||Ee.chrome)&&((a=l==null?void 0:l.dom)==null?void 0:a.contentEditable)=="false"){s(!0);return}i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),o?A.jsx("img",{ref:i,className:"ProseMirror-separator"}):null}function ME(n,e){if(n===e)return!0;if(!n||!e)return!1;const t=Object.keys(n),r=Object.keys(e),i=t.length;if(r.length!==i)return!1;for(let o=0;oo.current(),document.createElement("div"),document.createTextNode(s.text??""),s.text??"");return}let a=l;for(;a.firstChild;)a=a.firstChild;!this.viewDescRef||this.viewDescRef instanceof Gl?this.viewDescRef=new nE(void 0,[],()=>o.current(),s,t,_.empty,l,a):(this.viewDescRef.parent=i.current,this.viewDescRef.children=[],this.viewDescRef.node=s,this.viewDescRef.getPos=()=>o.current(),this.viewDescRef.outerDeco=t,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=l,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=a),r.current.includes(this.viewDescRef)||r.current.push(this.viewDescRef),r.current.sort(gr)}shouldComponentUpdate(e){return!ME(this.props,e)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}componentWillUnmount(){const{siblingsRef:e}=this.props;if(this.viewDescRef&&e.current.includes(this.viewDescRef)){const t=e.current.indexOf(this.viewDescRef);e.current.splice(t,1)}}render(){const{view:e,getPos:t,node:r,decorations:i}=this.props;return e!=null&&e.composing&&e.state.selection.from>=t.current()&&e.state.selection.from<=t.current()+r.nodeSize?this.renderRef:(this.renderRef=i.reduce(vd,r.text),this.renderRef)}}function OE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null);return k.useLayoutEffect(()=>{const o=e.current;return()=>{if(r.current&&o.includes(r.current)){const s=o.indexOf(r.current);o.splice(s,1)}}},[e]),k.useLayoutEffect(()=>{i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),A.jsx("br",{ref:i,className:"ProseMirror-trailingBreak"})}function DE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(()=>e.current()).current,s=k.useRef(null);k.useLayoutEffect(()=>{const a=t.current;return()=>{if(i.current&&a.includes(i.current)){const u=a.indexOf(i.current);a.splice(u,1)}}},[t]),k.useLayoutEffect(()=>{s.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=s.current):i.current=new Sd(r.current,()=>e.current(),n,s.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))});const{Component:l}=n.type;return l&&A.jsx(l,{ref:s,widget:n,getPos:o,contentEditable:!1})}function vd(n,e){const{nodeName:t,...r}=e.type.attrs,i=X1(r);return t||typeof n=="string"?k.createElement(t??"span",i,n):k.cloneElement(n,G1(n.props,i))}function xu(n,e){var t,r,i;return n.type===e.type&&n.marks.every(o=>o.isInSet(e.marks))&&e.marks.every(o=>o.isInSet(n.marks))&&n.key===e.key&&(n.type==="node"?((t=n.outerDeco)==null?void 0:t.length)===((r=e.outerDeco)==null?void 0:r.length)&&((i=n.outerDeco)==null?void 0:i.every(o=>{var s;return(s=e.outerDeco)==null?void 0:s.some(l=>o.from===l.from&&o.to&&l.to&&o.type.eq(l.type))}))&&n.innerDeco.eq(e.innerDeco):!0)&&n.node===e.node&&n.widget===e.widget}const TE=k.memo(function({child:e,getInnerPos:t}){const{view:r}=k.useContext(yi),i=k.useRef(()=>t.current()+e.offset);return i.current=()=>t.current()+e.offset,e.type==="widget"?A.jsx(DE,{widget:e.widget,getPos:i},e.key):e.type==="native-widget"?A.jsx(vE,{widget:e.widget,getPos:i},e.key):e.node.isText?A.jsx(mt.Consumer,{children:({siblingsRef:o,parentRef:s})=>A.jsx(EE,{view:r,node:e.node,getPos:i,siblingsRef:o,parentRef:s,decorations:e.outerDeco})},e.key):A.jsx(eS,{node:e.node,getPos:i,outerDeco:e.outerDeco,innerDeco:e.innerDeco},e.key)}),RE=k.memo(function({childViews:e,getInnerPos:t}){const r=e[0],i=k.useRef(()=>t.current()+r.offset);i.current=()=>t.current()+r.offset;const o=r.marks[0];return o?A.jsx(Z1,{getPos:i,mark:o,children:A.jsx(xd,{getInnerPos:t,childViews:e.map(s=>({...s,marks:s.marks.slice(1)}))},r.key)},r.key):A.jsx(A.Fragment,{children:e.map(s=>A.jsx(TE,{child:s,getInnerPos:t},s.key))})}),xd=k.memo(function({getInnerPos:e,childViews:t}){const r=t.reduce((i,o)=>{var a;const s=i[i.length-1];if(!s)return[[o]];const l=s[s.length-1];return l?!o.marks.length&&!l.marks.length||o.marks.length&&l.marks.length&&((a=o.marks[0])!=null&&a.eq(l.marks[0]))?[...i.slice(0,i.length-1),[...s.slice(0,s.length),o]]:[...i,[o]]:[...i.slice(0,i.length),[o]]},[]);return A.jsx(A.Fragment,{children:r.map(i=>{const o=i[0];return o?A.jsx(RE,{childViews:i,getInnerPos:e},o.key):null})})});function Cu(n,e,t,r,i,o){const s=n+e,l=r==null?void 0:r.get(s);if(t==="widget"||t==="native-widget")return i.type.spec.key?i.type.spec.key:(console.warn(`Widget at position ${s} doesn't have a key specified. This may cause issues.`),`${l}-${o}`);if(l)return l;const a=n-1,u=r==null?void 0:r.get(a);return u?`${u}-${e}`:s}function AE(n){const e=Array.from(n.values()).sort((o,s)=>o.offset-s.offset),t=e[e.length-1];if((t==null?void 0:t.type)!=="widget"&&(t==null?void 0:t.type)!=="native-widget"||t.widget.type.side>=0)return;let r=null;for(let o=e.length-2;o>=0;o--){const s=e[o];if((s==null?void 0:s.type)==="node"){r=s;break}}if(!r||!r.node.isInline)return;const i=r.marks;t.marks=t.marks.reduce((o,s)=>s.addToSet(o),i)}function bE(n){const e=Array.from(n.values()).sort((i,o)=>i.offset-o.offset),t=e[e.length-1];if((t==null?void 0:t.type)!=="node"||!t.node.isInline)return;const r=t.marks;for(let i=e.length-2;i>=0;i--){const o=e[i];if((o==null?void 0:o.type)!=="widget"&&(o==null?void 0:o.type)!=="native-widget"||o.widget.type.side<0)break;o.marks=o.marks.reduce((s,l)=>l.addToSet(s),r)}}const IE=k.memo(function({child:e,getInnerPos:t}){const r=k.useRef(()=>t.current()+e.offset);return r.current=()=>t.current()+e.offset,e.type==="node"?A.jsx(eS,{outerDeco:e.outerDeco,node:e.node,innerDeco:e.innerDeco,getPos:r},e.key):A.jsx(xd,{childViews:[e],getInnerPos:t},e.key)});function zE(n,e){return n.length?n.every(t=>t.type!=="node"||t.node.isInline)?[A.jsx(xd,{childViews:n,getInnerPos:e},n[0].key)]:n.map(t=>A.jsx(IE,{child:t,getInnerPos:e},t.key)):[]}const mo=k.memo(function({getPos:e,node:t,innerDecorations:r}){const i=gE(),o=k.useRef(()=>e.current()+1),s=k.useRef(new Map).current;if(!t)return null;const l=new Set;mE(t,r,(f,d,p,h)=>{const m=f.type.spec.marks??[];if(d){const S=Cu(o.current(),p,"native-widget",i==null?void 0:i.posToKey,f,h),g={type:"native-widget",widget:f,marks:m,offset:p,index:h,key:S},y=s.get(S);y&&xu(y,g)?y.offset=p:s.set(S,g),l.add(S)}else{const S=Cu(o.current(),p,"widget",i==null?void 0:i.posToKey,f,h),g={type:"widget",widget:f,marks:m,offset:p,index:h,key:S},y=s.get(S);y&&xu(y,g)?y.offset=p:s.set(S,g),l.add(S)}AE(s)},(f,d,p,h)=>{const m=Cu(o.current(),h,"node",i==null?void 0:i.posToKey),S={type:"node",node:f,marks:f.marks,innerDeco:p,outerDeco:d,offset:h,key:m},g=s.get(m);g&&xu(g,S)?g.offset=h:s.set(m,S),l.add(m),bE(s)});for(const f of s.keys())l.has(f)||s.delete(f);const a=Array.from(s.values()).sort((f,d)=>f.offset-d.offset),u=zE(a,o),c=a[a.length-1];return(!c||c.type!=="node"||c.node.isInline&&!c.node.isText||/\n$/.test(c.node.text))&&u.push(A.jsx(NE,{getPos:o},"trailing-hack-img"),A.jsx(OE,{getPos:o},"trailing-hack-br")),A.jsx(A.Fragment,{children:u})}),Nu={current(){return-1}},PE=k.memo(k.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=k.useRef(null);k.useImperativeHandle(a,()=>u.current,[]);const{childDescriptors:c,nodeViewDescRef:f}=Q1(t,()=>Nu.current(),u,u,r,i,s),d=k.useMemo(()=>({parentRef:f,siblingsRef:c}),[c,f]),p={...l,ref:u,className:e,suppressContentEditableWarning:!0},h=o?k.cloneElement(o,p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})})):k.createElement("div",p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})}));if(!t)return h;const m=i.filter(g=>!g.inline);return m.length?m.reduce(vd,h):h})),tS=k.createContext(null);function FE({as:n,...e},t){const r=k.useRef([]),i=k.useRef(null),{setMount:o,...s}=k.useContext(tS),l=k.useRef(void 0);k.useImperativeHandle(t,()=>i.current,[]);const a=k.useMemo(()=>({parentRef:l,siblingsRef:r}),[r,l]);return A.jsx(mt.Provider,{value:a,children:A.jsx(PE,{ref:u=>{i.current=u,o(u)},...e,...s,as:n})})}const LE=k.forwardRef(FE),$E=[];function VE({className:n,children:e,nodeViews:t={},customNodeViews:r,...i}){var p;const[o,s]=k.useState(null),{editor:l,state:a}=dE(o,{...i,nodeViews:r}),u=l.view?EM(l.view,l.cursorWrapper):_.empty,c=l.view?xM(l.view):$E,f=k.useMemo(()=>({nodeViews:t}),[t]),d=k.useMemo(()=>{var h;return{className:n,setMount:s,node:(h=l.view)==null?void 0:h.state.doc,innerDeco:u,outerDeco:c,viewDesc:l.docViewDescRef.current}},[n,l.docViewDescRef,(p=l.view)==null?void 0:p.state.doc,u,c]);return A.jsx(yi.Provider,{value:l,children:A.jsx(vM.Provider,{value:a,children:A.jsx(F1.Provider,{value:f,children:A.jsx(tS.Provider,{value:d,children:e})})})})}function BE(n){return A.jsx(hE,{children:A.jsx(VE,{...n})})}const J=new zm({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Bx({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),JE=dn.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[PM(),ix({rules:[ox(/^\s*([-+*])\s$/,J.nodes.list)]}),oC(),yC()]}),_E=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("p",{ref:i,...r,children:e})}),WE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("ul",{ref:i,...r,children:e})}),UE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("li",{ref:i,...r,children:e})}),HE=k.forwardRef(function({nodeProps:e,...t},r){return A.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:A.jsx("button",{children:e.node.attrs.number})})}),jE=k.forwardRef(function({widget:e,getPos:t,...r},i){return A.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),KE=new $t({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new $t({props:{decorations(n){return _.create(n.doc,[J1(n.selection.from,jE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const qE=[ux({...Hw,"Mod-i":jd(J.marks.em),"Mod-b":jd(J.marks.strong)}),KE,Jv()],QE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function YE(){const[n,e]=k.useState(JE),[t,r]=k.useState(!0),i=k.useMemo(()=>t?{paragraph:_E,list:WE,list_item:UE,footnote:HE}:void 0,[t]),o=k.useCallback(function(s){e(l=>l.apply(s))},[]);return A.jsxs("main",{children:[A.jsx("h1",{children:"React ProseMirror Demo"}),A.jsxs("button",{onClick:()=>{t?r(s=>!s):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),A.jsx(BE,{className:"ProseMirror",state:n,dispatchTransaction:o,plugins:qE,nodeViews:i,customNodeViews:t?void 0:QE,children:A.jsx(LE,{})},`${t}`)]})}const GE=P1(document.getElementById("root"));GE.render(A.jsx(k.StrictMode,{children:A.jsx(YE,{})})); +*/(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],i=0;i{var t;return((t=e[1])==null?void 0:t.toUpperCase())??""})}function kE(n){const e=new CSSStyleSheet;e.insertRule(`* { ${n} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[t]=r;break}}return e}const kd=k.memo(k.forwardRef(function({outputSpec:e,children:t,...r},i){if(typeof e=="string")return A.jsx(A.Fragment,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=G1(X1(l),a));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return k.createElement(s,a,t)}c.push(A.jsx(kd,{outputSpec:d,children:t}))}return k.createElement(s,a,...c)})),Z1=k.memo(k.forwardRef(function({mark:e,getPos:t,children:r},i){const{siblingsRef:o,parentRef:s}=k.useContext(mt),l=k.useRef(void 0),a=k.useRef([]),u=k.useRef(null);k.useImperativeHandle(i,()=>u.current,[]);const c=k.useMemo(()=>{var d,p;return(p=(d=e.type.spec).toDOM)==null?void 0:p.call(d,e,!0)},[e]);if(!c)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);k.useLayoutEffect(()=>{const d=o.current;return()=>{if(l.current&&d.includes(l.current)){const p=d.indexOf(l.current);d.splice(p,1)}}},[o]),k.useLayoutEffect(()=>{if(!u.current)return;const d=a.current[0];l.current?(l.current.parent=s.current,l.current.dom=u.current,l.current.contentDOM=(d==null?void 0:d.dom.parentElement)??u.current,l.current.mark=e,l.current.getPos=()=>t.current()):l.current=new tE(s.current,a.current,()=>t.current(),e,u.current,(d==null?void 0:d.dom.parentElement)??u.current),o.current.includes(l.current)||o.current.push(l.current),o.current.sort(gr);for(const p of a.current)p.parent=l.current});const f=k.useMemo(()=>({parentRef:l,siblingsRef:a}),[a,l]);return A.jsx(kd,{ref:u,outputSpec:c,children:A.jsx(mt.Provider,{value:f,children:r})})}));function vE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(null);return k.useLayoutEffect(()=>{const s=t.current;return()=>{if(i.current&&s.includes(i.current)){const l=s.indexOf(i.current);s.splice(l,1)}}},[t]),B1(s=>{if(!o.current)return;const l=n.type.toDOM;let a=typeof l=="function"?l(s,()=>e.current()):l;if(!n.type.spec.raw){if(a.nodeType!=1){const u=document.createElement("span");u.appendChild(a),a=u}a.contentEditable="false",a.classList.add("ProseMirror-widget")}o.current.firstElementChild!==a&&o.current.replaceChildren(a)}),k.useLayoutEffect(()=>{o.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=o.current):i.current=new Sd(r.current,()=>e.current(),n,o.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))}),A.jsx("span",{ref:o})}const xE=k.createContext(null),CE=k.createContext(null),eS=k.memo(function({outerDeco:e,getPos:t,node:r,innerDeco:i,...o}){const s=k.useRef(null),l=k.useRef(null),a=k.useRef(null),u=k.useRef(()=>t.current()).current,c=k.useRef(r),f=k.useRef(e),d=k.useRef(i),p=k.useRef(null),h=k.useRef(null),{nodeViews:m}=k.useContext(F1),{view:w}=k.useContext(yi);let g=null;const y=m[r.type.name],S=k.useMemo(()=>{var j,he;return(he=(j=r.type.spec).toDOM)==null?void 0:he.call(j,r)},[r]),x=w==null?void 0:w.someProp("nodeViews",j=>j==null?void 0:j[r.type.name]);k.useLayoutEffect(()=>{if(!h.current||!p.current)return;const{dom:j}=h.current;return l.current=p.current,p.current.appendChild(j),()=>{var he,$n;($n=(he=h.current)==null?void 0:he.destroy)==null||$n.call(he)}},[]),k.useLayoutEffect(()=>{if(!x||!h.current)return;const{destroy:j,update:he}=h.current;if(((he==null?void 0:he.call(h.current,r,e,i))??!0)||(j==null||j.call(h.current),!p.current))return;c.current=r,f.current=e,d.current=i,h.current=x(c.current,w,()=>t.current(),f.current,d.current);const{dom:T}=h.current;l.current=p.current,p.current.appendChild(T)},[x,w,i,r,e,t]);const{hasContentDOM:N,childDescriptors:M,setStopEvent:O,setSelectNode:D,nodeViewDescRef:b}=Q1(r,()=>t.current(),s,l,i,e,void 0,a),z={...o,...!N&&{contentEditable:!1}},ae=k.useMemo(()=>({node:r,getPos:u,decorations:e,innerDecorations:i}),[u,i,r,e]);if(y)g=A.jsx(y,{...z,ref:l,nodeProps:ae,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})});else if(x){h.current||(h.current=x(c.current,w,()=>t.current(),f.current,d.current));const{contentDOM:j}=h.current;a.current=j??null,g=k.createElement(r.isInline?"span":"div",{ref:p,contentEditable:!!j,suppressContentEditableWarning:!0},j&&fi.createPortal(A.jsx(mo,{getPos:t,node:r,innerDecorations:i}),j))}else S&&(g=A.jsx(kd,{...z,ref:l,outputSpec:S,children:A.jsx(mo,{getPos:t,node:r,innerDecorations:i})}));if(!g)throw new Error(`Node spec for ${r.type.name} is missing toDOM`);const Vt=k.cloneElement(e.reduce(vd,g),e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0),Ln=r.marks.reduce((j,he)=>A.jsx(Z1,{getPos:t,mark:he,children:j}),Vt),ls=k.useMemo(()=>({parentRef:b,siblingsRef:M}),[M,b]);return A.jsx(xE.Provider,{value:D,children:A.jsx(CE.Provider,{value:O,children:A.jsx(mt.Provider,{value:ls,children:k.cloneElement(Ln,r.marks.length||e.some(j=>j.type.attrs.nodeName)?{ref:s}:void 0)})})})});function NE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null),[o,s]=k.useState(!1);return k.useLayoutEffect(()=>{const l=e.current;return()=>{if(r.current&&l.includes(r.current)){const a=l.indexOf(r.current);l.splice(a,1)}}},[e]),k.useLayoutEffect(()=>{var a;const l=e.current[e.current.length-1];if((Ee.safari||Ee.chrome)&&((a=l==null?void 0:l.dom)==null?void 0:a.contentEditable)=="false"){s(!0);return}i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),o?A.jsx("img",{ref:i,className:"ProseMirror-separator"}):null}function ME(n,e){if(n===e)return!0;if(!n||!e)return!1;const t=Object.keys(n),r=Object.keys(e),i=t.length;if(r.length!==i)return!1;for(let o=0;oo.current(),document.createElement("div"),document.createTextNode(s.text??""),s.text??"");return}let a=l;for(;a.firstChild;)a=a.firstChild;!this.viewDescRef||this.viewDescRef instanceof Gl?this.viewDescRef=new nE(void 0,[],()=>o.current(),s,t,_.empty,l,a):(this.viewDescRef.parent=i.current,this.viewDescRef.children=[],this.viewDescRef.node=s,this.viewDescRef.getPos=()=>o.current(),this.viewDescRef.outerDeco=t,this.viewDescRef.innerDeco=_.empty,this.viewDescRef.dom=l,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=a),r.current.includes(this.viewDescRef)||r.current.push(this.viewDescRef),r.current.sort(gr)}shouldComponentUpdate(e){return!ME(this.props,e)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}componentWillUnmount(){const{siblingsRef:e}=this.props;if(this.viewDescRef&&e.current.includes(this.viewDescRef)){const t=e.current.indexOf(this.viewDescRef);e.current.splice(t,1)}}render(){const{view:e,getPos:t,node:r,decorations:i}=this.props;return e!=null&&e.composing&&e.state.selection.from>=t.current()&&e.state.selection.from<=t.current()+r.nodeSize?this.renderRef:(this.renderRef=i.reduce(vd,r.text),this.renderRef)}}function OE({getPos:n}){const{siblingsRef:e,parentRef:t}=k.useContext(mt),r=k.useRef(null),i=k.useRef(null);return k.useLayoutEffect(()=>{const o=e.current;return()=>{if(r.current&&o.includes(r.current)){const s=o.indexOf(r.current);o.splice(s,1)}}},[e]),k.useLayoutEffect(()=>{i.current&&(r.current?(r.current.parent=t.current,r.current.dom=i.current,r.current.getPos=()=>n.current()):r.current=new jo(t.current,[],()=>n.current(),i.current,null),e.current.includes(r.current)||e.current.push(r.current),e.current.sort(gr))}),A.jsx("br",{ref:i,className:"ProseMirror-trailingBreak"})}function DE({widget:n,getPos:e}){const{siblingsRef:t,parentRef:r}=k.useContext(mt),i=k.useRef(null),o=k.useRef(()=>e.current()).current,s=k.useRef(null);k.useLayoutEffect(()=>{const a=t.current;return()=>{if(i.current&&a.includes(i.current)){const u=a.indexOf(i.current);a.splice(u,1)}}},[t]),k.useLayoutEffect(()=>{s.current&&(i.current?(i.current.parent=r.current,i.current.widget=n,i.current.getPos=()=>e.current(),i.current.dom=s.current):i.current=new Sd(r.current,()=>e.current(),n,s.current),t.current.includes(i.current)||t.current.push(i.current),t.current.sort(gr))});const{Component:l}=n.type;return l&&A.jsx(l,{ref:s,widget:n,getPos:o,contentEditable:!1})}function vd(n,e){const{nodeName:t,...r}=e.type.attrs,i=X1(r);return t||typeof n=="string"?k.createElement(t??"span",i,n):k.cloneElement(n,G1(n.props,i))}function xu(n,e){var t,r,i;return n.type===e.type&&n.marks.every(o=>o.isInSet(e.marks))&&e.marks.every(o=>o.isInSet(n.marks))&&n.key===e.key&&(n.type==="node"?((t=n.outerDeco)==null?void 0:t.length)===((r=e.outerDeco)==null?void 0:r.length)&&((i=n.outerDeco)==null?void 0:i.every(o=>{var s;return(s=e.outerDeco)==null?void 0:s.some(l=>o.from===l.from&&o.to&&l.to&&o.type.eq(l.type))}))&&n.innerDeco.eq(e.innerDeco):!0)&&n.node===e.node&&n.widget===e.widget}const TE=k.memo(function({child:e,getInnerPos:t}){const{view:r}=k.useContext(yi),i=k.useRef(()=>t.current()+e.offset);return i.current=()=>t.current()+e.offset,e.type==="widget"?A.jsx(DE,{widget:e.widget,getPos:i},e.key):e.type==="native-widget"?A.jsx(vE,{widget:e.widget,getPos:i},e.key):e.node.isText?A.jsx(mt.Consumer,{children:({siblingsRef:o,parentRef:s})=>A.jsx(EE,{view:r,node:e.node,getPos:i,siblingsRef:o,parentRef:s,decorations:e.outerDeco})},e.key):A.jsx(eS,{node:e.node,getPos:i,outerDeco:e.outerDeco,innerDeco:e.innerDeco},e.key)}),RE=k.memo(function({childViews:e,getInnerPos:t}){const r=e[0],i=k.useRef(()=>t.current()+r.offset);i.current=()=>t.current()+r.offset;const o=r.marks[0];return o?A.jsx(Z1,{getPos:i,mark:o,children:A.jsx(xd,{getInnerPos:t,childViews:e.map(s=>({...s,marks:s.marks.slice(1)}))},r.key)},r.key):A.jsx(A.Fragment,{children:e.map(s=>A.jsx(TE,{child:s,getInnerPos:t},s.key))})}),xd=k.memo(function({getInnerPos:e,childViews:t}){const r=t.reduce((i,o)=>{var a;const s=i[i.length-1];if(!s)return[[o]];const l=s[s.length-1];return l?!o.marks.length&&!l.marks.length||o.marks.length&&l.marks.length&&((a=o.marks[0])!=null&&a.eq(l.marks[0]))?[...i.slice(0,i.length-1),[...s.slice(0,s.length),o]]:[...i,[o]]:[...i.slice(0,i.length),[o]]},[]);return A.jsx(A.Fragment,{children:r.map(i=>{const o=i[0];return o?A.jsx(RE,{childViews:i,getInnerPos:e},o.key):null})})});function Cu(n,e,t,r,i,o){const s=n+e,l=r==null?void 0:r.get(s);if(t==="widget"||t==="native-widget")return i.type.spec.key?i.type.spec.key:(console.warn(`Widget at position ${s} doesn't have a key specified. This may cause issues.`),`${l}-${o}`);if(l)return l;const a=n-1,u=r==null?void 0:r.get(a);return u?`${u}-${e}`:s}function AE(n,e){if(!e||e.widget.type.side>=0||!n||!n.node.isInline)return;const t=n.marks;e.marks=e.marks.reduce((r,i)=>i.addToSet(r),t)}function bE(n,e){if(!e.node.isInline)return;const t=e.marks;for(let r=n.length-1;r>=0;r--){const i=n[r];i.widget.type.side<0||(i.marks=i.marks.reduce((o,s)=>s.addToSet(o),t))}}const IE=k.memo(function({child:e,getInnerPos:t}){const r=k.useRef(()=>t.current()+e.offset);return r.current=()=>t.current()+e.offset,e.type==="node"?A.jsx(eS,{outerDeco:e.outerDeco,node:e.node,innerDeco:e.innerDeco,getPos:r},e.key):A.jsx(xd,{childViews:[e],getInnerPos:t},e.key)});function zE(n,e){return n.length?n.every(t=>t.type!=="node"||t.node.isInline)?[A.jsx(xd,{childViews:n,getInnerPos:e},n[0].key)]:n.map(t=>A.jsx(IE,{child:t,getInnerPos:e},t.key)):[]}const mo=k.memo(function({getPos:e,node:t,innerDecorations:r}){const i=gE(),o=k.useRef(()=>e.current()+1),s=k.useRef(new Map).current;if(!t)return null;const l=new Set;let a=[],u=null;mE(t,r,(p,h,m,w)=>{const g=p.type.spec.marks??[];let y;if(h){y=Cu(o.current(),m,"native-widget",i==null?void 0:i.posToKey,p,w);const x={type:"native-widget",widget:p,marks:g,offset:m,index:w,key:y},N=s.get(y);N&&xu(N,x)?N.offset=m:s.set(y,x),l.add(y)}else{y=Cu(o.current(),m,"widget",i==null?void 0:i.posToKey,p,w);const x={type:"widget",widget:p,marks:g,offset:m,index:w,key:y},N=s.get(y);N&&xu(N,x)?N.offset=m:s.set(y,x),l.add(y)}const S=s.get(y);a.push(S),AE(u,s.get(y))},(p,h,m,w)=>{const g=Cu(o.current(),w,"node",i==null?void 0:i.posToKey),y={type:"node",node:p,marks:p.marks,innerDeco:m,outerDeco:h,offset:w,key:g},S=s.get(g);S&&xu(S,y)?(S.offset=w,u=S):(s.set(g,y),u=y),l.add(g),bE(a,u),a=[]});for(const p of s.keys())l.has(p)||s.delete(p);const c=Array.from(s.values()).sort((p,h)=>p.offset-h.offset),f=zE(c,o),d=c[c.length-1];return(!d||d.type!=="node"||d.node.isInline&&!d.node.isText||/\n$/.test(d.node.text))&&f.push(A.jsx(NE,{getPos:o},"trailing-hack-img"),A.jsx(OE,{getPos:o},"trailing-hack-br")),A.jsx(A.Fragment,{children:f})}),Nu={current(){return-1}},PE=k.memo(k.forwardRef(function({className:e,node:t,innerDeco:r,outerDeco:i,as:o,viewDesc:s,...l},a){const u=k.useRef(null);k.useImperativeHandle(a,()=>u.current,[]);const{childDescriptors:c,nodeViewDescRef:f}=Q1(t,()=>Nu.current(),u,u,r,i,s),d=k.useMemo(()=>({parentRef:f,siblingsRef:c}),[c,f]),p={...l,ref:u,className:e,suppressContentEditableWarning:!0},h=o?k.cloneElement(o,p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})})):k.createElement("div",p,A.jsx(mt.Provider,{value:d,children:A.jsx(mo,{getPos:Nu,node:t,innerDecorations:r})}));if(!t)return h;const m=i.filter(g=>!g.inline);return m.length?m.reduce(vd,h):h})),tS=k.createContext(null);function FE({as:n,...e},t){const r=k.useRef([]),i=k.useRef(null),{setMount:o,...s}=k.useContext(tS),l=k.useRef(void 0);k.useImperativeHandle(t,()=>i.current,[]);const a=k.useMemo(()=>({parentRef:l,siblingsRef:r}),[r,l]);return A.jsx(mt.Provider,{value:a,children:A.jsx(PE,{ref:u=>{i.current=u,o(u)},...e,...s,as:n})})}const LE=k.forwardRef(FE),$E=[];function VE({className:n,children:e,nodeViews:t={},customNodeViews:r,...i}){var p;const[o,s]=k.useState(null),{editor:l,state:a}=dE(o,{...i,nodeViews:r}),u=l.view?EM(l.view,l.cursorWrapper):_.empty,c=l.view?xM(l.view):$E,f=k.useMemo(()=>({nodeViews:t}),[t]),d=k.useMemo(()=>{var h;return{className:n,setMount:s,node:(h=l.view)==null?void 0:h.state.doc,innerDeco:u,outerDeco:c,viewDesc:l.docViewDescRef.current}},[n,l.docViewDescRef,(p=l.view)==null?void 0:p.state.doc,u,c]);return A.jsx(yi.Provider,{value:l,children:A.jsx(vM.Provider,{value:a,children:A.jsx(F1.Provider,{value:f,children:A.jsx(tS.Provider,{value:d,children:e})})})})}function BE(n){return A.jsx(hE,{children:A.jsx(VE,{...n})})}const J=new zm({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Bx({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),JE=dn.create({schema:J,doc:J.nodes.doc.create({},[J.nodes.paragraph.create({},[J.text("This ",[J.marks.em.create()]),J.text("is",[J.marks.em.create(),J.marks.strong.create()]),J.text(" the first paragraph")]),J.nodes.paragraph.create({},[J.text("This is the second paragraph"),J.nodes.footnote.create({number:1},J.text("Footnote"))]),J.nodes.paragraph.create(),J.nodes.image.create(),J.nodes.image.create(),J.nodes.paragraph.create({},J.text("This is the third paragraph 🫵")),J.nodes.table.create({},[J.nodes.table_row.create({},[J.nodes.table_header.create({},J.text("h1")),J.nodes.table_header.create({},J.text("h2"))]),J.nodes.table_row.create({},[J.nodes.table_cell.create({},J.text("c1")),J.nodes.table_cell.create({},J.text("c2"))])])]),plugins:[PM(),ix({rules:[ox(/^\s*([-+*])\s$/,J.nodes.list)]}),oC(),yC()]}),_E=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("p",{ref:i,...r,children:e})}),WE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("ul",{ref:i,...r,children:e})}),UE=k.forwardRef(function({children:e,nodeProps:t,...r},i){return A.jsx("li",{ref:i,...r,children:e})}),HE=k.forwardRef(function({nodeProps:e,...t},r){return A.jsx("span",{ref:r,...t,suppressContentEditableWarning:!0,contentEditable:"false",children:A.jsx("button",{children:e.node.attrs.number})})}),jE=k.forwardRef(function({widget:e,getPos:t,...r},i){return A.jsx("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),KE=new $t({view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});new $t({props:{decorations(n){return _.create(n.doc,[J1(n.selection.from,jE,{side:0,key:"widget-plugin-widget"})])}},view(n){const e=n.coordsAtPos(n.state.selection.from),t=document.createElement("div");return t.style.width="4px",t.style.height="4px",t.style.position="absolute",t.style.top=`${e.top-2}px`,t.style.left=`${e.left-2}px`,t.style.backgroundColor="blue",document.body.appendChild(t),{update(r){const i=r.coordsAtPos(r.state.selection.from);t.style.top=`${i.top-2}px`,t.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(t)}}}});const qE=[ux({...Hw,"Mod-i":jd(J.marks.em),"Mod-b":jd(J.marks.strong)}),KE,Jv()],QE={paragraph:()=>{const n=document.createElement("p");return{dom:n,contentDOM:n}}};function YE(){const[n,e]=k.useState(JE),[t,r]=k.useState(!0),i=k.useMemo(()=>t?{paragraph:_E,list:WE,list_item:UE,footnote:HE}:void 0,[t]),o=k.useCallback(function(s){e(l=>l.apply(s))},[]);return A.jsxs("main",{children:[A.jsx("h1",{children:"React ProseMirror Demo"}),A.jsxs("button",{onClick:()=>{t?r(s=>!s):window.location.reload()},children:["Switch to"," ",t?"ProseMirror node views":"React node views (requires reload)"]}),A.jsx(BE,{className:"ProseMirror",state:n,dispatchTransaction:o,plugins:qE,nodeViews:i,customNodeViews:t?void 0:QE,children:A.jsx(LE,{})},`${t}`)]})}const GE=P1(document.getElementById("root"));GE.render(A.jsx(k.StrictMode,{children:A.jsx(YE,{})})); diff --git a/docs/index.html b/docs/index.html index 3667373..e4dd3ac 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ React-ProseMirror Demo - + diff --git a/src/components/ChildNodeViews.tsx b/src/components/ChildNodeViews.tsx index bcae69a..4c78685 100644 --- a/src/components/ChildNodeViews.tsx +++ b/src/components/ChildNodeViews.tsx @@ -281,55 +281,46 @@ function createKey( return pos; } -function adjustWidgetMarksForward(childMap: Map) { - const children = Array.from(childMap.values()).sort( - (a, b) => a.offset - b.offset - ); - const lastChild = children[children.length - 1]; +function adjustWidgetMarksForward( + lastNodeChild: ChildNode | null, + widgetChild: ChildWidget | ChildNativeWidget | null +) { if ( - (lastChild?.type !== "widget" && lastChild?.type !== "native-widget") || + !widgetChild || // Using internal Decoration property, "type" // eslint-disable-next-line @typescript-eslint/no-explicit-any - (lastChild.widget as any).type.side >= 0 + (widgetChild.widget as any).type.side >= 0 ) return; - let lastNodeChild: ChildNode | null = null; - for (let i = children.length - 2; i >= 0; i--) { - const child = children[i]; - if (child?.type === "node") { - lastNodeChild = child; - break; - } - } - if (!lastNodeChild || !lastNodeChild.node.isInline) return; const marksToSpread = lastNodeChild.marks; - lastChild.marks = lastChild.marks.reduce( + widgetChild.marks = widgetChild.marks.reduce( (acc, mark) => mark.addToSet(acc), marksToSpread ); } -function adjustWidgetMarksBack(childMap: Map) { - const children = Array.from(childMap.values()).sort( - (a, b) => a.offset - b.offset - ); - const lastChild = children[children.length - 1]; - if (lastChild?.type !== "node" || !lastChild.node.isInline) return; +function adjustWidgetMarksBack( + widgetChildren: Array, + nodeChild: ChildNode +) { + if (!nodeChild.node.isInline) return; + + const marksToSpread = nodeChild.marks; + for (let i = widgetChildren.length - 1; i >= 0; i--) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const child = widgetChildren[i]!; - const marksToSpread = lastChild.marks; - for (let i = children.length - 2; i >= 0; i--) { - const child = children[i]; if ( - (child?.type !== "widget" && child?.type !== "native-widget") || // Using internal Decoration property, "type" // eslint-disable-next-line @typescript-eslint/no-explicit-any (child.widget as any).type.side < 0 - ) - break; + ) { + continue; + } child.marks = child.marks.reduce( (acc, mark) => mark.addToSet(acc), @@ -422,14 +413,18 @@ export const ChildNodeViews = memo(function ChildNodeViews({ const keysSeen = new Set(); + let widgetChildren: Array = []; + let lastNodeChild: ChildNode | null = null; + iterDeco( node, innerDecorations, (widget, isNative, offset, index) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const widgetMarks = ((widget as any).type.spec.marks as Mark[]) ?? []; + let key; if (isNative) { - const key = createKey( + key = createKey( getInnerPos.current(), offset, "native-widget", @@ -453,7 +448,7 @@ export const ChildNodeViews = memo(function ChildNodeViews({ } keysSeen.add(key); } else { - const key = createKey( + key = createKey( getInnerPos.current(), offset, "widget", @@ -477,7 +472,12 @@ export const ChildNodeViews = memo(function ChildNodeViews({ } keysSeen.add(key); } - adjustWidgetMarksForward(childMap); + const child = childMap.get(key) as ChildWidget | ChildNativeWidget; + widgetChildren.push(child); + adjustWidgetMarksForward( + lastNodeChild, + childMap.get(key) as ChildWidget | ChildNativeWidget + ); }, (childNode, outerDeco, innerDeco, offset) => { const key = createKey( @@ -498,11 +498,14 @@ export const ChildNodeViews = memo(function ChildNodeViews({ const prevChild = childMap.get(key); if (prevChild && areChildrenEqual(prevChild, child)) { prevChild.offset = offset; + lastNodeChild = prevChild as ChildNode; } else { childMap.set(key, child); + lastNodeChild = child; } keysSeen.add(key); - adjustWidgetMarksBack(childMap); + adjustWidgetMarksBack(widgetChildren, lastNodeChild); + widgetChildren = []; } );