Files
llm-in-text/.build-check/assets/prosemirror-n4jms1hu.js
T
ydy0615 838eec30a8 feat: add theme management with light and dark modes
- Implemented a new composable `useTheme` for managing theme state.
- Added functions to read and write theme preference to local storage.
- Applied theme styles to the DOM based on user preference.
- Introduced a toggle function to switch between light and dark themes.

refactor: enhance copilot plugin functionality

- Improved request handling with sequence and document versioning.
- Refactored ghost text handling to improve clarity and efficiency.
- Updated markdown insertion logic to handle parsed content more robustly.
- Enhanced error handling and logging for better debugging.

style: update global styles for light and dark themes

- Defined CSS variables for light and dark themes to streamline styling.
- Improved overall styling consistency and responsiveness.
- Added transitions for smoother theme changes and interactions.
2026-02-15 15:44:09 +08:00

11 lines
246 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{R as Oi}from"./vendor-rope-sequence-nfUW61tr.js";import{i as ao}from"./vendor-ocavue-utils-C1mApV17.js";import{k as co,b as fo}from"./vendor-w3c-keyname-Vcq4gwWv.js";import{O as cr}from"./vendor-orderedmap-C4TimWWB.js";function Ti(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Ti(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Di(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let c=0,f=Math.min(o.text.length,l.text.length);for(;c<f&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,n--;return{a:t,b:n}}if(o.content.size||l.content.size){let c=Di(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}class y{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&n(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),n,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new y(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let n=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),n.push(l),i+=l.nodeSize),o=a}return new y(n,i)}cutByIndex(e,t){return e==t?y.empty:e==0&&t==this.content.length?this:new y(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new y(i,s)}addToStart(e){return new y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new y(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let i=this.content[t];e(i,n,t),n+=i.nodeSize}}findDiffStart(e,t=0){return Ti(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Di(this,e,t,n)}findIndex(e){if(e==0)return Nt(0,e);if(e==this.size)return Nt(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let i=this.child(t),s=n+i.nodeSize;if(s>=e)return s==e?Nt(t+1,s):Nt(t,n);n=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 y.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new y(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return y.empty;let t,n=0;for(let i=0;i<e.length;i++){let s=e[i];n+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new y(t||e,n)}static from(e){if(!e)return y.empty;if(e instanceof y)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new y([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}y.empty=new y([],0);const rn={index:0,offset:0};function Nt(r,e){return rn.index=r,rn.offset=e,rn}function Ft(r,e){if(r===e)return!0;if(!(r&&typeof r=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(r);if(Array.isArray(e)!=t)return!1;if(t){if(r.length!=e.length)return!1;for(let n=0;n<r.length;n++)if(!Ft(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!Ft(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}class M{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Ft(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=n.create(t.attrs);return n.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return M.none;if(e instanceof M)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}}M.none=[];class Vt extends Error{}class x{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Ei(this.content,e+this.openStart,t);return n&&new x(n,this.openStart,this.openEnd)}removeBetween(e,t){return new x(Ai(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 x.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(y.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new x(e,n,i)}}x.empty=new x(y.empty,0,0);function Ai(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Ai(s.content,e-i-1,t-i-1)))}function Ei(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return n&&!n.canReplace(i,i,t)?null:r.cut(0,e).append(t).append(r.cut(e));let l=Ei(o.content,e-s-1,t,o);return l&&r.replaceChild(i,o.copy(l))}function ho(r,e,t){if(t.openStart>r.depth)throw new Vt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Vt("Inconsistent open depths");return Ri(r,e,t,0)}function Ri(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n<r.depth-t.openStart){let o=Ri(r,e,t,n+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&r.depth==n&&e.depth==n){let o=r.parent,l=o.content;return Be(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=uo(t,r);return Be(s,zi(r,o,l,e,n))}else return Be(s,Lt(r,e,n))}function Ii(r,e){if(!e.type.compatibleContent(r.type))throw new Vt("Cannot join "+e.type.name+" onto "+r.type.name)}function kn(r,e,t){let n=r.node(t);return Ii(n,e.node(t)),n}function ze(r,e){let t=e.length-1;t>=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function ct(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(ze(r.nodeAfter,n),s++));for(let l=s;l<o;l++)ze(i.child(l),n);e&&e.depth==t&&e.textOffset&&ze(e.nodeBefore,n)}function Be(r,e){return r.type.checkContent(e),r.copy(e)}function zi(r,e,t,n,i){let s=r.depth>i&&kn(r,e,i+1),o=n.depth>i&&kn(t,n,i+1),l=[];return ct(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Ii(s,o),ze(Be(s,zi(r,e,t,n,i+1)),l)):(s&&ze(Be(s,Lt(r,e,i+1)),l),ct(e,t,i,l),o&&ze(Be(o,Lt(t,n,i+1)),l)),ct(n,null,i,l),new y(l)}function Lt(r,e,t){let n=[];if(ct(null,r,t,n),r.depth>t){let i=kn(r,e,t+1);ze(Be(i,Lt(r,e,t+1)),n)}return ct(e,null,t,n),new y(n)}function uo(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}class pt{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=n.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return M.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),i=e.maybeChild(t);if(!n){let l=n;n=i,i=l}let s=n.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<n.length;s++)n[s].type.spec.inclusive===!1&&(!i||!n[s].isInSet(i.marks))&&(n=n[s--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Bi(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(n.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new pt(t,n,s)}static resolveCached(e,t){let n=fr.get(e);if(n)for(let s=0;s<n.elts.length;s++){let o=n.elts[s];if(o.pos==t)return o}else fr.set(e,n=new po);let i=n.elts[n.i]=pt.resolve(e,t);return n.i=(n.i+1)%mo,i}}class po{constructor(){this.elts=[],this.i=0}}const mo=12,fr=new WeakMap;class Bi{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const go=Object.create(null);class ie{constructor(e,t,n,i=M.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||y.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,i=0){this.content.nodesBetween(e,t,n,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,i){return this.content.textBetween(e,t,n,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Ft(this.attrs,t||e.defaultAttrs||go)&&M.sameSet(this.marks,n||M.none)}copy(e=null){return e==this.content?this:new ie(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new ie(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return x.empty;let i=this.resolve(e),s=this.resolve(t),o=n?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new x(c,i.depth-o,s.depth-o)}replace(e,t,n){return ho(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let i=this.content.child(t-1);return{node:i,index:t-1,offset:n-i.nodeSize}}resolve(e){return pt.resolveCached(this,e)}resolveNoCache(e){return pt.resolve(this,e)}rangeHasMark(e,t,n){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(n.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Pi(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=y.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(n.child(a).marks))return!1;return!0}canReplaceWith(e,t,n,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(n),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=M.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!M.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let i=y.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,n);return s.type.checkAttrs(s.attrs),s}}ie.prototype.text=void 0;class $t extends ie{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Pi(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 $t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new $t(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 Pi(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}class Ve{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new yo(e,t);if(n.next==null)return Ve.empty;let i=vi(n);n.next&&n.err("Unexpected trailing text");let s=Mo(wo(i));return No(s,n),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let i=this;for(let s=t;i&&s<n;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let i=[this];function s(o,l){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return y.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:f,next:h}=o.next[c];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let d=s(h,l.concat(f));if(d)return d}}return null}return s(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let i=n.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(n.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let i=0;i<n.next.length;i++)e.indexOf(n.next[i].next)==-1&&t(n.next[i].next)}return t(this),e.map((n,i)=>{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o<n.next.length;o++)s+=(o?", ":"")+n.next[o].type.name+"->"+e.indexOf(n.next[o].next);return s}).join(`
`)}}Ve.empty=new Ve(!0);class yo{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 vi(r){let e=[];do e.push(bo(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function bo(r){let e=[];do e.push(xo(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function xo(r){let e=ko(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=So(r,e);else break;return e}function hr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function So(r,e){let t=hr(r),n=t;return r.eat(",")&&(r.next!="}"?n=hr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Co(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function ko(r){if(r.eat("(")){let e=vi(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=Co(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function wo(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let f=t();i(s(o.expr,a),f),a=f}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let f=t();n(a,f),i(s(o.expr,a),f),a=f}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Fi(r,e){return e-r}function dr(r,e){let t=[];return n(e),t.sort(Fi);function n(i){let s=r[i];if(s.length==1&&!s[0].term)return n(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&n(a)}}}function Mo(r){let e=Object.create(null);return t(dr(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f<i.length;f++)i[f][0]==l&&(c=i[f][1]);dr(r,a).forEach(f=>{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[n.join(",")]=new Ve(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Fi);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function No(r,e){for(let t=0,n=[r];t<n.length;t++){let i=n[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),n.indexOf(c)==-1&&n.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Vi(r){let e=Object.create(null);for(let t in r){let n=r[t];if(!n.hasDefault)return null;e[t]=n.default}return e}function Li(r,e){let t=Object.create(null);for(let n in r){let i=e&&e[n];if(i===void 0){let s=r[n];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+n)}t[n]=i}return t}function $i(r,e,t,n){for(let i in e)if(!(i in r))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${i}`);for(let i in r){let s=r[i];s.validate&&s.validate(e[i])}}function Wi(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new To(r,n,e[n]);return t}let ur=class Ji{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=Wi(e,n.attrs),this.defaultAttrs=Vi(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Ve.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Li(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ie(this,this.computeAttrs(e),y.from(t),M.setFrom(n))}createChecked(e=null,t,n){return t=y.from(t),this.checkContent(t),new ie(this,this.computeAttrs(e),t,M.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=y.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(y.empty,!0);return s?new ie(this,e,t.append(s),M.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n<e.childCount;n++)if(!this.allowsMarks(e.child(n).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){$i(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:M.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new Ji(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function Oo(r,e,t){let n=t.split("|");return i=>{let s=i===null?"null":typeof i;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${r}, got ${s}`)}}class To{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Oo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Ut{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Wi(e,i.attrs),this.excluded=null;let s=Vi(this.attrs);this.instance=s?new M(this,s):null}create(e=null){return!e&&this.instance?this.instance:new M(this,Li(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Ut(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){$i(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Hf{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=cr.from(e.nodes),t.marks=cr.from(e.marks||{}),this.nodes=ur.compile(this.spec.nodes,this),this.marks=Ut.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=n[o]||(n[o]=Ve.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?pr(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:pr(this,o.split(" "))}this.nodeFromJSON=i=>ie.fromJSON(this,i),this.markFromJSON=i=>M.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ur){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new $t(n,n.defaultAttrs,e,M.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function pr(r,e){let t=[];for(let n=0;n<e.length;n++){let i=e[n],s=r.marks[i],o=s;if(s)t.push(s);else for(let l in r.marks){let a=r.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function Do(r){return r.tag!=null}function Ao(r){return r.style!=null}class mt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(Do(i))this.tags.push(i);else if(Ao(i)){let s=/[^=]*/.exec(i.style)[0];n.indexOf(s)<0&&n.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let n=new gr(this,t,!1);return n.addAll(e,M.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new gr(this,t,!0);return n.addAll(e,M.none,t.from,t.to),x.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(Io(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,n,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!n.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{n(o=yr(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{n(o=yr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new mt(e,mt.schemaRules(e)))}}const qi={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},Eo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ki={ol:!0,ul:!0},gt=1,wn=2,ft=4;function mr(r,e,t){return e!=null?(e?gt:0)|(e==="full"?wn:0):r&&r.whitespace=="pre"?gt|wn:t&~ft}class Ot{constructor(e,t,n,i,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=o,this.content=[],this.activeMarks=M.none,this.match=s||(o&ft?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&gt)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!qi.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class gr{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=mr(null,t.preserveWhitespace,0)|(n?ft:0);i?s=new Ot(i.type,i.attrs,M.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ot(null,null,M.none,!0,null,o):s=new Ot(e.schema.topNodeType,null,M.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,i=this.top,s=i.options&wn?"full":this.localPreserveWS||(i.options&gt)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
`);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=i.content[i.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Ki.hasOwnProperty(o)&&this.parser.normalizeLists&&Ro(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:Eo.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(qi.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let h=a&&a.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,i){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(n)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o<i.length;o++)t=this.enterInner(i[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let i=this.findPlace(e,t,n);if(i){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=M.none;for(let l of i.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):br(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,i)),s}enterInner(e,t,n,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=mr(e,s,o.options);o.options&ft&&o.content.length==0&&(l|=ft);let a=M.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):br(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ot(e,t,a,i,null,l)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=gt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}}function Ro(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Ki.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Io(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function yr(r){let e={};for(let t in r)e[t]=r[t];return e}function br(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:f}=l.edge(a);if(c==e||s.indexOf(f)<0&&o(f))return!0}};if(o(i.contentMatch))return!0}}class nt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=sn(t).createDocumentFragment());let i=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],f=this.serializeMark(c,o.isInline,t);f&&(s.push([c,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=It(sn(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&It(sn(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return It(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new nt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=xr(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return xr(e.marks)}}function xr(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function sn(r){return r.document||window.document}const Sr=new WeakMap;function zo(r){let e=Sr.get(r);return e===void 0&&Sr.set(r,e=Bo(r)),e}function Bo(r){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);else for(let i=0;i<n.length;i++)t(n[i]);else for(let i in n)t(n[i])}return t(r),e}function It(r,e,t,n){if(typeof e=="string")return{dom:r.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=zo(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?r.createElementNS(t,i):r.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?a.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):h=="style"&&a.style?a.style.cssText=c[h]:a.setAttribute(h,c[h])}}for(let h=f;h<e.length;h++){let d=e[h];if(d===0){if(h<e.length-1||h>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:u,contentDOM:p}=It(r,d,t,n);if(a.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Hi=65535,ji=Math.pow(2,16);function Po(r,e){return r+e*ji}function Cr(r){return r&Hi}function vo(r){return(r-(r&Hi))/ji}const Ui=1,Gi=2,zt=4,Xi=8;class Mn{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Xi)>0}get deletedBefore(){return(this.delInfo&(Ui|zt))>0}get deletedAfter(){return(this.delInfo&(Gi|zt))>0}get deletedAcross(){return(this.delInfo&zt)>0}}class U{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&U.empty)return U.empty}recover(e){let t=0,n=Cr(e);if(!this.inverted)for(let i=0;i<n;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[n*3]+t+vo(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],f=this.ranges[l+o],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,u=a+i+(d<0?0:f);if(n)return u;let p=e==(t<0?a:h)?null:Po(l/3,e-a),m=e==a?Gi:e==h?Ui:zt;return(t<0?e!=a:e!=h)&&(m|=Xi),new Mn(u,m,p)}i+=f-c}return n?e+i:new Mn(e+i,0,null)}touches(e,t){let n=0,i=Cr(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;n+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],f=this.ranges[i+n];e(l,l+c,a,a+f),s+=f-c}}invert(){return new U(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?U.empty:new U(e<0?[0,-e,0]:[0,0,e])}}U.empty=new U([]);class yt{constructor(e,t,n=0,i=e?e.length:0){this.mirror=t,this.from=n,this.to=i,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new yt(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let i=e.getMirror(t);this.appendMap(e._maps[t],i!=null&&i<t?n+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?n-i-1:void 0)}}invert(){let e=new yt;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let i=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}i|=l.delInfo,e=l.pos}return n?e:new Mn(e,i,null)}}const on=Object.create(null);class ${getMap(){return U.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=on[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in on)throw new RangeError("Duplicate use of step JSON ID "+e);return on[e]=t,t.prototype.jsonID=e,t}}class I{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new I(e,null)}static fail(e){return new I(null,e)}static fromReplace(e,t,n,i){try{return I.ok(e.replace(t,n,i))}catch(s){if(s instanceof Vt)return I.fail(s.message);throw s}}}function qn(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(qn(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return y.fromArray(n)}class Se extends ${constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new x(qn(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,s)}invert(){return new re(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Se(t.pos,n.pos,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Se(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("addMark",Se);class re extends ${constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new x(qn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,n)}invert(){return new Se(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new re(t.pos,n.pos,this.mark)}merge(e){return e instanceof re&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new re(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new re(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("removeMark",re);class Ce extends ${constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new x(y.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(n))return new Ce(this.pos,t.marks[i]);return new Ce(this.pos,this.mark)}}return new Le(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ce(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Ce(t.pos,e.markFromJSON(t.mark))}}$.jsonID("addNodeMark",Ce);class Le extends ${constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new x(y.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Ce(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Le(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Le(t.pos,e.markFromJSON(t.mark))}}$.jsonID("removeNodeMark",Le);class B extends ${constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&Nn(e,this.from,this.to)?I.fail("Structure replace would overwrite content"):I.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new U([this.from,this.to-this.from,this.slice.size])}invert(e){return new B(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deletedAcross&&n.deletedAcross?null:new B(t.pos,Math.max(t.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof B)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?x.empty:new x(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new B(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?x.empty:new x(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new B(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};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")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new B(t.from,t.to,x.fromJSON(e,t.slice),!!t.structure)}}$.jsonID("replace",B);class L extends ${constructor(e,t,n,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(Nn(e,this.from,this.gapFrom)||Nn(e,this.gapTo,this.to)))return I.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return I.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?I.fromReplace(e,this.from,this.to,n):I.fail("Content does not fit in gap")}getMap(){return new U([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new L(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||i<t.pos||s>n.pos?null:new L(t.pos,n.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new L(t.from,t.to,t.gapFrom,t.gapTo,x.fromJSON(e,t.slice),t.insert,!!t.structure)}}$.jsonID("replaceAround",L);function Nn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Fo(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let h=a.marks;if(!n.isInSet(h)&&f.type.allowsMarkType(n.type)){let d=Math.max(c,e),u=Math.min(c+a.nodeSize,t),p=n.addToSet(h);for(let m=0;m<h.length;m++)h[m].isInSet(p)||(o&&o.to==d&&o.mark.eq(h[m])?o.to=u:i.push(o=new re(d,u,h[m])));l&&l.to==d?l.to=u:s.push(l=new Se(d,u,n))}}),i.forEach(a=>r.step(a)),s.forEach(a=>r.step(a))}function Vo(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(n instanceof Ut){let c=o.marks,f;for(;f=n.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;f<a.length;f++){let h=a[f],d;for(let u=0;u<i.length;u++){let p=i[u];p.step==s-1&&h.eq(i[u].style)&&(d=p)}d?(d.to=c,d.step=s):i.push({style:h,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new re(o.from,o.to,o.style)))}function Kn(r,e,t,n=t.contentMatch,i=!0){let s=r.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),f=l+c.nodeSize,h=n.matchType(c.type);if(!h)o.push(new B(l,f,x.empty));else{n=h;for(let d=0;d<c.marks.length;d++)t.allowsMarkType(c.marks[d].type)||r.step(new re(l,f,c.marks[d]));if(i&&c.isText&&t.whitespace!="pre"){let d,u=/\r?\n|\r/g,p;for(;d=u.exec(c.text);)p||(p=new x(y.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new B(l+d.index,l+d.index+d[0].length,p))}}l=f}if(!n.validEnd){let a=n.fillBefore(y.empty,!0);r.replace(l,l,new x(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function Lo(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function Gt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth,i=0,s=0;;--n){let o=r.$from.node(n),l=r.$from.index(n)+i,a=r.$to.indexAfter(n)-s;if(n<r.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!Lo(o,l,a))break;l&&(i=1),a<o.childCount&&(s=1)}return null}function $o(r,e,t){let{$from:n,$to:i,depth:s}=e,o=n.before(s+1),l=i.after(s+1),a=o,c=l,f=y.empty,h=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,f=y.from(n.node(p).copy(f)),h++):a--;let d=y.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)<i.end(p)?(m=!0,d=y.from(i.node(p).copy(d)),u++):c++;r.step(new L(a,c,o,l,new x(f.append(d),h,u),f.size-h,!0))}function Yi(r,e,t=null,n=r){let i=Wo(r,e),s=i&&Jo(n,e);return s?i.map(kr).concat({type:e,attrs:t}).concat(s.map(kr)):null}function kr(r){return{type:r,attrs:null}}function Wo(r,e){let{parent:t,startIndex:n,endIndex:i}=r,s=t.contentMatchAt(n).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(n,i,o)?s:null}function Jo(r,e){let{parent:t,startIndex:n,endIndex:i}=r,s=t.child(n),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let c=n;a&&c<i;c++)a=a.matchType(t.child(c).type);return!a||!a.validEnd?null:o}function qo(r,e,t){let n=y.empty;for(let o=t.length-1;o>=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=y.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new L(i,s,i,s,new x(n,0,0),t.length,!0))}function Ko(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(n,a)&&Ho(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let u=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);u&&!p?c=!1:!u&&p&&(c=!0)}c===!1&&Zi(r,o,l,s),Kn(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),h=f.map(l,1),d=f.map(l+o.nodeSize,1);return r.step(new L(h,d,h+1,d-1,new x(y.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&_i(r,o,l,s),!1}})}function _i(r,e,t,n){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=r.mapping.slice(n).map(t+1+s+o.index);r.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Zi(r,e,t,n){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=r.mapping.slice(n).map(t+1+s);r.replaceWith(o,o+1,e.type.schema.text(`
`))}})}function Ho(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function jo(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new L(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new x(y.from(o),0,0),1,!0))}function ht(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let u=h.content.cutByIndex(d,h.childCount),p=n&&n[f+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Uo(r,e,t=1,n){let i=r.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=y.from(i.node(l).copy(s));let f=n&&n[c];o=y.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}r.step(new B(e,e,new x(s.append(o),t,t),!0))}function Xt(r,e){let t=r.resolve(e),n=t.index();return Xo(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function Go(r,e){e.content.size||r.type.compatibleContent(e.type);let t=r.contentMatchAt(r.childCount),{linebreakReplacement:n}=r.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==n?r.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!r.type.allowsMarks(s.marks))return!1}return t.validEnd}function Xo(r,e){return!!(r&&e&&!r.isLeaf&&Go(r,e))}function Yo(r,e,t){let n=null,{linebreakReplacement:i}=r.doc.type.schema,s=r.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",h=!!o.contentMatch.matchType(i);f&&!h?n=!1:!f&&h&&(n=!0)}let l=r.steps.length;if(n===!1){let f=r.doc.resolve(e+t);Zi(r,f.node(),f.before(),l)}o.inlineContent&&Kn(r,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=r.mapping.slice(l),c=a.map(e-t);if(r.step(new B(c,a.map(e+t,-1),x.empty,!0)),n===!0){let f=r.doc.resolve(c);_i(r,f.node(),f.before(),r.steps.length)}return r}function _o(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;i>=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s<n.node(i).childCount)return null}return null}function Zo(r,e,t){let n=r.resolve(e);if(!t.content.size)return e;let i=t.content;for(let s=0;s<t.openStart;s++)i=i.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=n.depth;o>=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),c=n.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function Yt(r,e,t=e,n=x.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return Qi(i,s,n)?new B(e,t,n):new Qo(i,s,n).fit()}function Qi(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class Qo{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new x(s,o,l);return e>-1?new L(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new B(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n<e;n++){let s=t.firstChild;if(t.childCount>1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=ln(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(o?c.matchType(o.type)||(h=c.fillBefore(y.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ln(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ln(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new x(st(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new x(st(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,c=0,f=[],{match:h,type:d}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)f.push(i.child(m));h=h.matchFragment(i)}let u=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=h.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(h=g,f.push(es(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?u:-1)))}let p=c==l.childCount;p||(u=-1),this.placed=ot(this.placed,t,y.from(f)),this.frontier[t].match=h,p&&u<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<u;m++){let b=g.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),g=b.content}this.unplaced=p?e==0?x.empty:new x(st(o.content,e-1,1),e-1,u<0?o.openEnd:e-1):new x(st(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!an(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,i=this.$to.after(n);for(;n>1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=an(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],f=an(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ot(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ot(this.placed,this.depth,y.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=ot(this.placed,this.frontier.length,t))}}function st(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(st(r.firstChild.content,e-1,t)))}function ot(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ot(r.lastChild.content,e-1,t)))}function ln(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function es(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,es(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(y.empty,!0)))),r.copy(n)}function an(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!el(t,s.content,o)?l:null}function el(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function tl(r){return r.spec.defining||r.spec.definingForContent}function nl(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(Qi(i,s,n))return r.step(new B(e,t,n));let o=ns(i,s);o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let d=i.depth,u=i.pos-1;d>0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],f=n.openStart;for(let d=n.content,u=0;;u++){let p=d.firstChild;if(c.push(p),u==n.openStart)break;d=p.content}for(let d=f-1;d>=0;d--){let u=c[d],p=tl(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(p||!u.type.isTextblock)break}for(let d=n.openStart;d>=0;d--){let u=(d+f+1)%(n.openStart+1),p=c[u];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],b=!0;g<0&&(b=!1,g=-g);let N=i.node(g-1),O=i.index(g-1);if(N.canReplaceWith(O,O,p.type,p.marks))return r.replace(i.before(g),b?s.after(g):t,new x(ts(n.content,0,n.openStart,u),u,n.openEnd))}}let h=r.steps.length;for(let d=o.length-1;d>=0&&(r.replace(e,t,n),!(r.steps.length>h));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function ts(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(ts(s.content,e+1,t,n,s)))}if(e>n){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return r}function rl(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=_o(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new x(y.from(n),0,0))}function il(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=ns(n,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return r.delete(n.start(l),i.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o&&n.start(o-1)==i.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),i.index(o-1)))return r.delete(n.before(o),t);r.delete(e,t)}function ns(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(s<r.pos-(r.depth-i)||e.end(i)>e.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class Xe extends ${constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new x(y.from(i),0,t.isLeaf?0:1))}getMap(){return U.empty}invert(e){return new Xe(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 Xe(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 Xe(t.pos,t.attr,t.value)}}$.jsonID("attr",Xe);class bt extends ${constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return I.ok(n)}getMap(){return U.empty}invert(e){return new bt(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 bt(t.attr,t.value)}}$.jsonID("docAttr",bt);let _e=class extends Error{};_e=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};_e.prototype=Object.create(Error.prototype);_e.prototype.constructor=_e;_e.prototype.name="TransformError";class rs{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new yt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new _e(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=x.empty){let i=Yt(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new x(y.from(n),0,0))}delete(e,t){return this.replace(e,t,x.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return nl(this,e,t,n),this}replaceRangeWith(e,t,n){return rl(this,e,t,n),this}deleteRange(e,t){return il(this,e,t),this}lift(e,t){return $o(this,e,t),this}join(e,t=1){return Yo(this,e,t),this}wrap(e,t){return qo(this,e,t),this}setBlockType(e,t=e,n,i=null){return Ko(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return jo(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Xe(e,t,n)),this}setDocAttribute(e,t){return this.step(new bt(e,t)),this}addNodeMark(e,t){return this.step(new Ce(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof M)t.isInSet(n.marks)&&this.step(new Le(e,t));else{let i=n.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Le(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return Uo(this,e,t,n),this}addMark(e,t,n){return Fo(this,e,t,n),this}removeMark(e,t,n){return Vo(this,e,t,n),this}clearIncompatible(e,t,n){return Kn(this,e,t,n),this}}const cn=Object.create(null);class C{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new is(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<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=x.empty){let n=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],f=e.mapping.slice(s);e.replaceRange(f.map(a.pos),f.map(c.pos),l?x.empty:t),l==0&&Nr(e,s,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(n),c=a.map(o.pos),f=a.map(l.pos);s?e.deleteRange(c,f):(e.replaceRangeWith(c,f,t),Nr(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new k(e):He(e.node(0),e.parent,e.pos,e.index(),t,n);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?He(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):He(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new X(e.node(0))}static atStart(e){return He(e,e,0,0,1)||new X(e)}static atEnd(e){return He(e,e,e.content.size,e.childCount,-1)||new X(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=cn[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in cn)throw new RangeError("Duplicate use of selection JSON ID "+e);return cn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return k.between(this.$anchor,this.$head).getBookmark()}}C.prototype.visible=!0;class is{constructor(e,t){this.$from=e,this.$to=t}}let wr=!1;function Mr(r){!wr&&!r.parent.inlineContent&&(wr=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class k extends C{constructor(e,t=e){Mr(e),Mr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return C.near(n);let i=e.resolve(t.map(this.anchor));return new k(i.parent.inlineContent?i:n,n)}replace(e,t=x.empty){if(super.replace(e,t),t==x.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof k&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new _t(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 k(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=C.findFrom(t,n,!0)||C.findFrom(t,-n,!0);if(s)t=s.$head;else return C.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(C.findFrom(e,-n,!0)||C.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new k(e,t)}}C.jsonID("text",k);class _t{constructor(e,t){this.anchor=e,this.head=t}map(e){return new _t(e.map(this.anchor),e.map(this.head))}resolve(e){return k.between(e.resolve(this.anchor),e.resolve(this.head))}}class S extends C{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return n?C.near(s):new S(s)}content(){return new x(y.from(this.node),0,0)}eq(e){return e instanceof S&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Hn(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new S(e.resolve(t.anchor))}static create(e,t){return new S(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}S.prototype.visible=!1;C.jsonID("node",S);class Hn{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new _t(n,n):new Hn(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&S.isSelectable(n)?new S(t):C.near(t)}}class X extends C{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=x.empty){if(t==x.empty){e.delete(0,e.doc.content.size);let n=C.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new X(e)}map(e){return new X(e)}eq(e){return e instanceof X}getBookmark(){return sl}}C.jsonID("all",X);const sl={map(){return this},resolve(r){return new X(r)}};function He(r,e,t,n,i,s=!1){if(e.inlineContent)return k.create(r,t);for(let o=n-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(r,t-(i<0?l.nodeSize:0))}else{let a=He(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Nr(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof B||i instanceof L))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,f)=>{o==null&&(o=f)}),r.setSelection(C.near(r.doc.resolve(o),t))}const Or=1,Tt=2,Tr=4;class ol extends rs{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.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Or)&~Tt,this.storedMarks=null,this}get selectionSet(){return(this.updated&Or)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Tt,this}ensureMarks(e){return M.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Tt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Tt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||M.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(C.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Tr,this}get scrolledIntoView(){return(this.updated&Tr)>0}}function Dr(r,e){return!e||!r?r:r.bind(e)}class lt{constructor(e,t,n){this.name=e,this.init=Dr(t.init,n),this.apply=Dr(t.apply,n)}}const ll=[new lt("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new lt("selection",{init(r,e){return r.selection||C.atStart(e.doc)},apply(r){return r.selection}}),new lt("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new lt("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class fn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ll.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new lt(n.key,n.spec.state,n))})}}class at{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let i=this.config.plugins[n];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,f=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(f&&n.filterTransaction(f,o)){if(f.setMeta("appendedTransaction",e),!i){i=[];for(let h=0;h<this.config.plugins.length;h++)i.push(h<o?{state:n,n:t.length}:{state:this,n:0})}t.push(f),n=n.applyInner(f),s=!0}i&&(i[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new at(this.config),n=this.config.fields;for(let i=0;i<n.length;i++){let s=n[i];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new ol(this)}static create(e){let t=new fn(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new at(t);for(let i=0;i<t.fields.length;i++)n[t.fields[i].name]=t.fields[i].init(e,n);return n}reconfigure(e){let t=new fn(this.schema,e.plugins),n=t.fields,i=new at(t);for(let s=0;s<n.length;s++){let o=n[s].name;i[o]=this.hasOwnProperty(o)?this[o]:n[s].init(e,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(n=>n.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new fn(e.schema,e.plugins),s=new at(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ie.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=C.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function ss(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=ss(i,e,{})),t[n]=i}return t}class Oe{constructor(e){this.spec=e,this.props={},e.props&&ss(e.props,this,this.props),this.key=e.key?e.key.key:ls("plugin")}getState(e){return e[this.key]}}const hn=Object.create(null);function ls(r){return r in hn?r+"$"+ ++hn[r]:(hn[r]=0,r+"$")}class Te{constructor(e="key"){this.key=ls(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const as=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function cs(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const al=(r,e,t)=>{let n=cs(r,t);if(!n)return!1;let i=jn(n);if(!i){let o=n.blockRange(),l=o&&Gt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(hs(r,i,e,-1))return!0;if(n.parent.content.size==0&&(Ze(s,"end")||S.isSelectable(s)))for(let o=n.depth;;o--){let l=Yt(r.doc,n.before(o),n.after(o),x.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(Ze(s,"end")?C.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):S.create(a.doc,i.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||n.node(o-1).childCount>1)break}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},jf=(r,e,t)=>{let n=cs(r,t);if(!n)return!1;let i=jn(n);return i?cl(r,i,e):!1};function cl(r,e,t){let n=e.nodeBefore,i=n,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let f=i.lastChild;if(!f)return!1;i=f}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let f=l.firstChild;if(!f)return!1;l=f}let c=Yt(r.doc,s,a,x.empty);if(!c||c.from!=s||c instanceof B&&c.slice.size>=a-s)return!1;if(t){let f=r.tr.step(c);f.setSelection(k.create(f.doc,s)),t(f.scrollIntoView())}return!0}function Ze(r,e,t=!1){for(let n=r;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}const fl=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=jn(n)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function jn(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function hl(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}const dl=(r,e,t)=>{let n=hl(r,t);if(!n)return!1;let i=fs(n);if(!i)return!1;let s=i.nodeAfter;if(hs(r,i,e,1))return!0;if(n.parent.content.size==0&&(Ze(s,"start")||S.isSelectable(s))){let o=Yt(r.doc,n.before(),n.after(),x.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(Ze(s,"start")?C.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):S.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},ul=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset<n.parent.content.size)return!1;s=fs(n)}let o=s&&s.nodeAfter;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos)).scrollIntoView()),!0)};function fs(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){let t=r.node(e);if(r.index(e)+1<t.childCount)return r.doc.resolve(r.after(e+1));if(t.type.spec.isolating)break}return null}const pl=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
`).scrollIntoView()),!0)};function Un(r){for(let e=0;e<r.edgeCount;e++){let{type:t}=r.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const ml=(r,e)=>{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Un(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(C.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},gl=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof X||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=Un(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index()<i.parent.childCount?n:i).pos,l=r.tr.insert(o,s.createAndFill());l.setSelection(k.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},yl=(r,e)=>{let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ht(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&Gt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function bl(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof S&&e.selection.node.isBlock)return!n.parentOffset||!ht(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let u=n.depth;;u--)if(n.node(u).isBlock){a=n.end(u)==n.pos+(n.depth-u),c=n.start(u)==n.pos-(n.depth-u),l=Un(n.node(u-1).contentMatchAt(n.indexAfter(u-1))),s.unshift(a&&l?{type:l}:null),o=u;break}else{if(u==1)return!1;s.unshift(null)}let f=e.tr;(e.selection instanceof k||e.selection instanceof X)&&f.deleteSelection();let h=f.mapping.map(n.pos),d=ht(f.doc,h,s.length,s);if(d||(s[0]=l?{type:l}:null,d=ht(f.doc,h,s.length,s)),!d)return!1;if(f.split(h,s.length,s),!a&&c&&n.node(o).type!=l){let u=f.mapping.map(n.before(o)),p=f.doc.resolve(u);l&&n.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&f.setNodeMarkup(f.mapping.map(n.before(o)),l)}return t&&t(f.scrollIntoView()),!0}}const xl=bl(),Sl=(r,e)=>(e&&e(r.tr.setSelection(new X(r.doc))),!0);function Cl(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Xt(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function hs(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Cl(r,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=y.empty;for(let b=o.length-1;b>=0;b--)p=y.from(o[b].create(null,p));p=y.from(i.copy(p));let m=r.tr.step(new L(e.pos-1,u,e.pos,u,new x(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Xt(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||n>0&&a?null:C.findFrom(e,1),h=f&&f.$from.blockRange(f.$to),d=h&&Gt(h);if(d!=null&&d>=e.depth)return t&&t(r.tr.lift(h,d).scrollIntoView()),!0;if(c&&Ze(s,"start",!0)&&Ze(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let b=y.empty;for(let O=p.length-1;O>=0;O--)b=y.from(p[O].copy(b));let N=r.tr.step(new L(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new x(b,p.length,0),0,!0));t(N.scrollIntoView())}return!0}}return!1}function ds(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(k.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const kl=ds(-1),wl=ds(1);function Uf(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Yi(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Gf(r,e=null){return function(t,n){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,c)=>{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(r,e)))if(a.type==r)i=!0;else{let f=t.doc.resolve(c),h=f.index();i=f.parent.canReplaceWith(h,h+1,r)}})}if(!i)return!1;if(n){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,r,e)}n(s.scrollIntoView())}return!0}}function Ml(r,e,t,n){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?r.inlineContent&&r.type.allowsMarkType(t):!1;if(r.nodesBetween(s.pos,o.pos,(a,c)=>{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Xf(r,e=null,t){return function(n,i){let{empty:s,$cursor:o,ranges:l}=n.selection;if(s&&!o||!Ml(n.doc,l,r))return!1;if(i)if(o)r.isInSet(n.storedMarks||o.marks())?i(n.tr.removeStoredMark(r)):i(n.tr.addStoredMark(r.create(e)));else{let a,c=n.tr;a=!l.some(f=>n.doc.rangeHasMark(f.$from.pos,f.$to.pos,r));for(let f=0;f<l.length;f++){let{$from:h,$to:d}=l[f];if(!a)c.removeMark(h.pos,d.pos,r);else{let u=h.pos,p=d.pos,m=h.nodeAfter,g=d.nodeBefore,b=m&&m.isText?/^\s*/.exec(m.text)[0].length:0,N=g&&g.isText?/\s*$/.exec(g.text)[0].length:0;u+b<p&&(u+=b,p-=N),c.addMark(u,p,r.create(e))}}i(c.scrollIntoView())}return!0}}function Gn(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}let dn=Gn(as,al,fl),Ar=Gn(as,dl,ul);const he={Enter:Gn(pl,gl,yl,xl),"Mod-Enter":ml,Backspace:dn,"Mod-Backspace":dn,"Shift-Backspace":dn,Delete:Ar,"Mod-Delete":Ar,"Mod-a":Sl},us={"Ctrl-h":he.Backspace,"Alt-Backspace":he["Mod-Backspace"],"Ctrl-d":he.Delete,"Ctrl-Alt-Backspace":he["Mod-Delete"],"Alt-Delete":he["Mod-Delete"],"Alt-d":he["Mod-Delete"],"Ctrl-a":kl,"Ctrl-e":wl};for(let r in he)us[r]=he[r];const Nl=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Yf=Nl?us:he;class De{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Ol(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1,this.inCodeMark=n.inCodeMark!==!1}}function Ol(r){return function(e,t,n,i){let s=r;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-i;l>0&&(s=t[0].slice(o-l,o)+s,n=i)}return e.tr.insertText(s,n,i)}}const _f=(r,e)=>{let t=r.plugins;for(let n=0;n<t.length;n++){let i=t[n],s;if(i.spec.isInputRules&&(s=i.getState(r))){if(e){let o=r.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1};new De(/--$/,"—",{inCodeMark:!1});new De(/\.\.\.$/,"…",{inCodeMark:!1});new De(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1});new De(/"$/,"”",{inCodeMark:!1});new De(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"",{inCodeMark:!1});new De(/'$/,"",{inCodeMark:!1});function Zf(r,e,t=null,n){return new De(r,(i,s,o,l)=>{let a=t instanceof Function?t(s):t,c=i.tr.delete(o,l),f=c.doc.resolve(o),h=f.blockRange(),d=h&&Yi(h,e,a);if(!d)return null;c.wrap(h,d);let u=c.doc.resolve(o-1).nodeBefore;return u&&u.type==e&&Xt(c.doc,o-1)&&(!n||n(s,u))&&c.join(o-1),c})}function Qf(r,e,t=null){return new De(r,(n,i,s,o)=>{let l=n.doc.resolve(s),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?n.tr.delete(s,o).setBlockType(s,s,e,a):null})}const Tl=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Dl=typeof navigator<"u"&&/Win/.test(navigator.platform);function Al(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))n=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Tl?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return n&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function El(r){let e=Object.create(null);for(let t in r)e[Al(t)]=r[t];return e}function un(r,e,t=!0){return e.altKey&&(r="Alt-"+r),e.ctrlKey&&(r="Ctrl-"+r),e.metaKey&&(r="Meta-"+r),t&&e.shiftKey&&(r="Shift-"+r),r}function eh(r){return new Oe({props:{handleKeyDown:Xn(r)}})}function Xn(r){let e=El(r);return function(t,n){let i=co(n),s,o=e[un(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[un(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(Dl&&n.ctrlKey&&n.altKey)&&(s=fo[n.keyCode])&&s!=i){let l=e[un(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const P=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},Qe=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e};let On=null;const fe=function(r,e,t){let n=On||(On=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Rl=function(){On=null},$e=function(r,e,t,n){return t&&(Er(r,e,t,n,-1)||Er(r,e,t,n,1))},Il=/^(img|br|input|textarea|hr)$/i;function Er(r,e,t,n,i){for(var s;;){if(r==t&&e==n)return!0;if(e==(i<0?0:_(r))){let o=r.parentNode;if(!o||o.nodeType!=1||kt(r)||Il.test(r.nodeName)||r.contentEditable=="false")return!1;e=P(r)+(i<0?0:1),r=o}else if(r.nodeType==1){let o=r.childNodes[e+(i<0?-1:0)];if(o.nodeType==1&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else r=o,e=i<0?_(r):0}else return!1}}function _(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function zl(r,e){for(;;){if(r.nodeType==3&&e)return r;if(r.nodeType==1&&e>0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=_(r)}else if(r.parentNode&&!kt(r))e=P(r),r=r.parentNode;else return null}}function Bl(r,e){for(;;){if(r.nodeType==3&&e<r.nodeValue.length)return r;if(r.nodeType==1&&e<r.childNodes.length){if(r.contentEditable=="false")return null;r=r.childNodes[e],e=0}else if(r.parentNode&&!kt(r))e=P(r)+1,r=r.parentNode;else return null}}function Pl(r,e,t){for(let n=e==0,i=e==_(r);n||i;){if(r==t)return!0;let s=P(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==_(r)}}function kt(r){let e;for(let t=r;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==r||e.contentDOM==r)}const Zt=function(r){return r.focusNode&&$e(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Ee(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function vl(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Fl(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(_(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(_(n.startContainer),n.startOffset)}}}const se=typeof navigator<"u"?navigator:null,Rr=typeof document<"u"?document:null,Ae=se&&se.userAgent||"",Tn=/Edge\/(\d+)/.exec(Ae),ps=/MSIE \d/.exec(Ae),Dn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ae),H=!!(ps||Dn||Tn),we=ps?document.documentMode:Dn?+Dn[1]:Tn?+Tn[1]:0,Z=!H&&/gecko\/(\d+)/i.test(Ae);Z&&+(/Firefox\/(\d+)/.exec(Ae)||[0,0])[1];const An=!H&&/Chrome\/(\d+)/.exec(Ae),z=!!An,ms=An?+An[1]:0,F=!H&&!!se&&/Apple Computer/.test(se.vendor),et=F&&(/Mobile\/\w+/.test(Ae)||!!se&&se.maxTouchPoints>2),Y=et||(se?/Mac/.test(se.platform):!1),gs=se?/Win/.test(se.platform):!1,de=/Android \d/.test(Ae),wt=!!Rr&&"webkitFontSmoothing"in Rr.documentElement.style,Vl=wt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ll(r){let e=r.defaultView&&r.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function ae(r,e){return typeof r=="number"?r:r[e]}function $l(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Ir(r,e,t){let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;){if(o.nodeType!=1){o=Qe(o);continue}let l=o,a=l==s.body,c=a?Ll(s):$l(l),f=0,h=0;if(e.top<c.top+ae(n,"top")?h=-(c.top-e.top+ae(i,"top")):e.bottom>c.bottom-ae(n,"bottom")&&(h=e.bottom-e.top>c.bottom-c.top?e.top+ae(i,"top")-c.top:e.bottom-c.bottom+ae(i,"bottom")),e.left<c.left+ae(n,"left")?f=-(c.left-e.left+ae(i,"left")):e.right>c.right-ae(n,"right")&&(f=e.right-c.right+ae(i,"right")),f||h)if(a)s.defaultView.scrollBy(f,h);else{let u=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),f&&(l.scrollLeft+=f);let m=l.scrollLeft-u,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o=d=="absolute"?o.offsetParent:Qe(o)}}function Wl(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=r.root.elementFromPoint(s,o);if(!l||l==r.dom||!r.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:ys(r.dom)}}function ys(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=Qe(n));return e}function Jl({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;bs(t,n==0?0:n-e)}function bs(r,e){for(let t=0;t<r.length;t++){let{dom:n,top:i,left:s}=r[t];n.scrollTop!=i+e&&(n.scrollTop=i+e),n.scrollLeft!=s&&(n.scrollLeft=s)}}let qe=null;function ql(r){if(r.setActive)return r.setActive();if(qe)return r.focus(qe);let e=ys(r);r.focus(qe==null?{get preventScroll(){return qe={preventScroll:!0},!0}}:void 0),qe||(qe=!1,bs(e,0))}function xs(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let f=r.firstChild,h=0;f;f=f.nextSibling,h++){let d;if(f.nodeType==1)d=f.getClientRects();else if(f.nodeType==3)d=fe(f).getClientRects();else continue;for(let u=0;u<d.length;u++){let p=d[u];if(p.top<=o&&p.bottom>=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right<e.left?e.left-p.right:0;if(m<n){t=f,n=m,i=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,f.nodeType==1&&m&&(s=h+(e.left>=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=f,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=h+1)}}return!t&&a&&(t=a,i=c,n=0),t&&t.nodeType==3?Kl(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:xs(t,i)}function Kl(r,e){let t=r.nodeValue.length,n=document.createRange(),i;for(let s=0;s<t;s++){n.setEnd(r,s+1),n.setStart(r,s);let o=me(n,1);if(o.top!=o.bottom&&Yn(e,o)){i={node:r,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),i||{node:r,offset:0}}function Yn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Hl(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<r.getBoundingClientRect().left?t:r}function jl(r,e,t){let{node:n,offset:i}=xs(e,t),s=-1;if(n.nodeType==1&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function Ul(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>n.left||a.top>n.top?i=l.posBefore:(!o&&a.right<n.left||a.bottom<n.top)&&(i=l.posAfter),o=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?n.top<(a.top+a.bottom)/2:n.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return i>-1?i:r.docView.posFromDOM(e,t,-1)}function Ss(r,e,t){let n=r.childNodes.length;if(n&&t.top<t.bottom)for(let i=Math.max(0,Math.min(n-1,Math.floor(n*(e.top-t.top)/(t.bottom-t.top))-2)),s=i;;){let o=r.childNodes[s];if(o.nodeType==1){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Yn(e,c))return Ss(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function Gl(r,e){let t=r.dom.ownerDocument,n,i=0,s=Fl(t,e.left,e.top);s&&({node:n,offset:i}=s);let o=(r.root.elementFromPoint?r.root:t).elementFromPoint(e.left,e.top),l;if(!o||!r.dom.contains(o.nodeType!=1?o.parentNode:o)){let c=r.dom.getBoundingClientRect();if(!Yn(e,c)||(o=Ss(r.dom,e,c),!o))return null}if(F)for(let c=o;n&&c;c=Qe(c))c.draggable&&(n=void 0);if(o=Hl(o,e),n){if(Z&&n.nodeType==1&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let f=n.childNodes[i],h;f.nodeName=="IMG"&&(h=f.getBoundingClientRect()).right<=e.left&&h.bottom>e.top&&i++}let c;wt&&i&&n.nodeType==1&&(c=n.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&n.lastChild.nodeType==1&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||n.nodeType!=1||n.childNodes[i-1].nodeName!="BR")&&(l=Ul(r,n,i,e))}l==null&&(l=jl(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function zr(r){return r.top<r.bottom||r.left<r.right}function me(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(zr(n))return n}return Array.prototype.find.call(t,zr)||r.getBoundingClientRect()}const Xl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Cs(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=wt||Z;if(n.nodeType==3)if(o&&(Xl.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=me(fe(n,i,i),t);if(Z&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=me(fe(n,i-1,i-1),-1);if(c.top==a.top){let f=me(fe(n,i,i+1),-1);if(f.top!=a.top)return it(f,f.left<c.left)}}return a}else{let a=i,c=i,f=t<0?1:-1;return t<0&&!i?(c++,f=-1):t>=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,it(me(fe(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return pn(a.getBoundingClientRect(),!1)}if(s==null&&i<_(n)){let a=n.childNodes[i];if(a.nodeType==1)return pn(a.getBoundingClientRect(),!0)}return pn(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_(n))){let a=n.childNodes[i-1],c=a.nodeType==3?fe(a,_(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return it(me(c,1),!1)}if(s==null&&i<_(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?fe(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return it(me(c,-1),!0)}return it(me(n.nodeType==3?fe(n):n,-t),t>=0)}function it(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function pn(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function ks(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function Yl(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return ks(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Cs(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=fe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let f=a[c];if(f.bottom>f.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}const _l=/[\u0590-\u08ac]/;function Zl(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return l?!_l.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:ks(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=r.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:p,focusOffset:m}=r.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):n.pos==n.start()||n.pos==n.end()}let Br=null,Pr=null,vr=!1;function Ql(r,e,t){return Br==e&&Pr==t?vr:(Br=e,Pr=t,vr=t=="up"||t=="down"?Yl(r,e,t):Zl(r,e,t))}const Q=0,Fr=1,Re=2,oe=3;class Mt{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=Q,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let i=this.children[t];if(i==e)return n;n+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(n<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=t>P(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let i=this.children[t],s=n+i.size;if(n==e&&s!=n){for(;!i.border&&i.children.length;)for(let o=0;o<i.children.length;o++){let l=i.children[o];if(l.size){i=l;break}}return i}if(e<s)return i.descAt(e-n-i.border);n=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,i=0;for(let s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.size;if(l>e||o instanceof Ms){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(let s;n&&!(s=this.children[n-1]).size&&s instanceof ws&&s.side>=0;n--);if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?P(s.dom)+1:0}}else{let s,o=!0;for(;s=n<this.children.length?this.children[n]:null,!(!s||s.dom.parentNode==this.contentDOM);n++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?P(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let f=o+a.border;if(e>=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=P(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;f<this.children.length;f++){let h=this.children[f];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(-1)){s=P(h.dom);break}t+=h.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(t.nodeType!=1||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,i=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let u=0,p=0;u<this.children.length;u++){let m=this.children[u],g=p+m.size;if(s>p&&o<g)return m.setSelection(e-p-m.border,t-p-m.border,n,i);p=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),f=n.domSelectionRange(),h=!1;if((Z||F)&&e==t){let{node:u,offset:p}=l;if(u.nodeType==3){if(h=!!(p&&u.nodeValue[p-1]==`
`),h&&p==u.nodeValue.length)for(let m=u,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:P(g)+1});break}let b=m.pmViewDesc;if(b&&b.node&&b.node.isBlock)break}}else{let m=u.childNodes[p-1];h=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(Z&&f.focusNode&&f.focusNode!=a.node&&f.focusNode.nodeType==1){let u=f.focusNode.childNodes[f.focusOffset];u&&u.contentEditable=="false"&&(i=!0)}if(!(i||h&&F)&&$e(l.node,l.offset,f.anchorNode,f.anchorOffset)&&$e(a.node,a.offset,f.focusNode,f.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(h&&Z)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let p=l;l=a,a=p}let u=document.createRange();u.setEnd(a.node,a.offset),u.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(u)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,i=0;i<this.children.length;i++){let s=this.children[i],o=n+s.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Re:Fr,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=oe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Re:oe}n=o}this.dirty=Re}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Re:Fr;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ws extends Mt{constructor(e,t,n,i){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(n,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Q&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class ea extends Mt{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class We extends Mt{constructor(e,t,n,i,s){super(e,[],n,i),this.mark=t,this.spec=s}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=nt.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new We(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&oe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=oe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Q){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=Q}}slice(e,t,n){let i=We.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=Rn(s,t,o,n)),e>0&&(s=Rn(s,0,e,n));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Me extends Mt{constructor(e,t,n,i,s,o,l,a,c){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=i,this.nodeDOM=l}static create(e,t,n,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=nt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=Ts(f,n,t),c?a=new ta(e,t,n,i,f,h||null,d,c,s,o+1):t.isText?new Qt(e,t,n,i,f,d,s):new Me(e,t,n,i,f,h||null,d,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,n){return this.dirty==Q&&e.eq(this.node)&&Wt(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new ra(this,o&&o.node,e);oa(this.node,this.innerDeco,(c,f,h)=>{c.spec.marks?a.syncToMarks(c.spec.marks,n,e,f):c.type.side>=0&&!h&&a.syncToMarks(f==this.node.childCount?M.none:this.node.child(f).marks,n,e,f),a.placeWidget(c,e,i)},(c,f,h,d)=>{a.syncToMarks(c.marks,n,e,d);let u;a.findNodeMatch(c,f,h,d)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(u=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,f,h,u,e)||a.updateNextNode(c,f,h,e,d,i)||a.addNode(c,f,h,e,i),i+=c.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Re)&&(o&&this.protectLocalComposition(e,o),Ns(this.contentDOM,this.children,e),et&&la(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof k)||n<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=aa(this.node.content,o,n-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new ea(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rn(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==oe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Q}updateOuterDeco(e){if(Wt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Os(this.dom,this.nodeDOM,En(this.outerDeco,this.node,t),En(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Vr(r,e,t,n,i){Ts(n,e,r);let s=new Me(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Qt extends Me{constructor(e,t,n,i,s,o,l){super(e,t,n,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,i){return this.dirty==oe||this.dirty!=Q&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Q||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=Q,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new Qt(this.parent,i,this.outerDeco,this.innerDeco,s,s,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=oe)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Ms extends Mt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Q&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class ta extends Me{constructor(e,t,n,i,s,o,l,a,c,f){super(e,t,n,i,s,o,l,c,f),this.spec=a}update(e,t,n,i){if(this.dirty==oe)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Ns(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==r){for(;l!=n;)n=Lr(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof We){let a=n?n.previousSibling:r.lastChild;Ns(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=Lr(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}const dt=function(r){r&&(this.nodeName=r)};dt.prototype=Object.create(null);const Ie=[new dt];function En(r,e,t){if(r.length==0)return Ie;let n=t?Ie[0]:new dt,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new dt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new dt(e.isInline?"span":"div")),l=="class"?n.class=(n.class?n.class+" ":"")+a:l=="style"?n.style=(n.style?n.style+";":"")+a:l!="nodeName"&&(n[l]=a))}}}return i}function Os(r,e,t,n){if(t==Ie&&n==Ie)return e;let i=e;for(let s=0;s<n.length;s++){let o=n[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&i!=r&&(a=i.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=Ie[0]),i=a}na(i,l||Ie[0],o)}return i}function na(r,e,t){for(let n in e)n!="class"&&n!="style"&&n!="nodeName"&&!(n in t)&&r.removeAttribute(n);for(let n in t)n!="class"&&n!="style"&&n!="nodeName"&&t[n]!=e[n]&&r.setAttribute(n,t[n]);if(e.class!=t.class){let n=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<n.length;s++)i.indexOf(n[s])==-1&&r.classList.remove(n[s]);for(let s=0;s<i.length;s++)n.indexOf(i[s])==-1&&r.classList.add(i[s]);r.classList.length==0&&r.removeAttribute("class")}if(e.style!=t.style){if(e.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=n.exec(e.style);)r.style.removeProperty(i[1])}t.style&&(r.style.cssText+=t.style)}}function Ts(r,e,t){return Os(r,r,Ie,En(e,t,r.nodeType!=1))}function Wt(r,e){if(r.length!=e.length)return!1;for(let t=0;t<r.length;t++)if(!r[t].type.eq(e[t].type))return!1;return!0}function Lr(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}class ra{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=ia(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,i){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=Q,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let f=this.index;f<c;f++){let h=this.top.children[f];if(h.matchesMark(e[o])&&!this.isLocked(h.dom)){a=f;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let f=We.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,f),this.top=f,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,n)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,i,s){let o=this.top.children[i];return o.dirty==oe&&o.dom==o.contentDOM&&(o.dirty=Re),o.update(e,t,n,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let n=e.pmViewDesc;if(n){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==n)return i}return-1}e=t}}updateNextNode(e,t,n,i,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Me){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let f=a.dom,h,d=this.isLocked(f)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=oe&&Wt(t,a.outerDeco));if(!d&&a.update(e,t,n,i))return this.destroyBetween(this.index,l),a.dom!=f&&(this.changed=!0),this.index++,!0;if(!d&&(h=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=h,h.contentDOM&&(h.dirty=Re,h.updateChildren(i,o+1),h.dirty=Q),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,i,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Wt(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Me.create(this.top,t,n,i,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,n,i,s){let o=Me.create(this.top,e,t,n,i,s);o.contentDOM&&o.updateChildren(i,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new ws(this.top,e,t,n);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof We;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Qt)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((F||z)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e=="IMG"&&(n.className="ProseMirror-separator",n.alt=""),e=="BR"&&(n.className="ProseMirror-trailingBreak");let i=new Ms(this.top,[],n,null);t!=this.top?t.children.push(i):t.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function ia(r,e){let t=e,n=t.children.length,i=r.childCount,s=new Map,o=[];e:for(;i>0;){let l;for(;;)if(n){let c=t.children[n-1];if(c instanceof We)t=c,n=c.children.length;else{l=c,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function sa(r,e){return r.type.side-e.type.side}function oa(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let f=r.child(c);n(f,i,e.forChild(s,f),c),s+=f.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let f,h;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(f?(h||(h=[f])).push(g):f=g)}if(f)if(h){h.sort(sa);for(let g=0;g<h.length;g++)t(h[g],c,!!a)}else t(f,c,!!a);let d,u;if(a)u=-1,d=a,a=null;else if(c<r.childCount)u=c,d=r.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o<i.length&&i[o].from<g&&(g=i[o].from);for(let b=0;b<l.length;b++)l[b].to<g&&(g=l[b].to);g<p&&(a=d.cut(g-s),d=d.cut(0,g-s),p=g,u=-1)}else for(;o<i.length&&i[o].to<p;)o++;let m=d.isInline&&!d.isLeaf?l.filter(g=>!g.inline):l.slice();n(d,m,e.forChild(s,d),u),s=p}}function la(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function aa(r,e,t,n){for(let i=0,s=0;i<r.childCount&&s<=n;){let o=r.child(i++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;i<r.childCount;){let c=r.child(i++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let c=l<n?a.lastIndexOf(e,n-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function Rn(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,f=l+=a.size;c>=t||f<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),f>t&&s.push(a.slice(t-c,a.size,n)))}return s}function _n(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,c;if(Zt(t)){for(a=o;i&&!i.node;)i=i.parent;let h=i.node;if(i&&h.isAtom&&S.isSelectable(h)&&i.parent&&!(h.isInline&&Pl(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new S(o==d?l:n.resolve(d))}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let h=o,d=o;for(let u=0;u<t.rangeCount;u++){let p=t.getRangeAt(u);h=Math.min(h,r.docView.posFromDOM(p.startContainer,p.startOffset,1)),d=Math.max(d,r.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(h<0)return null;[a,o]=d==r.state.selection.anchor?[d,h]:[h,d],l=n.resolve(o)}else a=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let f=n.resolve(a);if(!c){let h=e=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=Zn(r,f,l,h)}return c}function Ds(r){return r.editable?r.hasFocus():Es(r)&&document.activeElement&&document.activeElement.contains(r.dom)}function ue(r,e=!1){let t=r.state.selection;if(As(r,t),!!Ds(r)){if(!e&&r.input.mouseDown&&r.input.mouseDown.allowDefault&&z){let n=r.domSelectionRange(),i=r.domObserver.currentSelection;if(n.anchorNode&&i.anchorNode&&$e(n.anchorNode,n.anchorOffset,i.anchorNode,i.anchorOffset)){r.input.mouseDown.delayedSelectionSync=!0,r.domObserver.setCurSelection();return}}if(r.domObserver.disconnectSelection(),r.cursorWrapper)fa(r);else{let{anchor:n,head:i}=t,s,o;$r&&!(t instanceof k)&&(t.$from.parent.inlineContent||(s=Wr(r,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Wr(r,t.to))),r.docView.setSelection(n,i,r,e),$r&&(s&&Jr(s),o&&Jr(o)),t.visible?r.dom.classList.remove("ProseMirror-hideselection"):(r.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&ca(r))}r.domObserver.setCurSelection(),r.domObserver.connectSelection()}}const $r=F||z&&ms<63;function Wr(r,e){let{node:t,offset:n}=r.docView.domFromPos(e,0),i=n<t.childNodes.length?t.childNodes[n]:null,s=n?t.childNodes[n-1]:null;if(F&&i&&i.contentEditable=="false")return mn(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return mn(i);if(s)return mn(s)}}function mn(r){return r.contentEditable="true",F&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function Jr(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function ca(r){let e=r.dom.ownerDocument;e.removeEventListener("selectionchange",r.input.hideSelectionGuard);let t=r.domSelectionRange(),n=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!Ds(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function fa(r){let e=r.domSelection();if(!e)return;let t=r.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,P(t)+1):e.collapse(t,0),!n&&!r.state.selection.visible&&H&&we<=11&&(t.disabled=!0,t.disabled=!1)}function As(r,e){if(e instanceof S){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(qr(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else qr(r)}function qr(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Zn(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||k.between(e,t,n)}function Kr(r){return r.editable&&!r.hasFocus()?!1:Es(r)}function Es(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return r.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(r.editable||r.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function ha(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return $e(e.node,e.offset,t.anchorNode,t.anchorOffset)}function In(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&C.findFrom(s,e)}function ge(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Hr(r,e,t){let n=r.state.selection;if(n instanceof k)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return ge(r,new k(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=In(r.state,e);return i&&i instanceof S?ge(r,i):!1}else if(!(Y&&t.indexOf("m")>-1)){let i=n.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=r.docView.descAt(l))&&!o.contentDOM?S.isSelectable(s)?ge(r,new S(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):wt?ge(r,new k(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof S&&n.node.isInline)return ge(r,new k(e>0?n.$to:n.$from));{let i=In(r.state,e);return i?ge(r,i):!1}}}function Jt(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function ut(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function Ke(r,e){return e<0?da(r):ua(r)}function da(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(Z&&t.nodeType==1&&n<Jt(t)&&ut(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(ut(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(Rs(t))break;{let l=t.previousSibling;for(;l&&ut(l,-1);)i=t.parentNode,s=P(l),l=l.previousSibling;if(l)t=l,n=Jt(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?zn(r,t,n):i&&zn(r,i,s)}function ua(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=Jt(t),s,o;for(;;)if(n<i){if(t.nodeType!=1)break;let l=t.childNodes[n];if(ut(l,1))s=t,o=++n;else break}else{if(Rs(t))break;{let l=t.nextSibling;for(;l&&ut(l,1);)s=l.parentNode,o=P(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=Jt(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&zn(r,s,o)}function Rs(r){let e=r.pmViewDesc;return e&&e.node&&e.node.isBlock}function pa(r,e){for(;r&&e==r.childNodes.length&&!kt(r);)e=P(r)+1,r=r.parentNode;for(;r&&e<r.childNodes.length;){let t=r.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;r=t,e=0}}function ma(r,e){for(;r&&!e&&!kt(r);)e=P(r),r=r.parentNode;for(;r&&e;){let t=r.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;r=t,e=r.childNodes.length}}function zn(r,e,t){if(e.nodeType!=3){let s,o;(o=pa(e,t))?(e=o,t=0):(s=ma(e,t))&&(e=s,t=s.nodeValue.length)}let n=r.domSelection();if(!n)return;if(Zt(n)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),n.removeAllRanges(),n.addRange(s)}else n.extend&&n.extend(e,t);r.domObserver.setCurSelection();let{state:i}=r;setTimeout(()=>{r.state==i&&ue(r)},50)}function jr(r,e){let t=r.state.doc.resolve(e);if(!(z||gs)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left<i.left?"ltr":"rtl"}if(e<t.end()){let s=r.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(r.dom).direction=="rtl"?"rtl":"ltr"}function Ur(r,e,t){let n=r.state.selection;if(n instanceof k&&!n.empty||t.indexOf("s")>-1||Y&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=In(r.state,e);if(o&&o instanceof S)return ge(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof X?C.near(o,e):C.findFrom(o,e);return l?ge(r,l):!1}return!1}function Gr(r,e){if(!(r.state.selection instanceof k))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function Xr(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function ga(r){if(!F||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let n=e.firstChild;Xr(r,n,"true"),setTimeout(()=>Xr(r,n,"false"),20)}return!1}function ya(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function ba(r,e){let t=e.keyCode,n=ya(e);if(t==8||Y&&t==72&&n=="c")return Gr(r,-1)||Ke(r,-1);if(t==46&&!e.shiftKey||Y&&t==68&&n=="c")return Gr(r,1)||Ke(r,1);if(t==13||t==27)return!0;if(t==37||Y&&t==66&&n=="c"){let i=t==37?jr(r,r.state.selection.from)=="ltr"?-1:1:-1;return Hr(r,i,n)||Ke(r,i)}else if(t==39||Y&&t==70&&n=="c"){let i=t==39?jr(r,r.state.selection.from)=="ltr"?1:-1:1;return Hr(r,i,n)||Ke(r,i)}else{if(t==38||Y&&t==80&&n=="c")return Ur(r,-1,n)||Ke(r,-1);if(t==40||Y&&t==78&&n=="c")return ga(r)||Ur(r,1,n)||Ke(r,1);if(n==(Y?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Qn(r,e){r.someProp("transformCopied",u=>{e=u(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let u=n.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),n=u.content}let o=r.someProp("clipboardSerializer")||nt.fromSchema(r.state.schema),l=Fs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,h=0;for(;c&&c.nodeType==1&&(f=vs[c.nodeName.toLowerCase()]);){for(let u=f.length-1;u>=0;u--){let p=l.createElement(f[u]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),h++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=r.someProp("clipboardTextSerializer",u=>u(e,r))||e.content.textBetween(0,e.content.size,`
`);return{dom:a,text:d,slice:e}}function Is(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",d=>{e=d(e,s||n,r)}),s)return l=new x(y.from(r.state.schema.text(e.replace(/\r\n?/g,`
`))),0,0),r.someProp("transformPasted",d=>{l=d(l,r,!0)}),l;let h=r.someProp("clipboardTextParser",d=>d(e,i,n,r));if(h)l=h;else{let d=i.marks(),{schema:u}=r.state,p=nt.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,d)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=ka(t),wt&&wa(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||mt.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!xa.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Ma(Yr(l,+f[1],+f[2]),f[4]);else if(l=x.maxOpen(Sa(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let u=l.content.firstChild;h<l.openStart&&!u.type.spec.isolating;h++,u=u.firstChild);for(let u=l.content.lastChild;d<l.openEnd&&!u.type.spec.isolating;d++,u=u.lastChild);l=Yr(l,h,d)}return r.someProp("transformPasted",h=>{l=h(l,r,a)}),l}const xa=/^(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 Sa(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&Bs(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Ps(o[o.length-1],s.length));let f=zs(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return y.from(o)}return r}function zs(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,y.from(r));return r}function Bs(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=Bs(r,e,t,n.lastChild,i+1);if(s)return n.copy(n.content.replaceChild(n.childCount-1,s));if(n.contentMatchAt(n.childCount).matchType(i==r.length-1?t.type:r[i+1]))return n.copy(n.content.append(y.from(zs(t,r,i+1))))}}function Ps(r,e){if(e==0)return r;let t=r.content.replaceChild(r.childCount-1,Ps(r.lastChild,e-1)),n=r.contentMatchAt(r.childCount).fillBefore(y.empty,!0);return r.copy(t.append(n))}function Bn(r,e,t,n,i,s){let o=e<0?r.firstChild:r.lastChild,l=o.content;return r.childCount>1&&(s=0),i<n-1&&(l=Bn(l,e,t,n,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(y.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function Yr(r,e,t){return e<r.openStart&&(r=new x(Bn(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new x(Bn(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}const vs={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let _r=null;function Fs(){return _r||(_r=document.implementation.createHTMLDocument("title"))}let gn=null;function Ca(r){let e=window.trustedTypes;return e?(gn||(gn=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),gn.createHTML(r)):r}function ka(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=Fs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&vs[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=Ca(r),i)for(let s=0;s<i.length;s++)t=t.querySelector(i[s])||t;return t}function wa(r){let e=r.querySelectorAll(z?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let n=e[t];n.childNodes.length==1&&n.textContent==" "&&n.parentNode&&n.parentNode.replaceChild(r.ownerDocument.createTextNode(" "),n)}}function Ma(r,e){if(!r.size)return r;let t=r.content.firstChild.type.schema,n;try{n=JSON.parse(e)}catch{return r}let{content:i,openStart:s,openEnd:o}=r;for(let l=n.length-2;l>=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(n[l+1],i)),s++,o++}return new x(i,s,o)}const J={},q={},Na={touchstart:!0,touchmove:!0};class Oa{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Ta(r){for(let e in J){let t=J[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Aa(r,n)&&!er(r,n)&&(r.editable||!(n.type in q))&&t(r,n)},Na[e]?{passive:!0}:void 0)}F&&r.dom.addEventListener("input",()=>null),Pn(r)}function ke(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Da(r){r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function Pn(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>er(r,n))})}function er(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Aa(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Ea(r,e){!er(r,e)&&J[e.type]&&(r.editable||!(e.type in q))&&J[e.type](r,e)}q.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Ls(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(de&&z&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),et&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ee(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||ba(r,t)?t.preventDefault():ke(r,"key")};q.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};q.keypress=(r,e)=>{let t=e;if(Ls(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||Y&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof k)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode),s=()=>r.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",o=>o(r,n.$from.pos,n.$to.pos,i,s))&&r.dispatch(s()),t.preventDefault()}};function en(r){return{left:r.clientX,top:r.clientY}}function Ra(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function tr(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Ye(r,e,t){if(r.focused||r.focus(),r.state.selection.eq(e))return;let n=r.state.tr.setSelection(e);n.setMeta("pointer",!0),r.dispatch(n)}function Ia(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&S.isSelectable(n)?(Ye(r,new S(t)),!0):!1}function za(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof S&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){n&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(Ye(r,S.create(r.state.doc,i)),!0):!1}function Ba(r,e,t,n,i){return tr(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?za(r,t):Ia(r,t))}function Pa(r,e,t,n){return tr(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function va(r,e,t,n){return tr(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Fa(r,t,n)}function Fa(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(Ye(r,k.create(n,0,n.content.size)),!0):!1;let i=n.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)Ye(r,k.create(n,l+1,l+1+o.content.size));else if(S.isSelectable(o))Ye(r,S.create(n,l));else continue;return!0}}function nr(r){return qt(r)}const Vs=Y?"metaKey":"ctrlKey";J.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=nr(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Ra(t,r.input.lastClick)&&!t[Vs]&&r.input.lastClick.button==t.button&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button};let o=r.posAtCoords(en(t));o&&(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new Va(r,o,t,!!n)):(s=="doubleClick"?Pa:va)(r,o.pos,o.inside,t)?t.preventDefault():ke(r,"pointer"))};class Va{constructor(e,t,n,i){this.view=e,this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Vs],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}const l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof S&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Z&&!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)),ke(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(()=>ue(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(en(e))),this.updateAllowDefault(e),this.allowDefault||!t?ke(this.view,"pointer"):Ba(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||F&&this.mightDrag&&!this.mightDrag.node.isAtom||z&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Ye(this.view,C.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ke(this.view,"pointer")}move(e){this.updateAllowDefault(e),ke(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)}}J.touchstart=r=>{r.input.lastTouch=Date.now(),nr(r),ke(r,"pointer")};J.touchmove=r=>{r.input.lastTouch=Date.now(),ke(r,"pointer")};J.contextmenu=r=>nr(r);function Ls(r,e){return r.composing?!0:F&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const La=de?5e3:-1;q.compositionstart=q.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof k&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||z&&gs&&$a(r)))r.markCursor=r.state.storedMarks||t.marks(),qt(r,!0),r.markCursor=null;else if(qt(r,!e.selection.empty),Z&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=r.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}$s(r,La)};function $a(r){let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return n.nodeType==1&&n.contentEditable=="false"}q.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=e.timeStamp,r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionNode=null,r.input.badSafariComposition?r.domObserver.forceFlush():r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,$s(r,20))};function $s(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>qt(r),e))}function Ws(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Ja());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Wa(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=zl(e.focusNode,e.focusOffset),n=Bl(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let i=n.pmViewDesc,s=r.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!i||!i.isText(n.nodeValue))return n;if(r.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function Ja(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function qt(r,e=!1){if(!(de&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Ws(r),e||r.docView&&r.docView.dirty){let t=_n(r),n=r.state.selection;return t&&!t.eq(n)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function qa(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}const xt=H&&we<15||et&&Vl<604;J.copy=q.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=xt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Qn(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):qa(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Ka(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function Ha(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?St(r,n.value,null,i,e):St(r,n.textContent,n.innerHTML,i,e)},50)}function St(r,e,t,n,i){let s=Is(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||x.empty)))return!0;if(!s)return!1;let o=Ka(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Js(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}q.paste=(r,e)=>{let t=e;if(r.composing&&!de)return;let n=xt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&St(r,Js(n),n.getData("text/html"),i,t)?t.preventDefault():Ha(r,t)};class qs{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const ja=Y?"altKey":"ctrlKey";function Ks(r,e){let t=r.someProp("dragCopies",n=>!n(e));return t??!e[ja]}J.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(en(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(n&&n.mightDrag)o=S.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let h=r.docView.nearestDesc(t.target,!0);h&&h.node.type.spec.draggable&&h!=r.docView&&(o=S.create(r.state.doc,h.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=Qn(r,l);(!t.dataTransfer.files.length||!z||ms>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(xt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",xt||t.dataTransfer.setData("text/plain",c),r.dragging=new qs(f,Ks(r,t),o)};J.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};q.dragover=q.dragenter=(r,e)=>e.preventDefault();q.drop=(r,e)=>{try{Ua(r,e,r.dragging)}finally{r.dragging=null}};function Ua(r,e,t){if(!e.dataTransfer)return;let n=r.posAtCoords(en(e));if(!n)return;let i=r.state.doc.resolve(n.pos),s=t&&t.slice;s?r.someProp("transformPasted",u=>{s=u(s,r,!1)}):s=Is(r,Js(e.dataTransfer),xt?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Ks(r,e));if(r.someProp("handleDrop",u=>u(r,e,s||x.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Zo(r.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=r.state.tr;if(o){let{node:u}=t;u?u.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(h))return;let d=a.doc.resolve(c);if(f&&S.isSelectable(s.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new S(d));else{let u=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,b)=>u=b),a.setSelection(Zn(r,d,a.doc.resolve(u)))}r.focus(),r.dispatch(a.setMeta("uiEvent","drop"))}J.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&ue(r)},20))};J.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};J.beforeinput=(r,e)=>{if(z&&de&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ee(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in q)J[r]=q[r];function Ct(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}class Kt{constructor(e,t){this.toDOM=e,this.spec=t||Pe,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new v(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Kt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Ct(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Ne{constructor(e,t){this.attrs=e,this.spec=t||Pe}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new v(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Ne&&Ct(this.attrs,e.attrs)&&Ct(this.spec,e.spec)}static is(e){return e.type instanceof Ne}destroy(){}}class rr{constructor(e,t){this.attrs=e,this.spec=t||Pe}map(e,t,n,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new v(s.pos-n,o.pos-n,this)}valid(e,t){let{index:n,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(n)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof rr&&Ct(this.attrs,e.attrs)&&Ct(this.spec,e.spec)}destroy(){}}class v{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new v(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new v(e,e,new Kt(t,n))}static inline(e,t,n,i){return new v(e,t,new Ne(n,i))}static node(e,t,n,i){return new v(e,t,new rr(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ne}get widget(){return this.type instanceof Kt}}const je=[],Pe={};class D{constructor(e,t){this.local=e.length?e:je,this.children=t.length?t:je}static create(e,t){return t.length?Ht(t,e,0,Pe):V}find(e,t,n){let i=[];return this.findInner(e??0,t??1e9,i,0,n),i}findInner(e,t,n,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&n.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,n,i+l,s)}}map(e,t,n){return this==V||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Pe)}mapInner(e,t,n,i,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,n,i);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?Ga(this.children,o||[],e,t,n,i,s):o?new D(o.sort(ve),je):V}add(e,t){return t.length?this==V?D.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let i,s=0;e.forEach((l,a)=>{let c=a+n,f;if(f=js(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,f,c+1):i.splice(s,0,a,a+l.nodeSize,Ht(f,l,c+1,Pe)),s+=3}});let o=Hs(s?Us(t):t,-n);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new D(o.length?this.local.concat(o).sort(ve):this.local,i||this.children)}remove(e){return e.length==0||this==V?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,i=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let f=0,h;f<e.length;f++)(h=e[f])&&h.from>l&&h.to<a&&(e[f]=null,(o||(o=[])).push(h));if(!o)continue;n==this.children&&(n=this.children.slice());let c=n[s+2].removeInner(o,l+1);c!=V?n[s+2]=c:(n.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return n==this.children&&i==this.local?this:i.length||n.length?new D(i,n):V}forChild(e,t){if(this==V)return this;if(t.isLeaf)return D.empty;let n,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Ne){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;c<f&&(i||(i=[])).push(a.copy(c,f))}}if(i){let l=new D(i.sort(ve),je);return n?new be([l,n]):l}return n||V}eq(e){if(this==e)return!0;if(!(e instanceof D)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return ir(this.localsInner(e))}localsInner(e){if(this==V)return je;if(e.inlineContent||!this.local.some(Ne.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Ne||t.push(this.local[n]);return t}forEachSet(e){e(this)}}D.empty=new D([],[]);D.removeOverlap=ir;const V=D.empty;class be{constructor(e){this.members=e}map(e,t){const n=this.members.map(i=>i.map(e,t,Pe));return be.from(n)}forChild(e,t){if(t.isLeaf)return D.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=V&&(s instanceof be?n=n.concat(s.members):n.push(s))}return be.from(n)}eq(e){if(!(e instanceof be)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{n&&(t=t.slice(),n=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?ir(n?t:t.sort(ve)):je}static from(e){switch(e.length){case 0:return V;case 1:return e[0];default:return new be(e.every(t=>t instanceof D)?e:e.reduce((t,n)=>t.concat(n instanceof D?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Ga(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,f=s;c<t.maps.length;c++){let h=0;t.maps[c].forEach((d,u,p,m)=>{let g=m-p-(u-d);for(let b=0;b<l.length;b+=3){let N=l[b+1];if(N<0||d>N+f-h)continue;let O=l[b]+f-h;u>=O?l[b+1]=d<=O?-2:-1:d>=f&&g&&(l[b]+=g,l[b+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let f=t.map(r[c]+s),h=f-i;if(h<0||h>=n.content.size){a=!0;continue}let d=t.map(r[c+1]+s,-1),u=d-i,{index:p,offset:m}=n.content.findIndex(h),g=n.maybeChild(p);if(g&&m==h&&m+g.nodeSize==u){let b=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);b!=V?(l[c]=h,l[c+1]=u,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Xa(l,r,e,t,i,s,o),f=Ht(c,n,0,o);e=f.local;for(let h=0;h<l.length;h+=3)l[h+1]<0&&(l.splice(h,3),h-=3);for(let h=0,d=0;h<f.children.length;h+=3){let u=f.children[h];for(;d<l.length&&l[d]<u;)d+=3;l.splice(d,0,f.children[h],f.children[h+1],f.children[h+2])}}return new D(e.sort(ve),l)}function Hs(r,e){if(!e||!r.length)return r;let t=[];for(let n=0;n<r.length;n++){let i=r[n];t.push(new v(i.from+e,i.to+e,i.type))}return t}function Xa(r,e,t,n,i,s,o){function l(a,c){for(let f=0;f<a.local.length;f++){let h=a.local[f].map(n,i,c);h?t.push(h):o.onRemove&&o.onRemove(a.local[f].spec)}for(let f=0;f<a.children.length;f+=3)l(a.children[f+2],a.children[f]+c+1)}for(let a=0;a<r.length;a+=3)r[a+1]==-1&&l(r[a+2],e[a]+s+1);return t}function js(r,e,t){if(e.isLeaf)return null;let n=t+e.nodeSize,i=null;for(let s=0,o;s<r.length;s++)(o=r[s])&&o.from>t&&o.to<n&&((i||(i=[])).push(o),r[s]=null);return i}function Us(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function Ht(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=js(r,l,a+t);if(c){s=!0;let f=Ht(c,l,t+a+1,n);f!=V&&i.push(a,a+l.nodeSize,f)}});let o=Hs(s?Us(r):r,-t).sort(ve);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(n.onRemove&&n.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new D(o,i):V}function ve(r,e){return r.from-e.from||r.to-e.to}function ir(r){let e=r;for(let t=0;t<e.length-1;t++){let n=e[t];if(n.from!=n.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==n.from){s.to!=n.to&&(e==r&&(e=r.slice()),e[i]=s.copy(s.from,n.to),Zr(e,i+1,s.copy(n.to,s.to)));continue}else{s.from<n.to&&(e==r&&(e=r.slice()),e[t]=n.copy(n.from,s.from),Zr(e,i,n.copy(s.from,n.to)));break}}}return e}function Zr(r,e,t){for(;e<r.length&&ve(t,r[e])>0;)e++;r.splice(e,0,t)}function yn(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=V&&e.push(n)}),r.cursorWrapper&&e.push(D.create(r.state.doc,[r.cursorWrapper.deco])),be.from(e)}const Ya={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},_a=H&&we<=11;class Za{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 Qa{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Za,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;i<n.length;i++)this.queue.push(n[i]);H&&we<=11&&n.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():F&&e.composing&&n.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),_a&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ya)),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;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.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(Kr(this.view)){if(this.suppressingSelectionUpdates)return ue(this.view);if(H&&we<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&$e(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=Qe(s))t.add(s);for(let s=e.anchorNode;s;s=Qe(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.ignoreMutation({type:"selection",target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Kr(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;f<t.length;f++){let h=this.registerMutation(t[f],a);h&&(s=s<0?h.from:Math.min(h.from,s),o=o<0?h.to:Math.max(h.to,o),h.typeOver&&(l=!0))}if(Z&&a.length){let f=a.filter(h=>h.nodeName=="BR");if(f.length==2){let[h,d]=f;h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}else{let{focusNode:h}=this.currentSelection;for(let d of f){let u=d.parentNode;u&&u.nodeName=="LI"&&(!h||nc(e,h)!=u)&&d.remove()}}}else if((z||F)&&a.some(f=>f.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let f of a)if(f.nodeName=="BR"&&f.parentNode){let h=f.nextSibling;h&&h.nodeType==1&&h.contentEditable=="false"&&f.parentNode.removeChild(f)}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Zt(n)&&(c=_n(e))&&c.eq(C.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ue(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),ec(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,rc(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ue(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;f<e.addedNodes.length;f++){let h=e.addedNodes[f];t.push(h),h.nodeType==3&&(this.lastChangedTextNode=h)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let i=e.previousSibling,s=e.nextSibling;if(H&&we<=11&&e.addedNodes.length)for(let f=0;f<e.addedNodes.length;f++){let{previousSibling:h,nextSibling:d}=e.addedNodes[f];(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(i=h),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(s=d)}let o=i&&i.parentNode==e.target?P(i)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?P(s):e.target.childNodes.length,c=n.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Qr=new WeakMap,ei=!1;function ec(r){if(!Qr.has(r)&&(Qr.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=Z,ei)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),ei=!0}}function ti(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return $e(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:i,focusOffset:s}}function tc(r,e){if(e.getComposedRanges){let i=e.getComposedRanges(r.root)[0];if(i)return ti(r,i)}let t;function n(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return r.dom.addEventListener("beforeinput",n,!0),document.execCommand("indent"),r.dom.removeEventListener("beforeinput",n,!0),t?ti(r,t):null}function nc(r,e){for(let t=e.parentNode;t&&t!=r.dom;t=t.parentNode){let n=r.docView.nearestDesc(t,!0);if(n&&n.node.isBlock)return t}return null}function rc(r,e){var t;let{focusNode:n,focusOffset:i}=r.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&r.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}function ic(r,e,t){let{node:n,fromOffset:i,toOffset:s,from:o,to:l}=r.docView.parseRange(e,t),a=r.domSelectionRange(),c,f=a.anchorNode;if(f&&r.dom.contains(f.nodeType==1?f:f.parentNode)&&(c=[{node:f,offset:a.anchorOffset}],Zt(a)||c.push({node:a.focusNode,offset:a.focusOffset})),z&&r.input.lastKeyCode===8)for(let g=s;g>i;g--){let b=n.childNodes[g-1],N=b.pmViewDesc;if(b.nodeName=="BR"&&!N){s=g;break}if(!N||N.size)break}let h=r.state.doc,d=r.someProp("domParser")||mt.fromSchema(r.state.schema),u=h.resolve(o),p=null,m=d.parse(n,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:sc,context:u});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),p={anchor:g+o,head:b+o}}return{doc:m,sel:p,from:o,to:l}}function sc(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(F&&/^(ul|ol)$/i.test(r.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(r.parentNode.lastChild==r||F&&/^(tr|table)$/i.test(r.parentNode.nodeName))return{ignore:!0}}else if(r.nodeName=="IMG"&&r.getAttribute("mark-placeholder"))return{ignore:!0};return null}const oc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lc(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let w=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,A=_n(r,w);if(A&&!r.state.selection.eq(A)){if(z&&de&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&r.someProp("handleKeyDown",lo=>lo(r,Ee(13,"Enter"))))return;let K=r.state.tr.setSelection(A);w=="pointer"?K.setMeta("pointer",!0):w=="key"&&K.scrollIntoView(),s&&K.setMeta("composition",s),r.dispatch(K)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,c=ic(r,e,t),f=r.state.doc,h=f.slice(c.from,c.to),d,u;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(d=r.state.selection.to,u="end"):(d=r.state.selection.from,u="start"),r.input.lastKeyCode=null;let p=fc(h.content,c.doc.content,c.from,d,u);if(p&&r.input.domChangeCount++,(et&&r.input.lastIOSEnter>Date.now()-225||de)&&i.some(w=>w.nodeType==1&&!oc.test(w.nodeName))&&(!p||p.endA>=p.endB)&&r.someProp("handleKeyDown",w=>w(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof k&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let w=ni(r,r.state.doc,c.sel);if(w&&!w.eq(r.state.selection)){let A=r.state.tr.setSelection(w);s&&A.setMeta("composition",s),r.dispatch(A)}}return}r.state.selection.from<r.state.selection.to&&p.start==p.endB&&r.state.selection instanceof k&&(p.start>r.state.selection.from&&p.start<=r.state.selection.from+2&&r.state.selection.from>=c.from?p.start=r.state.selection.from:p.endA<r.state.selection.to&&p.endA>=r.state.selection.to-2&&r.state.selection.to<=c.to&&(p.endB+=r.state.selection.to-p.endA,p.endA=r.state.selection.to)),H&&we<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)=="  "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),b=f.resolve(p.start),N=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=p.endA;if((et&&r.input.lastIOSEnter>Date.now()-225&&(!N||i.some(w=>w.nodeName=="DIV"||w.nodeName=="P"))||!N&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(c.doc.textBetween(m.pos,g.pos,"","")))&&r.someProp("handleKeyDown",w=>w(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>p.start&&cc(f,p.start,p.endA,m,g)&&r.someProp("handleKeyDown",w=>w(r,Ee(8,"Backspace")))){de&&z&&r.domObserver.suppressSelectionUpdates();return}z&&p.endB==p.start&&(r.input.lastChromeDelete=Date.now()),de&&!N&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(w){return w(r,Ee(13,"Enter"))})},20));let O=p.start,W=p.endA,j=w=>{let A=w||r.state.tr.replace(O,W,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let K=ni(r,A.doc,c.sel);K&&!(z&&r.composing&&K.empty&&(p.start!=p.endB||r.input.lastChromeDelete<Date.now()-100)&&(K.head==O||K.head==A.mapping.map(W)-1)||H&&K.empty&&K.head==O)&&A.setSelection(K)}return s&&A.setMeta("composition",s),A.scrollIntoView()},le;if(N)if(m.pos==g.pos){H&&we<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>ue(r),20));let w=j(r.state.tr.delete(O,W)),A=f.resolve(p.start).marksAcross(f.resolve(p.endA));A&&w.ensureMarks(A),r.dispatch(w)}else if(p.endA==p.endB&&(le=ac(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,p.endA-b.start())))){let w=j(r.state.tr);le.type=="add"?w.addMark(O,W,le.mark):w.removeMark(O,W,le.mark),r.dispatch(w)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let w=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>j(r.state.tr.insertText(w,O,W));r.someProp("handleTextInput",K=>K(r,O,W,w,A))||r.dispatch(A())}else r.dispatch(j());else r.dispatch(j())}function ni(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Zn(r,e.resolve(t.anchor),e.resolve(t.head))}function ac(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let f=0;f<n.length;f++)i=n[f].removeFromSet(i);for(let f=0;f<t.length;f++)s=t[f].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=f=>f.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;f<e.childCount;f++)c.push(a(e.child(f)));if(y.from(c).eq(r))return{mark:l,type:o}}function cc(r,e,t,n,i){if(t-e<=i.pos-n.pos||bn(n,!0,!1)<i.pos)return!1;let s=r.resolve(e);if(!n.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=r.resolve(bn(s,!0,!0));return!o.parent.isTextblock||o.pos>t||bn(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function bn(r,e,t){let n=r.depth,i=e?r.end():r.pos;for(;n>0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function fc(r,e,t,n,i){let s=r.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=r.findDiffEnd(e,t+r.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));n-=o+a-s}if(o<s&&r.size<e.size){let a=n<=s&&n>=o?s-n:0;s-=a,s&&s<e.size&&ri(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-o),o=s}else if(l<s){let a=n<=s&&n>=l?s-n:0;s-=a,s&&s<r.size&&ri(r.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function ri(r){if(r.length!=2)return!1;let e=r.charCodeAt(0),t=r.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class hc{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 Oa,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ai),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=oi(this),si(this),this.nodeViews=li(this),this.docView=Vr(this.state.doc,ii(this),yn(this),this.dom,this),this.domObserver=new Qa(this,(n,i,s,o)=>lc(this,n,i,s,o)),this.domObserver.start(),Ta(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&&Pn(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ai),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Ws(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=li(this);uc(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Pn(this),this.editable=oi(this),si(this);let a=yn(this),c=ii(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(o=!0);let d=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Wl(this);if(o){this.domObserver.stop();let u=h&&(H||z)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&dc(i.selection,e.selection);if(h){let p=z?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Wa(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Vr(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ha(this))?ue(this,u):(As(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((n=this.dragging)===null||n===void 0)&&n.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&Jl(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof S){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ir(this,t.getBoundingClientRect(),e)}else Ir(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;t<this.directPlugins.length;t++){let n=this.directPlugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let n=this.state.plugins[t];n.spec.view&&this.pluginViews.push(n.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,i=-1;if(this.state.doc.nodeAt(n.from)==n.node)i=n.from;else{let s=n.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new qs(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(H){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&ql(this.dom),ue(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Gl(this,e)}coordsAtPos(e,t=1){return Cs(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Ql(this,t||this.state,e)}pasteHTML(e,t){return St(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return St(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Qn(this,e)}destroy(){this.docView&&(Da(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],yn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Rl())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Ea(this,e)}domSelectionRange(){let e=this.domSelection();return e?F&&this.root.nodeType===11&&vl(this.dom.ownerDocument)==this.dom&&tc(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}hc.prototype.dispatch=function(r){let e=this._props.dispatchTransaction;e?e.call(this,r):this.updateState(this.state.apply(r))};function ii(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[v.node(0,r.state.doc.content.size,e)]}function si(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:v.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function oi(r){return!r.someProp("editable",e=>e(r.state)===!1)}function dc(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function li(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function uc(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function ai(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function th(r,e){return function(t,n){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(l.type!=r)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=r||i.index(-2)!=i.node(-2).childCount-1)return!1;if(n){let h=y.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let b=i.depth-d;b>=i.depth-3;b--)h=y.from(i.node(b).copy(h));let u=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;h=h.append(y.from(r.createAndFill()));let p=i.before(i.depth-(d-1)),m=t.tr.replace(p,i.after(-u),new x(h,4-d,0)),g=-1;m.doc.nodesBetween(p,m.doc.content.size,(b,N)=>{if(g>-1)return!1;b.isTextblock&&b.content.size==0&&(g=N+1)}),g>-1&&m.setSelection(C.near(m.doc.resolve(g))),n(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,s.pos),f=a?[null,{type:a}]:void 0;return ht(c.doc,i.pos,2,f)?(n&&n(c.split(i.pos,2,f).scrollIntoView()),!0):!1}}function nh(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,o=>o.childCount>0&&o.firstChild.type==r);return s?t?n.node(s.depth-1).type==r?pc(e,t,r,s):mc(e,t,s):!0:!1}}function pc(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);s<o&&(i.step(new L(s-1,o,s,o,new x(y.from(t.create(null,n.parent.copy())),1,0),1,!0)),n=new Bi(i.doc.resolve(n.$from.pos),i.doc.resolve(o),n.depth));const l=Gt(n);if(l==null)return!1;i.lift(n,l);let a=i.doc.resolve(i.mapping.map(s,-1)-1);return Xt(i.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&i.join(a.pos),e(i.scrollIntoView()),!0}function mc(r,e,t){let n=r.tr,i=t.parent;for(let u=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)u-=i.child(p).nodeSize,n.delete(u-1,u+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),f=s.index(-1);if(!c.canReplace(f+(l?0:1),f+1,o.content.append(a?y.empty:y.from(i))))return!1;let h=s.pos,d=h+o.nodeSize;return n.step(new L(h-(l?1:0),d+(a?1:0),h+1,d-1,new x((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function rh(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,c=>c.childCount>0&&c.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=r)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=y.from(c?r.create():null),h=new x(y.from(r.create(null,y.from(l.type.create(null,f)))),c?3:1,0),d=s.start,u=s.end;t(e.tr.step(new L(d-(c?3:1),u,d,u,h,1,!0)).scrollIntoView())}return!0}}let vn,Fn;if(typeof WeakMap<"u"){let r=new WeakMap;vn=e=>r.get(e),Fn=(e,t)=>(r.set(e,t),t)}else{const r=[];let t=0;vn=n=>{for(let i=0;i<r.length;i+=2)if(r[i]==n)return r[i+1]},Fn=(n,i)=>(t==10&&(t=0),r[t++]=n,r[t++]=i)}var T=class{constructor(r,e,t,n){this.width=r,this.height=e,this.map=t,this.problems=n}findCell(r){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=r)continue;const n=e%this.width,i=e/this.width|0;let s=n+1,o=i+1;for(let l=1;s<this.width&&this.map[e+l]==t;l++)s++;for(let l=1;o<this.height&&this.map[e+this.width*l]==t;l++)o++;return{left:n,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${r} found`)}colCount(r){for(let e=0;e<this.map.length;e++)if(this.map[e]==r)return e%this.width;throw new RangeError(`No cell with offset ${r} found`)}nextCell(r,e,t){const{left:n,right:i,top:s,bottom:o}=this.findCell(r);return e=="horiz"?(t<0?n==0:i==this.width)?null:this.map[s*this.width+(t<0?n-1:i)]:(t<0?s==0:o==this.height)?null:this.map[n+this.width*(t<0?s-1:o)]}rectBetween(r,e){const{left:t,right:n,top:i,bottom:s}=this.findCell(r),{left:o,right:l,top:a,bottom:c}=this.findCell(e);return{left:Math.min(t,o),top:Math.min(i,a),right:Math.max(n,l),bottom:Math.max(s,c)}}cellsInRect(r){const e=[],t={};for(let n=r.top;n<r.bottom;n++)for(let i=r.left;i<r.right;i++){const s=n*this.width+i,o=this.map[s];t[o]||(t[o]=!0,!(i==r.left&&i&&this.map[s-1]==o||n==r.top&&n&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(r,e,t){for(let n=0,i=0;;n++){const s=i+t.child(n).nodeSize;if(n==r){let o=e+r*this.width;const l=(r+1)*this.width;for(;o<l&&this.map[o]<i;)o++;return o==l?s-1:this.map[o]}i=s}}static get(r){return vn(r)||Fn(r,gc(r))}};function gc(r){if(r.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+r.type.name);const e=yc(r),t=r.childCount,n=[];let i=0,s=null;const o=[];for(let c=0,f=e*t;c<f;c++)n[c]=0;for(let c=0,f=0;c<t;c++){const h=r.child(c);f++;for(let p=0;;p++){for(;i<n.length&&n[i]!=0;)i++;if(p==h.childCount)break;const m=h.child(p),{colspan:g,rowspan:b,colwidth:N}=m.attrs;for(let O=0;O<b;O++){if(O+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:f,n:b-O});break}const W=i+O*e;for(let j=0;j<g;j++){n[W+j]==0?n[W+j]=f:(s||(s=[])).push({type:"collision",row:c,pos:f,n:g-j});const le=N&&N[j];if(le){const w=(W+j)%e*2,A=o[w];A==null||A!=le&&o[w+1]==1?(o[w]=le,o[w+1]=1):A==le&&o[w+1]++}}}i+=g,f+=m.nodeSize}const d=(c+1)*e;let u=0;for(;i<d;)n[i++]==0&&u++;u&&(s||(s=[])).push({type:"missing",row:c,n:u}),f++}(e===0||t===0)&&(s||(s=[])).push({type:"zero_sized"});const l=new T(e,t,n,s);let a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&bc(l,o,r),l}function yc(r){let e=-1,t=!1;for(let n=0;n<r.childCount;n++){const i=r.child(n);let s=0;if(t)for(let o=0;o<n;o++){const l=r.child(o);for(let a=0;a<l.childCount;a++){const c=l.child(a);o+c.attrs.rowspan>n&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function bc(r,e,t){r.problems||(r.problems=[]);const n={};for(let i=0;i<r.map.length;i++){const s=r.map[i];if(n[s])continue;n[s]=!0;const o=t.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let l=null;const a=o.attrs;for(let c=0;c<a.colspan;c++){const f=e[(i+c)%r.width*2];f!=null&&(!a.colwidth||a.colwidth[c]!=f)&&((l||(l=xc(a)))[c]=f)}l&&r.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function xc(r){if(r.colwidth)return r.colwidth.slice();const e=[];for(let t=0;t<r.colspan;t++)e.push(0);return e}function ci(r,e){if(typeof r=="string")return{};const t=r.getAttribute("data-colwidth"),n=t&&/^\d+(,\d+)*$/.test(t)?t.split(",").map(o=>Number(o)):null,i=Number(r.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(r.getAttribute("rowspan")||1),colwidth:n&&n.length==i?n:null};for(const o in e){const l=e[o].getFromDOM,a=l&&l(r);a!=null&&(s[o]=a)}return s}function fi(r,e){const t={};r.attrs.colspan!=1&&(t.colspan=r.attrs.colspan),r.attrs.rowspan!=1&&(t.rowspan=r.attrs.rowspan),r.attrs.colwidth&&(t["data-colwidth"]=r.attrs.colwidth.join(","));for(const n in e){const i=e[n].setDOMAttr;i&&i(r.attrs[n],t)}return t}function Sc(r){if(r!==null){if(!Array.isArray(r))throw new TypeError("colwidth must be null or an array");for(const e of r)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function ih(r){const e=r.cellAttributes||{},t={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Sc}};for(const n in e)t[n]={default:e[n].default,validate:e[n].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:r.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:r.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:n=>ci(n,e)}],toDOM(n){return["td",fi(n,e),0]}},table_header:{content:r.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:n=>ci(n,e)}],toDOM(n){return["th",fi(n,e),0]}}}}function ee(r){let e=r.cached.tableNodeTypes;if(!e){e=r.cached.tableNodeTypes={};for(const t in r.nodes){const n=r.nodes[t],i=n.spec.tableRole;i&&(e[i]=n)}}return e}const xe=new Te("selectingCells");function tt(r){for(let e=r.depth-1;e>0;e--)if(r.node(e).type.spec.tableRole=="row")return r.node(0).resolve(r.before(e+1));return null}function pe(r){const e=r.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function tn(r){const e=r.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=tt(e.$head)||Cc(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Cc(r){for(let e=r.nodeAfter,t=r.pos;e;e=e.firstChild,t++){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t)}for(let e=r.nodeBefore,t=r.pos;e;e=e.lastChild,t--){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t-e.nodeSize)}}function Vn(r){return r.parent.type.spec.tableRole=="row"&&!!r.nodeAfter}function kc(r){return r.node(0).resolve(r.pos+r.nodeAfter.nodeSize)}function sr(r,e){return r.depth==e.depth&&r.pos>=e.start(-1)&&r.pos<=e.end(-1)}function Gs(r,e,t){const n=r.node(-1),i=T.get(n),s=r.start(-1),o=i.nextCell(r.pos-s,e,t);return o==null?null:r.node(0).resolve(s+o)}function Je(r,e,t=1){const n={...r,colspan:r.colspan-t};return n.colwidth&&(n.colwidth=n.colwidth.slice(),n.colwidth.splice(e,t),n.colwidth.some(i=>i>0)||(n.colwidth=null)),n}function wc(r,e,t=1){const n={...r,colspan:r.colspan+t};if(n.colwidth){n.colwidth=n.colwidth.slice();for(let i=0;i<t;i++)n.colwidth.splice(e,0,0)}return n}function Mc(r,e,t){const n=ee(e.type.schema).header_cell;for(let i=0;i<r.height;i++)if(e.nodeAt(r.map[t+i*r.width]).type!=n)return!1;return!0}var R=class ce extends C{constructor(e,t=e){const n=e.node(-1),i=T.get(n),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(f=>f!=t.pos-s);a.unshift(t.pos-s);const c=a.map(f=>{const h=n.nodeAt(f);if(!h)throw new RangeError(`No cell with offset ${f} found`);const d=s+f+1;return new is(l.resolve(d),l.resolve(d+h.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const n=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Vn(n)&&Vn(i)&&sr(n,i)){const s=this.$anchorCell.node(-1)!=n.node(-1);return s&&this.isRowSelection()?ce.rowSelection(n,i):s&&this.isColSelection()?ce.colSelection(n,i):new ce(n,i)}return k.between(n,i)}content(){const e=this.$anchorCell.node(-1),t=T.get(e),n=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),s={},o=[];for(let a=i.top;a<i.bottom;a++){const c=[];for(let f=a*t.width+i.left,h=i.left;h<i.right;h++,f++){const d=t.map[f];if(s[d])continue;s[d]=!0;const u=t.findCell(d);let p=e.nodeAt(d);if(!p)throw new RangeError(`No cell with offset ${d} found`);const m=i.left-u.left,g=u.right-i.right;if(m>0||g>0){let b=p.attrs;if(m>0&&(b=Je(b,0,m)),g>0&&(b=Je(b,b.colspan-g,g)),u.left<i.left){if(p=p.type.createAndFill(b),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`)}else p=p.type.create(b,p.content)}if(u.top<i.top||u.bottom>i.bottom){const b={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top<i.top?p=p.type.createAndFill(b):p=p.type.create(b,p.content)}c.push(p)}o.push(e.child(a).copy(y.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new x(y.from(l),1,1)}replace(e,t=x.empty){const n=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:l,$to:a}=i[o],c=e.mapping.slice(n);e.replace(c.map(l.pos),c.map(a.pos),o?x.empty:t)}const s=C.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new x(y.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=T.get(t),i=this.$anchorCell.start(-1),s=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const n=e.node(-1),i=T.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+i.map[o.left])),l.bottom<i.height&&(t=a.resolve(s+i.map[i.width*(i.height-1)+l.right-1]))):(l.top>0&&(t=a.resolve(s+i.map[l.left])),o.bottom<i.height&&(e=a.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new ce(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=T.get(e),n=this.$anchorCell.start(-1),i=t.colCount(this.$anchorCell.pos-n),s=t.colCount(this.$headCell.pos-n);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof ce&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const n=e.node(-1),i=T.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+i.map[o.top*i.width])),l.right<i.width&&(t=a.resolve(s+i.map[i.width*(l.top+1)-1]))):(l.left>0&&(t=a.resolve(s+i.map[l.top*i.width])),o.right<i.width&&(e=a.resolve(s+i.map[i.width*(o.top+1)-1]))),new ce(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new ce(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){return new ce(e.resolve(t),e.resolve(n))}getBookmark(){return new Nc(this.$anchorCell.pos,this.$headCell.pos)}};R.prototype.visible=!1;C.jsonID("cell",R);var Nc=class Xs{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Xs(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&n.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&sr(t,n)?new R(t,n):C.near(n,1)}};function Oc(r){if(!(r.selection instanceof R))return null;const e=[];return r.selection.forEachCell((t,n)=>{e.push(v.node(n,n+t.nodeSize,{class:"selectedCell"}))}),D.create(r.doc,e)}function Tc({$from:r,$to:e}){if(r.pos==e.pos||r.pos<e.pos-6)return!1;let t=r.pos,n=e.pos,i=r.depth;for(;i>=0&&!(r.after(i+1)<r.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,n--);return t==n&&/row|table/.test(r.node(i).type.spec.tableRole)}function Dc({$from:r,$to:e}){let t,n;for(let i=r.depth;i>0;i--){const s=r.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}return t!==n&&e.parentOffset===0}function Ac(r,e,t){const n=(e||r).selection,i=(e||r).doc;let s,o;if(n instanceof S&&(o=n.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=R.create(i,n.from);else if(o=="row"){const l=i.resolve(n.from+1);s=R.rowSelection(l,l)}else if(!t){const l=T.get(n.node),a=n.from+1,c=a+l.map[l.width*l.height-1];s=R.create(i,a+1,c)}}else n instanceof k&&Tc(n)?s=k.create(i,n.from):n instanceof k&&Dc(n)&&(s=k.create(i,n.$from.start(),n.$from.end()));return s&&(e||(e=r.tr)).setSelection(s),e}const Ec=new Te("fix-tables");function Ys(r,e,t,n){const i=r.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){const a=e.child(o);for(let c=l,f=Math.min(i,o+3);c<f;c++)if(r.child(c)==a){l=c+1,t+=a.nodeSize;continue e}n(a,t),l<i&&r.child(l).sameMarkup(a)?Ys(r.child(l),a,t+1,n):a.nodesBetween(0,a.content.size,n,t+1),t+=a.nodeSize}}function Rc(r,e){let t;const n=(i,s)=>{i.type.spec.tableRole=="table"&&(t=Ic(r,i,s,t))};return e?e.doc!=r.doc&&Ys(e.doc,r.doc,0,n):r.doc.descendants(n),t}function Ic(r,e,t,n){const i=T.get(e);if(!i.problems)return n;n||(n=r.tr);const s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){const c=i.problems[a];if(c.type=="collision"){const f=e.nodeAt(c.pos);if(!f)continue;const h=f.attrs;for(let d=0;d<h.rowspan;d++)s[c.row+d]+=c.n;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,Je(h,h.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const f=e.nodeAt(c.pos);if(!f)continue;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,{...f.attrs,rowspan:f.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const f=e.nodeAt(c.pos);if(!f)continue;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,{...f.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const f=n.mapping.map(t);n.delete(f,f+e.nodeSize)}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){const f=e.child(a),h=c+f.nodeSize,d=s[a];if(d>0){let u="cell";f.firstChild&&(u=f.firstChild.type.spec.tableRole);const p=[];for(let g=0;g<d;g++){const b=ee(r.schema)[u].createAndFill();b&&p.push(b)}const m=(a==0||o==a-1)&&l==a?c+1:h-1;n.insert(n.mapping.map(m),p)}c=h}return n.setMeta(Ec,{fixTables:!0})}function _s(r){const e=T.get(r),t=[],n=e.height,i=e.width;for(let s=0;s<n;s++){const o=[];for(let l=0;l<i;l++){const a=s*i+l,c=e.map[a];if(s>0){const f=a-i;if(c===e.map[f]){o.push(null);continue}}if(l>0){const f=a-1;if(c===e.map[f]){o.push(null);continue}}o.push(r.nodeAt(c))}t.push(o)}return t}function Zs(r,e){const t=[],n=T.get(r),i=n.height,s=n.width;for(let o=0;o<i;o++){const l=r.child(o),a=[];for(let f=0;f<s;f++){const h=e[o][f];if(!h)continue;const d=n.map[o*n.width+f],u=r.nodeAt(d);if(!u)continue;const p=u.type.createChecked(h.attrs,h.content,h.marks);a.push(p)}const c=l.type.createChecked(l.attrs,a,l.marks);t.push(c)}return r.type.createChecked(r.attrs,t,r.marks)}function Qs(r,e,t,n){const i=e[0]>t[0]?-1:1,s=r.splice(e[0],e.length),o=s.length%2===0?1:0;let l;return l=i===-1?t[0]:t[t.length-1]-o,r.splice(l,0,...s),r}function nn(r){return zc(e=>e.type.spec.tableRole==="table",r)}function zc(r,e){for(let t=e.depth;t>=0;t-=1){const n=e.node(t);if(r(n))return{node:n,pos:t===0?0:e.before(t),start:e.start(t),depth:t}}return null}function Ue(r,e){const t=nn(e.$from);if(!t)return;const n=T.get(t.node);if(!(r<0||r>n.width-1))return n.cellsInRect({left:r,right:r+1,top:0,bottom:n.height}).map(i=>{const s=t.node.nodeAt(i),o=i+t.start;return{pos:o,start:o+1,node:s,depth:t.depth+2}})}function Ge(r,e){const t=nn(e.$from);if(!t)return;const n=T.get(t.node);if(!(r<0||r>n.height-1))return n.cellsInRect({left:0,right:n.width,top:r,bottom:r+1}).map(i=>{const s=t.node.nodeAt(i),o=i+t.start;return{pos:o,start:o+1,node:s,depth:t.depth+2}})}function hi(r,e,t=e){let n=e,i=t;for(let f=e;f>=0;f--){const h=Ue(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.colspan+f-1;u>=n&&(n=f),u>i&&(i=u)})}for(let f=e;f<=i;f++){const h=Ue(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.colspan+f-1;d.node.attrs.colspan>1&&u>i&&(i=u)})}const s=[];for(let f=n;f<=i;f++){const h=Ue(f,r.selection);h&&h.length>0&&s.push(f)}n=s[0],i=s[s.length-1];const o=Ue(n,r.selection),l=Ge(0,r.selection);if(!o||!l)return;const a=r.doc.resolve(o[o.length-1].pos);let c;for(let f=i;f>=n;f--){const h=Ue(f,r.selection);if(h&&h.length>0){for(let d=l.length-1;d>=0;d--)if(l[d].pos===h[0].pos){c=h[0];break}if(c)break}}if(c)return{$anchor:a,$head:r.doc.resolve(c.pos),indexes:s}}function di(r,e,t=e){let n=e,i=t;for(let f=e;f>=0;f--){const h=Ge(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.rowspan+f-1;u>=n&&(n=f),u>i&&(i=u)})}for(let f=e;f<=i;f++){const h=Ge(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.rowspan+f-1;d.node.attrs.rowspan>1&&u>i&&(i=u)})}const s=[];for(let f=n;f<=i;f++){const h=Ge(f,r.selection);h&&h.length>0&&s.push(f)}n=s[0],i=s[s.length-1];const o=Ge(n,r.selection),l=Ue(0,r.selection);if(!o||!l)return;const a=r.doc.resolve(o[o.length-1].pos);let c;for(let f=i;f>=n;f--){const h=Ge(f,r.selection);if(h&&h.length>0){for(let d=l.length-1;d>=0;d--)if(l[d].pos===h[0].pos){c=h[0];break}if(c)break}}if(c)return{$anchor:a,$head:r.doc.resolve(c.pos),indexes:s}}function ui(r){return r[0].map((e,t)=>r.map(n=>n[t]))}function Bc(r){var e,t;const{tr:n,originIndex:i,targetIndex:s,select:o,pos:l}=r,a=nn(n.doc.resolve(l));if(!a)return!1;const c=(e=hi(n,i))===null||e===void 0?void 0:e.indexes,f=(t=hi(n,s))===null||t===void 0?void 0:t.indexes;if(!c||!f||c.includes(s))return!1;const h=Pc(a.node,c,f);if(n.replaceWith(a.pos,a.pos+a.node.nodeSize,h),!o)return!0;const d=T.get(h),u=a.start,p=s,m=d.positionAt(d.height-1,p,h),g=n.doc.resolve(u+m),b=d.positionAt(0,p,h),N=n.doc.resolve(u+b);return n.setSelection(R.colSelection(g,N)),!0}function Pc(r,e,t,n){let i=ui(_s(r));return i=Qs(i,e,t),i=ui(i),Zs(r,i)}function vc(r){var e,t;const{tr:n,originIndex:i,targetIndex:s,select:o,pos:l}=r,a=nn(n.doc.resolve(l));if(!a)return!1;const c=(e=di(n,i))===null||e===void 0?void 0:e.indexes,f=(t=di(n,s))===null||t===void 0?void 0:t.indexes;if(!c||!f||c.includes(s))return!1;const h=Fc(a.node,c,f);if(n.replaceWith(a.pos,a.pos+a.node.nodeSize,h),!o)return!0;const d=T.get(h),u=a.start,p=s,m=d.positionAt(p,d.width-1,h),g=n.doc.resolve(u+m),b=d.positionAt(p,0,h),N=n.doc.resolve(u+b);return n.setSelection(R.rowSelection(g,N)),!0}function Fc(r,e,t,n){let i=_s(r);return i=Qs(i,e,t),Zs(r,i)}function rt(r){const e=r.selection,t=tn(r),n=t.node(-1),i=t.start(-1),s=T.get(n);return{...e instanceof R?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(t.pos-i),tableStart:i,map:s,table:n}}function eo(r,{map:e,tableStart:t,table:n},i){let s=i>0?-1:0;Mc(e,n,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){const l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){const a=e.map[l],c=n.nodeAt(a);r.setNodeMarkup(r.mapping.map(t+a),null,wc(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{const a=s==null?ee(n.type.schema).cell:n.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,n);r.insert(r.mapping.map(t+c),a.createAndFill())}}return r}function sh(r,e){if(!pe(r))return!1;if(e){const t=rt(r);e(eo(r.tr,t,t.left))}return!0}function oh(r,e){if(!pe(r))return!1;if(e){const t=rt(r);e(eo(r.tr,t,t.right))}return!0}function Vc(r,{map:e,table:t,tableStart:n},i){const s=r.mapping.maps.length;for(let o=0;o<e.height;){const l=o*e.width+i,a=e.map[l],c=t.nodeAt(a),f=c.attrs;if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)r.setNodeMarkup(r.mapping.slice(s).map(n+a),null,Je(f,i-e.colCount(a)));else{const h=r.mapping.slice(s).map(n+a);r.delete(h,h+c.nodeSize)}o+=f.rowspan}}function lh(r,e){if(!pe(r))return!1;if(e){const t=rt(r),n=r.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;Vc(n,t,i),i!=t.left;i--){const s=t.tableStart?n.doc.nodeAt(t.tableStart-1):n.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=T.get(s)}e(n)}return!0}function Lc(r,{map:e,table:t,tableStart:n},i){let s=0;for(let c=0;c<i;c++)s+=t.child(c).nodeSize;const o=s+t.child(i).nodeSize,l=r.mapping.maps.length;r.delete(s+n,o+n);const a=new Set;for(let c=0,f=i*e.width;c<e.width;c++,f++){const h=e.map[f];if(!a.has(h)){if(a.add(h),i>0&&h==e.map[f-e.width]){const d=t.nodeAt(h).attrs;r.setNodeMarkup(r.mapping.slice(l).map(h+n),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i<e.height&&h==e.map[f+e.width]){const d=t.nodeAt(h),u=d.attrs,p=d.type.create({...u,rowspan:d.attrs.rowspan-1},d.content),m=e.positionAt(i+1,c,t);r.insert(r.mapping.slice(l).map(n+m),p),c+=u.colspan-1}}}}function ah(r,e){if(!pe(r))return!1;if(e){const t=rt(r),n=r.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;Lc(n,t,i),i!=t.top;i--){const s=t.tableStart?n.doc.nodeAt(t.tableStart-1):n.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=T.get(t.table)}e(n)}return!0}function ch(r,e){return function(t,n){if(!pe(t))return!1;const i=tn(t);if(i.nodeAfter.attrs[r]===e)return!1;if(n){const s=t.tr;t.selection instanceof R?t.selection.forEachCell((o,l)=>{o.attrs[r]!==e&&s.setNodeMarkup(l,null,{...o.attrs,[r]:e})}):s.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[r]:e}),n(s)}return!0}}function $c(r){return function(e,t){if(!pe(e))return!1;if(t){const n=ee(e.schema),i=rt(e),s=e.tr,o=i.map.cellsInRect(r=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:r=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==n.header_cell&&s.setNodeMarkup(i.tableStart+o[a],n.cell,l[a].attrs);if(s.steps.length===0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],n.header_cell,l[a].attrs);t(s)}return!0}}function pi(r,e,t){const n=e.map.cellsInRect({left:0,top:0,right:r=="row"?e.map.width:1,bottom:r=="column"?e.map.height:1});for(let i=0;i<n.length;i++){const s=e.table.nodeAt(n[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function or(r,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?$c(r):function(t,n){if(!pe(t))return!1;if(n){const i=ee(t.schema),s=rt(t),o=t.tr,l=pi("row",s,i),a=pi("column",s,i),c=(r==="column"?l:r==="row"&&a)?1:0,f=r=="column"?{left:0,top:c,right:1,bottom:s.map.height}:r=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,h=r=="column"?a?i.cell:i.header_cell:r=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(f).forEach(d=>{const u=d+s.tableStart,p=o.doc.nodeAt(u);p&&o.setNodeMarkup(u,h,p.attrs)}),n(o)}return!0}}or("row",{useDeprecatedLogic:!0});or("column",{useDeprecatedLogic:!0});or("cell",{useDeprecatedLogic:!0});function Wc(r,e){if(e<0){const t=r.nodeBefore;if(t)return r.pos-t.nodeSize;for(let n=r.index(-1)-1,i=r.before();n>=0;n--){const s=r.node(-1).child(n),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(r.index()<r.parent.childCount-1)return r.pos+r.nodeAfter.nodeSize;const t=r.node(-1);for(let n=r.indexAfter(-1),i=r.after();n<t.childCount;n++){const s=t.child(n);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function fh(r){return function(e,t){if(!pe(e))return!1;const n=Wc(tn(e),r);if(n==null)return!1;if(t){const i=e.doc.resolve(n);t(e.tr.setSelection(k.between(i,kc(i))).scrollIntoView())}return!0}}function hh(r,e){const t=r.selection.$anchor;for(let n=t.depth;n>0;n--)if(t.node(n).type.spec.tableRole=="table")return e&&e(r.tr.delete(t.before(n),t.after(n)).scrollIntoView()),!0;return!1}function Dt(r,e){const t=r.selection;if(!(t instanceof R))return!1;if(e){const n=r.tr,i=ee(r.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||n.replace(n.mapping.map(o+1),n.mapping.map(o+s.nodeSize-1),new x(i,0,0))}),n.docChanged&&e(n)}return!0}function dh(r){return(e,t)=>{const{from:n,to:i,select:s=!0,pos:o=e.selection.from}=r,l=e.tr;return vc({tr:l,originIndex:n,targetIndex:i,select:s,pos:o})?(t?.(l),!0):!1}}function uh(r){return(e,t)=>{const{from:n,to:i,select:s=!0,pos:o=e.selection.from}=r,l=e.tr;return Bc({tr:l,originIndex:n,targetIndex:i,select:s,pos:o})?(t?.(l),!0):!1}}function Jc(r){if(r.size===0)return null;let{content:e,openStart:t,openEnd:n}=r;for(;e.childCount==1&&(t>0&&n>0||e.child(0).type.spec.tableRole=="table");)t--,n--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content;const f=a?0:Math.max(0,t-1),h=a<e.childCount-1?0:Math.max(0,n-1);(f||h)&&(c=Ln(ee(o).row,new x(c,f,h)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||n?Ln(ee(o).row,new x(e,t,n)).content:e);else return null;return qc(o,l)}function qc(r,e){const t=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let n=0;for(let i=0;i<t.length;i++)n=Math.max(n,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(y.empty),t[i]<n){const s=ee(r).cell.createAndFill(),o=[];for(let l=t[i];l<n;l++)o.push(s);e[i]=e[i].append(y.from(o))}return{height:e.length,width:n,rows:e}}function Ln(r,e){const t=r.createAndFill();return new rs(t).replace(0,t.content.size,e).doc}function Kc({width:r,height:e,rows:t},n,i){if(r!=n){const s=[],o=[];for(let l=0;l<t.length;l++){const a=t[l],c=[];for(let f=s[l]||0,h=0;f<n;h++){let d=a.child(h%a.childCount);f+d.attrs.colspan>n&&(d=d.type.createChecked(Je(d.attrs,d.attrs.colspan,f+d.attrs.colspan-n),d.content)),c.push(d),f+=d.attrs.colspan;for(let u=1;u<d.attrs.rowspan;u++)s[l+u]=(s[l+u]||0)+d.attrs.colspan}o.push(y.from(c))}t=o,r=n}if(e!=i){const s=[];for(let o=0,l=0;o<i;o++,l++){const a=[],c=t[l%e];for(let f=0;f<c.childCount;f++){let h=c.child(f);o+h.attrs.rowspan>i&&(h=h.type.create({...h.attrs,rowspan:Math.max(1,i-h.attrs.rowspan)},h.content)),a.push(h)}s.push(y.from(a))}t=s,e=i}return{width:r,height:e,rows:t}}function Hc(r,e,t,n,i,s,o){const l=r.doc.type.schema,a=ee(l);let c,f;if(i>e.width)for(let h=0,d=0;h<e.height;h++){const u=t.child(h);d+=u.nodeSize;const p=[];let m;u.lastChild==null||u.lastChild.type==a.cell?m=c||(c=a.cell.createAndFill()):m=f||(f=a.header_cell.createAndFill());for(let g=e.width;g<i;g++)p.push(m);r.insert(r.mapping.slice(o).map(d-1+n),p)}if(s>e.height){const h=[];for(let p=0,m=(e.height-1)*e.width;p<Math.max(e.width,i);p++){const g=p>=e.width?!1:t.nodeAt(e.map[m+p]).type==a.header_cell;h.push(g?f||(f=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const d=a.row.create(null,y.from(h)),u=[];for(let p=e.height;p<s;p++)u.push(d);r.insert(r.mapping.slice(o).map(n+t.nodeSize-2),u)}return!!(c||f)}function mi(r,e,t,n,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){const f=o*e.width+c,h=e.map[f];if(e.map[f-e.width]==h){a=!0;const d=t.nodeAt(h),{top:u,left:p}=e.findCell(h);r.setNodeMarkup(r.mapping.slice(l).map(h+n),null,{...d.attrs,rowspan:o-u}),r.insert(r.mapping.slice(l).map(e.positionAt(o,p,t)),d.type.createAndFill({...d.attrs,rowspan:u+d.attrs.rowspan-o})),c+=d.attrs.colspan-1}}return a}function gi(r,e,t,n,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){const f=c*e.width+o,h=e.map[f];if(e.map[f-1]==h){a=!0;const d=t.nodeAt(h),u=e.colCount(h),p=r.mapping.slice(l).map(h+n);r.setNodeMarkup(p,null,Je(d.attrs,o-u,d.attrs.colspan-(o-u))),r.insert(p+d.nodeSize,d.type.createAndFill(Je(d.attrs,0,o-u))),c+=d.attrs.rowspan-1}}return a}function yi(r,e,t,n,i){let s=t?r.doc.nodeAt(t-1):r.doc;if(!s)throw new Error("No table found");let o=T.get(s);const{top:l,left:a}=n,c=a+i.width,f=l+i.height,h=r.tr;let d=0;function u(){if(s=t?h.doc.nodeAt(t-1):h.doc,!s)throw new Error("No table found");o=T.get(s),d=h.mapping.maps.length}Hc(h,o,s,t,c,f,d)&&u(),mi(h,o,s,t,a,c,l,d)&&u(),mi(h,o,s,t,a,c,f,d)&&u(),gi(h,o,s,t,l,f,a,d)&&u(),gi(h,o,s,t,l,f,c,d)&&u();for(let p=l;p<f;p++){const m=o.positionAt(p,a,s),g=o.positionAt(p,c,s);h.replace(h.mapping.slice(d).map(m+t),h.mapping.slice(d).map(g+t),new x(i.rows[p-l],0,0))}u(),h.setSelection(new R(h.doc.resolve(t+o.positionAt(l,a,s)),h.doc.resolve(t+o.positionAt(f-1,c-1,s)))),e(h)}const jc=Xn({ArrowLeft:At("horiz",-1),ArrowRight:At("horiz",1),ArrowUp:At("vert",-1),ArrowDown:At("vert",1),"Shift-ArrowLeft":Et("horiz",-1),"Shift-ArrowRight":Et("horiz",1),"Shift-ArrowUp":Et("vert",-1),"Shift-ArrowDown":Et("vert",1),Backspace:Dt,"Mod-Backspace":Dt,Delete:Dt,"Mod-Delete":Dt});function Bt(r,e,t){return t.eq(r.selection)?!1:(e&&e(r.tr.setSelection(t).scrollIntoView()),!0)}function At(r,e){return(t,n,i)=>{if(!i)return!1;const s=t.selection;if(s instanceof R)return Bt(t,n,C.near(s.$headCell,e));if(r!="horiz"&&!s.empty)return!1;const o=to(i,r,e);if(o==null)return!1;if(r=="horiz")return Bt(t,n,C.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=Gs(l,r,e);let c;return a?c=C.near(a,1):e<0?c=C.near(t.doc.resolve(l.before(-1)),-1):c=C.near(t.doc.resolve(l.after(-1)),1),Bt(t,n,c)}}}function Et(r,e){return(t,n,i)=>{if(!i)return!1;const s=t.selection;let o;if(s instanceof R)o=s;else{const a=to(i,r,e);if(a==null)return!1;o=new R(t.doc.resolve(a))}const l=Gs(o.$headCell,r,e);return l?Bt(t,n,new R(o.$anchorCell,l)):!1}}function Uc(r,e){const t=r.state.doc,n=tt(t.resolve(e));return n?(r.dispatch(r.state.tr.setSelection(new R(n))),!0):!1}function Gc(r,e,t){if(!pe(r.state))return!1;let n=Jc(t);const i=r.state.selection;if(i instanceof R){n||(n={width:1,height:1,rows:[y.from(Ln(ee(r.state.schema).cell,t))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=T.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return n=Kc(n,l.right-l.left,l.bottom-l.top),yi(r.state,r.dispatch,o,l,n),!0}else if(n){const s=tn(r.state),o=s.start(-1);return yi(r.state,r.dispatch,o,T.get(s.node(-1)).findCell(s.pos-o),n),!0}else return!1}function Xc(r,e){var t;if(e.button!=0||e.ctrlKey||e.metaKey)return;const n=bi(r,e.target);let i;if(e.shiftKey&&r.state.selection instanceof R)s(r.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&n&&(i=tt(r.state.selection.$anchor))!=null&&((t=xn(r,e))===null||t===void 0?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!n)return;function s(a,c){let f=xn(r,c);const h=xe.getState(r.state)==null;if(!f||!sr(a,f))if(h)f=a;else return;const d=new R(a,f);if(h||!r.state.selection.eq(d)){const u=r.state.tr.setSelection(d);h&&u.setMeta(xe,a.pos),r.dispatch(u)}}function o(){r.root.removeEventListener("mouseup",o),r.root.removeEventListener("dragstart",o),r.root.removeEventListener("mousemove",l),xe.getState(r.state)!=null&&r.dispatch(r.state.tr.setMeta(xe,-1))}function l(a){const c=a,f=xe.getState(r.state);let h;if(f!=null)h=r.state.doc.resolve(f);else if(bi(r,c.target)!=n&&(h=xn(r,e),!h))return o();h&&s(h,c)}r.root.addEventListener("mouseup",o),r.root.addEventListener("dragstart",o),r.root.addEventListener("mousemove",l)}function to(r,e,t){if(!(r.state.selection instanceof k))return null;const{$head:n}=r.state.selection;for(let i=n.depth-1;i>=0;i--){const s=n.node(i);if((t<0?n.index(i):n.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=n.before(i),l=e=="vert"?t>0?"down":"up":t>0?"right":"left";return r.endOfTextblock(l)?o:null}}return null}function bi(r,e){for(;e&&e!=r.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function xn(r,e){const t=r.posAtCoords({left:e.clientX,top:e.clientY});if(!t)return null;let{inside:n,pos:i}=t;return n>=0&&tt(r.state.doc.resolve(n))||tt(r.state.doc.resolve(i))}var Yc=class{constructor(r,e){this.node=r,this.defaultCellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),$n(r,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(r){return r.type!=this.node.type?!1:(this.node=r,$n(r,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(r){return r.type=="attributes"&&(r.target==this.table||this.colgroup.contains(r.target))}};function $n(r,e,t,n,i,s){let o=0,l=!0,a=e.firstChild;const c=r.firstChild;if(c){for(let h=0,d=0;h<c.childCount;h++){const{colspan:u,colwidth:p}=c.child(h).attrs;for(let m=0;m<u;m++,d++){const g=i==d?s:p&&p[m],b=g?g+"px":"";if(o+=g||n,g||(l=!1),a)a.style.width!=b&&(a.style.width=b),a=a.nextSibling;else{const N=document.createElement("col");N.style.width=b,e.appendChild(N)}}}for(;a;){var f;const h=a.nextSibling;(f=a.parentNode)===null||f===void 0||f.removeChild(a),a=h}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}}const G=new Te("tableColumnResizing");function ph({handleWidth:r=5,cellMinWidth:e=25,defaultCellMinWidth:t=100,View:n=Yc,lastColumnResizable:i=!0}={}){const s=new Oe({key:G,state:{init(o,l){var a;const c=(a=s.spec)===null||a===void 0||(a=a.props)===null||a===void 0?void 0:a.nodeViews,f=ee(l.schema).table.name;return n&&c&&(c[f]=(h,d)=>new n(h,t,d)),new _c(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=G.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{Zc(o,l,r,i)},mouseleave:o=>{Qc(o)},mousedown:(o,l)=>{ef(o,l,e,t)}},decorations:o=>{const l=G.getState(o);if(l&&l.activeHandle>-1)return of(o,l.activeHandle)},nodeViews:{}}});return s}var _c=class Pt{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,n=e.getMeta(G);if(n&&n.setHandle!=null)return new Pt(n.setHandle,!1);if(n&&n.setDragging!==void 0)return new Pt(t.activeHandle,n.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Vn(e.doc.resolve(i))||(i=-1),new Pt(i,t.dragging)}return t}};function Zc(r,e,t,n){if(!r.editable)return;const i=G.getState(r.state);if(i&&!i.dragging){const s=nf(e.target);let o=-1;if(s){const{left:l,right:a}=s.getBoundingClientRect();e.clientX-l<=t?o=xi(r,e,"left",t):a-e.clientX<=t&&(o=xi(r,e,"right",t))}if(o!=i.activeHandle){if(!n&&o!==-1){const l=r.state.doc.resolve(o),a=l.node(-1),c=T.get(a),f=l.start(-1);if(c.colCount(l.pos-f)+l.nodeAfter.attrs.colspan-1==c.width-1)return}no(r,o)}}}function Qc(r){if(!r.editable)return;const e=G.getState(r.state);e&&e.activeHandle>-1&&!e.dragging&&no(r,-1)}function ef(r,e,t,n){var i;if(!r.editable)return!1;const s=(i=r.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,o=G.getState(r.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=r.state.doc.nodeAt(o.activeHandle),a=tf(r,o.activeHandle,l.attrs);r.dispatch(r.state.tr.setMeta(G,{setDragging:{startX:e.clientX,startWidth:a}}));function c(h){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",f);const d=G.getState(r.state);d?.dragging&&(rf(r,d.activeHandle,Si(d.dragging,h,t)),r.dispatch(r.state.tr.setMeta(G,{setDragging:null})))}function f(h){if(!h.which)return c(h);const d=G.getState(r.state);if(d&&d.dragging){const u=Si(d.dragging,h,t);Ci(r,d.activeHandle,u,n)}}return Ci(r,o.activeHandle,a,n),s.addEventListener("mouseup",c),s.addEventListener("mousemove",f),e.preventDefault(),!0}function tf(r,e,{colspan:t,colwidth:n}){const i=n&&n[n.length-1];if(i)return i;const s=r.domAtPos(e);let o=s.node.childNodes[s.offset].offsetWidth,l=t;if(n)for(let a=0;a<t;a++)n[a]&&(o-=n[a],l--);return o/l}function nf(r){for(;r&&r.nodeName!="TD"&&r.nodeName!="TH";)r=r.classList&&r.classList.contains("ProseMirror")?null:r.parentNode;return r}function xi(r,e,t,n){const i=t=="right"?-n:n,s=r.posAtCoords({left:e.clientX+i,top:e.clientY});if(!s)return-1;const{pos:o}=s,l=tt(r.state.doc.resolve(o));if(!l)return-1;if(t=="right")return l.pos;const a=T.get(l.node(-1)),c=l.start(-1),f=a.map.indexOf(l.pos-c);return f%a.width==0?-1:c+a.map[f-1]}function Si(r,e,t){const n=e.clientX-r.startX;return Math.max(t,r.startWidth+n)}function no(r,e){r.dispatch(r.state.tr.setMeta(G,{setHandle:e}))}function rf(r,e,t){const n=r.state.doc.resolve(e),i=n.node(-1),s=T.get(i),o=n.start(-1),l=s.colCount(n.pos-o)+n.nodeAfter.attrs.colspan-1,a=r.state.tr;for(let c=0;c<s.height;c++){const f=c*s.width+l;if(c&&s.map[f]==s.map[f-s.width])continue;const h=s.map[f],d=i.nodeAt(h).attrs,u=d.colspan==1?0:l-s.colCount(h);if(d.colwidth&&d.colwidth[u]==t)continue;const p=d.colwidth?d.colwidth.slice():sf(d.colspan);p[u]=t,a.setNodeMarkup(o+h,null,{...d,colwidth:p})}a.docChanged&&r.dispatch(a)}function Ci(r,e,t,n){const i=r.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=T.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;let a=r.domAtPos(i.start(-1)).node;for(;a&&a.nodeName!="TABLE";)a=a.parentNode;a&&$n(s,a.firstChild,a,n,l,t)}function sf(r){return Array(r).fill(0)}function of(r,e){const t=[],n=r.doc.resolve(e),i=n.node(-1);if(!i)return D.empty;const s=T.get(i),o=n.start(-1),l=s.colCount(n.pos-o)+n.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const f=l+c*s.width;if((l==s.width-1||s.map[f]!=s.map[f+1])&&(c==0||s.map[f]!=s.map[f-s.width])){var a;const h=s.map[f],d=o+h+i.nodeAt(h).nodeSize-1,u=document.createElement("div");u.className="column-resize-handle",!((a=G.getState(r))===null||a===void 0)&&a.dragging&&t.push(v.node(o+h,o+h+i.nodeAt(h).nodeSize,{class:"column-resize-dragging"})),t.push(v.widget(d,u))}}return D.create(r.doc,t)}function mh({allowTableNodeSelection:r=!1}={}){return new Oe({key:xe,state:{init(){return null},apply(e,t){const n=e.getMeta(xe);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;const{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:Oc,handleDOMEvents:{mousedown:Xc},createSelectionBetween(e){return xe.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Uc,handleKeyDown:jc,handlePaste:Gc},appendTransaction(e,t,n){return Ac(n,Rc(n,t),r)}})}var jt=typeof navigator<"u"?navigator:null,lr=jt&&jt.userAgent||"",lf=/Edge\/(\d+)/.exec(lr),af=/MSIE \d/.exec(lr),cf=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(lr),ff=!!(af||cf||lf),hf=!ff&&!!jt&&/Apple Computer/.test(jt.vendor),ro=new Te("safari-ime-span"),Wn=!1,df={key:ro,props:{decorations:uf,handleDOMEvents:{compositionstart:()=>{Wn=!0},compositionend:()=>{Wn=!1}}}};function uf(r){const{$from:e,$to:t,to:n}=r.selection;if(Wn&&e.sameParent(t)){const i=v.widget(n,pf,{ignoreSelection:!0,key:"safari-ime-span"});return D.create(r.doc,[i])}}function pf(r){const e=r.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var gh=new Oe(hf?df:{key:ro});const mf=500;class te{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(n,d+1),s=i.maps.length),s--,f.push(h);return}if(i){f.push(new ne(h.map));let u=h.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new ne(p,void 0,void 0,c.length+f.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new te(this.items.slice(0,n).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;f<e.steps.length;f++){let h=e.steps[f].invert(e.docs[f]),d=new ne(e.mapping.maps[f],h,t),u;(u=a&&a.merge(d))&&(d=u,f?s.pop():l=l.slice(0,l.length-1)),s.push(d),t&&(o++,t=void 0),i||(a=d)}let c=o-n.depth;return c>yf&&(l=gf(l,c),o-=c),new te(l.append(s),o)}remapping(e,t){let n=new yt;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new te(this.items.append(e.map(t=>new ne(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let u=s.getMirror(--a);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(d.step){let m=e.steps[u].invert(e.docs[u]),g=d.selection&&d.selection.map(s.slice(a+1,u));g&&l++,n.push(new ne(p,m,g))}else n.push(new ne(p))},i);let c=[];for(let d=t;d<o;d++)c.push(new ne(s.maps[d]));let f=this.items.slice(0,i).append(c).append(n),h=new te(f,l);return h.emptyItemCount()>mf&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(n)),c=a&&a.getMap();if(n--,c&&t.appendMap(c,n),a){let f=o.selection&&o.selection.map(t.slice(n));f&&s++;let h=new ne(c.invert(),a,f),d,u=i.length-1;(d=i.length&&i[u].merge(h))?i[u]=d:i.push(h)}}else o.map&&n--},this.items.length,0),new te(Oi.from(i.reverse()),s)}}te.empty=new te(Oi.empty,0);function gf(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class ne{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ne(t.getMap().invert(),t,this.selection)}}}class ye{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}}const yf=20;function bf(r,e,t,n){let i=t.getMeta(Fe),s;if(i)return i.historyState;t.getMeta(Cf)&&(r=new ye(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Fe))return o.getMeta(Fe).redo?new ye(r.done.addTransform(t,void 0,n,vt(e)),r.undone,ki(t.mapping.maps),r.prevTime,r.prevComposition):new ye(r.done,r.undone.addTransform(t,void 0,n,vt(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!xf(t,r.prevRanges)),c=o?Sn(r.prevRanges,t.mapping):ki(t.mapping.maps);return new ye(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,vt(e)),te.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ye(r.done.rebased(t,s),r.undone.rebased(t,s),Sn(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ye(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Sn(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function xf(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s<e.length;s+=2)n<=e[s+1]&&i>=e[s]&&(t=!0)}),t}function ki(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,s,o)=>e.push(s,o));return e}function Sn(r,e){if(!r)return null;let t=[];for(let n=0;n<r.length;n+=2){let i=e.map(r[n],1),s=e.map(r[n+1],-1);i<=s&&t.push(i,s)}return t}function Sf(r,e,t){let n=vt(e),i=Fe.get(e).spec.config,s=(t?r.undone:r.done).popEvent(e,n);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?r.done:r.undone).addTransform(s.transform,e.selection.getBookmark(),i,n),a=new ye(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Fe,{redo:t,historyState:a})}let Cn=!1,wi=null;function vt(r){let e=r.plugins;if(wi!=e){Cn=!1,wi=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Cn=!0;break}}return Cn}const Fe=new Te("history"),Cf=new Te("closeHistory");function yh(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new Oe({key:Fe,state:{init(){return new ye(te.empty,te.empty,null,0,-1)},apply(e,t,n){return bf(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?kf:n=="historyRedo"?wf:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function io(r,e){return(t,n)=>{let i=Fe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=Sf(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}const kf=io(!1,!0),wf=io(!0,!0);function Mf(r){let e=[[-1,r.state.doc]],t=[];for(;e.length>0;){const[n,i]=e.pop();if(n>=0){let s=r.nodeDOM(n);if(s&&ao(s)){let{top:o,bottom:l,left:a,right:c}=s.getBoundingClientRect();t.push([n,[a,o,c,o]],[n+i.nodeSize,[a,l,c,l]])}}if(i.isBlock&&!i.isTextblock){let s=n+1;for(let o of i.children)e.push([s,o]),s+=o.nodeSize}}return t}function Nf(r,e){let t=[],n,i;const s=()=>{const f=r.dom.getBoundingClientRect(),h=r.state.doc;return t&&n&&i&&f.width===i.width&&f.height===i.height&&f.x===i.x&&f.y===i.y&&n.eq(h)||(i=f,n=h,t=Mf(r)),t},o=(f,h)=>{if(!r.editable||r.isDestroyed)return;const d=(m,g)=>{const[b,N]=m,[O,W]=g;return Ni(f,N)-Ni(f,W)||b-O};let u=s();u.sort(d),u=u.slice(0,8);const p=u.find(m=>e?.({view:r,pos:m[0],event:h})!==!1);if(!(p&&Tf(r,p[0])))return p};let l,a;return(f,h)=>(l&&Of(l,f)||(l=f,a=o(f,h)),a)}function Of(r,e){return r[0]===e[0]&&r[1]===e[1]}function Mi(r,e){return Math.abs(r[0]-e[0])+Math.abs(r[1]-e[1])}function Ni(r,e){return Math.min(Mi(r,[e[0],e[1]]),Mi(r,[e[2],e[3]]))}function Tf(r,e){const t=r.dragging;if(!t)return;const{move:n}=t;if(!n)return;const i=r.state.selection;if(!(i instanceof S))return;const{from:s,to:o}=i;return s<=e&&e<=o}function bh(r){let e;return new Oe({key:new Te("prosekit-drop-indicator"),view:t=>(e=Nf(t,r.onDrag),Af(t,e,r)),props:{handleDrop(t,n,i,s){if(!e)return!1;const o=e([n.clientX,n.clientY],n);if(!o)return!1;n.preventDefault();let l=o[0],a=t.state.tr;if(s){let{node:u}=t.dragging||{};u?u.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=i.openStart==0&&i.openEnd==0&&i.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(h))return!0;let d=a.doc.resolve(c);if(f&&S.isSelectable(i.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new S(d));else{let u=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,b)=>u=b),a.setSelection(Df(t,d,a.doc.resolve(u)))}return t.focus(),t.dispatch(a.setMeta("uiEvent","drop")),!0}}})}function Df(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||k.between(e,t,n)}function Af(r,e,t){let n=r.dom,i,s,o,l=!1;const a=()=>{i&&clearTimeout(i),l=!1,i=setTimeout(()=>{l||t.onHide?.()},30)},c=h=>{l=!0;const{clientX:d,clientY:u}=h;if(s===d&&o===u)return;s=d,o=u;let p=e([d,u],h);if(p){const[m,[g,b,N,O]]=p,W={p1:{x:g,y:b},p2:{x:N,y:O}};t.onShow?.({view:r,pos:m,line:W})}else{a();return}};return n.addEventListener("dragover",c),n.addEventListener("dragend",a),n.addEventListener("drop",a),n.addEventListener("dragleave",a),{destroy:()=>{n.removeEventListener("dragover",c),n.removeEventListener("dragend",a),n.removeEventListener("drop",a),n.removeEventListener("dragleave",a)}}}class E extends C{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return E.valid(n)?new E(n):C.near(n)}content(){return x.empty}eq(e){return e instanceof E&&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 E(e.resolve(t.pos))}getBookmark(){return new ar(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ef(e)||!Rf(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&E.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)<l.childCount:e.index(o)>0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(E.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!S.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),n=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(E.valid(l))return l}return null}}}E.prototype.visible=!1;E.findFrom=E.findGapCursorFrom;C.jsonID("gapcursor",E);class ar{constructor(e){this.pos=e}map(e){return new ar(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return E.valid(t)?new E(t):C.near(t)}}function so(r){return r.isAtom||r.spec.isolating||r.spec.createGapCursor}function Ef(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||so(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Rf(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||so(i.type))return!0;if(i.inlineContent)return!1}}return!0}function xh(){return new Oe({props:{decorations:Pf,createSelectionBetween(r,e,t){return e.pos==t.pos&&E.valid(t)?new E(t):null},handleClick:zf,handleKeyDown:If,handleDOMEvents:{beforeinput:Bf}}})}const If=Xn({ArrowLeft:Rt("horiz",-1),ArrowRight:Rt("horiz",1),ArrowUp:Rt("vert",-1),ArrowDown:Rt("vert",1)});function Rt(r,e){const t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,s){let o=n.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof k){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let c=E.findGapCursorFrom(l,e,a);return c?(i&&i(n.tr.setSelection(new E(c))),!0):!1}}function zf(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!E.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&S.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new E(n))),!0)}function Bf(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof E))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=y.empty;for(let o=n.length-1;o>=0;o--)i=y.from(n[o].createAndFill(null,i));let s=r.state.tr.replace(t.pos,t.pos,new x(i,0,0));return s.setSelection(k.near(s.doc.resolve(t.pos+1))),r.dispatch(s),!1}function Pf(r){if(!(r.selection instanceof E))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",D.create(r.doc,[v.widget(r.selection.head,e,{key:"gapcursor"})])}function Sh(r){var e;const t=(e=void 0)!=null?e:!1;let n=typeof document>"u"?null:document.createElement("div");return new Oe({key:vf,view:i=>{t!==!0&&$f(i.state.schema,t||[]);const s=i.dom.ownerDocument;n=n||document.createElement("div");const o=n,l=()=>{Vf(i,o)};let a;return window.ResizeObserver&&(a=new window.ResizeObserver(()=>l()),a.observe(i.dom)),s.addEventListener("selectionchange",l),{update:()=>{l()},destroy:()=>{s.removeEventListener("selectionchange",l),a&&a.unobserve(i.dom)}}},props:{handleKeyDown:(i,s)=>{var o;const{selection:l}=i.state;if(s.altKey||s.ctrlKey||s.metaKey||s.shiftKey||s.isComposing||!["ArrowLeft","ArrowRight"].includes(s.key)||!Jn(l)||!l.empty)return!1;const a=l.$head,[c,f]=oo(a),h=i.state.storedMarks||a.marks();if(c&&f&&!M.sameSet(c,f)){if(s.key==="ArrowLeft"&&!M.sameSet(c,h))return i.dispatch(i.state.tr.setStoredMarks(c)),!0;if(s.key==="ArrowRight"&&!M.sameSet(f,h))return i.dispatch(i.state.tr.setStoredMarks(f)),!0}return s.key==="ArrowLeft"&&a.textOffset===1?(i.dispatch(i.state.tr.setSelection(k.create(i.state.doc,a.pos-1)).setStoredMarks(a.marks())),!0):s.key==="ArrowRight"&&a.textOffset+1===((o=a.parent.maybeChild(a.index()))==null?void 0:o.nodeSize)?(i.dispatch(i.state.tr.setSelection(k.create(i.state.doc,a.pos+1)).setStoredMarks(a.marks())),!0):!1},decorations:i=>{if(!(!n||!Jn(i.selection)||!i.selection.empty))return D.create(i.doc,[v.widget(0,n,{key:"prosemirror-virtual-cursor"})])},attributes:{class:"virtual-cursor-enabled"}}})}var vf=new Te("prosemirror-virtual-cursor");function Ff(r,e){var t;const n=window.getSelection();if(!n||!n.rangeCount)return null;const i=(t=n?.getRangeAt(0))==null?void 0:t.cloneRange();if(!i)return null;i.collapse(e);const s=i.getClientRects(),o=s?.length?s[s.length-1]:null;return o?.height?o:r.coordsAtPos(r.state.selection.head)}function oo(r){const e=r.index(),t=r.parent.maybeChild(e);let n=r.textOffset?t:null;return!n&&e>0&&(n=r.parent.maybeChild(e-1)),[n?.marks,t?.marks]}function Jn(r){return r&&typeof r=="object"&&"$cursor"in r}function Vf(r,e){if(!r||!r.dom||r.isDestroyed||!e)return;const{state:t,dom:n}=r,{selection:i}=t;if(!Jn(i))return;const s=Ff(r,i.$head===i.$from);if(!s)return e;const o=n.getBoundingClientRect();let l="prosemirror-virtual-cursor";const a=t.selection.$head,[c,f]=oo(a),h=t.storedMarks||a.marks();i.$cursor&&c&&f&&h&&!M.sameSet(c,f)&&(M.sameSet(c,h)?l+=" prosemirror-virtual-cursor-left":M.sameSet(f,h)&&(l+=" prosemirror-virtual-cursor-right")),e.className=l,Lf(e,"prosemirror-virtual-cursor-animation"),e.style.height=`${s.bottom-s.top}px`,e.style.left=`${s.left-o.left}px`,e.style.top=`${s.top-o.top}px`}function Lf(r,e){r.classList.remove(e),r.offsetWidth,r.classList.add(e)}function $f(r,e){for(const[t,n]of Object.entries(r.marks))n.spec.inclusive===!1&&!e.includes(t)&&console.warn(`[prosemirror-virtual-cursor] Virtual cursor does not work well with marks that have inclusive set to false. Please consider removing the inclusive option from the "${t}" mark or adding it to the "skipWarning" option.`)}export{nn as $,Se as A,gh as B,mh as C,mt as D,at as E,y as F,fh as G,pe as H,De as I,dh as J,uh as K,R as L,M,S as N,hh as O,Oe as P,lh as Q,B as R,Hf as S,k as T,ah as U,sh as V,oh as W,rt as X,ch as Y,ph as Z,T as _,Te as a,kf as a0,wf as a1,ml as a2,xh as a3,bh as a4,nt as a5,yh as a6,X as a7,Sh as a8,hc as b,ie as c,Gn as d,Yf as e,as as f,x as g,ur as h,v as i,jf as j,eh as k,D as l,Gf as m,Qf as n,Uf as o,C as p,rh as q,nh as r,fl as s,Xf as t,_f as u,th as v,Zf as w,Yi as x,al as y,ih as z};