@jinntec/jinntap 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jinn-tap.es.js +814 -763
- package/dist/jinn-tap.umd.js +18 -18
- package/package.json +1 -1
package/dist/jinn-tap.umd.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
(function(Ke,P){typeof exports=="object"&&typeof module<"u"?P(exports):typeof define=="function"&&define.amd?define(["exports"],P):(Ke=typeof globalThis<"u"?globalThis:Ke||self,P(Ke.JinnTap={}))})(this,function(Ke){"use strict";function P(r){this.content=r}P.prototype={constructor:P,find:function(r){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===r)return e;return-1},get:function(r){var e=this.find(r);return e==-1?void 0:this.content[e+1]},update:function(r,e,t){var n=t&&t!=r?this.remove(t):this,i=n.find(r),s=n.content.slice();return i==-1?s.push(t||r,e):(s[i+1]=e,t&&(s[i]=t)),new P(s)},remove:function(r){var e=this.find(r);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new P(t)},addToStart:function(r,e){return new P([r,e].concat(this.remove(r).content))},addToEnd:function(r,e){var t=this.remove(r).content.slice();return t.push(r,e),new P(t)},addBefore:function(r,e,t){var n=this.remove(e),i=n.content.slice(),s=n.find(r);return i.splice(s==-1?i.length:s,0,e,t),new P(i)},forEach:function(r){for(var e=0;e<this.content.length;e+=2)r(this.content[e],this.content[e+1])},prepend:function(r){return r=P.from(r),r.size?new P(r.content.concat(this.subtract(r).content)):this},append:function(r){return r=P.from(r),r.size?new P(this.subtract(r).content.concat(r.content)):this},subtract:function(r){var e=this;r=P.from(r);for(var t=0;t<r.content.length;t+=2)e=e.remove(r.content[t]);return e},toObject:function(){var r={};return this.forEach(function(e,t){r[e]=t}),r},get size(){return this.content.length>>1}},P.from=function(r){if(r instanceof P)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new P(e)};function Ar(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=Ar(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function vr(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,u=Math.min(o.text.length,l.text.length);for(;c<u&&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=vr(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}class b{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 u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),n,i+u)}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 b(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 b(n,i)}cutByIndex(e,t){return e==t?b.empty:e==0&&t==this.content.length?this:new b(this.content.slice(e,t))}replaceChild(e,t){let 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 b(i,s)}addToStart(e){return new b([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new b(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;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 Ar(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return vr(this,e,t,n)}findIndex(e,t=-1){if(e==0)return At(0,e);if(e==this.size)return At(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),o=i+s.nodeSize;if(o>=e)return o==e||t>0?At(n+1,o):At(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return b.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new b(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return b.empty;let t,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 b(t||e,n)}static from(e){if(!e)return b.empty;if(e instanceof b)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new b([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}b.empty=new b([],0);const yn={index:0,offset:0};function At(r,e){return yn.index=r,yn.offset=e,yn}function vt(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(!vt(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!vt(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}let D=class Er{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&&vt(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 Er.none;if(e instanceof Er)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}};D.none=[];class Dt extends Error{}class k{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=Ir(this.content,e+this.openStart,t);return n&&new k(n,this.openStart,this.openEnd)}removeBetween(e,t){return new k(Dr(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 k.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 k(b.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 k(e,n,i)}}k.empty=new k(b.empty,0,0);function Dr(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(Dr(s.content,e-i-1,t-i-1)))}function Ir(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return r.cut(0,e).append(t).append(r.cut(e));let l=Ir(o.content,e-s-1,t);return l&&r.replaceChild(i,o.copy(l))}function Do(r,e,t){if(t.openStart>r.depth)throw new Dt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Dt("Inconsistent open depths");return Pr(r,e,t,0)}function Pr(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=Pr(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 Ie(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Io(t,r);return Ie(s,Br(r,o,l,e,n))}else return Ie(s,It(r,e,n))}function Rr(r,e){if(!e.type.compatibleContent(r.type))throw new Dt("Cannot join "+e.type.name+" onto "+r.type.name)}function bn(r,e,t){let n=r.node(t);return Rr(n,e.node(t)),n}function De(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 lt(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&&(De(r.nodeAfter,n),s++));for(let l=s;l<o;l++)De(i.child(l),n);e&&e.depth==t&&e.textOffset&&De(e.nodeBefore,n)}function Ie(r,e){return r.type.checkContent(e),r.copy(e)}function Br(r,e,t,n,i){let s=r.depth>i&&bn(r,e,i+1),o=n.depth>i&&bn(t,n,i+1),l=[];return lt(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Rr(s,o),De(Ie(s,Br(r,e,t,n,i+1)),l)):(s&&De(Ie(s,It(r,e,i+1)),l),lt(e,t,i,l),o&&De(Ie(o,It(t,n,i+1)),l)),lt(n,null,i,l),new b(l)}function It(r,e,t){let n=[];if(lt(null,r,t,n),r.depth>t){let i=bn(r,e,t+1);De(Ie(i,It(r,e,t+1)),n)}return lt(e,null,t,n),new b(n)}function Io(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(b.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}class at{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 D.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 Pt(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 at(t,n,s)}static resolveCached(e,t){let n=zr.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 zr.set(e,n=new Po);let i=n.elts[n.i]=at.resolve(e,t);return n.i=(n.i+1)%Ro,i}}class Po{constructor(){this.elts=[],this.i=0}}const Ro=12,zr=new WeakMap;class Pt{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 Bo=Object.create(null);let ye=class Tr{constructor(e,t,n,i=D.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||b.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&&vt(this.attrs,t||e.defaultAttrs||Bo)&&D.sameSet(this.marks,n||D.none)}copy(e=null){return e==this.content?this:new Tr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Tr(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 k.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 k(c,i.depth-o,s.depth-o)}replace(e,t,n){return Do(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 at.resolveCached(this,e)}resolveNoCache(e){return at.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()+")"),Fr(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=b.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=D.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(!D.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=b.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,n);return s.type.checkAttrs(s.attrs),s}};ye.prototype.text=void 0;class Rt extends ye{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):Fr(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 Rt(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Rt(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 Fr(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}class Pe{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new zo(e,t);if(n.next==null)return Pe.empty;let i=Lr(n);n.next&&n.err("Unexpected trailing text");let s=Ho(Wo(i));return Jo(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 b.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:u,next:d}=o.next[c];if(!(u.isText||u.hasRequiredAttrs())&&i.indexOf(d)==-1){i.push(d);let f=s(d,l.concat(u));if(f)return f}}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(`
|
|
2
|
-
`)}}Pe.empty=new Pe(!0);class zo{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 Lr(r){let e=[];do e.push(Fo(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Fo(r){let e=[];do e.push(Lo(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Lo(r){let e=jo(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=$o(r,e);else break;return e}function $r(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function $o(r,e){let t=$r(r),n=t;return r.eat(",")&&(r.next!="}"?n=$r(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Vo(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 jo(r){if(r.eat("(")){let e=Lr(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=Vo(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 u=t();i(s(o.expr,a),u),a=u}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let u=t();n(a,u),i(s(o.expr,a),u),a=u}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Vr(r,e){return e-r}function jr(r,e){let t=[];return n(e),t.sort(Vr);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 Ho(r){let e=Object.create(null);return t(jr(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u<i.length;u++)i[u][0]==l&&(c=i[u][1]);jr(r,a).forEach(u=>{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[n.join(",")]=new Pe(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Vr);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function Jo(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 Wr(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 Hr(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 Jr(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 qr(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new Ko(r,n,e[n]);return t}let Kr=class vo{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=qr(e,n.attrs),this.defaultAttrs=Wr(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==Pe.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:Hr(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ye(this,this.computeAttrs(e),b.from(t),D.setFrom(n))}createChecked(e=null,t,n){return t=b.from(t),this.checkContent(t),new ye(this,this.computeAttrs(e),t,D.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=b.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(b.empty,!0);return s?new ye(this,e,t.append(s),D.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){Jr(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:D.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new vo(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 qo(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 Ko{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?qo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Bt{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=qr(e,i.attrs),this.excluded=null;let s=Wr(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,Hr(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Bt(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){Jr(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Ur{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=P.from(e.nodes),t.marks=P.from(e.marks||{}),this.nodes=Kr.compile(this.spec.nodes,this),this.marks=Bt.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]=Pe.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?_r(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==""?[]:_r(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Kr){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 Rt(n,n.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return ye.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function _r(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 Uo(r){return r.tag!=null}function _o(r){return r.style!=null}let ct=class Or{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(Uo(i))this.tags.push(i);else if(_o(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 Zr(this,t,!1);return n.addAll(e,D.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Zr(this,t,!0);return n.addAll(e,D.none,t.from,t.to),k.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(Xo(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=Qr(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=Qr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Or(e,Or.schemaRules(e)))}};const Gr={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},Go={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Yr={ol:!0,ul:!0},ut=1,kn=2,zt=4;function Xr(r,e,t){return e!=null?(e?ut:0)|(e==="full"?kn:0):r&&r.whitespace=="pre"?ut|kn:t&-5}class Ft{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=D.none,this.match=s||(o&zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(b.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let 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&ut)){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=b.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(b.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Gr.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Zr{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=Xr(null,t.preserveWhitespace,0)|(n?zt:0);i?s=new Ft(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ft(null,null,D.none,!0,null,o):s=new Ft(e.schema.topNodeType,null,D.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&kn?"full":this.localPreserveWS||(i.options&ut)>0;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)s!=="full"?n=n.replace(/\r?\n|\r/g," "):n=n.replace(/\r\n?/g,`
|
|
3
|
-
`);else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t),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;Yr.hasOwnProperty(o)&&this.parser.normalizeLists&&
|
|
4
|
-
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let 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)||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));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){let n,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,i=o,!l.length)||o.solid)break}if(!n)return null;this.sync(i);for(let s=0;s<n.length;s++)t=this.enterInner(n[s],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let i=this.textblockFromContext();i&&(t=this.enterInner(i,null,t))}let n=this.findPlace(e,t);if(n){this.closeExtra();let i=this.top;i.match&&(i.match=i.match.matchType(e.type));let s=D.none;for(let o of n.concat(e.marks))(i.type?i.type.allowsMarkType(o.type):ei(o.type,e.type))&&(s=o.addToSet(s));return i.content.push(e.mark(s)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n);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=Xr(e,s,o.options);o.options&zt&&o.content.length==0&&(l|=zt);let a=D.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):ei(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ft(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|=ut)}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 u=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!u||u.name!=c&&!u.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 Yo(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Yr.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Xo(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function Qr(r){let e={};for(let t in r)e[t]=r[t];return e}function ei(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:u}=l.edge(a);if(c==e||s.indexOf(u)<0&&o(u))return!0}};if(o(i.contentMatch))return!0}}class Re{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=xn(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++],u=this.serializeMark(c,o.isInline,t);u&&(s.push([c,i]),i.appendChild(u.dom),i=u.contentDOM||u.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=Lt(xn(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&&Lt(xn(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return Lt(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Re(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ti(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return ti(e.marks)}}function ti(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function xn(r){return r.document||window.document}const ni=new WeakMap;function Zo(r){let e=ni.get(r);return e===void 0&&ni.set(r,e=Qo(r)),e}function Qo(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 Lt(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],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let d in c)if(c[d]!=null){let f=d.indexOf(" ");f>0?a.setAttributeNS(d.slice(0,f),d.slice(f+1),c[d]):a.setAttribute(d,c[d])}}for(let d=u;d<e.length;d++){let f=e[d];if(f===0){if(d<e.length-1||d>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:p}=Lt(r,f,t,n);if(a.appendChild(h),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const ri=65535,ii=Math.pow(2,16);function el(r,e){return r+e*ii}function si(r){return r&ri}function tl(r){return(r-(r&ri))/ii}const oi=1,li=2,$t=4,ai=8;class Sn{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ai)>0}get deletedBefore(){return(this.delInfo&(oi|$t))>0}get deletedAfter(){return(this.delInfo&(li|$t))>0}get deletedAcross(){return(this.delInfo&$t)>0}}class X{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&X.empty)return X.empty}recover(e){let t=0,n=si(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+tl(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],u=this.ranges[l+o],d=a+c;if(e<=d){let f=c?e==a?-1:e==d?1:t:t,h=a+i+(f<0?0:u);if(n)return h;let p=e==(t<0?a:d)?null:el(l/3,e-a),m=e==a?li:e==d?oi:$t;return(t<0?e!=a:e!=d)&&(m|=ai),new Sn(h,m,p)}i+=u-c}return n?e+i:new Sn(e+i,0,null)}touches(e,t){let n=0,i=si(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],u=a+c;if(e<=u&&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],u=this.ranges[i+n];e(l,l+c,a,a+u),s+=u-c}}invert(){return new X(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?X.empty:new X(e<0?[0,-e,0]:[0,0,e])}}X.empty=new X([]);class dt{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 dt(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 dt;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 Sn(e,i,null)}}const Cn=Object.create(null);class W{getMap(){return X.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=Cn[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 Cn)throw new RangeError("Duplicate use of step JSON ID "+e);return Cn[e]=t,t.prototype.jsonID=e,t}}class R{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new R(e,null)}static fail(e){return new R(null,e)}static fromReplace(e,t,n,i){try{return R.ok(e.replace(t,n,i))}catch(s){if(s instanceof Dt)return R.fail(s.message);throw s}}}function wn(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(wn(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return b.fromArray(n)}class be extends W{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 k(wn(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 R.fromReplace(e,this.from,this.to,s)}invert(){return new ae(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 be(t.pos,n.pos,this.mark)}merge(e){return e instanceof be&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new be(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 be(t.from,t.to,e.markFromJSON(t.mark))}}W.jsonID("addMark",be);class ae extends W{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 k(wn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return R.fromReplace(e,this.from,this.to,n)}invert(){return new be(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 ae(t.pos,n.pos,this.mark)}merge(e){return e instanceof ae&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ae(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 ae(t.from,t.to,e.markFromJSON(t.mark))}}W.jsonID("removeMark",ae);class ke extends W{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return R.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return R.fromReplace(e,this.pos,this.pos+1,new k(b.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 ke(this.pos,t.marks[i]);return new ke(this.pos,this.mark)}}return new Ue(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new ke(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 ke(t.pos,e.markFromJSON(t.mark))}}W.jsonID("addNodeMark",ke);class Ue extends W{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return R.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return R.fromReplace(e,this.pos,this.pos+1,new k(b.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new ke(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ue(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 Ue(t.pos,e.markFromJSON(t.mark))}}W.jsonID("removeNodeMark",Ue);class B extends W{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&Mn(e,this.from,this.to)?R.fail("Structure replace would overwrite content"):R.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new X([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)}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?k.empty:new k(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?k.empty:new k(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,k.fromJSON(e,t.slice),!!t.structure)}}W.jsonID("replace",B);class F extends W{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&&(Mn(e,this.from,this.gapFrom)||Mn(e,this.gapTo,this.to)))return R.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return R.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?R.fromReplace(e,this.from,this.to,n):R.fail("Content does not fit in gap")}getMap(){return new X([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 F(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 F(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 F(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}}W.jsonID("replaceAround",F);function Mn(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 nl(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,c,u)=>{if(!a.isInline)return;let d=a.marks;if(!n.isInSet(d)&&u.type.allowsMarkType(n.type)){let f=Math.max(c,e),h=Math.min(c+a.nodeSize,t),p=n.addToSet(d);for(let m=0;m<d.length;m++)d[m].isInSet(p)||(o&&o.to==f&&o.mark.eq(d[m])?o.to=h:i.push(o=new ae(f,h,d[m])));l&&l.to==f?l.to=h:s.push(l=new be(f,h,n))}}),i.forEach(a=>r.step(a)),s.forEach(a=>r.step(a))}function rl(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 Bt){let c=o.marks,u;for(;u=n.isInSet(c);)(a||(a=[])).push(u),c=u.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 u=0;u<a.length;u++){let d=a[u],f;for(let h=0;h<i.length;h++){let p=i[h];p.step==s-1&&d.eq(i[h].style)&&(f=p)}f?(f.to=c,f.step=s):i.push({style:d,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new ae(o.from,o.to,o.style)))}function En(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),u=l+c.nodeSize,d=n.matchType(c.type);if(!d)o.push(new B(l,u,k.empty));else{n=d;for(let f=0;f<c.marks.length;f++)t.allowsMarkType(c.marks[f].type)||r.step(new ae(l,u,c.marks[f]));if(i&&c.isText&&t.whitespace!="pre"){let f,h=/\r?\n|\r/g,p;for(;f=h.exec(c.text);)p||(p=new k(b.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new B(l+f.index,l+f.index+f[0].length,p))}}l=u}if(!n.validEnd){let a=n.fillBefore(b.empty,!0);r.replace(l,l,new k(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function il(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function _e(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth;;--n){let i=r.$from.node(n),s=r.$from.index(n),o=r.$to.indexAfter(n);if(n<r.depth&&i.canReplace(s,o,t))return n;if(n==0||i.type.spec.isolating||!il(i,s,o))break}return null}function sl(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,u=b.empty,d=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,u=b.from(n.node(p).copy(u)),d++):a--;let f=b.empty,h=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)<i.end(p)?(m=!0,f=b.from(i.node(p).copy(f)),h++):c++;r.step(new F(a,c,o,l,new k(u.append(f),d,h),u.size-d,!0))}function ci(r,e,t=null,n=r){let i=ol(r,e),s=i&&ll(n,e);return s?i.map(ui).concat({type:e,attrs:t}).concat(s.map(ui)):null}function ui(r){return{type:r,attrs:null}}function ol(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 ll(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 al(r,e,t){let n=b.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=b.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new F(i,s,i,s,new k(n,0,0),t.length,!0))}function cl(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)&&ul(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let h=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);h&&!p?c=!1:!h&&p&&(c=!0)}c===!1&&fi(r,o,l,s),En(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let u=r.mapping.slice(s),d=u.map(l,1),f=u.map(l+o.nodeSize,1);return r.step(new F(d,f,d+1,f-1,new k(b.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&di(r,o,l,s),!1}})}function di(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 fi(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(`
|
|
5
|
-
`))}})}function ul(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function dl(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 F(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new k(b.from(o),0,0),1,!0))}function fe(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,u=t-2;c>s;c--,u--){let d=i.node(c),f=i.index(c);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=n&&n[u+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[u]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(h))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 fl(r,e,t=1,n){let i=r.doc.resolve(e),s=b.empty,o=b.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=b.from(i.node(l).copy(s));let u=n&&n[c];o=b.from(u?u.type.create(u.attrs,o):i.node(l).copy(o))}r.step(new B(e,e,new k(s.append(o),t,t),!0))}function Be(r,e){let t=r.resolve(e),n=t.index();return hi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function hl(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 hi(r,e){return!!(r&&e&&!r.isLeaf&&hl(r,e))}function Vt(r,e,t=-1){let n=r.resolve(e);for(let i=n.depth;;i--){let s,o,l=n.index(i);if(i==n.depth?(s=n.nodeBefore,o=n.nodeAfter):t>0?(s=n.node(i+1),l++,o=n.node(i).maybeChild(l)):(s=n.node(i).maybeChild(l-1),o=n.node(i+1)),s&&!s.isTextblock&&hi(s,o)&&n.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?n.before(i):n.after(i)}}function pl(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 u=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);u&&!d?n=!1:!u&&d&&(n=!0)}let l=r.steps.length;if(n===!1){let u=r.doc.resolve(e+t);fi(r,u.node(),u.before(),l)}o.inlineContent&&En(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),k.empty,!0)),n===!0){let u=r.doc.resolve(c);di(r,u.node(),u.before(),r.steps.length)}return r}function ml(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 gl(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),u=!1;if(s==1)u=c.canReplace(a,a,i);else{let d=c.contentMatchAt(a).findWrapping(i.firstChild.type);u=d&&c.canReplaceWith(a,a,d[0])}if(u)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function jt(r,e,t=e,n=k.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return pi(i,s,n)?new B(e,t,n):new yl(i,s,n).fit()}function pi(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class yl{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=b.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=b.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,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 k(s,o,l);return e>-1?new F(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=Tn(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],u,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(b.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(u=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:u};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Tn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(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=Tn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new k(ft(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new k(ft(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,u=[],{match:d,type:f}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)u.push(i.child(m));d=d.matchFragment(i)}let h=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=d.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(d=g,u.push(mi(m.mark(f.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?h:-1)))}let p=c==l.childCount;p||(h=-1),this.placed=ht(this.placed,t,b.from(u)),this.frontier[t].match=d,p&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<h;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=p?e==0?k.empty:new k(ft(o.content,e-1,1),e-1,h<0?o.openEnd:e-1):new k(ft(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||!On(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=On(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],u=On(e,l,c,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ht(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=ht(this.placed,this.depth,b.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(b.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}}function ft(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(ft(r.firstChild.content,e-1,t)))}function ht(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ht(r.lastChild.content,e-1,t)))}function Tn(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function mi(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,mi(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(b.empty,!0)))),r.copy(n)}function On(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&&!bl(t,s.content,o)?l:null}function bl(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function kl(r){return r.spec.defining||r.spec.definingForContent}function xl(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(pi(i,s,n))return r.step(new B(e,t,n));let o=yi(i,r.doc.resolve(t));o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let f=i.depth,h=i.pos-1;f>0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==h&&o.splice(1,0,-f)}let a=o.indexOf(l),c=[],u=n.openStart;for(let f=n.content,h=0;;h++){let p=f.firstChild;if(c.push(p),h==n.openStart)break;f=p.content}for(let f=u-1;f>=0;f--){let h=c[f],p=kl(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))u=f;else if(p||!h.type.isTextblock)break}for(let f=n.openStart;f>=0;f--){let h=(f+u+1)%(n.openStart+1),p=c[h];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let S=i.node(g-1),w=i.index(g-1);if(S.canReplaceWith(w,w,p.type,p.marks))return r.replace(i.before(g),y?s.after(g):t,new k(gi(n.content,0,n.openStart,h),h,n.openEnd))}}let d=r.steps.length;for(let f=o.length-1;f>=0&&(r.replace(e,t,n),!(r.steps.length>d));f--){let h=o[f];h<0||(e=i.before(h),t=s.after(h))}}function gi(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(gi(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(b.empty,!0))}return r}function Sl(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=ml(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new k(b.from(n),0,0))}function Cl(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=yi(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 yi(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 Ge extends W{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 R.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 R.fromReplace(e,this.pos,this.pos+1,new k(b.from(i),0,t.isLeaf?0:1))}getMap(){return X.empty}invert(e){return new Ge(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 Ge(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 Ge(t.pos,t.attr,t.value)}}W.jsonID("attr",Ge);class pt extends W{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 R.ok(n)}getMap(){return X.empty}invert(e){return new pt(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 pt(t.attr,t.value)}}W.jsonID("docAttr",pt);let Ye=class extends Error{};Ye=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t},Ye.prototype=Object.create(Error.prototype),Ye.prototype.constructor=Ye,Ye.prototype.name="TransformError";class wl{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new dt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ye(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=k.empty){let i=jt(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new k(b.from(n),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return xl(this,e,t,n),this}replaceRangeWith(e,t,n){return Sl(this,e,t,n),this}deleteRange(e,t){return Cl(this,e,t),this}lift(e,t){return sl(this,e,t),this}join(e,t=1){return pl(this,e,t),this}wrap(e,t){return al(this,e,t),this}setBlockType(e,t=e,n,i=null){return cl(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return dl(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Ge(e,t,n)),this}setDocAttribute(e,t){return this.step(new pt(e,t)),this}addNodeMark(e,t){return this.step(new ke(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t=t.isInSet(n.marks),!t)return this}return this.step(new Ue(e,t)),this}split(e,t=1,n){return fl(this,e,t,n),this}addMark(e,t,n){return nl(this,e,t,n),this}removeMark(e,t,n){return rl(this,e,t,n),this}clearIncompatible(e,t,n){return En(this,e,t,n),this}}const Nn=Object.create(null);class O{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Ml(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=k.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],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(c.pos),l?k.empty:t),l==0&&xi(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),u=a.map(l.pos);s?e.deleteRange(c,u):(e.replaceRangeWith(c,u,t),xi(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new E(e):Xe(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?Xe(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Xe(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 Z(e.node(0))}static atStart(e){return Xe(e,e,0,0,1)||new Z(e)}static atEnd(e){return Xe(e,e,e.content.size,e.childCount,-1)||new Z(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Nn[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 Nn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Nn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return E.between(this.$anchor,this.$head).getBookmark()}}O.prototype.visible=!0;class Ml{constructor(e,t){this.$from=e,this.$to=t}}let bi=!1;function ki(r){!bi&&!r.parent.inlineContent&&(bi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class E extends O{constructor(e,t=e){ki(e),ki(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 O.near(n);let i=e.resolve(t.map(this.anchor));return new E(i.parent.inlineContent?i:n,n)}replace(e,t=k.empty){if(super.replace(e,t),t==k.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof E&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Wt(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new E(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,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=O.findFrom(t,n,!0)||O.findFrom(t,-n,!0);if(s)t=s.$head;else return O.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(O.findFrom(e,-n,!0)||O.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new E(e,t)}}O.jsonID("text",E);class Wt{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Wt(e.map(this.anchor),e.map(this.head))}resolve(e){return E.between(e.resolve(this.anchor),e.resolve(this.head))}}class C extends O{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?O.near(s):new C(s)}content(){return new k(b.from(this.node),0,0)}eq(e){return e instanceof C&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new An(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new C(e.resolve(t.anchor))}static create(e,t){return new C(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}C.prototype.visible=!1,O.jsonID("node",C);class An{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Wt(n,n):new An(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&C.isSelectable(n)?new C(t):O.near(t)}}class Z extends O{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=k.empty){if(t==k.empty){e.delete(0,e.doc.content.size);let n=O.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Z(e)}map(e){return new Z(e)}eq(e){return e instanceof Z}getBookmark(){return El}}O.jsonID("all",Z);const El={map(){return this},resolve(r){return new Z(r)}};function Xe(r,e,t,n,i,s=!1){if(e.inlineContent)return E.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&&C.isSelectable(l))return C.create(r,t-(i<0?l.nodeSize:0))}else{let a=Xe(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function xi(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof B||i instanceof F))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,u)=>{o==null&&(o=u)}),r.setSelection(O.near(r.doc.resolve(o),t))}const Si=1,Ci=2,wi=4;class Tl extends wl{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|Si)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&Si)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ci,this}ensureMarks(e){return D.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&Ci)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&-3,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)||D.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),n=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.setSelection(O.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|=wi,this}get scrolledIntoView(){return(this.updated&wi)>0}}function Mi(r,e){return!e||!r?r:r.bind(e)}class mt{constructor(e,t,n){this.name=e,this.init=Mi(t.init,n),this.apply=Mi(t.apply,n)}}const Ol=[new mt("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new mt("selection",{init(r,e){return r.selection||O.atStart(e.doc)},apply(r){return r.selection}}),new mt("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new mt("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class vn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ol.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 mt(n.key,n.spec.state,n))})}}class Ze{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,u=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(u&&n.filterTransaction(u,o)){if(u.setMeta("appendedTransaction",e),!i){i=[];for(let d=0;d<this.config.plugins.length;d++)i.push(d<o?{state:n,n:t.length}:{state:this,n:0})}t.push(u),n=n.applyInner(u),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 Ze(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 Tl(this)}static create(e){let t=new vn(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Ze(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 vn(this.schema,e.plugins),n=t.fields,i=new Ze(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 vn(e.schema,e.plugins),s=new Ze(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ye.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=O.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 Ei(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=Ei(i,e,{})),t[n]=i}return t}class Q{constructor(e){this.spec=e,this.props={},e.props&&Ei(e.props,this,this.props),this.key=e.key?e.key.key:Ti("plugin")}getState(e){return e[this.key]}}const Dn=Object.create(null);function Ti(r){return r in Dn?r+"$"+ ++Dn[r]:(Dn[r]=0,r+"$")}class se{constructor(e="key"){this.key=Ti(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const V=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 In=null;const he=function(r,e,t){let n=In||(In=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Nl=function(){In=null},ze=function(r,e,t,n){return t&&(Oi(r,e,t,n,-1)||Oi(r,e,t,n,1))},Al=/^(img|br|input|textarea|hr)$/i;function Oi(r,e,t,n,i){for(;;){if(r==t&&e==n)return!0;if(e==(i<0?0:ee(r))){let s=r.parentNode;if(!s||s.nodeType!=1||gt(r)||Al.test(r.nodeName)||r.contentEditable=="false")return!1;e=V(r)+(i<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(i<0?-1:0)],r.contentEditable=="false")return!1;e=i<0?ee(r):0}else return!1}}function ee(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function vl(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=ee(r)}else if(r.parentNode&&!gt(r))e=V(r),r=r.parentNode;else return null}}function Dl(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&&!gt(r))e=V(r)+1,r=r.parentNode;else return null}}function Il(r,e,t){for(let n=e==0,i=e==ee(r);n||i;){if(r==t)return!0;let s=V(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==ee(r)}}function gt(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 Ht=function(r){return r.focusNode&&ze(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Fe(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function Pl(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Rl(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(ee(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(ee(n.startContainer),n.startOffset)}}}const ce=typeof navigator<"u"?navigator:null,Ni=typeof document<"u"?document:null,xe=ce&&ce.userAgent||"",Pn=/Edge\/(\d+)/.exec(xe),Ai=/MSIE \d/.exec(xe),Rn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(xe),G=!!(Ai||Rn||Pn),Se=Ai?document.documentMode:Rn?+Rn[1]:Pn?+Pn[1]:0,oe=!G&&/gecko\/(\d+)/i.test(xe);oe&&+(/Firefox\/(\d+)/.exec(xe)||[0,0])[1];const Bn=!G&&/Chrome\/(\d+)/.exec(xe),H=!!Bn,vi=Bn?+Bn[1]:0,K=!G&&!!ce&&/Apple Computer/.test(ce.vendor),et=K&&(/Mobile\/\w+/.test(xe)||!!ce&&ce.maxTouchPoints>2),te=et||(ce?/Mac/.test(ce.platform):!1),Bl=ce?/Win/.test(ce.platform):!1,pe=/Android \d/.test(xe),yt=!!Ni&&"webkitFontSmoothing"in Ni.documentElement.style,zl=yt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Fl(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 me(r,e){return typeof r=="number"?r:r[e]}function Ll(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 Di(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?Fl(s):Ll(l),u=0,d=0;if(e.top<c.top+me(n,"top")?d=-(c.top-e.top+me(i,"top")):e.bottom>c.bottom-me(n,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+me(i,"top")-c.top:e.bottom-c.bottom+me(i,"bottom")),e.left<c.left+me(n,"left")?u=-(c.left-e.left+me(i,"left")):e.right>c.right-me(n,"right")&&(u=e.right-c.right+me(i,"right")),u||d)if(a)s.defaultView.scrollBy(u,d);else{let h=l.scrollLeft,p=l.scrollTop;d&&(l.scrollTop+=d),u&&(l.scrollLeft+=u);let m=l.scrollLeft-h,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let f=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:Qe(o)}}function $l(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:Ii(r.dom)}}function Ii(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 Vl({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;Pi(t,n==0?0:n-e)}function Pi(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 tt=null;function jl(r){if(r.setActive)return r.setActive();if(tt)return r.focus(tt);let e=Ii(r);r.focus(tt==null?{get preventScroll(){return tt={preventScroll:!0},!0}}:void 0),tt||(tt=!1,Pi(e,0))}function Ri(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let u=r.firstChild,d=0;u;u=u.nextSibling,d++){let f;if(u.nodeType==1)f=u.getClientRects();else if(u.nodeType==3)f=he(u).getClientRects();else continue;for(let h=0;h<f.length;h++){let p=f[h];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=u,n=m,i=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,u.nodeType==1&&m&&(s=d+(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=u,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,n=0),t&&t.nodeType==3?Wl(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:Ri(t,i)}function Wl(r,e){let t=r.nodeValue.length,n=document.createRange();for(let i=0;i<t;i++){n.setEnd(r,i+1),n.setStart(r,i);let s=Ce(n,1);if(s.top!=s.bottom&&zn(e,s))return{node:r,offset:i+(e.left>=(s.left+s.right)/2?1:0)}}return{node:r,offset:0}}function zn(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}=Ri(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 ql(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&&(!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 Bi(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(zn(e,c))return Bi(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function Kl(r,e){let t=r.dom.ownerDocument,n,i=0,s=Rl(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(!zn(e,c)||(o=Bi(r.dom,e,c),!o))return null}if(K)for(let c=o;n&&c;c=Qe(c))c.draggable&&(n=void 0);if(o=Hl(o,e),n){if(oe&&n.nodeType==1&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let u=n.childNodes[i],d;u.nodeName=="IMG"&&(d=u.getBoundingClientRect()).right<=e.left&&d.bottom>e.top&&i++}let c;yt&&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=ql(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 zi(r){return r.top<r.bottom||r.left<r.right}function Ce(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(zi(n))return n}return Array.prototype.find.call(t,zi)||r.getBoundingClientRect()}const Ul=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Fi(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=yt||oe;if(n.nodeType==3)if(o&&(Ul.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=Ce(he(n,i,i),t);if(oe&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=Ce(he(n,i-1,i-1),-1);if(c.top==a.top){let u=Ce(he(n,i,i+1),-1);if(u.top!=a.top)return bt(u,u.left<c.left)}}return a}else{let a=i,c=i,u=t<0?1:-1;return t<0&&!i?(c++,u=-1):t>=0&&i==n.nodeValue.length?(a--,u=1):t<0?a--:c++,bt(Ce(he(n,a,c),u),u<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==ee(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return Fn(a.getBoundingClientRect(),!1)}if(s==null&&i<ee(n)){let a=n.childNodes[i];if(a.nodeType==1)return Fn(a.getBoundingClientRect(),!0)}return Fn(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==ee(n))){let a=n.childNodes[i-1],c=a.nodeType==3?he(a,ee(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return bt(Ce(c,1),!1)}if(s==null&&i<ee(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?he(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return bt(Ce(c,-1),!0)}return bt(Ce(n.nodeType==3?he(n):n,-t),t>=0)}function bt(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 Fn(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 Li(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 _l(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return Li(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=Fi(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=he(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let u=a[c];if(u.bottom>u.top+1&&(t=="up"?o.top-u.top>(u.bottom-o.top)*2:u.bottom-o.bottom>(o.bottom-u.top)*2))return!1}}return!0})}const Gl=/[\u0590-\u08ac]/;function Yl(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?!Gl.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Li(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:d}=r.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let h=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:p,focusOffset:m}=r.domSelectionRange(),g=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(u,d),a&&(a!=u||c!=d)&&l.extend&&l.extend(a,c)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):n.pos==n.start()||n.pos==n.end()}let $i=null,Vi=null,ji=!1;function Xl(r,e,t){return $i==e&&Vi==t?ji:($i=e,Vi=t,ji=t=="up"||t=="down"?_l(r,e,t):Yl(r,e,t))}const ne=0,Wi=1,Le=2,ue=3;class kt{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=ne,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>V(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 qi){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 Hi&&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?V(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?V(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 u=o+a.border;if(e>=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=V(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;u<this.children.length;u++){let d=this.children[u];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(-1)){s=V(d.dom);break}t+=d.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 h=0,p=0;h<this.children.length;h++){let m=this.children[h],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(),u=n.domSelectionRange(),d=!1;if((oe||K)&&e==t){let{node:h,offset:p}=l;if(h.nodeType==3){if(d=!!(p&&h.nodeValue[p-1]==`
|
|
6
|
-
`),d&&p==h.nodeValue.length)for(let m=h,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:V(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=h.childNodes[p-1];d=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(oe&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(i=!0)}if(!(i||d&&K)&&ze(l.node,l.offset,u.anchorNode,u.anchorOffset)&&ze(a.node,a.offset,u.focusNode,u.focusOffset))return;let f=!1;if((c.extend||e==t)&&!d){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),f=!0}catch{}}if(!f){if(e>t){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}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?Le:Wi,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ue:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Le:ue}n=o}this.dirty=Le}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Le:Wi;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class Hi extends kt{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==ne&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class Zl extends kt{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 $e extends kt{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=Re.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new $e(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ue||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ue&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ne){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=ne}}slice(e,t,n){let i=$e.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=$n(s,t,o,n)),e>0&&(s=$n(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 we extends kt{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),u=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:d}=Re.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let f=u;return u=_i(u,n,t),c?a=new Ql(e,t,n,i,u,d||null,f,c,s,o+1):t.isText?new Jt(e,t,n,i,u,f,s):new we(e,t,n,i,u,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>b.empty)}return e}matchesNode(e,t,n){return this.dirty==ne&&e.eq(this.node)&&qt(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 ta(this,o&&o.node,e);ia(this.node,this.innerDeco,(c,u,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,n,e):c.type.side>=0&&!d&&a.syncToMarks(u==this.node.childCount?D.none:this.node.child(u).marks,n,e),a.placeWidget(c,e,i)},(c,u,d,f)=>{a.syncToMarks(c.marks,n,e);let h;a.findNodeMatch(c,u,d,f)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(h=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,u,d,h,e)||a.updateNextNode(c,u,d,e,f,i)||a.addNode(c,u,d,e,i),i+=c.nodeSize}),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Le)&&(o&&this.protectLocalComposition(e,o),Ki(this.contentDOM,this.children,e),et&&sa(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof E)||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=oa(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 Zl(this,s,t,i);e.input.compositionNodes.push(o),this.children=$n(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==ue||!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=ne}updateOuterDeco(e){if(qt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Ui(this.dom,this.nodeDOM,Ln(this.outerDeco,this.node,t),Ln(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.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ji(r,e,t,n,i){_i(n,e,r);let s=new we(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Jt extends we{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==ue||this.dirty!=ne&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ne||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=ne,!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 Jt(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=ue)}get domAtom(){return!1}isText(e){return this.node.text==e}}class qi extends kt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ne&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Ql extends we{constructor(e,t,n,i,s,o,l,a,c,u){super(e,t,n,i,s,o,l,c,u),this.spec=a}update(e,t,n,i){if(this.dirty==ue)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 Ki(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=Gi(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof $e){let a=n?n.previousSibling:r.lastChild;Ki(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=Gi(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}const xt=function(r){r&&(this.nodeName=r)};xt.prototype=Object.create(null);const Ve=[new xt];function Ln(r,e,t){if(r.length==0)return Ve;let n=t?Ve[0]:new xt,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new xt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new xt(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 Ui(r,e,t,n){if(t==Ve&&n==Ve)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=Ve[0]),i=a}ea(i,l||Ve[0],o)}return i}function ea(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 _i(r,e,t){return Ui(r,r,Ve,Ln(e,t,r.nodeType!=1))}function qt(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 Gi(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}class ta{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=na(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){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=ne,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1;for(let a=this.index;a<Math.min(this.index+3,this.top.children.length);a++){let c=this.top.children[a];if(c.matchesMark(e[s])&&!this.isLocked(c.dom)){l=a;break}}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=$e.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}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==ue&&o.dom==o.contentDOM&&(o.dirty=Le),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 we){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let u=a.dom,d,f=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=ue&&qt(t,a.outerDeco));if(!f&&a.update(e,t,n,i))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!f&&(d=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=Le,d.updateChildren(i,o+1),d.dirty=ne),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)||!qt(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=we.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=we.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 Hi(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 $e;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Jt)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((K||H)&&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 qi(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 na(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 $e)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 ra(r,e){return r.type.side-e.type.side}function ia(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let u=r.child(c);n(u,i,e.forChild(s,u),c),s+=u.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let u,d;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(u?(d||(d=[u])).push(g):u=g)}if(u)if(d){d.sort(ra);for(let g=0;g<d.length;g++)t(d[g],c,!!a)}else t(u,c,!!a);let f,h;if(a)h=-1,f=a,a=null;else if(c<r.childCount)h=c,f=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+f.nodeSize;if(f.isText){let g=p;o<i.length&&i[o].from<g&&(g=i[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<p&&(a=f.cut(g-s),f=f.cut(0,g-s),p=g,h=-1)}else for(;o<i.length&&i[o].to<p;)o++;let m=f.isInline&&!f.isLeaf?l.filter(g=>!g.inline):l.slice();n(f,m,e.forChild(s,f),h),s=p}}function sa(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 oa(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 $n(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,u=l+=a.size;c>=t||u<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),u>t&&s.push(a.slice(t-c,a.size,n)))}return s}function Vn(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(Ht(t)){for(a=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&Il(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;c=new C(o==f?l:n.resolve(f))}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let h=0;h<t.rangeCount;h++){let p=t.getRangeAt(h);d=Math.min(d,r.docView.posFromDOM(p.startContainer,p.startOffset,1)),f=Math.max(f,r.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(d<0)return null;[a,o]=f==r.state.selection.anchor?[f,d]:[d,f],l=n.resolve(o)}else a=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=n.resolve(a);if(!c){let d=e=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=Wn(r,u,l,d)}return c}function Yi(r){return r.editable?r.hasFocus():rs(r)&&document.activeElement&&document.activeElement.contains(r.dom)}function ge(r,e=!1){let t=r.state.selection;if(es(r,t),!!Yi(r)){if(!e&&r.input.mouseDown&&r.input.mouseDown.allowDefault&&H){let n=r.domSelectionRange(),i=r.domObserver.currentSelection;if(n.anchorNode&&i.anchorNode&&ze(n.anchorNode,n.anchorOffset,i.anchorNode,i.anchorOffset)){r.input.mouseDown.delayedSelectionSync=!0,r.domObserver.setCurSelection();return}}if(r.domObserver.disconnectSelection(),r.cursorWrapper)aa(r);else{let{anchor:n,head:i}=t,s,o;Xi&&!(t instanceof E)&&(t.$from.parent.inlineContent||(s=Zi(r,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Zi(r,t.to))),r.docView.setSelection(n,i,r,e),Xi&&(s&&Qi(s),o&&Qi(o)),t.visible?r.dom.classList.remove("ProseMirror-hideselection"):(r.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&la(r))}r.domObserver.setCurSelection(),r.domObserver.connectSelection()}}const Xi=K||H&&vi<63;function Zi(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(K&&i&&i.contentEditable=="false")return jn(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return jn(i);if(s)return jn(s)}}function jn(r){return r.contentEditable="true",K&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function Qi(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function la(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(()=>{(!Yi(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function aa(r){let e=r.domSelection(),t=document.createRange();if(!e)return;let n=r.cursorWrapper.dom,i=n.nodeName=="IMG";i?t.setStart(n.parentNode,V(n)+1):t.setStart(n,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!r.state.selection.visible&&G&&Se<=11&&(n.disabled=!0,n.disabled=!1)}function es(r,e){if(e instanceof C){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(ts(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else ts(r)}function ts(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Wn(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||E.between(e,t,n)}function ns(r){return r.editable&&!r.hasFocus()?!1:rs(r)}function rs(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 ca(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return ze(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Hn(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&&O.findFrom(s,e)}function Me(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function is(r,e,t){let n=r.state.selection;if(n instanceof E)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 Me(r,new E(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=Hn(r.state,e);return i&&i instanceof C?Me(r,i):!1}else if(!(te&&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?C.isSelectable(s)?Me(r,new C(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):yt?Me(r,new E(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof C&&n.node.isInline)return Me(r,new E(e>0?n.$to:n.$from));{let i=Hn(r.state,e);return i?Me(r,i):!1}}}function Kt(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function St(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function nt(r,e){return e<0?ua(r):da(r)}function ua(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(oe&&t.nodeType==1&&n<Kt(t)&&St(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(St(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(ss(t))break;{let l=t.previousSibling;for(;l&&St(l,-1);)i=t.parentNode,s=V(l),l=l.previousSibling;if(l)t=l,n=Kt(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?Jn(r,t,n):i&&Jn(r,i,s)}function da(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=Kt(t),s,o;for(;;)if(n<i){if(t.nodeType!=1)break;let l=t.childNodes[n];if(St(l,1))s=t,o=++n;else break}else{if(ss(t))break;{let l=t.nextSibling;for(;l&&St(l,1);)s=l.parentNode,o=V(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=Kt(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&Jn(r,s,o)}function ss(r){let e=r.pmViewDesc;return e&&e.node&&e.node.isBlock}function fa(r,e){for(;r&&e==r.childNodes.length&&!gt(r);)e=V(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 ha(r,e){for(;r&&!e&&!gt(r);)e=V(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 Jn(r,e,t){if(e.nodeType!=3){let s,o;(o=fa(e,t))?(e=o,t=0):(s=ha(e,t))&&(e=s,t=s.nodeValue.length)}let n=r.domSelection();if(!n)return;if(Ht(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&&ge(r)},50)}function ls(r,e){let t=r.state.doc.resolve(e);if(!(H||Bl)&&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 as(r,e,t){let n=r.state.selection;if(n instanceof E&&!n.empty||t.indexOf("s")>-1||te&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=Hn(r.state,e);if(o&&o instanceof C)return Me(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof Z?O.near(o,e):O.findFrom(o,e);return l?Me(r,l):!1}return!1}function cs(r,e){if(!(r.state.selection instanceof E))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 us(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function pa(r){if(!K||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;us(r,n,"true"),setTimeout(()=>us(r,n,"false"),20)}return!1}function ma(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function ga(r,e){let t=e.keyCode,n=ma(e);if(t==8||te&&t==72&&n=="c")return cs(r,-1)||nt(r,-1);if(t==46&&!e.shiftKey||te&&t==68&&n=="c")return cs(r,1)||nt(r,1);if(t==13||t==27)return!0;if(t==37||te&&t==66&&n=="c"){let i=t==37?ls(r,r.state.selection.from)=="ltr"?-1:1:-1;return is(r,i,n)||nt(r,i)}else if(t==39||te&&t==70&&n=="c"){let i=t==39?ls(r,r.state.selection.from)=="ltr"?1:-1:1;return is(r,i,n)||nt(r,i)}else{if(t==38||te&&t==80&&n=="c")return as(r,-1,n)||nt(r,-1);if(t==40||te&&t==78&&n=="c")return pa(r)||as(r,1,n)||nt(r,1);if(n==(te?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function qn(r,e){r.someProp("transformCopied",h=>{e=h(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 h=n.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),n=h.content}let o=r.someProp("clipboardSerializer")||Re.fromSchema(r.state.schema),l=bs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,u,d=0;for(;c&&c.nodeType==1&&(u=gs[c.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let p=l.createElement(u[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=r.someProp("clipboardTextSerializer",h=>h(e,r))||e.content.textBetween(0,e.content.size,`
|
|
1
|
+
(function(Ke,P){typeof exports=="object"&&typeof module<"u"?P(exports):typeof define=="function"&&define.amd?define(["exports"],P):(Ke=typeof globalThis<"u"?globalThis:Ke||self,P(Ke.JinnTap={}))})(this,function(Ke){"use strict";function P(r){this.content=r}P.prototype={constructor:P,find:function(r){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===r)return e;return-1},get:function(r){var e=this.find(r);return e==-1?void 0:this.content[e+1]},update:function(r,e,t){var n=t&&t!=r?this.remove(t):this,i=n.find(r),s=n.content.slice();return i==-1?s.push(t||r,e):(s[i+1]=e,t&&(s[i]=t)),new P(s)},remove:function(r){var e=this.find(r);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new P(t)},addToStart:function(r,e){return new P([r,e].concat(this.remove(r).content))},addToEnd:function(r,e){var t=this.remove(r).content.slice();return t.push(r,e),new P(t)},addBefore:function(r,e,t){var n=this.remove(e),i=n.content.slice(),s=n.find(r);return i.splice(s==-1?i.length:s,0,e,t),new P(i)},forEach:function(r){for(var e=0;e<this.content.length;e+=2)r(this.content[e],this.content[e+1])},prepend:function(r){return r=P.from(r),r.size?new P(r.content.concat(this.subtract(r).content)):this},append:function(r){return r=P.from(r),r.size?new P(this.subtract(r).content.concat(r.content)):this},subtract:function(r){var e=this;r=P.from(r);for(var t=0;t<r.content.length;t+=2)e=e.remove(r.content[t]);return e},toObject:function(){var r={};return this.forEach(function(e,t){r[e]=t}),r},get size(){return this.content.length>>1}},P.from=function(r){if(r instanceof P)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new P(e)};function Ar(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=Ar(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function vr(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,u=Math.min(o.text.length,l.text.length);for(;c<u&&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=vr(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}class b{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 u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),n,i+u)}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 b(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 b(n,i)}cutByIndex(e,t){return e==t?b.empty:e==0&&t==this.content.length?this:new b(this.content.slice(e,t))}replaceChild(e,t){let 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 b(i,s)}addToStart(e){return new b([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new b(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;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 Ar(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return vr(this,e,t,n)}findIndex(e,t=-1){if(e==0)return At(0,e);if(e==this.size)return At(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,i=0;;n++){let s=this.child(n),o=i+s.nodeSize;if(o>=e)return o==e||t>0?At(n+1,o):At(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return b.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new b(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return b.empty;let t,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 b(t||e,n)}static from(e){if(!e)return b.empty;if(e instanceof b)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new b([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}b.empty=new b([],0);const yn={index:0,offset:0};function At(r,e){return yn.index=r,yn.offset=e,yn}function vt(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(!vt(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!vt(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}let D=class Er{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&&vt(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 Er.none;if(e instanceof Er)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}};D.none=[];class Dt extends Error{}class k{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=Ir(this.content,e+this.openStart,t);return n&&new k(n,this.openStart,this.openEnd)}removeBetween(e,t){return new k(Dr(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 k.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 k(b.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 k(e,n,i)}}k.empty=new k(b.empty,0,0);function Dr(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(Dr(s.content,e-i-1,t-i-1)))}function Ir(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return r.cut(0,e).append(t).append(r.cut(e));let l=Ir(o.content,e-s-1,t);return l&&r.replaceChild(i,o.copy(l))}function vo(r,e,t){if(t.openStart>r.depth)throw new Dt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Dt("Inconsistent open depths");return Pr(r,e,t,0)}function Pr(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=Pr(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 Ie(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Do(t,r);return Ie(s,Br(r,o,l,e,n))}else return Ie(s,It(r,e,n))}function Rr(r,e){if(!e.type.compatibleContent(r.type))throw new Dt("Cannot join "+e.type.name+" onto "+r.type.name)}function bn(r,e,t){let n=r.node(t);return Rr(n,e.node(t)),n}function De(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 lt(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&&(De(r.nodeAfter,n),s++));for(let l=s;l<o;l++)De(i.child(l),n);e&&e.depth==t&&e.textOffset&&De(e.nodeBefore,n)}function Ie(r,e){return r.type.checkContent(e),r.copy(e)}function Br(r,e,t,n,i){let s=r.depth>i&&bn(r,e,i+1),o=n.depth>i&&bn(t,n,i+1),l=[];return lt(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Rr(s,o),De(Ie(s,Br(r,e,t,n,i+1)),l)):(s&&De(Ie(s,It(r,e,i+1)),l),lt(e,t,i,l),o&&De(Ie(o,It(t,n,i+1)),l)),lt(n,null,i,l),new b(l)}function It(r,e,t){let n=[];if(lt(null,r,t,n),r.depth>t){let i=bn(r,e,t+1);De(Ie(i,It(r,e,t+1)),n)}return lt(e,null,t,n),new b(n)}function Do(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(b.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}class at{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 D.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 Pt(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 at(t,n,s)}static resolveCached(e,t){let n=zr.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 zr.set(e,n=new Io);let i=n.elts[n.i]=at.resolve(e,t);return n.i=(n.i+1)%Po,i}}class Io{constructor(){this.elts=[],this.i=0}}const Po=12,zr=new WeakMap;class Pt{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 Ro=Object.create(null);let ye=class Tr{constructor(e,t,n,i=D.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||b.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&&vt(this.attrs,t||e.defaultAttrs||Ro)&&D.sameSet(this.marks,n||D.none)}copy(e=null){return e==this.content?this:new Tr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Tr(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 k.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 k(c,i.depth-o,s.depth-o)}replace(e,t,n){return vo(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 at.resolveCached(this,e)}resolveNoCache(e){return at.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()+")"),Fr(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=b.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=D.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(!D.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=b.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,n);return s.type.checkAttrs(s.attrs),s}};ye.prototype.text=void 0;class Rt extends ye{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):Fr(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 Rt(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Rt(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 Fr(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}class Pe{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new Bo(e,t);if(n.next==null)return Pe.empty;let i=Lr(n);n.next&&n.err("Unexpected trailing text");let s=Wo(jo(i));return Ho(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 b.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:u,next:d}=o.next[c];if(!(u.isText||u.hasRequiredAttrs())&&i.indexOf(d)==-1){i.push(d);let f=s(d,l.concat(u));if(f)return f}}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(`
|
|
2
|
+
`)}}Pe.empty=new Pe(!0);class Bo{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 Lr(r){let e=[];do e.push(zo(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function zo(r){let e=[];do e.push(Fo(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Fo(r){let e=Vo(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=Lo(r,e);else break;return e}function $r(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function Lo(r,e){let t=$r(r),n=t;return r.eat(",")&&(r.next!="}"?n=$r(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function $o(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 Vo(r){if(r.eat("(")){let e=Lr(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=$o(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 jo(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 u=t();i(s(o.expr,a),u),a=u}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let u=t();n(a,u),i(s(o.expr,a),u),a=u}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Vr(r,e){return e-r}function jr(r,e){let t=[];return n(e),t.sort(Vr);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 Wo(r){let e=Object.create(null);return t(jr(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u<i.length;u++)i[u][0]==l&&(c=i[u][1]);jr(r,a).forEach(u=>{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[n.join(",")]=new Pe(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Vr);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function Ho(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 Wr(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 Hr(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 Jr(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 qr(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new qo(r,n,e[n]);return t}let Kr=class Ao{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=qr(e,n.attrs),this.defaultAttrs=Wr(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==Pe.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:Hr(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ye(this,this.computeAttrs(e),b.from(t),D.setFrom(n))}createChecked(e=null,t,n){return t=b.from(t),this.checkContent(t),new ye(this,this.computeAttrs(e),t,D.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=b.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(b.empty,!0);return s?new ye(this,e,t.append(s),D.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){Jr(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:D.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new Ao(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 Jo(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 qo{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Jo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Bt{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=qr(e,i.attrs),this.excluded=null;let s=Wr(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,Hr(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Bt(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){Jr(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Ur{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=P.from(e.nodes),t.marks=P.from(e.marks||{}),this.nodes=Kr.compile(this.spec.nodes,this),this.marks=Bt.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]=Pe.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?_r(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==""?[]:_r(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Kr){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 Rt(n,n.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return ye.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function _r(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 Ko(r){return r.tag!=null}function Uo(r){return r.style!=null}let ct=class Or{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(Ko(i))this.tags.push(i);else if(Uo(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 Zr(this,t,!1);return n.addAll(e,D.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Zr(this,t,!0);return n.addAll(e,D.none,t.from,t.to),k.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(Yo(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=Qr(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=Qr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Or(e,Or.schemaRules(e)))}};const Gr={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},_o={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Yr={ol:!0,ul:!0},ut=1,kn=2,zt=4;function Xr(r,e,t){return e!=null?(e?ut:0)|(e==="full"?kn:0):r&&r.whitespace=="pre"?ut|kn:t&-5}class Ft{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=D.none,this.match=s||(o&zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(b.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let 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&ut)){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=b.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(b.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Gr.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Zr{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=Xr(null,t.preserveWhitespace,0)|(n?zt:0);i?s=new Ft(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ft(null,null,D.none,!0,null,o):s=new Ft(e.schema.topNodeType,null,D.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&kn?"full":this.localPreserveWS||(i.options&ut)>0;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)s!=="full"?n=n.replace(/\r?\n|\r/g," "):n=n.replace(/\r\n?/g,`
|
|
3
|
+
`);else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t),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;Yr.hasOwnProperty(o)&&this.parser.normalizeLists&&Go(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:_o.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,u=this.needsBlock;if(Gr.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 d=a&&a.skip?t:this.readStyles(e,t);d&&this.addAll(e,d),c&&this.sync(s),this.needsBlock=u}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(`
|
|
4
|
+
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let 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)||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));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){let n,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,i=o,!l.length)||o.solid)break}if(!n)return null;this.sync(i);for(let s=0;s<n.length;s++)t=this.enterInner(n[s],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let i=this.textblockFromContext();i&&(t=this.enterInner(i,null,t))}let n=this.findPlace(e,t);if(n){this.closeExtra();let i=this.top;i.match&&(i.match=i.match.matchType(e.type));let s=D.none;for(let o of n.concat(e.marks))(i.type?i.type.allowsMarkType(o.type):ei(o.type,e.type))&&(s=o.addToSet(s));return i.content.push(e.mark(s)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n);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=Xr(e,s,o.options);o.options&zt&&o.content.length==0&&(l|=zt);let a=D.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):ei(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ft(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|=ut)}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 u=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!u||u.name!=c&&!u.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 Go(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Yr.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Yo(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function Qr(r){let e={};for(let t in r)e[t]=r[t];return e}function ei(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:u}=l.edge(a);if(c==e||s.indexOf(u)<0&&o(u))return!0}};if(o(i.contentMatch))return!0}}class Re{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=xn(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++],u=this.serializeMark(c,o.isInline,t);u&&(s.push([c,i]),i.appendChild(u.dom),i=u.contentDOM||u.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=Lt(xn(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&&Lt(xn(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return Lt(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Re(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ti(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return ti(e.marks)}}function ti(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function xn(r){return r.document||window.document}const ni=new WeakMap;function Xo(r){let e=ni.get(r);return e===void 0&&ni.set(r,e=Zo(r)),e}function Zo(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 Lt(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=Xo(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],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let d in c)if(c[d]!=null){let f=d.indexOf(" ");f>0?a.setAttributeNS(d.slice(0,f),d.slice(f+1),c[d]):a.setAttribute(d,c[d])}}for(let d=u;d<e.length;d++){let f=e[d];if(f===0){if(d<e.length-1||d>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:p}=Lt(r,f,t,n);if(a.appendChild(h),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const ri=65535,ii=Math.pow(2,16);function Qo(r,e){return r+e*ii}function si(r){return r&ri}function el(r){return(r-(r&ri))/ii}const oi=1,li=2,$t=4,ai=8;class Sn{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ai)>0}get deletedBefore(){return(this.delInfo&(oi|$t))>0}get deletedAfter(){return(this.delInfo&(li|$t))>0}get deletedAcross(){return(this.delInfo&$t)>0}}class X{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&X.empty)return X.empty}recover(e){let t=0,n=si(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+el(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],u=this.ranges[l+o],d=a+c;if(e<=d){let f=c?e==a?-1:e==d?1:t:t,h=a+i+(f<0?0:u);if(n)return h;let p=e==(t<0?a:d)?null:Qo(l/3,e-a),m=e==a?li:e==d?oi:$t;return(t<0?e!=a:e!=d)&&(m|=ai),new Sn(h,m,p)}i+=u-c}return n?e+i:new Sn(e+i,0,null)}touches(e,t){let n=0,i=si(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],u=a+c;if(e<=u&&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],u=this.ranges[i+n];e(l,l+c,a,a+u),s+=u-c}}invert(){return new X(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?X.empty:new X(e<0?[0,-e,0]:[0,0,e])}}X.empty=new X([]);class dt{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 dt(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 dt;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 Sn(e,i,null)}}const Cn=Object.create(null);class W{getMap(){return X.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=Cn[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 Cn)throw new RangeError("Duplicate use of step JSON ID "+e);return Cn[e]=t,t.prototype.jsonID=e,t}}class R{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new R(e,null)}static fail(e){return new R(null,e)}static fromReplace(e,t,n,i){try{return R.ok(e.replace(t,n,i))}catch(s){if(s instanceof Dt)return R.fail(s.message);throw s}}}function wn(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(wn(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return b.fromArray(n)}class be extends W{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 k(wn(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 R.fromReplace(e,this.from,this.to,s)}invert(){return new ae(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 be(t.pos,n.pos,this.mark)}merge(e){return e instanceof be&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new be(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 be(t.from,t.to,e.markFromJSON(t.mark))}}W.jsonID("addMark",be);class ae extends W{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 k(wn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return R.fromReplace(e,this.from,this.to,n)}invert(){return new be(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 ae(t.pos,n.pos,this.mark)}merge(e){return e instanceof ae&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ae(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 ae(t.from,t.to,e.markFromJSON(t.mark))}}W.jsonID("removeMark",ae);class ke extends W{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return R.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return R.fromReplace(e,this.pos,this.pos+1,new k(b.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 ke(this.pos,t.marks[i]);return new ke(this.pos,this.mark)}}return new Ue(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new ke(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 ke(t.pos,e.markFromJSON(t.mark))}}W.jsonID("addNodeMark",ke);class Ue extends W{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return R.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return R.fromReplace(e,this.pos,this.pos+1,new k(b.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new ke(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ue(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 Ue(t.pos,e.markFromJSON(t.mark))}}W.jsonID("removeNodeMark",Ue);class B extends W{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&Mn(e,this.from,this.to)?R.fail("Structure replace would overwrite content"):R.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new X([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)}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?k.empty:new k(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?k.empty:new k(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,k.fromJSON(e,t.slice),!!t.structure)}}W.jsonID("replace",B);class F extends W{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&&(Mn(e,this.from,this.gapFrom)||Mn(e,this.gapTo,this.to)))return R.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return R.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?R.fromReplace(e,this.from,this.to,n):R.fail("Content does not fit in gap")}getMap(){return new X([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 F(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 F(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 F(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}}W.jsonID("replaceAround",F);function Mn(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 tl(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,c,u)=>{if(!a.isInline)return;let d=a.marks;if(!n.isInSet(d)&&u.type.allowsMarkType(n.type)){let f=Math.max(c,e),h=Math.min(c+a.nodeSize,t),p=n.addToSet(d);for(let m=0;m<d.length;m++)d[m].isInSet(p)||(o&&o.to==f&&o.mark.eq(d[m])?o.to=h:i.push(o=new ae(f,h,d[m])));l&&l.to==f?l.to=h:s.push(l=new be(f,h,n))}}),i.forEach(a=>r.step(a)),s.forEach(a=>r.step(a))}function nl(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 Bt){let c=o.marks,u;for(;u=n.isInSet(c);)(a||(a=[])).push(u),c=u.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 u=0;u<a.length;u++){let d=a[u],f;for(let h=0;h<i.length;h++){let p=i[h];p.step==s-1&&d.eq(i[h].style)&&(f=p)}f?(f.to=c,f.step=s):i.push({style:d,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new ae(o.from,o.to,o.style)))}function En(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),u=l+c.nodeSize,d=n.matchType(c.type);if(!d)o.push(new B(l,u,k.empty));else{n=d;for(let f=0;f<c.marks.length;f++)t.allowsMarkType(c.marks[f].type)||r.step(new ae(l,u,c.marks[f]));if(i&&c.isText&&t.whitespace!="pre"){let f,h=/\r?\n|\r/g,p;for(;f=h.exec(c.text);)p||(p=new k(b.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new B(l+f.index,l+f.index+f[0].length,p))}}l=u}if(!n.validEnd){let a=n.fillBefore(b.empty,!0);r.replace(l,l,new k(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function rl(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function _e(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth;;--n){let i=r.$from.node(n),s=r.$from.index(n),o=r.$to.indexAfter(n);if(n<r.depth&&i.canReplace(s,o,t))return n;if(n==0||i.type.spec.isolating||!rl(i,s,o))break}return null}function il(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,u=b.empty,d=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,u=b.from(n.node(p).copy(u)),d++):a--;let f=b.empty,h=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)<i.end(p)?(m=!0,f=b.from(i.node(p).copy(f)),h++):c++;r.step(new F(a,c,o,l,new k(u.append(f),d,h),u.size-d,!0))}function ci(r,e,t=null,n=r){let i=sl(r,e),s=i&&ol(n,e);return s?i.map(ui).concat({type:e,attrs:t}).concat(s.map(ui)):null}function ui(r){return{type:r,attrs:null}}function sl(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 ol(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 ll(r,e,t){let n=b.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=b.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new F(i,s,i,s,new k(n,0,0),t.length,!0))}function al(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)&&cl(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let h=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);h&&!p?c=!1:!h&&p&&(c=!0)}c===!1&&fi(r,o,l,s),En(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let u=r.mapping.slice(s),d=u.map(l,1),f=u.map(l+o.nodeSize,1);return r.step(new F(d,f,d+1,f-1,new k(b.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&di(r,o,l,s),!1}})}function di(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 fi(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(`
|
|
5
|
+
`))}})}function cl(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function ul(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 F(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new k(b.from(o),0,0),1,!0))}function fe(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,u=t-2;c>s;c--,u--){let d=i.node(c),f=i.index(c);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=n&&n[u+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[u]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(h))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 dl(r,e,t=1,n){let i=r.doc.resolve(e),s=b.empty,o=b.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=b.from(i.node(l).copy(s));let u=n&&n[c];o=b.from(u?u.type.create(u.attrs,o):i.node(l).copy(o))}r.step(new B(e,e,new k(s.append(o),t,t),!0))}function Be(r,e){let t=r.resolve(e),n=t.index();return hi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function fl(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 hi(r,e){return!!(r&&e&&!r.isLeaf&&fl(r,e))}function Vt(r,e,t=-1){let n=r.resolve(e);for(let i=n.depth;;i--){let s,o,l=n.index(i);if(i==n.depth?(s=n.nodeBefore,o=n.nodeAfter):t>0?(s=n.node(i+1),l++,o=n.node(i).maybeChild(l)):(s=n.node(i).maybeChild(l-1),o=n.node(i+1)),s&&!s.isTextblock&&hi(s,o)&&n.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?n.before(i):n.after(i)}}function hl(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 u=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);u&&!d?n=!1:!u&&d&&(n=!0)}let l=r.steps.length;if(n===!1){let u=r.doc.resolve(e+t);fi(r,u.node(),u.before(),l)}o.inlineContent&&En(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),k.empty,!0)),n===!0){let u=r.doc.resolve(c);di(r,u.node(),u.before(),r.steps.length)}return r}function pl(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 ml(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),u=!1;if(s==1)u=c.canReplace(a,a,i);else{let d=c.contentMatchAt(a).findWrapping(i.firstChild.type);u=d&&c.canReplaceWith(a,a,d[0])}if(u)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function jt(r,e,t=e,n=k.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return pi(i,s,n)?new B(e,t,n):new gl(i,s,n).fit()}function pi(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class gl{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=b.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=b.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,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 k(s,o,l);return e>-1?new F(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=Tn(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],u,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(b.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(u=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:u};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Tn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(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=Tn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new k(ft(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new k(ft(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,u=[],{match:d,type:f}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)u.push(i.child(m));d=d.matchFragment(i)}let h=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=d.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(d=g,u.push(mi(m.mark(f.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?h:-1)))}let p=c==l.childCount;p||(h=-1),this.placed=ht(this.placed,t,b.from(u)),this.frontier[t].match=d,p&&h<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<h;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=p?e==0?k.empty:new k(ft(o.content,e-1,1),e-1,h<0?o.openEnd:e-1):new k(ft(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||!On(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=On(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],u=On(e,l,c,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ht(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=ht(this.placed,this.depth,b.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(b.empty,!0);t.childCount&&(this.placed=ht(this.placed,this.frontier.length,t))}}function ft(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(ft(r.firstChild.content,e-1,t)))}function ht(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ht(r.lastChild.content,e-1,t)))}function Tn(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function mi(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,mi(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(b.empty,!0)))),r.copy(n)}function On(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&&!yl(t,s.content,o)?l:null}function yl(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function bl(r){return r.spec.defining||r.spec.definingForContent}function kl(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(pi(i,s,n))return r.step(new B(e,t,n));let o=yi(i,r.doc.resolve(t));o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let f=i.depth,h=i.pos-1;f>0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==h&&o.splice(1,0,-f)}let a=o.indexOf(l),c=[],u=n.openStart;for(let f=n.content,h=0;;h++){let p=f.firstChild;if(c.push(p),h==n.openStart)break;f=p.content}for(let f=u-1;f>=0;f--){let h=c[f],p=bl(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))u=f;else if(p||!h.type.isTextblock)break}for(let f=n.openStart;f>=0;f--){let h=(f+u+1)%(n.openStart+1),p=c[h];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let S=i.node(g-1),w=i.index(g-1);if(S.canReplaceWith(w,w,p.type,p.marks))return r.replace(i.before(g),y?s.after(g):t,new k(gi(n.content,0,n.openStart,h),h,n.openEnd))}}let d=r.steps.length;for(let f=o.length-1;f>=0&&(r.replace(e,t,n),!(r.steps.length>d));f--){let h=o[f];h<0||(e=i.before(h),t=s.after(h))}}function gi(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(gi(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(b.empty,!0))}return r}function xl(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=pl(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new k(b.from(n),0,0))}function Sl(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=yi(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 yi(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 Ge extends W{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 R.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 R.fromReplace(e,this.pos,this.pos+1,new k(b.from(i),0,t.isLeaf?0:1))}getMap(){return X.empty}invert(e){return new Ge(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 Ge(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 Ge(t.pos,t.attr,t.value)}}W.jsonID("attr",Ge);class pt extends W{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 R.ok(n)}getMap(){return X.empty}invert(e){return new pt(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 pt(t.attr,t.value)}}W.jsonID("docAttr",pt);let Ye=class extends Error{};Ye=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t},Ye.prototype=Object.create(Error.prototype),Ye.prototype.constructor=Ye,Ye.prototype.name="TransformError";class Cl{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new dt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ye(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=k.empty){let i=jt(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new k(b.from(n),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return kl(this,e,t,n),this}replaceRangeWith(e,t,n){return xl(this,e,t,n),this}deleteRange(e,t){return Sl(this,e,t),this}lift(e,t){return il(this,e,t),this}join(e,t=1){return hl(this,e,t),this}wrap(e,t){return ll(this,e,t),this}setBlockType(e,t=e,n,i=null){return al(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return ul(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Ge(e,t,n)),this}setDocAttribute(e,t){return this.step(new pt(e,t)),this}addNodeMark(e,t){return this.step(new ke(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t=t.isInSet(n.marks),!t)return this}return this.step(new Ue(e,t)),this}split(e,t=1,n){return dl(this,e,t,n),this}addMark(e,t,n){return tl(this,e,t,n),this}removeMark(e,t,n){return nl(this,e,t,n),this}clearIncompatible(e,t,n){return En(this,e,t,n),this}}const Nn=Object.create(null);class O{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new wl(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=k.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],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(c.pos),l?k.empty:t),l==0&&xi(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),u=a.map(l.pos);s?e.deleteRange(c,u):(e.replaceRangeWith(c,u,t),xi(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new E(e):Xe(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?Xe(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Xe(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 Z(e.node(0))}static atStart(e){return Xe(e,e,0,0,1)||new Z(e)}static atEnd(e){return Xe(e,e,e.content.size,e.childCount,-1)||new Z(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Nn[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 Nn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Nn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return E.between(this.$anchor,this.$head).getBookmark()}}O.prototype.visible=!0;class wl{constructor(e,t){this.$from=e,this.$to=t}}let bi=!1;function ki(r){!bi&&!r.parent.inlineContent&&(bi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class E extends O{constructor(e,t=e){ki(e),ki(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 O.near(n);let i=e.resolve(t.map(this.anchor));return new E(i.parent.inlineContent?i:n,n)}replace(e,t=k.empty){if(super.replace(e,t),t==k.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof E&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Wt(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new E(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,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=O.findFrom(t,n,!0)||O.findFrom(t,-n,!0);if(s)t=s.$head;else return O.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(O.findFrom(e,-n,!0)||O.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new E(e,t)}}O.jsonID("text",E);class Wt{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Wt(e.map(this.anchor),e.map(this.head))}resolve(e){return E.between(e.resolve(this.anchor),e.resolve(this.head))}}class C extends O{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?O.near(s):new C(s)}content(){return new k(b.from(this.node),0,0)}eq(e){return e instanceof C&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new An(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new C(e.resolve(t.anchor))}static create(e,t){return new C(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}C.prototype.visible=!1,O.jsonID("node",C);class An{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Wt(n,n):new An(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&C.isSelectable(n)?new C(t):O.near(t)}}class Z extends O{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=k.empty){if(t==k.empty){e.delete(0,e.doc.content.size);let n=O.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Z(e)}map(e){return new Z(e)}eq(e){return e instanceof Z}getBookmark(){return Ml}}O.jsonID("all",Z);const Ml={map(){return this},resolve(r){return new Z(r)}};function Xe(r,e,t,n,i,s=!1){if(e.inlineContent)return E.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&&C.isSelectable(l))return C.create(r,t-(i<0?l.nodeSize:0))}else{let a=Xe(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function xi(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof B||i instanceof F))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,u)=>{o==null&&(o=u)}),r.setSelection(O.near(r.doc.resolve(o),t))}const Si=1,Ci=2,wi=4;class El extends Cl{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|Si)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&Si)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ci,this}ensureMarks(e){return D.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&Ci)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&-3,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)||D.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),n=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.setSelection(O.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|=wi,this}get scrolledIntoView(){return(this.updated&wi)>0}}function Mi(r,e){return!e||!r?r:r.bind(e)}class mt{constructor(e,t,n){this.name=e,this.init=Mi(t.init,n),this.apply=Mi(t.apply,n)}}const Tl=[new mt("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new mt("selection",{init(r,e){return r.selection||O.atStart(e.doc)},apply(r){return r.selection}}),new mt("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new mt("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class vn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Tl.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 mt(n.key,n.spec.state,n))})}}class Ze{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,u=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(u&&n.filterTransaction(u,o)){if(u.setMeta("appendedTransaction",e),!i){i=[];for(let d=0;d<this.config.plugins.length;d++)i.push(d<o?{state:n,n:t.length}:{state:this,n:0})}t.push(u),n=n.applyInner(u),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 Ze(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 El(this)}static create(e){let t=new vn(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Ze(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 vn(this.schema,e.plugins),n=t.fields,i=new Ze(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 vn(e.schema,e.plugins),s=new Ze(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ye.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=O.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 Ei(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=Ei(i,e,{})),t[n]=i}return t}class Q{constructor(e){this.spec=e,this.props={},e.props&&Ei(e.props,this,this.props),this.key=e.key?e.key.key:Ti("plugin")}getState(e){return e[this.key]}}const Dn=Object.create(null);function Ti(r){return r in Dn?r+"$"+ ++Dn[r]:(Dn[r]=0,r+"$")}class se{constructor(e="key"){this.key=Ti(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const V=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 In=null;const he=function(r,e,t){let n=In||(In=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Ol=function(){In=null},ze=function(r,e,t,n){return t&&(Oi(r,e,t,n,-1)||Oi(r,e,t,n,1))},Nl=/^(img|br|input|textarea|hr)$/i;function Oi(r,e,t,n,i){for(;;){if(r==t&&e==n)return!0;if(e==(i<0?0:ee(r))){let s=r.parentNode;if(!s||s.nodeType!=1||gt(r)||Nl.test(r.nodeName)||r.contentEditable=="false")return!1;e=V(r)+(i<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(i<0?-1:0)],r.contentEditable=="false")return!1;e=i<0?ee(r):0}else return!1}}function ee(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Al(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=ee(r)}else if(r.parentNode&&!gt(r))e=V(r),r=r.parentNode;else return null}}function vl(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&&!gt(r))e=V(r)+1,r=r.parentNode;else return null}}function Dl(r,e,t){for(let n=e==0,i=e==ee(r);n||i;){if(r==t)return!0;let s=V(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==ee(r)}}function gt(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 Ht=function(r){return r.focusNode&&ze(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)};function Fe(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function Il(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Pl(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(ee(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(ee(n.startContainer),n.startOffset)}}}const ce=typeof navigator<"u"?navigator:null,Ni=typeof document<"u"?document:null,xe=ce&&ce.userAgent||"",Pn=/Edge\/(\d+)/.exec(xe),Ai=/MSIE \d/.exec(xe),Rn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(xe),G=!!(Ai||Rn||Pn),Se=Ai?document.documentMode:Rn?+Rn[1]:Pn?+Pn[1]:0,oe=!G&&/gecko\/(\d+)/i.test(xe);oe&&+(/Firefox\/(\d+)/.exec(xe)||[0,0])[1];const Bn=!G&&/Chrome\/(\d+)/.exec(xe),H=!!Bn,vi=Bn?+Bn[1]:0,K=!G&&!!ce&&/Apple Computer/.test(ce.vendor),et=K&&(/Mobile\/\w+/.test(xe)||!!ce&&ce.maxTouchPoints>2),te=et||(ce?/Mac/.test(ce.platform):!1),Rl=ce?/Win/.test(ce.platform):!1,pe=/Android \d/.test(xe),yt=!!Ni&&"webkitFontSmoothing"in Ni.documentElement.style,Bl=yt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function zl(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 me(r,e){return typeof r=="number"?r:r[e]}function Fl(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 Di(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?zl(s):Fl(l),u=0,d=0;if(e.top<c.top+me(n,"top")?d=-(c.top-e.top+me(i,"top")):e.bottom>c.bottom-me(n,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+me(i,"top")-c.top:e.bottom-c.bottom+me(i,"bottom")),e.left<c.left+me(n,"left")?u=-(c.left-e.left+me(i,"left")):e.right>c.right-me(n,"right")&&(u=e.right-c.right+me(i,"right")),u||d)if(a)s.defaultView.scrollBy(u,d);else{let h=l.scrollLeft,p=l.scrollTop;d&&(l.scrollTop+=d),u&&(l.scrollLeft+=u);let m=l.scrollLeft-h,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let f=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:Qe(o)}}function Ll(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:Ii(r.dom)}}function Ii(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 $l({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;Pi(t,n==0?0:n-e)}function Pi(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 tt=null;function Vl(r){if(r.setActive)return r.setActive();if(tt)return r.focus(tt);let e=Ii(r);r.focus(tt==null?{get preventScroll(){return tt={preventScroll:!0},!0}}:void 0),tt||(tt=!1,Pi(e,0))}function Ri(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let u=r.firstChild,d=0;u;u=u.nextSibling,d++){let f;if(u.nodeType==1)f=u.getClientRects();else if(u.nodeType==3)f=he(u).getClientRects();else continue;for(let h=0;h<f.length;h++){let p=f[h];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=u,n=m,i=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,u.nodeType==1&&m&&(s=d+(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=u,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,n=0),t&&t.nodeType==3?jl(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:Ri(t,i)}function jl(r,e){let t=r.nodeValue.length,n=document.createRange();for(let i=0;i<t;i++){n.setEnd(r,i+1),n.setStart(r,i);let s=Ce(n,1);if(s.top!=s.bottom&&zn(e,s))return{node:r,offset:i+(e.left>=(s.left+s.right)/2?1:0)}}return{node:r,offset:0}}function zn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Wl(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<r.getBoundingClientRect().left?t:r}function Hl(r,e,t){let{node:n,offset:i}=Ri(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 Jl(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&&(!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 Bi(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(zn(e,c))return Bi(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function ql(r,e){let t=r.dom.ownerDocument,n,i=0,s=Pl(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(!zn(e,c)||(o=Bi(r.dom,e,c),!o))return null}if(K)for(let c=o;n&&c;c=Qe(c))c.draggable&&(n=void 0);if(o=Wl(o,e),n){if(oe&&n.nodeType==1&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let u=n.childNodes[i],d;u.nodeName=="IMG"&&(d=u.getBoundingClientRect()).right<=e.left&&d.bottom>e.top&&i++}let c;yt&&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=Jl(r,n,i,e))}l==null&&(l=Hl(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function zi(r){return r.top<r.bottom||r.left<r.right}function Ce(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(zi(n))return n}return Array.prototype.find.call(t,zi)||r.getBoundingClientRect()}const Kl=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Fi(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=yt||oe;if(n.nodeType==3)if(o&&(Kl.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=Ce(he(n,i,i),t);if(oe&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=Ce(he(n,i-1,i-1),-1);if(c.top==a.top){let u=Ce(he(n,i,i+1),-1);if(u.top!=a.top)return bt(u,u.left<c.left)}}return a}else{let a=i,c=i,u=t<0?1:-1;return t<0&&!i?(c++,u=-1):t>=0&&i==n.nodeValue.length?(a--,u=1):t<0?a--:c++,bt(Ce(he(n,a,c),u),u<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==ee(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return Fn(a.getBoundingClientRect(),!1)}if(s==null&&i<ee(n)){let a=n.childNodes[i];if(a.nodeType==1)return Fn(a.getBoundingClientRect(),!0)}return Fn(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==ee(n))){let a=n.childNodes[i-1],c=a.nodeType==3?he(a,ee(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return bt(Ce(c,1),!1)}if(s==null&&i<ee(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?he(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return bt(Ce(c,-1),!0)}return bt(Ce(n.nodeType==3?he(n):n,-t),t>=0)}function bt(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 Fn(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 Li(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 Ul(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return Li(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=Fi(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=he(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let u=a[c];if(u.bottom>u.top+1&&(t=="up"?o.top-u.top>(u.bottom-o.top)*2:u.bottom-o.bottom>(o.bottom-u.top)*2))return!1}}return!0})}const _l=/[\u0590-\u08ac]/;function Gl(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:Li(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:d}=r.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let h=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:p,focusOffset:m}=r.domSelectionRange(),g=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(u,d),a&&(a!=u||c!=d)&&l.extend&&l.extend(a,c)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):n.pos==n.start()||n.pos==n.end()}let $i=null,Vi=null,ji=!1;function Yl(r,e,t){return $i==e&&Vi==t?ji:($i=e,Vi=t,ji=t=="up"||t=="down"?Ul(r,e,t):Gl(r,e,t))}const ne=0,Wi=1,Le=2,ue=3;class kt{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=ne,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>V(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 qi){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 Hi&&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?V(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?V(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 u=o+a.border;if(e>=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=V(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;u<this.children.length;u++){let d=this.children[u];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(-1)){s=V(d.dom);break}t+=d.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 h=0,p=0;h<this.children.length;h++){let m=this.children[h],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(),u=n.domSelectionRange(),d=!1;if((oe||K)&&e==t){let{node:h,offset:p}=l;if(h.nodeType==3){if(d=!!(p&&h.nodeValue[p-1]==`
|
|
6
|
+
`),d&&p==h.nodeValue.length)for(let m=h,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:V(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=h.childNodes[p-1];d=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(oe&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(i=!0)}if(!(i||d&&K)&&ze(l.node,l.offset,u.anchorNode,u.anchorOffset)&&ze(a.node,a.offset,u.focusNode,u.focusOffset))return;let f=!1;if((c.extend||e==t)&&!d){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),f=!0}catch{}}if(!f){if(e>t){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(h)}}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?Le:Wi,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ue:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Le:ue}n=o}this.dirty=Le}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Le:Wi;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class Hi extends kt{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==ne&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class Xl extends kt{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 $e extends kt{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=Re.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new $e(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ue||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ue&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ne){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty<this.dirty&&(n.dirty=this.dirty),this.dirty=ne}}slice(e,t,n){let i=$e.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=$n(s,t,o,n)),e>0&&(s=$n(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 we extends kt{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),u=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:d}=Re.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let f=u;return u=_i(u,n,t),c?a=new Zl(e,t,n,i,u,d||null,f,c,s,o+1):t.isText?new Jt(e,t,n,i,u,f,s):new we(e,t,n,i,u,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>b.empty)}return e}matchesNode(e,t,n){return this.dirty==ne&&e.eq(this.node)&&qt(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 ea(this,o&&o.node,e);ra(this.node,this.innerDeco,(c,u,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,n,e):c.type.side>=0&&!d&&a.syncToMarks(u==this.node.childCount?D.none:this.node.child(u).marks,n,e),a.placeWidget(c,e,i)},(c,u,d,f)=>{a.syncToMarks(c.marks,n,e);let h;a.findNodeMatch(c,u,d,f)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(h=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,u,d,h,e)||a.updateNextNode(c,u,d,e,f,i)||a.addNode(c,u,d,e,i),i+=c.nodeSize}),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Le)&&(o&&this.protectLocalComposition(e,o),Ki(this.contentDOM,this.children,e),et&&ia(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof E)||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=sa(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 Xl(this,s,t,i);e.input.compositionNodes.push(o),this.children=$n(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==ue||!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=ne}updateOuterDeco(e){if(qt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Ui(this.dom,this.nodeDOM,Ln(this.outerDeco,this.node,t),Ln(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.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ji(r,e,t,n,i){_i(n,e,r);let s=new we(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Jt extends we{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==ue||this.dirty!=ne&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ne||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=ne,!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 Jt(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=ue)}get domAtom(){return!1}isText(e){return this.node.text==e}}class qi extends kt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ne&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Zl extends we{constructor(e,t,n,i,s,o,l,a,c,u){super(e,t,n,i,s,o,l,c,u),this.spec=a}update(e,t,n,i){if(this.dirty==ue)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 Ki(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=Gi(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof $e){let a=n?n.previousSibling:r.lastChild;Ki(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=Gi(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}const xt=function(r){r&&(this.nodeName=r)};xt.prototype=Object.create(null);const Ve=[new xt];function Ln(r,e,t){if(r.length==0)return Ve;let n=t?Ve[0]:new xt,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new xt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new xt(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 Ui(r,e,t,n){if(t==Ve&&n==Ve)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=Ve[0]),i=a}Ql(i,l||Ve[0],o)}return i}function Ql(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 _i(r,e,t){return Ui(r,r,Ve,Ln(e,t,r.nodeType!=1))}function qt(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 Gi(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}class ea{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=ta(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){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=ne,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1;for(let a=this.index;a<Math.min(this.index+3,this.top.children.length);a++){let c=this.top.children[a];if(c.matchesMark(e[s])&&!this.isLocked(c.dom)){l=a;break}}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=$e.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}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==ue&&o.dom==o.contentDOM&&(o.dirty=Le),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 we){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let u=a.dom,d,f=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=ue&&qt(t,a.outerDeco));if(!f&&a.update(e,t,n,i))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!f&&(d=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=Le,d.updateChildren(i,o+1),d.dirty=ne),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)||!qt(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=we.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=we.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 Hi(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 $e;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Jt)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((K||H)&&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 qi(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 ta(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 $e)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 na(r,e){return r.type.side-e.type.side}function ra(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let u=r.child(c);n(u,i,e.forChild(s,u),c),s+=u.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let u,d;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(u?(d||(d=[u])).push(g):u=g)}if(u)if(d){d.sort(na);for(let g=0;g<d.length;g++)t(d[g],c,!!a)}else t(u,c,!!a);let f,h;if(a)h=-1,f=a,a=null;else if(c<r.childCount)h=c,f=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+f.nodeSize;if(f.isText){let g=p;o<i.length&&i[o].from<g&&(g=i[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<p&&(a=f.cut(g-s),f=f.cut(0,g-s),p=g,h=-1)}else for(;o<i.length&&i[o].to<p;)o++;let m=f.isInline&&!f.isLeaf?l.filter(g=>!g.inline):l.slice();n(f,m,e.forChild(s,f),h),s=p}}function ia(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 sa(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 $n(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,u=l+=a.size;c>=t||u<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),u>t&&s.push(a.slice(t-c,a.size,n)))}return s}function Vn(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(Ht(t)){for(a=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&Dl(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;c=new C(o==f?l:n.resolve(f))}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let h=0;h<t.rangeCount;h++){let p=t.getRangeAt(h);d=Math.min(d,r.docView.posFromDOM(p.startContainer,p.startOffset,1)),f=Math.max(f,r.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(d<0)return null;[a,o]=f==r.state.selection.anchor?[f,d]:[d,f],l=n.resolve(o)}else a=r.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=n.resolve(a);if(!c){let d=e=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=Wn(r,u,l,d)}return c}function Yi(r){return r.editable?r.hasFocus():rs(r)&&document.activeElement&&document.activeElement.contains(r.dom)}function ge(r,e=!1){let t=r.state.selection;if(es(r,t),!!Yi(r)){if(!e&&r.input.mouseDown&&r.input.mouseDown.allowDefault&&H){let n=r.domSelectionRange(),i=r.domObserver.currentSelection;if(n.anchorNode&&i.anchorNode&&ze(n.anchorNode,n.anchorOffset,i.anchorNode,i.anchorOffset)){r.input.mouseDown.delayedSelectionSync=!0,r.domObserver.setCurSelection();return}}if(r.domObserver.disconnectSelection(),r.cursorWrapper)la(r);else{let{anchor:n,head:i}=t,s,o;Xi&&!(t instanceof E)&&(t.$from.parent.inlineContent||(s=Zi(r,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Zi(r,t.to))),r.docView.setSelection(n,i,r,e),Xi&&(s&&Qi(s),o&&Qi(o)),t.visible?r.dom.classList.remove("ProseMirror-hideselection"):(r.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&oa(r))}r.domObserver.setCurSelection(),r.domObserver.connectSelection()}}const Xi=K||H&&vi<63;function Zi(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(K&&i&&i.contentEditable=="false")return jn(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return jn(i);if(s)return jn(s)}}function jn(r){return r.contentEditable="true",K&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function Qi(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function oa(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(()=>{(!Yi(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function la(r){let e=r.domSelection(),t=document.createRange();if(!e)return;let n=r.cursorWrapper.dom,i=n.nodeName=="IMG";i?t.setStart(n.parentNode,V(n)+1):t.setStart(n,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!r.state.selection.visible&&G&&Se<=11&&(n.disabled=!0,n.disabled=!1)}function es(r,e){if(e instanceof C){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(ts(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else ts(r)}function ts(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Wn(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||E.between(e,t,n)}function ns(r){return r.editable&&!r.hasFocus()?!1:rs(r)}function rs(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 aa(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return ze(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Hn(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&&O.findFrom(s,e)}function Me(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function is(r,e,t){let n=r.state.selection;if(n instanceof E)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 Me(r,new E(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=Hn(r.state,e);return i&&i instanceof C?Me(r,i):!1}else if(!(te&&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?C.isSelectable(s)?Me(r,new C(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):yt?Me(r,new E(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof C&&n.node.isInline)return Me(r,new E(e>0?n.$to:n.$from));{let i=Hn(r.state,e);return i?Me(r,i):!1}}}function Kt(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function St(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function nt(r,e){return e<0?ca(r):ua(r)}function ca(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(oe&&t.nodeType==1&&n<Kt(t)&&St(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(St(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(ss(t))break;{let l=t.previousSibling;for(;l&&St(l,-1);)i=t.parentNode,s=V(l),l=l.previousSibling;if(l)t=l,n=Kt(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?Jn(r,t,n):i&&Jn(r,i,s)}function ua(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=Kt(t),s,o;for(;;)if(n<i){if(t.nodeType!=1)break;let l=t.childNodes[n];if(St(l,1))s=t,o=++n;else break}else{if(ss(t))break;{let l=t.nextSibling;for(;l&&St(l,1);)s=l.parentNode,o=V(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=Kt(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&Jn(r,s,o)}function ss(r){let e=r.pmViewDesc;return e&&e.node&&e.node.isBlock}function da(r,e){for(;r&&e==r.childNodes.length&&!gt(r);)e=V(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 fa(r,e){for(;r&&!e&&!gt(r);)e=V(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 Jn(r,e,t){if(e.nodeType!=3){let s,o;(o=da(e,t))?(e=o,t=0):(s=fa(e,t))&&(e=s,t=s.nodeValue.length)}let n=r.domSelection();if(!n)return;if(Ht(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&&ge(r)},50)}function ls(r,e){let t=r.state.doc.resolve(e);if(!(H||Rl)&&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 as(r,e,t){let n=r.state.selection;if(n instanceof E&&!n.empty||t.indexOf("s")>-1||te&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=Hn(r.state,e);if(o&&o instanceof C)return Me(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof Z?O.near(o,e):O.findFrom(o,e);return l?Me(r,l):!1}return!1}function cs(r,e){if(!(r.state.selection instanceof E))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 us(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function ha(r){if(!K||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;us(r,n,"true"),setTimeout(()=>us(r,n,"false"),20)}return!1}function pa(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function ma(r,e){let t=e.keyCode,n=pa(e);if(t==8||te&&t==72&&n=="c")return cs(r,-1)||nt(r,-1);if(t==46&&!e.shiftKey||te&&t==68&&n=="c")return cs(r,1)||nt(r,1);if(t==13||t==27)return!0;if(t==37||te&&t==66&&n=="c"){let i=t==37?ls(r,r.state.selection.from)=="ltr"?-1:1:-1;return is(r,i,n)||nt(r,i)}else if(t==39||te&&t==70&&n=="c"){let i=t==39?ls(r,r.state.selection.from)=="ltr"?1:-1:1;return is(r,i,n)||nt(r,i)}else{if(t==38||te&&t==80&&n=="c")return as(r,-1,n)||nt(r,-1);if(t==40||te&&t==78&&n=="c")return ha(r)||as(r,1,n)||nt(r,1);if(n==(te?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function qn(r,e){r.someProp("transformCopied",h=>{e=h(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 h=n.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),n=h.content}let o=r.someProp("clipboardSerializer")||Re.fromSchema(r.state.schema),l=bs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,u,d=0;for(;c&&c.nodeType==1&&(u=gs[c.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let p=l.createElement(u[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=r.someProp("clipboardTextSerializer",h=>h(e,r))||e.content.textBetween(0,e.content.size,`
|
|
7
7
|
|
|
8
8
|
`);return{dom:a,text:f,slice:e}}function ds(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",f=>{e=f(e,s||n,r)}),s)return e?new k(b.from(r.state.schema.text(e.replace(/\r\n?/g,`
|
|
9
|
-
`))),0,0):k.empty;let d=r.someProp("clipboardTextParser",f=>f(e,i,n,r));if(d)l=d;else{let f=i.marks(),{schema:h}=r.state,p=Re.fromSchema(h);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(h.text(m,f)))})}}else r.someProp("transformPastedHTML",d=>{t=d(t,r)}),o=xa(t),yt&&Sa(o);let c=o&&o.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let d=+u[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||ct.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!ya.test(f.parentNode.nodeName)?{ignore:!0}:null}})),u)l=Ca(ms(l,+u[1],+u[2]),u[4]);else if(l=k.maxOpen(ba(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let h=l.content.firstChild;d<l.openStart&&!h.type.spec.isolating;d++,h=h.firstChild);for(let h=l.content.lastChild;f<l.openEnd&&!h.type.spec.isolating;f++,h=h.lastChild);l=ms(l,d,f)}return r.someProp("transformPasted",d=>{l=d(l,r)}),l}const ya=/^(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 ba(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&&hs(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 u=fs(l,a);o.push(u),i=i.matchType(u.type),s=a}}),o)return b.from(o)}return r}function fs(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,b.from(r));return r}function hs(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=hs(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(b.from(fs(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(b.empty,!0);return r.copy(t.append(n))}function Kn(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=Kn(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(b.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function ms(r,e,t){return e<r.openStart&&(r=new k(Kn(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new k(Kn(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}const gs={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 ys=null;function bs(){return ys||(ys=document.implementation.createHTMLDocument("title"))}let Un=null;function ka(r){let e=window.trustedTypes;return e?(Un||(Un=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Un.createHTML(r)):r}function xa(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=bs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&gs[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=ka(r),i)for(let s=0;s<i.length;s++)t=t.querySelector(i[s])||t;return t}function Sa(r){let e=r.querySelectorAll(H?"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 Ca(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=b.from(a.create(n[l+1],i)),s++,o++}return new k(i,s,o)}const U={},_={},wa={touchstart:!0,touchmove:!0};class Ma{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Ea(r){for(let e in U){let t=U[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Oa(r,n)&&!Gn(r,n)&&(r.editable||!(n.type in _))&&t(r,n)},wa[e]?{passive:!0}:void 0)}K&&r.dom.addEventListener("input",()=>null),_n(r)}function Ee(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Ta(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 _n(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Gn(r,n))})}function Gn(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Oa(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 Na(r,e){!Gn(r,e)&&U[e.type]&&(r.editable||!(e.type in _))&&U[e.type](r,e)}_.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!xs(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(pe&&H&&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,Fe(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||ga(r,t)?t.preventDefault():Ee(r,"key")},_.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)},_.keypress=(r,e)=>{let t=e;if(xs(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||te&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof E)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",s=>s(r,n.$from.pos,n.$to.pos,i))&&r.dispatch(r.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function Ut(r){return{left:r.clientX,top:r.clientY}}function Aa(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Yn(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 rt(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 va(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&C.isSelectable(n)?(rt(r,new C(t)),!0):!1}function Da(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof C&&(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(C.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?(rt(r,C.create(r.state.doc,i)),!0):!1}function Ia(r,e,t,n,i){return Yn(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?Da(r,t):va(r,t))}function Pa(r,e,t,n){return Yn(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Ra(r,e,t,n){return Yn(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Ba(r,t,n)}function Ba(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(rt(r,E.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)rt(r,E.create(n,l+1,l+1+o.content.size));else if(C.isSelectable(o))rt(r,C.create(n,l));else continue;return!0}}function Xn(r){return _t(r)}const ks=te?"metaKey":"ctrlKey";U.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=Xn(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Aa(t,r.input.lastClick)&&!t[ks]&&(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};let o=r.posAtCoords(Ut(t));o&&(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new za(r,o,t,!!n)):(s=="doubleClick"?Pa:Ra)(r,o.pos,o.inside,t)?t.preventDefault():Ee(r,"pointer"))};class za{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[ks],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,o=u.depth?u.before():0}const l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof C&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&oe&&!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)),Ee(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(()=>ge(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(Ut(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ee(this.view,"pointer"):Ia(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||K&&this.mightDrag&&!this.mightDrag.node.isAtom||H&&!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)?(rt(this.view,O.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Ee(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ee(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)}}U.touchstart=r=>{r.input.lastTouch=Date.now(),Xn(r),Ee(r,"pointer")},U.touchmove=r=>{r.input.lastTouch=Date.now(),Ee(r,"pointer")},U.contextmenu=r=>Xn(r);function xs(r,e){return r.composing?!0:K&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const Fa=pe?5e3:-1;_.compositionstart=_.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof E&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))r.markCursor=r.state.storedMarks||t.marks(),_t(r,!0),r.markCursor=null;else if(_t(r,!e.selection.empty),oe&&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}Ss(r,Fa)},_.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.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Ss(r,20))};function Ss(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>_t(r),e))}function Cs(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=$a());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function La(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=vl(e.focusNode,e.focusOffset),n=Dl(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 $a(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function _t(r,e=!1){if(!(pe&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Cs(r),e||r.docView&&r.docView.dirty){let t=Vn(r);return t&&!t.eq(r.state.selection)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!r.state.selection.empty?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function Va(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 Ct=G&&Se<15||et&&zl<604;U.copy=_.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=Ct?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)):Va(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ja(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function Wa(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?wt(r,n.value,null,i,e):wt(r,n.textContent,n.innerHTML,i,e)},50)}function wt(r,e,t,n,i){let s=ds(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||k.empty)))return!0;if(!s)return!1;let o=ja(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 ws(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," "):""}_.paste=(r,e)=>{let t=e;if(r.composing&&!pe)return;let n=Ct?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&wt(r,ws(n),n.getData("text/html"),i,t)?t.preventDefault():Wa(r,t)};class Ms{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Ha=te?"altKey":"ctrlKey";function Es(r,e){let t=r.someProp("dragCopies",n=>!n(e));return t??!e[Ha]}U.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(Ut(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(n&&n.mightDrag)o=C.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=r.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=r.docView&&(o=C.create(r.state.doc,d.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:u}=qn(r,l);(!t.dataTransfer.files.length||!H||vi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ct?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ct||t.dataTransfer.setData("text/plain",c),r.dragging=new Ms(u,Es(r,t),o)},U.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)},_.dragover=_.dragenter=(r,e)=>e.preventDefault(),_.drop=(r,e)=>{let t=e,n=r.dragging;if(r.dragging=null,!t.dataTransfer)return;let i=r.posAtCoords(Ut(t));if(!i)return;let s=r.state.doc.resolve(i.pos),o=n&&n.slice;o?r.someProp("transformPasted",p=>{o=p(o,r)}):o=ds(r,ws(t.dataTransfer),Ct?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(n&&Es(r,t));if(r.someProp("handleDrop",p=>p(r,t,o||k.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?gl(r.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=r.state.tr;if(l){let{node:p}=n;p?p.replace(c):c.deleteSelection()}let u=c.mapping.map(a),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=c.doc;if(d?c.replaceRangeWith(u,u,o.content.firstChild):c.replaceRange(u,u,o),c.doc.eq(f))return;let h=c.doc.resolve(u);if(d&&C.isSelectable(o.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new C(h));else{let p=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,S)=>p=S),c.setSelection(Wn(r,h,c.doc.resolve(p)))}r.focus(),r.dispatch(c.setMeta("uiEvent","drop"))},U.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())&&ge(r)},20))},U.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)},U.beforeinput=(r,e)=>{if(H&&pe&&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,Fe(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 _)U[r]=_[r];function Mt(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 Gt{constructor(e,t){this.toDOM=e,this.spec=t||je,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 re(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Gt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Mt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Te{constructor(e,t){this.attrs=e,this.spec=t||je}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 re(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Te&&Mt(this.attrs,e.attrs)&&Mt(this.spec,e.spec)}static is(e){return e.type instanceof Te}destroy(){}}class Zn{constructor(e,t){this.attrs=e,this.spec=t||je}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 re(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 Zn&&Mt(this.attrs,e.attrs)&&Mt(this.spec,e.spec)}destroy(){}}class re{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new re(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 re(e,e,new Gt(t,n))}static inline(e,t,n,i){return new re(e,t,new Te(n,i))}static node(e,t,n,i){return new re(e,t,new Zn(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Te}get widget(){return this.type instanceof Gt}}const it=[],je={};class z{constructor(e,t){this.local=e.length?e:it,this.children=t.length?t:it}static create(e,t){return t.length?Yt(t,e,0,je):J}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==J||e.maps.length==0?this:this.mapInner(e,t,0,0,n||je)}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?Ja(this.children,o||[],e,t,n,i,s):o?new z(o.sort(We),it):J}add(e,t){return t.length?this==J?z.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,u;if(u=Os(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,u,c+1):i.splice(s,0,a,a+l.nodeSize,Yt(u,l,c+1,je)),s+=3}});let o=Ts(s?Ns(t):t,-n);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new z(o.length?this.local.concat(o).sort(We):this.local,i||this.children)}remove(e){return e.length==0||this==J?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 u=0,d;u<e.length;u++)(d=e[u])&&d.from>l&&d.to<a&&(e[u]=null,(o||(o=[])).push(d));if(!o)continue;n==this.children&&(n=this.children.slice());let c=n[s+2].removeInner(o,l+1);c!=J?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 z(i,n):J}forChild(e,t){if(this==J)return this;if(t.isLeaf)return z.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 Te){let c=Math.max(s,a.from)-s,u=Math.min(o,a.to)-s;c<u&&(i||(i=[])).push(a.copy(c,u))}}if(i){let l=new z(i.sort(We),it);return n?new Oe([l,n]):l}return n||J}eq(e){if(this==e)return!0;if(!(e instanceof z)||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 Qn(this.localsInner(e))}localsInner(e){if(this==J)return it;if(e.inlineContent||!this.local.some(Te.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Te||t.push(this.local[n]);return t}forEachSet(e){e(this)}}z.empty=new z([],[]),z.removeOverlap=Qn;const J=z.empty;class Oe{constructor(e){this.members=e}map(e,t){const n=this.members.map(i=>i.map(e,t,je));return Oe.from(n)}forChild(e,t){if(t.isLeaf)return z.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=J&&(s instanceof Oe?n=n.concat(s.members):n.push(s))}return Oe.from(n)}eq(e){if(!(e instanceof Oe)||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?Qn(n?t:t.sort(We)):it}static from(e){switch(e.length){case 0:return J;case 1:return e[0];default:return new Oe(e.every(t=>t instanceof z)?e:e.reduce((t,n)=>t.concat(n instanceof z?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Ja(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,u=s;c<t.maps.length;c++){let d=0;t.maps[c].forEach((f,h,p,m)=>{let g=m-p-(h-f);for(let y=0;y<l.length;y+=3){let S=l[y+1];if(S<0||f>S+u-d)continue;let w=l[y]+u-d;h>=w?l[y+1]=f<=w?-2:-1:f>=u&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let u=t.map(r[c]+s),d=u-i;if(d<0||d>=n.content.size){a=!0;continue}let f=t.map(r[c+1]+s,-1),h=f-i,{index:p,offset:m}=n.content.findIndex(d),g=n.maybeChild(p);if(g&&m==d&&m+g.nodeSize==h){let y=l[c+2].mapInner(t,g,u+1,r[c]+s+1,o);y!=J?(l[c]=d,l[c+1]=h,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=qa(l,r,e,t,i,s,o),u=Yt(c,n,0,o);e=u.local;for(let d=0;d<l.length;d+=3)l[d+1]<0&&(l.splice(d,3),d-=3);for(let d=0,f=0;d<u.children.length;d+=3){let h=u.children[d];for(;f<l.length&&l[f]<h;)f+=3;l.splice(f,0,u.children[d],u.children[d+1],u.children[d+2])}}return new z(e.sort(We),l)}function Ts(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 re(i.from+e,i.to+e,i.type))}return t}function qa(r,e,t,n,i,s,o){function l(a,c){for(let u=0;u<a.local.length;u++){let d=a.local[u].map(n,i,c);d?t.push(d):o.onRemove&&o.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+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 Os(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 Ns(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function Yt(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=Os(r,l,a+t);if(c){s=!0;let u=Yt(c,l,t+a+1,n);u!=J&&i.push(a,a+l.nodeSize,u)}});let o=Ts(s?Ns(r):r,-t).sort(We);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 z(o,i):J}function We(r,e){return r.from-e.from||r.to-e.to}function Qn(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),As(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),As(e,i,n.copy(s.from,n.to)));break}}}return e}function As(r,e,t){for(;e<r.length&&We(t,r[e])>0;)e++;r.splice(e,0,t)}function er(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=J&&e.push(n)}),r.cursorWrapper&&e.push(z.create(r.state.doc,[r.cursorWrapper.deco])),Oe.from(e)}const Ka={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Ua=G&&Se<=11;class _a{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 Ga{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new _a,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]);G&&Se<=11&&n.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Ua&&(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,Ka)),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(ns(this.view)){if(this.suppressingSelectionUpdates)return ge(this.view);if(G&&Se<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&ze(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)&&ns(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let d=this.registerMutation(t[u],a);d&&(s=s<0?d.from:Math.min(d.from,s),o=o<0?d.to:Math.max(d.to,o),d.typeOver&&(l=!0))}if(oe&&a.length){let u=a.filter(d=>d.nodeName=="BR");if(u.length==2){let[d,f]=u;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of u){let h=f.parentNode;h&&h.nodeName=="LI"&&(!d||Za(e,d)!=h)&&f.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ht(n)&&(c=Vn(e))&&c.eq(O.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ge(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Ya(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ge(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 u=0;u<e.addedNodes.length;u++){let d=e.addedNodes[u];t.push(d),d.nodeType==3&&(this.lastChangedTextNode=d)}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(G&&Se<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:d,nextSibling:f}=e.addedNodes[u];(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(i=d),(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(s=f)}let o=i&&i.parentNode==e.target?V(i)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?V(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 vs=new WeakMap,Ds=!1;function Ya(r){if(!vs.has(r)&&(vs.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=oe,Ds)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."),Ds=!0}}function Is(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return ze(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:i,focusOffset:s}}function Xa(r,e){if(e.getComposedRanges){let i=e.getComposedRanges(r.root)[0];if(i)return Is(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?Is(r,t):null}function Za(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 Qa(r,e,t){let{node:n,fromOffset:i,toOffset:s,from:o,to:l}=r.docView.parseRange(e,t),a=r.domSelectionRange(),c,u=a.anchorNode;if(u&&r.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:a.anchorOffset}],Ht(a)||c.push({node:a.focusNode,offset:a.focusOffset})),H&&r.input.lastKeyCode===8)for(let g=s;g>i;g--){let y=n.childNodes[g-1],S=y.pmViewDesc;if(y.nodeName=="BR"&&!S){s=g;break}if(!S||S.size)break}let d=r.state.doc,f=r.someProp("domParser")||ct.fromSchema(r.state.schema),h=d.resolve(o),p=null,m=f.parse(n,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:ec,context:h});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function ec(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(K&&/^(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||K&&/^(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 tc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function nc(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let T=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,ie=Vn(r,T);if(ie&&!r.state.selection.eq(ie)){if(H&&pe&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&r.someProp("handleKeyDown",Gd=>Gd(r,Fe(13,"Enter"))))return;let gn=r.state.tr.setSelection(ie);T=="pointer"?gn.setMeta("pointer",!0):T=="key"&&gn.scrollIntoView(),s&&gn.setMeta("composition",s),r.dispatch(gn)}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=Qa(r,e,t),u=r.state.doc,d=u.slice(c.from,c.to),f,h;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(f=r.state.selection.to,h="end"):(f=r.state.selection.from,h="start"),r.input.lastKeyCode=null;let p=sc(d.content,c.doc.content,c.from,f,h);if(p&&r.input.domChangeCount++,(et&&r.input.lastIOSEnter>Date.now()-225||pe)&&i.some(T=>T.nodeType==1&&!tc.test(T.nodeName))&&(!p||p.endA>=p.endB)&&r.someProp("handleKeyDown",T=>T(r,Fe(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof E&&!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 T=Ps(r,r.state.doc,c.sel);if(T&&!T.eq(r.state.selection)){let ie=r.state.tr.setSelection(T);s&&ie.setMeta("composition",s),r.dispatch(ie)}}return}r.state.selection.from<r.state.selection.to&&p.start==p.endB&&r.state.selection instanceof E&&(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)),G&&Se<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)==" "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),y=u.resolve(p.start),S=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,w;if((et&&r.input.lastIOSEnter>Date.now()-225&&(!S||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!S&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&(w=O.findFrom(c.doc.resolve(m.pos+1),1,!0))&&w.head>m.pos)&&r.someProp("handleKeyDown",T=>T(r,Fe(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>p.start&&ic(u,p.start,p.endA,m,g)&&r.someProp("handleKeyDown",T=>T(r,Fe(8,"Backspace")))){pe&&H&&r.domObserver.suppressSelectionUpdates();return}H&&p.endB==p.start&&(r.input.lastChromeDelete=Date.now()),pe&&!S&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(T){return T(r,Fe(13,"Enter"))})},20));let v=p.start,A=p.endA,M,I,q;if(S){if(m.pos==g.pos)G&&Se<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>ge(r),20)),M=r.state.tr.delete(v,A),I=u.resolve(p.start).marksAcross(u.resolve(p.endA));else if(p.endA==p.endB&&(q=rc(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))M=r.state.tr,q.type=="add"?M.addMark(v,A,q.mark):M.removeMark(v,A,q.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(r.someProp("handleTextInput",ie=>ie(r,v,A,T)))return;M=r.state.tr.insertText(T,v,A)}}if(M||(M=r.state.tr.replace(v,A,c.doc.slice(p.start-c.from,p.endB-c.from))),c.sel){let T=Ps(r,M.doc,c.sel);T&&!(H&&r.composing&&T.empty&&(p.start!=p.endB||r.input.lastChromeDelete<Date.now()-100)&&(T.head==v||T.head==M.mapping.map(A)-1)||G&&T.empty&&T.head==v)&&M.setSelection(T)}I&&M.ensureMarks(I),s&&M.setMeta("composition",s),r.dispatch(M.scrollIntoView())}function Ps(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Wn(r,e.resolve(t.anchor),e.resolve(t.head))}function rc(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let u=0;u<n.length;u++)i=n[u].removeFromSet(i);for(let u=0;u<t.length;u++)s=t[u].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=u=>u.mark(l.addToSet(u.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(a(e.child(u)));if(b.from(c).eq(r))return{mark:l,type:o}}function ic(r,e,t,n,i){if(t-e<=i.pos-n.pos||tr(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(tr(s,!0,!0));return!o.parent.isTextblock||o.pos>t||tr(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function tr(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 sc(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&&Rs(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&&Rs(r.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function Rs(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 oc{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 Ma,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach($s),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=Fs(this),zs(this),this.nodeViews=Ls(this),this.docView=Ji(this.state.doc,Bs(this),er(this),this.dom,this),this.domObserver=new Ga(this,(n,i,s,o)=>nc(this,n,i,s,o)),this.domObserver.start(),Ea(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&&_n(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach($s),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&&(Cs(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 h=Ls(this);ac(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&_n(this),this.editable=Fs(this),zs(this);let a=er(this),c=Bs(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,c,a);(d||!e.selection.eq(i.selection))&&(o=!0);let f=u=="preserve"&&o&&this.dom.style.overflowAnchor==null&&$l(this);if(o){this.domObserver.stop();let h=d&&(G||H)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&lc(i.selection,e.selection);if(d){let p=H?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=La(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Ji(e.doc,c,a,this.dom,this)),p&&!this.trackWrites&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ca(this))?ge(this,h):(es(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),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():f&&Vl(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Di(this,t.getBoundingClientRect(),e)}else Di(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 Ms(e.slice,e.move,i<0?void 0:C.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(G){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&&jl(this.dom),ge(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 Kl(this,e)}coordsAtPos(e,t=1){return Fi(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 Xl(this,t||this.state,e)}pasteHTML(e,t){return wt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return wt(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return qn(this,e)}destroy(){this.docView&&(Ta(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],er(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Nl())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Na(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?K&&this.root.nodeType===11&&Pl(this.dom.ownerDocument)==this.dom&&Xa(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Bs(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"),[re.node(0,r.state.doc.content.size,e)]}function zs(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:re.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function Fs(r){return!r.someProp("editable",e=>e(r.state)===!1)}function lc(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 Ls(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 ac(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 $s(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")}for(var Ne={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Xt={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},cc=typeof navigator<"u"&&/Mac/.test(navigator.platform),uc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),j=0;j<10;j++)Ne[48+j]=Ne[96+j]=String(j);for(var j=1;j<=24;j++)Ne[j+111]="F"+j;for(var j=65;j<=90;j++)Ne[j]=String.fromCharCode(j+32),Xt[j]=String.fromCharCode(j);for(var nr in Ne)Xt.hasOwnProperty(nr)||(Xt[nr]=Ne[nr]);function dc(r){var e=cc&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||uc&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?Xt:Ne)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const fc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function hc(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))fc?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 pc(r){let e=Object.create(null);for(let t in r)e[hc(t)]=r[t];return e}function rr(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 mc(r){return new Q({props:{handleKeyDown:gc(r)}})}function gc(r){let e=pc(r);return function(t,n){let i=dc(n),s,o=e[rr(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[rr(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.shiftKey||n.altKey||n.metaKey||i.charCodeAt(0)>127)&&(s=Ne[n.keyCode])&&s!=i){let l=e[rr(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const ir=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Vs(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const js=(r,e,t)=>{let n=Vs(r,t);if(!n)return!1;let i=sr(n);if(!i){let o=n.blockRange(),l=o&&_e(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Ys(r,i,e,-1))return!0;if(n.parent.content.size==0&&(st(s,"end")||C.isSelectable(s)))for(let o=n.depth;;o--){let l=jt(r.doc,n.before(o),n.after(o),k.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(st(s,"end")?O.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):C.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},yc=(r,e,t)=>{let n=Vs(r,t);if(!n)return!1;let i=sr(n);return i?Ws(r,i,e):!1},bc=(r,e,t)=>{let n=Js(r,t);if(!n)return!1;let i=or(n);return i?Ws(r,i,e):!1};function Ws(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 u=i.lastChild;if(!u)return!1;i=u}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let c=jt(r.doc,s,a,k.empty);if(!c||c.from!=s||c instanceof B&&c.slice.size>=a-s)return!1;if(t){let u=r.tr.step(c);u.setSelection(E.create(u.doc,s)),t(u.scrollIntoView())}return!0}function st(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 Hs=(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=sr(n)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(r.tr.setSelection(C.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function sr(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 Js(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}const qs=(r,e,t)=>{let n=Js(r,t);if(!n)return!1;let i=or(n);if(!i)return!1;let s=i.nodeAfter;if(Ys(r,i,e,1))return!0;if(n.parent.content.size==0&&(st(s,"start")||C.isSelectable(s))){let o=jt(r.doc,n.before(),n.after(),k.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(st(s,"start")?O.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):C.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},Ks=(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=or(n)}let o=s&&s.nodeAfter;return!o||!C.isSelectable(o)?!1:(e&&e(r.tr.setSelection(C.create(r.doc,s.pos)).scrollIntoView()),!0)};function or(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 kc=(r,e)=>{let t=r.selection,n=t instanceof C,i;if(n){if(t.node.isTextblock||!Be(r.doc,t.from))return!1;i=t.from}else if(i=Vt(r.doc,t.from,-1),i==null)return!1;if(e){let s=r.tr.join(i);n&&s.setSelection(C.create(s.doc,i-r.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},xc=(r,e)=>{let t=r.selection,n;if(t instanceof C){if(t.node.isTextblock||!Be(r.doc,t.to))return!1;n=t.to}else if(n=Vt(r.doc,t.to,1),n==null)return!1;return e&&e(r.tr.join(n).scrollIntoView()),!0},Sc=(r,e)=>{let{$from:t,$to:n}=r.selection,i=t.blockRange(n),s=i&&_e(i);return s==null?!1:(e&&e(r.tr.lift(i,s).scrollIntoView()),!0)},Us=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
|
|
10
|
-
`).scrollIntoView()),!0)};function lr(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 Cc=(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=lr(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(O.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},_s=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof Z||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=lr(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(E.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Gs=(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(fe(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&_e(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function wc(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!n.parentOffset||!fe(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 h=n.depth;;h--)if(n.node(h).isBlock){a=n.end(h)==n.pos+(n.depth-h),c=n.start(h)==n.pos-(n.depth-h),l=lr(n.node(h-1).contentMatchAt(n.indexAfter(h-1))),s.unshift(a&&l?{type:l}:null),o=h;break}else{if(h==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof E||e.selection instanceof Z)&&u.deleteSelection();let d=u.mapping.map(n.pos),f=fe(u.doc,d,s.length,s);if(f||(s[0]=l?{type:l}:null,f=fe(u.doc,d,s.length,s)),!f)return!1;if(u.split(d,s.length,s),!a&&c&&n.node(o).type!=l){let h=u.mapping.map(n.before(o)),p=u.doc.resolve(h);l&&n.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&u.setNodeMarkup(u.mapping.map(n.before(o)),l)}return t&&t(u.scrollIntoView()),!0}}const Mc=wc(),Ec=(r,e)=>{let{$from:t,to:n}=r.selection,i,s=t.sharedDepth(n);return s==0?!1:(i=t.before(s),e&&e(r.tr.setSelection(C.create(r.doc,i))),!0)};function Tc(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||Be(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Ys(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Tc(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 h=e.pos+s.nodeSize,p=b.empty;for(let y=o.length-1;y>=0;y--)p=b.from(o[y].create(null,p));p=b.from(i.copy(p));let m=r.tr.step(new F(e.pos-1,h,e.pos,h,new k(p,1,0),o.length,!0)),g=m.doc.resolve(h+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Be(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let u=s.type.spec.isolating||n>0&&a?null:O.findFrom(e,1),d=u&&u.$from.blockRange(u.$to),f=d&&_e(d);if(f!=null&&f>=e.depth)return t&&t(r.tr.lift(d,f).scrollIntoView()),!0;if(c&&st(s,"start",!0)&&st(i,"end")){let h=i,p=[];for(;p.push(h),!h.isTextblock;)h=h.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(h.canReplace(h.childCount,h.childCount,m.content)){if(t){let y=b.empty;for(let w=p.length-1;w>=0;w--)y=b.from(p[w].copy(y));let S=r.tr.step(new F(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new k(y,p.length,0),0,!0));t(S.scrollIntoView())}return!0}}return!1}function Xs(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(E.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const Oc=Xs(-1),Nc=Xs(1);function Ac(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&ci(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Zs(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 u=t.doc.resolve(c),d=u.index();i=u.parent.canReplaceWith(d,d+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 ar(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}ar(ir,js,Hs),ar(ir,qs,Ks),ar(Us,_s,Gs,Mc),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function vc(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s);if(!o)return!1;let l=n?t.tr:null;return Dc(l,o,r,e)?(n&&n(l.scrollIntoView()),!0):!1}}function Dc(r,e,t,n=null){let i=!1,s=e,o=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new Pt(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new Pt(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),i=!0}let l=ci(s,t,n,e);return l?(r&&Ic(r,e,l,i,t),!0):!1}function Ic(r,e,t,n,i){let s=b.empty;for(let u=t.length-1;u>=0;u--)s=b.from(t[u].type.create(t[u].attrs,s));r.step(new F(e.start-(n?2:0),e.end,e.start,e.end,new k(s,0,0),t.length,!0));let o=0;for(let u=0;u<t.length;u++)t[u].type==i&&(o=u+1);let l=t.length-o,a=e.start+t.length-(n?2:0),c=e.parent;for(let u=e.startIndex,d=e.endIndex,f=!0;u<d;u++,f=!1)!f&&fe(r.doc,a,l)&&(r.split(a,l),a+=2*l),a+=c.child(u).nodeSize;return r}function Pc(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?Rc(e,t,r,s):Bc(e,t,s):!0:!1}}function Rc(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);s<o&&(i.step(new F(s-1,o,s,o,new k(b.from(t.create(null,n.parent.copy())),1,0),1,!0)),n=new Pt(i.doc.resolve(n.$from.pos),i.doc.resolve(o),n.depth));const l=_e(n);if(l==null)return!1;i.lift(n,l);let a=i.doc.resolve(i.mapping.map(s,-1)-1);return Be(i.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&i.join(a.pos),e(i.scrollIntoView()),!0}function Bc(r,e,t){let n=r.tr,i=t.parent;for(let h=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)h-=i.child(p).nodeSize,n.delete(h-1,h+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),u=s.index(-1);if(!c.canReplace(u+(l?0:1),u+1,o.content.append(a?b.empty:b.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return n.step(new F(d-(l?1:0),f+(a?1:0),d+1,f-1,new k((l?b.empty:b.from(i.copy(b.empty))).append(a?b.empty:b.from(i.copy(b.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function zc(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,u=b.from(c?r.create():null),d=new k(b.from(r.create(null,b.from(l.type.create(null,u)))),c?3:1,0),f=s.start,h=s.end;t(e.tr.step(new F(f-(c?3:1),h,f,h,d,1,!0)).scrollIntoView())}return!0}}function Zt(r){const{state:e,transaction:t}=r;let{selection:n}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return n},get doc(){return i},get tr(){return n=t.selection,i=t.doc,s=t.storedMarks,t}}}class Qt{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:i}=t,{tr:s}=n,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...u)=>{const d=a(...u)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,u=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(n).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,t),y=h(...m)(g);return l.push(y),d}])),run:u};return d}createCan(e){const{rawCommands:t,state:n}=this,i=!1,s=e||n.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...u)=>c(...u)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:Zt({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([a,c])=>[a,(...u)=>c(...u)(l)]))}};return l}}class Fc{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach(i=>i.apply(this,t)),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(i=>i!==t):delete this.callbacks[e]),this}once(e,t){const n=(...i)=>{this.off(e,n),t.apply(this,i)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}}function x(r,e,t){return r.config[e]===void 0&&r.parent?x(r.parent,e,t):typeof r.config[e]=="function"?r.config[e].bind({...t,parent:r.parent?x(r.parent,e,t):null}):r.config[e]}function en(r){const e=r.filter(i=>i.type==="extension"),t=r.filter(i=>i.type==="node"),n=r.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:n}}function Qs(r){const e=[],{nodeExtensions:t,markExtensions:n}=en(r),i=[...t,...n],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return r.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage,extensions:i},a=x(o,"addGlobalAttributes",l);if(!a)return;a().forEach(u=>{u.types.forEach(d=>{Object.entries(u.attributes).forEach(([f,h])=>{e.push({type:d,name:f,attribute:{...s,...h}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=x(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([u,d])=>{const f={...s,...d};typeof(f==null?void 0:f.default)=="function"&&(f.default=f.default()),f!=null&&f.isRequired&&(f==null?void 0:f.default)===void 0&&delete f.default,e.push({type:o.name,name:u,attribute:f})})}),e}function L(r,e){if(typeof r=="string"){if(!e.nodes[r])throw Error(`There is no node type named '${r}'. Maybe you forgot to add the extension?`);return e.nodes[r]}return r}function Lc(...r){return r.filter(e=>!!e).reduce((e,t)=>{const n={...e};return Object.entries(t).forEach(([i,s])=>{if(!n[i]){n[i]=s;return}if(i==="class"){const l=s?String(s).split(" "):[],a=n[i]?n[i].split(" "):[],c=l.filter(u=>!a.includes(u));n[i]=[...a,...c].join(" ")}else if(i==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],a=n[i]?n[i].split(";").map(u=>u.trim()).filter(Boolean):[],c=new Map;a.forEach(u=>{const[d,f]=u.split(":").map(h=>h.trim());c.set(d,f)}),l.forEach(u=>{const[d,f]=u.split(":").map(h=>h.trim());c.set(d,f)}),n[i]=Array.from(c.entries()).map(([u,d])=>`${u}: ${d}`).join("; ")}else n[i]=s}),n},{})}function cr(r,e){return e.filter(t=>t.type===r.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(r.attrs)||{}:{[t.name]:r.attrs[t.name]}).reduce((t,n)=>Lc(t,n),{})}function eo(r){return typeof r=="function"}function N(r,e=void 0,...t){return eo(r)?e?r.bind(e)(...t):r(...t):r}function $c(r={}){return Object.keys(r).length===0&&r.constructor===Object}function Vc(r){return typeof r!="string"?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):r==="true"?!0:r==="false"?!1:r}function to(r,e){return"style"in r?r:{...r,getAttrs:t=>{const n=r.getAttrs?r.getAttrs(t):r.attrs;if(n===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):Vc(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...n,...i}}}}function no(r){return Object.fromEntries(Object.entries(r).filter(([e,t])=>e==="attrs"&&$c(t)?!1:t!=null))}function jc(r,e){var t;const n=Qs(r),{nodeExtensions:i,markExtensions:s}=en(r),o=(t=i.find(c=>x(c,"topNode")))===null||t===void 0?void 0:t.name,l=Object.fromEntries(i.map(c=>{const u=n.filter(y=>y.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=r.reduce((y,S)=>{const w=x(S,"extendNodeSchema",d);return{...y,...w?w(c):{}}},{}),h=no({...f,content:N(x(c,"content",d)),marks:N(x(c,"marks",d)),group:N(x(c,"group",d)),inline:N(x(c,"inline",d)),atom:N(x(c,"atom",d)),selectable:N(x(c,"selectable",d)),draggable:N(x(c,"draggable",d)),code:N(x(c,"code",d)),whitespace:N(x(c,"whitespace",d)),linebreakReplacement:N(x(c,"linebreakReplacement",d)),defining:N(x(c,"defining",d)),isolating:N(x(c,"isolating",d)),attrs:Object.fromEntries(u.map(y=>{var S;return[y.name,{default:(S=y==null?void 0:y.attribute)===null||S===void 0?void 0:S.default}]}))}),p=N(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(y=>to(y,u)));const m=x(c,"renderHTML",d);m&&(h.toDOM=y=>m({node:y,HTMLAttributes:cr(y,u)}));const g=x(c,"renderText",d);return g&&(h.toText=g),[c.name,h]})),a=Object.fromEntries(s.map(c=>{const u=n.filter(g=>g.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=r.reduce((g,y)=>{const S=x(y,"extendMarkSchema",d);return{...g,...S?S(c):{}}},{}),h=no({...f,inclusive:N(x(c,"inclusive",d)),excludes:N(x(c,"excludes",d)),group:N(x(c,"group",d)),spanning:N(x(c,"spanning",d)),code:N(x(c,"code",d)),attrs:Object.fromEntries(u.map(g=>{var y;return[g.name,{default:(y=g==null?void 0:g.attribute)===null||y===void 0?void 0:y.default}]}))}),p=N(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(g=>to(g,u)));const m=x(c,"renderHTML",d);return m&&(h.toDOM=g=>m({mark:g,HTMLAttributes:cr(g,u)})),[c.name,h]}));return new Ur({topNode:o,nodes:l,marks:a})}function ur(r,e){return e.nodes[r]||e.marks[r]||null}function ro(r,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===r.name):e}function dr(r,e){const t=Re.fromSchema(e).serializeFragment(r),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}const Wc=(r,e=500)=>{let t="";const n=r.parentOffset;return r.parent.nodesBetween(Math.max(0,n-e),n,(i,s,o,l)=>{var a,c;const u=((c=(a=i.type.spec).toText)===null||c===void 0?void 0:c.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";t+=i.isAtom&&!i.isText?u:u.slice(0,Math.max(0,n-s))}),t};function fr(r){return Object.prototype.toString.call(r)==="[object RegExp]"}const Hc=(r,e)=>{if(fr(e))return e.exec(r);const t=e(r);if(!t)return null;const n=[t.text];return n.index=t.index,n.input=r,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),n.push(t.replaceWith)),n};function tn(r){var e;const{editor:t,from:n,to:i,text:s,rules:o,plugin:l}=r,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(n);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(f=>f.type.spec.code))return!1;let u=!1;const d=Wc(c)+s;return o.forEach(f=>{if(u)return;const h=Hc(d,f.find);if(!h)return;const p=a.state.tr,m=Zt({state:a.state,transaction:p}),g={from:n-(h[0].length-s.length),to:i},{commands:y,chain:S,can:w}=new Qt({editor:t,state:m});f.handler({state:m,range:g,match:h,commands:y,chain:S,can:w})===null||!p.steps.length||(p.setMeta(l,{transform:p,from:n,to:i,text:s}),a.dispatch(p),u=!0)}),u}function Jc(r){const{editor:e,rules:t}=r,n=new Q({state:{init(){return null},apply(i,s,o){const l=i.getMeta(n);if(l)return l;const a=i.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:u}=a;typeof u=="string"?u=u:u=dr(b.from(u),o.schema);const{from:d}=a,f=d+u.length;tn({editor:e,from:d,to:f,text:u,rules:t,plugin:n})}),i.selectionSet||i.docChanged?null:s}},props:{handleTextInput(i,s,o,l){return tn({editor:e,from:s,to:o,text:l,rules:t,plugin:n})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&tn({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:n})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?tn({editor:e,from:o.pos,to:o.pos,text:`
|
|
11
|
-
`,rules:t,plugin:n}):!1}},isInputRules:!0});return n}function
|
|
9
|
+
`))),0,0):k.empty;let d=r.someProp("clipboardTextParser",f=>f(e,i,n,r));if(d)l=d;else{let f=i.marks(),{schema:h}=r.state,p=Re.fromSchema(h);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(h.text(m,f)))})}}else r.someProp("transformPastedHTML",d=>{t=d(t,r)}),o=ka(t),yt&&xa(o);let c=o&&o.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let d=+u[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||ct.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!ga.test(f.parentNode.nodeName)?{ignore:!0}:null}})),u)l=Sa(ms(l,+u[1],+u[2]),u[4]);else if(l=k.maxOpen(ya(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let h=l.content.firstChild;d<l.openStart&&!h.type.spec.isolating;d++,h=h.firstChild);for(let h=l.content.lastChild;f<l.openEnd&&!h.type.spec.isolating;f++,h=h.lastChild);l=ms(l,d,f)}return r.someProp("transformPasted",d=>{l=d(l,r)}),l}const ga=/^(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 ya(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&&hs(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 u=fs(l,a);o.push(u),i=i.matchType(u.type),s=a}}),o)return b.from(o)}return r}function fs(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,b.from(r));return r}function hs(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=hs(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(b.from(fs(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(b.empty,!0);return r.copy(t.append(n))}function Kn(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=Kn(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(b.empty,!0))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function ms(r,e,t){return e<r.openStart&&(r=new k(Kn(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new k(Kn(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}const gs={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 ys=null;function bs(){return ys||(ys=document.implementation.createHTMLDocument("title"))}let Un=null;function ba(r){let e=window.trustedTypes;return e?(Un||(Un=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Un.createHTML(r)):r}function ka(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=bs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&gs[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=ba(r),i)for(let s=0;s<i.length;s++)t=t.querySelector(i[s])||t;return t}function xa(r){let e=r.querySelectorAll(H?"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 Sa(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=b.from(a.create(n[l+1],i)),s++,o++}return new k(i,s,o)}const U={},_={},Ca={touchstart:!0,touchmove:!0};class wa{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Ma(r){for(let e in U){let t=U[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Ta(r,n)&&!Gn(r,n)&&(r.editable||!(n.type in _))&&t(r,n)},Ca[e]?{passive:!0}:void 0)}K&&r.dom.addEventListener("input",()=>null),_n(r)}function Ee(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Ea(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 _n(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Gn(r,n))})}function Gn(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Ta(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 Oa(r,e){!Gn(r,e)&&U[e.type]&&(r.editable||!(e.type in _))&&U[e.type](r,e)}_.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!xs(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(pe&&H&&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,Fe(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||ma(r,t)?t.preventDefault():Ee(r,"key")},_.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)},_.keypress=(r,e)=>{let t=e;if(xs(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||te&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof E)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",s=>s(r,n.$from.pos,n.$to.pos,i))&&r.dispatch(r.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function Ut(r){return{left:r.clientX,top:r.clientY}}function Na(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Yn(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 rt(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 Aa(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&C.isSelectable(n)?(rt(r,new C(t)),!0):!1}function va(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof C&&(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(C.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?(rt(r,C.create(r.state.doc,i)),!0):!1}function Da(r,e,t,n,i){return Yn(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?va(r,t):Aa(r,t))}function Ia(r,e,t,n){return Yn(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Pa(r,e,t,n){return Yn(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Ra(r,t,n)}function Ra(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(rt(r,E.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)rt(r,E.create(n,l+1,l+1+o.content.size));else if(C.isSelectable(o))rt(r,C.create(n,l));else continue;return!0}}function Xn(r){return _t(r)}const ks=te?"metaKey":"ctrlKey";U.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=Xn(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Na(t,r.input.lastClick)&&!t[ks]&&(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};let o=r.posAtCoords(Ut(t));o&&(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new Ba(r,o,t,!!n)):(s=="doubleClick"?Ia:Pa)(r,o.pos,o.inside,t)?t.preventDefault():Ee(r,"pointer"))};class Ba{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[ks],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,o=u.depth?u.before():0}const l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof C&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&oe&&!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)),Ee(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(()=>ge(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(Ut(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ee(this.view,"pointer"):Da(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||K&&this.mightDrag&&!this.mightDrag.node.isAtom||H&&!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)?(rt(this.view,O.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Ee(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ee(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)}}U.touchstart=r=>{r.input.lastTouch=Date.now(),Xn(r),Ee(r,"pointer")},U.touchmove=r=>{r.input.lastTouch=Date.now(),Ee(r,"pointer")},U.contextmenu=r=>Xn(r);function xs(r,e){return r.composing?!0:K&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const za=pe?5e3:-1;_.compositionstart=_.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof E&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))r.markCursor=r.state.storedMarks||t.marks(),_t(r,!0),r.markCursor=null;else if(_t(r,!e.selection.empty),oe&&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}Ss(r,za)},_.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.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,Ss(r,20))};function Ss(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>_t(r),e))}function Cs(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=La());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Fa(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=Al(e.focusNode,e.focusOffset),n=vl(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 La(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function _t(r,e=!1){if(!(pe&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Cs(r),e||r.docView&&r.docView.dirty){let t=Vn(r);return t&&!t.eq(r.state.selection)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!r.state.selection.empty?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function $a(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 Ct=G&&Se<15||et&&Bl<604;U.copy=_.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=Ct?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)):$a(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Va(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function ja(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?wt(r,n.value,null,i,e):wt(r,n.textContent,n.innerHTML,i,e)},50)}function wt(r,e,t,n,i){let s=ds(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||k.empty)))return!0;if(!s)return!1;let o=Va(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 ws(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," "):""}_.paste=(r,e)=>{let t=e;if(r.composing&&!pe)return;let n=Ct?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&wt(r,ws(n),n.getData("text/html"),i,t)?t.preventDefault():ja(r,t)};class Ms{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Wa=te?"altKey":"ctrlKey";function Es(r,e){let t=r.someProp("dragCopies",n=>!n(e));return t??!e[Wa]}U.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(Ut(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(n&&n.mightDrag)o=C.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=r.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=r.docView&&(o=C.create(r.state.doc,d.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:u}=qn(r,l);(!t.dataTransfer.files.length||!H||vi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ct?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ct||t.dataTransfer.setData("text/plain",c),r.dragging=new Ms(u,Es(r,t),o)},U.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)},_.dragover=_.dragenter=(r,e)=>e.preventDefault(),_.drop=(r,e)=>{let t=e,n=r.dragging;if(r.dragging=null,!t.dataTransfer)return;let i=r.posAtCoords(Ut(t));if(!i)return;let s=r.state.doc.resolve(i.pos),o=n&&n.slice;o?r.someProp("transformPasted",p=>{o=p(o,r)}):o=ds(r,ws(t.dataTransfer),Ct?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(n&&Es(r,t));if(r.someProp("handleDrop",p=>p(r,t,o||k.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?ml(r.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=r.state.tr;if(l){let{node:p}=n;p?p.replace(c):c.deleteSelection()}let u=c.mapping.map(a),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=c.doc;if(d?c.replaceRangeWith(u,u,o.content.firstChild):c.replaceRange(u,u,o),c.doc.eq(f))return;let h=c.doc.resolve(u);if(d&&C.isSelectable(o.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new C(h));else{let p=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,S)=>p=S),c.setSelection(Wn(r,h,c.doc.resolve(p)))}r.focus(),r.dispatch(c.setMeta("uiEvent","drop"))},U.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())&&ge(r)},20))},U.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)},U.beforeinput=(r,e)=>{if(H&&pe&&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,Fe(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 _)U[r]=_[r];function Mt(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 Gt{constructor(e,t){this.toDOM=e,this.spec=t||je,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 re(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Gt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Mt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Te{constructor(e,t){this.attrs=e,this.spec=t||je}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 re(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Te&&Mt(this.attrs,e.attrs)&&Mt(this.spec,e.spec)}static is(e){return e.type instanceof Te}destroy(){}}class Zn{constructor(e,t){this.attrs=e,this.spec=t||je}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 re(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 Zn&&Mt(this.attrs,e.attrs)&&Mt(this.spec,e.spec)}destroy(){}}class re{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new re(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 re(e,e,new Gt(t,n))}static inline(e,t,n,i){return new re(e,t,new Te(n,i))}static node(e,t,n,i){return new re(e,t,new Zn(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Te}get widget(){return this.type instanceof Gt}}const it=[],je={};class z{constructor(e,t){this.local=e.length?e:it,this.children=t.length?t:it}static create(e,t){return t.length?Yt(t,e,0,je):J}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==J||e.maps.length==0?this:this.mapInner(e,t,0,0,n||je)}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?Ha(this.children,o||[],e,t,n,i,s):o?new z(o.sort(We),it):J}add(e,t){return t.length?this==J?z.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,u;if(u=Os(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,u,c+1):i.splice(s,0,a,a+l.nodeSize,Yt(u,l,c+1,je)),s+=3}});let o=Ts(s?Ns(t):t,-n);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new z(o.length?this.local.concat(o).sort(We):this.local,i||this.children)}remove(e){return e.length==0||this==J?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 u=0,d;u<e.length;u++)(d=e[u])&&d.from>l&&d.to<a&&(e[u]=null,(o||(o=[])).push(d));if(!o)continue;n==this.children&&(n=this.children.slice());let c=n[s+2].removeInner(o,l+1);c!=J?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 z(i,n):J}forChild(e,t){if(this==J)return this;if(t.isLeaf)return z.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 Te){let c=Math.max(s,a.from)-s,u=Math.min(o,a.to)-s;c<u&&(i||(i=[])).push(a.copy(c,u))}}if(i){let l=new z(i.sort(We),it);return n?new Oe([l,n]):l}return n||J}eq(e){if(this==e)return!0;if(!(e instanceof z)||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 Qn(this.localsInner(e))}localsInner(e){if(this==J)return it;if(e.inlineContent||!this.local.some(Te.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Te||t.push(this.local[n]);return t}forEachSet(e){e(this)}}z.empty=new z([],[]),z.removeOverlap=Qn;const J=z.empty;class Oe{constructor(e){this.members=e}map(e,t){const n=this.members.map(i=>i.map(e,t,je));return Oe.from(n)}forChild(e,t){if(t.isLeaf)return z.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=J&&(s instanceof Oe?n=n.concat(s.members):n.push(s))}return Oe.from(n)}eq(e){if(!(e instanceof Oe)||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?Qn(n?t:t.sort(We)):it}static from(e){switch(e.length){case 0:return J;case 1:return e[0];default:return new Oe(e.every(t=>t instanceof z)?e:e.reduce((t,n)=>t.concat(n instanceof z?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Ha(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,u=s;c<t.maps.length;c++){let d=0;t.maps[c].forEach((f,h,p,m)=>{let g=m-p-(h-f);for(let y=0;y<l.length;y+=3){let S=l[y+1];if(S<0||f>S+u-d)continue;let w=l[y]+u-d;h>=w?l[y+1]=f<=w?-2:-1:f>=u&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let u=t.map(r[c]+s),d=u-i;if(d<0||d>=n.content.size){a=!0;continue}let f=t.map(r[c+1]+s,-1),h=f-i,{index:p,offset:m}=n.content.findIndex(d),g=n.maybeChild(p);if(g&&m==d&&m+g.nodeSize==h){let y=l[c+2].mapInner(t,g,u+1,r[c]+s+1,o);y!=J?(l[c]=d,l[c+1]=h,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Ja(l,r,e,t,i,s,o),u=Yt(c,n,0,o);e=u.local;for(let d=0;d<l.length;d+=3)l[d+1]<0&&(l.splice(d,3),d-=3);for(let d=0,f=0;d<u.children.length;d+=3){let h=u.children[d];for(;f<l.length&&l[f]<h;)f+=3;l.splice(f,0,u.children[d],u.children[d+1],u.children[d+2])}}return new z(e.sort(We),l)}function Ts(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 re(i.from+e,i.to+e,i.type))}return t}function Ja(r,e,t,n,i,s,o){function l(a,c){for(let u=0;u<a.local.length;u++){let d=a.local[u].map(n,i,c);d?t.push(d):o.onRemove&&o.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+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 Os(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 Ns(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function Yt(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=Os(r,l,a+t);if(c){s=!0;let u=Yt(c,l,t+a+1,n);u!=J&&i.push(a,a+l.nodeSize,u)}});let o=Ts(s?Ns(r):r,-t).sort(We);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 z(o,i):J}function We(r,e){return r.from-e.from||r.to-e.to}function Qn(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),As(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),As(e,i,n.copy(s.from,n.to)));break}}}return e}function As(r,e,t){for(;e<r.length&&We(t,r[e])>0;)e++;r.splice(e,0,t)}function er(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=J&&e.push(n)}),r.cursorWrapper&&e.push(z.create(r.state.doc,[r.cursorWrapper.deco])),Oe.from(e)}const qa={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Ka=G&&Se<=11;class Ua{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 _a{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Ua,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]);G&&Se<=11&&n.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Ka&&(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,qa)),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(ns(this.view)){if(this.suppressingSelectionUpdates)return ge(this.view);if(G&&Se<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&ze(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)&&ns(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let d=this.registerMutation(t[u],a);d&&(s=s<0?d.from:Math.min(d.from,s),o=o<0?d.to:Math.max(d.to,o),d.typeOver&&(l=!0))}if(oe&&a.length){let u=a.filter(d=>d.nodeName=="BR");if(u.length==2){let[d,f]=u;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of u){let h=f.parentNode;h&&h.nodeName=="LI"&&(!d||Xa(e,d)!=h)&&f.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ht(n)&&(c=Vn(e))&&c.eq(O.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ge(e),this.currentSelection.set(n),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Ga(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ge(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 u=0;u<e.addedNodes.length;u++){let d=e.addedNodes[u];t.push(d),d.nodeType==3&&(this.lastChangedTextNode=d)}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(G&&Se<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:d,nextSibling:f}=e.addedNodes[u];(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(i=d),(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(s=f)}let o=i&&i.parentNode==e.target?V(i)+1:0,l=n.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?V(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 vs=new WeakMap,Ds=!1;function Ga(r){if(!vs.has(r)&&(vs.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=oe,Ds)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."),Ds=!0}}function Is(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return ze(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:i,focusOffset:s}}function Ya(r,e){if(e.getComposedRanges){let i=e.getComposedRanges(r.root)[0];if(i)return Is(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?Is(r,t):null}function Xa(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 Za(r,e,t){let{node:n,fromOffset:i,toOffset:s,from:o,to:l}=r.docView.parseRange(e,t),a=r.domSelectionRange(),c,u=a.anchorNode;if(u&&r.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:a.anchorOffset}],Ht(a)||c.push({node:a.focusNode,offset:a.focusOffset})),H&&r.input.lastKeyCode===8)for(let g=s;g>i;g--){let y=n.childNodes[g-1],S=y.pmViewDesc;if(y.nodeName=="BR"&&!S){s=g;break}if(!S||S.size)break}let d=r.state.doc,f=r.someProp("domParser")||ct.fromSchema(r.state.schema),h=d.resolve(o),p=null,m=f.parse(n,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Qa,context:h});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Qa(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(K&&/^(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||K&&/^(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 ec=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function tc(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let T=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,ie=Vn(r,T);if(ie&&!r.state.selection.eq(ie)){if(H&&pe&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&r.someProp("handleKeyDown",Gd=>Gd(r,Fe(13,"Enter"))))return;let gn=r.state.tr.setSelection(ie);T=="pointer"?gn.setMeta("pointer",!0):T=="key"&&gn.scrollIntoView(),s&&gn.setMeta("composition",s),r.dispatch(gn)}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=Za(r,e,t),u=r.state.doc,d=u.slice(c.from,c.to),f,h;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(f=r.state.selection.to,h="end"):(f=r.state.selection.from,h="start"),r.input.lastKeyCode=null;let p=ic(d.content,c.doc.content,c.from,f,h);if(p&&r.input.domChangeCount++,(et&&r.input.lastIOSEnter>Date.now()-225||pe)&&i.some(T=>T.nodeType==1&&!ec.test(T.nodeName))&&(!p||p.endA>=p.endB)&&r.someProp("handleKeyDown",T=>T(r,Fe(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof E&&!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 T=Ps(r,r.state.doc,c.sel);if(T&&!T.eq(r.state.selection)){let ie=r.state.tr.setSelection(T);s&&ie.setMeta("composition",s),r.dispatch(ie)}}return}r.state.selection.from<r.state.selection.to&&p.start==p.endB&&r.state.selection instanceof E&&(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)),G&&Se<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)==" "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),y=u.resolve(p.start),S=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,w;if((et&&r.input.lastIOSEnter>Date.now()-225&&(!S||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!S&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&(w=O.findFrom(c.doc.resolve(m.pos+1),1,!0))&&w.head>m.pos)&&r.someProp("handleKeyDown",T=>T(r,Fe(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>p.start&&rc(u,p.start,p.endA,m,g)&&r.someProp("handleKeyDown",T=>T(r,Fe(8,"Backspace")))){pe&&H&&r.domObserver.suppressSelectionUpdates();return}H&&p.endB==p.start&&(r.input.lastChromeDelete=Date.now()),pe&&!S&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(T){return T(r,Fe(13,"Enter"))})},20));let v=p.start,A=p.endA,M,I,q;if(S){if(m.pos==g.pos)G&&Se<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>ge(r),20)),M=r.state.tr.delete(v,A),I=u.resolve(p.start).marksAcross(u.resolve(p.endA));else if(p.endA==p.endB&&(q=nc(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))M=r.state.tr,q.type=="add"?M.addMark(v,A,q.mark):M.removeMark(v,A,q.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(r.someProp("handleTextInput",ie=>ie(r,v,A,T)))return;M=r.state.tr.insertText(T,v,A)}}if(M||(M=r.state.tr.replace(v,A,c.doc.slice(p.start-c.from,p.endB-c.from))),c.sel){let T=Ps(r,M.doc,c.sel);T&&!(H&&r.composing&&T.empty&&(p.start!=p.endB||r.input.lastChromeDelete<Date.now()-100)&&(T.head==v||T.head==M.mapping.map(A)-1)||G&&T.empty&&T.head==v)&&M.setSelection(T)}I&&M.ensureMarks(I),s&&M.setMeta("composition",s),r.dispatch(M.scrollIntoView())}function Ps(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Wn(r,e.resolve(t.anchor),e.resolve(t.head))}function nc(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let u=0;u<n.length;u++)i=n[u].removeFromSet(i);for(let u=0;u<t.length;u++)s=t[u].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=u=>u.mark(l.addToSet(u.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(a(e.child(u)));if(b.from(c).eq(r))return{mark:l,type:o}}function rc(r,e,t,n,i){if(t-e<=i.pos-n.pos||tr(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(tr(s,!0,!0));return!o.parent.isTextblock||o.pos>t||tr(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function tr(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 ic(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&&Rs(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&&Rs(r.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function Rs(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 sc{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 wa,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach($s),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=Fs(this),zs(this),this.nodeViews=Ls(this),this.docView=Ji(this.state.doc,Bs(this),er(this),this.dom,this),this.domObserver=new _a(this,(n,i,s,o)=>tc(this,n,i,s,o)),this.domObserver.start(),Ma(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&&_n(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach($s),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&&(Cs(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 h=Ls(this);lc(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&_n(this),this.editable=Fs(this),zs(this);let a=er(this),c=Bs(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,c,a);(d||!e.selection.eq(i.selection))&&(o=!0);let f=u=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Ll(this);if(o){this.domObserver.stop();let h=d&&(G||H)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&oc(i.selection,e.selection);if(d){let p=H?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Fa(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Ji(e.doc,c,a,this.dom,this)),p&&!this.trackWrites&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&aa(this))?ge(this,h):(es(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),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():f&&$l(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Di(this,t.getBoundingClientRect(),e)}else Di(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 Ms(e.slice,e.move,i<0?void 0:C.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(G){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&&Vl(this.dom),ge(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 ql(this,e)}coordsAtPos(e,t=1){return Fi(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 Yl(this,t||this.state,e)}pasteHTML(e,t){return wt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return wt(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return qn(this,e)}destroy(){this.docView&&(Ea(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],er(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ol())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Oa(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?K&&this.root.nodeType===11&&Il(this.dom.ownerDocument)==this.dom&&Ya(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Bs(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"),[re.node(0,r.state.doc.content.size,e)]}function zs(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:re.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function Fs(r){return!r.someProp("editable",e=>e(r.state)===!1)}function oc(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 Ls(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 lc(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 $s(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")}for(var Ne={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Xt={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ac=typeof navigator<"u"&&/Mac/.test(navigator.platform),cc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),j=0;j<10;j++)Ne[48+j]=Ne[96+j]=String(j);for(var j=1;j<=24;j++)Ne[j+111]="F"+j;for(var j=65;j<=90;j++)Ne[j]=String.fromCharCode(j+32),Xt[j]=String.fromCharCode(j);for(var nr in Ne)Xt.hasOwnProperty(nr)||(Xt[nr]=Ne[nr]);function uc(r){var e=ac&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||cc&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?Xt:Ne)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const dc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function fc(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))dc?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 hc(r){let e=Object.create(null);for(let t in r)e[fc(t)]=r[t];return e}function rr(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 pc(r){return new Q({props:{handleKeyDown:mc(r)}})}function mc(r){let e=hc(r);return function(t,n){let i=uc(n),s,o=e[rr(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[rr(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.shiftKey||n.altKey||n.metaKey||i.charCodeAt(0)>127)&&(s=Ne[n.keyCode])&&s!=i){let l=e[rr(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const ir=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Vs(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const js=(r,e,t)=>{let n=Vs(r,t);if(!n)return!1;let i=sr(n);if(!i){let o=n.blockRange(),l=o&&_e(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Ys(r,i,e,-1))return!0;if(n.parent.content.size==0&&(st(s,"end")||C.isSelectable(s)))for(let o=n.depth;;o--){let l=jt(r.doc,n.before(o),n.after(o),k.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(st(s,"end")?O.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):C.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},gc=(r,e,t)=>{let n=Vs(r,t);if(!n)return!1;let i=sr(n);return i?Ws(r,i,e):!1},yc=(r,e,t)=>{let n=Js(r,t);if(!n)return!1;let i=or(n);return i?Ws(r,i,e):!1};function Ws(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 u=i.lastChild;if(!u)return!1;i=u}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let c=jt(r.doc,s,a,k.empty);if(!c||c.from!=s||c instanceof B&&c.slice.size>=a-s)return!1;if(t){let u=r.tr.step(c);u.setSelection(E.create(u.doc,s)),t(u.scrollIntoView())}return!0}function st(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 Hs=(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=sr(n)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(r.tr.setSelection(C.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function sr(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 Js(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}const qs=(r,e,t)=>{let n=Js(r,t);if(!n)return!1;let i=or(n);if(!i)return!1;let s=i.nodeAfter;if(Ys(r,i,e,1))return!0;if(n.parent.content.size==0&&(st(s,"start")||C.isSelectable(s))){let o=jt(r.doc,n.before(),n.after(),k.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(st(s,"start")?O.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):C.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},Ks=(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=or(n)}let o=s&&s.nodeAfter;return!o||!C.isSelectable(o)?!1:(e&&e(r.tr.setSelection(C.create(r.doc,s.pos)).scrollIntoView()),!0)};function or(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 bc=(r,e)=>{let t=r.selection,n=t instanceof C,i;if(n){if(t.node.isTextblock||!Be(r.doc,t.from))return!1;i=t.from}else if(i=Vt(r.doc,t.from,-1),i==null)return!1;if(e){let s=r.tr.join(i);n&&s.setSelection(C.create(s.doc,i-r.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},kc=(r,e)=>{let t=r.selection,n;if(t instanceof C){if(t.node.isTextblock||!Be(r.doc,t.to))return!1;n=t.to}else if(n=Vt(r.doc,t.to,1),n==null)return!1;return e&&e(r.tr.join(n).scrollIntoView()),!0},xc=(r,e)=>{let{$from:t,$to:n}=r.selection,i=t.blockRange(n),s=i&&_e(i);return s==null?!1:(e&&e(r.tr.lift(i,s).scrollIntoView()),!0)},Us=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
|
|
10
|
+
`).scrollIntoView()),!0)};function lr(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 Sc=(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=lr(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(O.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},_s=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof Z||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=lr(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(E.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Gs=(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(fe(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&_e(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function Cc(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!n.parentOffset||!fe(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 h=n.depth;;h--)if(n.node(h).isBlock){a=n.end(h)==n.pos+(n.depth-h),c=n.start(h)==n.pos-(n.depth-h),l=lr(n.node(h-1).contentMatchAt(n.indexAfter(h-1))),s.unshift(a&&l?{type:l}:null),o=h;break}else{if(h==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof E||e.selection instanceof Z)&&u.deleteSelection();let d=u.mapping.map(n.pos),f=fe(u.doc,d,s.length,s);if(f||(s[0]=l?{type:l}:null,f=fe(u.doc,d,s.length,s)),!f)return!1;if(u.split(d,s.length,s),!a&&c&&n.node(o).type!=l){let h=u.mapping.map(n.before(o)),p=u.doc.resolve(h);l&&n.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&u.setNodeMarkup(u.mapping.map(n.before(o)),l)}return t&&t(u.scrollIntoView()),!0}}const wc=Cc(),Mc=(r,e)=>{let{$from:t,to:n}=r.selection,i,s=t.sharedDepth(n);return s==0?!1:(i=t.before(s),e&&e(r.tr.setSelection(C.create(r.doc,i))),!0)};function Ec(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||Be(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Ys(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Ec(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 h=e.pos+s.nodeSize,p=b.empty;for(let y=o.length-1;y>=0;y--)p=b.from(o[y].create(null,p));p=b.from(i.copy(p));let m=r.tr.step(new F(e.pos-1,h,e.pos,h,new k(p,1,0),o.length,!0)),g=m.doc.resolve(h+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Be(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let u=s.type.spec.isolating||n>0&&a?null:O.findFrom(e,1),d=u&&u.$from.blockRange(u.$to),f=d&&_e(d);if(f!=null&&f>=e.depth)return t&&t(r.tr.lift(d,f).scrollIntoView()),!0;if(c&&st(s,"start",!0)&&st(i,"end")){let h=i,p=[];for(;p.push(h),!h.isTextblock;)h=h.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(h.canReplace(h.childCount,h.childCount,m.content)){if(t){let y=b.empty;for(let w=p.length-1;w>=0;w--)y=b.from(p[w].copy(y));let S=r.tr.step(new F(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new k(y,p.length,0),0,!0));t(S.scrollIntoView())}return!0}}return!1}function Xs(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(E.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const Tc=Xs(-1),Oc=Xs(1);function Nc(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&ci(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Zs(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 u=t.doc.resolve(c),d=u.index();i=u.parent.canReplaceWith(d,d+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 ar(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}ar(ir,js,Hs),ar(ir,qs,Ks),ar(Us,_s,Gs,wc),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Ac(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s);if(!o)return!1;let l=n?t.tr:null;return vc(l,o,r,e)?(n&&n(l.scrollIntoView()),!0):!1}}function vc(r,e,t,n=null){let i=!1,s=e,o=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new Pt(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new Pt(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),i=!0}let l=ci(s,t,n,e);return l?(r&&Dc(r,e,l,i,t),!0):!1}function Dc(r,e,t,n,i){let s=b.empty;for(let u=t.length-1;u>=0;u--)s=b.from(t[u].type.create(t[u].attrs,s));r.step(new F(e.start-(n?2:0),e.end,e.start,e.end,new k(s,0,0),t.length,!0));let o=0;for(let u=0;u<t.length;u++)t[u].type==i&&(o=u+1);let l=t.length-o,a=e.start+t.length-(n?2:0),c=e.parent;for(let u=e.startIndex,d=e.endIndex,f=!0;u<d;u++,f=!1)!f&&fe(r.doc,a,l)&&(r.split(a,l),a+=2*l),a+=c.child(u).nodeSize;return r}function Ic(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):Rc(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 F(s-1,o,s,o,new k(b.from(t.create(null,n.parent.copy())),1,0),1,!0)),n=new Pt(i.doc.resolve(n.$from.pos),i.doc.resolve(o),n.depth));const l=_e(n);if(l==null)return!1;i.lift(n,l);let a=i.doc.resolve(i.mapping.map(s,-1)-1);return Be(i.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&i.join(a.pos),e(i.scrollIntoView()),!0}function Rc(r,e,t){let n=r.tr,i=t.parent;for(let h=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)h-=i.child(p).nodeSize,n.delete(h-1,h+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),u=s.index(-1);if(!c.canReplace(u+(l?0:1),u+1,o.content.append(a?b.empty:b.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return n.step(new F(d-(l?1:0),f+(a?1:0),d+1,f-1,new k((l?b.empty:b.from(i.copy(b.empty))).append(a?b.empty:b.from(i.copy(b.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function Bc(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,u=b.from(c?r.create():null),d=new k(b.from(r.create(null,b.from(l.type.create(null,u)))),c?3:1,0),f=s.start,h=s.end;t(e.tr.step(new F(f-(c?3:1),h,f,h,d,1,!0)).scrollIntoView())}return!0}}function Zt(r){const{state:e,transaction:t}=r;let{selection:n}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return n},get doc(){return i},get tr(){return n=t.selection,i=t.doc,s=t.storedMarks,t}}}class Qt{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:i}=t,{tr:s}=n,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...u)=>{const d=a(...u)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,u=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(n).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,t),y=h(...m)(g);return l.push(y),d}])),run:u};return d}createCan(e){const{rawCommands:t,state:n}=this,i=!1,s=e||n.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...u)=>c(...u)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:Zt({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([a,c])=>[a,(...u)=>c(...u)(l)]))}};return l}}class zc{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach(i=>i.apply(this,t)),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(i=>i!==t):delete this.callbacks[e]),this}once(e,t){const n=(...i)=>{this.off(e,n),t.apply(this,i)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}}function x(r,e,t){return r.config[e]===void 0&&r.parent?x(r.parent,e,t):typeof r.config[e]=="function"?r.config[e].bind({...t,parent:r.parent?x(r.parent,e,t):null}):r.config[e]}function en(r){const e=r.filter(i=>i.type==="extension"),t=r.filter(i=>i.type==="node"),n=r.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:n}}function Qs(r){const e=[],{nodeExtensions:t,markExtensions:n}=en(r),i=[...t,...n],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return r.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage,extensions:i},a=x(o,"addGlobalAttributes",l);if(!a)return;a().forEach(u=>{u.types.forEach(d=>{Object.entries(u.attributes).forEach(([f,h])=>{e.push({type:d,name:f,attribute:{...s,...h}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=x(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([u,d])=>{const f={...s,...d};typeof(f==null?void 0:f.default)=="function"&&(f.default=f.default()),f!=null&&f.isRequired&&(f==null?void 0:f.default)===void 0&&delete f.default,e.push({type:o.name,name:u,attribute:f})})}),e}function L(r,e){if(typeof r=="string"){if(!e.nodes[r])throw Error(`There is no node type named '${r}'. Maybe you forgot to add the extension?`);return e.nodes[r]}return r}function Fc(...r){return r.filter(e=>!!e).reduce((e,t)=>{const n={...e};return Object.entries(t).forEach(([i,s])=>{if(!n[i]){n[i]=s;return}if(i==="class"){const l=s?String(s).split(" "):[],a=n[i]?n[i].split(" "):[],c=l.filter(u=>!a.includes(u));n[i]=[...a,...c].join(" ")}else if(i==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],a=n[i]?n[i].split(";").map(u=>u.trim()).filter(Boolean):[],c=new Map;a.forEach(u=>{const[d,f]=u.split(":").map(h=>h.trim());c.set(d,f)}),l.forEach(u=>{const[d,f]=u.split(":").map(h=>h.trim());c.set(d,f)}),n[i]=Array.from(c.entries()).map(([u,d])=>`${u}: ${d}`).join("; ")}else n[i]=s}),n},{})}function cr(r,e){return e.filter(t=>t.type===r.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(r.attrs)||{}:{[t.name]:r.attrs[t.name]}).reduce((t,n)=>Fc(t,n),{})}function eo(r){return typeof r=="function"}function N(r,e=void 0,...t){return eo(r)?e?r.bind(e)(...t):r(...t):r}function Lc(r={}){return Object.keys(r).length===0&&r.constructor===Object}function $c(r){return typeof r!="string"?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):r==="true"?!0:r==="false"?!1:r}function to(r,e){return"style"in r?r:{...r,getAttrs:t=>{const n=r.getAttrs?r.getAttrs(t):r.attrs;if(n===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):$c(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...n,...i}}}}function no(r){return Object.fromEntries(Object.entries(r).filter(([e,t])=>e==="attrs"&&Lc(t)?!1:t!=null))}function Vc(r,e){var t;const n=Qs(r),{nodeExtensions:i,markExtensions:s}=en(r),o=(t=i.find(c=>x(c,"topNode")))===null||t===void 0?void 0:t.name,l=Object.fromEntries(i.map(c=>{const u=n.filter(y=>y.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=r.reduce((y,S)=>{const w=x(S,"extendNodeSchema",d);return{...y,...w?w(c):{}}},{}),h=no({...f,content:N(x(c,"content",d)),marks:N(x(c,"marks",d)),group:N(x(c,"group",d)),inline:N(x(c,"inline",d)),atom:N(x(c,"atom",d)),selectable:N(x(c,"selectable",d)),draggable:N(x(c,"draggable",d)),code:N(x(c,"code",d)),whitespace:N(x(c,"whitespace",d)),linebreakReplacement:N(x(c,"linebreakReplacement",d)),defining:N(x(c,"defining",d)),isolating:N(x(c,"isolating",d)),attrs:Object.fromEntries(u.map(y=>{var S;return[y.name,{default:(S=y==null?void 0:y.attribute)===null||S===void 0?void 0:S.default}]}))}),p=N(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(y=>to(y,u)));const m=x(c,"renderHTML",d);m&&(h.toDOM=y=>m({node:y,HTMLAttributes:cr(y,u)}));const g=x(c,"renderText",d);return g&&(h.toText=g),[c.name,h]})),a=Object.fromEntries(s.map(c=>{const u=n.filter(g=>g.type===c.name),d={name:c.name,options:c.options,storage:c.storage,editor:e},f=r.reduce((g,y)=>{const S=x(y,"extendMarkSchema",d);return{...g,...S?S(c):{}}},{}),h=no({...f,inclusive:N(x(c,"inclusive",d)),excludes:N(x(c,"excludes",d)),group:N(x(c,"group",d)),spanning:N(x(c,"spanning",d)),code:N(x(c,"code",d)),attrs:Object.fromEntries(u.map(g=>{var y;return[g.name,{default:(y=g==null?void 0:g.attribute)===null||y===void 0?void 0:y.default}]}))}),p=N(x(c,"parseHTML",d));p&&(h.parseDOM=p.map(g=>to(g,u)));const m=x(c,"renderHTML",d);return m&&(h.toDOM=g=>m({mark:g,HTMLAttributes:cr(g,u)})),[c.name,h]}));return new Ur({topNode:o,nodes:l,marks:a})}function ur(r,e){return e.nodes[r]||e.marks[r]||null}function ro(r,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===r.name):e}function dr(r,e){const t=Re.fromSchema(e).serializeFragment(r),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}const jc=(r,e=500)=>{let t="";const n=r.parentOffset;return r.parent.nodesBetween(Math.max(0,n-e),n,(i,s,o,l)=>{var a,c;const u=((c=(a=i.type.spec).toText)===null||c===void 0?void 0:c.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";t+=i.isAtom&&!i.isText?u:u.slice(0,Math.max(0,n-s))}),t};function fr(r){return Object.prototype.toString.call(r)==="[object RegExp]"}const Wc=(r,e)=>{if(fr(e))return e.exec(r);const t=e(r);if(!t)return null;const n=[t.text];return n.index=t.index,n.input=r,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),n.push(t.replaceWith)),n};function tn(r){var e;const{editor:t,from:n,to:i,text:s,rules:o,plugin:l}=r,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(n);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(f=>f.type.spec.code))return!1;let u=!1;const d=jc(c)+s;return o.forEach(f=>{if(u)return;const h=Wc(d,f.find);if(!h)return;const p=a.state.tr,m=Zt({state:a.state,transaction:p}),g={from:n-(h[0].length-s.length),to:i},{commands:y,chain:S,can:w}=new Qt({editor:t,state:m});f.handler({state:m,range:g,match:h,commands:y,chain:S,can:w})===null||!p.steps.length||(p.setMeta(l,{transform:p,from:n,to:i,text:s}),a.dispatch(p),u=!0)}),u}function Hc(r){const{editor:e,rules:t}=r,n=new Q({state:{init(){return null},apply(i,s,o){const l=i.getMeta(n);if(l)return l;const a=i.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:u}=a;typeof u=="string"?u=u:u=dr(b.from(u),o.schema);const{from:d}=a,f=d+u.length;tn({editor:e,from:d,to:f,text:u,rules:t,plugin:n})}),i.selectionSet||i.docChanged?null:s}},props:{handleTextInput(i,s,o,l){return tn({editor:e,from:s,to:o,text:l,rules:t,plugin:n})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&tn({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:n})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?tn({editor:e,from:o.pos,to:o.pos,text:`
|
|
11
|
+
`,rules:t,plugin:n}):!1}},isInputRules:!0});return n}function Jc(r){return Object.prototype.toString.call(r).slice(8,-1)}function nn(r){return Jc(r)!=="Object"?!1:r.constructor===Object&&Object.getPrototypeOf(r)===Object.prototype}function rn(r,e){const t={...r};return nn(r)&&nn(e)&&Object.keys(e).forEach(n=>{nn(e[n])&&nn(r[n])?t[n]=rn(r[n],e[n]):t[n]=e[n]}),t}class Et{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=N(x(this,"addOptions",{name:this.name}))),this.storage=N(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Et(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>rn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Et(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=N(x(t,"addOptions",{name:t.name})),t.storage=N(x(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:n}=e.state,i=e.state.selection.$from;if(i.pos===i.end()){const o=i.marks();if(!!!o.find(c=>(c==null?void 0:c.type.name)===t.name))return!1;const a=o.find(c=>(c==null?void 0:c.type.name)===t.name);return a&&n.removeStoredMark(a),n.insertText(" ",i.pos),e.view.dispatch(n),!0}return!1}}function qc(r){return typeof r=="number"}const Kc=(r,e,t)=>{if(fr(e))return[...r.matchAll(e)];const n=e(r,t);return n?n.map(i=>{const s=[i.text];return s.index=i.index,s.input=r,s.data=i.data,i.replaceWith&&(i.text.includes(i.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(i.replaceWith)),s}):[]};function Uc(r){const{editor:e,state:t,from:n,to:i,rule:s,pasteEvent:o,dropEvent:l}=r,{commands:a,chain:c,can:u}=new Qt({editor:e,state:t}),d=[];return t.doc.nodesBetween(n,i,(h,p)=>{if(!h.isTextblock||h.type.spec.code)return;const m=Math.max(n,p),g=Math.min(i,p+h.content.size),y=h.textBetween(m-p,g-p,void 0,"");Kc(y,s.find,o).forEach(w=>{if(w.index===void 0)return;const v=m+w.index+1,A=v+w[0].length,M={from:t.tr.mapping.map(v),to:t.tr.mapping.map(A)},I=s.handler({state:t,range:M,match:w,commands:a,chain:c,can:u,pasteEvent:o,dropEvent:l});d.push(I)})}),d.every(h=>h!==null)}let sn=null;const _c=r=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)===null||e===void 0||e.setData("text/html",r),t};function Gc(r){const{editor:e,rules:t}=r;let n=null,i=!1,s=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const a=({state:u,from:d,to:f,rule:h,pasteEvt:p})=>{const m=u.tr,g=Zt({state:u,transaction:m});if(!(!Uc({editor:e,state:g,from:Math.max(d-1,0),to:f.b-1,rule:h,pasteEvent:p,dropEvent:l})||!m.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,m}};return t.map(u=>new Q({view(d){const f=p=>{var m;n=!((m=d.dom.parentElement)===null||m===void 0)&&m.contains(p.target)?d.dom.parentElement:null,n&&(sn=e)},h=()=>{sn&&(sn=null)};return window.addEventListener("dragstart",f),window.addEventListener("dragend",h),{destroy(){window.removeEventListener("dragstart",f),window.removeEventListener("dragend",h)}}},props:{handleDOMEvents:{drop:(d,f)=>{if(s=n===d.dom.parentElement,l=f,!s){const h=sn;h&&setTimeout(()=>{const p=h.state.selection;p&&h.commands.deleteRange({from:p.from,to:p.to})},10)}return!1},paste:(d,f)=>{var h;const p=(h=f.clipboardData)===null||h===void 0?void 0:h.getData("text/html");return o=f,i=!!(p!=null&&p.includes("data-pm-slice")),!1}}},appendTransaction:(d,f,h)=>{const p=d[0],m=p.getMeta("uiEvent")==="paste"&&!i,g=p.getMeta("uiEvent")==="drop"&&!s,y=p.getMeta("applyPasteRules"),S=!!y;if(!m&&!g&&!S)return;if(S){let{text:A}=y;typeof A=="string"?A=A:A=dr(b.from(A),h.schema);const{from:M}=y,I=M+A.length,q=_c(A);return a({rule:u,state:h,from:M,to:{b:I},pasteEvt:q})}const w=f.doc.content.findDiffStart(h.doc.content),v=f.doc.content.findDiffEnd(h.doc.content);if(!(!qc(w)||!v||w===v.b))return a({rule:u,state:h,from:w,to:v,pasteEvt:o})}}))}function Yc(r){const e=r.filter((t,n)=>r.indexOf(t)!==n);return Array.from(new Set(e))}class ot{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=ot.resolve(e),this.schema=Vc(this.extensions,t),this.setupExtensions()}static resolve(e){const t=ot.sort(ot.flatten(e)),n=Yc(t.map(i=>i.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{const n={name:t.name,options:t.options,storage:t.storage},i=x(t,"addExtensions",n);return i?[t,...this.flatten(i())]:t}).flat(10)}static sort(e){return e.sort((n,i)=>{const s=x(n,"priority")||100,o=x(i,"priority")||100;return s>o?-1:s<o?1:0})}get commands(){return this.extensions.reduce((e,t)=>{const n={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:ur(t.name,this.schema)},i=x(t,"addCommands",n);return i?{...e,...i()}:e},{})}get plugins(){const{editor:e}=this,t=ot.sort([...this.extensions].reverse()),n=[],i=[],s=t.map(o=>{const l={name:o.name,options:o.options,storage:o.storage,editor:e,type:ur(o.name,this.schema)},a=[],c=x(o,"addKeyboardShortcuts",l);let u={};if(o.type==="mark"&&x(o,"exitable",l)&&(u.ArrowRight=()=>Et.handleExit({editor:e,mark:o})),c){const m=Object.fromEntries(Object.entries(c()).map(([g,y])=>[g,()=>y({editor:e})]));u={...u,...m}}const d=pc(u);a.push(d);const f=x(o,"addInputRules",l);ro(o,e.options.enableInputRules)&&f&&n.push(...f());const h=x(o,"addPasteRules",l);ro(o,e.options.enablePasteRules)&&h&&i.push(...h());const p=x(o,"addProseMirrorPlugins",l);if(p){const m=p();a.push(...m)}return a}).flat();return[Hc({editor:e,rules:n}),...Gc({editor:e,rules:i}),...s]}get attributes(){return Qs(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=en(this.extensions);return Object.fromEntries(t.filter(n=>!!x(n,"addNodeView")).map(n=>{const i=this.attributes.filter(a=>a.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:e,type:L(n.name,this.schema)},o=x(n,"addNodeView",s);if(!o)return[];const l=(a,c,u,d,f)=>{const h=cr(a,i);return o()({node:a,view:c,getPos:u,decorations:d,innerDecorations:f,editor:e,extension:n,HTMLAttributes:h})};return[n.name,l]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const n={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:ur(e.name,this.schema)};e.type==="mark"&&(!((t=N(x(e,"keepOnSplit",n)))!==null&&t!==void 0)||t)&&this.splittableMarks.push(e.name);const i=x(e,"onBeforeCreate",n),s=x(e,"onCreate",n),o=x(e,"onUpdate",n),l=x(e,"onSelectionUpdate",n),a=x(e,"onTransaction",n),c=x(e,"onFocus",n),u=x(e,"onBlur",n),d=x(e,"onDestroy",n);i&&this.editor.on("beforeCreate",i),s&&this.editor.on("create",s),o&&this.editor.on("update",o),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),c&&this.editor.on("focus",c),u&&this.editor.on("blur",u),d&&this.editor.on("destroy",d)})}}class Y{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=N(x(this,"addOptions",{name:this.name}))),this.storage=N(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Y(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>rn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Y({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=N(x(t,"addOptions",{name:t.name})),t.storage=N(x(t,"addStorage",{name:t.name,options:t.options})),t}}function io(r,e,t){const{from:n,to:i}=e,{blockSeparator:s=`
|
|
12
12
|
|
|
13
|
-
`,textSerializers:o={}}=t||{};let l="";return r.nodesBetween(n,i,(a,c,u,d)=>{var f;a.isBlock&&c>n&&(l+=s);const h=o==null?void 0:o[a.type.name];if(h)return u&&(l+=h({node:a,pos:c,parent:u,index:d,range:e})),!1;a.isText&&(l+=(f=a==null?void 0:a.text)===null||f===void 0?void 0:f.slice(Math.max(n,c)-c,i-c))}),l}function so(r){return Object.fromEntries(Object.entries(r.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Zc=Y.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Q({key:new se("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:r}=this,{state:e,schema:t}=r,{doc:n,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),a=so(t);return io(n,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),Qc=()=>({editor:r,view:e})=>(requestAnimationFrame(()=>{var t;r.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),eu=(r=!1)=>({commands:e})=>e.setContent("",r),tu=()=>({state:r,tr:e,dispatch:t})=>{const{selection:n}=e,{ranges:i}=n;return t&&i.forEach(({$from:s,$to:o})=>{r.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:u}=e,d=c.resolve(u.map(a)),f=c.resolve(u.map(a+l.nodeSize)),h=d.blockRange(f);if(!h)return;const p=_e(h);if(l.type.isTextblock){const{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(h.start,m)}(p||p===0)&&e.lift(h,p)})}),!0},nu=r=>e=>r(e),ru=()=>({state:r,dispatch:e})=>_s(r,e),iu=(r,e)=>({editor:t,tr:n})=>{const{state:i}=t,s=i.doc.slice(r.from,r.to);n.deleteRange(r.from,r.to);const o=n.mapping.map(e);return n.insert(o,s.content),n.setSelection(new E(n.doc.resolve(o-1))),!0},su=()=>({tr:r,dispatch:e})=>{const{selection:t}=r,n=t.$anchor.node();if(n.content.size>0)return!1;const i=r.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===n.type){if(e){const l=i.before(s),a=i.after(s);r.delete(l,a).scrollIntoView()}return!0}return!1},ou=r=>({tr:e,state:t,dispatch:n})=>{const i=L(r,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(n){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},lu=r=>({tr:e,dispatch:t})=>{const{from:n,to:i}=r;return t&&e.delete(n,i),!0},au=()=>({state:r,dispatch:e})=>ir(r,e),cu=()=>({commands:r})=>r.keyboardShortcut("Enter"),uu=()=>({state:r,dispatch:e})=>Cc(r,e);function on(r,e,t={strict:!0}){const n=Object.keys(e);return n.length?n.every(i=>t.strict?e[i]===r[i]:fr(e[i])?e[i].test(r[i]):e[i]===r[i]):!0}function oo(r,e,t={}){return r.find(n=>n.type===e&&on(Object.fromEntries(Object.keys(t).map(i=>[i,n.attrs[i]])),t))}function lo(r,e,t={}){return!!oo(r,e,t)}function hr(r,e,t){var n;if(!r||!e)return;let i=r.parent.childAfter(r.parentOffset);if((!i.node||!i.node.marks.some(u=>u.type===e))&&(i=r.parent.childBefore(r.parentOffset)),!i.node||!i.node.marks.some(u=>u.type===e)||(t=t||((n=i.node.marks[0])===null||n===void 0?void 0:n.attrs),!oo([...i.node.marks],e,t)))return;let o=i.index,l=r.start()+i.offset,a=o+1,c=l+i.node.nodeSize;for(;o>0&&lo([...r.parent.child(o-1).marks],e,t);)o-=1,l-=r.parent.child(o).nodeSize;for(;a<r.parent.childCount&&lo([...r.parent.child(a).marks],e,t);)c+=r.parent.child(a).nodeSize,a+=1;return{from:l,to:c}}function Ae(r,e){if(typeof r=="string"){if(!e.marks[r])throw Error(`There is no mark type named '${r}'. Maybe you forgot to add the extension?`);return e.marks[r]}return r}const du=(r,e={})=>({tr:t,state:n,dispatch:i})=>{const s=Ae(r,n.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:u}=l;if(i){const d=hr(a,s,e);if(d&&d.from<=c&&d.to>=u){const f=E.create(o,d.from,d.to);t.setSelection(f)}}return!0},fu=r=>e=>{const t=typeof r=="function"?r(e):r;for(let n=0;n<t.length;n+=1)if(t[n](e))return!0;return!1};function ao(r){return r instanceof E}function He(r=0,e=0,t=0){return Math.min(Math.max(r,e),t)}function co(r,e=null){if(!e)return null;const t=O.atStart(r),n=O.atEnd(r);if(e==="start"||e===!0)return t;if(e==="end")return n;const i=t.from,s=n.to;return e==="all"?E.create(r,He(0,i,s),He(r.content.size,i,s)):E.create(r,He(e,i,s),He(e,i,s))}function hu(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function pr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const pu=(r=null,e={})=>({editor:t,view:n,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{(pr()||hu())&&n.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(n.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};if(n.hasFocus()&&r===null||r===!1)return!0;if(s&&r===null&&!ao(t.state.selection))return o(),!0;const l=co(i.doc,r)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},mu=(r,e)=>t=>r.every((n,i)=>e(n,{...t,index:i})),gu=(r,e)=>({tr:t,commands:n})=>n.insertContentAt({from:t.selection.from,to:t.selection.to},r,e),uo=r=>{const e=r.childNodes;for(let t=e.length-1;t>=0;t-=1){const n=e[t];n.nodeType===3&&n.nodeValue&&/^(\n\s\s|\n)$/.test(n.nodeValue)?r.removeChild(n):n.nodeType===1&&uo(n)}return r};function ln(r){const e=`<body>${r}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return uo(t)}function an(r,e,t){if(r instanceof ye||r instanceof b)return r;t={slice:!0,parseOptions:{},...t};const n=typeof r=="object"&&r!==null,i=typeof r=="string";if(n)try{if(Array.isArray(r)&&r.length>0)return b.fromArray(r.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(r);return t.errorOnInvalidContent&&o.check(),o}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",r,"Error:",s),an("",e,t)}if(i){if(t.errorOnInvalidContent){let o=!1,l="";const a=new Ur({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,l=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?ct.fromSchema(a).parseSlice(ln(r),t.parseOptions):ct.fromSchema(a).parse(ln(r),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=ct.fromSchema(e);return t.slice?s.parseSlice(ln(r),t.parseOptions).content:s.parse(ln(r),t.parseOptions)}return an("",e,t)}function yu(r,e,t){const n=r.steps.length-1;if(n<e)return;const i=r.steps[n];if(!(i instanceof B||i instanceof F))return;const s=r.mapping.maps[n];let o=0;s.forEach((l,a,c,u)=>{o===0&&(o=u)}),r.setSelection(O.near(r.doc.resolve(o),t))}const bu=r=>!("type"in r),ku=(r,e,t)=>({tr:n,dispatch:i,editor:s})=>{var o;if(i){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;try{l=an(e,s.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions},errorOnInvalidContent:(o=t.errorOnInvalidContent)!==null&&o!==void 0?o:s.options.enableContentCheck})}catch(p){return s.emit("contentError",{editor:s,error:p,disableCollaboration:()=>{s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}}),!1}let{from:a,to:c}=typeof r=="number"?{from:r,to:r}:{from:r.from,to:r.to},u=!0,d=!0;if((bu(l)?l:[l]).forEach(p=>{p.check(),u=u?p.isText&&p.marks.length===0:!1,d=d?p.isBlock:!1}),a===c&&d){const{parent:p}=n.doc.resolve(a);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(a-=1,c+=1)}let h;if(u){if(Array.isArray(e))h=e.map(p=>p.text||"").join("");else if(e instanceof b){let p="";e.forEach(m=>{m.text&&(p+=m.text)}),h=p}else typeof e=="object"&&e&&e.text?h=e.text:h=e;n.insertText(h,a,c)}else h=l,n.replaceWith(a,c,h);t.updateSelection&&yu(n,n.steps.length-1,-1),t.applyInputRules&&n.setMeta("applyInputRules",{from:a,text:h}),t.applyPasteRules&&n.setMeta("applyPasteRules",{from:a,text:h})}return!0},xu=()=>({state:r,dispatch:e})=>kc(r,e),Su=()=>({state:r,dispatch:e})=>xc(r,e),Cu=()=>({state:r,dispatch:e})=>js(r,e),wu=()=>({state:r,dispatch:e})=>qs(r,e),Mu=()=>({state:r,dispatch:e,tr:t})=>{try{const n=Vt(r.doc,r.selection.$from.pos,-1);return n==null?!1:(t.join(n,2),e&&e(t),!0)}catch{return!1}},Eu=()=>({state:r,dispatch:e,tr:t})=>{try{const n=Vt(r.doc,r.selection.$from.pos,1);return n==null?!1:(t.join(n,2),e&&e(t),!0)}catch{return!1}},Tu=()=>({state:r,dispatch:e})=>yc(r,e),Ou=()=>({state:r,dispatch:e})=>bc(r,e);function fo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Nu(r){const e=r.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let n,i,s,o;for(let l=0;l<e.length-1;l+=1){const 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))pr()||fo()?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}const Au=r=>({editor:e,view:t,tr:n,dispatch:i})=>{const s=Nu(r).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a==null||a.steps.forEach(c=>{const u=c.map(n.mapping);u&&i&&n.maybeStep(u)}),!0};function Tt(r,e,t={}){const{from:n,to:i,empty:s}=r.selection,o=e?L(e,r.schema):null,l=[];r.doc.nodesBetween(n,i,(d,f)=>{if(d.isText)return;const h=Math.max(n,f),p=Math.min(i,f+d.nodeSize);l.push({node:d,from:h,to:p})});const a=i-n,c=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>on(d.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((d,f)=>d+f.to-f.from,0)>=a}const vu=(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return Tt(t,i,e)?Sc(t,n):!1},Du=()=>({state:r,dispatch:e})=>Gs(r,e),Iu=r=>({state:e,dispatch:t})=>{const n=L(r,e.schema);return Pc(n)(e,t)},Pu=()=>({state:r,dispatch:e})=>Us(r,e);function cn(r,e){return e.nodes[r]?"node":e.marks[r]?"mark":null}function ho(r,e){const t=typeof e=="string"?[e]:e;return Object.keys(r).reduce((n,i)=>(t.includes(i)||(n[i]=r[i]),n),{})}const Ru=(r,e)=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=cn(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=L(r,n.schema)),l==="mark"&&(o=Ae(r,n.schema)),i&&t.selection.ranges.forEach(a=>{n.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,u)=>{s&&s===c.type&&t.setNodeMarkup(u,void 0,ho(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(d=>{o===d.type&&t.addMark(u,u+c.nodeSize,o.create(ho(d.attrs,e)))})})}),!0):!1},Bu=()=>({tr:r,dispatch:e})=>(e&&r.scrollIntoView(),!0),zu=()=>({tr:r,dispatch:e})=>{if(e){const t=new Z(r.doc);r.setSelection(t)}return!0},Fu=()=>({state:r,dispatch:e})=>Hs(r,e),Lu=()=>({state:r,dispatch:e})=>Ks(r,e),$u=()=>({state:r,dispatch:e})=>Ec(r,e),Vu=()=>({state:r,dispatch:e})=>Nc(r,e),ju=()=>({state:r,dispatch:e})=>Oc(r,e);function mr(r,e,t={},n={}){return an(r,e,{slice:!1,parseOptions:t,errorOnInvalidContent:n.errorOnInvalidContent})}const Wu=(r,e=!1,t={},n={})=>({editor:i,tr:s,dispatch:o,commands:l})=>{var a,c;const{doc:u}=s;if(t.preserveWhitespace!=="full"){const d=mr(r,i.schema,t,{errorOnInvalidContent:(a=n.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});return o&&s.replaceWith(0,u.content.size,d).setMeta("preventUpdate",!e),!0}return o&&s.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:u.content.size},r,{parseOptions:t,errorOnInvalidContent:(c=n.errorOnInvalidContent)!==null&&c!==void 0?c:i.options.enableContentCheck})};function po(r,e){const t=Ae(e,r.schema),{from:n,to:i,empty:s}=r.selection,o=[];s?(r.storedMarks&&o.push(...r.storedMarks),o.push(...r.selection.$head.marks())):r.doc.nodesBetween(n,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function Hu(r){for(let e=0;e<r.edgeCount;e+=1){const{type:t}=r.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function Ot(r,e){for(let t=r.depth;t>0;t-=1){const n=r.node(t);if(e(n))return{pos:t>0?r.before(t):0,start:r.start(t),depth:t,node:n}}}function gr(r){return e=>Ot(e.$from,r)}function Ju(r,e){const t={from:0,to:r.content.size};return io(r,t,e)}function qu(r,e){const t=L(e,r.schema),{from:n,to:i}=r.selection,s=[];r.doc.nodesBetween(n,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function Ku(r,e){const t=cn(typeof e=="string"?e:e.name,r.schema);return t==="node"?qu(r,e):t==="mark"?po(r,e):{}}function un(r,e,t){return Object.fromEntries(Object.entries(t).filter(([n])=>{const i=r.find(s=>s.type===e&&s.name===n);return i?i.attribute.keepOnSplit:!1}))}function yr(r,e,t={}){const{empty:n,ranges:i}=r.selection,s=e?Ae(e,r.schema):null;if(n)return!!(r.storedMarks||r.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>on(d.attrs,t,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:d,$to:f})=>{const h=d.pos,p=f.pos;r.doc.nodesBetween(h,p,(m,g)=>{if(!m.isText&&!m.marks.length)return;const y=Math.max(h,g),S=Math.min(p,g+m.nodeSize),w=S-y;o+=w,l.push(...m.marks.map(v=>({mark:v,from:y,to:S})))})}),o===0)return!1;const a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>on(d.mark.attrs,t,{strict:!1})).reduce((d,f)=>d+f.to-f.from,0),c=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,f)=>d+f.to-f.from,0);return(a>0?a+c:a)>=o}function Uu(r,e,t={}){if(!e)return Tt(r,null,t)||yr(r,null,t);const n=cn(e,r.schema);return n==="node"?Tt(r,e,t):n==="mark"?yr(r,e,t):!1}function mo(r,e){const{nodeExtensions:t}=en(e),n=t.find(o=>o.name===r);if(!n)return!1;const i={name:n.name,options:n.options,storage:n.storage},s=N(x(n,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function dn(r,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var n;if(t){if(r.type.name==="hardBreak")return!0;if(r.isText)return/^\s*$/m.test((n=r.text)!==null&&n!==void 0?n:"")}if(r.isText)return!r.text;if(r.isAtom||r.isLeaf)return!1;if(r.content.childCount===0)return!0;if(e){let i=!0;return r.content.forEach(s=>{i!==!1&&(dn(s,{ignoreWhitespace:t,checkChildren:e})||(i=!1))}),i}return!1}function _u(r,e,t){var n;const{selection:i}=e;let s=null;if(ao(i)&&(s=i.$cursor),s){const l=(n=r.storedMarks)!==null&&n!==void 0?n:s.marks();return!!t.isInSet(l)||!l.some(a=>a.type.excludes(t))}const{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?r.doc.inlineContent&&r.doc.type.allowsMarkType(t):!1;return r.doc.nodesBetween(l.pos,a.pos,(u,d,f)=>{if(c)return!1;if(u.isInline){const h=!f||f.type.allowsMarkType(t),p=!!t.isInSet(u.marks)||!u.marks.some(m=>m.type.excludes(t));c=h&&p}return!c}),c})}const Gu=(r,e={})=>({tr:t,state:n,dispatch:i})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=Ae(r,n.schema);if(i)if(o){const c=po(n,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const u=c.$from.pos,d=c.$to.pos;n.doc.nodesBetween(u,d,(f,h)=>{const p=Math.max(h,u),m=Math.min(h+f.nodeSize,d);f.marks.find(y=>y.type===a)?f.marks.forEach(y=>{a===y.type&&t.addMark(p,m,a.create({...y.attrs,...e}))}):t.addMark(p,m,a.create(e))})});return _u(n,t,a)},Yu=(r,e)=>({tr:t})=>(t.setMeta(r,e),!0),Xu=(r,e={})=>({state:t,dispatch:n,chain:i})=>{const s=L(r,t.schema);let o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),s.isTextblock?i().command(({commands:l})=>Zs(s,{...o,...e})(t)?!0:l.clearNodes()).command(({state:l})=>Zs(s,{...o,...e})(l,n)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Zu=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,i=He(r,0,n.content.size),s=C.create(n,i);e.setSelection(s)}return!0},Qu=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,{from:i,to:s}=typeof r=="number"?{from:r,to:r}:r,o=E.atStart(n).from,l=E.atEnd(n).to,a=He(i,o,l),c=He(s,o,l),u=E.create(n,a,c);e.setSelection(u)}return!0},ed=r=>({state:e,dispatch:t})=>{const n=L(r,e.schema);return zc(n)(e,t)};function go(r,e){const t=r.storedMarks||r.selection.$to.parentOffset&&r.selection.$from.marks();if(t){const n=t.filter(i=>e==null?void 0:e.includes(i.type.name));r.tr.ensureMarks(n)}}const td=({keepMarks:r=!0}={})=>({tr:e,state:t,dispatch:n,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,u=un(c,l.node().type.name,l.node().attrs);if(s instanceof C&&s.node.isBlock)return!l.parentOffset||!fe(o,l.pos)?!1:(n&&(r&&go(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const d=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:Hu(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&f?[{type:f,attrs:u}]:void 0,p=fe(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!p&&fe(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(p=!0,h=f?[{type:f,attrs:u}]:void 0),n){if(p&&(s instanceof E&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),f&&!d&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}r&&go(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return p},nd=(r,e={})=>({tr:t,state:n,dispatch:i,editor:s})=>{var o;const l=L(r,n.schema),{$from:a,$to:c}=n.selection,u=n.selection.node;if(u&&u.isBlock||a.depth<2||!a.sameParent(c))return!1;const d=a.node(-1);if(d.type!==l)return!1;const f=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(i){let y=b.empty;const S=a.index(-1)?1:a.index(-2)?2:3;for(let q=a.depth-S;q>=a.depth-3;q-=1)y=b.from(a.node(q).copy(y));const w=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,v={...un(f,a.node().type.name,a.node().attrs),...e},A=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(v))||void 0;y=y.append(b.from(l.createAndFill(null,A)||void 0));const M=a.before(a.depth-(S-1));t.replace(M,a.after(-w),new k(y,4-S,0));let I=-1;t.doc.nodesBetween(M,t.doc.content.size,(q,T)=>{if(I>-1)return!1;q.isTextblock&&q.content.size===0&&(I=T+1)}),I>-1&&t.setSelection(E.near(t.doc.resolve(I))),t.scrollIntoView()}return!0}const h=c.pos===a.end()?d.contentMatchAt(0).defaultType:null,p={...un(f,d.type.name,d.attrs),...e},m={...un(f,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,c.pos);const g=h?[{type:l,attrs:p},{type:h,attrs:m}]:[{type:l,attrs:p}];if(!fe(t.doc,a.pos,2))return!1;if(i){const{selection:y,storedMarks:S}=n,{splittableMarks:w}=s.extensionManager,v=S||y.$to.parentOffset&&y.$from.marks();if(t.split(a.pos,2,g).scrollIntoView(),!v||!i)return!0;const A=v.filter(M=>w.includes(M.type.name));t.ensureMarks(A)}return!0},br=(r,e)=>{const t=gr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&Be(r.doc,t.pos)&&r.join(t.pos),!0},kr=(r,e)=>{const t=gr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(t.start).after(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&Be(r.doc,n)&&r.join(n),!0};var rd=Object.freeze({__proto__:null,blur:Qc,clearContent:eu,clearNodes:tu,command:nu,createParagraphNear:ru,cut:iu,deleteCurrentNode:su,deleteNode:ou,deleteRange:lu,deleteSelection:au,enter:cu,exitCode:uu,extendMarkRange:du,first:fu,focus:pu,forEach:mu,insertContent:gu,insertContentAt:ku,joinBackward:Cu,joinDown:Su,joinForward:wu,joinItemBackward:Mu,joinItemForward:Eu,joinTextblockBackward:Tu,joinTextblockForward:Ou,joinUp:xu,keyboardShortcut:Au,lift:vu,liftEmptyBlock:Du,liftListItem:Iu,newlineInCode:Pu,resetAttributes:Ru,scrollIntoView:Bu,selectAll:zu,selectNodeBackward:Fu,selectNodeForward:Lu,selectParentNode:$u,selectTextblockEnd:Vu,selectTextblockStart:ju,setContent:Wu,setMark:Gu,setMeta:Yu,setNode:Xu,setNodeSelection:Zu,setTextSelection:Qu,sinkListItem:ed,splitBlock:td,splitListItem:nd,toggleList:(r,e,t,n={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:c,can:u})=>{const{extensions:d,splittableMarks:f}=i.extensionManager,h=L(r,o.schema),p=L(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:S}=m,w=y.blockRange(S),v=g||m.$to.parentOffset&&m.$from.marks();if(!w)return!1;const A=gr(M=>mo(M.type.name,d))(m);if(w.depth>=1&&A&&w.depth-A.depth<=1){if(A.node.type===h)return c.liftListItem(p);if(mo(A.node.type.name,d)&&h.validContent(A.node.content)&&l)return a().command(()=>(s.setNodeMarkup(A.pos,h),!0)).command(()=>br(s,h)).command(()=>kr(s,h)).run()}return!t||!v||!l?a().command(()=>u().wrapInList(h,n)?!0:c.clearNodes()).wrapInList(h,n).command(()=>br(s,h)).command(()=>kr(s,h)).run():a().command(()=>{const M=u().wrapInList(h,n),I=v.filter(q=>f.includes(q.type.name));return s.ensureMarks(I),M?!0:c.clearNodes()}).wrapInList(h,n).command(()=>br(s,h)).command(()=>kr(s,h)).run()},toggleMark:(r,e={},t={})=>({state:n,commands:i})=>{const{extendEmptyMarkRange:s=!1}=t,o=Ae(r,n.schema);return yr(n,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},toggleNode:(r,e,t={})=>({state:n,commands:i})=>{const s=L(r,n.schema),o=L(e,n.schema),l=Tt(n,s,t);let a;return n.selection.$anchor.sameParent(n.selection.$head)&&(a=n.selection.$anchor.parent.attrs),l?i.setNode(o,a):i.setNode(s,{...a,...t})},toggleWrap:(r,e={})=>({state:t,commands:n})=>{const i=L(r,t.schema);return Tt(t,i,e)?n.lift(i):n.wrapIn(i,e)},undoInputRule:()=>({state:r,dispatch:e})=>{const t=r.plugins;for(let n=0;n<t.length;n+=1){const i=t[n];let s;if(i.spec.isInputRules&&(s=i.getState(r))){if(e){const o=r.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},unsetAllMarks:()=>({tr:r,dispatch:e})=>{const{selection:t}=r,{empty:n,ranges:i}=t;return n||e&&i.forEach(s=>{r.removeMark(s.$from.pos,s.$to.pos)}),!0},unsetMark:(r,e={})=>({tr:t,state:n,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Ae(r,n.schema),{$from:c,empty:u,ranges:d}=l;if(!i)return!0;if(u&&o){let{from:f,to:h}=l;const p=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=hr(c,a,p);m&&(f=m.from,h=m.to),t.removeMark(f,h,a)}else d.forEach(f=>{t.removeMark(f.$from.pos,f.$to.pos,a)});return t.removeStoredMark(a),!0},updateAttributes:(r,e={})=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=cn(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=L(r,n.schema)),l==="mark"&&(o=Ae(r,n.schema)),i&&t.selection.ranges.forEach(a=>{const c=a.$from.pos,u=a.$to.pos;let d,f,h,p;t.selection.empty?n.doc.nodesBetween(c,u,(m,g)=>{s&&s===m.type&&(h=Math.max(g,c),p=Math.min(g+m.nodeSize,u),d=g,f=m)}):n.doc.nodesBetween(c,u,(m,g)=>{g<c&&s&&s===m.type&&(h=Math.max(g,c),p=Math.min(g+m.nodeSize,u),d=g,f=m),g>=c&&g<=u&&(s&&s===m.type&&t.setNodeMarkup(g,void 0,{...m.attrs,...e}),o&&m.marks.length&&m.marks.forEach(y=>{if(o===y.type){const S=Math.max(g,c),w=Math.min(g+m.nodeSize,u);t.addMark(S,w,o.create({...y.attrs,...e}))}}))}),f&&(d!==void 0&&t.setNodeMarkup(d,void 0,{...f.attrs,...e}),o&&f.marks.length&&f.marks.forEach(m=>{o===m.type&&t.addMark(h,p,o.create({...m.attrs,...e}))}))}),!0):!1},wrapIn:(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return Ac(i,e)(t,n)},wrapInList:(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return vc(i,e)(t,n)}});const id=Y.create({name:"commands",addCommands(){return{...rd}}}),sd=Y.create({name:"drop",addProseMirrorPlugins(){return[new Q({key:new se("tiptapDrop"),props:{handleDrop:(r,e,t,n)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:n})}}})]}}),od=Y.create({name:"editable",addProseMirrorPlugins(){return[new Q({key:new se("editable"),props:{editable:()=>this.editor.options.editable}})]}}),ld=new se("focusEvents"),ad=Y.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:r}=this;return[new Q({key:ld,props:{handleDOMEvents:{focus:(e,t)=>{r.isFocused=!0;const n=r.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1},blur:(e,t)=>{r.isFocused=!1;const n=r.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1}}}})]}}),cd=Y.create({name:"keymap",addKeyboardShortcuts(){const r=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:u,$anchor:d}=a,{pos:f,parent:h}=d,p=d.parent.isTextblock&&f>0?l.doc.resolve(f-1):d,m=p.parent.type.spec.isolating,g=d.pos-d.parentOffset,y=m&&p.parent.childCount===1?g===d.pos:O.atStart(c).from===f;return!u||!h.type.isTextblock||h.textContent.length||!y||y&&d.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:r,"Mod-Backspace":r,"Shift-Backspace":r,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...n},s={...n,"Ctrl-h":r,"Alt-Backspace":r,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return pr()||fo()?s:i},addProseMirrorPlugins(){return[new Q({key:new se("clearDocument"),appendTransaction:(r,e,t)=>{if(r.some(m=>m.getMeta("composition")))return;const n=r.some(m=>m.docChanged)&&!e.doc.eq(t.doc),i=r.some(m=>m.getMeta("preventClearDocument"));if(!n||i)return;const{empty:s,from:o,to:l}=e.selection,a=O.atStart(e.doc).from,c=O.atEnd(e.doc).to;if(s||!(o===a&&l===c)||!dn(t.doc))return;const f=t.tr,h=Zt({state:t,transaction:f}),{commands:p}=new Qt({editor:this.editor,state:h});if(p.clearNodes(),!!f.steps.length)return f}})]}}),ud=Y.create({name:"paste",addProseMirrorPlugins(){return[new Q({key:new se("tiptapPaste"),props:{handlePaste:(r,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),dd=Y.create({name:"tabindex",addProseMirrorPlugins(){return[new Q({key:new se("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Je{get name(){return this.node.type.name}constructor(e,t,n=!1,i=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=i}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new Je(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new Je(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new Je(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,n)=>{const i=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,o=this.pos+n+(s?0:1),l=this.resolvedPos.doc.resolve(o);if(!i&&l.depth<=this.depth)return;const a=new Je(l,this.editor,i,i?t:null);i&&(a.actualDepth=this.depth+1),e.push(new Je(l,this.editor,i,i?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,i=this.parent;for(;i&&!n;){if(i.node.type.name===e)if(Object.keys(t).length>0){const s=i.node.attrs,o=Object.keys(t);for(let l=0;l<o.length;l+=1){const a=o[l];if(s[a]!==t[a])break}}else n=i;i=i.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let i=[];if(!this.children||this.children.length===0)return i;const s=Object.keys(t);return this.children.forEach(o=>{n&&i.length>0||(o.node.type.name===e&&s.every(a=>t[a]===o.node.attrs[a])&&i.push(o),!(n&&i.length>0)&&(i=i.concat(o.querySelectorAll(e,t,n))))}),i}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}const fd=`.ProseMirror {
|
|
13
|
+
`,textSerializers:o={}}=t||{};let l="";return r.nodesBetween(n,i,(a,c,u,d)=>{var f;a.isBlock&&c>n&&(l+=s);const h=o==null?void 0:o[a.type.name];if(h)return u&&(l+=h({node:a,pos:c,parent:u,index:d,range:e})),!1;a.isText&&(l+=(f=a==null?void 0:a.text)===null||f===void 0?void 0:f.slice(Math.max(n,c)-c,i-c))}),l}function so(r){return Object.fromEntries(Object.entries(r.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Xc=Y.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Q({key:new se("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:r}=this,{state:e,schema:t}=r,{doc:n,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),a=so(t);return io(n,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),Zc=()=>({editor:r,view:e})=>(requestAnimationFrame(()=>{var t;r.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),Qc=(r=!1)=>({commands:e})=>e.setContent("",r),eu=()=>({state:r,tr:e,dispatch:t})=>{const{selection:n}=e,{ranges:i}=n;return t&&i.forEach(({$from:s,$to:o})=>{r.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:u}=e,d=c.resolve(u.map(a)),f=c.resolve(u.map(a+l.nodeSize)),h=d.blockRange(f);if(!h)return;const p=_e(h);if(l.type.isTextblock){const{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(h.start,m)}(p||p===0)&&e.lift(h,p)})}),!0},tu=r=>e=>r(e),nu=()=>({state:r,dispatch:e})=>_s(r,e),ru=(r,e)=>({editor:t,tr:n})=>{const{state:i}=t,s=i.doc.slice(r.from,r.to);n.deleteRange(r.from,r.to);const o=n.mapping.map(e);return n.insert(o,s.content),n.setSelection(new E(n.doc.resolve(o-1))),!0},iu=()=>({tr:r,dispatch:e})=>{const{selection:t}=r,n=t.$anchor.node();if(n.content.size>0)return!1;const i=r.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===n.type){if(e){const l=i.before(s),a=i.after(s);r.delete(l,a).scrollIntoView()}return!0}return!1},su=r=>({tr:e,state:t,dispatch:n})=>{const i=L(r,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(n){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},ou=r=>({tr:e,dispatch:t})=>{const{from:n,to:i}=r;return t&&e.delete(n,i),!0},lu=()=>({state:r,dispatch:e})=>ir(r,e),au=()=>({commands:r})=>r.keyboardShortcut("Enter"),cu=()=>({state:r,dispatch:e})=>Sc(r,e);function on(r,e,t={strict:!0}){const n=Object.keys(e);return n.length?n.every(i=>t.strict?e[i]===r[i]:fr(e[i])?e[i].test(r[i]):e[i]===r[i]):!0}function oo(r,e,t={}){return r.find(n=>n.type===e&&on(Object.fromEntries(Object.keys(t).map(i=>[i,n.attrs[i]])),t))}function lo(r,e,t={}){return!!oo(r,e,t)}function hr(r,e,t){var n;if(!r||!e)return;let i=r.parent.childAfter(r.parentOffset);if((!i.node||!i.node.marks.some(u=>u.type===e))&&(i=r.parent.childBefore(r.parentOffset)),!i.node||!i.node.marks.some(u=>u.type===e)||(t=t||((n=i.node.marks[0])===null||n===void 0?void 0:n.attrs),!oo([...i.node.marks],e,t)))return;let o=i.index,l=r.start()+i.offset,a=o+1,c=l+i.node.nodeSize;for(;o>0&&lo([...r.parent.child(o-1).marks],e,t);)o-=1,l-=r.parent.child(o).nodeSize;for(;a<r.parent.childCount&&lo([...r.parent.child(a).marks],e,t);)c+=r.parent.child(a).nodeSize,a+=1;return{from:l,to:c}}function Ae(r,e){if(typeof r=="string"){if(!e.marks[r])throw Error(`There is no mark type named '${r}'. Maybe you forgot to add the extension?`);return e.marks[r]}return r}const uu=(r,e={})=>({tr:t,state:n,dispatch:i})=>{const s=Ae(r,n.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:u}=l;if(i){const d=hr(a,s,e);if(d&&d.from<=c&&d.to>=u){const f=E.create(o,d.from,d.to);t.setSelection(f)}}return!0},du=r=>e=>{const t=typeof r=="function"?r(e):r;for(let n=0;n<t.length;n+=1)if(t[n](e))return!0;return!1};function ao(r){return r instanceof E}function He(r=0,e=0,t=0){return Math.min(Math.max(r,e),t)}function co(r,e=null){if(!e)return null;const t=O.atStart(r),n=O.atEnd(r);if(e==="start"||e===!0)return t;if(e==="end")return n;const i=t.from,s=n.to;return e==="all"?E.create(r,He(0,i,s),He(r.content.size,i,s)):E.create(r,He(e,i,s),He(e,i,s))}function fu(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function pr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const hu=(r=null,e={})=>({editor:t,view:n,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{(pr()||fu())&&n.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(n.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};if(n.hasFocus()&&r===null||r===!1)return!0;if(s&&r===null&&!ao(t.state.selection))return o(),!0;const l=co(i.doc,r)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},pu=(r,e)=>t=>r.every((n,i)=>e(n,{...t,index:i})),mu=(r,e)=>({tr:t,commands:n})=>n.insertContentAt({from:t.selection.from,to:t.selection.to},r,e),uo=r=>{const e=r.childNodes;for(let t=e.length-1;t>=0;t-=1){const n=e[t];n.nodeType===3&&n.nodeValue&&/^(\n\s\s|\n)$/.test(n.nodeValue)?r.removeChild(n):n.nodeType===1&&uo(n)}return r};function ln(r){const e=`<body>${r}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return uo(t)}function an(r,e,t){if(r instanceof ye||r instanceof b)return r;t={slice:!0,parseOptions:{},...t};const n=typeof r=="object"&&r!==null,i=typeof r=="string";if(n)try{if(Array.isArray(r)&&r.length>0)return b.fromArray(r.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(r);return t.errorOnInvalidContent&&o.check(),o}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",r,"Error:",s),an("",e,t)}if(i){if(t.errorOnInvalidContent){let o=!1,l="";const a=new Ur({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,l=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?ct.fromSchema(a).parseSlice(ln(r),t.parseOptions):ct.fromSchema(a).parse(ln(r),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=ct.fromSchema(e);return t.slice?s.parseSlice(ln(r),t.parseOptions).content:s.parse(ln(r),t.parseOptions)}return an("",e,t)}function gu(r,e,t){const n=r.steps.length-1;if(n<e)return;const i=r.steps[n];if(!(i instanceof B||i instanceof F))return;const s=r.mapping.maps[n];let o=0;s.forEach((l,a,c,u)=>{o===0&&(o=u)}),r.setSelection(O.near(r.doc.resolve(o),t))}const yu=r=>!("type"in r),bu=(r,e,t)=>({tr:n,dispatch:i,editor:s})=>{var o;if(i){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;try{l=an(e,s.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions},errorOnInvalidContent:(o=t.errorOnInvalidContent)!==null&&o!==void 0?o:s.options.enableContentCheck})}catch(p){return s.emit("contentError",{editor:s,error:p,disableCollaboration:()=>{s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}}),!1}let{from:a,to:c}=typeof r=="number"?{from:r,to:r}:{from:r.from,to:r.to},u=!0,d=!0;if((yu(l)?l:[l]).forEach(p=>{p.check(),u=u?p.isText&&p.marks.length===0:!1,d=d?p.isBlock:!1}),a===c&&d){const{parent:p}=n.doc.resolve(a);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(a-=1,c+=1)}let h;if(u){if(Array.isArray(e))h=e.map(p=>p.text||"").join("");else if(e instanceof b){let p="";e.forEach(m=>{m.text&&(p+=m.text)}),h=p}else typeof e=="object"&&e&&e.text?h=e.text:h=e;n.insertText(h,a,c)}else h=l,n.replaceWith(a,c,h);t.updateSelection&&gu(n,n.steps.length-1,-1),t.applyInputRules&&n.setMeta("applyInputRules",{from:a,text:h}),t.applyPasteRules&&n.setMeta("applyPasteRules",{from:a,text:h})}return!0},ku=()=>({state:r,dispatch:e})=>bc(r,e),xu=()=>({state:r,dispatch:e})=>kc(r,e),Su=()=>({state:r,dispatch:e})=>js(r,e),Cu=()=>({state:r,dispatch:e})=>qs(r,e),wu=()=>({state:r,dispatch:e,tr:t})=>{try{const n=Vt(r.doc,r.selection.$from.pos,-1);return n==null?!1:(t.join(n,2),e&&e(t),!0)}catch{return!1}},Mu=()=>({state:r,dispatch:e,tr:t})=>{try{const n=Vt(r.doc,r.selection.$from.pos,1);return n==null?!1:(t.join(n,2),e&&e(t),!0)}catch{return!1}},Eu=()=>({state:r,dispatch:e})=>gc(r,e),Tu=()=>({state:r,dispatch:e})=>yc(r,e);function fo(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ou(r){const e=r.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let n,i,s,o;for(let l=0;l<e.length-1;l+=1){const 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))pr()||fo()?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}const Nu=r=>({editor:e,view:t,tr:n,dispatch:i})=>{const s=Ou(r).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a==null||a.steps.forEach(c=>{const u=c.map(n.mapping);u&&i&&n.maybeStep(u)}),!0};function Tt(r,e,t={}){const{from:n,to:i,empty:s}=r.selection,o=e?L(e,r.schema):null,l=[];r.doc.nodesBetween(n,i,(d,f)=>{if(d.isText)return;const h=Math.max(n,f),p=Math.min(i,f+d.nodeSize);l.push({node:d,from:h,to:p})});const a=i-n,c=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>on(d.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((d,f)=>d+f.to-f.from,0)>=a}const Au=(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return Tt(t,i,e)?xc(t,n):!1},vu=()=>({state:r,dispatch:e})=>Gs(r,e),Du=r=>({state:e,dispatch:t})=>{const n=L(r,e.schema);return Ic(n)(e,t)},Iu=()=>({state:r,dispatch:e})=>Us(r,e);function cn(r,e){return e.nodes[r]?"node":e.marks[r]?"mark":null}function ho(r,e){const t=typeof e=="string"?[e]:e;return Object.keys(r).reduce((n,i)=>(t.includes(i)||(n[i]=r[i]),n),{})}const Pu=(r,e)=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=cn(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=L(r,n.schema)),l==="mark"&&(o=Ae(r,n.schema)),i&&t.selection.ranges.forEach(a=>{n.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,u)=>{s&&s===c.type&&t.setNodeMarkup(u,void 0,ho(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(d=>{o===d.type&&t.addMark(u,u+c.nodeSize,o.create(ho(d.attrs,e)))})})}),!0):!1},Ru=()=>({tr:r,dispatch:e})=>(e&&r.scrollIntoView(),!0),Bu=()=>({tr:r,dispatch:e})=>{if(e){const t=new Z(r.doc);r.setSelection(t)}return!0},zu=()=>({state:r,dispatch:e})=>Hs(r,e),Fu=()=>({state:r,dispatch:e})=>Ks(r,e),Lu=()=>({state:r,dispatch:e})=>Mc(r,e),$u=()=>({state:r,dispatch:e})=>Oc(r,e),Vu=()=>({state:r,dispatch:e})=>Tc(r,e);function mr(r,e,t={},n={}){return an(r,e,{slice:!1,parseOptions:t,errorOnInvalidContent:n.errorOnInvalidContent})}const ju=(r,e=!1,t={},n={})=>({editor:i,tr:s,dispatch:o,commands:l})=>{var a,c;const{doc:u}=s;if(t.preserveWhitespace!=="full"){const d=mr(r,i.schema,t,{errorOnInvalidContent:(a=n.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});return o&&s.replaceWith(0,u.content.size,d).setMeta("preventUpdate",!e),!0}return o&&s.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:u.content.size},r,{parseOptions:t,errorOnInvalidContent:(c=n.errorOnInvalidContent)!==null&&c!==void 0?c:i.options.enableContentCheck})};function po(r,e){const t=Ae(e,r.schema),{from:n,to:i,empty:s}=r.selection,o=[];s?(r.storedMarks&&o.push(...r.storedMarks),o.push(...r.selection.$head.marks())):r.doc.nodesBetween(n,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function Wu(r){for(let e=0;e<r.edgeCount;e+=1){const{type:t}=r.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function Ot(r,e){for(let t=r.depth;t>0;t-=1){const n=r.node(t);if(e(n))return{pos:t>0?r.before(t):0,start:r.start(t),depth:t,node:n}}}function gr(r){return e=>Ot(e.$from,r)}function Hu(r,e){const t={from:0,to:r.content.size};return io(r,t,e)}function Ju(r,e){const t=L(e,r.schema),{from:n,to:i}=r.selection,s=[];r.doc.nodesBetween(n,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function qu(r,e){const t=cn(typeof e=="string"?e:e.name,r.schema);return t==="node"?Ju(r,e):t==="mark"?po(r,e):{}}function un(r,e,t){return Object.fromEntries(Object.entries(t).filter(([n])=>{const i=r.find(s=>s.type===e&&s.name===n);return i?i.attribute.keepOnSplit:!1}))}function yr(r,e,t={}){const{empty:n,ranges:i}=r.selection,s=e?Ae(e,r.schema):null;if(n)return!!(r.storedMarks||r.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>on(d.attrs,t,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:d,$to:f})=>{const h=d.pos,p=f.pos;r.doc.nodesBetween(h,p,(m,g)=>{if(!m.isText&&!m.marks.length)return;const y=Math.max(h,g),S=Math.min(p,g+m.nodeSize),w=S-y;o+=w,l.push(...m.marks.map(v=>({mark:v,from:y,to:S})))})}),o===0)return!1;const a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>on(d.mark.attrs,t,{strict:!1})).reduce((d,f)=>d+f.to-f.from,0),c=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,f)=>d+f.to-f.from,0);return(a>0?a+c:a)>=o}function Ku(r,e,t={}){if(!e)return Tt(r,null,t)||yr(r,null,t);const n=cn(e,r.schema);return n==="node"?Tt(r,e,t):n==="mark"?yr(r,e,t):!1}function mo(r,e){const{nodeExtensions:t}=en(e),n=t.find(o=>o.name===r);if(!n)return!1;const i={name:n.name,options:n.options,storage:n.storage},s=N(x(n,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function dn(r,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var n;if(t){if(r.type.name==="hardBreak")return!0;if(r.isText)return/^\s*$/m.test((n=r.text)!==null&&n!==void 0?n:"")}if(r.isText)return!r.text;if(r.isAtom||r.isLeaf)return!1;if(r.content.childCount===0)return!0;if(e){let i=!0;return r.content.forEach(s=>{i!==!1&&(dn(s,{ignoreWhitespace:t,checkChildren:e})||(i=!1))}),i}return!1}function Uu(r,e,t){var n;const{selection:i}=e;let s=null;if(ao(i)&&(s=i.$cursor),s){const l=(n=r.storedMarks)!==null&&n!==void 0?n:s.marks();return!!t.isInSet(l)||!l.some(a=>a.type.excludes(t))}const{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?r.doc.inlineContent&&r.doc.type.allowsMarkType(t):!1;return r.doc.nodesBetween(l.pos,a.pos,(u,d,f)=>{if(c)return!1;if(u.isInline){const h=!f||f.type.allowsMarkType(t),p=!!t.isInSet(u.marks)||!u.marks.some(m=>m.type.excludes(t));c=h&&p}return!c}),c})}const _u=(r,e={})=>({tr:t,state:n,dispatch:i})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=Ae(r,n.schema);if(i)if(o){const c=po(n,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const u=c.$from.pos,d=c.$to.pos;n.doc.nodesBetween(u,d,(f,h)=>{const p=Math.max(h,u),m=Math.min(h+f.nodeSize,d);f.marks.find(y=>y.type===a)?f.marks.forEach(y=>{a===y.type&&t.addMark(p,m,a.create({...y.attrs,...e}))}):t.addMark(p,m,a.create(e))})});return Uu(n,t,a)},Gu=(r,e)=>({tr:t})=>(t.setMeta(r,e),!0),Yu=(r,e={})=>({state:t,dispatch:n,chain:i})=>{const s=L(r,t.schema);let o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),s.isTextblock?i().command(({commands:l})=>Zs(s,{...o,...e})(t)?!0:l.clearNodes()).command(({state:l})=>Zs(s,{...o,...e})(l,n)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Xu=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,i=He(r,0,n.content.size),s=C.create(n,i);e.setSelection(s)}return!0},Zu=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,{from:i,to:s}=typeof r=="number"?{from:r,to:r}:r,o=E.atStart(n).from,l=E.atEnd(n).to,a=He(i,o,l),c=He(s,o,l),u=E.create(n,a,c);e.setSelection(u)}return!0},Qu=r=>({state:e,dispatch:t})=>{const n=L(r,e.schema);return Bc(n)(e,t)};function go(r,e){const t=r.storedMarks||r.selection.$to.parentOffset&&r.selection.$from.marks();if(t){const n=t.filter(i=>e==null?void 0:e.includes(i.type.name));r.tr.ensureMarks(n)}}const ed=({keepMarks:r=!0}={})=>({tr:e,state:t,dispatch:n,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,u=un(c,l.node().type.name,l.node().attrs);if(s instanceof C&&s.node.isBlock)return!l.parentOffset||!fe(o,l.pos)?!1:(n&&(r&&go(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const d=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:Wu(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&f?[{type:f,attrs:u}]:void 0,p=fe(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!p&&fe(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(p=!0,h=f?[{type:f,attrs:u}]:void 0),n){if(p&&(s instanceof E&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),f&&!d&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}r&&go(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return p},td=(r,e={})=>({tr:t,state:n,dispatch:i,editor:s})=>{var o;const l=L(r,n.schema),{$from:a,$to:c}=n.selection,u=n.selection.node;if(u&&u.isBlock||a.depth<2||!a.sameParent(c))return!1;const d=a.node(-1);if(d.type!==l)return!1;const f=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(i){let y=b.empty;const S=a.index(-1)?1:a.index(-2)?2:3;for(let q=a.depth-S;q>=a.depth-3;q-=1)y=b.from(a.node(q).copy(y));const w=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,v={...un(f,a.node().type.name,a.node().attrs),...e},A=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(v))||void 0;y=y.append(b.from(l.createAndFill(null,A)||void 0));const M=a.before(a.depth-(S-1));t.replace(M,a.after(-w),new k(y,4-S,0));let I=-1;t.doc.nodesBetween(M,t.doc.content.size,(q,T)=>{if(I>-1)return!1;q.isTextblock&&q.content.size===0&&(I=T+1)}),I>-1&&t.setSelection(E.near(t.doc.resolve(I))),t.scrollIntoView()}return!0}const h=c.pos===a.end()?d.contentMatchAt(0).defaultType:null,p={...un(f,d.type.name,d.attrs),...e},m={...un(f,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,c.pos);const g=h?[{type:l,attrs:p},{type:h,attrs:m}]:[{type:l,attrs:p}];if(!fe(t.doc,a.pos,2))return!1;if(i){const{selection:y,storedMarks:S}=n,{splittableMarks:w}=s.extensionManager,v=S||y.$to.parentOffset&&y.$from.marks();if(t.split(a.pos,2,g).scrollIntoView(),!v||!i)return!0;const A=v.filter(M=>w.includes(M.type.name));t.ensureMarks(A)}return!0},br=(r,e)=>{const t=gr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&Be(r.doc,t.pos)&&r.join(t.pos),!0},kr=(r,e)=>{const t=gr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(t.start).after(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&Be(r.doc,n)&&r.join(n),!0};var nd=Object.freeze({__proto__:null,blur:Zc,clearContent:Qc,clearNodes:eu,command:tu,createParagraphNear:nu,cut:ru,deleteCurrentNode:iu,deleteNode:su,deleteRange:ou,deleteSelection:lu,enter:au,exitCode:cu,extendMarkRange:uu,first:du,focus:hu,forEach:pu,insertContent:mu,insertContentAt:bu,joinBackward:Su,joinDown:xu,joinForward:Cu,joinItemBackward:wu,joinItemForward:Mu,joinTextblockBackward:Eu,joinTextblockForward:Tu,joinUp:ku,keyboardShortcut:Nu,lift:Au,liftEmptyBlock:vu,liftListItem:Du,newlineInCode:Iu,resetAttributes:Pu,scrollIntoView:Ru,selectAll:Bu,selectNodeBackward:zu,selectNodeForward:Fu,selectParentNode:Lu,selectTextblockEnd:$u,selectTextblockStart:Vu,setContent:ju,setMark:_u,setMeta:Gu,setNode:Yu,setNodeSelection:Xu,setTextSelection:Zu,sinkListItem:Qu,splitBlock:ed,splitListItem:td,toggleList:(r,e,t,n={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:c,can:u})=>{const{extensions:d,splittableMarks:f}=i.extensionManager,h=L(r,o.schema),p=L(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:S}=m,w=y.blockRange(S),v=g||m.$to.parentOffset&&m.$from.marks();if(!w)return!1;const A=gr(M=>mo(M.type.name,d))(m);if(w.depth>=1&&A&&w.depth-A.depth<=1){if(A.node.type===h)return c.liftListItem(p);if(mo(A.node.type.name,d)&&h.validContent(A.node.content)&&l)return a().command(()=>(s.setNodeMarkup(A.pos,h),!0)).command(()=>br(s,h)).command(()=>kr(s,h)).run()}return!t||!v||!l?a().command(()=>u().wrapInList(h,n)?!0:c.clearNodes()).wrapInList(h,n).command(()=>br(s,h)).command(()=>kr(s,h)).run():a().command(()=>{const M=u().wrapInList(h,n),I=v.filter(q=>f.includes(q.type.name));return s.ensureMarks(I),M?!0:c.clearNodes()}).wrapInList(h,n).command(()=>br(s,h)).command(()=>kr(s,h)).run()},toggleMark:(r,e={},t={})=>({state:n,commands:i})=>{const{extendEmptyMarkRange:s=!1}=t,o=Ae(r,n.schema);return yr(n,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},toggleNode:(r,e,t={})=>({state:n,commands:i})=>{const s=L(r,n.schema),o=L(e,n.schema),l=Tt(n,s,t);let a;return n.selection.$anchor.sameParent(n.selection.$head)&&(a=n.selection.$anchor.parent.attrs),l?i.setNode(o,a):i.setNode(s,{...a,...t})},toggleWrap:(r,e={})=>({state:t,commands:n})=>{const i=L(r,t.schema);return Tt(t,i,e)?n.lift(i):n.wrapIn(i,e)},undoInputRule:()=>({state:r,dispatch:e})=>{const t=r.plugins;for(let n=0;n<t.length;n+=1){const i=t[n];let s;if(i.spec.isInputRules&&(s=i.getState(r))){if(e){const o=r.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},unsetAllMarks:()=>({tr:r,dispatch:e})=>{const{selection:t}=r,{empty:n,ranges:i}=t;return n||e&&i.forEach(s=>{r.removeMark(s.$from.pos,s.$to.pos)}),!0},unsetMark:(r,e={})=>({tr:t,state:n,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Ae(r,n.schema),{$from:c,empty:u,ranges:d}=l;if(!i)return!0;if(u&&o){let{from:f,to:h}=l;const p=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=hr(c,a,p);m&&(f=m.from,h=m.to),t.removeMark(f,h,a)}else d.forEach(f=>{t.removeMark(f.$from.pos,f.$to.pos,a)});return t.removeStoredMark(a),!0},updateAttributes:(r,e={})=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=cn(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=L(r,n.schema)),l==="mark"&&(o=Ae(r,n.schema)),i&&t.selection.ranges.forEach(a=>{const c=a.$from.pos,u=a.$to.pos;let d,f,h,p;t.selection.empty?n.doc.nodesBetween(c,u,(m,g)=>{s&&s===m.type&&(h=Math.max(g,c),p=Math.min(g+m.nodeSize,u),d=g,f=m)}):n.doc.nodesBetween(c,u,(m,g)=>{g<c&&s&&s===m.type&&(h=Math.max(g,c),p=Math.min(g+m.nodeSize,u),d=g,f=m),g>=c&&g<=u&&(s&&s===m.type&&t.setNodeMarkup(g,void 0,{...m.attrs,...e}),o&&m.marks.length&&m.marks.forEach(y=>{if(o===y.type){const S=Math.max(g,c),w=Math.min(g+m.nodeSize,u);t.addMark(S,w,o.create({...y.attrs,...e}))}}))}),f&&(d!==void 0&&t.setNodeMarkup(d,void 0,{...f.attrs,...e}),o&&f.marks.length&&f.marks.forEach(m=>{o===m.type&&t.addMark(h,p,o.create({...m.attrs,...e}))}))}),!0):!1},wrapIn:(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return Nc(i,e)(t,n)},wrapInList:(r,e={})=>({state:t,dispatch:n})=>{const i=L(r,t.schema);return Ac(i,e)(t,n)}});const rd=Y.create({name:"commands",addCommands(){return{...nd}}}),id=Y.create({name:"drop",addProseMirrorPlugins(){return[new Q({key:new se("tiptapDrop"),props:{handleDrop:(r,e,t,n)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:n})}}})]}}),sd=Y.create({name:"editable",addProseMirrorPlugins(){return[new Q({key:new se("editable"),props:{editable:()=>this.editor.options.editable}})]}}),od=new se("focusEvents"),ld=Y.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:r}=this;return[new Q({key:od,props:{handleDOMEvents:{focus:(e,t)=>{r.isFocused=!0;const n=r.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1},blur:(e,t)=>{r.isFocused=!1;const n=r.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1}}}})]}}),ad=Y.create({name:"keymap",addKeyboardShortcuts(){const r=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:u,$anchor:d}=a,{pos:f,parent:h}=d,p=d.parent.isTextblock&&f>0?l.doc.resolve(f-1):d,m=p.parent.type.spec.isolating,g=d.pos-d.parentOffset,y=m&&p.parent.childCount===1?g===d.pos:O.atStart(c).from===f;return!u||!h.type.isTextblock||h.textContent.length||!y||y&&d.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:r,"Mod-Backspace":r,"Shift-Backspace":r,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...n},s={...n,"Ctrl-h":r,"Alt-Backspace":r,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return pr()||fo()?s:i},addProseMirrorPlugins(){return[new Q({key:new se("clearDocument"),appendTransaction:(r,e,t)=>{if(r.some(m=>m.getMeta("composition")))return;const n=r.some(m=>m.docChanged)&&!e.doc.eq(t.doc),i=r.some(m=>m.getMeta("preventClearDocument"));if(!n||i)return;const{empty:s,from:o,to:l}=e.selection,a=O.atStart(e.doc).from,c=O.atEnd(e.doc).to;if(s||!(o===a&&l===c)||!dn(t.doc))return;const f=t.tr,h=Zt({state:t,transaction:f}),{commands:p}=new Qt({editor:this.editor,state:h});if(p.clearNodes(),!!f.steps.length)return f}})]}}),cd=Y.create({name:"paste",addProseMirrorPlugins(){return[new Q({key:new se("tiptapPaste"),props:{handlePaste:(r,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),ud=Y.create({name:"tabindex",addProseMirrorPlugins(){return[new Q({key:new se("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Je{get name(){return this.node.type.name}constructor(e,t,n=!1,i=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=i}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new Je(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new Je(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new Je(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,n)=>{const i=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,o=this.pos+n+(s?0:1),l=this.resolvedPos.doc.resolve(o);if(!i&&l.depth<=this.depth)return;const a=new Je(l,this.editor,i,i?t:null);i&&(a.actualDepth=this.depth+1),e.push(new Je(l,this.editor,i,i?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,i=this.parent;for(;i&&!n;){if(i.node.type.name===e)if(Object.keys(t).length>0){const s=i.node.attrs,o=Object.keys(t);for(let l=0;l<o.length;l+=1){const a=o[l];if(s[a]!==t[a])break}}else n=i;i=i.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let i=[];if(!this.children||this.children.length===0)return i;const s=Object.keys(t);return this.children.forEach(o=>{n&&i.length>0||(o.node.type.name===e&&s.every(a=>t[a]===o.node.attrs[a])&&i.push(o),!(n&&i.length>0)&&(i=i.concat(o.querySelectorAll(e,t,n))))}),i}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}const dd=`.ProseMirror {
|
|
14
14
|
position: relative;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -84,10 +84,10 @@ img.ProseMirror-separator {
|
|
|
84
84
|
|
|
85
85
|
.tippy-box[data-animation=fade][data-state=hidden] {
|
|
86
86
|
opacity: 0
|
|
87
|
-
}`;function
|
|
87
|
+
}`;function fd(r,e,t){const n=document.querySelector("style[data-tiptap-style]");if(n!==null)return n;const i=document.createElement("style");return e&&i.setAttribute("nonce",e),i.setAttribute("data-tiptap-style",""),i.innerHTML=r,document.getElementsByTagName("head")[0].appendChild(i),i}class hd extends zc{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:t})=>{throw t},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:t,slice:n,moved:i})=>this.options.onDrop(t,n,i)),this.on("paste",({event:t,slice:n})=>this.options.onPaste(t,n)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=fd(dd,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const n=eo(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:n});return this.view.updateState(i),i}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let n=t;if([].concat(e).forEach(s=>{const o=typeof s=="string"?`${s}$`:s.key;n=t.filter(l=>!l.key.startsWith(o))}),t.length===n.length)return;const i=this.state.reconfigure({plugins:n});return this.view.updateState(i),i}createExtensionManager(){var e,t;const i=[...this.options.enableCoreExtensions?[sd,Xc.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),rd,ld,ad,ud,id,cd].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s==null?void 0:s.type));this.extensionManager=new ot(i,this)}createCommandManager(){this.commandManager=new Qt({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=mr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(o){if(!(o instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(o.message))throw o;this.emit("contentError",{editor:this,error:o,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(l=>l.name!=="collaboration"),this.createExtensionManager()}}),t=mr(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const n=co(t,this.options.autofocus);this.view=new sc(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...(e=this.options.editorProps)===null||e===void 0?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:Ze.create({doc:t,selection:n||void 0})});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews(),this.prependClass();const s=this.view.dom;s.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var l;return(l=this.capturedTransaction)===null||l===void 0?void 0:l.step(o)});return}const t=this.state.apply(e),n=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),n&&this.emit("selectionUpdate",{editor:this,transaction:e});const i=e.getMeta("focus"),s=e.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:e}),s&&this.emit("blur",{editor:this,event:s.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return qu(this.state,e)}isActive(e,t){const n=typeof e=="string"?e:null,i=typeof e=="string"?t:e;return Ku(this.state,n,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return dr(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
|
|
88
88
|
|
|
89
|
-
`,textSerializers:n={}}=e||{};return Ju(this.state.doc,{blockSeparator:t,textSerializers:{...so(this.schema),...n}})}get isEmpty(){return dn(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var n;return((n=this.$doc)===null||n===void 0?void 0:n.querySelector(e,t))||null}$nodes(e,t){var n;return((n=this.$doc)===null||n===void 0?void 0:n.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new Je(t,this)}get $doc(){return this.$pos(0)}}let xr=class Nr{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=N(x(this,"addOptions",{name:this.name}))),this.storage=N(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Nr(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>rn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Nr(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=N(x(t,"addOptions",{name:t.name})),t.storage=N(x(t,"addStorage",{name:t.name,options:t.options})),t}};var fn=200,$=function(){};$.prototype.append=function(e){return e.length?(e=$.from(e),!this.length&&e||e.length<fn&&this.leafAppend(e)||this.length<fn&&e.leafPrepend(this)||this.appendInner(e)):this},$.prototype.prepend=function(e){return e.length?$.from(e).append(this):this},$.prototype.appendInner=function(e){return new md(this,e)},$.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?$.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},$.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},$.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},$.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i},$.from=function(e){return e instanceof $?e:e&&e.length?new yo(e):$.empty};var yo=function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=fn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=fn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}($);$.empty=new yo([]);var md=function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(n,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(n,i):n>=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e}($);const gd=500;class le{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=[],u=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(n,f+1),s=i.maps.length),s--,u.push(d);return}if(i){u.push(new de(d.map));let h=d.step.map(i.slice(s)),p;h&&o.maybeStep(h).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new de(p,void 0,void 0,c.length+u.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,a=new le(this.items.slice(0,n).append(u.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 u=0;u<e.steps.length;u++){let d=e.steps[u].invert(e.docs[u]),f=new de(e.mapping.maps[u],d,t),h;(h=a&&a.merge(f))&&(f=h,u?s.pop():l=l.slice(0,l.length-1)),s.push(f),t&&(o++,t=void 0),i||(a=f)}let c=o-n.depth;return c>bd&&(l=yd(l,c),o-=c),new le(l.append(s),o)}remapping(e,t){let n=new dt;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 le(this.items.append(e.map(t=>new de(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(f=>{f.selection&&l--},i);let a=t;this.items.forEach(f=>{let h=s.getMirror(--a);if(h==null)return;o=Math.min(o,h);let p=s.maps[h];if(f.step){let m=e.steps[h].invert(e.docs[h]),g=f.selection&&f.selection.map(s.slice(a+1,h));g&&l++,n.push(new de(p,m,g))}else n.push(new de(p))},i);let c=[];for(let f=t;f<o;f++)c.push(new de(s.maps[f]));let u=this.items.slice(0,i).append(c).append(n),d=new le(u,l);return d.emptyItemCount()>gd&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),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 u=o.selection&&o.selection.map(t.slice(n));u&&s++;let d=new de(c.invert(),a,u),f,h=i.length-1;(f=i.length&&i[h].merge(d))?i[h]=f:i.push(d)}}else o.map&&n--},this.items.length,0),new le($.from(i.reverse()),s)}}le.empty=new le($.empty,0);function yd(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class de{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 de(t.getMap().invert(),t,this.selection)}}}class ve{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}}const bd=20;function kd(r,e,t,n){let i=t.getMeta(qe),s;if(i)return i.historyState;t.getMeta(Cd)&&(r=new ve(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(qe))return o.getMeta(qe).redo?new ve(r.done.addTransform(t,void 0,n,hn(e)),r.undone,bo(t.mapping.maps),r.prevTime,r.prevComposition):new ve(r.done,r.undone.addTransform(t,void 0,n,hn(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||!xd(t,r.prevRanges)),c=o?Sr(r.prevRanges,t.mapping):bo(t.mapping.maps);return new ve(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,hn(e)),le.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ve(r.done.rebased(t,s),r.undone.rebased(t,s),Sr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ve(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Sr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function xd(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 bo(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 Sr(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 Sd(r,e,t){let n=hn(e),i=qe.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 ve(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(qe,{redo:t,historyState:a})}let Cr=!1,ko=null;function hn(r){let e=r.plugins;if(ko!=e){Cr=!1,ko=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Cr=!0;break}}return Cr}const qe=new se("history"),Cd=new se("closeHistory");function wd(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new Q({key:qe,state:{init(){return new ve(le.empty,le.empty,null,0,-1)},apply(e,t,n){return kd(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?So:n=="historyRedo"?Co:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function xo(r,e){return(t,n)=>{let i=qe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=Sd(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}const So=xo(!1,!0),Co=xo(!0,!0),Md=Y.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:r,dispatch:e})=>So(r,e),redo:()=>({state:r,dispatch:e})=>Co(r,e)}},addProseMirrorPlugins(){return[wd(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Ed=Y.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new Q({key:new se("placeholder"),props:{decorations:({doc:r,selection:e})=>{const t=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:n}=e,i=[];if(!t)return null;const s=this.editor.isEmpty;return r.descendants((o,l)=>{const a=n>=l&&n<=l+o.nodeSize,c=!o.isLeaf&&dn(o);if((a||!this.options.showOnlyCurrent)&&c){const u=[this.options.emptyNodeClass];s&&u.push(this.options.emptyEditorClass);const d=re.node(l,l+o.nodeSize,{class:u.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:o,pos:l,hasAnchor:a}):this.options.placeholder});i.push(d)}return this.options.includeChildren}),z.create(r,i)}}})]}});function wo(r){const t=r.state.doc.toJSON(),n=new Td(r);let i=[];return t.content.forEach(s=>{i.push(n.serialize(s))}),i.join(`
|
|
90
|
-
`)}function Mo(r,e){return r.type===e.type&&JSON.stringify(r.attrs)===JSON.stringify(e.attrs)}class Td{constructor(e){this.editor=e,this.openMarks=[]}serialize(e){if(e.type==="text"){let s="";return this.openMarks.forEach((o,l)=>{let a=!1;if(e.marks&&(a=e.marks.find(c=>Mo(c,o))),!a){const c=o.type.replace("tei-","");s+=`</${c}>`,this.openMarks.splice(l,1)}}),s+=e.text,e.marks&&e.marks.length>0&&e.marks.forEach(o=>{if(!this.openMarks.find(a=>Mo(o,a))){const a=o.type,c=o.attrs?Object.entries(o.attrs).filter(([u,d])=>d!==null).map(([u,d])=>`${u}="${d}"`).join(" "):"";s=`<${a}${c?" "+c:""}>${s}`,this.openMarks.unshift(o)}}),s}const t=e.type,n=e.attrs?Object.entries(e.attrs).filter(([s,o])=>o!==null&&!s.startsWith("_")).map(([s,o])=>s==="id"?`xml:id="${o}"`:`${s}="${o}"`).join(" "):"",i=e.content?e.content.map(s=>this.serialize(s)).join(""):"";return i?`<${t}${n?" "+n:""}>${i}${this.closeMarks()}</${t}>`:`<${t}${n?" "+n:""}/>`}closeMarks(){let e="";return this.openMarks.forEach(t=>{const n=t.type;e+=`</${n}>`}),this.openMarks=[],e}}const Od=xr.create({name:"doc",topNode:!0,content:"block+"}),Nd=xr.create({name:"text",group:"inline"}),Ad=Et.create({name:"inline",addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{}}},parseHTML(){return[{tag:this.options.tag}]},renderHTML({HTMLAttributes:r}){return this.name==="ref"?[this.options.tag,{...r,role:"link",tabindex:"0",onclick:"window.open(this.getAttribute('target'), '_blank', 'noopener,noreferrer')",onkeypress:"if(event.key === 'Enter') window.open(this.getAttribute('target'), '_blank', 'noopener,noreferrer')",rel:"noopener noreferrer"},0]:[this.options.tag,r,0]},addAttributes(){const r={};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{r[e]=()=>this.editor.commands.toggleMark(this.name,t.attributes)}),r},addCommands(){return{[`toggle${this.name.charAt(0).toUpperCase()+this.name.slice(1)}`]:()=>({commands:r,attributes:e})=>r.toggleMark(this.name,e)}}}),pn=xr.create({name:"block",group:"block",content:"inline*",addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{}}},parseHTML(){return[{tag:this.options.tag}]},renderHTML({HTMLAttributes:r}){return[this.options.tag,r,0]},addAttributes(){const r={};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{t.command?r[e]=()=>this.editor.commands[t.command](this.name,t.attributes):r[e]=()=>this.editor.commands.setNode(this.name,t.attributes)}),r},addCommands(){const r=this.name.charAt(0).toUpperCase()+this.name.slice(1);return{[`set${r}`]:()=>({commands:e,attributes:t})=>e.setNode(this.name,t),[`wrap${r}`]:()=>({commands:e,attributes:t})=>e.wrapIn(this.name,t),[`lift${r}`]:()=>({commands:e,attributes:t})=>e.lift(this.name,t)}}}),vd=pn.extend({name:"list",content:"head? item+",group:"block",defining:!0,inline:!1,addCommands(){return{[`toggle${this.name.charAt(0).toUpperCase()+this.name.slice(1)}`]:e=>({commands:t,editor:n})=>{const{state:i}=n,{selection:s}=i,{$from:o}=s;return Ot(o,a=>a.type.name===this.name)?t.liftListItem(this.name):t.wrapInList(this.name,e)},transformToHead:()=>({commands:e,state:t,tr:n})=>{const{selection:i}=t,{$from:s}=i,o=Ot(s,d=>d.type.name==="item");if(!o)return!1;const l=Ot(s,d=>d.type.name==="list");if(!l||!(l.node.firstChild===o.node))return!1;const c=o.node.firstChild;if(!c)return!1;const u=t.schema.nodes.head.create({},c.content);return n.replaceWith(o.pos,o.pos+o.node.nodeSize,u),!0}}},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{const n=this.name.charAt(0).toUpperCase()+this.name.slice(1);r[e]=()=>this.editor.commands[`toggle${n}`](this.name)}),r}}),Dd=pn.extend({name:"item",content:"p block*",group:"item",defining:!1,addKeyboardShortcuts(){return{Enter:()=>{const{state:r}=this.editor,{selection:e}=r,{$from:t}=e,n=t.node();return t.parentOffset===0&&n.content.size===0?this.editor.commands.liftListItem(this.name):this.editor.commands.splitListItem(this.name)},Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name),"Mod-Alt-1":()=>this.editor.commands.transformToHead()}}});function Eo(r){return Object.entries(r||{}).map(([e,t])=>`${e}="${t}"`).join(" ")}const To=pn.extend({name:"emptyElement",group:"inline",content:"",inline:!0,addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{},label:"Empty Element"}},parseHTML(){return[{tag:this.options.tag}]},addNodeView(){return({node:r})=>{const e=document.createElement(`tei-${this.name}`);e.classList.add("empty-element"),e.innerHTML=this.options.label;const t=Eo(r.attrs);return t&&e.setAttribute("data-tooltip",t),Object.entries(r.attrs).forEach(([n,i])=>{i&&e.setAttribute(n,i)}),e.addEventListener("click",()=>{this.editor.options.element.dispatchEvent(new CustomEvent("empty-element-clicked",{detail:{node:r}}))}),{dom:e,update:n=>{if(n.type!==r.type)return!1;r.attrs=n.attrs;const i=Eo(n.attrs);return i&&e.setAttribute("data-tooltip",i),Object.entries(r.attrs).forEach(([s,o])=>{o?e.setAttribute(s,o):e.removeAttribute(s)}),!0}}}},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{r[e]=()=>this.editor.commands.insertContent({type:this.name,attrs:t.attributes})}),r}});function Oo(){const r=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`fn-${r}-${e}`}const wr=new Map;function Id(r){const e=[];return r.nodesBetween(0,r.content.size,(t,n)=>{t.type.name==="anchor"&&e.push({node:t,pos:n})}),e.sort((t,n)=>t.pos-n.pos),wr.clear(),e.forEach((t,n)=>{const i=n+1;wr.set(t.node.attrs.id,i)}),e}function Nt(r){return wr.get(r)||-1}function Pd(r,e){return e.nodesBetween(0,e.content.size,(t,n)=>{if(t.type.name==="note"){const i=t.attrs.target;if(i&&i.startsWith("#")){const s=i.substring(1),o=Nt(s);o>0&&(r=r.setNodeMarkup(n,null,{...t.attrs,_reference:o.toString(),_timestamp:Date.now()}))}}}),r}function Rd(r,e,t=null){let n=null;if(e.descendants((c,u)=>{if(c.type.name==="noteGrp")return n=u,!1}),n===null)return r;const i=e.nodeAt(n);if(!i)return r;const s=[];let o=-1;i.content.forEach((c,u)=>{if(c.type.name==="note"){const d=c.attrs.target;if(d&&d.startsWith("#")){const f=d.substring(1),h=Nt(f);s.push({node:c,reference:h,originalIndex:s.length}),t&&d===`#${t}`&&(o=s.length-1)}}}),s.sort((c,u)=>c.reference-u.reference);let l=-1;o!==-1&&(l=s.findIndex(c=>c.originalIndex===o));const a=i.type.create(i.attrs,s.map(c=>c.node));if(r=r.replaceWith(n,n+i.nodeSize,a),l!==-1){let u=n+1;for(let d=0;d<l;d++){const f=r.doc.nodeAt(u);f&&(u+=f.nodeSize)}r=r.setSelection(E.create(r.doc,u+1))}return r}function Bd(r,e){const t=Date.now();return e.nodesBetween(0,e.content.size,(n,i)=>{if(n.type.name==="anchor"){const s=Nt(n.attrs.id),o=`${t}-${i}`;r=r.setNodeMarkup(i,null,{...n.attrs,_timestamp:o,_reference:s})}}),r}const zd=To.extend({name:"anchor",group:"inline",content:"",inline:!0,atom:!0,addAttributes(){const r={id:{isRequired:!0,type:"string",renderHTML(e){return{id:e.id}},parseHTML(e){return e.getAttribute("id")||Oo()}},_timestamp:{default:null,renderHTML:()=>({})},_reference:{default:null,renderHTML:()=>({})}};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addCommands(){return{addAnchor:r=>({commands:e})=>e.insertContent({type:this.name,attrs:{...r,id:Oo()}}),gotoNote:r=>({commands:e,editor:t})=>{const n=`tei-note[target="#${r}"]`,i=t.view.dom.querySelector(n);if(i){i.scrollIntoView({behavior:"smooth",block:"center"});const s=this.editor.view.posAtDOM(i,0);return e.setTextSelection(s),!0}return!1}}},addNodeView(){return({node:r,editor:e})=>{const t=document.createElement(`tei-${this.name}`);Object.entries(r.attrs).forEach(([i,s])=>{s&&t.setAttribute(i,s)});const n=Nt(r.attrs.id);return t.textContent=n>0?n.toString():"",t.addEventListener("click",()=>{e.commands.gotoNote(r.attrs.id)}),{dom:t,update:i=>{if(i.type!==r.type)return!1;Object.entries(i.attrs).forEach(([o,l])=>{l?t.setAttribute(o,l):t.removeAttribute(o)});const s=Nt(i.attrs.id);return t.textContent=s>0?s.toString():"",!0}}}}}),Fd=Y.create({name:"footnoteRules",priority:1e3,addProseMirrorPlugins(){return[new Q({key:new se("footnoteRules"),appendTransaction(r,e,t){let n=t.tr,i=null,s=!1,o=new Set;if(r.some(a=>a.steps.some(c=>c instanceof B?c.from===0&&c.to===e.doc.content.size:!1)))s=!0;else for(let a of r)if(a.docChanged)for(let c of a.steps){if(!(c instanceof B))continue;c.slice.size>0&&c.slice.content.descendants((m,g)=>{if((m==null?void 0:m.type.name)=="anchor")return i=m.attrs.id,s=!0,!1});const d=a.docs[0],f=a.doc,h=new Map,p=new Map;d.descendants((m,g)=>{m.type.name==="anchor"&&h.set(m.attrs.id,g)}),f.descendants((m,g)=>{m.type.name==="anchor"&&p.set(m.attrs.id,g)});for(const[m,g]of h)p.has(m)||(o.add(m),s=!0);(h.size!==p.size||Array.from(h.entries()).some(([m,g])=>p.get(m)!==g))&&(s=!0)}if(o.size>0&&t.doc.descendants((a,c)=>{if(a.type.name==="note"){const u=a.attrs.target;if(u&&u.startsWith("#")){const d=u.substring(1);o.has(d)&&(n=n.delete(c,c+a.nodeSize))}}}),i){let a=!1;if(t.doc.descendants((m,g)=>{if(m.type.name==="note"&&m.attrs.target===`#${i}`)return console.log("note found",m),a=!0,!1}),a)return null;let c=null;t.doc.descendants((m,g)=>{if(m.type.name==="noteGrp")return c=g,!1}),c===null&&(c=t.doc.content.size,n=n.insert(c,t.schema.nodes.noteGrp.create()));const u=n.doc.nodeAt(c);if(!u)return null;const d=t.schema.nodes.note.create({target:`#${i}`,_reference:"1"}),f=c+u.nodeSize-1;n=n.insert(f,d);const h=f;n.doc.nodeAt(h)&&(n=n.setSelection(E.create(n.doc,h+1)))}return s&&(Id(n.doc),n=Bd(n,n.doc),n=Pd(n,n.doc),n=Rd(n,n.doc,i)),n}})]}});function Ld(r){const e=[$d,Nd];return Object.entries(r.schema).forEach(([t,n])=>{let i;n.type==="inline"?i=Ad.extend({name:t}):n.type==="anchor"?i=zd.extend({name:t}):n.type==="empty"?i=To.extend({name:t}):n.type==="list"?i=vd.extend({name:t,content:n.content||"item+"}):n.type==="listItem"?i=Dd.extend({name:t,content:n.content||"p block*"}):n.type==="block"&&(i=pn.extend({name:t,group:n.group||"block",defining:n.defining,isolating:n.isolating,priority:n.priority,inline:n.inline,content:n.content}));const s={...r.attributes,...n.attributes};e.push(i.configure({shortcuts:n.keyboard,attributes:s,label:n.label}))}),e}const $d=Od.extend({content:"block+ noteGrp?"});function No(r,e,t){let n=null;return r.state.doc.nodesBetween(e,t,(i,s,o,l)=>{i.isText&&(n==null?n=i.marks.map(a=>({mark:a,pos:s})):n=n.filter(a=>i.marks.find(c=>c.type.name===a.mark.type.name)))}),n&&(n=n.map(i=>{const s=r.state.doc.resolve(i.pos),o=hr(s,i.mark.type,i.mark.attrs);return i.text=r.state.doc.textBetween(o.from,o.to,""," "),i}),n.sort((i,s)=>{var o,l;return(((o=s.text)==null?void 0:o.length)||0)-(((l=i.text)==null?void 0:l.length)||0)})),n}function Vd(r,e=[]){const t={},n=[];return r.state.doc.nodesBetween(0,r.state.doc.content.size,(i,s)=>{i.isText&&e.forEach(o=>{const l=i.text.indexOf(o);if(l!==-1){const a={pos:s,index:l,length:o.length};n.some(u=>u.pos<=a.pos&&u.pos+u.index+u.length>=a.pos+a.index+a.length)||(t[o]=[...t[o]||[],a],n.push(a))}})}),t}function jd(r){const t=new DOMParser().parseFromString(r,"application/xml"),n=t.querySelector("parsererror");return n?(console.error("XML Parsing Error:",n.textContent),null):t}function Wd(r){if(!r)return"";const e=[],t=r.querySelectorAll("text > body > *"),n=i=>{if(i.nodeType===Node.ELEMENT_NODE){const s=document.createElement(`tei-${i.tagName}`);for(const o of i.attributes)o.name==="xml:id"?s.setAttribute("id",o.value):s.setAttribute(o.name,o.value);for(const o of i.childNodes)s.appendChild(n(o));return s}else return i.cloneNode()};return t.forEach(i=>{const s=n(i);e.push(s.outerHTML)}),e.join("")}function Hd(r){const e=jd(r);return e.documentElement.namespaceURI==="http://www.tei-c.org/ns/1.0"?Wd(e):xml}function Jd(r,e,t,n=3){let i=e-1,s=0;for(;i>=0;){if(/[\p{P}\s]/.test(r.charAt(i))){for(;i>1&&/[\p{P}\s]/.test(r.charAt(i-1));)i-=1;if(s+=1,s===n)break}i-=1}let o=t+1;for(s=0;o<r.length;){if(/[\p{P}\s]/.test(r.charAt(o))){for(;o<r.length-1&&/[\p{P}\s]/.test(r.charAt(o+1));)o+=1;if(s+=1,s===n)break}o+=1}return`… ${r.substring(i,e)}<mark>${r.substring(e,t)}</mark>${r.substring(t,o+1)} …`}class qd{constructor(e,t){this.editor=e.tiptap,this.schemaDef=t,this.panel=e.querySelector(".attribute-panel"),this.currentElement=null,this.currentMark=null,this.setupEventListeners(),this.overlay=document.createElement("div"),this.overlay.className="jinn-tap overlay",this.overlay.style.display="block",this.overlay.style.position="fixed",this.overlay.style.pointerEvents="none",this.overlay.style.zIndex="1000",this.overlay.style.display="none"}setupEventListeners(){this.editor.on("selectionUpdate",({editor:e})=>{this.updatePanelForCurrentPosition(e)}),this.editor.on("update",({editor:e})=>{this.updatePanelForCurrentPosition(e)}),this.editor.options.element.addEventListener("empty-element-clicked",({detail:e})=>{this.showNodeAttributes(e.node)})}updatePanelForCurrentPosition(e){var l;const{from:t,to:n}=e.state.selection,i=No(e,t,n);if(i&&i.length>0){this.currentElement=null;const a=i[i.length-1];((l=this.currentMark)==null?void 0:l.mark)!=a.mark&&this.showMarkAttributes(a.mark,a.text),this.currentMark=a;return}const o=e.state.doc.resolve(t).node();if(this.currentMark=null,o&&Object.keys(this.schemaDef.schema).includes(o.type.name)){if(this.currentElement==o)return;this.currentElement=o,this.currentAttributes={...o.attrs},this.showNodeAttributes(o)}else this.currentElement=null,this.currentAttributes={},this.hidePanel()}showMarkAttributes(e,t){this.updatePanel(e,t)}showNodeAttributes(e){this.updatePanel(e)}hidePanel(){this.updatePanel()}createAttributeInput(e,t,n,i,s=""){const o=document.createElement("label");o.textContent=t;let l;return n.enum?(l=document.createElement("select"),n.enum.forEach(a=>{const c=document.createElement("option");c.value=a,c.textContent=a,l.appendChild(c)})):(l=document.createElement("input"),l.type="text"),l.placeholder=s,l.value=i||n.default||"",l.name=t,o.appendChild(l),e.appendChild(o),l}updatePanel(e,t){if(!this.panel)return;if(this.panel.innerHTML="",!e){this.panel.innerHTML="<p>Select text or a node to edit attributes</p>";return}const n=this.schemaDef.schema[e.type.name];if(!n){this.panel.innerHTML="";return}const i=document.createElement("h4");i.textContent=e.type.name,this.panel.appendChild(i);const s=document.createElement("div");this.panel.appendChild(s);const o=document.createElement("form");this.panel.appendChild(o);const l={...this.schemaDef.attributes,...n.attributes};if(Object.entries(l).forEach(([a,c])=>{if(!a.startsWith("_"))if(c.connector){const u=this.createAttributeInput(o,a,c,e.attrs[a],"No reference assigned");u.readOnly=!0;const d=document.createElement("details");d.open=!e.attrs[a];const f=document.createElement("summary");f.textContent="Lookup",d.appendChild(f);const h=document.createElement("pb-authority-lookup");h.setAttribute("type",c.connector.type),h.setAttribute("query",t),h.setAttribute("auto",e.attrs[a]?"true":"false"),h.setAttribute("no-occurrences",!0);const p=document.createElement("pb-authority");if(p.setAttribute("connector",c.connector.name),p.setAttribute("name",c.connector.type),c.connector.user&&p.setAttribute("user",c.connector.user),h.appendChild(p),document.addEventListener("pb-authority-select",m=>{const g=`${c.connector.prefix}-${m.detail.properties.ref}`;u.value=g,d.open=!1,this.handleAttributeUpdate(e,{[a]:g})}),d.appendChild(h),o.appendChild(d),e.attrs[a]){const m=e.attrs[a].substring(e.attrs[a].indexOf("-")+1);h.lookup(c.connector.type,m,s).then(g=>{const y=g.strings;y.sort((S,w)=>w.length-S.length),y.unshift(t),this.updateOccurrences(this.editor,e,y)})}}else this.createAttributeInput(o,a,c,e.attrs[a])}),Object.keys(l).length>0&&!(Object.keys(l).length===1&&l[Object.keys(l)[0]].connector)){const a=document.createElement("button");a.dataset.tooltip="Apply Changes",a.type="submit",a.innerHTML='<i class="bi bi-check-all"></i>',a.addEventListener("click",c=>{c.preventDefault(),this.handleAttributeUpdate(e)}),this.panel.appendChild(a)}}handleAttributeUpdate(e,t={}){const n=new FormData(this.panel.querySelector("form")),i=[];for(const[l,a]of n.entries())a!==""?t[l]=a:i.push(l);console.log("<jinn-tap> pendingChanges: %o, cleared: %o",t,i);const{from:s,to:o}=this.editor.state.selection;this.editor.chain().focus().extendMarkRange(e.type).run(),i.length>0&&this.editor.commands.resetAttributes(e.type,i),Object.keys(t).length>0&&this.editor.chain().focus().updateAttributes(e.type,t).setTextSelection({from:s,to:o}).run()}updateOccurrences(e,t,n){const i=Vd(e,n),s=document.createElement("div");s.classList.add("occurrences"),s.innerHTML=`
|
|
89
|
+
`,textSerializers:n={}}=e||{};return Hu(this.state.doc,{blockSeparator:t,textSerializers:{...so(this.schema),...n}})}get isEmpty(){return dn(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var n;return((n=this.$doc)===null||n===void 0?void 0:n.querySelector(e,t))||null}$nodes(e,t){var n;return((n=this.$doc)===null||n===void 0?void 0:n.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new Je(t,this)}get $doc(){return this.$pos(0)}}let xr=class Nr{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=N(x(this,"addOptions",{name:this.name}))),this.storage=N(x(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Nr(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>rn(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Nr(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=N(x(t,"addOptions",{name:t.name})),t.storage=N(x(t,"addStorage",{name:t.name,options:t.options})),t}};var fn=200,$=function(){};$.prototype.append=function(e){return e.length?(e=$.from(e),!this.length&&e||e.length<fn&&this.leafAppend(e)||this.length<fn&&e.leafPrepend(this)||this.appendInner(e)):this},$.prototype.prepend=function(e){return e.length?$.from(e).append(this):this},$.prototype.appendInner=function(e){return new pd(this,e)},$.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?$.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},$.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},$.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},$.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,n),i},$.from=function(e){return e instanceof $?e:e&&e.length?new yo(e):$.empty};var yo=function(r){function e(n){r.call(this),this.values=n}r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=fn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=fn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}($);$.empty=new yo([]);var pd=function(r){function e(t,n){r.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return r&&(e.__proto__=r),e.prototype=Object.create(r&&r.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},e.prototype.forEachInner=function(n,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(n,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(n,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(n,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(n,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(n,i){if(n==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(n,i):n>=s?this.right.slice(n-s,i-s):this.left.slice(n,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e}($);const md=500;class le{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=[],u=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(n,f+1),s=i.maps.length),s--,u.push(d);return}if(i){u.push(new de(d.map));let h=d.step.map(i.slice(s)),p;h&&o.maybeStep(h).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new de(p,void 0,void 0,c.length+u.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,a=new le(this.items.slice(0,n).append(u.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 u=0;u<e.steps.length;u++){let d=e.steps[u].invert(e.docs[u]),f=new de(e.mapping.maps[u],d,t),h;(h=a&&a.merge(f))&&(f=h,u?s.pop():l=l.slice(0,l.length-1)),s.push(f),t&&(o++,t=void 0),i||(a=f)}let c=o-n.depth;return c>yd&&(l=gd(l,c),o-=c),new le(l.append(s),o)}remapping(e,t){let n=new dt;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 le(this.items.append(e.map(t=>new de(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(f=>{f.selection&&l--},i);let a=t;this.items.forEach(f=>{let h=s.getMirror(--a);if(h==null)return;o=Math.min(o,h);let p=s.maps[h];if(f.step){let m=e.steps[h].invert(e.docs[h]),g=f.selection&&f.selection.map(s.slice(a+1,h));g&&l++,n.push(new de(p,m,g))}else n.push(new de(p))},i);let c=[];for(let f=t;f<o;f++)c.push(new de(s.maps[f]));let u=this.items.slice(0,i).append(c).append(n),d=new le(u,l);return d.emptyItemCount()>md&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),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 u=o.selection&&o.selection.map(t.slice(n));u&&s++;let d=new de(c.invert(),a,u),f,h=i.length-1;(f=i.length&&i[h].merge(d))?i[h]=f:i.push(d)}}else o.map&&n--},this.items.length,0),new le($.from(i.reverse()),s)}}le.empty=new le($.empty,0);function gd(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class de{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 de(t.getMap().invert(),t,this.selection)}}}class ve{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}}const yd=20;function bd(r,e,t,n){let i=t.getMeta(qe),s;if(i)return i.historyState;t.getMeta(Sd)&&(r=new ve(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(qe))return o.getMeta(qe).redo?new ve(r.done.addTransform(t,void 0,n,hn(e)),r.undone,bo(t.mapping.maps),r.prevTime,r.prevComposition):new ve(r.done,r.undone.addTransform(t,void 0,n,hn(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||!kd(t,r.prevRanges)),c=o?Sr(r.prevRanges,t.mapping):bo(t.mapping.maps);return new ve(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,hn(e)),le.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ve(r.done.rebased(t,s),r.undone.rebased(t,s),Sr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ve(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Sr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function kd(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 bo(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 Sr(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 xd(r,e,t){let n=hn(e),i=qe.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 ve(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(qe,{redo:t,historyState:a})}let Cr=!1,ko=null;function hn(r){let e=r.plugins;if(ko!=e){Cr=!1,ko=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Cr=!0;break}}return Cr}const qe=new se("history"),Sd=new se("closeHistory");function Cd(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new Q({key:qe,state:{init(){return new ve(le.empty,le.empty,null,0,-1)},apply(e,t,n){return bd(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?So:n=="historyRedo"?Co:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function xo(r,e){return(t,n)=>{let i=qe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=xd(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}const So=xo(!1,!0),Co=xo(!0,!0),wd=Y.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:r,dispatch:e})=>So(r,e),redo:()=>({state:r,dispatch:e})=>Co(r,e)}},addProseMirrorPlugins(){return[Cd(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Md=Y.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new Q({key:new se("placeholder"),props:{decorations:({doc:r,selection:e})=>{const t=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:n}=e,i=[];if(!t)return null;const s=this.editor.isEmpty;return r.descendants((o,l)=>{const a=n>=l&&n<=l+o.nodeSize,c=!o.isLeaf&&dn(o);if((a||!this.options.showOnlyCurrent)&&c){const u=[this.options.emptyNodeClass];s&&u.push(this.options.emptyEditorClass);const d=re.node(l,l+o.nodeSize,{class:u.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:o,pos:l,hasAnchor:a}):this.options.placeholder});i.push(d)}return this.options.includeChildren}),z.create(r,i)}}})]}});function wo(r){const t=r.state.doc.toJSON(),n=new Ed(r);let i=[];return t.content.forEach(s=>{i.push(n.serialize(s))}),i.join(`
|
|
90
|
+
`)}function Mo(r,e){return r.type===e.type&&JSON.stringify(r.attrs)===JSON.stringify(e.attrs)}class Ed{constructor(e){this.editor=e,this.openMarks=[]}serialize(e){if(e.type==="text"){let s="";return this.openMarks.forEach((o,l)=>{let a=!1;if(e.marks&&(a=e.marks.find(c=>Mo(c,o))),!a){const c=o.type.replace("tei-","");s+=`</${c}>`,this.openMarks.splice(l,1)}}),s+=e.text,e.marks&&e.marks.length>0&&e.marks.forEach(o=>{if(!this.openMarks.find(a=>Mo(o,a))){const a=o.type,c=o.attrs?Object.entries(o.attrs).filter(([u,d])=>d!==null).map(([u,d])=>`${u}="${d}"`).join(" "):"";s=`<${a}${c?" "+c:""}>${s}`,this.openMarks.unshift(o)}}),s}const t=e.type,n=e.attrs?Object.entries(e.attrs).filter(([s,o])=>o!==null&&!s.startsWith("_")).map(([s,o])=>s==="id"?`xml:id="${o}"`:`${s}="${o}"`).join(" "):"",i=e.content?e.content.map(s=>this.serialize(s)).join(""):"";return i?`<${t}${n?" "+n:""}>${i}${this.closeMarks()}</${t}>`:`<${t}${n?" "+n:""}/>`}closeMarks(){let e="";return this.openMarks.forEach(t=>{const n=t.type;e+=`</${n}>`}),this.openMarks=[],e}}const Td=xr.create({name:"doc",topNode:!0,content:"block+"}),Od=xr.create({name:"text",group:"inline"}),Nd=Et.create({name:"inline",addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{}}},parseHTML(){return[{tag:this.options.tag}]},renderHTML({HTMLAttributes:r}){return this.name==="ref"?[this.options.tag,{...r,role:"link",tabindex:"0",onclick:"window.open(this.getAttribute('target'), '_blank', 'noopener,noreferrer')",onkeypress:"if(event.key === 'Enter') window.open(this.getAttribute('target'), '_blank', 'noopener,noreferrer')",rel:"noopener noreferrer"},0]:[this.options.tag,r,0]},addAttributes(){const r={};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{r[e]=()=>this.editor.commands.toggleMark(this.name,t.attributes)}),r},addCommands(){return{[`toggle${this.name.charAt(0).toUpperCase()+this.name.slice(1)}`]:()=>({commands:r,attributes:e})=>r.toggleMark(this.name,e)}}}),pn=xr.create({name:"block",group:"block",content:"inline*",addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{}}},parseHTML(){return[{tag:this.options.tag}]},renderHTML({HTMLAttributes:r}){return[this.options.tag,r,0]},addAttributes(){const r={};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{t.command?r[e]=()=>this.editor.commands[t.command](this.name,t.attributes):r[e]=()=>this.editor.commands.setNode(this.name,t.attributes)}),r},addCommands(){const r=this.name.charAt(0).toUpperCase()+this.name.slice(1);return{[`set${r}`]:()=>({commands:e,attributes:t})=>e.setNode(this.name,t),[`wrap${r}`]:()=>({commands:e,attributes:t})=>e.wrapIn(this.name,t),[`lift${r}`]:()=>({commands:e,attributes:t})=>e.lift(this.name,t)}}}),Ad=pn.extend({name:"list",content:"head? item+",group:"block",defining:!0,inline:!1,addCommands(){return{[`toggle${this.name.charAt(0).toUpperCase()+this.name.slice(1)}`]:e=>({commands:t,editor:n})=>{const{state:i}=n,{selection:s}=i,{$from:o}=s;return Ot(o,a=>a.type.name===this.name)?t.liftListItem(this.name):t.wrapInList(this.name,e)},transformToHead:()=>({commands:e,state:t,tr:n})=>{const{selection:i}=t,{$from:s}=i,o=Ot(s,d=>d.type.name==="item");if(!o)return!1;const l=Ot(s,d=>d.type.name==="list");if(!l||!(l.node.firstChild===o.node))return!1;const c=o.node.firstChild;if(!c)return!1;const u=t.schema.nodes.head.create({},c.content);return n.replaceWith(o.pos,o.pos+o.node.nodeSize,u),!0}}},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{const n=this.name.charAt(0).toUpperCase()+this.name.slice(1);r[e]=()=>this.editor.commands[`toggle${n}`](this.name)}),r}}),vd=pn.extend({name:"item",content:"p block*",group:"item",defining:!1,addKeyboardShortcuts(){return{Enter:()=>{const{state:r}=this.editor,{selection:e}=r,{$from:t}=e,n=t.node();return t.parentOffset===0&&n.content.size===0?this.editor.commands.liftListItem(this.name):this.editor.commands.splitListItem(this.name)},Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name),"Mod-Alt-1":()=>this.editor.commands.transformToHead()}}});function Dd(r){return Object.entries(r||{}).map(([e,t])=>`${e}="${t}"`).join(" ")}const Eo=pn.extend({name:"emptyElement",group:"inline",content:"",inline:!0,addOptions(){return{tag:`tei-${this.name}`,shortcuts:{},attributes:{},label:"Empty Element"}},parseHTML(){return[{tag:this.options.tag}]},addNodeView(){return({node:r})=>{const e=document.createElement(`tei-${this.name}`);return e.classList.add("empty-element"),e.innerHTML=this.options.label,Object.entries(r.attrs).forEach(([t,n])=>{n&&e.setAttribute(t,n)}),e.addEventListener("click",()=>{this.editor.options.element.dispatchEvent(new CustomEvent("empty-element-clicked",{detail:{node:r}}))}),{dom:e,update:t=>{if(t.type!==r.type)return!1;r.attrs=t.attrs;const n=Dd(t.attrs);return n&&e.setAttribute("data-tooltip",n),Object.entries(r.attrs).forEach(([i,s])=>{s?e.setAttribute(i,s):e.removeAttribute(i)}),!0}}}},addKeyboardShortcuts(){const r={};return this.options.shortcuts&&Object.entries(this.options.shortcuts).forEach(([e,t])=>{r[e]=()=>this.editor.commands.insertContent({type:this.name,attrs:t.attributes})}),r}});function To(){const r=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`fn-${r}-${e}`}const wr=new Map;function Id(r){const e=[];return r.nodesBetween(0,r.content.size,(t,n)=>{t.type.name==="anchor"&&e.push({node:t,pos:n})}),e.sort((t,n)=>t.pos-n.pos),wr.clear(),e.forEach((t,n)=>{const i=n+1;wr.set(t.node.attrs.id,i)}),e}function Nt(r){return wr.get(r)||-1}function Pd(r,e){return e.nodesBetween(0,e.content.size,(t,n)=>{if(t.type.name==="note"){const i=t.attrs.target;if(i&&i.startsWith("#")){const s=i.substring(1),o=Nt(s);o>0&&(r=r.setNodeMarkup(n,null,{...t.attrs,_reference:o.toString(),_timestamp:Date.now()}))}}}),r}function Rd(r,e,t=null){let n=null;if(e.descendants((c,u)=>{if(c.type.name==="noteGrp")return n=u,!1}),n===null)return r;const i=e.nodeAt(n);if(!i)return r;const s=[];let o=-1;i.content.forEach((c,u)=>{if(c.type.name==="note"){const d=c.attrs.target;if(d&&d.startsWith("#")){const f=d.substring(1),h=Nt(f);s.push({node:c,reference:h,originalIndex:s.length}),t&&d===`#${t}`&&(o=s.length-1)}}}),s.sort((c,u)=>c.reference-u.reference);let l=-1;o!==-1&&(l=s.findIndex(c=>c.originalIndex===o));const a=i.type.create(i.attrs,s.map(c=>c.node));if(r=r.replaceWith(n,n+i.nodeSize,a),l!==-1){let u=n+1;for(let d=0;d<l;d++){const f=r.doc.nodeAt(u);f&&(u+=f.nodeSize)}r=r.setSelection(E.create(r.doc,u+1))}return r}function Bd(r,e){const t=Date.now();return e.nodesBetween(0,e.content.size,(n,i)=>{if(n.type.name==="anchor"){const s=Nt(n.attrs.id),o=`${t}-${i}`;r=r.setNodeMarkup(i,null,{...n.attrs,_timestamp:o,_reference:s})}}),r}const zd=Eo.extend({name:"anchor",group:"inline",content:"",inline:!0,atom:!0,addAttributes(){const r={id:{isRequired:!0,type:"string",renderHTML(e){return{id:e.id}},parseHTML(e){return e.getAttribute("id")||To()}},_timestamp:{default:null,renderHTML:()=>({})},_reference:{default:null,renderHTML:()=>({})}};return this.options.attributes&&Object.entries(this.options.attributes).forEach(([e,t])=>{r[e]={default:t.default||null,parseHTML:n=>n.getAttribute(e),renderHTML:n=>n[e]?{[e]:n[e]}:{}}}),r},addCommands(){return{addAnchor:r=>({commands:e})=>e.insertContent({type:this.name,attrs:{...r,id:To()}}),gotoNote:r=>({commands:e,editor:t})=>{const n=`tei-note[target="#${r}"]`,i=t.view.dom.querySelector(n);if(i){i.scrollIntoView({behavior:"smooth",block:"center"});const s=this.editor.view.posAtDOM(i,0);return e.setTextSelection(s),!0}return!1}}},addNodeView(){return({node:r,editor:e})=>{const t=document.createElement(`tei-${this.name}`);Object.entries(r.attrs).forEach(([i,s])=>{s&&t.setAttribute(i,s)});const n=Nt(r.attrs.id);return t.textContent=n>0?n.toString():"",t.addEventListener("click",()=>{e.commands.gotoNote(r.attrs.id)}),{dom:t,update:i=>{if(i.type!==r.type)return!1;Object.entries(i.attrs).forEach(([o,l])=>{l?t.setAttribute(o,l):t.removeAttribute(o)});const s=Nt(i.attrs.id);return t.textContent=s>0?s.toString():"",!0}}}}}),Fd=Y.create({name:"footnoteRules",priority:1e3,addProseMirrorPlugins(){return[new Q({key:new se("footnoteRules"),appendTransaction(r,e,t){let n=t.tr,i=null,s=!1,o=new Set;if(r.some(a=>a.steps.some(c=>c instanceof B?c.from===0&&c.to===e.doc.content.size:!1)))s=!0;else for(let a of r)if(a.docChanged)for(let c of a.steps){if(!(c instanceof B))continue;c.slice.size>0&&c.slice.content.descendants((m,g)=>{if((m==null?void 0:m.type.name)=="anchor")return i=m.attrs.id,s=!0,!1});const d=a.docs[0],f=a.doc,h=new Map,p=new Map;d.descendants((m,g)=>{m.type.name==="anchor"&&h.set(m.attrs.id,g)}),f.descendants((m,g)=>{m.type.name==="anchor"&&p.set(m.attrs.id,g)});for(const[m,g]of h)p.has(m)||(o.add(m),s=!0);(h.size!==p.size||Array.from(h.entries()).some(([m,g])=>p.get(m)!==g))&&(s=!0)}if(o.size>0&&t.doc.descendants((a,c)=>{if(a.type.name==="note"){const u=a.attrs.target;if(u&&u.startsWith("#")){const d=u.substring(1);o.has(d)&&(n=n.delete(c,c+a.nodeSize))}}}),i){let a=!1;if(t.doc.descendants((m,g)=>{if(m.type.name==="note"&&m.attrs.target===`#${i}`)return console.log("note found",m),a=!0,!1}),a)return null;let c=null;t.doc.descendants((m,g)=>{if(m.type.name==="noteGrp")return c=g,!1}),c===null&&(c=t.doc.content.size,n=n.insert(c,t.schema.nodes.noteGrp.create()));const u=n.doc.nodeAt(c);if(!u)return null;const d=t.schema.nodes.note.create({target:`#${i}`,_reference:"1"}),f=c+u.nodeSize-1;n=n.insert(f,d);const h=f;n.doc.nodeAt(h)&&(n=n.setSelection(E.create(n.doc,h+1)))}return s&&(Id(n.doc),n=Bd(n,n.doc),n=Pd(n,n.doc),n=Rd(n,n.doc,i)),n}})]}});function Ld(r){const e=[$d,Od];return Object.entries(r.schema).forEach(([t,n])=>{let i;n.type==="inline"?i=Nd.extend({name:t}):n.type==="anchor"?i=zd.extend({name:t}):n.type==="empty"?i=Eo.extend({name:t}):n.type==="list"?i=Ad.extend({name:t,content:n.content||"item+"}):n.type==="listItem"?i=vd.extend({name:t,content:n.content||"p block*"}):n.type==="block"&&(i=pn.extend({name:t,group:n.group||"block",defining:n.defining,isolating:n.isolating,priority:n.priority,inline:n.inline,content:n.content}));const s={...r.attributes,...n.attributes};e.push(i.configure({shortcuts:n.keyboard,attributes:s,label:n.label}))}),e}const $d=Td.extend({content:"block+ noteGrp?"});function Oo(r,e,t){let n=null;return r.state.doc.nodesBetween(e,t,(i,s,o,l)=>{i.isText&&(n==null?n=i.marks.map(a=>({mark:a,pos:s})):n=n.filter(a=>i.marks.find(c=>c.type.name===a.mark.type.name)))}),n&&(n=n.map(i=>{const s=r.state.doc.resolve(i.pos),o=hr(s,i.mark.type,i.mark.attrs);return i.text=r.state.doc.textBetween(o.from,o.to,""," "),i}),n.sort((i,s)=>{var o,l;return(((o=s.text)==null?void 0:o.length)||0)-(((l=i.text)==null?void 0:l.length)||0)})),n}function Vd(r,e=[]){const t={},n=[];return r.state.doc.nodesBetween(0,r.state.doc.content.size,(i,s)=>{i.isText&&e.forEach(o=>{const l=i.text.indexOf(o);if(l!==-1){const a={pos:s,index:l,length:o.length};n.some(u=>u.pos<=a.pos&&u.pos+u.index+u.length>=a.pos+a.index+a.length)||(t[o]=[...t[o]||[],a],n.push(a))}})}),t}function jd(r){const t=new DOMParser().parseFromString(r,"application/xml"),n=t.querySelector("parsererror");return n?(console.error("XML Parsing Error:",n.textContent),null):t}function Wd(r){if(!r)return"";const e=[],t=r.querySelectorAll("text > body > *"),n=i=>{if(i.nodeType===Node.ELEMENT_NODE){const s=document.createElement(`tei-${i.tagName}`);for(const o of i.attributes)o.name==="xml:id"?s.setAttribute("id",o.value):s.setAttribute(o.name,o.value);for(const o of i.childNodes)s.appendChild(n(o));return s}else return i.cloneNode()};return t.forEach(i=>{const s=n(i);e.push(s.outerHTML)}),e.join("")}function Hd(r){const e=jd(r);return e.documentElement.namespaceURI==="http://www.tei-c.org/ns/1.0"?Wd(e):xml}function Jd(r,e,t,n=3){let i=e-1,s=0;for(;i>=0;){if(/[\p{P}\s]/.test(r.charAt(i))){for(;i>1&&/[\p{P}\s]/.test(r.charAt(i-1));)i-=1;if(s+=1,s===n)break}i-=1}let o=t+1;for(s=0;o<r.length;){if(/[\p{P}\s]/.test(r.charAt(o))){for(;o<r.length-1&&/[\p{P}\s]/.test(r.charAt(o+1));)o+=1;if(s+=1,s===n)break}o+=1}return`… ${r.substring(i,e)}<mark>${r.substring(e,t)}</mark>${r.substring(t,o+1)} …`}class qd{constructor(e,t){this.editor=e.tiptap,this.schemaDef=t,this.panel=e.querySelector(".attribute-panel"),this.currentElement=null,this.currentMark=null,this.setupEventListeners(),this.overlay=document.createElement("div"),this.overlay.className="jinn-tap overlay",this.overlay.style.display="block",this.overlay.style.position="fixed",this.overlay.style.pointerEvents="none",this.overlay.style.zIndex="1000",this.overlay.style.display="none"}setupEventListeners(){this.editor.on("selectionUpdate",({editor:e})=>{this.updatePanelForCurrentPosition(e)}),this.editor.on("update",({editor:e})=>{this.updatePanelForCurrentPosition(e)}),this.editor.options.element.addEventListener("empty-element-clicked",({detail:e})=>{this.showNodeAttributes(e.node)})}updatePanelForCurrentPosition(e){var l;const{from:t,to:n}=e.state.selection,i=Oo(e,t,n);if(i&&i.length>0){this.currentElement=null;const a=i[i.length-1];((l=this.currentMark)==null?void 0:l.mark)!=a.mark&&this.showMarkAttributes(a.mark,a.text),this.currentMark=a;return}const o=e.state.doc.resolve(t).node();if(this.currentMark=null,o&&Object.keys(this.schemaDef.schema).includes(o.type.name)){if(this.currentElement==o)return;this.currentElement=o,this.currentAttributes={...o.attrs},this.showNodeAttributes(o)}else this.currentElement=null,this.currentAttributes={},this.hidePanel()}showMarkAttributes(e,t){this.updatePanel(e,t)}showNodeAttributes(e){this.updatePanel(e)}hidePanel(){this.updatePanel()}createAttributeInput(e,t,n,i,s=""){const o=document.createElement("label");o.textContent=t;let l;return n.enum?(l=document.createElement("select"),n.enum.forEach(a=>{const c=document.createElement("option");c.value=a,c.textContent=a,l.appendChild(c)})):(l=document.createElement("input"),l.type="text"),l.placeholder=s,l.value=i||n.default||"",l.name=t,o.appendChild(l),e.appendChild(o),l}updatePanel(e,t){if(!this.panel)return;if(this.panel.innerHTML="",!e){this.panel.innerHTML="<p>Select text or a node to edit attributes</p>";return}const n=this.schemaDef.schema[e.type.name];if(!n){this.panel.innerHTML="";return}const i=document.createElement("h4");i.textContent=e.type.name,this.panel.appendChild(i);const s=document.createElement("div");this.panel.appendChild(s);const o=document.createElement("form");this.panel.appendChild(o);const l={...this.schemaDef.attributes,...n.attributes};if(Object.entries(l).forEach(([a,c])=>{if(!a.startsWith("_"))if(c.connector){const u=this.createAttributeInput(o,a,c,e.attrs[a],"No reference assigned");u.readOnly=!0;const d=document.createElement("details");d.open=!e.attrs[a];const f=document.createElement("summary");f.textContent="Lookup",d.appendChild(f);const h=document.createElement("pb-authority-lookup");h.setAttribute("type",c.connector.type),h.setAttribute("query",t),h.setAttribute("auto",e.attrs[a]?"true":"false"),h.setAttribute("no-occurrences",!0);const p=document.createElement("pb-authority");if(p.setAttribute("connector",c.connector.name),p.setAttribute("name",c.connector.type),c.connector.user&&p.setAttribute("user",c.connector.user),h.appendChild(p),document.addEventListener("pb-authority-select",m=>{const g=`${c.connector.prefix}-${m.detail.properties.ref}`;u.value=g,d.open=!1,this.handleAttributeUpdate(e,{[a]:g})}),d.appendChild(h),o.appendChild(d),e.attrs[a]){const m=e.attrs[a].substring(e.attrs[a].indexOf("-")+1);h.lookup(c.connector.type,m,s).then(g=>{const y=g.strings;y.sort((S,w)=>w.length-S.length),y.unshift(t),this.updateOccurrences(this.editor,e,y)})}}else this.createAttributeInput(o,a,c,e.attrs[a])}),Object.keys(l).length>0&&!(Object.keys(l).length===1&&l[Object.keys(l)[0]].connector)){const a=document.createElement("button");a.dataset.tooltip="Apply Changes",a.type="submit",a.innerHTML='<i class="bi bi-check-all"></i>',a.addEventListener("click",c=>{c.preventDefault(),this.handleAttributeUpdate(e)}),this.panel.appendChild(a)}}handleAttributeUpdate(e,t={}){const n=new FormData(this.panel.querySelector("form")),i=[];for(const[l,a]of n.entries())a!==""?t[l]=a:i.push(l);console.log("<jinn-tap> pendingChanges: %o, cleared: %o",t,i);const{from:s,to:o}=this.editor.state.selection;this.editor.chain().focus().extendMarkRange(e.type).run(),i.length>0&&this.editor.commands.resetAttributes(e.type,i),Object.keys(t).length>0&&this.editor.chain().focus().updateAttributes(e.type,t).setTextSelection({from:s,to:o}).run()}updateOccurrences(e,t,n){const i=Vd(e,n),s=document.createElement("div");s.classList.add("occurrences"),s.innerHTML=`
|
|
91
91
|
<h5>Other Occurrences
|
|
92
92
|
<div role="group">
|
|
93
93
|
<button class="apply-all" data-tooltip="Apply to All">
|
|
@@ -95,7 +95,7 @@ img.ProseMirror-separator {
|
|
|
95
95
|
</button>
|
|
96
96
|
</div>
|
|
97
97
|
</h5>
|
|
98
|
-
<ul></ul>`;const o=s.querySelector("ul");this.panel.appendChild(s);const l=[];for(const[c,u]of Object.entries(i))for(const d of u){const f=e.state.doc.resolve(d.pos);let h=f.node(),p=null;h.isText||e.state.doc.nodesBetween(d.pos,d.pos+d.length,(M,I)=>{if(M.isText)return p=M,!1});const m=p&&p.marks.find(M=>t.eq(M)),g=document.createElement("li"),y=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=m,y.appendChild(S),l.push({checkbox:S,from:d.pos+d.index,to:d.pos+d.index+d.length,hasMark:m});const w=e.state.doc.textBetween(d.pos,f.end()),v=Jd(w,d.index,d.index+d.length),A=document.createElement("span");A.innerHTML=v,y.appendChild(A),g.appendChild(y),o.appendChild(g),y.addEventListener("mouseenter",M=>{M.preventDefault(),M.stopPropagation();const I=e.view.nodeDOM(d.pos);if(I){(I.nodeType===Node.TEXT_NODE?I.parentNode:I).scrollIntoView({behavior:"instant",block:"center"});let T;if(I.nodeType===Node.TEXT_NODE){const ie=document.createRange();ie.setStart(I,d.index),ie.setEnd(I,d.index+d.length),T=ie.getBoundingClientRect()}else T=I.getBoundingClientRect();this.overlay.style.display="block",this.overlay.style.top=T.top-10+"px",this.overlay.style.left=T.left-10+"px",this.overlay.style.width=T.width+20+"px",this.overlay.style.height=T.height+20+"px",document.body.appendChild(this.overlay)}}),y.addEventListener("mouseleave",M=>{M.preventDefault(),M.stopPropagation(),this.overlay.style.display="none"}),S.addEventListener("change",M=>{M.preventDefault(),M.stopPropagation(),this.editor.chain().focus().setTextSelection({from:d.pos+d.index,to:d.pos+d.index+d.length}).toggleMark(t.type,t.attrs).run()})}s.querySelector(".apply-all").addEventListener("click",c=>{c.preventDefault(),c.stopPropagation();const u=l.filter(d=>!d.checkbox.checked);if(u.length>0){let d=this.editor.chain().focus();u.forEach(f=>{d=d.setTextSelection({from:f.from,to:f.to}).toggleMark(t.type,t.attrs),f.checkbox.checked=!0}),d.run()}})}}class Kd{constructor(e,t){this.editor=e.tiptap,this.attributePanel=t,this.panel=e.querySelector(".navigation-panel"),this.setupEventListeners()}setupEventListeners(){this.editor.on("selectionUpdate",({editor:e})=>{this.updatePanelForCurrentPosition(e)})}updatePanelForCurrentPosition(e){this.panel.innerHTML="";const{from:t,to:n}=e.state.selection,i=e.state.doc.nodeAt(t),s=[];let o;if(i){i.isText&&(o=
|
|
98
|
+
<ul></ul>`;const o=s.querySelector("ul");this.panel.appendChild(s);const l=[];for(const[c,u]of Object.entries(i))for(const d of u){const f=e.state.doc.resolve(d.pos);let h=f.node(),p=null;h.isText||e.state.doc.nodesBetween(d.pos,d.pos+d.length,(M,I)=>{if(M.isText)return p=M,!1});const m=p&&p.marks.find(M=>t.eq(M)),g=document.createElement("li"),y=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=m,y.appendChild(S),l.push({checkbox:S,from:d.pos+d.index,to:d.pos+d.index+d.length,hasMark:m});const w=e.state.doc.textBetween(d.pos,f.end()),v=Jd(w,d.index,d.index+d.length),A=document.createElement("span");A.innerHTML=v,y.appendChild(A),g.appendChild(y),o.appendChild(g),y.addEventListener("mouseenter",M=>{M.preventDefault(),M.stopPropagation();const I=e.view.nodeDOM(d.pos);if(I){(I.nodeType===Node.TEXT_NODE?I.parentNode:I).scrollIntoView({behavior:"instant",block:"center"});let T;if(I.nodeType===Node.TEXT_NODE){const ie=document.createRange();ie.setStart(I,d.index),ie.setEnd(I,d.index+d.length),T=ie.getBoundingClientRect()}else T=I.getBoundingClientRect();this.overlay.style.display="block",this.overlay.style.top=T.top-10+"px",this.overlay.style.left=T.left-10+"px",this.overlay.style.width=T.width+20+"px",this.overlay.style.height=T.height+20+"px",document.body.appendChild(this.overlay)}}),y.addEventListener("mouseleave",M=>{M.preventDefault(),M.stopPropagation(),this.overlay.style.display="none"}),S.addEventListener("change",M=>{M.preventDefault(),M.stopPropagation(),this.editor.chain().focus().setTextSelection({from:d.pos+d.index,to:d.pos+d.index+d.length}).toggleMark(t.type,t.attrs).run()})}s.querySelector(".apply-all").addEventListener("click",c=>{c.preventDefault(),c.stopPropagation();const u=l.filter(d=>!d.checkbox.checked);if(u.length>0){let d=this.editor.chain().focus();u.forEach(f=>{d=d.setTextSelection({from:f.from,to:f.to}).toggleMark(t.type,t.attrs),f.checkbox.checked=!0}),d.run()}})}}class Kd{constructor(e,t){this.editor=e.tiptap,this.attributePanel=t,this.panel=e.querySelector(".navigation-panel"),this.setupEventListeners()}setupEventListeners(){this.editor.on("selectionUpdate",({editor:e})=>{this.updatePanelForCurrentPosition(e)})}updatePanelForCurrentPosition(e){this.panel.innerHTML="";const{from:t,to:n}=e.state.selection,i=e.state.doc.nodeAt(t),s=[];let o;if(i){i.isText&&(o=Oo(e,t,n));let a=t,c=e.state.doc.resolve(a).depth;const u=e.state.doc.resolve(a);for(;c>0;){const d=u.node(c);if(d){const f={type:d.type.name,node:d,pos:{from:u.start(c),to:u.end(c)}};s.push(f)}c--}}let l=document.createElement("ul");s.reverse().forEach((a,c)=>{const u=document.createElement("li"),d=document.createElement("a");d.setAttribute("href","#"),d.textContent=a.type,d.addEventListener("click",f=>{f.preventDefault(),this.editor.chain().focus().setTextSelection(a.pos).run(),this.attributePanel.showNodeAttributes(a.node)}),u.appendChild(d),l.appendChild(u)}),o&&o.forEach(a=>{const c=document.createElement("li"),u=document.createElement("a");u.setAttribute("href","#"),u.textContent=a.mark.type.name,u.addEventListener("click",d=>{d.preventDefault(),this.editor.chain().focus().extendMarkRange(a.mark.type).run(),this.attributePanel.showMarkAttributes(a.mark,a.text)}),c.appendChild(u),l.appendChild(c)}),this.panel.appendChild(l)}}class Ud{constructor(e,t){this.editor=e.tiptap,this.toolbar=e.querySelector(".toolbar"),this.schemaDef=t,this.addButtons(t);const n=document.createElement("a");n.href="#",n.dataset.tooltip="Toggle debug mode",n.dataset.placement="bottom",n.className="outline toolbar-button",n.innerHTML='<i class="bi bi-question-circle"></i>',n.title="Toggle debug mode",n.addEventListener("click",s=>{s.preventDefault();const o=this.toolbar.closest("jinn-tap");o.hasAttribute("debug")?o.removeAttribute("debug"):o.setAttribute("debug","")});const i=document.createElement("li");i.appendChild(n),this.toolbar.appendChild(i)}addButtons(e){const t=Object.entries(e.schema).sort(([,i],[,s])=>{const o=l=>l==="block"||l==="list"||l==="empty"?0:l==="inline"?1:2;return o(i.type)-o(s.type)}),n=new Map;t.forEach(([i,s])=>{s.toolbar&&Object.entries(s.toolbar).forEach(([o,l])=>{if(l.select){const a=l.select;let c=n.get(a);if(!c){c=this.createSelect(a),n.set(a,c);const u=document.createElement("li");u.appendChild(c),this.toolbar.appendChild(u)}this.addOptionToSelect(c,i,s,o,l)}else{const a=this.createButton(i,o,l);a.addEventListener("click",u=>{u.preventDefault(),this.handleNodeAction(i,s,l)});const c=document.createElement("li");c.appendChild(a),this.toolbar.appendChild(c)}})})}handleNodeAction(e,t,n){if(e==="head"){const{state:s}=this.editor,{selection:o}=s,{$from:l}=o;if(Ot(l,c=>c.type.name==="item")){this.editor.chain().focus().transformToHead().run();return}}const i=this.editor.chain().focus();if(n.command)i[n.command](e,n.attributes);else if(t.type==="inline")i.toggleMark(e,n.attributes);else if(t.type==="list")i.toggleList(n.attributes);else if(t.type==="anchor")i.addAnchor(n.attributes);else if(t.type==="empty")i.insertContent({type:e,attrs:n.attributes});else{const s=this.editor.schema.nodes[e];s&&s.isTextblock?i.setNode(e,n.attributes):i.wrapIn(e,n.attributes)}i.run()}createButton(e,t,n){const i=document.createElement("a");return i.href="#",i.className="outline toolbar-button",n.label&&(i.innerHTML=n.label),i.dataset.tooltip=t,i.dataset.placement="bottom",i.addEventListener("mousedown",s=>{s.preventDefault()}),this.editor.on("selectionUpdate",({editor:s})=>{this.updateButtonState(i,e,n,s)}),i}updateButtonState(e,t,n,i){const s=this.schemaDef[t];if(!s)return;let o=!0;n.command?o=i.can()[n.command](t,n.attributes):s.type==="inline"?o=i.can().toggleMark(t,n.attributes):s.type==="block"?o=i.can().setNode(t,n.attributes):s.type==="list"?o=i.can().toggleList(t,n.attributes):(s.type==="empty"||s.type==="anchor")&&(o=i.can().insertContent({type:t,attrs:n.attributes})),e.disabled=!o,o?e.classList.remove("disabled"):e.classList.add("disabled"),e.classList.toggle("active",i.isActive(t))}createSelect(e){const t=document.createElement("details");t.className="dropdown";const n=document.createElement("summary");n.textContent=e,t.appendChild(n);const i=document.createElement("ul");return t.appendChild(i),t}addOptionToSelect(e,t,n,i,s){const o=document.createElement("li"),l=document.createElement("a");l.innerHTML=s.label,l.appendChild(document.createTextNode(" "+i)),l.href="#",o.appendChild(l),l.addEventListener("click",a=>{a.preventDefault(),e.open=!1,this.handleNodeAction(t,n,s)}),this.editor.on("selectionUpdate",({editor:a})=>{this.updateButtonState(l,t,n,a)}),e.querySelector("ul").appendChild(o)}}function _d(r){const e="#E48500",t={},n=[],i=u=>{let d=parseInt(u.substring(1,3),16)/255,f=parseInt(u.substring(3,5),16)/255,h=parseInt(u.substring(5,7),16)/255,p=Math.max(d,f,h),m=Math.min(d,f,h),g,y,S=(p+m)/2;if(p===m)g=y=0;else{let w=p-m;switch(y=S>.5?w/(2-p-m):w/(p+m),p){case d:g=(f-h)/w+(f<h?6:0);break;case f:g=(h-d)/w+2;break;case h:g=(d-f)/w+4;break}g/=6}return[g*360,y*100,S*100]},s=(u,d,f)=>{f/=100;const h=d*Math.min(f,1-f)/100,p=m=>{const g=(m+u/30)%12,y=f-h*Math.max(Math.min(g-3,9-g,1),-1);return Math.round(255*y).toString(16).padStart(2,"0")};return`#${p(0)}${p(8)}${p(4)}`},[o,l,a]=i(e);for(let u=0;u<5;u++){const d=(o+u*40)%360,f=s(d,l,a);t[`--tei-div-color-${u}`]=f}let c=5;return Object.entries(r.schema).forEach(([u,d])=>{const f=(o+c*60)%360,h=s(f,l,a);t[`--tei-${u}-color`]=`${h}`,(d.type==="inline"||d.type==="empty")&&n.push(`
|
|
99
99
|
.debug tei-${u}::after {
|
|
100
100
|
background-color: var(--tei-${u}-color);
|
|
101
101
|
content: "${u}";
|
|
@@ -108,7 +108,7 @@ img.ProseMirror-separator {
|
|
|
108
108
|
|
|
109
109
|
${n.join(`
|
|
110
110
|
`)}
|
|
111
|
-
`}const mn={attributes:{rend:{type:"string"},id:{type:"string"}},schema:{div:{type:"block",defining:!0,content:"heading* block*",attributes:{type:{type:"string"},n:{type:"string"}},keyboard:{"Mod-Shift-e":{attributes:{},command:"wrapDiv"},"Mod-Alt-e":{attributes:{},command:"liftDiv"}},toolbar:{Division:{attributes:{},command:"wrapDiv",label:"<i class='bi bi-body-text'></i>"},"Unwrap nodes in division":{attributes:{},command:"liftDiv",label:"<i class='bi bi-arrow-up-left'></i>"}}},hi:{type:"inline",attributes:{rend:{type:"string",default:"i",enum:["i","b","u","code"]}},keyboard:{"Cmd-b":{attributes:{rend:"b"}},"Cmd-i":{attributes:{rend:"i"}},"Cmd-u":{attributes:{rend:"u"}}},toolbar:{Bold:{attributes:{rend:"b"},label:"<i class='bi bi-type-bold'></i>"},Italic:{attributes:{rend:"i"},label:"<i class='bi bi-type-italic'></i>"},Underline:{attributes:{rend:"u"},label:"<i class='bi bi-type-underline'></i>"}}},ref:{type:"inline",attributes:{target:{type:"string"}},keyboard:{"Alt-Shift-r":{attributes:{}}},toolbar:{Reference:{attributes:{},label:"<i class='bi bi-link'></i>"}}},title:{type:"inline",attributes:{level:{type:"string",enum:["m","s","a"]}},keyboard:{"Mod-Alt-t":{attributes:{level:"m"}}},toolbar:{Title:{attributes:{level:"m"},label:"<i class='bi bi-quote'></i>"}}},persName:{type:"inline",attributes:{key:{connector:{name:"GND",type:"person",prefix:"gnd"},type:"string"}},keyboard:{"Mod-Shift-p":{attributes:{}}},toolbar:{Person:{attributes:{},label:"<i class='bi bi-person'></i>"}}},orgName:{type:"inline",attributes:{key:{connector:{name:"GND",type:"organization",prefix:"gnd"},type:"string"}},toolbar:{Organization:{attributes:{},label:"<i class='bi bi-people'></i>"}}},placeName:{type:"inline",attributes:{key:{type:"string",connector:{name:"GeoNames",type:"place",prefix:"geo",user:"existdb"}}},keyboard:{"Mod-Shift-h":{attributes:{}}},toolbar:{Place:{attributes:{},label:"<i class='bi bi-geo-alt'></i>"}}},term:{type:"inline",attributes:{key:{type:"string",connector:{name:"GND",type:"term",prefix:"gnd"}}},keyboard:{"Mod-Shift-t":{attributes:{}}},toolbar:{Term:{attributes:{},label:"<i class='bi bi-bookmark'></i>"}}},date:{type:"inline",attributes:{when:{type:"string"},"not-before":{type:"string"},"not-after":{type:"string"},from:{type:"string"},to:{type:"string"}},toolbar:{Date:{attributes:{},label:"<i class='bi bi-calendar-date'></i>"}}},p:{type:"block",priority:100,toolbar:{Paragraph:{select:"Blocks",attributes:{},label:"<i class='bi bi-paragraph'></i>"}}},head:{type:"block",group:"heading",attributes:{type:{type:"string"},n:{type:"string"}},keyboard:{"Shift-Mod-1":{attributes:{n:"1"}}},toolbar:{Head:{select:"Blocks",attributes:{},label:"<i class='bi bi-type-h1'></i>"}}},item:{type:"listItem"},list:{type:"list",content:"heading* item+",attributes:{rend:{type:"string",enum:["ordered","unordered"]}},keyboard:{"Mod-Shift-l":{attributes:{}}},toolbar:{List:{select:"Blocks",attributes:{rend:"unordered"},label:"<i class='bi bi-list-ul'></i>"},"Numbered list":{select:"Blocks",attributes:{rend:"ordered"},label:"<i class='bi bi-list-ol'></i>"}}},noteGrp:{type:"list",group:"",defining:!0,content:"note+",keyboard:{"Mod-Shift-u":{attributes:{}}}},note:{type:"listItem",content:"inline*",defining:!0,isolating:!0,attributes:{target:{type:"string"},_reference:{type:"string"}}},anchor:{type:"anchor",attributes:{type:{type:"string",default:"note"}},toolbar:{Footnote:{attributes:{type:"note"},label:"<i class='bi bi-123'></i>"}}},pb:{type:"empty",label:"pb",attributes:{n:{type:"string"}},keyboard:{"Mod-Alt-p":{attributes:{n:"22"}}},toolbar:{PageBreak:{attributes:{n:"22"},label:"<i class='bi bi-file-earmark-break'></i>"}}}}},Mr=document.createElement("style");Mr.textContent=`
|
|
111
|
+
`}const mn={attributes:{rend:{type:"string"},id:{type:"string"}},schema:{div:{type:"block",defining:!0,content:"heading* block*",attributes:{type:{type:"string"},n:{type:"string"}},keyboard:{"Mod-Shift-e":{attributes:{},command:"wrapDiv"},"Mod-Alt-e":{attributes:{},command:"liftDiv"}},toolbar:{Division:{attributes:{},command:"wrapDiv",label:"<i class='bi bi-body-text'></i>"},"Unwrap nodes in division":{attributes:{},command:"liftDiv",label:"<i class='bi bi-arrow-up-left'></i>"}}},hi:{type:"inline",attributes:{rend:{type:"string",default:"i",enum:["i","b","u","code"]}},keyboard:{"Cmd-b":{attributes:{rend:"b"}},"Cmd-i":{attributes:{rend:"i"}},"Cmd-u":{attributes:{rend:"u"}}},toolbar:{Bold:{attributes:{rend:"b"},label:"<i class='bi bi-type-bold'></i>"},Italic:{attributes:{rend:"i"},label:"<i class='bi bi-type-italic'></i>"},Underline:{attributes:{rend:"u"},label:"<i class='bi bi-type-underline'></i>"}}},ref:{type:"inline",attributes:{target:{type:"string"}},keyboard:{"Alt-Shift-r":{attributes:{}}},toolbar:{Reference:{attributes:{},label:"<i class='bi bi-link'></i>"}}},title:{type:"inline",attributes:{level:{type:"string",enum:["m","s","a"]}},keyboard:{"Mod-Alt-t":{attributes:{level:"m"}}},toolbar:{Title:{attributes:{level:"m"},label:"<i class='bi bi-quote'></i>"}}},persName:{type:"inline",attributes:{key:{connector:{name:"GND",type:"person",prefix:"gnd"},type:"string"}},keyboard:{"Mod-Shift-p":{attributes:{}}},toolbar:{Person:{attributes:{},label:"<i class='bi bi-person'></i>"}}},orgName:{type:"inline",attributes:{key:{connector:{name:"GND",type:"organization",prefix:"gnd"},type:"string"}},toolbar:{Organization:{attributes:{},label:"<i class='bi bi-people'></i>"}}},placeName:{type:"inline",attributes:{key:{type:"string",connector:{name:"GeoNames",type:"place",prefix:"geo",user:"existdb"}}},keyboard:{"Mod-Shift-h":{attributes:{}}},toolbar:{Place:{attributes:{},label:"<i class='bi bi-geo-alt'></i>"}}},term:{type:"inline",attributes:{key:{type:"string",connector:{name:"GND",type:"term",prefix:"gnd"}}},keyboard:{"Mod-Shift-t":{attributes:{}}},toolbar:{Term:{attributes:{},label:"<i class='bi bi-bookmark'></i>"}}},date:{type:"inline",attributes:{when:{type:"string"},"not-before":{type:"string"},"not-after":{type:"string"},from:{type:"string"},to:{type:"string"}},toolbar:{Date:{attributes:{},label:"<i class='bi bi-calendar-date'></i>"}}},p:{type:"block",priority:100,toolbar:{Paragraph:{select:"Blocks",attributes:{},label:"<i class='bi bi-paragraph'></i>"}}},head:{type:"block",group:"heading",attributes:{type:{type:"string"},n:{type:"string"}},keyboard:{"Shift-Mod-1":{attributes:{n:"1"}}},toolbar:{Head:{select:"Blocks",attributes:{},label:"<i class='bi bi-type-h1'></i>"}}},item:{type:"listItem"},list:{type:"list",content:"heading* item+",attributes:{rend:{type:"string",enum:["ordered","unordered"]}},keyboard:{"Mod-Shift-l":{attributes:{}}},toolbar:{List:{select:"Blocks",attributes:{rend:"unordered"},label:"<i class='bi bi-list-ul'></i>"},"Numbered list":{select:"Blocks",attributes:{rend:"ordered"},label:"<i class='bi bi-list-ol'></i>"}}},opener:{type:"block",content:"block*",toolbar:{Opener:{select:"Blocks",attributes:{},label:"<i class='bi bi-envelope-open'></i>"}}},closer:{type:"block",content:"block*",toolbar:{Closer:{select:"Blocks",attributes:{},label:"<i class='bi bi-envelope'></i>"}}},noteGrp:{type:"list",group:"",defining:!0,content:"note+",keyboard:{"Mod-Shift-u":{attributes:{}}}},note:{type:"listItem",content:"inline*",defining:!0,isolating:!0,attributes:{target:{type:"string"},_reference:{type:"string"}}},anchor:{type:"anchor",attributes:{type:{type:"string",default:"note"}},toolbar:{Footnote:{attributes:{type:"note"},label:"<i class='bi bi-123'></i>"}}},pb:{type:"empty",label:"pb",attributes:{n:{type:"string"}},keyboard:{"Mod-Alt-p":{attributes:{n:"22"}}},toolbar:{PageBreak:{attributes:{n:"22"},label:"<i class='bi bi-file-earmark-break'></i>"}}},lb:{type:"empty",label:"↵",attributes:{n:{type:"string"}},toolbar:{LineBreak:{attributes:{},label:"<i class='bi bi-arrow-return-left'></i>"}}}}},Mr=document.createElement("style");Mr.textContent=`
|
|
112
112
|
jinn-tap {
|
|
113
113
|
display: grid;
|
|
114
114
|
grid-template-rows: min-content 1fr;
|
|
@@ -194,7 +194,7 @@ img.ProseMirror-separator {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
${_d(mn)}
|
|
197
|
-
`,document.querySelector("#jinn-tap-styles")||(Mr.id="jinn-tap-styles",document.head.appendChild(Mr));class
|
|
197
|
+
`,document.querySelector("#jinn-tap-styles")||(Mr.id="jinn-tap-styles",document.head.appendChild(Mr));class No extends HTMLElement{static get observedAttributes(){return["debug","url"]}constructor(){super(),this.editor=null,this.toolbar=null,this.attributePanel=null}attributeChangedCallback(e,t,n){e==="debug"?n!==null?this.classList.add("debug"):this.classList.remove("debug"):e==="url"&&n&&this.loadFromUrl(n)}async loadFromUrl(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const n=await t.text(),i=Hd(n);this.editor?this.content=i:this._pendingContent=i}catch(t){console.error("Error loading content from URL:",t),this.dispatchEvent(new CustomEvent("error",{detail:{error:t.message}}))}}connectedCallback(){this.setupEditor()}setupEditor(){const e=document.createElement("div");e.innerHTML=this.innerHTML,this.innerHTML=`
|
|
198
198
|
<nav>
|
|
199
199
|
<ul class="toolbar">
|
|
200
200
|
<slot name="toolbar"></slot>
|
|
@@ -206,9 +206,9 @@ img.ProseMirror-separator {
|
|
|
206
206
|
<nav class="navigation-panel" aria-label="breadcrumb"></nav>
|
|
207
207
|
<div class="attribute-panel"></div>
|
|
208
208
|
</div>
|
|
209
|
-
`,this.applySlots(e);const t=e.innerHTML.trim(),n=Ld(mn);this.editor=new
|
|
209
|
+
`,this.applySlots(e);const t=e.innerHTML.trim(),n=Ld(mn);this.editor=new hd({element:this.querySelector(".editor-area"),extensions:[...n,Fd,wd,Md.configure({placeholder:"Write something...",includeChildren:!0})],content:this._pendingContent||t||`
|
|
210
210
|
<tei-div>
|
|
211
211
|
<tei-p></tei-p>
|
|
212
212
|
</tei-div>
|
|
213
|
-
`,autofocus:!0,onCreate:()=>{this.dispatchContentChange(),this.dispatchEvent(new CustomEvent("ready"))},onUpdate:()=>this.dispatchContentChange()}),this.toolbar=new Ud(this,mn),this.attributePanel=new qd(this,mn),this.navigationPanel=new Kd(this,this.attributePanel);const i=this.getAttribute("url");i&&this.loadFromUrl(i)}dispatchContentChange(){this.dispatchEvent(new CustomEvent("content-change",{detail:{content:this.editor.getText(),xml:wo(this.editor)}}))}get content(){return this.editor.getText()}set content(e){this.editor.chain().focus().setContent(e).setTextSelection(0).run(),this.dispatchContentChange()}get xml(){return wo(this.editor)}focus(){this.editor.commands.focus()}get tiptap(){return this.editor}applySlots(e){const t=this.querySelectorAll("slot");for(const n of t){const i=n.name,s=e.
|
|
213
|
+
`,autofocus:!0,onCreate:()=>{this.dispatchContentChange(),this.dispatchEvent(new CustomEvent("ready"))},onUpdate:()=>this.dispatchContentChange()}),this.toolbar=new Ud(this,mn),this.attributePanel=new qd(this,mn),this.navigationPanel=new Kd(this,this.attributePanel);const i=this.getAttribute("url");i&&this.loadFromUrl(i)}dispatchContentChange(){this.dispatchEvent(new CustomEvent("content-change",{detail:{content:this.editor.getText(),xml:wo(this.editor)}}))}get content(){return this.editor.getText()}set content(e){this.editor.chain().focus().setContent(e).setTextSelection(0).run(),this.dispatchContentChange()}get xml(){return wo(this.editor)}focus(){this.editor.commands.focus()}get tiptap(){return this.editor}applySlots(e){const t=this.querySelectorAll("slot");for(const n of t){const i=n.name,s=e.querySelectorAll(`[slot="${i}"]`);if(s.length>0){const o=n.parentNode;s.forEach(l=>{const a=document.createElement("div");a.innerHTML=l.outerHTML,Array.from(a.children).forEach(u=>o.insertBefore(u,n)),l.remove()})}}return t.forEach(n=>n.remove()),e}}customElements.define("jinn-tap",No),Ke.JinnTap=No,Object.defineProperty(Ke,Symbol.toStringTag,{value:"Module"})});
|
|
214
214
|
//# sourceMappingURL=jinn-tap.umd.js.map
|