wds-editor 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +184 -3
- package/dist/types/color.d.ts +13 -0
- package/dist/types/commands.d.ts +55 -0
- package/dist/types/editor.d.ts +152 -0
- package/dist/types/filemanager/api.d.ts +69 -0
- package/dist/types/filemanager/ui.d.ts +40 -0
- package/dist/types/html.d.ts +16 -0
- package/dist/types/i18n.d.ts +128 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/plugins.d.ts +18 -0
- package/dist/types/sanitize.d.ts +11 -0
- package/dist/types/schema.d.ts +8 -0
- package/dist/types/toolbar.d.ts +31 -0
- package/dist/types/ui/dialog.d.ts +33 -0
- package/dist/types/ui/icons.d.ts +1 -0
- package/dist/types/ui/imageview.d.ts +35 -0
- package/dist/types/ui/menu.d.ts +29 -0
- package/dist/wds-editor.js +2153 -0
- package/dist/wds-editor.js.map +1 -0
- package/dist/wds-editor.min.css +1 -0
- package/dist/wds-editor.min.js +17 -0
- package/dist/wds-editor.min.js.map +1 -0
- package/dist/wds-editor.umd.cjs +8 -0
- package/dist/wds-editor.umd.cjs.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var WDSEditor=(function(){"use strict";function Q(r){this.content=r}Q.prototype={constructor:Q,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 Q(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 Q(t)},addToStart:function(r,e){return new Q([r,e].concat(this.remove(r).content))},addToEnd:function(r,e){var t=this.remove(r).content.slice();return t.push(r,e),new Q(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 Q(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=Q.from(r),r.size?new Q(r.content.concat(this.subtract(r).content)):this},append:function(r){return r=Q.from(r),r.size?new Q(this.subtract(r).content.concat(r.content)):this},subtract:function(r){var e=this;r=Q.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}},Q.from=function(r){if(r instanceof Q)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new Q(e)};function Li(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){let o=i.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&Pi(o.charCodeAt(a-1))&&Bi(o.charCodeAt(a))&&t--,t}if(i.content.size||s.content.size){let o=Li(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function zi(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=o.text,f=l.text,d=c.length,h=f.length;for(;d>0&&h>0&&c[d-1]==f[h-1];)d--,h--,t--,n--;return d&&h&&d<c.length&&Pi(c.charCodeAt(d-1))&&Bi(c.charCodeAt(d))&&(t++,n++),{a:t,b:n}}if(o.content.size||l.content.size){let c=zi(o.content,l.content,t-1,n-1);if(c)return c}t-=a,n-=a}}function Bi(r){return r>=56320&&r<57344}function Pi(r){return r>=55296&&r<56320}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 f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),n,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new 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 Li(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return zi(this,e,t,n)}findIndex(e){if(e==0)return xn(0,e);if(e==this.size)return xn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let i=this.child(t),s=n+i.nodeSize;if(s>=e)return s==e?xn(t+1,s):xn(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return b.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return b.fromArray(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 sr={index:0,offset:0};function xn(r,e){return sr.index=r,sr.offset=e,sr}function Sn(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(!Sn(r[n],e[n]))return!1}else{for(let n in r)if(!(n in e)||!Sn(r[n],e[n]))return!1;for(let n in e)if(!(n in r))return!1}return!0}class V{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&&Sn(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`);return n.create(t.attrs)}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 V.none;if(e instanceof V)return[e];let t=e.slice();return t.sort((n,i)=>n.type.rank-i.type.rank),t}}V.none=[];class Wt extends Error{}class x{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Vi(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new x(n,this.openStart,this.openEnd)}removeBetween(e,t){return new x(Fi(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return x.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(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 x(e,n,i)}}x.empty=new x(b.empty,0,0);function Fi(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(Fi(s.content,e-i-1,t-i-1)))}function Vi(r,e,t,n,i,s){let{index:o,offset:l}=r.findIndex(e),a=r.maybeChild(o);if(l==e||a.isText)return s&&n<=0&&i<=0&&!s.canReplace(o,o,t)?null:r.cut(0,e).append(t).append(r.cut(e));let c=Vi(a.content,e-l-1,t,o==0?n-1:0,o==r.childCount-1?i-1:0,a);return c&&r.replaceChild(o,a.copy(c))}function wa(r,e,t){if(t.openStart>r.depth)throw new Wt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Wt("Inconsistent open depths");return $i(r,e,t,0)}function $i(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=$i(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 it(o,l.cut(0,r.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=ka(t,r);return it(s,Wi(r,o,l,e,n))}else return it(s,Cn(r,e,n))}function Hi(r,e){if(!e.type.compatibleContent(r.type))throw new Wt("Cannot join "+e.type.name+" onto "+r.type.name)}function or(r,e,t){let n=r.node(t);return Hi(n,e.node(t)),n}function rt(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 qt(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&&(rt(r.nodeAfter,n),s++));for(let l=s;l<o;l++)rt(i.child(l),n);e&&e.depth==t&&e.textOffset&&rt(e.nodeBefore,n)}function it(r,e){if(!r.type.validContent(e))throw new Wt("Invalid content for node "+r.type.name);return r.copy(e)}function Wi(r,e,t,n,i){let s=r.depth>i&&or(r,e,i+1),o=n.depth>i&&or(t,n,i+1),l=[];return qt(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Hi(s,o),rt(it(s,Wi(r,e,t,n,i+1)),l)):(s&&rt(it(s,Cn(r,e,i+1)),l),qt(e,t,i,l),o&&rt(it(o,Cn(t,n,i+1)),l)),qt(n,null,i,l),new b(l)}function Cn(r,e,t){let n=[];if(qt(null,r,t,n),r.depth>t){let i=or(r,e,t+1);rt(it(i,Cn(r,e,t+1)),n)}return qt(e,null,t,n),new b(n)}function ka(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 Jt{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 V.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 Mn(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 Jt(t,n,s)}static resolveCached(e,t){let n=qi.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 qi.set(e,n=new xa);let i=n.elts[n.i]=Jt.resolve(e,t);return n.i=(n.i+1)%Sa,i}}class xa{constructor(){this.elts=[],this.i=0}}const Sa=12,qi=new WeakMap;class Mn{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 Ca=Object.create(null);let st=class Ii{constructor(e,t,n,i=V.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&&Sn(this.attrs,t||e.defaultAttrs||Ca)&&V.sameSet(this.marks,n||V.none)}copy(e=null){return e==this.content?this:new Ii(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Ii(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return x.empty;let i=this.resolve(e),s=this.resolve(t),o=n?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new x(c,i.depth-o,s.depth-o)}replace(e,t,n){return wa(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 Jt.resolveCached(this,e)}resolveNoCache(e){return Jt.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()+")"),Ui(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),Ki(this.type.attrs,this.attrs,"node",this.type.name);let e=V.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];Ki(n.type.attrs,n.attrs,"mark",n.type.name),e=n.addToSet(e)}if(!V.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);return e.nodeType(t.type).create(t.attrs,i,n)}};st.prototype.text=void 0;const Ji=(()=>{let{stack:r}=new Error("/");if(!r||!/\n\s*at\s/.test(r))return t=>t;let e=Object.create(null);return t=>(e[t],t)})();class An extends st{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):Ui(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return Ji(this.text.slice(e,t))}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new An(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new An(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(Ji(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 Ui(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}function Ki(r,e,t,n){for(let i in e)if(!(i in r))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${n}`);for(let i in r)r[i].validate&&r[i].validate(e[i])}class ot{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new Ma(e,t);if(n.next==null)return ot.empty;let i=_i(n);n.next&&n.err("Unexpected trailing text");let s=Da(va(i));return Ra(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:f,next:d}=o.next[c];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(d)==-1){i.push(d);let h=s(d,l.concat(f));if(h)return h}}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
|
+
`)}}ot.empty=new ot(!0);class Ma{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 _i(r){let e=[];do e.push(Aa(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Aa(r){let e=[];do e.push(Na(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Na(r){let e=Ta(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=Ea(r,e);else break;return e}function ji(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function Ea(r,e){let t=ji(r),n=t;return r.eat(",")&&(r.next!="}"?n=ji(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Oa(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 Ta(r){if(r.eat("(")){let e=_i(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=Oa(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 va(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let f=t();i(s(o.expr,a),f),a=f}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let f=t();n(a,f),i(s(o.expr,a),f),a=f}return[n(a)]}else{if(o.type=="name")return[n(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Gi(r,e){return e-r}function Yi(r,e){let t=[];return n(e),t.sort(Gi);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 Da(r){let e=Object.create(null);return t(Yi(r,0));function t(n){let i=[];n.forEach(o=>{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f<i.length;f++)i[f][0]==l&&(c=i[f][1]);Yi(r,a).forEach(f=>{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[n.join(",")]=new ot(n.indexOf(r.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Gi);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function Ra(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 Xi(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 Zi(r,e){let t=Object.create(null);for(let n in r){let i=r[n],s=e&&e[n];if(s===void 0)if(i.hasDefault)s=i.default;else throw new RangeError("No value supplied for attribute "+n);else i.validate&&i.validate(s);t[n]=s}return t}function Qi(r,e){let t=Object.create(null);if(e)for(let n in e)t[n]=new La(r,n,e[n]);return t}let Ut=class ya{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=Qi(e,n.attrs),this.defaultAttrs=Xi(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==ot.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:Zi(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new st(this,this.computeAttrs(e),b.from(t),V.setFrom(n))}createChecked(e=null,t,n){return t=b.from(t),this.checkContent(t),new st(this,this.computeAttrs(e),t,V.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 st(this,e,t.append(s),V.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){}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:V.none:e}static compile(e,t){let n=Object.create(null);e.forEach((s,o)=>n[s]=new ya(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 Ia(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 La{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Ia(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Nn{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Qi(e,i.attrs),this.excluded=null;let s=Xi(this.attrs);this.instance=s?new V(this,s):null}create(e=null){return!e&&this.instance?this.instance:new V(this,Zi(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Nn(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]}excludes(e){return this.excluded.indexOf(e)>-1}}class es{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=Q.from(e.nodes),t.marks=Q.from(e.marks||{}),this.nodes=Ut.compile(this.spec.nodes,this),this.marks=Nn.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]=ot.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?ts(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==""?[]:ts(this,o.split(" "))}this.nodeFromJSON=i=>st.fromJSON(this,i),this.markFromJSON=i=>V.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ut){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 An(n,n.defaultAttrs,e,V.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function ts(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 za(r){return r.tag!=null}function Ba(r){return r.style!=null}class bt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(za(i))this.tags.push(i);else if(Ba(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 ss(this,t,!1);return n.addAll(e,V.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ss(this,t,!0);return n.addAll(e,V.none,t.from,t.to),x.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(Va(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=ls(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=ls(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new bt(e,bt.schemaRules(e)))}}const ns={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Pa={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},rs={ol:!0,ul:!0},Kt=1,lr=2,_t=4;function is(r,e,t){return e!=null?(e?Kt:0)|(e==="full"?lr:0):r&&r.whitespace=="pre"?Kt|lr:t&~_t}class En{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=V.none,this.match=s||(o&_t?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&Kt)){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&&!ns.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ss{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=is(null,t.preserveWhitespace,0)|(n?_t:0);i?s=new En(i.type,i.attrs,V.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new En(null,null,V.none,!0,null,o):s=new En(e.schema.topNodeType,null,V.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&lr?"full":this.localPreserveWS||(i.options&Kt)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,`
|
|
3
|
+
`);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let l=i.content[i.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;rs.hasOwnProperty(o)&&this.parser.normalizeLists&&Fa(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:Pa.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(ns.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=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
4
|
+
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=n.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,i){let s=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,n){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(n)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o<i.length;o++)t=this.enterInner(i[o],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let i=this.findPlace(e,t,n);if(i){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=V.none;for(let l of i.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):as(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,n,i){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,i)),s}enterInner(e,t,n,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=is(e,s,o.options);o.options&_t&&o.content.length==0&&(l|=_t);let a=V.none;return n=n.filter(c=>(o.type?o.type.allowsMarkType(c.type):as(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new En(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|=Kt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}}function Fa(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&rs.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Va(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function ls(r){let e={};for(let t in r)e[t]=r[t];return e}function as(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:f}=l.edge(a);if(c==e||s.indexOf(f)<0&&o(f))return!0}};if(o(i.contentMatch))return!0}}class lt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=On(t).createDocumentFragment());let i=n,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],f=this.serializeMark(c,o.isInline,t);f&&(s.push([c,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),n}serializeNodeInner(e,t){if(e.isText)return On(t).createTextNode(e.text);let{dom:n,contentDOM:i}=Tn(On(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&&Tn(On(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return typeof t=="string"?{dom:e.createTextNode(t)}:Tn(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new lt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=cs(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return cs(e.marks)}}function cs(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function On(r){return r.document||window.document}const fs=new WeakMap;function $a(r){let e=fs.get(r);return e===void 0&&fs.set(r,e=Ha(r)),e}function Ha(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 Tn(r,e,t,n){if(e.nodeType==1)return{dom:e};if(e.dom&&e.dom.nodeType==1)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(s=$a(n))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?r.createElementNS(t,i):r.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let d in c)if(c[d]!=null){let h=d.indexOf(" ");h>0?a.setAttributeNS(d.slice(0,h),d.slice(h+1),c[d]):d=="style"&&a.style?a.style.cssText=c[d]:a.setAttribute(d,c[d])}}for(let d=f;d<e.length;d++){let h=e[d];if(h===0){if(d<e.length-1||d>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else if(typeof h=="string")a.appendChild(r.createTextNode(h));else{let{dom:u,contentDOM:p}=Tn(r,h,t,n);if(a.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const ds=65535,hs=Math.pow(2,16);function Wa(r,e){return r+e*hs}function us(r){return r&ds}function qa(r){return(r-(r&ds))/hs}const ps=1,ms=2,vn=4,gs=8;class ar{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&gs)>0}get deletedBefore(){return(this.delInfo&(ps|vn))>0}get deletedAfter(){return(this.delInfo&(ms|vn))>0}get deletedAcross(){return(this.delInfo&vn)>0}}class me{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&me.empty)return me.empty}recover(e){let t=0,n=us(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+qa(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],f=this.ranges[l+o],d=a+c;if(e<=d){let h=c?e==a?-1:e==d?1:t:t,u=a+i+(h<0?0:f);if(n)return u;let p=e==(t<0?a:d)?null:Wa(l/3,e-a),m=0;return c&&(m|=e==a?ms:e==d?ps:vn,(t<0?e!=a:e!=d)&&(m|=gs)),new ar(u,m,p)}i+=f-c}return n?e+i:new ar(e+i,0,null)}touches(e,t){let n=0,i=us(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?n:0);if(a>e)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;n+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],f=this.ranges[i+n];e(l,l+c,a,a+f),s+=f-c}}invert(){return new me(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?me.empty:new me(e<0?[0,-e,0]:[0,0,e])}}me.empty=new me([]);class jt{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 jt(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=e.from,n=this._maps.length;t<e.to;t++){let i=e.getMirror(t);i!=null&&(i=i<t&&i>=e.from?n+(i-e.from):void 0),this.appendMap(e._maps[t],i)}}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.to-1,n=this._maps.length+e._maps.length;t>=e.from;t--){let i=e.getMirror(t);i!=null&&(i=i>t&&i<e.to?n-(i-e.from)-1:void 0),this.appendMap(e._maps[t].invert(),i)}}invert(){let e=new jt;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 ar(e,i,null)}}const cr=Object.create(null);class j{getMap(){return me.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=cr[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 cr)throw new RangeError("Duplicate use of step JSON ID "+e);return cr[e]=t,t.prototype.jsonID=e,t}}class K{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new K(e,null)}static fail(e){return new K(null,e)}static fromReplace(e,t,n,i){try{return K.ok(e.replace(t,n,i))}catch(s){if(s instanceof Wt)return K.fail(s.message);throw s}}}function fr(r,e,t){let n=[];for(let i=0;i<r.childCount;i++){let s=r.child(i);s.content.size&&(s=s.copy(fr(s.content,e,s))),s.isInline&&(s=e(s,t,i)),n.push(s)}return b.fromArray(n)}class Se extends j{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),s=new x(fr(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 K.fromReplace(e,this.from,this.to,s)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{if(n.isInline&&n.isAtom){let s=this.mark.addToSet(n.marks);if(!V.sameSet(s,n.marks)){let o=Math.max(this.from,i),l=Math.min(this.to,i+n.nodeSize);Dn(Ce,o,l,this.mark,t);for(let a of n.marks)a.isInSet(s)||Dn(Se,o,l,a,t)}}}),t.length==1?t[0]:new at(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new Se(t,n,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Se(t.from,t.to,e.markFromJSON(t.mark))}}j.jsonID("addMark",Se);class Ce extends j{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new x(fr(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return K.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(n,i)=>{n.isInline&&n.isAtom&&this.mark.isInSet(n.marks)&&Dn(Se,Math.max(this.from,i),Math.min(this.to,i+n.nodeSize),this.mark,t)}),t.length==1?t[0]:new at(t)}map(e){let t=e.map(this.from,1),n=e.map(this.to,-1);return t>=n?null:new Ce(t,n,this.mark)}merge(e){return e instanceof Ce&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ce(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 Ce(t.from,t.to,e.markFromJSON(t.mark))}}j.jsonID("removeMark",Ce);function Dn(r,e,t,n,i){let s=i.length?i[i.length-1]:null;s&&s instanceof r&&s.to==e&&s.mark.eq(n)?i[i.length-1]=new r(s.from,t,n):i.push(new r(e,t,n))}class at extends j{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new K(e,null)}invert(e){return new at(this.steps.map(t=>t.invert(e)))}map(e){let t=[];for(let n of this.steps){let i=n.map(e);i&&t.push(i)}return t.length?new at(t):null}toJSON(){return{stepType:"markSet",steps:this.steps.map(e=>e.toJSON())}}static fromJSON(e,t){if(!Array.isArray(t.steps)||!t.steps.every(n=>n.stepType=="addMark"||n.stepType=="removeMark"))throw new RangeError("Invalid JSON for MarkSetStep");return new at(t.steps.map(n=>j.fromJSON(e,n)))}}j.jsonID("markSet",at);class We extends j{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return K.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return K.fromReplace(e,this.pos,this.pos+1,new x(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 We(this.pos,t.marks[i]);return new We(this.pos,this.mark)}}return new ct(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new We(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 We(t.pos,e.markFromJSON(t.mark))}}j.jsonID("addNodeMark",We);class ct extends j{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return K.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return K.fromReplace(e,this.pos,this.pos+1,new x(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 We(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new ct(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 ct(t.pos,e.markFromJSON(t.mark))}}j.jsonID("removeNodeMark",ct);class Y extends j{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&dr(e,this.from,this.to)?K.fail("Structure replace would overwrite content"):K.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new me([this.from,this.to-this.from,this.slice.size])}invert(e){return new Y(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&Y.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new Y(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Y)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?x.empty:new x(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Y(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?x.empty:new x(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Y(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 Y(t.from,t.to,x.fromJSON(e,t.slice),!!t.structure)}}Y.MAP_BIAS=1,j.jsonID("replace",Y);class ee extends j{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&&(dr(e,this.from,this.gapFrom)||dr(e,this.gapTo,this.to)))return K.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return K.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?K.fromReplace(e,this.from,this.to,n):K.fail("Content does not fit in gap")}getMap(){return new me([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 ee(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||i>s?null:new ee(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 ee(t.from,t.to,t.gapFrom,t.gapTo,x.fromJSON(e,t.slice),t.insert,!!t.structure)}}j.jsonID("replaceAround",ee);function dr(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 Ja(r,e,t,n){let i=[];r.doc.nodesBetween(e,t,(s,o,l)=>{if(!s.isInline)return;let a=s.marks;if(!n.isInSet(a)&&l.type.allowsMarkType(n.type)){let c=Math.max(o,e),f=Math.min(o+s.nodeSize,t);Dn(Se,c,f,n,i)}}),i.forEach(s=>r.step(s))}function Ua(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline||!o.isAtom)return;s++;let a=null;if(n instanceof Nn){let c=o.marks,f;for(;f=n.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;f<a.length;f++){let d=a[f],h;for(let u=0;u<i.length;u++){let p=i[u];p.step==s-1&&d.eq(i[u].style)&&(h=p)}h?(h.to=c,h.step=s):i.push({style:d,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>r.step(new Ce(o.from,o.to,o.style)))}function hr(r,e,t,n=t.contentMatch,i=!0){let s=r.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),f=l+c.nodeSize,d=n.matchType(c.type);if(!d)o.push(new Y(l,f,x.empty));else{n=d;for(let h=0;h<c.marks.length;h++)t.allowsMarkType(c.marks[h].type)||r.step(new Ce(l,f,c.marks[h]));if(i&&c.isText&&t.whitespace!="pre"){let h,u=/\r?\n|\r/g,p;for(;h=u.exec(c.text);)p||(p=new x(b.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new Y(l+h.index,l+h.index+h[0].length,p))}}l=f}if(!n.validEnd){let a=n.fillBefore(b.empty,!0);r.replace(l,l,new x(a,0,0))}for(let a=o.length-1;a>=0;a--)r.step(o[a])}function Ka(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function Gt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth,i=0,s=0;;--n){let o=r.$from.node(n),l=r.$from.index(n)+i,a=r.$to.indexAfter(n)-s;if(n<r.depth&&o.canReplace(l,a,t))return n;if(n==0||o.type.spec.isolating||!Ka(o,l,a))break;l&&(i=1),a<o.childCount&&(s=1)}return null}function _a(r,e,t){let{$from:n,$to:i,depth:s}=e,o=n.before(s+1),l=i.after(s+1),a=o,c=l,f=b.empty,d=0;for(let p=s,m=!1;p>t;p--)m||n.index(p)>0?(m=!0,f=b.from(n.node(p).copy(f)),d++):a--;let h=b.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)<i.end(p)?(m=!0,h=b.from(i.node(p).copy(h)),u++):c++;r.step(new ee(a,c,o,l,new x(f.append(h),d,u),f.size-d,!0))}function ur(r,e,t=null,n=r){let i=ja(r,e),s=i&&Ga(n,e);return s?i.map(ys).concat({type:e,attrs:t}).concat(s.map(ys)):null}function ys(r){return{type:r,attrs:null}}function ja(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 Ga(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 Ya(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 ee(i,s,i,s,new x(n,0,0),t.length,!0))}function Xa(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)&&Za(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let u=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);u&&!p?c=!1:!u&&p&&(c=!0)}c===!1&&ws(r,o,l,s),hr(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),d=f.map(l,1),h=f.map(l+o.nodeSize,1);return r.step(new ee(d,h,d+1,h-1,new x(b.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&bs(r,o,l,s),!1}})}function bs(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 ws(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 Za(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function Qa(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 ee(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new x(b.from(o),0,0),1,!0))}function wt(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,f=t-2;c>s;c--,f--){let d=i.node(c),h=i.index(c);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(h,d.childCount),p=n&&n[f+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[f]||d;if(!d.canReplace(h+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function ec(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 f=n&&n[c];o=b.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}r.step(new Y(e,e,new x(s.append(o),t,t),!0))}function Rn(r,e){let t=r.resolve(e),n=t.index();return nc(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function tc(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 nc(r,e){return!!(r&&e&&!r.isLeaf&&tc(r,e))}function rc(r,e,t){let n=null,{linebreakReplacement:i}=r.doc.type.schema,s=r.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);f&&!d?n=!1:!f&&d&&(n=!0)}let l=r.steps.length;if(n===!1){let f=r.doc.resolve(e+t);ws(r,f.node(),f.before(),l)}o.inlineContent&&hr(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 Y(c,a.map(e+t,-1),x.empty,!0)),n===!0){let f=r.doc.resolve(c);bs(r,f.node(),f.before(),r.steps.length)}return r}function ic(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 ks(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;for(let a=0;a<2;a++){if(a){if(!l)break;l=-l}let c=n.index(o)+(l>0?1:0),f=n.node(o),d=!1;if(s==1)d=f.canReplace(c,c,i);else{let h=f.contentMatchAt(c).findWrapping(i.firstChild.type);d=h&&f.canReplaceWith(c,c,h[0])}if(d)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}}return null}function pr(r,e,t=e,n=x.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return xs(i,s,n)?new Y(e,t,n):new sc(i,s,n).fit()}function xs(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class sc{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 x(s,o,l);return e>-1?new ee(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new Y(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=Ss(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,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&&(f=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return Ms(e,-1)<=t?!1:(this.unplaced.size>1&&Ms(e,1)>n&&n++,this.unplaced=new x(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=Ss(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new x(Yt(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new x(Yt(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=n?n.content:o.content,a=o.openStart-e,c=0,f=[],{match:d,type:h}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)f.push(i.child(m));d=d.matchFragment(i)}let u=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,f.push(Cs(m.mark(h.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?u:-1)))}let p=c==l.childCount;p||(u=-1),this.placed=Xt(this.placed,t,b.from(f)),this.frontier[t].match=d,p&&u<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=f[f.length-1];g&&m<u;m++)this.frontier.push({type:g.type,match:g.contentMatchAt(g.childCount)}),g=g.lastChild;this.unplaced=p?e==0?x.empty:new x(Yt(o.content,e-1,1),e-1,u<0?o.openEnd:e-1):new x(Yt(o.content,e,c),e,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!mr(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=mr(e,t,i,n,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],f=mr(e,l,c,a,!0);if(!f||f.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Xt(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=Xt(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=Xt(this.placed,this.frontier.length,t))}}function Yt(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(Yt(r.firstChild.content,e-1,t)))}function Xt(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(Xt(r.lastChild.content,e-1,t)))}function Ss(r,e){for(let t=0;t<e;t++)r=r.firstChild.content;return r}function Cs(r,e,t){if(e<=0)return r;let n=r.content;return e>1&&(n=n.replaceChild(0,Cs(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 mr(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&&!oc(t,s.content,o)?l:null}function oc(r,e,t){for(let n=t;n<e.childCount;n++)if(!r.allowsMarks(e.child(n).marks))return!0;return!1}function lc(r){return r.spec.defining||r.spec.definingForContent}function Ms(r,e){for(let t=0;;t++){let n=e<0?r.firstChild:r.lastChild;if(!n||n.isAtom)return t;r=n.content}}function ac(r,e,t,n){if(!n.size)return r.deleteRange(e,t);let i=r.doc.resolve(e),s=r.doc.resolve(t);if(xs(i,s,n))return r.step(new Y(e,t,n));let o=Ns(i,s);o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let h=i.depth,u=i.pos-1;h>0;h--,u--){let p=i.node(h).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(h)>-1?l=h:i.before(h)==u&&o.splice(1,0,-h)}let a=o.indexOf(l),c=[],f=n.openStart;for(let h=n.content,u=0;;u++){let p=h.firstChild;if(c.push(p),u==n.openStart)break;h=p.content}for(let h=f-1;h>=0;h--){let u=c[h],p=lc(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))f=h;else if(p||!u.type.isTextblock)break}for(let h=n.openStart;h>=0;h--){let u=(h+f+1)%(n.openStart+1),p=c[u];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let O=i.node(g-1),w=i.index(g-1);if(O.canReplaceWith(w,w,p.type,p.marks))return r.replace(i.before(g),y?s.after(g):t,new x(As(n.content,0,n.openStart,u),u,n.openEnd))}}let d=r.steps.length;for(let h=o.length-1;h>=0&&(r.replace(e,t,n),!(r.steps.length>d));h--){let u=o[h];u<0||(e=i.before(u),t=s.after(u))}}function As(r,e,t,n,i){if(e<t){let s=r.firstChild;r=r.replaceChild(0,s.copy(As(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 cc(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=ic(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new x(b.from(n),0,0))}function fc(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t);if(n.parent.isTextblock&&i.parent.isTextblock&&n.start()!=i.start()&&n.parentOffset==0&&i.parentOffset==0){let o=n.sharedDepth(t),l=!1;for(let a=n.depth;a>o;a--)n.node(a).type.spec.isolating&&(l=!0);for(let a=i.depth;a>o;a--)i.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=n.depth;a>0&&e==n.start(a);a--)e=n.before(a);for(let a=i.depth;a>0&&t==i.start(a);a--)t=i.before(a);n=r.doc.resolve(e),i=r.doc.resolve(t)}}let s=Ns(n,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||n.node(l).type.contentMatch.validEnd)return r.delete(n.start(l),i.end(l));if(l>0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o&&n.start(o-1)==i.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),i.index(o-1)))return r.delete(n.before(o),t);r.delete(e,t)}function Ns(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(s<r.pos-(r.depth-i)||e.end(i)>e.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class kt extends j{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 K.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 K.fromReplace(e,this.pos,this.pos+1,new x(b.from(i),0,t.isLeaf?0:1))}getMap(){return me.empty}invert(e){return new kt(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 kt(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 kt(t.pos,t.attr,t.value)}}j.jsonID("attr",kt);class Zt extends j{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 K.ok(n)}getMap(){return me.empty}invert(e){return new Zt(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 Zt(t.attr,t.value)}}j.jsonID("docAttr",Zt);let xt=class extends Error{};xt=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t},xt.prototype=Object.create(Error.prototype),xt.prototype.constructor=xt,xt.prototype.name="TransformError";class Es{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new jt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new xt(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}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let i=this.mapping.maps[n];n&&(e=i.map(e,1),t=i.map(t,-1)),i.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=x.empty){let i=pr(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new x(b.from(n),0,0))}delete(e,t){return this.replace(e,t,x.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return ac(this,e,t,n),this}replaceRangeWith(e,t,n){return cc(this,e,t,n),this}deleteRange(e,t){return fc(this,e,t),this}lift(e,t){return _a(this,e,t),this}join(e,t=1){return rc(this,e,t),this}wrap(e,t){return Ya(this,e,t),this}setBlockType(e,t=e,n,i=null){return Xa(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return Qa(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new kt(e,t,n)),this}setDocAttribute(e,t){return this.step(new Zt(e,t)),this}addNodeMark(e,t){return this.step(new We(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof V)t.isInSet(n.marks)&&this.step(new ct(e,t));else{let i=n.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new ct(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return ec(this,e,t,n),this}addMark(e,t,n){return Ja(this,e,t,n),this}removeMark(e,t,n){return Ua(this,e,t,n),this}clearIncompatible(e,t,n){return hr(this,e,t,n),this}}const gr=Object.create(null);class I{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Os(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=x.empty){let n=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=n,n=n.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],f=e.mapping.slice(s);e.replaceRange(f.map(a.pos),f.map(c.pos),l?x.empty:t),l==0&&Ds(e,s,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(n),c=a.map(o.pos),f=a.map(l.pos);s?e.deleteRange(c,f):(e.replaceRangeWith(c,f,t),Ds(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new L(e):St(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?St(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):St(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 ge(e.node(0))}static atStart(e){return St(e,e,0,0,1)||new ge(e)}static atEnd(e){return St(e,e,e.content.size,e.childCount,-1)||new ge(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=gr[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 gr)throw new RangeError("Duplicate use of selection JSON ID "+e);return gr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return L.between(this.$anchor,this.$head).getBookmark()}}I.prototype.visible=!0;class Os{constructor(e,t){this.$from=e,this.$to=t}}let Ts=!1;function vs(r){!Ts&&!r.parent.inlineContent&&(Ts=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class L extends I{constructor(e,t=e){vs(e),vs(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 I.near(n);let i=e.resolve(t.map(this.anchor));return new L(i.parent.inlineContent?i:n,n)}replace(e,t=x.empty){if(super.replace(e,t),t==x.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof L&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new In(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 L(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=I.findFrom(t,n,!0)||I.findFrom(t,-n,!0);if(s)t=s.$head;else return I.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(I.findFrom(e,-n,!0)||I.findFrom(e,n,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new L(e,t)}}I.jsonID("text",L);class In{constructor(e,t){this.anchor=e,this.head=t}map(e){return new In(e.map(this.anchor),e.map(this.head))}resolve(e){return L.between(e.resolve(this.anchor),e.resolve(this.head))}}class M extends I{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?I.near(s):new M(s)}content(){return new x(b.from(this.node),0,0)}eq(e){return e instanceof M&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new yr(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new M(e.resolve(t.anchor))}static create(e,t){return new M(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}M.prototype.visible=!1,I.jsonID("node",M);class yr{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new In(n,n):new yr(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&M.isSelectable(n)?new M(t):I.near(t)}}class ge extends I{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=x.empty){if(t==x.empty){e.delete(0,e.doc.content.size);let n=I.atStart(e.doc);n.eq(e.selection)||e.setSelection(n)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new ge(e)}map(e){return new ge(e)}eq(e){return e instanceof ge}getBookmark(){return dc}}I.jsonID("all",ge);const dc={map(){return this},resolve(r){return new ge(r)}};function St(r,e,t,n,i,s=!1){if(e.inlineContent)return L.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&&M.isSelectable(l))return M.create(r,t-(i<0?l.nodeSize:0))}else{let a=St(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Ds(r,e,t){let n=r.steps.length-1;if(n<e)return;let i=r.steps[n];if(!(i instanceof Y||i instanceof ee))return;let s=r.mapping.maps[n],o;s.forEach((l,a,c,f)=>{o==null&&(o=f)}),r.setSelection(I.near(r.doc.resolve(o),t))}const Rs=1,Ln=2,Is=4;class hc extends Es{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|Rs)&~Ln,this.storedMarks=null,this}get selectionSet(){return(this.updated&Rs)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ln,this}ensureMarks(e){return V.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&Ln)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ln,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)||V.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(I.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|=Is,this}get scrolledIntoView(){return(this.updated&Is)>0}}function Ls(r,e){return!e||!r?r:r.bind(e)}class Qt{constructor(e,t,n){this.name=e,this.init=Ls(t.init,n),this.apply=Ls(t.apply,n)}}const uc=[new Qt("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new Qt("selection",{init(r,e){return r.selection||I.atStart(e.doc)},apply(r){return r.selection}}),new Qt("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new Qt("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class br{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=uc.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 Qt(n.key,n.spec.state,n))})}}class Ct{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let i=this.config.plugins[n];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,f=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,n);if(f&&n.filterTransaction(f,o)){if(f.setMeta("appendedTransaction",e),!i){i=[];for(let d=0;d<this.config.plugins.length;d++)i.push(d<o?{state:n,n:t.length}:{state:this,n:0})}t.push(f),n=n.applyInner(f),s=!0}i&&(i[o]={state:n,n:t.length})}}if(!s)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Ct(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 hc(this)}static create(e){let t=new br(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new Ct(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 br(this.schema,e.plugins),n=t.fields,i=new Ct(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 br(e.schema,e.plugins),s=new Ct(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=st.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=I.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 zs(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=zs(i,e,{})),t[n]=i}return t}class qe{constructor(e){this.spec=e,this.props={},e.props&&zs(e.props,this,this.props),this.key=e.key?e.key.key:Bs("plugin")}getState(e){return e[this.key]}}const wr=Object.create(null);function Bs(r){return r in wr?r+"$"+ ++wr[r]:(wr[r]=0,r+"$")}class Mt{constructor(e="key"){this.key=Bs(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const re=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e};function At(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e}let kr=null;function Me(r,e,t){let n=kr||(kr=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n}function pc(){kr=null}function en(r,e,t,n){return t&&(Fs(r,e,t,n,-1)||Fs(r,e,t,n,1))}const Ps=/^(img|br|input|textarea|hr)$/i;function Fs(r,e,t,n,i){for(var s;;){if(r==t&&e==n)return!0;if(e==(i<0?0:X(r))){let o=r.parentNode;if(!o||!E(o)||tn(r)||Ps.test(r.nodeName)||r.contentEditable=="false")return!1;e=re(r)+(i<0?0:1),r=o}else if(E(r)){let o=r.childNodes[e+(i<0?-1:0)];if(E(o)&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else{if(tn(o)||Ps.test(o.nodeName))return!1;r=o,e=i<0?X(r):0}}else return!1}}function X(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function E(r){return r.nodeType==1}function _(r){return r.nodeType==3}function Nt(r,e){return e?r.contains(E(e)?e:e.parentNode):!1}function xr(r,e){for(;;){if(_(r)&&e)return r;if(E(r)&&e>0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=X(r)}else if(r.parentNode&&!tn(r,!0))e=re(r),r=r.parentNode;else return null}}function Sr(r,e){for(;;){if(_(r)&&e<r.nodeValue.length)return r;if(E(r)&&e<r.childNodes.length){if(r.contentEditable=="false")return null;r=r.childNodes[e],e=0}else if(r.parentNode&&!tn(r,!0))e=re(r)+1,r=r.parentNode;else return null}}function mc(r,e,t){for(let n=e==0,i=e==X(r);n||i;){if(r==t)return!0;let s=re(r);if(r=r.parentNode,!r)return!1;n=n&&s==0,i=i&&s==X(r)}}function tn(r,e=!1){let t;for(let n=r;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&(!e||t.node.isBlock)&&(t.dom==r||t.contentDOM==r)}function zn(r){return r.focusNode&&en(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)}function Vs(r,e){r.collapse(e.anchorNode,e.anchorOffset),(e.focusNode!=e.anchorNode||e.focusOffset!=e.anchorOffset)&&r.extend(e.focusNode,e.focusOffset)}function gc(r,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=r,t.key=t.code=e,t}function yc(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function bc(r,e,t){if(r.caretPositionFromPoint)try{let n=r.caretPositionFromPoint(e,t);if(n)return{node:n.offsetNode,offset:Math.min(X(n.offsetNode),n.offset)}}catch{}if(r.caretRangeFromPoint){let n=r.caretRangeFromPoint(e,t);if(n)return{node:n.startContainer,offset:Math.min(X(n.startContainer),n.startOffset)}}}const Ae=typeof navigator<"u"?navigator:null,$s=typeof document<"u"?document:null,Et=Ae&&Ae.userAgent||"",be=/gecko\/(\d+)/i.test(Et)&&!/edge?\//i.test(Et);be&&+(/Firefox\/(\d+)/.exec(Et)||[0,0])[1];const Cr=/Chrome\/(\d+)/.exec(Et),le=!!Cr,Hs=Cr?+Cr[1]:0,ie=!!Ae&&/Apple Computer/.test(Ae.vendor),Ot=ie&&(/Mobile\/\w+/.test(Et)||!!Ae&&Ae.maxTouchPoints>2),ye=Ot||(Ae?/Mac/.test(Ae.platform):!1),Ws=Ae?/Win/.test(Ae.platform):!1,Le=/Android \d/.test(Et),Bn=!!$s&&"webkitFontSmoothing"in $s.documentElement.style,wc=Bn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function kc(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 ze(r,e){return typeof r=="number"?r:r[e]}function xc(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 qs(r,e,t){for(;;)if(t<0?e:e<X(r)){if(_(r))return Ne(Me(r,e+(t<0?-1:0),e+(t>0?1:0)),-t);let n=r.childNodes[t<0?e-1:e];if(_(n))r=n,e=t<0?n.nodeValue.length:0;else return E(n)?Ne(n,-t):null}else{if(tn(r,!0)||!r.parentNode)return null;e=re(r)+(t<0?0:1),r=r.parentNode}}function Js(r,e,t){if(!Ar(e)&&e.left==0)return;let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;){if(!E(o)){o=At(o);continue}let l=o==s.body,a=l?kc(s):xc(o),c=0,f=0;if(e.top<a.top+ze(n,"top")?f=-(a.top-e.top+ze(i,"top")):e.bottom>a.bottom-ze(n,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+ze(i,"top")-a.top:e.bottom-a.bottom+ze(i,"bottom")),e.left<a.left+ze(n,"left")?c=-(a.left-e.left+ze(i,"left")):e.right>a.right-ze(n,"right")&&(c=e.right-a.right+ze(i,"right")),c||f)if(l)s.defaultView.scrollBy(c,f);else{let h=o.scrollLeft,u=o.scrollTop;f&&(o.scrollTop+=f),c&&(o.scrollLeft+=c);let p=o.scrollLeft-h,m=o.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}let d=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o=d=="absolute"?o.offsetParent:At(o)}}function Sc(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:Us(r.dom)}}function Us(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=At(n));return e}function Cc({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;Ks(t,n==0?0:n-e)}function Ks(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 _s(r){if(r.setActive)return r.setActive();if(Tt)return r.focus(Tt);let e=Us(r);r.focus(Tt==null?{get preventScroll(){return Tt={preventScroll:!0},!0}}:void 0),Tt||(Tt=!1,Ks(e,0))}function js(r,e){let t,n=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let f=r.firstChild,d=0;f;f=f.nextSibling,d++){let h;if(E(f))h=f.getClientRects();else if(_(f))h=Me(f).getClientRects();else continue;for(let u=0;u<h.length;u++){let p=h[u];if(p.top<=o&&p.bottom>=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right<e.left?e.left-p.right:0;if(m<n){t=f,n=m,i=m&&_(t)?{left:p.right<e.left?p.right:p.left,top:e.top}:e,E(f)&&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=f,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,n=0),t&&_(t)?Mc(t,i):!t||n?{node:r,offset:s}:js(t,i)}function Mc(r,e){let t=r.nodeValue.length,n=document.createRange(),i;for(let s=0;s<t;s++){n.setEnd(r,s+1),n.setStart(r,s);let o=Ne(n,1);if(o.top!=o.bottom&&Mr(e,o)){i={node:r,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return n.detach(),i||{node:r,offset:0}}function Mr(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Ac(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<r.getBoundingClientRect().left?t:r}function Nc(r,e,t){let{node:n,offset:i}=js(e,t),s=-1;if(E(n)&&!n.firstChild){let o=n.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return{pos:r.docView.posFromDOM(n,i,s),affinity:Ys(n,i,t)}}function Gs(r,e){return r<e.left?e.left-r:r>e.right?r-e.right:0}function Ys(r,e,t){let n=qs(r,e,-1),i=qs(r,e,1);return n?i?n.bottom<=i.top?t.top>(n.bottom+i.top)/2?1:-1:Gs(t.left,n)<Gs(t.left,i)?-1:1:-1:1}function Ec(r,e,t,n){let i=-1;for(let s=e;s!=r.dom;){let o=r.docView.nearestDesc(s,!0),l;if(!o)return null;if(E(o.dom)&&((l=o.dom.getBoundingClientRect()).width||l.height)){if(!o.contentDOM&&!o.node.isText&&n.left>=l.left&&n.left<=l.right&&n.top>=l.top&&n.top<=l.bottom){let a=o.node.isBlock?n.top<(l.top+l.bottom)/2:n.left<(l.left+l.right)/2;return{pos:a?o.posBefore:o.posAfter,affinity:a?1:-1}}o.node.isBlock&&o.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(o.dom.nodeName)&&(n.top<l.top||n.top>l.bottom)&&(i=n.top<l.top?o.posBefore:o.posAfter)}s=o.dom.parentNode}return i>-1?{pos:i,affinity:0}:{pos:r.docView.posFromDOM(e,t,-1),affinity:Ys(e,t,n)}}function Xs(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(E(o)){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Mr(e,c))return Xs(o,e,c)}}if((s=(s+1)%n)==i)break}return r}function Oc(r,e){let t=r.dom.ownerDocument,n,i=0,s=bc(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,a=0;if(!o||!r.dom.contains(o)){let f=r.dom.getBoundingClientRect();if(!Mr(e,f)||(o=Xs(r.dom,e,f),!o))return null}if(ie)for(let f=o;n&&f;f=At(f))f.draggable&&(n=void 0);if(o=Ac(o,e),n){if(be&&E(n)&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let d=n.childNodes[i],h;d.nodeName=="IMG"&&(h=d.getBoundingClientRect()).right<=e.left&&h.bottom>e.top&&i++}let f;if(Bn&&i&&E(n)&&E(f=n.childNodes[i-1])&&f.contentEditable=="false"&&f.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&E(n.lastChild)&&e.top>n.lastChild.getBoundingClientRect().bottom)l=r.state.doc.content.size;else if(i==0||!E(n)||n.childNodes[i-1].nodeName!="BR"){let d=Ec(r,n,i,e);d&&({pos:l,affinity:a}=d)}}l==null&&({pos:l,affinity:a}=Nc(r,o,e));let c=r.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1,affinity:a}}function Ar(r){return r.top<r.bottom||r.left<r.right}function Ne(r,e){let t=r.getClientRects();if(t.length){let n=t[e<0?0:t.length-1];if(Ar(n))return n}return Array.prototype.find.call(t,Ar)||r.getBoundingClientRect()}const Tc=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Zs(r,e,t){let{node:n,offset:i,atom:s}=r.docView.domFromPos(e,t<0?-1:1),o=Bn||be;if(_(n))if(o&&(Tc.test(n.nodeValue)||(t<0?!i:i==n.nodeValue.length))){let a=Ne(Me(n,i,i),t);if(be&&i&&/\s/.test(n.nodeValue[i-1])&&i<n.nodeValue.length){let c=Ne(Me(n,i-1,i-1),-1);if(c.top==a.top){let f=Ne(Me(n,i,i+1),-1);if(f.top!=a.top)return nn(f,f.left<c.left)}}return a}else{let a=i,c=i,f=t<0?1:-1;return t<0&&!i?(c++,f=-1):t>=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,nn(Ne(Me(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==X(n))){let a=n.childNodes[i-1];if(E(a))return Nr(a.getBoundingClientRect(),!1)}if(s==null&&i<X(n)){let a=n.childNodes[i];if(E(a))return Nr(a.getBoundingClientRect(),!0)}return Nr(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==X(n))){let a=n.childNodes[i-1],c=_(a)?Me(a,X(a)-(o?0:1)):E(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return nn(Ne(c,1),!1)}if(s==null&&i<X(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?_(a)?Me(a,0,o?0:1):E(a)?a:null:null;if(c)return nn(Ne(c,-1),!0)}return nn(Ne(_(n)?Me(n):n,-t),t>=0)}function nn(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 Nr(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 Qs(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 vc(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return Qs(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=Zs(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(E(l))a=l.getClientRects();else if(_(l))a=Me(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let f=a[c];if(f.bottom>f.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}const Dc=/[\u0590-\u08ac]/;function Rc(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?!Dc.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Qs(r,e,()=>{let a=r.domSel.readRange(),c=l.caretBidiLevel;l.modify("move",t,"character");let f=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:d,focusOffset:h}=r.domSel.readRange(),u=d&&!Nt(f,d)||a.focusNode==d&&a.focusOffset==h;return Vs(l,a),c!=null&&(l.caretBidiLevel=c),u}):n.pos==n.start()||n.pos==n.end()}let eo=null,to=null,no=!1;function Ic(r,e,t){return eo==e&&to==t?no:(eo=e,to=t,no=t=="up"||t=="down"?vc(r,e,t):Rc(r,e,t))}class rn{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.damage=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){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&&Nt(this.contentDOM,e))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>re(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let s=e.compareDocumentPosition(this.contentDOM);s&16?i=t>Array.from(e.childNodes).findIndex(o=>o.contains(this.contentDOM)):i=!(s&4)}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)&&!(E(o)?Nt(o,e):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){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(;n>0;n--){let s=this.children[n-1];if(s.size||!(s instanceof so||s instanceof ro&&s.side>=0))break}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?re(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?re(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=n,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let f=o+a.border;if(e>=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let d=l;d>0;d--){let h=this.children[d-1];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(1)){i=re(h.dom)+1;break}e-=h.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;f<this.children.length;f++){let d=this.children[f];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(-1)){s=re(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(!E(t)||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDamage(e){e&&(this.damage|=e,this.markParentDamage())}markParentDamage(){for(let e=this;;){let{parent:t}=e;if(!t||t.damage&1)break;t.damage|=1,e=t}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ro extends rn{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){let l=E(o)?o:document.createElement("span");l!=o&&(l.appendChild(o),o=l),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return!this.damage&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Lc extends rn{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 Je extends rn{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=lt.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Je(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.damage&4||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return!(this.damage&4)&&this.mark.eq(e)}markDamage(e){var t;this.damage|=e,(t=this.parent)===null||t===void 0||t.markDamage(2)}slice(e,t,n){let i=Je.create(this.parent,this.mark,!0,n),s=this.children,o=this.size;t<o&&(s=Or(s,t,o,n)),e>0&&(s=Or(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 Ue extends rn{constructor(e,t,n,i,s,o,l){super(e,[],s,o),this.node=t,this.outerDeco=n,this.innerDeco=i,this.nodeDOM=l}static create(e,t,n,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),f=c&&c.dom,d=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(!_(f))throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:d}=lt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let h=f;return f=ao(f,n,t),c?a=new oo(e,t,n,i,f,d||null,h,c):t.isText?new sn(e,t,n,i,f,h):new Ue(e,t,n,i,f,d||null,h)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(t.preserveWhitespace="full"),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let i=this.children[n];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(i=>E(i)&&e.indexOf(i.parentNode)<0&&this.dom.contains(i));n?t.contentElement=n:t.getContent=()=>b.empty}}return t}matchesNode(e,t,n){return!this.damage&&e.eq(this.node)&&Pn(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 Bc(this,o&&o.node,e),c=this.node.inlineContent,f=c&&this.node.isBlock;Vc(this.node,this.innerDeco,(d,h,u)=>{d.spec.marks?a.syncToMarks(d.spec.marks,n,e,h):d.type.side>=0&&!u&&a.syncToMarks(h==this.node.childCount?V.none:this.node.child(h).marks,n,e,h),a.placeWidget(d,e,i)},(d,h,u,p)=>{a.syncToMarks(d.marks,n,e,p),f&&d.isAtom&&!d.isText&&a.addHackNode("IMG",a.top);let m;a.findNodeMatch(d,h,u,p)||l&&e.state.selection.from>i&&e.state.selection.to<i+d.nodeSize&&(m=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(d,h,u,m,e,i)||a.updateNextNode(d,h,u,e,p,i)||a.addNode(d,h,u,e,i),i+=d.nodeSize,c&&(f=d.isAtom&&!d.isText)}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.damage&2)&&(o&&this.protectLocalComposition(e,o),lo(this.contentDOM,this.children,e),Ot&&$c(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof L)||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=Hc(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 Lc(this,s,t,i);e.input.compositionNodes.push(o),this.children=Or(this.children,n,n+i.length,e,o)}update(e,t,n,i,s){return this.damage&4||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i,s),!0)}updateInner(e,t,n,i,s){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,s+1),this.damage=0}updateOuterDeco(e){if(Pn(e,this.outerDeco))return;let t=!E(this.nodeDOM),n=this.dom;this.dom=Er(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(){E(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){E(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function io(r,e,t,n,i,s){s?Er(n,n,ln(s,r,!1),ln(e,r,!1)):ao(n,e,r);let o=new Ue(void 0,r,e,t,n,n,n);return o.contentDOM&&o.updateChildren(i,0),o}class sn extends Ue{constructor(e,t,n,i,s,o){super(e,t,n,i,s,null,o)}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.damage&4||this.damage&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.damage&8||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.damage=0,!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!1}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new sn(this.parent,i,this.outerDeco,this.innerDeco,s,s)}get domAtom(){return!1}isText(e){return this.node.text==e}}class so extends rn{parseRule(){return{ignore:!0}}matchesHack(e){return!this.damage&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class oo extends Ue{constructor(e,t,n,i,s,o,l,a){super(e,t,n,i,s,o,l),this.spec=a}update(e,t,n,i,s){if(this.damage&4)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,n);return o&&this.updateInner(e,t,n,i,s),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}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 lo(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=co(n),i=!0;n=n.nextSibling}else i=!0,r.insertBefore(l,n);if(o instanceof Je){let a=n?n.previousSibling:r.lastChild;lo(o.contentDOM,o.children,t),n=a?a.nextSibling:r.firstChild}}for(;n;)n=co(n),i=!0;i&&t.trackWrites==r&&(t.trackWrites=null)}const on=function(r){r&&(this.nodeName=r)};on.prototype=Object.create(null);const ft=[new on];function ln(r,e,t){if(r.length==0)return ft;let n=t?ft[0]:new on,i=[n];for(let s=0;s<r.length;s++){let o=r[s].type.attrs;if(o){o.nodeName&&i.push(n=new on(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(n=new on(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 Er(r,e,t,n){if(t==ft&&n==ft)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=ft[0]),i=a}zc(i,l||ft[0],o)}return i}function zc(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 ao(r,e,t){return Er(r,r,ft,ln(e,t,!E(r)))}function Pn(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 co(r){let e=r.nextSibling;return r.parentNode.removeChild(r),e}class Bc{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Pc(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,i){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.damage=0,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,c=this.top.children.length;i<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let f=this.index;f<c;f++){let d=this.top.children[f];if(d.matchesMark(e[o])&&!this.isLocked(d.dom)){a=f;break}}if(a<0&&this.index<this.top.children.length){let f=this.top.children[this.index];f instanceof Je&&!(f.damage&4)&&f.mark.type==e[o].type&&f.spec.update&&!this.isLocked(f.dom)&&f.spec.update(e[o])&&(f.mark=e[o],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let f=Je.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,f),this.top=f,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,n)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,i,s,o){let l=this.top.children[i];return l.damage&4&&l.dom==l.contentDOM&&(l.damage=2),l.update(e,t,n,s,o)?(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 Ue){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let f=a.dom,d,h=this.isLocked(f)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&!(a.damage&4)&&Pn(t,a.outerDeco));if(!h&&a.update(e,t,n,i,o))return this.destroyBetween(this.index,l),a.dom!=f&&(this.changed=!0),this.index++,!0;if(!h&&(d=this.recreateWrapper(a,e,t,n,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=d,d.contentDOM&&(d.damage|=2,d.updateChildren(i,o+1),d.damage=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,i,s,o){if(e.damage&3||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Pn(n,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Ue.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=Ue.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 ro(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 Je;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof sn)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((ie||le)&&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 so(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(e)&&e.contains(this.lock.parentNode))}}function Pc(r,e){let t=e,n=t.children.length,i=[],s=r.childCount,o=new Map,l=[];e:for(;s>0;){let a;for(;;)if(n){let f=t.children[n-1];if(f instanceof Je)i.push(n-1),t=f,n=f.children.length;else{a=f,n--;break}}else{if(t==e)break e;n=i.pop(),t=t.parent}let c=a.node;if(c){if(c!=r.child(s-1))break;--s,o.set(a,s),l.push(a)}}return{index:s,matched:o,matches:l.reverse()}}function Fc(r,e){return r.type.side-e.type.side}function Vc(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;c<r.childCount;c++){let f=r.child(c);n(f,i,e.forChild(s,f),c),s+=f.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let f,d;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(f?(d||(d=[f])).push(g):f=g)}if(f)if(d){d.sort(Fc);for(let g=0;g<d.length;g++)t(d[g],c,!!a)}else t(f,c,!!a);let h,u;if(a)u=-1,h=a,a=null;else if(c<r.childCount)u=c,h=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+h.nodeSize;if(h.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=h.cut(g-s),h=h.cut(0,g-s),p=g,u=-1)}else for(;o<i.length&&i[o].to<p;)o++;let m=h.isInline&&!h.isLeaf?l.filter(g=>!g.inline):l.slice();n(h,m,e.forChild(s,h),u),s=p}}function $c(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 Hc(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 Or(r,e,t,n,i){let s=[];for(let o=0,l=0;o<r.length;o++){let a=r[o],c=l,f=l+=a.size;c>=t||f<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,n)),i&&(s.push(i),i=void 0),f>t&&s.push(a.slice(t-c,a.size,n)))}return s}function Tr(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&&I.findFrom(s,e)}function Ke(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function fo(r,e,t){let n=r.state.selection;if(n instanceof L)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 Ke(r,new L(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=Tr(r.state,e);return i&&i instanceof M?Ke(r,i):!1}else if(!ye||t.indexOf("m")<0){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?M.isSelectable(s)?Ke(r,new M(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):Ke(r,new L(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(n instanceof M&&n.node.isInline)return Ke(r,new L(e>0?n.$to:n.$from));{let i=Tr(r.state,e);return i?Ke(r,i):!1}}}function an(r,e){let t=r.pmViewDesc;return t?t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR"):E(r)&&r.contentEditable=="false"}function vt(r,e){return e<0?Wc(r):qc(r)}function Wc(r){let e=r.domSel.readRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(be&&E(t)&&n<X(t)&&an(t.childNodes[n],-1)&&(o=!0);;)if(n>0){if(!E(t))break;let l=t.childNodes[n-1];if(an(l,-1))i=t,s=--n;else if(_(l))t=l,n=t.nodeValue.length;else break}else{if(ho(t))break;{let l=t.previousSibling;for(;l&&an(l,-1);)i=t.parentNode,s=re(l),l=l.previousSibling;if(l)t=l,n=X(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?vr(r,t,n):i&&vr(r,i,s)}function qc(r){let e=r.domSel.readRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=X(t),s,o;for(;;)if(n<i){if(!E(t))break;let l=t.childNodes[n];if(an(l,1))s=t,o=++n;else break}else{if(ho(t))break;{let l=t.nextSibling;for(;l&&an(l,1);)s=l.parentNode,o=re(l)+1,l=l.nextSibling;if(l)t=l,n=0,i=X(t);else{if(t=t.parentNode,t==r.dom)break;n=i=0}}}s&&vr(r,s,o)}function ho(r){for(let e=r;e;e=e.parentNode){let t=e.pmViewDesc;if(t)return t.node?t.node.isBlock:!1}return!1}function vr(r,e,t){if(!_(e)){let o,l;(l=Sr(e,t))?(e=l,t=0):(o=xr(e,t))&&(e=o,t=o.nodeValue.length)}let n=r.domSelection(),i=r.domSel.readRange();if(!n)return;zn(i)?n.collapse(e,t):n.extend&&(n.collapse(i.anchorNode,i.anchorOffset),n.extend(e,t)),r.domSel.ignore();let{state:s}=r;setTimeout(()=>{r.state==s&&r.domSel.sync()},50)}function uo(r,e){let t=r.state.doc.resolve(e);if(!(le||Ws)&&t.parent.inlineContent){let s=r.coordsAtPos(e);if(e>t.start()){let o=r.coordsAtPos(e-1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left<s.left?"ltr":"rtl"}if(e<t.end()){let o=r.coordsAtPos(e+1),l=(o.top+o.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(o.left-s.left)>1)return o.left>s.left?"ltr":"rtl"}}let n=r.dom;for(let s=t.depth;s>0;s--)if(t.node(s).isBlock){n=r.nodeDOM(t.before(s))||n;break}return getComputedStyle(n).direction=="rtl"?"rtl":"ltr"}function po(r,e,t){let n=r.state.selection;if(n instanceof L&&!n.empty||t.indexOf("s")>-1||ye&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=Tr(r.state,e);if(o&&o instanceof M)return Ke(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof ge?I.near(o,e):I.findFrom(o,e);return l?Ke(r,l):!1}return!1}function mo(r,e){if(!(r.state.selection instanceof L))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 go(r,e,t){r.domObserver.stopped(()=>e.contentEditable=t)}function Jc(r){if(!ie||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSel.readRange();if(e&&E(e)&&t==0&&e.firstChild&&E(e.firstChild)&&e.firstChild.contentEditable=="false"){let n=e.firstChild;go(r,n,"true"),setTimeout(()=>go(r,n,"false"),20)}return!1}function Uc(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Kc(r,e){let t=e.keyCode,n=Uc(e);if(t==8||ye&&t==72&&n=="c")return mo(r,-1)||vt(r,-1);if(t==46&&!e.shiftKey||ye&&t==68&&n=="c")return mo(r,1)||vt(r,1);if(t==13||t==27)return!0;if(t==37||ye&&t==66&&n=="c"){let i=t==37?uo(r,r.state.selection.from)=="ltr"?-1:1:-1;return fo(r,i,n)||vt(r,i)}else if(t==39||ye&&t==70&&n=="c"){let i=t==39?uo(r,r.state.selection.from)=="ltr"?1:-1:1;return fo(r,i,n)||vt(r,i)}else{if(t==38||ye&&t==80&&n=="c")return po(r,-1,n)||vt(r,-1);if(t==40||ye&&t==78&&n=="c")return Jc(r)||po(r,1,n)||vt(r,1);if(n==(ye?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Dr(r,e){r.someProp("transformCopied",u=>{e=u(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let u=n.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),n=u.content}let o=r.someProp("clipboardSerializer")||lt.fromSchema(r.state.schema),l=Co(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,d=0;for(;c&&E(c)&&(f=So[c.nodeName.toLowerCase()]);){for(let u=f.length-1;u>=0;u--){let p=l.createElement(f[u]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}c=a.firstChild}c&&E(c)&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let h=r.someProp("clipboardTextSerializer",u=>u(e,r))||e.content.textBetween(0,e.content.size,`
|
|
6
|
+
|
|
7
|
+
`);return{dom:a,text:h,slice:e}}function yo(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",h=>{e=h(e,s||n,r)}),s)return l=new x(b.from(r.state.schema.text(e.replace(/\r\n?/g,`
|
|
8
|
+
`))),0,0),r.someProp("transformPasted",h=>{l=h(l,r,!0)}),l;let d=r.someProp("clipboardTextParser",h=>h(e,i,n,r));if(d)l=d;else{let h=i.marks(),{schema:u}=r.state,p=lt.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,h)))})}}else r.someProp("transformPastedHTML",d=>{t=d(t,r)}),o=Yc(t),Bn&&Xc(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let d=+f[3];d>0;d--){let h=o.firstChild;for(;h&&!E(h);)h=h.nextSibling;if(!h)break;o=h}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||bt.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!_c.test(h.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Zc(xo(l,+f[1],+f[2]),f[4]);else if(l=x.maxOpen(jc(l.content,i),!0),l.openStart||l.openEnd){let d=0,h=0;for(let u=l.content.firstChild;d<l.openStart&&!u.type.spec.isolating;d++,u=u.firstChild);for(let u=l.content.lastChild;h<l.openEnd&&!u.type.spec.isolating;h++,u=u.lastChild);l=xo(l,d,h)}return r.someProp("transformPasted",d=>{l=d(l,r,n)}),l}const _c=/^(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 jc(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&&wo(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=ko(o[o.length-1],s.length));let f=bo(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return b.from(o)}return r}function bo(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,b.from(r));return r}function wo(r,e,t,n,i){if(i<r.length&&i<e.length&&r[i]==e[i]){let s=wo(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(bo(t,r,i+1))))}}function ko(r,e){if(e==0)return r;let t=r.content.replaceChild(r.childCount-1,ko(r.lastChild,e-1)),n=r.contentMatchAt(r.childCount).fillBefore(b.empty,!0);return r.copy(t.append(n))}function Rr(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=Rr(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 xo(r,e,t){return e<r.openStart&&(r=new x(Rr(r.content,-1,e,r.openStart,0,r.openEnd),e,r.openEnd)),t<r.openEnd&&(r=new x(Rr(r.content,1,t,r.openEnd,0,0),r.openStart,t)),r}const So={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function Co(){return document.implementation.createHTMLDocument("title")}let cn=null;function Gc(r){let e=window.trustedTypes;if(!e)return r;if(!cn){if(cn=e.defaultPolicy)try{return cn.createHTML(r)}catch{}cn=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return cn.createHTML(r)}function Yc(r){let e=/^(\s*<meta [^>]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=Co(),n=t.body,i=/<([a-z][^>\s]+)/i.exec(r),s;if((s=i&&So[i[1].toLowerCase()])&&(r=s.map(o=>"<"+o+">").join("")+r+s.map(o=>"</"+o+">").reverse().join("")),n.innerHTML=Gc(r),s)for(let o=0;o<s.length;o++)n=n.querySelector(s[o])||n;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let a=0;a<l.rules.length;a++){let c=l.rules[a];if(c instanceof CSSStyleRule){let f=n.querySelectorAll(c.selectorText);for(let d=0;d<f.length;d++)f[d].style.cssText+=c.style.cssText}}}return n}function Xc(r){let e=r.querySelectorAll(le?"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 Zc(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()||!a.createAndFill(null,i))break;try{i=b.from(a.create(n[l+1],i))}catch{break}s++,o++}return new x(i,s,o)}class pe{constructor(e,t,n,i){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=i}static from(e){return e instanceof pe?e:new pe(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}pe.null=new pe(null,0,null,0);class Qc{constructor(e){this.view=e,this.range=pe.null,this.active=!1,this.synced=!1,this.suppress=!1,this.currentDocument=null,this.onSelectionChange=this.onSelectionChange.bind(this)}ensureListener(){let e=this.view.dom.ownerDocument;e!=this.currentDocument&&(this.currentDocument&&this.currentDocument.removeEventListener("selectionchange",this.onSelectionChange),this.currentDocument=e,e.addEventListener("selectionchange",this.onSelectionChange))}destroy(){this.currentDocument&&(this.currentDocument.removeEventListener("selectionchange",this.onSelectionChange),this.currentDocument=null),this.active=!1,this.range=pe.null}suppressChanges(){this.suppress=!0,setTimeout(()=>this.suppress=!1,50)}onSelectionChange(){if(this.suppress&&this.view.hasFocus())return this.sync();this.read()&&this.view.domObserver.flush(!1)}readRange(){let{view:e}=this,t=e.dom.isConnected!==!1&&e.domSelection();return t?ie&&e.root.nodeType===11&&yc(e.dom.ownerDocument)==e.dom?pe.from(ef(e,t)||t):pe.from(t):pe.null}read(){this.ensureListener();let e=Do(this.view);if(!e){this.active=!1,this.range=pe.null;return}return this.active=!0,this.range.eq(e)?!1:(this.range=e,this.synced=!1,!0)}sync(e=!1){let{view:t}=this;t.docView&&(this.ensureListener(),t.domObserver.stopped(()=>{of(t,t.state.selection);let n=t.state.selection;if(t.input.mouseSelecting||Ao(t)){let{desc:i,start:s}=No(t.docView,n.from,n.to,0);t.cursorWrapper?sf(t):i instanceof oo&&i.spec.setSelection?i.spec.setSelection(n.anchor-s,n.head-s,t.root):tf(t,e,i,s),this.synced=this.active=!0}n.visible==t.dom.classList.contains("ProseMirror-hideselection")&&(n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),rf(t))),this.range=this.readRange()}))}ignore(e=this.readRange()){this.range=pe.from(e),this.synced=!0}deactivate(){this.range=pe.null,this.active=this.synced=!1}}function ef(r,e){if(e.getComposedRanges){let i=e.getComposedRanges({shadowRoots:[r.root]})[0];if(i)return Mo(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?Mo(r,t):null}function Mo(r,e){let t=e.startContainer,n=e.startOffset,i=e.endContainer,s=e.endOffset,o=r.domAtPos(r.state.selection.anchor);return en(o.node,o.offset,i,s)&&([t,n,i,s]=[i,s,t,n]),new pe(t,n,i,s)}function Ir(r,e,t=null){let n=r.state.doc;if(!e.focusNode)return null;let i=r.docView.nearestDesc(e.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(e.focusNode,e.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,c;if(zn(e)){for(a=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&M.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&mc(e.focusNode,e.focusOffset,i.dom))){let d=i.posBefore;c=new M(o==d?l:n.resolve(d))}else if(be&&t=="key"&&o>r.state.selection.to&&E(e.focusNode)&&e.focusOffset==e.focusNode.childNodes.length&&i&&i.posAtStart>r.state.selection.to)for(let d=e.focusNode;;d=d.parentNode){if(getComputedStyle(d).overflow!="visible"){c=I.findFrom(n.resolve(i.posAtStart),1);break}if(d==i.dom||d.nextSibling||!d.parentNode||!E(d.parentNode))break}}else{if(e instanceof r.dom.ownerDocument.defaultView.Selection&&e.rangeCount>1){let d=o,h=o;for(let u=0;u<e.rangeCount;u++){let p=e.getRangeAt(u);d=Math.min(d,r.docView.posFromDOM(p.startContainer,p.startOffset,1)),h=Math.max(h,r.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(d<0)return null;[a,o]=h==r.state.selection.anchor?[h,d]:[d,h],l=n.resolve(o)}else a=r.docView.posFromDOM(e.anchorNode,e.anchorOffset,1);if(a<0)return null}let f=n.resolve(a);if(!c){let d=t=="pointer"||r.state.selection.head<l.pos&&!s?1:-1;c=Dt(r,f,l,d)}return c}function Ao(r){return r.editable?r.hasFocus():Ro(r,r.domSel.readRange())&&(!document.activeElement||document.activeElement.contains(r.dom))}function tf(r,e,t,n){let i=r.state.selection,{anchor:s,head:o}=i,l,a;Eo&&!(i instanceof L)&&(i.$from.parent.inlineContent||(l=Oo(r,i.from)),!i.empty&&!i.$from.parent.inlineContent&&(a=Oo(r,i.to)));let c=t.domFromPos(s-n,s>n?-1:1),f=o==s?c:t.domFromPos(o-n,o>n?-1:1);nf(s,o,c,f,r,e),Eo&&(l&&To(l),a&&To(a))}function No(r,e,t,n=0){for(let i=0,s=n;i<r.children.length;i++){let o=r.children[i],l=s+o.size;if(e>s&&t<l)return No(o,e,t,s+o.border);s=l}return{desc:r,start:n}}function nf(r,e,t,n,i,s){let o=!1;if((be||ie)&&r==e){let{node:f,offset:d}=t;if(_(f)){if(o=!!(d&&f.nodeValue[d-1]==`
|
|
9
|
+
`),o&&d==f.nodeValue.length)for(let h=f,u;h;h=h.parentNode){if(u=h.nextSibling){u.nodeName=="BR"&&(t=n={node:u.parentNode,offset:re(u)+1});break}let p=h.pmViewDesc;if(p&&p.node&&p.node.isBlock)break}}else{let h=f.childNodes[d-1];o=h&&(h.nodeName=="BR"||h.contentEditable=="false")}}let l=i.domSel.readRange();if(be&&l.focusNode&&l.focusNode!=n.node&&E(l.focusNode)){let f=l.focusNode.childNodes[l.focusOffset];f&&f.contentEditable=="false"&&(s=!0)}if(!(s||o&&ie)&&en(t.node,t.offset,l.anchorNode,l.anchorOffset)&&en(n.node,n.offset,l.focusNode,l.focusOffset))return;let a=i.domSelection(),c=i.input.mouseSelecting;if(c&&c.affinity&&r==e&&c.pos==r){let{affinity:f}=c,{node:d,offset:h}=n,u,p=0;if(_(d)&&(f>0?h<X(d):h>0)?(u=d,p=h+f):(u=(f>0?Sr:xr)(d,h),u&&(p=f>0?1:u.nodeValue.length-1)),u){a.collapse(u,p),a.modify("move",f>0?"backward":"forward","lineboundary");let{focusNode:m,focusOffset:g}=a;if(ie&&i.root.nodeType==11){let y=a.getComposedRanges({shadowRoots:[i.root]});y.length&&(m=y[0].startContainer,g=y[0].startOffset)}if(en(d,h,m,g))return}}Vs(a,{focusNode:n.node,focusOffset:n.offset,anchorNode:t.node,anchorOffset:t.offset})}const Eo=ie||le&&Hs<63;function Oo(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(ie&&i&&i.contentEditable=="false")return Lr(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return Lr(i);if(s)return Lr(s)}}function Lr(r){return r.contentEditable="true",ie&&r.draggable&&(r.draggable=!1,r.wasDraggable=!0),r}function To(r){r.contentEditable="false",r.wasDraggable&&(r.draggable=!0,r.wasDraggable=null)}function rf(r){let e=r.dom.ownerDocument;e.removeEventListener("selectionchange",r.input.hideSelectionGuard);let t=r.domSel.readRange(),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(()=>{(!Ao(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function sf(r){let e=r.domSelection();if(!e)return;let t=r.cursorWrapper.dom;t.nodeName=="IMG"?e.collapse(t.parentNode,re(t)+1):e.collapse(t,0)}function of(r,e){if(e instanceof M){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(vo(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else vo(r)}function vo(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Dt(r,e,t,n){let i=r.someProp("createSelectionBetween",s=>s(r,e,t))||L.between(e,t,n);return r.someProp("adjustSelectionFromDOM",s=>{i=s(r,i)}),i}function Do(r){if(r.editable&&!r.hasFocus())return null;let e=r.domSel.readRange();return e&&Ro(r,e)?e:null}function Ro(r,e){if(!e.anchorNode)return!1;try{return Nt(r.dom,e.anchorNode)&&(r.editable||Nt(r.dom,e.focusNode))}catch{return!1}}const ae={},ce={},lf={touchstart:!0,touchmove:!0};class af{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastKeyDispatched=!1,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.mouseSelecting=null,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function cf(r){for(let e in ae){let t=ae[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{df(r,n)&&(r.input.composing&&(n.type=="keydown"||n.type=="beforeinput")&&n.isComposing===!1&&Vo(r,!0),!Br(r,n)&&(r.editable||!(n.type in ce))&&t(r,n))},lf[e]?{passive:!0}:void 0)}ie&&r.dom.addEventListener("input",()=>null),zr(r)}function Fn(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function ff(r){r.input.mouseDown&&r.input.mouseDown.done(),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 zr(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Br(r,n))})}function Br(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function df(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 hf(r,e){!Br(r,e)&&ae[e.type]&&(r.editable||!(e.type in ce))&&ae[e.type](r,e)}function _e(r,e){let{input:t}=r;return t.lastKeyDispatched||r.composing?!1:(t.lastKeyDispatched=!0,typeof e=="string"&&(e=gc(e=="Backspace"?8:13,e)),r.someProp("handleKeyDown",n=>n(r,e)))}ce.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),r.input.lastKeyDispatched=!1,!(Le&&le&&t.keyCode==13)){if(Ot&&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&&(_e(r,"Enter"),r.input.lastIOSEnter=0)},200);return}t.keyCode!=229&&r.domObserver.forceFlush(!0),_e(r,t)||Kc(r,t)?t.preventDefault():Fn(r,"key")}},ce.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)},ce.keypress=(r,e)=>{let t=e;if(xf(r)||!t.charCode||t.ctrlKey&&!t.altKey||ye&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof L)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode),s=()=>r.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",o=>o(r,n.$from.pos,n.$to.pos,i,s))&&r.dispatch(s()),t.preventDefault()}};function fn(r){return{left:r.clientX,top:r.clientY}}function uf(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Pr(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 Io(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 pf(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&M.isSelectable(n)?(Io(r,new M(t)),!0):!1}function mf(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof M&&(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(M.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?(Io(r,M.create(r.state.doc,i)),!0):!1}function gf(r,e,t,n,i){return Pr(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?mf(r,t):pf(r,t))}function yf(r,e,t,n){return Pr(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function bf(r,e,t,n){return Pr(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))}function Lo(r,e,t){if(e==-1)return r.inlineContent?L.create(r,0,r.content.size):null;let n=r.resolve(e);for(let i=n.depth+1;i>0;i--){let s=i>n.depth?n.nodeAfter:n.node(i),o=n.before(i);if(s.inlineContent)return L.create(r,o+1,o+1+s.content.size);if(t&&M.isSelectable(s))return M.create(r,o)}return null}let Fr=/[\w_\u00a1-\uffff]+/g;try{Fr=new RegExp("[\\p{L}\\p{N}_]+","gu")}catch{}function zo(r,e){let t=r.resolve(e),n=t.node(),i="",s=e,o=e;for(let m=t.indexAfter(),g=!1;m>0;m--){let y=n.child(m-1);if(!y.text)break;let O=s==e?e-t.posAtIndex(m-1):y.text.length,w=O;for(;w>0;w--)if(/\S/.test(y.text[w-1]))g=!0;else if(g)break;if(i=y.text.slice(w,O)+i,s-=O-w,w||s<e-50)break}for(let m=t.index(),g=!1;m<n.childCount;m++){let y=n.child(m);if(!y.text)break;let O=o==e?e-t.posAtIndex(m):0,w=O;for(;w<y.text.length;w++)if(/\S/.test(y.text[w]))g=!0;else if(g)break;if(i+=y.text.slice(O,w),o+=w-O,w<y.text.length||o>e+50)break}let l=s,a=o;if(Intl.Segmenter){for(let m of new Intl.Segmenter(void 0,{granularity:"word"}).segment(i))if(m.isWordLike){let g=m.index+s,y=g+m.segment.length;if(y<e)l=y;else if(g>e){a=g;break}else return L.create(r,g,y)}}else{Fr.lastIndex=0;for(let m;m=Fr.exec(i);){let g=m.index+s,y=g+m[0].length;if(y<e)l=y;else if(g>e){a=g;break}else return L.create(r,g,y)}}let c=i.slice(l-s,e-s),f=i.slice(e-s,a-s),d=/\S*$/.exec(c)[0].length,h=/^\S*/.exec(f)[0].length;if(d||h)return L.create(r,e-d,e+h);let u=/\s*$/.exec(c)[0].length,p=/^\s*/.exec(f)[0].length;return L.create(r,e-u,e+p)}const Bo=ye?"metaKey":"ctrlKey";ae.mousedown=(r,e)=>{let t=e,n=Date.now();if(r.input.shiftKey=t.shiftKey,r.input.lastTouch>n-500)return!1;dt(r);let i="singleClick";n-r.input.lastClick.time<500&&uf(t,r.input.lastClick)&&!t[Bo]&&r.input.lastClick.button==t.button&&(r.input.lastClick.type=="singleClick"?i="doubleClick":r.input.lastClick.type=="doubleClick"&&(i="tripleClick")),r.input.lastClick={time:n,x:t.clientX,y:t.clientY,type:i,button:t.button},r.input.mouseDown&&r.input.mouseDown.done();let s=r.posAtCoords(fn(t));if(s)if(t.button==0){if(!r.hasFocus()){_s(r.dom);let l=r.root.activeElement;l&&!l.contains(r.dom)&&l.blur()}(r.input.mouseDown=new wf(r,s,t,i)).mightDrag||t.preventDefault()}else Fn(r,"pointer")};class wf{constructor(e,t,n,i){var s;this.view=e,this.startPos=t,this.event=n,this.type=i,this.didMove=!1,this.lastPos=-1,this.anchorRange=null,this.startDoc=e.state.doc,this.selectNode=!!n[Bo],this.extend=n.shiftKey,this.anchorDoc=this.startDoc;let o=Po(e);if(this.extend){let l=e.state.selection;this.anchorRange=l instanceof M?{from:l.from,to:l.to}:{from:l.anchor,to:l.anchor};let a=l instanceof M?e.nodeDOM(l.from).getBoundingClientRect():e.coordsAtPos(l.anchor);this.anchorOffset={x:(a.left+a.right)/2-o.x,y:(a.top+a.bottom)/2-o.y}}else this.anchorOffset={x:n.clientX-o.x,y:n.clientY-o.y};if(i=="singleClick"){let{selection:l}=e.state,a,c,f=!1;if(l instanceof M&&l.from<=t.pos&&l.to>=t.pos)c=l.from,a=l.node,f=!0;else if(t.inside>-1)a=e.state.doc.nodeAt(t.inside),c=t.inside;else{let d=e.state.doc.resolve(t.pos);a=d.parent,c=d.depth?d.before():-1}if(f||c>-1&&a.type.spec.draggable&&a.type.spec.selectable!==!1){let d=(s=e.docView.descAt(c))===null||s===void 0?void 0:s.nodeDOM;this.mightDrag={node:a,elt:d,pos:c,addAttr:!1},d&&!d.draggable&&(this.mightDrag.addAttr=!0,e.domObserver.stopped(()=>d.draggable=!0))}else this.mightDrag=kf(e,n)}else this.mightDrag=!1;e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),this.mightDrag||this.select(this.startPos,!0)}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null),typeof this.mightDrag=="object"&&this.mightDrag.addAttr&&this.view.domObserver.stopped(()=>this.mightDrag.elt.removeAttribute("draggable"))}maybeRunHandler(e,t){return(this.type=="singleClick"?gf:this.type=="doubleClick"?yf:bf)(this.view,e.pos,e.inside,t,this.selectNode)}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.startPos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fn(e))),t&&(this.didMove||this.maybeRunHandler(t,e)||this.select(t,!0),e.preventDefault())}move(e){if(e.buttons==0){this.done();return}if(!this.didMove&&(Math.abs(this.event.x-e.clientX)>8||Math.abs(this.event.y-e.clientY)>8)&&(this.didMove=!0,this.mightDrag=!1),!this.mightDrag){let t=this.view.posAtCoords(fn(e));t&&this.select(t,!1)}e.preventDefault()}select(e,t){if(e.pos==this.lastPos)return;this.lastPos=e.pos;let{view:n}=this,{doc:i}=n.state,s=this.type=="singleClick"?Fo(n,i,e):this.type=="doubleClick"?zo(i,e.pos):Lo(i,e.inside,t);s&&(t&&!this.extend?this.anchorRange=s:(!t||this.extend)&&(i.eq(this.anchorDoc)||this.restoreAnchor(),this.anchorRange&&this.anchorRange.from<s.from?s=Dt(n,i.resolve(this.anchorRange.from),i.resolve(s.to)):this.anchorRange&&this.anchorRange.to>s.to&&(s=Dt(n,i.resolve(this.anchorRange.to),i.resolve(s.from)))),s.eq(n.state.selection)||(n.input.mouseSelecting=e,n.dispatch(n.state.tr.setSelection(s).setMeta("pointer",!0).scrollIntoView()),n.input.mouseSelecting=null))}restoreAnchor(){let e=Po(this.view),t=this.view.posAtCoords({left:this.anchorOffset.x+e.x,top:this.anchorOffset.y+e.y});if(!t)this.anchorRange=null;else{let{doc:n}=this.view.state;this.anchorRange=this.type=="singleClick"?Fo(this.view,n,t):this.type=="doubleClick"?zo(n,t.pos):Lo(n,t.inside,!1),this.anchorDoc=this.view.state.doc}}}function Po(r){let e=r.dom.getBoundingClientRect();return{x:e.left-r.dom.scrollLeft,y:e.top-r.dom.scrollTop}}function Fo(r,e,t){if(t.inside>-1){let i=e.nodeAt(t.inside);if(i.isAtom&&M.isSelectable(i))return M.create(e,t.inside)}let n=e.resolve(t.pos);return Dt(r,n,n)}function kf(r,e){let{selection:t}=r.state;if(t.empty)return!1;let n=r.domSelection();if(!n||n.rangeCount==0)return!0;let i=n.getRangeAt(0).getClientRects();for(let s=0;s<i.length;s++){let o=i[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}ae.touchstart=r=>{r.input.lastTouch=Date.now(),dt(r),Fn(r,"pointer")},ae.touchmove=r=>{r.input.lastTouch=Date.now(),Fn(r,"pointer")},ae.contextmenu=r=>dt(r);function xf(r,e){return r.composing?!0:ie&&Math.abs(Date.now()-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const Sf=Le?5e3:-1;ce.compositionstart=ce.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof L&&e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||le&&Ws&&Cf(r)))r.markCursor=r.state.storedMarks||t.marks(),dt(r,!0),r.markCursor=null;else if(dt(r,!e.selection.empty),be&&r.domSel.active&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length)for(let{focusNode:n,focusOffset:i}=r.domSel.range;n&&E(n)&&i!=0;){let s=i<0?n.lastChild:n.childNodes[i-1];if(!s)break;if(_(s)){let o=r.domSelection();o&&o.collapse(s,s.nodeValue.length);break}else n=s,i=-1}r.input.composing=!0}$o(r,Sf)};function Cf(r){let{focusNode:e,focusOffset:t}=r.domSel.range;if(!e||!E(e)||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return E(n)&&n.contentEditable=="false"}ce.compositionend=(r,e)=>{r.composing&&Vo(r)};function Vo(r,e=!1){r.input.composing=!1,r.input.compositionEndedAt=Date.now(),r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionNode=null,r.input.badSafariComposition?r.domObserver.forceFlush():r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,e?dt(r):$o(r,20)}function $o(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>dt(r),e))}function Ho(r){r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Date.now());for(let e;e=r.input.compositionNodes.pop();)e.markParentDamage()}function Mf(r){let e=r.domSel.range;if(!r.domSel.active||!e.focusNode)return null;let t=xr(e.focusNode,e.focusOffset),n=Sr(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 dt(r,e=!1){if(!(Le&&r.domObserver.flushingSoon>=0)&&(r.domObserver.forceFlush(),Ho(r),e||r.docView&&r.docView.damage)){let t=Ir(r,r.domSel.readRange()),n=r.state.selection;t&&!t.eq(n)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state)}}function Af(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 dn=Ot&&wc<604;ae.copy=ce.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=dn?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Dr(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Af(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Nf(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function Ef(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?hn(r,n.value,null,i,e):hn(r,n.textContent,n.innerHTML,i,e)},50)}function hn(r,e,t,n,i){let s=yo(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||x.empty)))return!0;if(!s)return!1;let o=Nf(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 Wo(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," "):""}ce.paste=(r,e)=>{let t=e;if(r.composing&&!Le)return;let n=dn?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&hn(r,Wo(n),n.getData("text/html"),i,t)?t.preventDefault():Ef(r,t)};class qo{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Of=ye?"altKey":"ctrlKey";function Jo(r,e){let t;return r.someProp("dragCopies",n=>{t=t||n(e)}),t!=null?!t:!e[Of]}ae.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(fn(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof M?i.to-1:i.to))){if(n&&typeof n.mightDrag=="object")o=M.create(r.state.doc,n.mightDrag.pos);else if(t.target&&E(t.target)){let d=r.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=r.docView&&(o=M.create(r.state.doc,d.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=Dr(r,l);(!t.dataTransfer.files.length||!le||Hs>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(dn?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",dn||t.dataTransfer.setData("text/plain",c),r.dragging=new qo(f,Jo(r,t),o)},ae.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)},ce.dragover=ce.dragenter=(r,e)=>e.preventDefault(),ce.drop=(r,e)=>{try{Tf(r,e,r.dragging)}finally{r.dragging=null}};function Tf(r,e,t){if(!e.dataTransfer)return;let n=r.posAtCoords(fn(e));if(!n)return;let i=r.state.doc.resolve(n.pos),s=t&&t.slice;s?r.someProp("transformPasted",u=>{s=u(s,r,!1)}):s=yo(r,Wo(e.dataTransfer),dn?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Jo(r,e));if(r.someProp("handleDrop",u=>u(r,e,s||x.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?ks(r.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=r.state.tr;if(o){let{node:u}=t;u?u.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(d))return;let h=a.doc.resolve(c);if(f&&M.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new M(h));else{let u=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,y)=>u=y),a.setSelection(Dt(r,h,a.doc.resolve(u)))}r.focus(),r.dispatch(a.setMeta("uiEvent","drop"))}ae.focus=r=>{if(r.input.lastFocus=Date.now(),!r.focused&&(r.domObserver.stopped(()=>r.dom.classList.add("ProseMirror-focused")),r.focused=!0,r.domSel.read(),!r.domSel.synced)){let e=r.domSel.range;setTimeout(()=>{let t=r.domSel.readRange();t&&e.eq(t)&&r.domSel.sync()},20)}},ae.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stopped(()=>r.dom.classList.remove("ProseMirror-focused")),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domSel.deactivate(),r.focused=!1)},ae.beforeinput=(r,e)=>{if(Le&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||r.domObserver.pendingRecords().length||(r.dom.blur(),r.focus(),_e(r,"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 ce)ae[r]=ce[r];function un(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 Vr{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index<this.frag.childCount;){let t=this.frag.child(this.index);if(this.off==e)return t;this.off+=t.nodeSize,this.index++}return null}}class Vn{constructor(e,t){this.toDOM=e,this.spec=t||ht,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 fe(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Vn&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&un(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class je{constructor(e,t){this.attrs=e,this.spec=t||ht}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 fe(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof je&&un(this.attrs,e.attrs)&&un(this.spec,e.spec)}static is(e){return e.type instanceof je}destroy(){}}class $r{constructor(e,t){this.attrs=e,this.spec=t||ht}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 fe(s.pos-n,o.pos-n,this)}valid(e,t,n){let i=n.nodeAt(t.from);return!!i&&!i.isText&&t.from+i.nodeSize==t.to}eq(e){return this==e||e instanceof $r&&un(this.attrs,e.attrs)&&un(this.spec,e.spec)}destroy(){}}class fe{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new fe(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 fe(e,e,new Vn(t,n))}static inline(e,t,n,i){return new fe(e,t,new je(n,i))}static node(e,t,n,i){return new fe(e,t,new $r(n,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof je}get widget(){return this.type instanceof Vn}}const Rt=[],ht={};class q{constructor(e,t){this.local=e.length?e:Rt,this.children=t.length?t:Rt}static create(e,t){return t.length?$n(t,e,0,ht):se}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];if(l.from>t)break;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&&!(this.children[o]>=t);o+=3)if(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==se||e.maps.length==0?this:this.mapInner(e,t,0,0,n||ht)}mapInner(e,t,n,i,s){let o;if(this.local.length){let l=new Vr(t.content);for(let a=0;a<this.local.length;a++){let c=this.local[a].map(e,n,i);c&&c.type.valid(t,c,l)?(o||(o=[])).push(c):s.onRemove&&s.onRemove(this.local[a].spec)}}return this.children.length?vf(this.children,o||[],e,t,n,i,s):o?new q(o.sort(Ye),Rt):se}add(e,t){return t.length?this==se?q.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let i,s=0;e.forEach((l,a)=>{let c=a+n,f;if(f=Ko(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,f,c+1):i.splice(s,0,a,a+l.nodeSize,$n(f,l,c+1,ht)),s+=3}});let o=Uo(s?_o(t):t,-n).sort(Ye);if(o.length){let l=new Vr(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||o.splice(a--,1)}return new q(o.length?this.local.concat(o).sort(Ye):this.local,i||this.children)}remove(e){return e.length==0||this==se?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,i=this.local;for(let s=0;s<n.length;s+=3){let o,l=n[s]+t,a=n[s+1]+t;for(let f=0,d;f<e.length;f++)(d=e[f])&&d.from>l&&d.to<a&&(e[f]=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!=se?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 q(i,n):se}forChild(e,t){if(this==se)return this;if(t.isLeaf)return q.empty;let n,i,s=0,o=this.children.length/3;for(;s<o;){let c=s+o>>>1,f=c*3,d=this.children[f];if(d<e)s=c+1;else if(d>e)o=c;else{n=this.children[f+2];break}}let l=e+1,a=l+t.content.size;for(let c=0;c<this.local.length;c++){let f=this.local[c];if(f.from<a&&f.to>l&&f.type instanceof je){let d=Math.max(l,f.from)-l,h=Math.min(a,f.to)-l;d<h&&(i||(i=[])).push(f.copy(d,h))}}if(i){let c=new q(i.sort(Ye),Rt);return n?new Ge([c,n]):c}return n||se}eq(e){if(this==e)return!0;if(!(e instanceof q)||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 Hr(this.localsInner(e))}localsInner(e){if(this==se)return Rt;if(e.inlineContent||!this.local.some(je.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof je||t.push(this.local[n]);return t}forEachSet(e){e(this)}}q.empty=new q([],[]),q.removeOverlap=Hr;const se=q.empty;class Ge{constructor(e){this.members=e}map(e,t){const n=this.members.map(i=>i.map(e,t,ht));return Ge.from(n)}forChild(e,t){if(t.isLeaf)return q.empty;let n=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=se&&(s instanceof Ge?n=n.concat(s.members):n.push(s))}return Ge.from(n)}eq(e){if(!(e instanceof Ge)||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?Hr(n?t:t.sort(Ye)):Rt}static from(e){switch(e.length){case 0:return se;case 1:return e[0];default:return new Ge(e.every(t=>t instanceof q)?e:e.reduce((t,n)=>t.concat(n instanceof q?n:n.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function vf(r,e,t,n,i,s,o){let l=r.slice();for(let c=0,f=s;c<t.maps.length;c++){let d=0;t.maps[c].forEach((h,u,p,m)=>{let g=m-p-(u-h);for(let y=0;y<l.length;y+=3){let O=l[y+1];if(O<0||h>O+f-d)continue;let w=l[y]+f-d;u>=w?l[y+1]=h<=w?-2:-1:h>=f&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let f=t.map(r[c]+s),d=f-i;if(d<0||d>=n.content.size){a=!0;continue}let h=t.map(r[c+1]+s,-1),u=h-i,{index:p,offset:m}=n.content.findIndex(d),g=n.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);y!=se?(l[c]=d,l[c+1]=u,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Df(l,r,e,t,i,s,o),f=$n(c,n,0,o);e=f.local;for(let d=0;d<l.length;d+=3)l[d+1]<0&&(l.splice(d,3),d-=3);for(let d=0,h=0;d<f.children.length;d+=3){let u=f.children[d];for(;h<l.length&&l[h]<u;)h+=3;l.splice(h,0,f.children[d],f.children[d+1],f.children[d+2])}}return new q(e.sort(Ye),l)}function Uo(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 fe(i.from+e,i.to+e,i.type))}return t}function Df(r,e,t,n,i,s,o){function l(a,c){for(let f=0;f<a.local.length;f++){let d=a.local[f].map(n,i,c);d?t.push(d):o.onRemove&&o.onRemove(a.local[f].spec)}for(let f=0;f<a.children.length;f+=3)l(a.children[f+2],a.children[f]+c+1)}for(let a=0;a<r.length;a+=3)r[a+1]==-1&&l(r[a+2],e[a]+s+1);return t}function Ko(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 _o(r){let e=[];for(let t=0;t<r.length;t++)r[t]!=null&&e.push(r[t]);return e}function $n(r,e,t,n){let i=[],s=!1;e.forEach((l,a)=>{let c=Ko(r,l,a+t);if(c){s=!0;let f=$n(c,l,t+a+1,n);f!=se&&i.push(a,a+l.nodeSize,f)}});let o=Uo(s?_o(r):r,-t).sort(Ye);if(o.length){let l=new Vr(e.content);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a],l)||(n.onRemove&&n.onRemove(o[a].spec),o.splice(a--,1))}return o.length||i.length?new q(o,i):se}function Ye(r,e){return r.from-e.from||r.to-e.to}function Hr(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),jo(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),jo(e,i,n.copy(s.from,n.to)));break}}}return e}function jo(r,e,t){for(;e<r.length&&Ye(t,r[e])>0;)e++;r.splice(e,0,t)}function Wr(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=se&&e.push(n)}),r.cursorWrapper&&e.push(q.create(r.state.doc,[r.cursorWrapper.deco])),Ge.from(e)}function Rf(r,e,t,n){let{node:i,fromOffset:s,toOffset:o,from:l,to:a}=r.docView.parseRange(e,t),c=r.domSel.range,f,d=c.anchorNode;if(d&&Nt(r.dom,d)&&(f=[{node:d,offset:c.anchorOffset}],zn(c)||f.push({node:c.focusNode,offset:c.focusOffset})),le&&r.input.lastKeyCode===8)for(let y=o;y>s;y--){let O=i.childNodes[y-1],w=O.pmViewDesc;if(O.nodeName=="BR"&&!w){o=y;break}if(!w||w.size)break}let h=r.state.doc,u=r.someProp("domParser")||bt.fromSchema(r.state.schema),p=h.resolve(l),m=null,g=u.parse(i,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:s,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:If(n),context:p});if(f&&f[0].pos!=null){let y=f[0].pos,O=f[1]&&f[1].pos;O==null&&(O=y),m={anchor:y+l,head:O+l}}return{doc:g,sel:m,from:l,to:a}}const If=r=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(r);if(e.nodeName=="BR"&&e.parentNode){if(ie&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(e.parentNode.lastChild==e||ie&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},Lf=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function zf(r,e,t,n,i,s){let o=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let B=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,U=Ir(r,r.domSel.range,B);if(U&&!r.state.selection.eq(U)&&r.domSel.active){if(le&&Le&&r.input.lastKeyCode===13&&Date.now()-100<r.input.lastKeyCodeTime&&_e(r,"Enter"))return;let ue=r.state.tr.setSelection(U);B=="pointer"?ue.setMeta("pointer",!0):B=="key"&&ue.scrollIntoView(),o&&ue.setMeta("composition",o),r.dispatch(ue)}return}let l=r.state.doc.resolve(e),a=l.sharedDepth(t);e=l.before(a+1),t=r.state.doc.resolve(t).after(a+1);let c=r.state.selection,f=Rf(r,e,t,s),d=r.state.doc,h=d.slice(f.from,f.to),u,p;r.input.lastKeyCode===8&&Date.now()-100<r.input.lastKeyCodeTime?(u=r.state.selection.to,p="end"):(u=r.state.selection.from,p="start"),r.input.lastKeyCode=null;let m=Vf(h.content,f.doc.content,f.from,u,p);if(m&&r.input.domChangeCount++,(Ot&&r.input.lastIOSEnter>Date.now()-225||Le)&&s.some(B=>E(B)&&!Lf.test(B.nodeName))&&(!m||m.endA>=m.endB)&&_e(r,"Enter")){r.input.lastIOSEnter=0;return}if(!m)if(i&&c instanceof L&&!c.empty&&c.$head.sameParent(c.$anchor)&&!r.composing&&!(f.sel&&f.sel.anchor!=f.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(f.sel){let B=Go(r,r.state.doc,f.sel);if(B&&!B.eq(r.state.selection)){let U=r.state.tr.setSelection(B);o&&U.setMeta("composition",o),r.dispatch(U)}}return}r.state.selection.from<r.state.selection.to&&m.start==m.endB&&r.state.selection instanceof L&&(m.start>r.state.selection.from&&m.start<=r.state.selection.from+2&&r.state.selection.from>=f.from?m.start=r.state.selection.from:m.endA<r.state.selection.to&&m.endA>=r.state.selection.to-2&&r.state.selection.to<=f.to&&(m.endB+=r.state.selection.to-m.endA,m.endA=r.state.selection.to));let g=f.doc.resolveNoCache(m.start-f.from),y=f.doc.resolveNoCache(m.endB-f.from),O=d.resolve(m.start),w=g.sameParent(y)&&g.parent.inlineContent&&O.end()>=m.endA;if((Ot&&r.input.lastIOSEnter>Date.now()-225&&(!w||s.some(B=>B.nodeName=="DIV"||B.nodeName=="P"))||!w&&Ff(f.doc,g.pos,y.pos))&&_e(r,"Enter")){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>m.start&&(w?m.endA>m.start&&m.endB==m.start:Pf(d,m.start,m.endA,g,y))&&_e(r,"Backspace")){Le&&le&&r.domSel.suppressChanges();return}le&&m.endB==m.start&&(r.input.lastChromeDelete=Date.now()),Le&&!w&&g.start()!=y.start()&&y.parentOffset==0&&g.depth==y.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==m.endA&&(m.endB-=2,y=f.doc.resolveNoCache(m.endB-f.from),setTimeout(()=>_e(r,"Enter"),20));let v=m.start,D=m.endA,$=B=>{let U=B||r.state.tr.replace(v,D,f.doc.slice(m.start-f.from,m.endB-f.from));if(f.sel){let ue=Go(r,U.doc,f.sel);ue&&!(le&&r.composing&&ue.empty&&(m.start!=m.endB||r.input.lastChromeDelete<Date.now()-100)&&(ue.head==v||ue.head==U.mapping.map(D)-1))&&U.setSelection(ue)}return o&&U.setMeta("composition",o),U.scrollIntoView()},H;if(w)if(g.pos==y.pos){let B=$(r.state.tr.delete(v,D)),U=d.resolve(m.start).marksAcross(d.resolve(m.endA));U&&B.ensureMarks(U),r.dispatch(B)}else if(m.endA==m.endB&&(H=Bf(g.parent.content.cut(g.parentOffset,y.parentOffset),O.parent.content.cut(O.parentOffset,m.endA-O.start())))){let B=$(r.state.tr);H.type=="add"?B.addMark(v,D,H.mark):B.removeMark(v,D,H.mark),r.dispatch(B)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let B=g.parent.textBetween(g.parentOffset,y.parentOffset),U=()=>$(r.state.tr.insertText(B,v,D));r.someProp("handleTextInput",ue=>ue(r,v,D,B,U))||r.dispatch(U())}else r.dispatch($());else r.dispatch($())}function Go(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Dt(r,e.resolve(t.anchor),e.resolve(t.head))}function Bf(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let f=0;f<n.length;f++)i=n[f].removeFromSet(i);for(let f=0;f<t.length;f++)s=t[f].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=f=>f.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;f<e.childCount;f++)c.push(a(e.child(f)));if(b.from(c).eq(r))return{mark:l,type:o}}function Pf(r,e,t,n,i){if(t-e<=i.pos-n.pos||qr(n,!0,!1)<i.pos)return!1;let s=r.resolve(e);if(!n.parent.inlineContent){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(qr(s,!0,!0));return!o.parent.isTextblock||o.pos>t||qr(o,!0,!1)<t?!1:n.parent.content.cut(n.parentOffset).eq(o.parent.content)}function Ff(r,e,t){let n=0,i=0;return r.nodesBetween(e,t,(s,o)=>{s.isTextblock&&o>=e&&o<t?n++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-o),Math.min(s.nodeSize,t-o))):s.isLeaf)&&i++}),i==0&&n==1}function qr(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 Vf(r,e,t,n,i){let s=r.findDiffStart(e,t),o=t+r.size,l=t+e.size;if(s==null)return null;let{a,b:c}=r.findDiffEnd(e,o,l);if(i=="end"){let f=Math.max(0,s-Math.min(a,c));n-=a+f-s}if(a<s&&o<l){let f=n<=s&&n>=a?s-n:0;s-=f,c=s+(c-a),a=s}else if(c<s){let f=n<=s&&n>=c?s-n:0;s-=f,a=s+(a-c),c=s}return{start:s,endA:a,endB:c}}const $f={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0};class Hf{constructor(e){this.view=e,this.queue=[],this.flushingSoon=-1,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.started=!1,this.observer=new window.MutationObserver(t=>{for(let n=0;n<t.length;n++)this.queue.push(t[n]);ie&&e.composing&&t.some(n=>n.type=="childList"&&n.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()})}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(e=!1){this.flushingSoon>-1?(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush(!0)):e&&this.flush(!0)}start(){this.observer.takeRecords(),this.observer.observe(this.view.dom,$f),this.started=!0}stop(){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.started=!1}stopped(e){if(!this.started)return e();this.stop();try{return e()}finally{this.start()}}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let s=e.focusNode;s;s=At(s))t.add(s);for(let s=e.anchorNode;s;s=At(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.ignoreMutation({type:"selection",target:_(n)?n.parentNode:n}))return this.view.domSel.ignore(e),!0}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(e=!0){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]),e&&t.domSel.read();let i=!t.domSel.suppress&&!t.domSel.synced&&!!Do(t)&&!this.ignoreSelectionChange(t.domSel.range),s=-1,o=-1,l=!1,a=[];if(t.editable)for(let f=0;f<n.length;f++){let d=this.registerMutation(n[f],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(a.some(f=>f.nodeName=="BR")&&(t.input.lastKeyCode==8||t.input.lastKeyCode==46||le&&(t.composing||t.input.compositionEndedAt>Date.now()-50)&&n.some(f=>f.type=="childList"&&f.removedNodes.length))){for(let f of a)if(f.nodeName=="BR"&&f.parentNode){let d=f.nextSibling;for(;d&&E(d);){if(d.contentEditable=="false"){f.parentNode.removeChild(f);break}d=d.firstChild}}}else if(be&&a.length){let f=a.filter(d=>d.nodeName=="BR");if(f.length==2){let[d,h]=f;d.parentNode&&d.parentNode.parentNode==h.parentNode?h.remove():d.remove()}else{let{focusNode:d}=t.domSel.range;for(let h of f){let u=h.parentNode;u&&u.nodeName=="LI"&&(!d||qf(t,d)!=u)&&h.remove()}}}let c=null;s<0&&i&&t.domSel.active&&t.input.lastFocus>Date.now()-200&&t.input.lastTouch<Date.now()-300&&zn(t.domSel.range)&&(c=Ir(t,t.domSel.range))&&c.eq(I.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,t.domSel.sync(),t.scrollToSelection()):(s>-1||i)&&(s>-1&&Wf(t),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,Jf(t,a)),zf(this.view,s,o,i,l,a),t.docView&&t.docView.damage?t.updateState(t.state):i&&t.domSel.sync())}registerMutation(e,t){var n;if(t.indexOf(e.target)>-1)return null;let i;for(let s=e.target;s&&!(i=this.view.docView.getDesc(s));s=s.parentNode);if(e.type=="attributes"&&(i==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!i||i.ignoreMutation(e))return null;if(e.type=="childList"){for(let d=0;d<e.addedNodes.length;d++){let h=e.addedNodes[d];t.push(h),_(h)&&(this.lastChangedTextNode=h)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(e.target))return i.markDamage(4),{from:i.posBefore,to:i.posAfter};let s=e.previousSibling,o=e.nextSibling,l=s&&s.parentNode==e.target?re(s)+1:0,a=i.localPosFromDOM(e.target,l,-1),c=o&&o.parentNode==e.target?re(o):e.target.childNodes.length,f=i.localPosFromDOM(e.target,c,1);return i.markDamage(!((n=i.contentDOM)===null||n===void 0)&&n.contains(e.target)?2:4),{from:a,to:f}}else return e.type=="attributes"?(i.markDamage(4),{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}):(this.lastChangedTextNode=e.target,i.markDamage(i instanceof sn&&e.target==i.nodeDOM?8:4),{from:i.posAtStart,to:i.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Yo=new WeakMap,Xo=!1;function Wf(r){if(!Yo.has(r)&&(Yo.set(r,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(r.dom).whiteSpace)!==-1)){if(r.requiresGeckoHackNode=be,Xo)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."),Xo=!0}}function qf(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 Jf(r,e){var t;let{focusNode:n,focusOffset:i}=r.domSel.range;for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||!E(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),n==s&&r.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}class Zo{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 af,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(rl),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=tl(this),el(this),this.nodeViews=nl(this),this.docView=io(this.state.doc,Qo(this),Wr(this),this.dom,this),this.domObserver=new Hf(this),this.domSel=new Qc(this),this.domObserver.start(),this.domSel.read(),cf(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&&zr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(rl),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&&(Ho(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=nl(this);Kf(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&zr(this),this.editable=tl(this),el(this);let a=Wr(this),c=Qo(this),f=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 h=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Sc(this);o&&this.domObserver.stopped(()=>{let u=d&&le&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Uf(i.selection,e.selection);if(d){let p=le?this.trackWrites=this.domSel.range.focusNode:null;if(this.composing&&(this.input.compositionNode=Mf(this)),s||!this.docView.update(e.doc,c,a,this,-1)){let m=this.docView.outerDeco;this.docView.destroy(),this.docView=io(e.doc,c,a,this.dom,this,m)}p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(u=!0)}this.domSel.sync(u)}),this.updatePluginViews(i),!((n=this.dragging)===null||n===void 0)&&n.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():h&&Cc(h)}scrollToSelection(){let e=this.domSel.range.focusNode;if(!(!e||!this.domSel.active)){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof M){let t=this.docView.domAfterPos(this.state.selection.from);E(t)&&Js(this,t.getBoundingClientRect(),e)}else Js(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(n.from<this.state.doc.content.size&&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&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==n.node&&(i=s)}this.dragging=new qo(e.slice,e.move,i<0?void 0:M.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(){return this.root.activeElement==this.dom}focus(){this.editable&&_s(this.dom),this.domSel.sync()}get root(){let e=this.dom.isConnected!==!1;e||(this._root=null);let t=this._root;if(t==null&&e){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return t||document}updateRoot(){this._root=null}posAtCoords(e){return Oc(this,e)}coordsAtPos(e,t=1){return Zs(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 Ic(this,t||this.state,e)}pasteHTML(e,t){return hn(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return hn(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Dr(this,e)}destroy(){this.docView&&(ff(this),this.domSel.destroy(),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Wr(this),this,-1),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,pc())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return hf(this,e)}domSelection(){return this.root.getSelection()}}Zo.prototype.dispatch=function(r){let e=this._props.dispatchTransaction;e?e.call(this,r):this.updateState(this.state.apply(r))};function Qo(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"),[fe.node(0,r.state.doc.content.size,e)]}function el(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:fe.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function tl(r){return!r.someProp("editable",e=>e(r.state)===!1)}function Uf(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 nl(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 Kf(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 rl(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")}var Hn=200,Z=function(){};Z.prototype.append=function(e){return e.length?(e=Z.from(e),!this.length&&e||e.length<Hn&&this.leafAppend(e)||this.length<Hn&&e.leafPrepend(this)||this.appendInner(e)):this},Z.prototype.prepend=function(e){return e.length?Z.from(e).append(this):this},Z.prototype.appendInner=function(e){return new _f(this,e)},Z.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?Z.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Z.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Z.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)},Z.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},Z.from=function(e){return e instanceof Z?e:e&&e.length?new il(e):Z.empty};var il=(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<=Hn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Hn)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})(Z);Z.empty=new il([]);var _f=(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})(Z);const jf=500;class we{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],f=[];return this.items.forEach((d,h)=>{if(!d.step){i||(i=this.remapping(n,h+1),s=i.maps.length),s--,f.push(d);return}if(i){f.push(new Ee(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new Ee(p,void 0,void 0,c.length+f.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 we(this.items.slice(0,n).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;f<e.steps.length;f++){let d=e.steps[f].invert(e.docs[f]),h=new Ee(e.mapping.maps[f],d,t),u;(u=a&&a.merge(h))&&(h=u,f?s.pop():l=l.slice(0,l.length-1)),s.push(h),t&&(o++,t=void 0),i||(a=h)}let c=o-n.depth;return c>Yf&&(l=Gf(l,c),o-=c),new we(l.append(s),o)}remapping(e,t){let n=new jt;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 we(this.items.append(e.map(t=>new Ee(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;t=Math.min(this.items.length,t);let n=[],i=this.items.length-t,s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},i);let a=t;this.items.forEach(h=>{let u=s.getMirror(--a);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(h.step){let m=e.steps[u].invert(e.docs[u]),g=h.selection&&h.selection.map(s.slice(a+1,u));g&&l++,n.push(new Ee(p,m,g))}else n.push(new Ee(p))},i);let c=[];for(let h=t;h<o;h++)c.push(new Ee(s.maps[h]));let f=this.items.slice(0,i).append(c).append(n),d=new we(f,l);return d.emptyItemCount()>jf&&(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 f=o.selection&&o.selection.map(t.slice(n));f&&s++;let d=new Ee(c.invert(),a,f),h,u=i.length-1;(h=i.length&&i[u].merge(d))?i[u]=h:i.push(d)}}else o.map&&n--},this.items.length,0),new we(Z.from(i.reverse()),s)}}we.empty=new we(Z.empty,0);function Gf(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class Ee{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 Ee(t.getMap().invert(),t,this.selection)}}}class Xe{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}}const Yf=20;function Xf(r,e,t,n){let i=t.getMeta(Be),s;if(i)return i.historyState;t.getMeta(td)&&(r=new Xe(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Be))return o.getMeta(Be).redo?new Xe(r.done.addTransform(t,void 0,n,Wn(e)),r.undone,sl(t.mapping.maps),r.prevTime,r.prevComposition):new Xe(r.done,r.undone.addTransform(t,void 0,n,Wn(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||!Zf(t,r.prevRanges)),c=o?Jr(r.prevRanges,t.mapping):sl(t.mapping.maps);return new Xe(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,Wn(e)),we.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new Xe(r.done.rebased(t,s),r.undone.rebased(t,s),Jr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new Xe(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Jr(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function Zf(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 sl(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 Jr(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 Qf(r,e){for(let t=0;t<e.steps.length;t++){let n=e.mapping.maps[t],i=-1;if(n.forEach((s,o)=>i=o),i<0){let s=e.steps[t];(s instanceof Se||s instanceof Ce)&&(i=s.to)}if(i>-1)return I.near(r.doc.resolve(i))}return r.selection}function ed(r,e,t){let n=Wn(e),i=Be.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,Qf(e,s.transform).getBookmark(),i,n),a=new Xe(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Be,{redo:t,historyState:a})}let Ur=!1,ol=null;function Wn(r){let e=r.plugins;if(ol!=e){Ur=!1,ol=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Ur=!0;break}}return Ur}const Be=new Mt("history"),td=new Mt("closeHistory");function nd(r={}){return r={depth:r.depth||100,newGroupDelay:r.newGroupDelay||500},new qe({key:Be,state:{init(){return new Xe(we.empty,we.empty,null,0,-1)},apply(e,t,n){return Xf(t,n,e,r)}},config:r,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,i=n=="historyUndo"?Kr:n=="historyRedo"?qn:null;return!i||!e.editable?!1:(t.preventDefault(),i(e.state,e.dispatch))}}}})}function ll(r,e){return(t,n)=>{let i=Be.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=ed(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}const Kr=ll(!1,!0),qn=ll(!0,!0);function rd(r){let e=Be.getState(r);return e?e.done.eventCount:0}function id(r){let e=Be.getState(r);return e?e.undone.eventCount:0}const sd=["ol",0],od=["ul",0],ld=["li",0],ad={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(r){return{order:r.hasAttribute("start")?+r.getAttribute("start"):1}}}],toDOM(r){return r.attrs.order==1?sd:["ol",{start:r.attrs.order},0]}},cd={parseDOM:[{tag:"ul"}],toDOM(){return od}},fd={parseDOM:[{tag:"li"}],toDOM(){return ld},defining:!0};function _r(r,e){let t={};for(let n in r)t[n]=r[n];for(let n in e)t[n]=e[n];return t}function dd(r,e,t){return r.append({ordered_list:_r(ad,{content:"list_item+",group:t}),bullet_list:_r(cd,{content:"list_item+",group:t}),list_item:_r(fd,{content:e})})}function hd(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 ud(l,o,r,e)?(n&&n(l.scrollIntoView()),!0):!1}}function ud(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 Mn(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new Mn(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),i=!0}let l=ur(s,t,n,e);return l?(r&&pd(r,e,l,i,t),!0):!1}function pd(r,e,t,n,i){let s=b.empty;for(let f=t.length-1;f>=0;f--)s=b.from(t[f].type.create(t[f].attrs,s));r.step(new ee(e.start-(n?2:0),e.end,e.start,e.end,new x(s,0,0),t.length,!0));let o=0;for(let f=0;f<t.length;f++)t[f].type==i&&(o=f+1);let l=t.length-o,a=e.start+t.length-(n?2:0),c=e.parent;for(let f=e.startIndex,d=e.endIndex,h=!0;f<d;f++,h=!1)!h&&l&&wt(r.doc,a,l)&&(r.split(a,l),a+=2*l),a+=c.child(f).nodeSize;return r}function It(r,e){return r instanceof Ut?e==r:r.indexOf(e)>-1}function md(r,e){return function(t,n){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(!It(r,l.type))return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||!It(r,i.node(-3).type)||i.index(-2)!=i.node(-2).childCount-1)return!1;if(n){let d=b.empty,h=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-h;y>=i.depth-3;y--)d=b.from(i.node(y).copy(d));let u=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;d=d.append(b.from(i.node(-3).type.createAndFill()));let p=i.before(i.depth-(h-1)),m=t.tr.replace(p,i.after(-u),new x(d,4-h,0)),g=-1;m.doc.nodesBetween(p,m.doc.content.size,(y,O)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=O+1)}),g>-1&&m.setSelection(I.near(m.doc.resolve(g))),n(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,s.pos),f=a||e?[null,a?{type:a}:null]:void 0;return wt(c.doc,i.pos,2,f)?(n&&n(c.split(i.pos,2,f).scrollIntoView()),!0):!1}}function al(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,o=>o.childCount>0&&It(r,o.firstChild.type));return s?t?It(r,n.node(s.depth-1).type)?gd(e,t,s):yd(e,t,s):!0:!1}}function gd(r,e,t){let n=r.tr,i=t.end,s=t.$to.end(t.depth),o=t.parent.child(t.endIndex-1).type;i<s&&(n.step(new ee(i-1,s,i,s,new x(b.from(o.create(null,t.parent.copy())),1,0),1,!0)),t=new Mn(n.doc.resolve(t.$from.pos),n.doc.resolve(s),t.depth));const l=Gt(t);if(l==null)return!1;n.lift(t,l);let a=n.doc.resolve(n.mapping.map(i,-1)-1);return Rn(n.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&n.join(a.pos),e(n.scrollIntoView()),!0}function yd(r,e,t){let n=r.tr,i=t.parent;for(let u=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)u-=i.child(p).nodeSize,n.delete(u-1,u+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),f=s.index(-1);if(!c.canReplace(f+(l?0:1),f+1,o.content.append(a?b.empty:b.from(i))))return!1;let d=s.pos,h=d+o.nodeSize;return n.step(new ee(d-(l?1:0),h+(a?1:0),d+1,h-1,new x((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 bd(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,c=>c.childCount>0&&It(r,c.firstChild.type));if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(!It(r,a.type))return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=b.from(c?a.lastChild.lastChild.type.create():null),d=new x(b.from(a.type.create(null,b.from(l.type.create(null,f)))),c?3:1,0),h=s.start,u=s.end;t(e.tr.step(new ee(h-(c?3:1),u,h,u,d,1,!0)).scrollIntoView())}return!0}}for(var Ze={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:"'"},Jn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},wd=typeof navigator<"u"&&/Mac/.test(navigator.platform),kd=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),te=0;te<10;te++)Ze[48+te]=Ze[96+te]=String(te);for(var te=1;te<=24;te++)Ze[te+111]="F"+te;for(var te=65;te<=90;te++)Ze[te]=String.fromCharCode(te+32),Jn[te]=String.fromCharCode(te);for(var jr in Ze)Jn.hasOwnProperty(jr)||(Jn[jr]=Ze[jr]);function xd(r){var e=wd&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||kd&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?Jn:Ze)[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 Sd=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Cd=typeof navigator<"u"&&/Win/.test(navigator.platform);function Md(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))Sd?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 Ad(r){let e=Object.create(null);for(let t in r)e[Md(t)]=r[t];return e}function Gr(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 Yr(r){return new qe({props:{handleKeyDown:Xr(r)}})}function Xr(r){let e=Ad(r);return function(t,n){let i=xd(n),s,o=e[Gr(i,n)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(n.shiftKey){let l=e[Gr(i,n,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(Cd&&n.ctrlKey&&n.altKey)&&(s=Ze[n.keyCode])&&s!=i){let l=e[Gr(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}let Zr,Qr;if(typeof WeakMap<"u"){let r=new WeakMap;Zr=e=>r.get(e),Qr=(e,t)=>(r.set(e,t),t)}else{const r=[];let t=0;Zr=n=>{for(let i=0;i<r.length;i+=2)if(r[i]==n)return r[i+1]},Qr=(n,i)=>(t==10&&(t=0),r[t++]=n,r[t++]=i)}var ne=class{constructor(r,e,t,n){this.width=r,this.height=e,this.map=t,this.problems=n}findCell(r){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=r)continue;const n=e%this.width,i=e/this.width|0;let s=n+1,o=i+1;for(let l=1;s<this.width&&this.map[e+l]==t;l++)s++;for(let l=1;o<this.height&&this.map[e+this.width*l]==t;l++)o++;return{left:n,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${r} found`)}colCount(r){for(let e=0;e<this.map.length;e++)if(this.map[e]==r)return e%this.width;throw new RangeError(`No cell with offset ${r} found`)}nextCell(r,e,t){const{left:n,right:i,top:s,bottom:o}=this.findCell(r);return e=="horiz"?(t<0?n==0:i==this.width)?null:this.map[s*this.width+(t<0?n-1:i)]:(t<0?s==0:o==this.height)?null:this.map[n+this.width*(t<0?s-1:o)]}rectBetween(r,e){const{left:t,right:n,top:i,bottom:s}=this.findCell(r),{left:o,right:l,top:a,bottom:c}=this.findCell(e);return{left:Math.min(t,o),top:Math.min(i,a),right:Math.max(n,l),bottom:Math.max(s,c)}}cellsInRect(r){const e=[],t={};for(let n=r.top;n<r.bottom;n++)for(let i=r.left;i<r.right;i++){const s=n*this.width+i,o=this.map[s];t[o]||(t[o]=!0,!(i==r.left&&i&&this.map[s-1]==o||n==r.top&&n&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(r,e,t){for(let n=0,i=0;;n++){const s=i+t.child(n).nodeSize;if(n==r){let o=e+r*this.width;const l=(r+1)*this.width;for(;o<l&&this.map[o]<i;)o++;return o==l?s-1:this.map[o]}i=s}}static get(r){return Zr(r)||Qr(r,Nd(r))}};function Nd(r){if(r.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+r.type.name);const e=Ed(r),t=r.childCount,n=[];let i=0,s=null;const o=[];for(let c=0,f=e*t;c<f;c++)n[c]=0;for(let c=0,f=0;c<t;c++){const d=r.child(c);f++;for(let p=0;;p++){for(;i<n.length&&n[i]!=0;)i++;if(p==d.childCount)break;const m=d.child(p),{colspan:g,rowspan:y,colwidth:O}=m.attrs;for(let w=0;w<y;w++){if(w+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:f,n:y-w});break}const v=i+w*e;for(let D=0;D<g;D++){n[v+D]==0?n[v+D]=f:(s||(s=[])).push({type:"collision",row:c,pos:f,n:g-D});const $=O&&O[D];if($){const H=(v+D)%e*2,B=o[H];B==null||B!=$&&o[H+1]==1?(o[H]=$,o[H+1]=1):B==$&&o[H+1]++}}}i+=g,f+=m.nodeSize}const h=(c+1)*e;let u=0;for(;i<h;)n[i++]==0&&u++;u&&(s||(s=[])).push({type:"missing",row:c,n:u}),f++}(e===0||t===0)&&(s||(s=[])).push({type:"zero_sized"});const l=new ne(e,t,n,s);let a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&Od(l,o,r),l}function Ed(r){let e=-1,t=!1;for(let n=0;n<r.childCount;n++){const i=r.child(n);let s=0;if(t)for(let o=0;o<n;o++){const l=r.child(o);for(let a=0;a<l.childCount;a++){const c=l.child(a);o+c.attrs.rowspan>n&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Od(r,e,t){r.problems||(r.problems=[]);const n={};for(let i=0;i<r.map.length;i++){const s=r.map[i];if(n[s])continue;n[s]=!0;const o=t.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let l=null;const a=o.attrs;for(let c=0;c<a.colspan;c++){const f=e[(i+c)%r.width*2];f!=null&&(!a.colwidth||a.colwidth[c]!=f)&&((l||(l=Td(a)))[c]=f)}l&&r.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Td(r){if(r.colwidth)return r.colwidth.slice();const e=[];for(let t=0;t<r.colspan;t++)e.push(0);return e}function cl(r,e){if(typeof r=="string")return{};const t=r.getAttribute("data-colwidth"),n=t&&/^\d+(,\d+)*$/.test(t)?t.split(",").map(o=>Number(o)):null,i=Number(r.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(r.getAttribute("rowspan")||1),colwidth:n&&n.length==i?n:null};for(const o in e){const l=e[o].getFromDOM,a=l&&l(r);a!=null&&(s[o]=a)}return s}function fl(r,e){const t={};r.attrs.colspan!=1&&(t.colspan=r.attrs.colspan),r.attrs.rowspan!=1&&(t.rowspan=r.attrs.rowspan),r.attrs.colwidth&&(t["data-colwidth"]=r.attrs.colwidth.join(","));for(const n in e){const i=e[n].setDOMAttr;i&&i(r.attrs[n],t)}return t}function vd(r){if(r!==null){if(!Array.isArray(r))throw new TypeError("colwidth must be null or an array");for(const e of r)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function Dd(r){const e=r.cellAttributes||{},t={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:vd}};for(const n in e)t[n]={default:e[n].default,validate:e[n].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:r.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:r.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:n=>cl(n,e)}],toDOM(n){return["td",fl(n,e),0]}},table_header:{content:r.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:n=>cl(n,e)}],toDOM(n){return["th",fl(n,e),0]}}}}function de(r){let e=r.cached.tableNodeTypes;if(!e){e=r.cached.tableNodeTypes={};for(const t in r.nodes){const n=r.nodes[t],i=n.spec.tableRole;i&&(e[i]=n)}}return e}const Qe=new Mt("selectingCells");function Lt(r){for(let e=r.depth-1;e>0;e--)if(r.node(e).type.spec.tableRole=="row")return r.node(0).resolve(r.before(e+1));return null}function Rd(r){for(let e=r.depth;e>0;e--){const t=r.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return r.node(e)}return null}function he(r){const e=r.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function ei(r){const e=r.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=Lt(e.$head)||Id(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Id(r){for(let e=r.nodeAfter,t=r.pos;e;e=e.firstChild,t++){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t)}for(let e=r.nodeBefore,t=r.pos;e;e=e.lastChild,t--){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t-e.nodeSize)}}function dl(r){return r.parent.type.spec.tableRole=="row"&&!!r.nodeAfter}function Ld(r){return r.node(0).resolve(r.pos+r.nodeAfter.nodeSize)}function ti(r,e){return r.depth==e.depth&&r.pos>=e.start(-1)&&r.pos<=e.end(-1)}function hl(r,e,t){const n=r.node(-1),i=ne.get(n),s=r.start(-1),o=i.nextCell(r.pos-s,e,t);return o==null?null:r.node(0).resolve(s+o)}function ut(r,e,t=1){const n={...r,colspan:r.colspan-t};return n.colwidth&&(n.colwidth=n.colwidth.slice(),n.colwidth.splice(e,t),n.colwidth.some(i=>i>0)||(n.colwidth=null)),n}function ul(r,e,t=1){const n={...r,colspan:r.colspan+t};if(n.colwidth){n.colwidth=n.colwidth.slice();for(let i=0;i<t;i++)n.colwidth.splice(e,0,0)}return n}function zd(r,e,t){const n=de(e.type.schema).header_cell;for(let i=0;i<r.height;i++)if(e.nodeAt(r.map[t+i*r.width]).type!=n)return!1;return!0}var W=class He extends I{constructor(e,t=e){const n=e.node(-1),i=ne.get(n),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(f=>f!=t.pos-s);a.unshift(t.pos-s);const c=a.map(f=>{const d=n.nodeAt(f);if(!d)throw new RangeError(`No cell with offset ${f} found`);const h=s+f+1;return new Os(l.resolve(h),l.resolve(h+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const n=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(dl(n)&&dl(i)&&ti(n,i)){const s=this.$anchorCell.node(-1)!=n.node(-1);return s&&this.isRowSelection()?He.rowSelection(n,i):s&&this.isColSelection()?He.colSelection(n,i):new He(n,i)}return L.between(n,i)}content(){const e=this.$anchorCell.node(-1),t=ne.get(e),n=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),s={},o=[];for(let a=i.top;a<i.bottom;a++){const c=[];for(let f=a*t.width+i.left,d=i.left;d<i.right;d++,f++){const h=t.map[f];if(s[h])continue;s[h]=!0;const u=t.findCell(h);let p=e.nodeAt(h);if(!p)throw new RangeError(`No cell with offset ${h} found`);const m=i.left-u.left,g=u.right-i.right;if(m>0||g>0){let y=p.attrs;if(m>0&&(y=ut(y,0,m)),g>0&&(y=ut(y,y.colspan-g,g)),u.left<i.left){if(p=p.type.createAndFill(y),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else p=p.type.create(y,p.content)}if(u.top<i.top||u.bottom>i.bottom){const y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top<i.top?p=p.type.createAndFill(y):p=p.type.create(y,p.content)}c.push(p)}o.push(e.child(a).copy(b.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new x(b.from(l),1,1)}replace(e,t=x.empty){const n=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:l,$to:a}=i[o],c=e.mapping.slice(n);e.replace(c.map(l.pos),c.map(a.pos),o?x.empty:t)}const s=I.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new x(b.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=ne.get(t),i=this.$anchorCell.start(-1),s=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const n=e.node(-1),i=ne.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+i.map[o.left])),l.bottom<i.height&&(t=a.resolve(s+i.map[i.width*(i.height-1)+l.right-1]))):(l.top>0&&(t=a.resolve(s+i.map[l.left])),o.bottom<i.height&&(e=a.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new He(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=ne.get(e),n=this.$anchorCell.start(-1),i=t.colCount(this.$anchorCell.pos-n),s=t.colCount(this.$headCell.pos-n);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof He&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const n=e.node(-1),i=ne.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+i.map[o.top*i.width])),l.right<i.width&&(t=a.resolve(s+i.map[i.width*(l.top+1)-1]))):(l.left>0&&(t=a.resolve(s+i.map[l.top*i.width])),o.right<i.width&&(e=a.resolve(s+i.map[i.width*(o.top+1)-1]))),new He(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new He(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){return new He(e.resolve(t),e.resolve(n))}getBookmark(){return new Bd(this.$anchorCell.pos,this.$headCell.pos)}};W.prototype.visible=!1,I.jsonID("cell",W);var Bd=class ba{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ba(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&n.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&ti(t,n)?new W(t,n):I.near(n,1)}};function Pd(r){if(!(r.selection instanceof W))return null;const e=[];return r.selection.forEachCell((t,n)=>{e.push(fe.node(n,n+t.nodeSize,{class:"selectedCell"}))}),q.create(r.doc,e)}function Fd({$from:r,$to:e}){if(r.pos==e.pos||r.pos<e.pos-6)return!1;let t=r.pos,n=e.pos,i=r.depth;for(;i>=0&&!(r.after(i+1)<r.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,n--);return t==n&&/row|table/.test(r.node(i).type.spec.tableRole)}function Vd({$from:r,$to:e}){let t,n;for(let i=r.depth;i>0;i--){const s=r.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}return t!==n&&e.parentOffset===0}function $d(r,e,t){const n=(e||r).selection,i=(e||r).doc;let s,o;if(n instanceof M&&(o=n.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=W.create(i,n.from);else if(o=="row"){const l=i.resolve(n.from+1);s=W.rowSelection(l,l)}else if(!t){const l=ne.get(n.node),a=n.from+1,c=a+l.map[l.width*l.height-1];s=W.create(i,a+1,c)}}else n instanceof L&&Fd(n)?s=L.create(i,n.from):n instanceof L&&Vd(n)&&(s=L.create(i,n.$from.start(),n.$from.end()));return s&&(e||(e=r.tr)).setSelection(s),e}const Hd=new Mt("fix-tables");function pl(r,e,t,n){const i=r.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){const a=e.child(o);for(let c=l,f=Math.min(i,o+3);c<f;c++)if(r.child(c)==a){l=c+1,t+=a.nodeSize;continue e}n(a,t),l<i&&r.child(l).sameMarkup(a)?pl(r.child(l),a,t+1,n):a.nodesBetween(0,a.content.size,n,t+1),t+=a.nodeSize}}function Wd(r,e){let t;const n=(i,s)=>{i.type.spec.tableRole=="table"&&(t=qd(r,i,s,t))};return e?e.doc!=r.doc&&pl(e.doc,r.doc,0,n):r.doc.descendants(n),t}function qd(r,e,t,n){const i=ne.get(e);if(!i.problems)return n;n||(n=r.tr);const s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){const c=i.problems[a];if(c.type=="collision"){const f=e.nodeAt(c.pos);if(!f)continue;const d=f.attrs;for(let h=0;h<d.rowspan;h++)s[c.row+h]+=c.n;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,ut(d,d.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const f=e.nodeAt(c.pos);if(!f)continue;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,{...f.attrs,rowspan:f.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const f=e.nodeAt(c.pos);if(!f)continue;n.setNodeMarkup(n.mapping.map(t+1+c.pos),null,{...f.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const f=n.mapping.map(t);n.delete(f,f+e.nodeSize)}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){const f=e.child(a),d=c+f.nodeSize,h=s[a];if(h>0){let u="cell";f.firstChild&&(u=f.firstChild.type.spec.tableRole);const p=[];for(let g=0;g<h;g++){const y=de(r.schema)[u].createAndFill();y&&p.push(y)}const m=(a==0||o==a-1)&&l==a?c+1:d-1;n.insert(n.mapping.map(m),p)}c=d}return n.setMeta(Hd,{fixTables:!0})}function Oe(r){const e=r.selection,t=ei(r),n=t.node(-1),i=t.start(-1),s=ne.get(n);return{...e instanceof W?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(t.pos-i),tableStart:i,map:s,table:n}}function ml(r,{map:e,tableStart:t,table:n},i){let s=i>0?-1:0;zd(e,n,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){const l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){const a=e.map[l],c=n.nodeAt(a);r.setNodeMarkup(r.mapping.map(t+a),null,ul(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{const a=s==null?de(n.type.schema).cell:n.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,n);r.insert(r.mapping.map(t+c),a.createAndFill())}}return r}function Jd(r,e){if(!he(r))return!1;if(e){const t=Oe(r);e(ml(r.tr,t,t.left))}return!0}function Ud(r,e){if(!he(r))return!1;if(e){const t=Oe(r);e(ml(r.tr,t,t.right))}return!0}function Kd(r,{map:e,table:t,tableStart:n},i){const s=r.mapping.maps.length;for(let o=0;o<e.height;){const l=o*e.width+i,a=e.map[l],c=t.nodeAt(a),f=c.attrs;if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)r.setNodeMarkup(r.mapping.slice(s).map(n+a),null,ut(f,i-e.colCount(a)));else{const d=r.mapping.slice(s).map(n+a);r.delete(d,d+c.nodeSize)}o+=f.rowspan}}function _d(r,e){if(!he(r))return!1;if(e){const t=Oe(r),n=r.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;Kd(n,t,i),i!=t.left;i--){const s=t.tableStart?n.doc.nodeAt(t.tableStart-1):n.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=ne.get(s)}e(n)}return!0}function jd(r,e,t){var n;const i=de(e.type.schema).header_cell;for(let s=0;s<r.width;s++)if(((n=e.nodeAt(r.map[s+t*r.width]))===null||n===void 0?void 0:n.type)!=i)return!1;return!0}function gl(r,{map:e,tableStart:t,table:n},i){let s=t;for(let c=0;c<i;c++)s+=n.child(c).nodeSize;const o=[];let l=i>0?-1:0;jd(e,n,i+l)&&(l=i==0||i==e.height?null:0);for(let c=0,f=e.width*i;c<e.width;c++,f++)if(i>0&&i<e.height&&e.map[f]==e.map[f-e.width]){const d=e.map[f],h=n.nodeAt(d).attrs;r.setNodeMarkup(t+d,null,{...h,rowspan:h.rowspan+1}),c+=h.colspan-1}else{var a;const d=l==null?de(n.type.schema).cell:(a=n.nodeAt(e.map[f+l*e.width]))===null||a===void 0?void 0:a.type,h=d?.createAndFill();h&&o.push(h)}return r.insert(s,de(n.type.schema).row.create(null,o)),r}function Gd(r,e){if(!he(r))return!1;if(e){const t=Oe(r);e(gl(r.tr,t,t.top))}return!0}function yl(r,e){if(!he(r))return!1;if(e){const t=Oe(r);e(gl(r.tr,t,t.bottom))}return!0}function Yd(r,{map:e,table:t,tableStart:n},i){let s=0;for(let c=0;c<i;c++)s+=t.child(c).nodeSize;const o=s+t.child(i).nodeSize,l=r.mapping.maps.length;r.delete(s+n,o+n);const a=new Set;for(let c=0,f=i*e.width;c<e.width;c++,f++){const d=e.map[f];if(!a.has(d)){if(a.add(d),i>0&&d==e.map[f-e.width]){const h=t.nodeAt(d).attrs;r.setNodeMarkup(r.mapping.slice(l).map(d+n),null,{...h,rowspan:h.rowspan-1}),c+=h.colspan-1}else if(i<e.height&&d==e.map[f+e.width]){const h=t.nodeAt(d),u=h.attrs,p=h.type.create({...u,rowspan:h.attrs.rowspan-1},h.content),m=e.positionAt(i+1,c,t);r.insert(r.mapping.slice(l).map(n+m),p),c+=u.colspan-1}}}}function Xd(r,e){if(!he(r))return!1;if(e){const t=Oe(r),n=r.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;Yd(n,t,i),i!=t.top;i--){const s=t.tableStart?n.doc.nodeAt(t.tableStart-1):n.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=ne.get(t.table)}e(n)}return!0}function bl(r){const e=r.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function Zd({width:r,height:e,map:t},n){let i=n.top*r+n.left,s=i,o=(n.bottom-1)*r+n.left,l=i+(n.right-n.left-1);for(let a=n.top;a<n.bottom;a++){if(n.left>0&&t[s]==t[s-1]||n.right<r&&t[l]==t[l+1])return!0;s+=r,l+=r}for(let a=n.left;a<n.right;a++){if(n.top>0&&t[i]==t[i-r]||n.bottom<e&&t[o]==t[o+r])return!0;i++,o++}return!1}function Qd(r,e){const t=r.selection;if(!(t instanceof W)||t.$anchorCell.pos==t.$headCell.pos)return!1;const n=Oe(r),{map:i}=n;if(Zd(i,n))return!1;if(e){const s=r.tr,o={};let l=b.empty,a,c;for(let f=n.top;f<n.bottom;f++)for(let d=n.left;d<n.right;d++){const h=i.map[f*i.width+d],u=n.table.nodeAt(h);if(!(o[h]||!u))if(o[h]=!0,a==null)a=h,c=u;else{bl(u)||(l=l.append(u.content));const p=s.mapping.map(h+n.tableStart);s.delete(p,p+u.nodeSize)}}if(a==null||c==null)return!0;if(s.setNodeMarkup(a+n.tableStart,null,{...ul(c.attrs,c.attrs.colspan,n.right-n.left-c.attrs.colspan),rowspan:n.bottom-n.top}),l.size>0){const f=a+1+c.content.size,d=bl(c)?a+1:f;s.replaceWith(d+n.tableStart,f+n.tableStart,l)}s.setSelection(new W(s.doc.resolve(a+n.tableStart))),e(s)}return!0}function eh(r,e){const t=de(r.schema);return th(({node:n})=>t[n.type.spec.tableRole])(r,e)}function th(r){return(e,t)=>{const n=e.selection;let i,s;if(n instanceof W){if(n.$anchorCell.pos!=n.$headCell.pos)return!1;i=n.$anchorCell.nodeAfter,s=n.$anchorCell.pos}else{var o;if(i=Rd(n.$from),!i)return!1;s=(o=Lt(n.$from))===null||o===void 0?void 0:o.pos}if(i==null||s==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(t){let l=i.attrs;const a=[],c=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});const f=Oe(e),d=e.tr;for(let u=0;u<f.right-f.left;u++)a.push(c?{...l,colwidth:c&&c[u]?[c[u]]:null}:l);let h;for(let u=f.top;u<f.bottom;u++){let p=f.map.positionAt(u,f.left,f.table);u==f.top&&(p+=i.nodeSize);for(let m=f.left,g=0;m<f.right;m++,g++)m==f.left&&u==f.top||d.insert(h=d.mapping.map(p+f.tableStart,1),r({node:i,row:u,col:m}).createAndFill(a[g]))}d.setNodeMarkup(s,r({node:i,row:f.top,col:f.left}),a[0]),n instanceof W&&d.setSelection(new W(d.doc.resolve(n.$anchorCell.pos),h?d.doc.resolve(h):void 0)),t(d)}return!0}}function nh(r){return function(e,t){if(!he(e))return!1;if(t){const n=de(e.schema),i=Oe(e),s=e.tr,o=i.map.cellsInRect(r=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:r=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==n.header_cell&&s.setNodeMarkup(i.tableStart+o[a],n.cell,l[a].attrs);if(s.steps.length===0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],n.header_cell,l[a].attrs);t(s)}return!0}}function wl(r,e,t){const n=e.map.cellsInRect({left:0,top:0,right:r=="row"?e.map.width:1,bottom:r=="column"?e.map.height:1});for(let i=0;i<n.length;i++){const s=e.table.nodeAt(n[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function ni(r,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?nh(r):function(t,n){if(!he(t))return!1;if(n){const i=de(t.schema),s=Oe(t),o=t.tr,l=wl("row",s,i),a=wl("column",s,i),c=(r==="column"?l:r==="row"&&a)?1:0,f=r=="column"?{left:0,top:c,right:1,bottom:s.map.height}:r=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,d=r=="column"?a?i.cell:i.header_cell:r=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(f).forEach(h=>{const u=h+s.tableStart,p=o.doc.nodeAt(u);p&&o.setNodeMarkup(u,d,p.attrs)}),n(o)}return!0}}const rh=ni("row",{useDeprecatedLogic:!0}),ih=ni("column",{useDeprecatedLogic:!0});ni("cell",{useDeprecatedLogic:!0});function sh(r,e){if(e<0){const t=r.nodeBefore;if(t)return r.pos-t.nodeSize;for(let n=r.index(-1)-1,i=r.before();n>=0;n--){const s=r.node(-1).child(n),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(r.index()<r.parent.childCount-1)return r.pos+r.nodeAfter.nodeSize;const t=r.node(-1);for(let n=r.indexAfter(-1),i=r.after();n<t.childCount;n++){const s=t.child(n);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function ri(r){return function(e,t){if(!he(e))return!1;const n=sh(ei(e),r);if(n==null)return!1;if(t){const i=e.doc.resolve(n);t(e.tr.setSelection(L.between(i,Ld(i))).scrollIntoView())}return!0}}function oh(r,e){const t=r.selection.$anchor;for(let n=t.depth;n>0;n--)if(t.node(n).type.spec.tableRole=="table")return e&&e(r.tr.delete(t.before(n),t.after(n)).scrollIntoView()),!0;return!1}function Un(r,e){const t=r.selection;if(!(t instanceof W))return!1;if(e){const n=r.tr,i=de(r.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||n.replace(n.mapping.map(o+1),n.mapping.map(o+s.nodeSize-1),new x(i,0,0))}),n.docChanged&&e(n)}return!0}function lh(r){if(r.size===0)return null;let{content:e,openStart:t,openEnd:n}=r;for(;e.childCount==1&&(t>0&&n>0||e.child(0).type.spec.tableRole=="table");)t--,n--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content;const f=a?0:Math.max(0,t-1),d=a<e.childCount-1?0:Math.max(0,n-1);(f||d)&&(c=ii(de(o).row,new x(c,f,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||n?ii(de(o).row,new x(e,t,n)).content:e);else return null;return ah(o,l)}function ah(r,e){const t=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let n=0;for(let i=0;i<t.length;i++)n=Math.max(n,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(b.empty),t[i]<n){const s=de(r).cell.createAndFill(),o=[];for(let l=t[i];l<n;l++)o.push(s);e[i]=e[i].append(b.from(o))}return{height:e.length,width:n,rows:e}}function ii(r,e){const t=r.createAndFill();return new Es(t).replace(0,t.content.size,e).doc}function ch({width:r,height:e,rows:t},n,i){if(r!=n){const s=[],o=[];for(let l=0;l<t.length;l++){const a=t[l],c=[];for(let f=s[l]||0,d=0;f<n;d++){let h=a.child(d%a.childCount);f+h.attrs.colspan>n&&(h=h.type.createChecked(ut(h.attrs,h.attrs.colspan,f+h.attrs.colspan-n),h.content)),c.push(h),f+=h.attrs.colspan;for(let u=1;u<h.attrs.rowspan;u++)s[l+u]=(s[l+u]||0)+h.attrs.colspan}o.push(b.from(c))}t=o,r=n}if(e!=i){const s=[];for(let o=0,l=0;o<i;o++,l++){const a=[],c=t[l%e];for(let f=0;f<c.childCount;f++){let d=c.child(f);o+d.attrs.rowspan>i&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),a.push(d)}s.push(b.from(a))}t=s,e=i}return{width:r,height:e,rows:t}}function fh(r,e,t,n,i,s,o){const l=r.doc.type.schema,a=de(l);let c,f;if(i>e.width)for(let d=0,h=0;d<e.height;d++){const u=t.child(d);h+=u.nodeSize;const p=[];let m;u.lastChild==null||u.lastChild.type==a.cell?m=c||(c=a.cell.createAndFill()):m=f||(f=a.header_cell.createAndFill());for(let g=e.width;g<i;g++)p.push(m);r.insert(r.mapping.slice(o).map(h-1+n),p)}if(s>e.height){const d=[];for(let p=0,m=(e.height-1)*e.width;p<Math.max(e.width,i);p++){const g=p>=e.width?!1:t.nodeAt(e.map[m+p]).type==a.header_cell;d.push(g?f||(f=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const h=a.row.create(null,b.from(d)),u=[];for(let p=e.height;p<s;p++)u.push(h);r.insert(r.mapping.slice(o).map(n+t.nodeSize-2),u)}return!!(c||f)}function kl(r,e,t,n,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){const f=o*e.width+c,d=e.map[f];if(e.map[f-e.width]==d){a=!0;const h=t.nodeAt(d),{top:u,left:p}=e.findCell(d);r.setNodeMarkup(r.mapping.slice(l).map(d+n),null,{...h.attrs,rowspan:o-u}),r.insert(r.mapping.slice(l).map(e.positionAt(o,p,t)),h.type.createAndFill({...h.attrs,rowspan:u+h.attrs.rowspan-o})),c+=h.attrs.colspan-1}}return a}function xl(r,e,t,n,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){const f=c*e.width+o,d=e.map[f];if(e.map[f-1]==d){a=!0;const h=t.nodeAt(d),u=e.colCount(d),p=r.mapping.slice(l).map(d+n);r.setNodeMarkup(p,null,ut(h.attrs,o-u,h.attrs.colspan-(o-u))),r.insert(p+h.nodeSize,h.type.createAndFill(ut(h.attrs,0,o-u))),c+=h.attrs.rowspan-1}}return a}function Sl(r,e,t,n,i){let s=t?r.doc.nodeAt(t-1):r.doc;if(!s)throw new Error("No table found");let o=ne.get(s);const{top:l,left:a}=n,c=a+i.width,f=l+i.height,d=r.tr;let h=0;function u(){if(s=t?d.doc.nodeAt(t-1):d.doc,!s)throw new Error("No table found");o=ne.get(s),h=d.mapping.maps.length}fh(d,o,s,t,c,f,h)&&u(),kl(d,o,s,t,a,c,l,h)&&u(),kl(d,o,s,t,a,c,f,h)&&u(),xl(d,o,s,t,l,f,a,h)&&u(),xl(d,o,s,t,l,f,c,h)&&u();for(let p=l;p<f;p++){const m=o.positionAt(p,a,s),g=o.positionAt(p,c,s);d.replace(d.mapping.slice(h).map(m+t),d.mapping.slice(h).map(g+t),new x(i.rows[p-l],0,0))}u(),d.setSelection(new W(d.doc.resolve(t+o.positionAt(l,a,s)),d.doc.resolve(t+o.positionAt(f-1,c-1,s)))),e(d)}const dh=Xr({ArrowLeft:_n("horiz",-1),ArrowRight:_n("horiz",1),ArrowUp:_n("vert",-1),ArrowDown:_n("vert",1),"Shift-ArrowLeft":jn("horiz",-1),"Shift-ArrowRight":jn("horiz",1),"Shift-ArrowUp":jn("vert",-1),"Shift-ArrowDown":jn("vert",1),Backspace:Un,"Mod-Backspace":Un,Delete:Un,"Mod-Delete":Un});function Kn(r,e,t){return t.eq(r.selection)?!1:(e&&e(r.tr.setSelection(t).scrollIntoView()),!0)}function _n(r,e){return(t,n,i)=>{if(!i)return!1;const s=t.selection;if(s instanceof W)return Kn(t,n,I.near(s.$headCell,e));if(r!="horiz"&&!s.empty)return!1;const o=Cl(i,r,e);if(o==null)return!1;if(r=="horiz")return Kn(t,n,I.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=hl(l,r,e);let c;return a?c=I.near(a,1):e<0?c=I.near(t.doc.resolve(l.before(-1)),-1):c=I.near(t.doc.resolve(l.after(-1)),1),Kn(t,n,c)}}}function jn(r,e){return(t,n,i)=>{if(!i)return!1;const s=t.selection;let o;if(s instanceof W)o=s;else{const a=Cl(i,r,e);if(a==null)return!1;o=new W(t.doc.resolve(a))}const l=hl(o.$headCell,r,e);return l?Kn(t,n,new W(o.$anchorCell,l)):!1}}function hh(r,e){const t=r.state.doc,n=Lt(t.resolve(e));return n?(r.dispatch(r.state.tr.setSelection(new W(n))),!0):!1}function uh(r,e,t){if(!he(r.state))return!1;let n=lh(t);const i=r.state.selection;if(i instanceof W){n||(n={width:1,height:1,rows:[b.from(ii(de(r.state.schema).cell,t))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=ne.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return n=ch(n,l.right-l.left,l.bottom-l.top),Sl(r.state,r.dispatch,o,l,n),!0}else if(n){const s=ei(r.state),o=s.start(-1);return Sl(r.state,r.dispatch,o,ne.get(s.node(-1)).findCell(s.pos-o),n),!0}else return!1}function ph(r,e){var t;if(e.button!=0||e.ctrlKey||e.metaKey)return;const n=Ml(r,e.target);let i;if(e.shiftKey&&r.state.selection instanceof W)s(r.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&n&&(i=Lt(r.state.selection.$anchor))!=null&&((t=si(r,e))===null||t===void 0?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!n)return;function s(a,c){let f=si(r,c);const d=Qe.getState(r.state)==null;if(!f||!ti(a,f))if(d)f=a;else return;const h=new W(a,f);if(d||!r.state.selection.eq(h)){const u=r.state.tr.setSelection(h);d&&u.setMeta(Qe,a.pos),r.dispatch(u)}}function o(){r.root.removeEventListener("mouseup",o),r.root.removeEventListener("dragstart",o),r.root.removeEventListener("mousemove",l),Qe.getState(r.state)!=null&&r.dispatch(r.state.tr.setMeta(Qe,-1))}function l(a){const c=a,f=Qe.getState(r.state);let d;if(f!=null)d=r.state.doc.resolve(f);else if(Ml(r,c.target)!=n&&(d=si(r,e),!d))return o();d&&s(d,c)}r.root.addEventListener("mouseup",o),r.root.addEventListener("dragstart",o),r.root.addEventListener("mousemove",l)}function Cl(r,e,t){if(!(r.state.selection instanceof L))return null;const{$head:n}=r.state.selection;for(let i=n.depth-1;i>=0;i--){const s=n.node(i);if((t<0?n.index(i):n.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=n.before(i),l=e=="vert"?t>0?"down":"up":t>0?"right":"left";return r.endOfTextblock(l)?o:null}}return null}function Ml(r,e){for(;e&&e!=r.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function si(r,e){const t=r.posAtCoords({left:e.clientX,top:e.clientY});if(!t)return null;let{inside:n,pos:i}=t;return n>=0&&Lt(r.state.doc.resolve(n))||Lt(r.state.doc.resolve(i))}new Mt("tableColumnResizing");function mh({allowTableNodeSelection:r=!1}={}){return new qe({key:Qe,state:{init(){return null},apply(e,t){const n=e.getMeta(Qe);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;const{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:Pd,handleDOMEvents:{mousedown:ph},createSelectionBetween(e){return Qe.getState(e.state)!=null?e.state.selection:null},handleTripleClick:hh,handleKeyDown:dh,handlePaste:uh},appendTransaction(e,t,n){return $d(n,Wd(n,t),r)}})}const gh=/^(https?:|mailto:|tel:)/i,Al=/^[a-z][a-z0-9+.-]*:/i;function Pe(r){if(r==null)return null;const e=r.trim();if(!e)return null;const t=e.replace(/[\u0000- \u007f-\u009f]/g,"");return Al.test(t)&&!gh.test(t)?null:e}function Nl(r){const e=r.trim();return e?/^[^\s@/]+@[^\s@/]+\.[^\s@/]+$/.test(e)?`mailto:${e}`:!Al.test(e)&&!/^[/#?.]/.test(e)&&/^[\w-]+(\.[\w-]+)+/.test(e)?`https://${e}`:Pe(e):null}function yh(r){return r.replace(/<!--[\s\S]*?-->/g,"").replace(/<\/?o:p[^>]*>/gi,"").replace(/<\/?(w|m|v):[^>]*>/gi,"").replace(/<xml[\s\S]*?<\/xml>/gi,"").replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<meta[^>]*>/gi,"").replace(/<link[^>]*>/gi,"")}const El={black:"#000000",white:"#ffffff",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",purple:"#800080",pink:"#ffc0cb",gray:"#808080",grey:"#808080",silver:"#c0c0c0",navy:"#000080",teal:"#008080",maroon:"#800000",olive:"#808000",lime:"#00ff00",aqua:"#00ffff",cyan:"#00ffff",fuchsia:"#ff00ff",magenta:"#ff00ff",darkred:"#8b0000",darkblue:"#00008b",darkgreen:"#006400",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",darkgray:"#a9a9a9",darkgrey:"#a9a9a9"},oi=r=>Math.max(0,Math.min(255,Math.round(r))).toString(16).padStart(2,"0");function zt(r){if(!r)return null;const e=r.trim().toLowerCase().replace(/\s*!important$/,"");if(El[e])return El[e];let t=/^#([0-9a-f]{3})$/.exec(e);return t?"#"+[...t[1]].map(n=>n+n).join(""):(t=/^#([0-9a-f]{6})(ff)?$/.exec(e),t?"#"+t[1]:(t=/^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(e),t?t[4]!==void 0&&(t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4]))<1?null:"#"+oi(+t[1])+oi(+t[2])+oi(+t[3]):null))}function Ol(r){const e=zt(r);return e&&e!=="#000000"?e:null}function li(r){const e=zt(r)??zt((r??"").split(/\s+(?![^(]*\))/).find(t=>zt(t)));return e&&e!=="#ffffff"?e:null}const bh=[{color:"#dc2626",name:"colorRed"},{color:"#ea580c",name:"colorOrange"},{color:"#ca8a04",name:"colorAmber"},{color:"#16a34a",name:"colorGreen"},{color:"#0d9488",name:"colorTeal"},{color:"#2563eb",name:"colorBlue"},{color:"#7c3aed",name:"colorPurple"},{color:"#db2777",name:"colorPink"},{color:"#475569",name:"colorSlate"},{color:"#94a3b8",name:"colorGray"}],wh=[{color:"#fef08a",name:"colorYellow"},{color:"#bbf7d0",name:"colorGreen"},{color:"#bae6fd",name:"colorBlue"},{color:"#fbcfe8",name:"colorPink"},{color:"#fed7aa",name:"colorOrange"},{color:"#e9d5ff",name:"colorPurple"}],kh=["left","center","right","justify"];function Tl(r){const e=(r.style.textAlign||r.getAttribute("align")||"").toLowerCase();return kh.includes(e)&&e!=="left"?e:null}function vl(r){return r?{style:`text-align: ${r}`}:{}}const xh={left:"float: left; margin: 0 1em 1em 0",right:"float: right; margin: 0 0 1em 1em",center:"display: block; margin-left: auto; margin-right: auto"},Sh={left:"float: left; margin: 0 1em 1em 0",right:"float: right; margin: 0 0 1em 1em",center:"display: table; margin-left: auto; margin-right: auto"};function Ch(r){const e=r.style.float||r.getAttribute("align")||"";return e==="left"||e==="right"?e:(r.style.display==="block"||r.style.display==="table")&&r.style.marginLeft==="auto"&&r.style.marginRight==="auto"?"center":null}const Dl={src:{},alt:{default:""},title:{default:null},width:{default:null},height:{default:null},align:{default:null}};function Rl(r,e){const t=Pe(r.getAttribute("src"));return t?{src:t,alt:r.getAttribute("alt")??"",title:r.getAttribute("title"),width:Il(r.getAttribute("width")??r.style.width),height:Il(r.getAttribute("height")??r.style.height),align:Ch(e)}:!1}function ai(r,e){const{src:t,alt:n,title:i,width:s,height:o,align:l}=r,a={src:t,alt:n??""};i&&(a.title=i),s&&(a.width=String(s)),s&&o&&(a.height=String(o));const c=e?xh[l]:void 0;return c&&(a.style=c),a}function Il(r){const e=/^\s*(\d{1,5})(px)?\s*$/.exec(r??"");return e?Number(e[1]):null}const Mh={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",attrs:{align:{default:null}},parseDOM:[{tag:"p",getAttrs:r=>({align:Tl(r)})}],toDOM:r=>["p",vl(r.attrs.align),0]},heading:{content:"inline*",group:"block",defining:!0,attrs:{level:{default:2},align:{default:null}},parseDOM:[1,2,3,4,5,6].map(r=>({tag:`h${r}`,getAttrs:e=>({level:Math.min(r,4),align:Tl(e)})})),toDOM:r=>[`h${r.attrs.level}`,vl(r.attrs.align),0]},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,attrs:{language:{default:null}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:r=>{const e=r.querySelector("code"),t=/language-([\w-]+)/.exec(e?.className??"");return{language:t?t[1]:null}}}],toDOM:r=>["pre",["code",r.attrs.language?{class:`language-${r.attrs.language}`}:{},0]]},...Dd({tableGroup:"block",cellContent:"block+",cellAttributes:{}}),text:{group:"inline"},image:{inline:!0,group:"inline",draggable:!0,attrs:Dl,parseDOM:[{tag:"img[src]",getAttrs:r=>Rl(r,r)}],toDOM:r=>["img",ai(r.attrs,!0)]},figure:{group:"block",content:"inline*",marks:"_",draggable:!0,isolating:!0,attrs:Dl,parseDOM:[{tag:"figure",getAttrs:r=>{const e=r.querySelector("img");return e?Rl(e,r):!1},contentElement:r=>r.querySelector("figcaption")??document.createElement("figcaption")}],toDOM:r=>{const e=Sh[r.attrs.align];return["figure",e?{style:e}:{},["img",ai(r.attrs,!1)],["figcaption",0]]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]}},Ah={link:{attrs:{href:{},title:{default:null},target:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:r=>{const e=r,t=Pe(e.getAttribute("href"));return t?{href:t,title:e.getAttribute("title"),target:e.getAttribute("target")==="_blank"?"_blank":null}:!1}}],toDOM:r=>{const e={href:r.attrs.href};return r.attrs.title&&(e.title=r.attrs.title),r.attrs.target==="_blank"&&(e.target="_blank",e.rel="noopener noreferrer"),["a",e,0]}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:r=>r.type.name==="strong"},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:r=>r.type.name==="em"}],toDOM:()=>["em",0]},underline:{parseDOM:[{tag:"u"},{style:"text-decoration=underline"},{style:"text-decoration-line=underline"}],toDOM:()=>["u",0]},strike:{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration=line-through"},{style:"text-decoration-line=line-through"}],toDOM:()=>["s",0]},textColor:{attrs:{color:{}},parseDOM:[{tag:"span",getAttrs:r=>{const e=Ol(r.style.color);return e?{color:e}:!1}},{tag:"font[color]",getAttrs:r=>{const e=Ol(r.getAttribute("color"));return e?{color:e}:!1}}],toDOM:r=>["span",{style:`color: ${r.attrs.color}`},0]},highlight:{attrs:{color:{default:"#fef08a"}},parseDOM:[{tag:"mark",getAttrs:r=>({color:li(r.style.backgroundColor)??"#fef08a"})},{style:"background-color",getAttrs:r=>{const e=li(r);return e?{color:e}:!1}},{style:"background",getAttrs:r=>{const e=li(r);return e?{color:e}:!1}}],toDOM:r=>["mark",{style:`background-color: ${zt(r.attrs.color)??"#fef08a"}`},0]},code:{parseDOM:[{tag:"code"}],toDOM:()=>["code",0]}},Ll=new es({nodes:Mh,marks:Ah}),S=new es({nodes:dd(Ll.spec.nodes,"paragraph block*","block"),marks:Ll.spec.marks}),Nh=lt.fromSchema(S),Eh=bt.fromSchema(S);function Gn(r){const e=new window.DOMParser().parseFromString(`<!doctype html><body>${r}`,"text/html");return Eh.parse(e.body)}function Yn(r){if(zl(r))return"";const e=document.createElement("div");return e.append(Nh.serializeFragment(r.content)),e.querySelectorAll("[style]").forEach(t=>t.setAttribute("style",Th(t.getAttribute("style")??""))),e.innerHTML}const Oh=(r,e,t,n)=>"#"+[e,t,n].map(i=>(+i).toString(16).padStart(2,"0")).join("");function Th(r){return r.split(";").map(e=>e.trim()).filter(Boolean).map(e=>e.replace(/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/g,Oh).replace(/(^|[\s:])0px(?![\w.])/g,(t,n)=>`${n}0`).replace(/\s*:\s*/,": ")).join("; ")}function zl(r){const e=r.firstChild;return r.childCount===1&&!!e&&e.type===S.nodes.paragraph&&e.content.size===0&&!e.attrs.align}const ci=new Set(["UL","OL","BLOCKQUOTE","TABLE","THEAD","TBODY","TFOOT","TR","FIGURE"]),fi=new Set(["LI","TH","TD"]),Bl=r=>r.nodeType===1&&(ci.has(r.tagName)||fi.has(r.tagName)||/^(P|H[1-6]|PRE|HR|FIGCAPTION|IMG|DIV)$/.test(r.tagName)),vh=r=>{const t=r.cloneNode(!1).outerHTML;return t.slice(0,t.length-`</${r.localName}>`.length)};function Pl(r){const e=document.createElement("div");e.innerHTML=r;const t=[],n=(i,s)=>{const o=" ".repeat(s);let l="";const a=()=>{l.trim()&&t.push(o+l.trim()),l=""};i.childNodes.forEach(c=>{if(!Bl(c)){l+=c.nodeType===1?c.outerHTML:c.nodeType===3?Dh(c.textContent??""):"";return}a();const f=c,d=Array.from(f.childNodes).filter(Bl);(fi.has(f.tagName)?d.length<=1&&d.every(u=>!ci.has(u.tagName)&&!fi.has(u.tagName)):!ci.has(f.tagName))?t.push(o+f.outerHTML):(t.push(o+vh(f)),n(f,s+1),t.push(`${o}</${f.localName}>`))}),a()};return n(e,0),t.join(`
|
|
10
|
+
`)}const Dh=r=>r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/ /g," ");class Fe{constructor(e,t,n={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Rh(t):t,this.undoable=n.undoable!==!1,this.inCode=n.inCode||!1,this.inCodeMark=n.inCodeMark!==!1}}function Rh(r){return function(e,t,n,i){let s=r;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),n+=o;let l=n-i;l>0&&(s=t[0].slice(o-l,o)+s,n=i)}return e.tr.insertText(s,n,i)}}const Ih=500;function Lh({rules:r}){let e=new qe({state:{init(){return null},apply(t,n){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:n)}},props:{handleTextInput(t,n,i,s){return Fl(t,n,i,s,r,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:n}=t.state.selection;n&&Fl(t,n.pos,n.pos,"",r,e)})}}},isInputRules:!0});return e}function Fl(r,e,t,n,i,s){if(r.composing)return!1;let o=r.state,l=o.doc.resolve(e),a=r.state.selection,c=l.parent.textBetween(Math.max(0,l.parentOffset-Ih),l.parentOffset,null,"")+n,f=e==a.from&&t==a.to&&r.state.storedMarks||(e==t?l.marks():l.marksAcross(o.doc.resolve(t))||[]);for(let d=0;d<i.length;d++){let h=i[d];if(!h.inCodeMark&&f.some(g=>g.type.spec.code))continue;if(l.parent.type.spec.code){if(!h.inCode)continue}else if(h.inCode==="only")continue;let u=h.match.exec(c);if(!u||u[0].length<n.length)continue;let p=e-(u[0].length-n.length);if(!h.inCodeMark){let g=!1;if(o.doc.nodesBetween(p,l.pos,y=>{y.isInline&&y.marks.some(O=>O.type.spec.code)&&(g=!0)}),g)continue}let m=h.handler(o,u,p,t,n);if(m)return h.undoable&&m.setMeta(s,{transform:m,from:e,to:t,text:n}),r.dispatch(m),!0}return!1}const zh=(r,e)=>{let t=r.plugins;for(let n=0;n<t.length;n++){let i=t[n],s;if(i.spec.isInputRules&&(s=i.getState(r))){if(e){let o=r.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1};new Fe(/--$/,"—",{inCodeMark:!1}),new Fe(/\.\.\.$/,"…",{inCodeMark:!1}),new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1}),new Fe(/"$/,"”",{inCodeMark:!1}),new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1}),new Fe(/'$/,"’",{inCodeMark:!1});function di(r,e,t,n){let i,s;return e instanceof Ut?s=e:(i=e,s=e.nodeType,t=e.getAttrs,n=e.joinPredicate),new Fe(r,(o,l,a,c)=>{let f=t instanceof Function?t(l):t,d=o.tr.delete(a,c),h=d.doc.resolve(a),u=h.blockRange(),p=u&&ur(u,s,f);if(!p)return null;d.wrap(u,p);let m=d.doc.resolve(a-1).nodeBefore;return m&&m.type==s&&Rn(d.doc,a-1)&&(!n||n(l,m))&&d.join(a-1),d},i)}function Vl(r,e,t){let n,i;return e instanceof Ut?i=e:(n=e,i=e.nodeType,t=e.getAttrs),new Fe(r,(s,o,l,a)=>{let c=s.doc.resolve(l),f=t instanceof Function?t(o):t;return c.node(-1).canReplaceWith(c.index(-1),c.indexAfter(-1),i)?s.tr.delete(l,a).setBlockType(l,l,i,f):null},n)}const $l=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Bh(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const Ph=(r,e,t)=>{let n=Bh(r,t);if(!n)return!1;let i=Hl(n);if(!i){let o=n.blockRange(),l=o&&Gt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Ul(r,i,e,-1))return!0;if(n.parent.content.size==0&&(Bt(s,"end")||M.isSelectable(s)))for(let o=n.depth;;o--){let l=pr(r.doc,n.before(o),n.after(o),x.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=r.tr.step(l);a.setSelection(Bt(s,"end")?I.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):M.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};function Bt(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 Fh=(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=Hl(n)}let o=s&&s.nodeBefore;return!o||!M.isSelectable(o)?!1:(e&&e(r.tr.setSelection(M.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Hl(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 Vh(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset<t.parent.content.size)?null:t}const $h=(r,e,t)=>{let n=Vh(r,t);if(!n)return!1;let i=Wl(n);if(!i)return!1;let s=i.nodeAfter;if(Ul(r,i,e,1))return!0;if(n.parent.content.size==0&&(Bt(s,"start")||M.isSelectable(s))){let o=pr(r.doc,n.before(),n.after(),x.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=r.tr.step(o);l.setSelection(Bt(s,"start")?I.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):M.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},Hh=(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=Wl(n)}let o=s&&s.nodeAfter;return!o||!M.isSelectable(o)?!1:(e&&e(r.tr.setSelection(M.create(r.doc,s.pos)).scrollIntoView()),!0)};function Wl(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 ql=(r,e)=>{let{$from:t,$to:n}=r.selection,i=t.blockRange(n),s=i&&Gt(i);return s==null?!1:(e&&e(r.tr.lift(i,s).scrollIntoView()),!0)},Wh=(r,e)=>{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(`
|
|
11
|
+
`).scrollIntoView()),!0)};function hi(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 Jl=(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=hi(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(I.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},qh=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof ge||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=hi(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(L.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Jh=(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(wt(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&Gt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function Uh(r){return(e,t)=>{if(e.selection instanceof M&&e.selection.node.isBlock){let{$from:u}=e.selection;return!u.parentOffset||!wt(e.doc,u.pos)?!1:(t&&t(e.tr.split(u.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let n=e.tr;!e.selection.empty&&(e.selection instanceof L||e.selection instanceof ge)&&n.deleteSelection();let{$from:i}=n.selection,s=n.steps.length,o=[],l,a,c=!1,f=!1;for(let u=i.depth;;u--)if(i.node(u).isBlock){c=i.end(u)==i.pos+(i.depth-u),f=i.start(u)==i.pos-(i.depth-u),a=hi(i.node(u-1).contentMatchAt(i.indexAfter(u-1))),o.unshift(c&&a?{type:a}:null),l=u;break}else{if(u==1)return!1;o.unshift(null)}let d=i.pos,h=wt(n.doc,d,o.length,o);if(h||(o[0]=a?{type:a}:null,h=wt(n.doc,d,o.length,o)),!h)return!1;if(n.split(d,o.length,o),!c&&f&&i.node(l).type!=a){let u=n.mapping.slice(s),p=u.map(i.before(l)),m=n.doc.resolve(p);a&&i.node(l-1).canReplaceWith(m.index(),m.index()+1,a)&&n.setNodeMarkup(u.map(i.before(l)),a)}return t&&t(n.scrollIntoView()),!0}}const Kh=Uh(),_h=(r,e)=>(e&&e(r.tr.setSelection(new ge(r.doc))),!0);function jh(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||Rn(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Ul(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&jh(r,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=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 ee(e.pos-1,u,e.pos,u,new x(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||n>0&&a?null:I.findFrom(e,1),d=f&&f.$from.blockRange(f.$to),h=d&&Gt(d);if(h!=null&&h>=e.depth)return t&&t(r.tr.lift(d,h).scrollIntoView()),!0;if(c&&Bt(s,"start",!0)&&Bt(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=b.empty;for(let w=p.length-1;w>=0;w--)y=b.from(p[w].copy(y));let O=r.tr.step(new ee(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new x(y,p.length,0),0,!0));t(O.scrollIntoView())}return!0}}return!1}function Kl(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(L.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const Gh=Kl(-1),Yh=Kl(1);function Xh(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&ur(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ui(r,e=null){return function(t,n){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,c)=>{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(r,e)))if(a.type==r)i=!0;else{let f=t.doc.resolve(c),d=f.index();i=f.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 Zh(r,e,t,n){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?r.inlineContent&&r.type.allowsMarkType(t):!1;if(r.nodesBetween(s.pos,o.pos,(a,c)=>{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Qh(r,e=null,t){return function(n,i){let{empty:s,$cursor:o,ranges:l}=n.selection;if(s&&!o||!Zh(n.doc,l,r))return!1;if(i)if(o)r.isInSet(n.storedMarks||o.marks())?i(n.tr.removeStoredMark(r)):i(n.tr.addStoredMark(r.create(e)));else{let a,c=n.tr;a=!l.some(f=>n.doc.rangeHasMark(f.$from.pos,f.$to.pos,r));for(let f=0;f<l.length;f++){let{$from:d,$to:h}=l[f];if(!a)c.removeMark(d.pos,h.pos,r);else{let u=d.pos,p=h.pos,m=d.nodeAfter,g=h.nodeBefore,y=m&&m.isText?/^\s*/.exec(m.text)[0].length:0,O=g&&g.isText?/\s*$/.exec(g.text)[0].length:0;u+y<p&&(u+=y,p-=O),c.addMark(u,p,r.create(e))}}i(c.scrollIntoView())}return!0}}function Xn(...r){return function(e,t,n){for(let i=0;i<r.length;i++)if(r[i](e,t,n))return!0;return!1}}let pi=Xn($l,Ph,Fh),_l=Xn($l,$h,Hh);const Ve={Enter:Xn(Wh,qh,Jh,Kh),"Mod-Enter":Jl,Backspace:pi,"Mod-Backspace":pi,"Shift-Backspace":pi,Delete:_l,"Mod-Delete":_l,"Mod-a":_h},jl={"Ctrl-h":Ve.Backspace,"Alt-Backspace":Ve["Mod-Backspace"],"Ctrl-d":Ve.Delete,"Ctrl-Alt-Backspace":Ve["Mod-Delete"],"Alt-Delete":Ve["Mod-Delete"],"Alt-d":Ve["Mod-Delete"],"Ctrl-a":Gh,"Ctrl-e":Yh};for(let r in Ve)jl[r]=Ve[r];const eu=(typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1)?jl:Ve;function pn(r,e){const{from:t,$from:n,to:i,empty:s}=r.selection;return s?!!e.isInSet(r.storedMarks||n.marks()):r.doc.rangeHasMark(t,i,e)}function tu(r){const e=r.selection.$from.parent;return e.type===S.nodes.paragraph?"paragraph":e.type===S.nodes.code_block?"codeBlock":e.type===S.nodes.heading?`heading${e.attrs.level}`:null}function nu(r){return r==="paragraph"?ui(S.nodes.paragraph):r==="codeBlock"?ui(S.nodes.code_block):ui(S.nodes.heading,{level:Number(r.slice(-1))})}const Te=r=>Qh(S.marks[r]);function Gl(r,e){const{$from:t}=r.selection;for(let n=t.depth;n>0;n--)if(t.node(n).type===e)return!0;return!1}function Yl(r){const{$from:e}=r.selection;for(let t=e.depth;t>0;t--){const n=e.node(t).type;if(n===S.nodes.bullet_list||n===S.nodes.ordered_list)return n}return null}function Xl(r){return(e,t,n)=>{const{$from:i}=e.selection;for(let s=i.depth;s>0;s--){const o=i.node(s);if(o.type===S.nodes.bullet_list||o.type===S.nodes.ordered_list)return o.type===r?al(S.nodes.list_item)(e,t):(t&&t(e.tr.setNodeMarkup(i.before(s),r)),!0)}return hd(r)(e,t)}}const mi=bd(S.nodes.list_item),gi=(r,e,t)=>al(S.nodes.list_item)(r,e)||ql(r,e);function ru(){return(r,e)=>Gl(r,S.nodes.blockquote)?ql(r,e):Xh(S.nodes.blockquote)(r,e)}function et(r){return(e,t)=>{const n=r==="left"?null:r,{from:i,to:s}=e.selection,o=e.tr;let l=!1;return e.doc.nodesBetween(i,s,(a,c)=>a.type===S.nodes.paragraph||a.type===S.nodes.heading?(l=!0,a.attrs.align!==n&&o.setNodeMarkup(c,void 0,{...a.attrs,align:n}),!1):!0),l?(t&&t(o),!0):!1}}function Zn(r){return r.selection.$from.parent.attrs.align??"left"}const iu=(r,e)=>{const t=S.nodes.horizontal_rule;if(!e)return!0;const n=r.tr.replaceSelectionWith(t.create()),i=n.selection.$from;return!i.nodeAfter&&i.parent.type===S.nodes.doc&&n.insert(i.pos,S.nodes.paragraph.create()),e(n.scrollIntoView()),!0},su=(r,e)=>{const{from:t,to:n,empty:i}=r.selection,s=r.tr;if(i)s.setStoredMarks([]);else for(const o of Object.values(S.marks))o!==S.marks.link&&s.removeMark(t,n,o);return r.doc.nodesBetween(t,n,(o,l)=>o.isTextblock&&o.type!==S.nodes.paragraph?(s.setBlockType(l,l+o.nodeSize,S.nodes.paragraph),!1):(o.type===S.nodes.paragraph&&o.attrs.align&&s.setNodeMarkup(l,void 0,{align:null}),!0)),e&&e(s),!0};function yi(r){const e=S.marks.link,{$from:t,from:n,to:i,empty:s}=r.selection;if(!s){let d=null;return r.doc.nodesBetween(n,i,(h,u)=>{const p=e.isInSet(h.marks);p&&!d&&(d={from:Math.max(u,n),to:Math.min(u+h.nodeSize,i),...p.attrs})}),d}const o=e.isInSet(t.marks())??e.isInSet(t.nodeBefore?.marks??[]);if(!o)return null;const l=t.start(),a=[];let c=0;t.parent.forEach(d=>{const h=l+c,u=h+d.nodeSize;if(o.isInSet(d.marks)){const p=a[a.length-1];p&&p[1]===h?p[1]=u:a.push([h,u])}c+=d.nodeSize});const f=a.find(([d,h])=>d<=t.pos&&t.pos<=h);return f?{from:f[0],to:f[1],...o.attrs}:null}function bi(r){const e=r.selection;return e instanceof M&&(e.node.type===S.nodes.image||e.node.type===S.nodes.figure)?{pos:e.from,attrs:e.node.attrs,figure:e.node.type===S.nodes.figure,node:e.node}:null}function Zl(r,e,t){const n=S.nodes.figure.create(t),i=r.doc.resolve(e),s=i.parent;s.type===S.nodes.paragraph&&s.childCount===1?r.replaceWith(i.before(),i.after(),n):r.replaceRangeWith(e,e+1,n);let o=-1;return r.doc.descendants((l,a)=>o>=0?!1:(l.type===S.nodes.figure&&l.attrs.src===t.src&&l.content.size===0&&(o=a),!0)),o>=0&&r.setSelection(L.create(r.doc,o+1)),r}function ou(r,e,t,n){const i=S.nodes.image.create(n),s=[S.nodes.paragraph.create(null,i)];return t.content.size&&s.push(S.nodes.paragraph.create(null,t.content)),r.replaceWith(e,e+t.nodeSize,b.from(s)),r.setSelection(M.create(r.doc,e+1))}function lu(r,e,t=!0){const n=S.nodes,i=s=>n.table_row.create(null,Array.from({length:e},()=>s.createAndFill()));return n.table.create(null,Array.from({length:r},(s,o)=>i(t&&o===0?n.table_header:n.table_cell)))}function au(r,e){return(t,n)=>{if(he(t))return!1;if(!n)return!0;const i=lu(r,e),s=t.tr,o=t.selection.$from;o.parent.type===S.nodes.paragraph&&o.parent.content.size===0&&o.depth===1?s.replaceWith(o.before(),o.after(),i):s.replaceSelectionWith(i);let a=-1;if(s.doc.descendants((c,f)=>a>=0?!1:(c===i&&(a=f),a<0&&c.type!==S.nodes.table)),a>=0){const c=a+s.doc.nodeAt(a).nodeSize;c>=s.doc.content.size&&s.insert(c,S.nodes.paragraph.create()),s.setSelection(L.create(s.doc,a+4))}return n(s.scrollIntoView()),!0}}const cu=(r,e,t)=>he(r)?ri(1)(r,e)||!e||!t?!0:(yl(r,e),ri(1)(t.state,e)):!1,fu=(r,e)=>he(r)&&ri(-1)(r,e);function wi(r,e){const t=S.marks[e],{from:n,to:i,empty:s,$from:o}=r.selection;if(s)return t.isInSet(r.storedMarks||o.marks())?.attrs.color??null;let l;return r.doc.nodesBetween(n,i,a=>{if(!a.isText||l===null)return;const c=t.isInSet(a.marks)?.attrs.color??null;l=l===void 0||l===c?c:null}),l??null}function du(r,e){return(t,n)=>{const i=S.marks[r],{from:s,to:o,empty:l}=t.selection;if(!n)return!0;const a=t.tr;return l?(a.removeStoredMark(i),e&&a.addStoredMark(i.create({color:e}))):(a.removeMark(s,o,i),e&&a.addMark(s,o,i.create({color:e}))),n(a.scrollIntoView()),!0}}function hu(){const r=S.nodes;return Lh({rules:[Vl(/^(#{1,4})\s$/,r.heading,e=>({level:e[1].length})),di(/^\s*>\s$/,r.blockquote),di(/^\s*([-+*])\s$/,r.bullet_list),di(/^(\d+)\.\s$/,r.ordered_list,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order===+e[1]),Vl(/^```$/,r.code_block),new Fe(/^(?:---|\*\*\*|___)$/,(e,t,n,i)=>{const s=e.doc.resolve(n);if(s.parent.type!==r.paragraph)return null;const o=s.before();return e.tr.replaceWith(o,i+1,[r.horizontal_rule.create(),r.paragraph.create()])})]})}function uu(r){const e=Xn(Jl,(t,n)=>(n&&n(t.tr.replaceSelectionWith(S.nodes.hard_break.create()).scrollIntoView()),!0));return Yr({"Mod-z":Kr,"Mod-y":qn,"Shift-Mod-z":qn,Backspace:zh,"Mod-b":Te("strong"),"Mod-i":Te("em"),"Mod-u":Te("underline"),"Mod-Shift-x":Te("strike"),"Mod-e":Te("code"),"Mod-k":r.link,"Shift-Enter":e,"Mod-Enter":e,Enter:md(S.nodes.list_item),Tab:mi,"Shift-Tab":gi})}const pu=()=>Yr(eu);function mu(r){return new qe({props:{decorations(e){const t=e.doc,n=t.firstChild;return!r||t.childCount!==1||!n||!n.isTextblock||n.content.size>0?null:q.create(t,[fe.node(0,n.nodeSize,{class:"wds-placeholder","data-placeholder":r})])}}})}const pt=new Mt("wds-upload");function gu(){return new qe({key:pt,state:{init:()=>q.empty,apply(r,e){e=e.map(r.mapping,r.doc);const t=r.getMeta(pt);if(t&&"add"in t){const n=document.createElement("span");n.className="wds-upload-placeholder",n.setAttribute("aria-hidden","true"),e=e.add(r.doc,[fe.widget(t.add.pos,n,{id:t.add.id})])}else t&&"remove"in t&&(e=e.remove(e.find(void 0,void 0,n=>n.id===t.remove.id)));return e}},props:{decorations:r=>pt.getState(r)}})}function yu(r,e){const t=pt.getState(r)?.find(void 0,void 0,n=>n.id===e);return t&&t.length?t[0].from:null}const P=r=>`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${r}</svg>`,z={undo:P('<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>'),redo:P('<path d="m15 14 5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>'),bold:P('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7z"/>'),italic:P('<path d="M14 5h-4"/><path d="M14 19h-4"/><path d="m14 5-4 14"/><path d="M18 5h-4M10 19H6"/>'),underline:P('<path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20h14"/>'),strike:P('<path d="M4 12h16"/><path d="M16.5 7.5C16 5.6 14.2 4.5 12 4.5c-2.6 0-4.5 1.4-4.5 3.4 0 1.3.8 2.3 2.4 3"/><path d="M8 16.5c.6 1.9 2.2 3 4.3 3 2.7 0 4.6-1.4 4.6-3.6 0-.9-.3-1.6-.9-2.2"/>'),code:P('<path d="m9 8-4 4 4 4"/><path d="m15 8 4 4-4 4"/>'),link:P('<path d="M10 14a4.5 4.5 0 0 0 6.4 0l3-3a4.5 4.5 0 0 0-6.4-6.4l-1 1"/><path d="M14 10a4.5 4.5 0 0 0-6.4 0l-3 3a4.5 4.5 0 0 0 6.4 6.4l1-1"/>'),blockquote:P('<path d="M5 18c2.5-1 4-3.2 4-6.5V7H5v5h3"/><path d="M14 18c2.5-1 4-3.2 4-6.5V7h-4v5h3"/>'),bulletList:P('<circle cx="5" cy="7" r="1" fill="currentColor"/><circle cx="5" cy="12" r="1" fill="currentColor"/><circle cx="5" cy="17" r="1" fill="currentColor"/><path d="M9 7h11M9 12h11M9 17h11"/>'),orderedList:P('<path d="M10 7h10M10 12h10M10 17h10"/><path d="M4 5.5 5.5 5v4"/><path d="M4 14.2c.3-.6.8-.9 1.4-.9.7 0 1.1.4 1.1 1 0 .9-1.4 1.6-2.5 2.7h2.6"/>'),indent:P('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m4 9.5 3 2.5-3 2.5"/>'),outdent:P('<path d="M4 6h16M10 10h10M10 14h10M4 18h16"/><path d="m7 9.5-3 2.5 3 2.5"/>'),alignLeft:P('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>'),alignCenter:P('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>'),alignRight:P('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>'),alignJustify:P('<path d="M4 6h16M4 10h16M4 14h16M4 18h16"/>'),hr:P('<path d="M3 12h18"/><path d="M8 7h8M8 17h8" opacity=".45"/>'),clear:P('<path d="M6 5h12"/><path d="M12 5 9 19"/><path d="m15 14 5 5M20 14l-5 5"/>'),source:P('<path d="m8 7-5 5 5 5"/><path d="m16 7 5 5-5 5"/><path d="m14 4-4 16"/>'),fullscreen:P('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),close:P('<path d="M6 6l12 12M18 6 6 18"/>'),image:P('<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="8.5" cy="9.5" r="1.5"/><path d="m21 16-5-5-9 9"/>'),file:P('<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M9 13h6M9 17h4"/>'),folder:P('<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>'),upload:P('<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),grid:P('<rect x="4" y="4" width="6" height="6" rx="1"/><rect x="14" y="4" width="6" height="6" rx="1"/><rect x="4" y="14" width="6" height="6" rx="1"/><rect x="14" y="14" width="6" height="6" rx="1"/>'),list:P('<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6h1M4 12h1M4 18h1"/>'),trash:P('<path d="M4 7h16"/><path d="M10 11v6M14 11v6"/><path d="M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12"/><path d="M9 7V4h6v3"/>'),table:P('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>'),pasteText:P('<path d="M9 4h6v3H9z"/><path d="M15 5h2a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2"/><path d="M9 12h6M12 12v6"/>'),textColor:P('<path d="m6 16 6-12 6 12"/><path d="M8.5 11h7"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),highlight:P('<path d="m14 4 5 5-7 7H7v-5z"/><path d="M7 16l-2 2"/><rect class="wds-swatch-bar" x="3" y="19" width="18" height="3" rx="1" stroke="none"/>'),globe:P('<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18"/>')},oe=r=>e=>e.exec(r),bu={undo:{type:"button",label:"undo",icon:z.undo,shortcut:"Mod+Z",run:r=>r.undo(),enabled:r=>rd(r)>0},redo:{type:"button",label:"redo",icon:z.redo,shortcut:"Mod+Y",run:r=>r.redo(),enabled:r=>id(r)>0},blocks:{type:"blocks"},bold:{type:"button",label:"bold",icon:z.bold,shortcut:"Mod+B",run:oe(Te("strong")),active:r=>pn(r,S.marks.strong)},italic:{type:"button",label:"italic",icon:z.italic,shortcut:"Mod+I",run:oe(Te("em")),active:r=>pn(r,S.marks.em)},underline:{type:"button",label:"underline",icon:z.underline,shortcut:"Mod+U",run:oe(Te("underline")),active:r=>pn(r,S.marks.underline)},strike:{type:"button",label:"strike",icon:z.strike,run:oe(Te("strike")),active:r=>pn(r,S.marks.strike)},textColor:{type:"button",label:"textColor",icon:z.textColor,popup:!0,run:(r,e)=>r.openColorPicker("textColor",e),swatch:r=>wi(r,"textColor")},highlight:{type:"button",label:"highlight",icon:z.highlight,popup:!0,run:(r,e)=>r.openColorPicker("highlight",e),swatch:r=>wi(r,"highlight")},code:{type:"button",label:"code",icon:z.code,run:oe(Te("code")),active:r=>pn(r,S.marks.code)},link:{type:"button",label:"link",icon:z.link,shortcut:"Mod+K",run:r=>r.openLinkDialog(),active:r=>!!yi(r)},image:{type:"button",label:"image",icon:z.image,run:r=>r.openImageDialog(),active:r=>!!bi(r)},file:{type:"button",label:"file",icon:z.file,run:r=>r.openFileManager("file"),available:r=>r.hasFileManager()},table:{type:"button",label:"table",icon:z.table,popup:!0,run:(r,e)=>r.openTableMenu(e),active:r=>he(r)},blockquote:{type:"button",label:"blockquote",icon:z.blockquote,run:oe(ru()),active:r=>Gl(r,S.nodes.blockquote)},bulletList:{type:"button",label:"bulletList",icon:z.bulletList,run:oe(Xl(S.nodes.bullet_list)),active:r=>Yl(r)===S.nodes.bullet_list},orderedList:{type:"button",label:"orderedList",icon:z.orderedList,run:oe(Xl(S.nodes.ordered_list)),active:r=>Yl(r)===S.nodes.ordered_list},outdent:{type:"button",label:"outdent",icon:z.outdent,run:oe(gi),enabled:r=>gi(r)},indent:{type:"button",label:"indent",icon:z.indent,run:oe(mi),enabled:r=>mi(r)},alignLeft:{type:"button",label:"alignLeft",icon:z.alignLeft,run:oe(et("left")),active:r=>Zn(r)==="left",enabled:r=>et("left")(r)},alignCenter:{type:"button",label:"alignCenter",icon:z.alignCenter,run:oe(et("center")),active:r=>Zn(r)==="center",enabled:r=>et("center")(r)},alignRight:{type:"button",label:"alignRight",icon:z.alignRight,run:oe(et("right")),active:r=>Zn(r)==="right",enabled:r=>et("right")(r)},alignJustify:{type:"button",label:"alignJustify",icon:z.alignJustify,run:oe(et("justify")),active:r=>Zn(r)==="justify",enabled:r=>et("justify")(r)},hr:{type:"button",label:"hr",icon:z.hr,run:oe(iu)},clear:{type:"button",label:"clear",icon:z.clear,run:oe(su)},pasteText:{type:"button",label:"pasteText",icon:z.pasteText,run:r=>r.togglePlainPaste(),active:(r,e)=>e.isPlainPaste()},source:{type:"button",label:"source",icon:z.source,run:r=>r.toggleSource(),active:(r,e)=>e.isSourceMode(),inSource:!0},fullscreen:{type:"button",label:"fullscreen",icon:z.fullscreen,run:r=>r.toggleFullscreen(),active:(r,e)=>e.isFullscreen(),inSource:!0}},wu=["undo","redo","|","blocks","|","bold","italic","underline","strike","code","textColor","highlight","|","link","image","file","table","blockquote","bulletList","orderedList","outdent","indent","|","alignLeft","alignCenter","alignRight","alignJustify","|","hr","clear","pasteText","|","source","fullscreen"],ku=[["paragraph","paragraph"],["heading1","heading1"],["heading2","heading2"],["heading3","heading3"],["heading4","heading4"],["codeBlock","codeBlock"]],xu=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform||navigator.userAgent),Su=r=>r.replace("Mod",xu?"⌘":"Ctrl");function Cu(r,e,t){const n=document.createElement("div");n.className="wds-toolbar",n.setAttribute("role","toolbar"),n.setAttribute("aria-label",t.toolbarLabel);const i=[];let s=document.createElement("div");s.className="wds-group",n.append(s);for(const l of e){if(l==="|"){s.childElementCount&&(s=document.createElement("div"),s.className="wds-group",n.append(s));continue}const a=bu[l];if(!a){console.warn(`[WDS Editor] Unknown toolbar item "${l}".`);continue}if(a.type==="blocks"){const d=document.createElement("select");d.className="wds-select",d.setAttribute("aria-label",t.blockType),d.title=t.blockType;for(const[u,p]of ku){const m=document.createElement("option");m.value=u,m.textContent=t[p],d.append(m)}const h=document.createElement("option");h.value="",h.textContent="—",h.hidden=!0,d.append(h),d.addEventListener("change",()=>{d.value&&r.exec(nu(d.value)),r.focus()}),s.append(d),i.push(u=>{d.value=tu(u)??"",d.disabled=r.isSourceMode()||r.isReadOnly()});continue}if(a.available&&!a.available(r))continue;const c=document.createElement("button");c.type="button",c.className="wds-button-tool",c.innerHTML=a.icon;const f=t[a.label];c.setAttribute("aria-label",f),c.title=a.shortcut?`${f} (${Su(a.shortcut)})`:f,c.dataset.item=l,a.popup&&(c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false")),c.addEventListener("mousedown",d=>d.preventDefault()),c.addEventListener("click",()=>{c.disabled||a.run(r,c)}),s.append(c),i.push(d=>{const h=r.isSourceMode()&&!a.inSource||r.isReadOnly()&&!a.inSource;if(c.disabled=h||(a.enabled?!a.enabled(d,r):!1),a.swatch){const u=h?null:a.swatch(d);u?c.style.setProperty("--wds-swatch",u):c.style.removeProperty("--wds-swatch")}if(a.active){const u=!h&&a.active(d,r);c.classList.toggle("is-active",u),c.setAttribute("aria-pressed",String(u))}})}return n.addEventListener("keydown",l=>{if(l.key!=="ArrowRight"&&l.key!=="ArrowLeft"&&l.key!=="Home"&&l.key!=="End"||l.target.tagName==="SELECT"&&(l.key==="Home"||l.key==="End"))return;const a=[...n.querySelectorAll("button:not([disabled]), select:not([disabled])")],c=a.indexOf(document.activeElement);if(c<0)return;l.preventDefault();const f=l.key==="Home"?0:l.key==="End"?a.length-1:(c+(l.key==="ArrowRight"?1:-1)+a.length)%a.length;a.forEach(d=>d.tabIndex=-1),a[f].tabIndex=0,a[f].focus()}),{element:n,update:l=>{i.forEach(c=>c(l));const a=[...n.querySelectorAll("button, select")];if(!a.some(c=>c.tabIndex===0&&!c.disabled)){a.forEach(f=>f.tabIndex=-1);const c=a.find(f=>!f.disabled);c&&(c.tabIndex=0)}}}}class J extends I{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return J.valid(n)?new J(n):I.near(n)}content(){return x.empty}eq(e){return e instanceof J&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new J(e.resolve(t.pos))}getBookmark(){return new ki(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!Mu(e)||!Au(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&J.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)<l.childCount:e.index(o)>0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let a=e.doc.resolve(i);if(J.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!M.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),n=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(J.valid(l))return l}return null}}}J.prototype.visible=!1,J.findFrom=J.findGapCursorFrom,I.jsonID("gapcursor",J);class ki{constructor(e){this.pos=e}map(e){return new ki(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return J.valid(t)?new J(t):I.near(t)}}function Ql(r){return r.isAtom||r.spec.isolating||r.spec.createGapCursor}function Mu(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||Ql(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Au(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||Ql(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Nu(){return new qe({props:{decorations:vu,createSelectionBetween(r,e,t){return e.pos==t.pos&&J.valid(t)?new J(t):null},handleClick:Ou,handleKeyDown:Eu,handleDOMEvents:{beforeinput:Tu}}})}const Eu=Xr({ArrowLeft:Qn("horiz",-1),ArrowRight:Qn("horiz",1),ArrowUp:Qn("vert",-1),ArrowDown:Qn("vert",1)});function Qn(r,e){const t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,s){let o=n.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof L){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let c=J.findGapCursorFrom(l,e,a);return c?(i&&i(n.tr.setSelection(new J(c))),!0):!1}}function Ou(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!J.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&M.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new J(n))),!0)}function Tu(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof J))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=b.empty;for(let o=n.length-1;o>=0;o--)i=b.from(n[o].createAndFill(null,i));let s=r.state.tr.replace(t.pos,t.pos,new x(i,0,0));return s.setSelection(L.near(s.doc.resolve(t.pos+1))),r.dispatch(s),!1}function vu(r){if(!(r.selection instanceof J))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",q.create(r.doc,[fe.widget(r.selection.head,e,{key:"gapcursor"})])}function Du(r={}){return new qe({view(e){return new Ru(e,r)}})}class Ru{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=(n=t.width)!==null&&n!==void 0?n:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc)if(this.lastDragEvent){let n=this.computeTarget(this.lastDragEvent);n==this.cursorPos?this.updateOverlay():this.setCursor(n)}else this.updateOverlay()}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,i=this.editorView.dom,s=i.getBoundingClientRect(),o=s.width/i.offsetWidth,l=s.height/i.offsetHeight;if(t){let d=e.nodeBefore,h=e.nodeAfter;if(d||h){let u=this.editorView.nodeDOM(this.cursorPos-(d?d.nodeSize:0));if(u){let p=u.getBoundingClientRect(),m=d?p.bottom:p.top;d&&h&&(m=(m+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let g=this.width/2*l;n={left:p.left,right:p.right,top:m-g,bottom:m+g}}}}if(!n){let d=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*o;n={left:d.left-h,right:d.left+h,top:d.top,bottom:d.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let c,f;if(!a||a==document.body&&getComputedStyle(a).position=="static")c=-pageXOffset,f=-pageYOffset;else{let d=a.getBoundingClientRect(),h=d.width/a.offsetWidth,u=d.height/a.offsetHeight;c=d.left-a.scrollLeft*h,f=d.top-a.scrollTop*u}this.element.style.left=(n.left-c)/o+"px",this.element.style.top=(n.top-f)/l+"px",this.element.style.width=(n.right-n.left)/o+"px",this.element.style.height=(n.bottom-n.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=n&&n.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(!t||s)return null;let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=ks(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}return o}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}function ea(r,e,t,n){const i=document.createElement("span");i.className="wds-image";const s=document.createElement("img");s.draggable=!1;const o=document.createElement("span");o.className="wds-resize-handle",o.title=n.resizeLabel,o.setAttribute("aria-hidden","true"),i.append(s,o);const l=()=>{const f=e();f!==void 0&&r.dispatch(r.state.tr.setSelection(M.create(r.state.doc,f)))};let a=!1;return o.addEventListener("pointerdown",f=>{if(!r.editable)return;f.preventDefault(),f.stopPropagation(),l(),a=!0;try{o.setPointerCapture(f.pointerId)}catch{}const d=f.clientX,h=s.getBoundingClientRect().width,u=Math.max(40,r.dom.clientWidth-8);let p=h;const m=y=>{p=Math.round(Math.min(u,Math.max(40,h+y.clientX-d))),s.style.width=`${p}px`,s.style.height="auto",i.dataset.size=`${p}px`},g=()=>{a=!1,window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g),delete i.dataset.size,s.style.width="",s.style.height="";const y=e();if(y===void 0||Math.abs(p-h)<2)return;const O=t(),w=r.state.tr.setNodeMarkup(y,void 0,{...O.attrs,width:p,height:null});r.dispatch(w.setSelection(M.create(w.doc,y)))};window.addEventListener("pointermove",m),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g)}),i.addEventListener("dblclick",f=>{if(!r.editable)return;f.preventDefault(),l();const d=e();d!==void 0&&n.onEdit(d)}),{box:i,img:s,handle:o,select:l,render:f=>{const d=ai(f.attrs,!1);for(const h of["src","alt","title","width","height"])d[h]!==void 0?s.setAttribute(h,d[h]):s.removeAttribute(h)},isResizing:()=>a}}const ta=(r,e)=>{r.classList.remove("wds-align-left","wds-align-center","wds-align-right"),e&&r.classList.add(`wds-align-${e}`)};class Iu{constructor(e,t,n,i){this.node=e,this.parts=ea(t,n,()=>this.node,i),this.dom=this.parts.box,this.render()}render(){this.parts.render(this.node),ta(this.dom,this.node.attrs.align)}update(e){return e.type!==this.node.type?!1:(this.node=e,this.render(),!0)}stopEvent(e){return e.target===this.parts.handle||this.parts.isResizing()}ignoreMutation(){return!0}}class Lu{constructor(e,t,n,i){this.node=e,this.dom=document.createElement("figure"),this.dom.className="wds-figure",this.parts=ea(t,n,()=>this.node,i),this.parts.box.contentEditable="false",this.parts.box.addEventListener("mousedown",s=>{s.target===this.parts.handle||s.detail>1||(s.preventDefault(),this.parts.select(),t.focus())}),this.contentDOM=document.createElement("figcaption"),this.contentDOM.dataset.placeholder=i.captionPlaceholder,this.dom.append(this.parts.box,this.contentDOM),this.render()}render(){this.parts.render(this.node),ta(this.dom,this.node.attrs.align),this.dom.classList.toggle("is-empty",this.node.content.size===0)}update(e){return e.type!==this.node.type?!1:(this.node=e,this.render(),!0)}stopEvent(e){return this.parts.box.contains(e.target)&&!e.type.startsWith("drag")}ignoreMutation(e){return!this.contentDOM.contains(e.target)}}let er=null;function na(){er?.close()}function xi(r,e,t,n){na();const i=document.createElement("div");i.className=`wds-menu ${t}`,e.append(i);const s=()=>{const d=r.getBoundingClientRect();i.style.maxHeight="";const h=i.offsetWidth,u=i.offsetHeight;i.style.left=`${Math.max(4,Math.min(d.left,window.innerWidth-h-4))}px`;const p=window.innerHeight-d.bottom-8,m=d.top-8;u<=p||p>=m?(i.style.top=`${d.bottom+4}px`,u>p&&(i.style.maxHeight=`${p}px`)):(i.style.top=`${Math.max(4,d.top-Math.min(u,m)-4)}px`,u>m&&(i.style.maxHeight=`${m}px`))},o=d=>{if(d.target instanceof Node&&i.contains(d.target))return;const h=r.getBoundingClientRect();h.bottom<0||h.top>window.innerHeight||!r.isConnected?f():s()};r.setAttribute("aria-expanded","true");const l=d=>{!i.contains(d.target)&&d.target!==r&&!r.contains(d.target)&&f()},a=d=>{d.key==="Escape"&&(d.preventDefault(),d.stopPropagation(),f(!0))};let c=!1;function f(d=!1){c||(c=!0,i.remove(),r.setAttribute("aria-expanded","false"),document.removeEventListener("mousedown",l,!0),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),i.removeEventListener("keydown",a),er?.close===f&&(er=null),d&&r.focus())}return document.addEventListener("mousedown",l,!0),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),i.addEventListener("keydown",a),er={close:f},{popup:i,place:s,close:f}}function zu(r,e,t,n){const{popup:i,place:s,close:o}=xi(r,e,"wds-menu-list");i.setAttribute("role","menu"),i.setAttribute("aria-label",n);for(const a of t){if(a==="|"){const f=document.createElement("div");f.className="wds-menu-sep",f.setAttribute("role","separator"),i.append(f);continue}const c=document.createElement("button");c.type="button",c.className=`wds-menu-item${a.danger?" is-danger":""}`,c.setAttribute("role","menuitem"),c.tabIndex=-1,c.innerHTML=a.icon??"",c.append(document.createTextNode(a.label)),a.enabled===!1&&(c.disabled=!0),c.addEventListener("mousedown",f=>f.preventDefault()),c.addEventListener("click",()=>{o(),a.run()}),i.append(c)}const l=()=>[...i.querySelectorAll(".wds-menu-item:not(:disabled)")];i.addEventListener("keydown",a=>{const c=l(),f=c.indexOf(document.activeElement);let d=-1;a.key==="ArrowDown"?d=(f+1)%c.length:a.key==="ArrowUp"?d=(f-1+c.length)%c.length:a.key==="Home"?d=0:a.key==="End"?d=c.length-1:a.key==="Tab"&&o(),d>=0&&(a.preventDefault(),c[d]?.focus())}),s(),l()[0]?.focus()}function Bu(r,e,t,n,i){const{popup:l,place:a,close:c}=xi(r,e,"wds-table-picker");l.setAttribute("role","dialog"),l.setAttribute("aria-label",t);const f=document.createElement("div");f.className="wds-picker-grid",f.style.gridTemplateColumns="repeat(10, 1fr)",f.tabIndex=0,f.setAttribute("role","grid"),f.setAttribute("aria-label",t);const d=document.createElement("div");d.className="wds-picker-label",d.setAttribute("aria-live","polite");const h=[];let u=3,p=3;const m=()=>{h.forEach((g,y)=>g.classList.toggle("is-on",Math.floor(y/10)<u&&y%10<p)),d.textContent=n(u,p),f.setAttribute("aria-valuetext",d.textContent)};for(let g=0;g<8;g++)for(let y=0;y<10;y++){const O=document.createElement("span");O.className="wds-picker-cell",O.addEventListener("mouseenter",()=>{u=g+1,p=y+1,m()}),O.addEventListener("mousedown",w=>w.preventDefault()),O.addEventListener("click",()=>{c(),i(g+1,y+1)}),h.push(O),f.append(O)}f.addEventListener("keydown",g=>{const y={ArrowRight:[0,1],ArrowLeft:[0,-1],ArrowDown:[1,0],ArrowUp:[-1,0]};y[g.key]?(g.preventDefault(),u=Math.min(8,Math.max(1,u+y[g.key][0])),p=Math.min(10,Math.max(1,p+y[g.key][1])),m()):g.key==="Enter"||g.key===" "?(g.preventDefault(),c(),i(u,p)):g.key==="Tab"&&c()}),l.append(f,d),m(),a(),f.focus()}function Pu(r,e,t){const{popup:n,place:i,close:s}=xi(r,e,"wds-color-picker");n.setAttribute("role","dialog"),n.setAttribute("aria-label",t.label);const o=c=>{s(),t.onPick(c)},l=document.createElement("button");l.type="button",l.className="wds-menu-item wds-color-remove",l.innerHTML='<span class="wds-swatch is-none" aria-hidden="true"></span>',l.append(document.createTextNode(t.removeLabel)),l.addEventListener("mousedown",c=>c.preventDefault()),l.addEventListener("click",()=>o(null));const a=document.createElement("div");a.className="wds-swatches",a.style.gridTemplateColumns=`repeat(${t.columns}, 1fr)`;for(const c of t.swatches){const f=document.createElement("button");f.type="button",f.className="wds-swatch",f.style.background=c.color,f.title=c.label,f.setAttribute("aria-label",c.label);const d=c.color===t.current;f.setAttribute("aria-pressed",String(d)),d&&f.classList.add("is-current"),f.addEventListener("mousedown",h=>h.preventDefault()),f.addEventListener("click",()=>o(c.color)),a.append(f)}n.append(l,a),n.addEventListener("keydown",c=>{const f=[l,...a.querySelectorAll(".wds-swatch")],d=f.indexOf(document.activeElement);if(d<0)return;const h=t.columns;let u=-1;c.key==="ArrowRight"?u=Math.min(f.length-1,d+1):c.key==="ArrowLeft"?u=Math.max(0,d-1):c.key==="ArrowDown"?u=d===0?1:Math.min(f.length-1,d+h):c.key==="ArrowUp"?u=d<=h?0:d-h:c.key==="Tab"&&s(),u>=0&&(c.preventDefault(),f[u].focus())}),i(),(a.querySelector(".is-current")??a.querySelector(".wds-swatch"))?.focus()}const tr={undo:"Undo",redo:"Redo",blockType:"Text style",paragraph:"Paragraph",heading1:"Heading 1",heading2:"Heading 2",heading3:"Heading 3",heading4:"Heading 4",codeBlock:"Code block",bold:"Bold",italic:"Italic",underline:"Underline",strike:"Strikethrough",code:"Inline code",link:"Insert link",blockquote:"Quote",bulletList:"Bulleted list",orderedList:"Numbered list",indent:"Increase indent",outdent:"Decrease indent",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignJustify:"Justify",hr:"Horizontal line",clear:"Clear formatting",source:"Source code",fullscreen:"Fullscreen",linkUrl:"URL",linkText:"Text to display",linkTitle:"Title",linkNewTab:"Open in a new tab",linkInvalid:"Enter a valid web address, email address or relative URL.",save:"Save",cancel:"Cancel",remove:"Remove link",close:"Close",words:"words",characters:"characters",poweredBy:"Powered by",editorLabel:"Rich text editor",toolbarLabel:"Editor toolbar",sourceLabel:"HTML source",image:"Insert image",file:"Insert file",imageEdit:"Image",imageUrl:"Image URL",imageAlt:"Alternative text",imageAltHint:"Describe the image for screen readers and search engines.",imageWidth:"Width (px)",imageAlign:"Alignment",alignNone:"None",alignLeftShort:"Left",alignCenterShort:"Center",alignRightShort:"Right",imageInvalid:"Enter a valid image address (https:// or a relative URL).",insert:"Insert",fmTitle:"File manager",fmRoot:"Files",fmBreadcrumb:"Folders",fmSearch:"Search files",fmSort:"Sort",fmSortNewest:"Newest first",fmSortName:"Name",fmSortLargest:"Largest first",fmGrid:"Grid view",fmList:"List view",fmUpload:"Upload",fmDrop:"Drop files to upload",fmLoading:"Loading…",fmEmpty:"No files here yet.",fmNoResults:"No files match your search.",fmLoadMore:"Load more",fmRetry:"Try again",fmDelete:"Delete",fmDeleteConfirm:'Delete "{name}"? This cannot be undone.',fmFromUrl:"Insert from URL",fmLinkText:"Link text",fmFolder:"Folder",fmNoSelection:"Select a file to see its details.",fmNotAllowed:"{name}: this file type is not allowed here.",fmUploadFailed:"{name}: upload failed. {error}",fmListFailed:"The file list could not be loaded. {error}",fmDeleteFailed:"The file could not be deleted. {error}",fmUploading:"Uploading {name}",table:"Table",tableInsert:"Insert table",tableSize:"{rows} × {cols} table",rowAbove:"Insert row above",rowBelow:"Insert row below",colLeft:"Insert column left",colRight:"Insert column right",deleteRow:"Delete row",deleteCol:"Delete column",headerRow:"Toggle header row",headerCol:"Toggle header column",mergeCells:"Merge cells",splitCell:"Split cell",deleteTable:"Delete table",caption:"Show caption",captionPlaceholder:"Write a caption…",resizeImage:"Drag to resize",pasteText:"Paste as plain text",textColor:"Text color",highlight:"Highlight",removeColor:"Default color",removeHighlight:"No highlight",colorRed:"Red",colorOrange:"Orange",colorAmber:"Amber",colorYellow:"Yellow",colorGreen:"Green",colorTeal:"Teal",colorBlue:"Blue",colorPurple:"Purple",colorPink:"Pink",colorSlate:"Slate",colorGray:"Gray"},nr={en:tr,tr:{undo:"Geri al",redo:"Yinele",blockType:"Metin stili",paragraph:"Paragraf",heading1:"Başlık 1",heading2:"Başlık 2",heading3:"Başlık 3",heading4:"Başlık 4",codeBlock:"Kod bloğu",bold:"Kalın",italic:"İtalik",underline:"Altı çizili",strike:"Üstü çizili",code:"Satır içi kod",link:"Bağlantı ekle",blockquote:"Alıntı",bulletList:"Madde işaretli liste",orderedList:"Numaralı liste",indent:"Girintiyi artır",outdent:"Girintiyi azalt",alignLeft:"Sola hizala",alignCenter:"Ortala",alignRight:"Sağa hizala",alignJustify:"İki yana yasla",hr:"Yatay çizgi",clear:"Biçimi temizle",source:"Kaynak kodu",fullscreen:"Tam ekran",linkUrl:"Adres (URL)",linkText:"Görünen metin",linkTitle:"Başlık",linkNewTab:"Yeni sekmede aç",linkInvalid:"Geçerli bir web adresi, e-posta adresi ya da göreli adres girin.",save:"Kaydet",cancel:"Vazgeç",remove:"Bağlantıyı kaldır",close:"Kapat",words:"kelime",characters:"karakter",poweredBy:"Destekleyen:",editorLabel:"Zengin metin editörü",toolbarLabel:"Editör araç çubuğu",sourceLabel:"HTML kaynağı",image:"Görsel ekle",file:"Dosya ekle",imageEdit:"Görsel",imageUrl:"Görsel adresi",imageAlt:"Alternatif metin",imageAltHint:"Ekran okuyucular ve arama motorları için görseli kısaca anlatın.",imageWidth:"Genişlik (px)",imageAlign:"Hizalama",alignNone:"Yok",alignLeftShort:"Sol",alignCenterShort:"Orta",alignRightShort:"Sağ",imageInvalid:"Geçerli bir görsel adresi girin (https:// ya da göreli adres).",insert:"Ekle",fmTitle:"Dosya yöneticisi",fmRoot:"Dosyalar",fmBreadcrumb:"Klasörler",fmSearch:"Dosyalarda ara",fmSort:"Sırala",fmSortNewest:"En yeni",fmSortName:"Ada göre",fmSortLargest:"En büyük",fmGrid:"Izgara görünümü",fmList:"Liste görünümü",fmUpload:"Yükle",fmDrop:"Yüklemek için dosyaları bırakın",fmLoading:"Yükleniyor…",fmEmpty:"Burada henüz dosya yok.",fmNoResults:"Aramanızla eşleşen dosya yok.",fmLoadMore:"Daha fazla yükle",fmRetry:"Tekrar dene",fmDelete:"Sil",fmDeleteConfirm:'"{name}" silinsin mi? Bu işlem geri alınamaz.',fmFromUrl:"Adresten ekle",fmLinkText:"Bağlantı metni",fmFolder:"Klasör",fmNoSelection:"Ayrıntıları görmek için bir dosya seçin.",fmNotAllowed:"{name}: bu dosya türüne burada izin verilmiyor.",fmUploadFailed:"{name}: yüklenemedi. {error}",fmListFailed:"Dosya listesi yüklenemedi. {error}",fmDeleteFailed:"Dosya silinemedi. {error}",fmUploading:"{name} yükleniyor",table:"Tablo",tableInsert:"Tablo ekle",tableSize:"{rows} × {cols} tablo",rowAbove:"Üste satır ekle",rowBelow:"Alta satır ekle",colLeft:"Sola sütun ekle",colRight:"Sağa sütun ekle",deleteRow:"Satırı sil",deleteCol:"Sütunu sil",headerRow:"Başlık satırı aç/kapat",headerCol:"Başlık sütunu aç/kapat",mergeCells:"Hücreleri birleştir",splitCell:"Hücreyi böl",deleteTable:"Tabloyu sil",caption:"Açıklama göster",captionPlaceholder:"Açıklama yazın…",resizeImage:"Boyutlandırmak için sürükleyin",pasteText:"Düz metin olarak yapıştır",textColor:"Yazı rengi",highlight:"Vurgu",removeColor:"Varsayılan renk",removeHighlight:"Vurgu yok",colorRed:"Kırmızı",colorOrange:"Turuncu",colorAmber:"Kehribar",colorYellow:"Sarı",colorGreen:"Yeşil",colorTeal:"Camgöbeği",colorBlue:"Mavi",colorPurple:"Mor",colorPink:"Pembe",colorSlate:"Arduvaz",colorGray:"Gri"}};function Fu(r,e){nr[r.toLowerCase()]={...tr,...nr[r.toLowerCase()],...e}}function Vu(r){if(r&&typeof r=="object")return{...tr,...r};const e=(r||(typeof navigator<"u"?navigator.language:"en")||"en").toLowerCase();return nr[e]??nr[e.split("-")[0]]??tr}function tt(r,e){return r.replace(/\{(\w+)\}/g,(t,n)=>e[n]??t)}let $u=0;function ra(r,e){const t=`wds-dlg-${++$u}`,n=document.createElement("dialog");n.className="wds-dialog",n.setAttribute("aria-labelledby",`${t}-title`);const i=document.createElement("form");i.method="dialog",i.noValidate=!0;const s=document.createElement("div");s.className="wds-dialog-header";const o=document.createElement("h2");o.id=`${t}-title`,o.textContent=e.title;const l=document.createElement("button");l.type="button",l.className="wds-icon-button",l.setAttribute("aria-label",e.closeLabel),l.innerHTML=z.close,s.append(o,l);const a=document.createElement("div");a.className="wds-dialog-body";const c=new Map;for(const w of e.fields){if(w.type==="select"){const D=document.createElement("select");D.id=`${t}-${w.name}`,D.name=w.name,D.className="wds-input";for(const H of w.options??[]){const B=document.createElement("option");B.value=H.value,B.textContent=H.label,D.append(B)}D.value=typeof w.value=="string"?w.value:"";const $=document.createElement("label");$.className="wds-label",$.htmlFor=D.id,$.textContent=w.label,a.append($,D),c.set(w.name,D);continue}const v=document.createElement("input");if(v.id=`${t}-${w.name}`,v.name=w.name,w.type==="checkbox"){v.type="checkbox",v.checked=!!w.value;const D=document.createElement("label");D.className="wds-check",D.htmlFor=v.id,D.append(v,document.createTextNode(w.label)),a.append(D)}else{v.type="text",w.type==="url"&&(v.inputMode="url"),w.type==="number"&&(v.inputMode="numeric"),v.className="wds-input",v.value=typeof w.value=="string"?w.value:"",v.autocomplete="off",v.spellcheck=!1,w.placeholder&&(v.placeholder=w.placeholder);const D=document.createElement("label");if(D.className="wds-label",D.htmlFor=v.id,D.textContent=w.label,a.append(D,v),w.hint){const $=document.createElement("p");$.className="wds-hint",$.id=`${v.id}-hint`,$.textContent=w.hint,v.setAttribute("aria-describedby",$.id),a.append($)}}c.set(w.name,v)}const f=document.createElement("p");f.className="wds-dialog-error",f.setAttribute("role","alert"),f.hidden=!0,a.append(f);const d=document.createElement("div");if(d.className="wds-dialog-footer",e.extraAction){const w=document.createElement("button");w.type="button",w.className="wds-button wds-button-danger",w.textContent=e.extraAction.label,w.addEventListener("click",()=>{e.extraAction.onClick(),y()}),d.append(w)}const h=document.createElement("span");h.className="wds-spacer";const u=document.createElement("button");u.type="button",u.className="wds-button",u.textContent=e.cancelLabel;const p=document.createElement("button");p.type="submit",p.className="wds-button wds-button-primary",p.textContent=e.submitLabel,d.append(h,u,p),i.append(s,a,d),n.append(i),r.append(n);const m=()=>{const w={};return c.forEach((v,D)=>w[D]=v instanceof HTMLInputElement&&v.type==="checkbox"?v.checked:v.value),w};let g=!1;function y(){g||(g=!0,n.open&&n.close(),n.remove(),e.onClose?.())}i.addEventListener("submit",w=>{w.preventDefault();const v=m(),D=e.validate?.(v)??null;if(D){f.textContent=D,f.hidden=!1,[...c.values()][0]?.focus();return}e.onSubmit(v),y()}),u.addEventListener("click",y),l.addEventListener("click",y),n.addEventListener("close",y),n.addEventListener("click",w=>{w.target===n&&y()}),n.showModal();const O=[...c.values()].find(w=>w instanceof HTMLInputElement&&w.type!=="checkbox");return O?.focus(),O?.select(),y}const nt=r=>typeof r=="string"&&r.trim()?r:void 0,Si=r=>typeof r=="number"&&Number.isFinite(r)&&r>=0?r:void 0;function ia(r){if(!r||typeof r!="object")return null;const e=r,t=Pe(nt(e.url)),n=nt(e.name);if(!t||!n)return null;const i={url:t,name:n},s=Si(e.size),o=Si(e.width),l=Si(e.height);s!==void 0&&(i.size=s),o!==void 0&&(i.width=o),l!==void 0&&(i.height=l),nt(e.type)&&(i.type=e.type.toLowerCase());const a=Pe(nt(e.thumb));return a&&(i.thumb=a),nt(e.modified)&&!Number.isNaN(Date.parse(e.modified))&&(i.modified=e.modified),i}function Hu(r,e="/"){const t=Array.isArray(r)?{files:r}:r&&typeof r=="object"?r:{},n=(Array.isArray(t.files)?t.files:[]).map(ia).filter(s=>!!s),i=(Array.isArray(t.folders)?t.folders:[]).map(s=>s&&typeof s=="object"?s:{}).filter(s=>nt(s.name)&&nt(s.path)).map(s=>({name:s.name,path:Ci(s.path)}));return{path:Ci(nt(t.path)??e),folders:i,files:n,hasMore:t.hasMore===!0,serverSearch:typeof t.q=="string"}}function Ci(r){return"/"+r.split("/").filter(t=>t&&t!=="."&&t!=="..").join("/")}const Wu=/\.(jpe?g|png|gif|webp|avif|svg|bmp|ico)$/i,qu={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",avif:"image/avif",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",txt:"text/plain",csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",mp4:"video/mp4",mp3:"audio/mpeg"},sa=r=>(/\.([a-z0-9]+)$/i.exec(r)?.[1]??"").toLowerCase();function oa(r){return r.type||qu[sa(r.name)]||""}function mn(r){const e=oa(r);return e?e.startsWith("image/"):Wu.test(r.url??r.name)}function la(r,e){if(!e||!e.trim())return!0;const t=oa(r),n="."+sa(r.name);return e.split(",").some(i=>{const s=i.trim().toLowerCase();return s?s.startsWith(".")?n===s:s.endsWith("/*")?t.startsWith(s.slice(0,-1)):t===s:!1})}function aa(r){if(r===void 0)return"";if(r<1024)return`${r} B`;const e=["KB","MB","GB"];let t=r/1024,n=0;for(;t>=1024&&n<e.length-1;)t/=1024,n++;return`${t<10?t.toFixed(1):Math.round(t)} ${e[n]}`}class ve extends Error{}async function ca(r){try{const e=await r.clone().json();if(e&&typeof e.error=="string")return e.error}catch{}return`HTTP ${r.status}`}function Ju(r,e){const t=new URL(r,document.baseURI);for(const[n,i]of Object.entries(e))i&&t.searchParams.set(n,i);return t.href}class Uu{constructor(e){this.options=e}get canUpload(){return!!this.options.uploadUrl}get canDelete(){return!!this.options.deleteUrl}init(e={}){return{...e,credentials:this.options.withCredentials?"include":"same-origin",headers:{Accept:"application/json",...this.options.headers,...e.headers}}}async list(e,t,n,i){const s=Ju(this.options.listUrl,{path:e,q:t,page:n>1?String(n):""});let o;try{o=await fetch(s,{...this.init(),signal:i})}catch(a){throw a.name==="AbortError"?a:new ve(a.message||"Network error")}if(!o.ok)throw new ve(await ca(o));let l;try{l=await o.json()}catch{throw new ve("Invalid JSON")}return Hu(l,e)}upload(e,t,n){const{uploadUrl:i,headers:s={},withCredentials:o}=this.options;return i?new Promise((l,a)=>{const c=new XMLHttpRequest;c.open("POST",new URL(i,document.baseURI).href),c.withCredentials=!!o,c.setRequestHeader("Accept","application/json");for(const[d,h]of Object.entries(s))c.setRequestHeader(d,h);c.upload.onprogress=d=>d.lengthComputable&&n?.(d.loaded/d.total),c.onerror=()=>a(new ve("Network error")),c.onload=()=>{let d=null;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){a(new ve(typeof d?.error=="string"?d.error:`HTTP ${c.status}`));return}const h=ia(d?.file);h?l(h):a(new ve("Invalid upload response"))};const f=new FormData;f.append("file",e,e.name),f.append("path",t),c.send(f)}):Promise.reject(new ve("Upload is not configured"))}async remove(e){const{deleteUrl:t}=this.options;if(!t)throw new ve("Delete is not configured");let n;try{n=await fetch(new URL(t,document.baseURI).href,this.init({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})}))}catch(i){throw new ve(i.message||"Network error")}if(!n.ok)throw new ve(await ca(n))}}const A=(r,e,t)=>{const n=document.createElement(r);return e&&(n.className=e),t!==void 0&&(n.textContent=t),n},Mi=(r,e,t="wds-icon-button")=>{const n=A("button",t);return n.type="button",n.innerHTML=r,n.setAttribute("aria-label",e),n.title=e,n},Ku=[["","alignNone"],["left","alignLeftShort"],["center","alignCenterShort"],["right","alignRightShort"]];class _u{constructor(e,t,n){this.host=e,this.api=t,this.t=n,this.path="/",this.view="grid",this.sort="newest"}open(e){const t=this.t,n=e.accept??"";let i=[],s=[],o=1,l=!1,a=!1,c="",f=null,d=null,h=0,u=!1;const p=A("dialog","wds-dialog wds-fm");p.setAttribute("aria-labelledby","wds-fm-title");const m=A("div","wds-dialog-header"),g=A("h2",void 0,t.fmTitle);g.id="wds-fm-title";const y=Mi(z.close,t.close);m.append(g,y);const O=A("div","wds-fm-bar"),w=A("nav","wds-fm-crumbs");w.setAttribute("aria-label",t.fmBreadcrumb);const v=A("input","wds-input wds-fm-search");v.type="search",v.placeholder=t.fmSearch,v.setAttribute("aria-label",t.fmSearch);const D=A("select","wds-input wds-fm-sort");D.setAttribute("aria-label",t.fmSort),D.title=t.fmSort;for(const[k,C]of[["newest","fmSortNewest"],["name","fmSortName"],["largest","fmSortLargest"]]){const R=A("option",void 0,t[C]);R.value=k,D.append(R)}D.value=this.sort;const $=Mi(this.view==="grid"?z.list:z.grid,this.view==="grid"?t.fmList:t.fmGrid),H=A("input");H.type="file",H.multiple=!0,H.hidden=!0,n&&(H.accept=n);const B=A("button","wds-button wds-button-primary wds-fm-upload");B.type="button",B.innerHTML=`${z.upload}<span>${Ai(t.fmUpload)}</span>`;const U=A("div","wds-fm-tools");U.append(v,D,$),this.api.canUpload&&U.append(B,H),O.append(w,U);const ue=A("div","wds-fm-main"),$e=A("div","wds-fm-browser"),Ei=A("div","wds-fm-uploads"),De=A("ul",`wds-fm-items is-${this.view}`);De.setAttribute("aria-label",t.fmTitle);const G=A("p","wds-fm-status");G.setAttribute("role","status");const Vt=A("button","wds-button",t.fmRetry);Vt.type="button",Vt.hidden=!0;const $t=A("button","wds-button wds-fm-more",t.fmLoadMore);$t.type="button",$t.hidden=!0;const da=A("div","wds-fm-drop",t.fmDrop);da.setAttribute("aria-hidden","true"),$e.append(Ei,De,G,Vt,$t,da);const Re=A("aside","wds-fm-details");Re.setAttribute("aria-label",t.imageEdit),ue.append($e,Re);const Oi=A("div","wds-dialog-footer");if(e.onFromUrl){const k=A("button","wds-button wds-fm-fromurl");k.type="button",k.innerHTML=`${z.globe}<span>${Ai(t.fmFromUrl)}</span>`,k.addEventListener("click",()=>{yt(),e.onFromUrl()}),Oi.append(k)}const Ti=A("button","wds-button",t.cancel);Ti.type="button";const gn=A("button","wds-button wds-button-primary",t.insert);gn.type="button",gn.disabled=!0,Oi.append(A("span","wds-spacer"),Ti,gn),p.append(m,O,ue,Oi),this.host.append(p);let yn=null,Ie=null,bn=null,mt=null,wn=null;const rr=(k,C,R,N)=>{C.id=R;const F=A("label","wds-label",k);if(F.htmlFor=R,Re.append(F,C),N){const T=A("p","wds-hint",N);T.id=`${R}-hint`,C.setAttribute("aria-describedby",T.id),Re.append(T)}},ir=()=>{if(Re.replaceChildren(),yn=Ie=wn=mt=null,bn=null,gn.disabled=!f,!f){Re.append(A("p","wds-fm-placeholder",t.fmNoSelection));return}const k=f,C=A("div","wds-fm-preview"),R=A("p","wds-fm-filename",k.name),N=A("p","wds-fm-facts"),F=()=>[k.width&&k.height?`${k.width} × ${k.height}`:"",aa(k.size),k.modified?new Date(k.modified).toLocaleDateString():""].filter(Boolean).join(" · ");if(N.textContent=F(),mn(k)){const T=A("img");T.alt="",!k.thumb&&!(k.width&&k.height)&&T.addEventListener("load",()=>{!T.naturalWidth||f!==k||(k.width=T.naturalWidth,k.height=T.naturalHeight,N.textContent=F(),Ie&&!Ie.placeholder&&(Ie.placeholder=String(k.width)))},{once:!0}),T.src=k.thumb??k.url,C.append(T)}else C.innerHTML=z.file;if(Re.append(C,R,N),e.mode==="image"&&mn(k)){yn=A("input","wds-input"),yn.value=k.name.replace(/\.[a-z0-9]+$/i,"").replace(/[-_]+/g," "),rr(t.imageAlt,yn,"wds-fm-alt",t.imageAltHint),Ie=A("input","wds-input"),Ie.inputMode="numeric",Ie.placeholder=k.width?String(k.width):"",rr(t.imageWidth,Ie,"wds-fm-width"),bn=A("select","wds-input");for(const[ke,xe]of Ku){const Ht=A("option",void 0,t[xe]);Ht.value=ke,bn.append(Ht)}rr(t.imageAlign,bn,"wds-fm-align"),mt=A("input"),mt.type="checkbox",mt.id="wds-fm-caption";const T=A("label","wds-check");T.htmlFor=mt.id,T.append(mt,document.createTextNode(t.caption)),Re.append(T)}else wn=A("input","wds-input"),wn.value=k.name,rr(t.fmLinkText,wn,"wds-fm-text");if(this.api.canDelete){const T=A("button","wds-button wds-button-danger wds-fm-delete");T.type="button",T.innerHTML=`${z.trash}<span>${Ai(t.fmDelete)}</span>`,T.addEventListener("click",()=>Zu(k)),Re.append(T)}},Xu=()=>{const k=c.trim().toLocaleLowerCase(),C=i.filter(N=>la(N,n)&&(a||!k||N.name.toLocaleLowerCase().includes(k))),R=N=>N.modified?Date.parse(N.modified):-1/0;return this.sort==="name"?C.sort((N,F)=>N.name.localeCompare(F.name,void 0,{numeric:!0,sensitivity:"base"})):this.sort==="largest"?C.sort((N,F)=>(F.size??-1)-(N.size??-1)):C.sort((N,F)=>R(F)-R(N)),C},vi=()=>{w.replaceChildren();const k=this.path.split("/").filter(Boolean),C=[[t.fmRoot,"/"],...k.map((R,N)=>[R,"/"+k.slice(0,N+1).join("/")])];C.forEach(([R,N],F)=>{if(F&&w.append(A("span","wds-fm-sep","/")),F===C.length-1){const T=A("span","wds-fm-crumb is-current",R);T.setAttribute("aria-current","location"),w.append(T)}else{const T=A("button","wds-fm-crumb",R);T.type="button",T.addEventListener("click",()=>pa(N)),w.append(T)}})},gt=()=>{De.className=`wds-fm-items is-${this.view}`,De.replaceChildren();const k=!c.trim();if(k)for(const N of s){const F=ua(z.folder,N.name,t.fmFolder,!0);F.addEventListener("click",()=>pa(N.path)),De.append(ha(F))}const C=Xu();for(const N of C){const F=mn(N)?N.thumb??N.url:null,T=ua(F?"":z.file,N.name,[aa(N.size),N.width&&N.height?`${N.width}×${N.height}`:""].filter(Boolean).join(" · "),!1);if(F){const xe=A("img");xe.loading="lazy",xe.decoding="async",xe.alt="",xe.src=F,T.querySelector(".wds-fm-thumb").append(xe)}T.dataset.url=N.url;const ke=f?.url===N.url;T.classList.toggle("is-selected",ke),T.setAttribute("aria-pressed",String(ke)),T.addEventListener("click",()=>Di(N)),T.addEventListener("dblclick",()=>{Di(N),Ri()}),De.append(ha(T))}const R=!C.length&&!(k&&s.length);!G.dataset.busy&&!G.dataset.error&&(G.textContent=R?c.trim()?t.fmNoResults:t.fmEmpty:""),$t.hidden=!l||!!G.dataset.busy},ha=k=>{const C=A("li");return C.append(k),C},ua=(k,C,R,N)=>{const F=A("button",`wds-fm-item${N?" is-folder":""}`);F.type="button";const T=A("span","wds-fm-thumb");T.innerHTML=k;const ke=A("span","wds-fm-name",C);ke.title=C;const xe=A("span","wds-fm-meta",R);return F.append(T,ke,xe),F},Di=k=>{f=k,De.querySelectorAll(".wds-fm-item[data-url]").forEach(C=>{const R=C.dataset.url===k.url;C.classList.toggle("is-selected",R),C.setAttribute("aria-pressed",String(R))}),ir()},kn=async k=>{d?.abort(),d=new AbortController,k&&(o=1,i=[],s=[]),G.dataset.busy="1",delete G.dataset.error,G.textContent=t.fmLoading,Vt.hidden=!0,$t.hidden=!0,k&>();try{const C=await this.api.list(this.path,c.trim(),o,d.signal);if(u)return;this.path=C.path,a=C.serverSearch,l=C.hasMore,s=k?C.folders:s;const R=new Set(i.map(N=>N.url));i=[...i,...C.files.filter(N=>!R.has(N.url))],delete G.dataset.busy,G.textContent="",vi(),gt()}catch(C){if(C.name==="AbortError"||u)return;delete G.dataset.busy,G.dataset.error="1",G.textContent=tt(t.fmListFailed,{error:C.message}),G.setAttribute("role","alert"),Vt.hidden=!1}},pa=k=>{this.path=Ci(k),c="",v.value="",f=null,ir(),vi(),kn(!0).then(()=>De.querySelector(".wds-fm-item")?.focus())},ma=k=>{for(const C of Array.from(k)){const R=A("div","wds-fm-upload-row"),N=A("span","wds-fm-upload-name",tt(t.fmUploading,{name:C.name}));if(!la(C,n)){ga(R,tt(t.fmNotAllowed,{name:C.name})),Ei.append(R);continue}const F=A("progress");F.max=1,F.value=0,R.append(N,F),Ei.append(R),this.api.upload(C,this.path,T=>F.value=T).then(T=>{u||(R.remove(),i=[T,...i.filter(ke=>ke.url!==T.url)],gt(),Di(T),e.onUpload?.(T))}).catch(T=>{u||(R.replaceChildren(),ga(R,tt(t.fmUploadFailed,{name:C.name,error:T.message})))})}},ga=(k,C)=>{k.classList.add("is-error");const R=A("span","wds-fm-upload-name",C);R.setAttribute("role","alert");const N=Mi(z.close,t.close);N.addEventListener("click",()=>k.remove()),k.append(R,N)},Zu=async k=>{if(window.confirm(tt(t.fmDeleteConfirm,{name:k.name})))try{await this.api.remove(k.url),i=i.filter(C=>C.url!==k.url),f=null,ir(),gt()}catch(C){G.dataset.error="1",G.setAttribute("role","alert"),G.textContent=tt(t.fmDeleteFailed,{error:C.message})}},Ri=()=>{if(!f)return;const k=Ie?parseInt(Ie.value,10):NaN;e.onPick({file:f,alt:yn?.value.trim()??"",width:Number.isFinite(k)&&k>0?k:null,align:bn?.value||null,text:wn?.value.trim()||f.name,caption:!!mt?.checked}),yt()};function yt(){u||(u=!0,d?.abort(),window.clearTimeout(h),p.open&&p.close(),p.remove(),e.onClose?.())}if(y.addEventListener("click",yt),Ti.addEventListener("click",yt),gn.addEventListener("click",Ri),p.addEventListener("close",yt),p.addEventListener("click",k=>k.target===p&&yt()),Vt.addEventListener("click",()=>{G.setAttribute("role","status"),kn(!0)}),$t.addEventListener("click",()=>{o++,kn(!1)}),D.addEventListener("change",()=>{this.sort=D.value,gt()}),$.addEventListener("click",()=>{this.view=this.view==="grid"?"list":"grid",$.innerHTML=this.view==="grid"?z.list:z.grid;const k=this.view==="grid"?t.fmList:t.fmGrid;$.setAttribute("aria-label",k),$.title=k,gt()}),v.addEventListener("input",()=>{window.clearTimeout(h),h=window.setTimeout(()=>{c=v.value,!a&&!l?gt():kn(!0)},250)}),B.addEventListener("click",()=>H.click()),H.addEventListener("change",()=>{H.files?.length&&ma(H.files),H.value=""}),this.api.canUpload){let k=0;$e.addEventListener("dragenter",C=>{C.dataTransfer?.types.includes("Files")&&(k++,$e.classList.add("is-dragging"))}),$e.addEventListener("dragleave",()=>{k=Math.max(0,k-1),k||$e.classList.remove("is-dragging")}),$e.addEventListener("dragover",C=>{C.dataTransfer?.types.includes("Files")&&C.preventDefault()}),$e.addEventListener("drop",C=>{C.preventDefault(),k=0,$e.classList.remove("is-dragging"),C.dataTransfer?.files.length&&ma(C.dataTransfer.files)})}return De.addEventListener("keydown",k=>{if(!["ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"].includes(k.key))return;const R=[...De.querySelectorAll(".wds-fm-item")],N=R.indexOf(document.activeElement);if(N<0)return;k.preventDefault();const F=R[0].offsetTop,T=this.view==="list"?1:Math.max(1,R.findIndex(Ht=>Ht.offsetTop!==F)===-1?R.length:R.findIndex(Ht=>Ht.offsetTop!==F)),ke={ArrowRight:1,ArrowLeft:-1,ArrowDown:T,ArrowUp:-T},xe=k.key==="Home"?0:k.key==="End"?R.length-1:Math.min(R.length-1,Math.max(0,N+ke[k.key]));R[xe].focus()}),Re.addEventListener("keydown",k=>{k.key==="Enter"&&k.target.tagName==="INPUT"&&(k.preventDefault(),Ri())}),vi(),ir(),p.showModal(),v.focus(),kn(!0),yt}}function Ai(r){const e=document.createElement("span");return e.textContent=r,e.innerHTML}const Pt=new WeakMap,fa=r=>r===void 0?void 0:typeof r=="number"?`${r}px`:r;function ju(r){return r===!1?[]:r===void 0||r==="default"?wu:Array.isArray(r)?r:r.split(/\s+/).filter(Boolean)}const Ft=class Ft{constructor(e,t={}){if(this.listeners=new Map,this.notice=null,this.noticeTimer=0,this.onFormSubmit=()=>this.syncTarget(),this.onKeydown=a=>{a.key==="Escape"&&this.fullscreen&&this.toggleFullscreen()},this.sourceMode=!1,this.plainPaste=!1,this.fullscreen=!1,this.destroyed=!1,Pt.has(e))throw new Error("[WDS Editor] This element already has an editor. Use WDSEditor.get() or destroy() first.");this.target=e,this.options=t,this.t=Vu(t.language),this.readOnly=!!t.readOnly,this.textarea=e instanceof HTMLTextAreaElement?e:null,this.originalContent=this.textarea?this.textarea.value:e.innerHTML;const n=t.content??this.originalContent;this.root=document.createElement("div"),this.root.className="wds-editor",this.root.dataset.theme=t.theme??"light",this.fileManager=t.fileManager?.listUrl?new _u(this.root,new Uu(t.fileManager),this.t):null,this.contentWrap=document.createElement("div"),this.contentWrap.className="wds-content-wrap";const i=fa(t.height);i?(this.contentWrap.style.height=i,this.root.classList.add("wds-fixed-height")):this.contentWrap.style.minHeight=fa(t.minHeight??240),this.sourceArea=document.createElement("textarea"),this.sourceArea.className="wds-source",this.sourceArea.spellcheck=!1,this.sourceArea.hidden=!0,this.sourceArea.setAttribute("aria-label",this.t.sourceLabel);const s=Ct.create({schema:S,doc:Gn(n),plugins:[mh(),Yr({Tab:cu,"Shift-Tab":fu}),hu(),uu({link:()=>(this.openLinkDialog(),!0)}),pu(),nd(),mu(t.placeholder??""),gu(),Nu(),Du({class:"wds-dropcursor",color:!1})]}),o={onEdit:()=>this.openImageUrlDialog(),resizeLabel:this.t.resizeImage,captionPlaceholder:this.t.captionPlaceholder};this.view=new Zo(this.contentWrap,{state:s,editable:()=>!this.readOnly,attributes:{class:"wds-content",role:"textbox","aria-multiline":"true","aria-label":this.t.editorLabel},dispatchTransaction:a=>this.dispatch(a),transformPastedHTML:yh,handlePaste:(a,c)=>{const f=c.clipboardData;if(this.plainPaste&&f){const h=f.getData("text/plain");if(h)return a.dispatch(a.state.tr.replaceSelection(Gu(h)).scrollIntoView()),!0}if(!f?.files.length||!this.canUploadInline()||f.getData("text/plain"))return!1;const d=[...f.files].filter(h=>h.type.startsWith("image/"));return d.length?(this.uploadFiles(d),!0):!1},handleDrop:(a,c,f,d)=>{const h=c.dataTransfer?.files;if(d||!h?.length||!this.canUploadInline())return!1;const u=a.posAtCoords({left:c.clientX,top:c.clientY})?.pos;return c.preventDefault(),this.uploadFiles([...h],u),!0},nodeViews:{image:(a,c,f)=>new Iu(a,c,f,o),figure:(a,c,f)=>new Lu(a,c,f,o)},handleDOMEvents:{focus:()=>(this.root.classList.add("is-focused"),this.emit("focus"),!1),blur:()=>(this.root.classList.remove("is-focused"),this.emit("blur"),!1)}}),this.contentWrap.append(this.sourceArea),this.toolbar=Cu(this,ju(t.toolbar),this.t),this.toolbar.element.childElementCount&&this.toolbar.element.firstElementChild.childElementCount&&this.root.append(this.toolbar.element),this.root.append(this.contentWrap);const l=document.createElement("div");if(l.className="wds-statusbar",this.counter=t.wordCount===!1?null:document.createElement("span"),this.counter&&(this.counter.className="wds-counter",this.counter.setAttribute("aria-live","off"),l.append(this.counter)),t.branding!==!1){const a=document.createElement("a");a.className="wds-branding",a.href="https://webdevsnippets.com/wds-editor",a.target="_blank",a.rel="noopener",a.innerHTML=`${Yu(this.t.poweredBy)} <strong>WDS Editor</strong>`,l.append(a)}l.childElementCount&&this.root.append(l),this.textarea?(this.textarea.style.display="none",this.textarea.after(this.root),this.textarea.form?.addEventListener("submit",this.onFormSubmit)):e.replaceChildren(this.root),document.addEventListener("keydown",this.onKeydown),Pt.set(e,this),this.lastHtml=this.getHTML(),this.syncTarget(),this.refresh(),this.emit("init")}static init(e){const t=typeof e.selector=="string"?document.querySelector(e.selector):e.selector;if(!t)throw new Error(`[WDS Editor] No element matches "${String(e.selector)}".`);return Pt.get(t)??new Ft(t,e)}static initAll(e){return[...document.querySelectorAll(e.selector)].map(t=>Pt.get(t)??new Ft(t,e))}static get(e){const t=typeof e=="string"?document.querySelector(e):e;return t?Pt.get(t):void 0}getHTML(){return this.sourceMode&&this.applySource(),Yn(this.view.state.doc)}setHTML(e){this.sourceMode&&(this.sourceArea.value=Pl(e));const t=Gn(e),n=this.view.state.tr.replaceWith(0,this.view.state.doc.content.size,t.content);this.dispatch(n.setSelection(L.atStart(n.doc)))}insertHTML(e){const t=Gn(e),n=x.maxOpen(t.content);this.dispatch(this.view.state.tr.replaceSelection(n).scrollIntoView())}getText(){const e=this.view.state.doc;return e.textBetween(0,e.content.size,`
|
|
12
|
+
|
|
13
|
+
`,`
|
|
14
|
+
`)}isEmpty(){return zl(this.view.state.doc)}focus(){this.sourceMode?this.sourceArea.focus():this.view.focus()}setReadOnly(e){this.readOnly=e,this.root.classList.toggle("is-readonly",e),this.sourceArea.readOnly=e,this.view.setProps({}),this.refresh()}isReadOnly(){return this.readOnly}exec(e){if(this.readOnly||this.sourceMode)return!1;const t=e(this.view.state,n=>this.dispatch(n),this.view);return this.view.focus(),t}undo(){this.exec(Kr)}redo(){this.exec(qn)}isSourceMode(){return this.sourceMode}toggleSource(){this.sourceMode?(this.applySource(),this.sourceMode=!1,this.sourceArea.hidden=!0,this.view.dom.hidden=!1,this.root.classList.remove("is-source"),this.view.focus()):(this.sourceArea.value=Pl(Yn(this.view.state.doc)),this.sourceMode=!0,this.view.dom.hidden=!0,this.sourceArea.hidden=!1,this.root.classList.add("is-source"),this.sourceArea.focus()),this.refresh()}isFullscreen(){return this.fullscreen}toggleFullscreen(){this.fullscreen=!this.fullscreen,this.root.classList.toggle("is-fullscreen",this.fullscreen),document.documentElement.classList.toggle("wds-noscroll",this.fullscreen),this.refresh(),this.focus()}openLinkDialog(){if(this.readOnly||this.sourceMode)return;const e=this.view.state,t=yi(e),{from:n,to:i,empty:s}=e.selection,o=s?"":e.doc.textBetween(n,i," "),l=s&&!t,a=this.t;ra(this.root,{title:a.link,closeLabel:a.close,submitLabel:a.save,cancelLabel:a.cancel,fields:[{name:"href",label:a.linkUrl,type:"url",value:t?.href??"",placeholder:"https://"},...l?[{name:"text",label:a.linkText,type:"text",value:o}]:[],{name:"title",label:a.linkTitle,type:"text",value:t?.title??""},{name:"newTab",label:a.linkNewTab,type:"checkbox",value:t?.target==="_blank"}],extraAction:t?{label:a.remove,onClick:()=>this.removeLink()}:void 0,validate:c=>Nl(String(c.href))?null:a.linkInvalid,onSubmit:c=>{const f=Nl(String(c.href)),d={href:f,title:String(c.title).trim()||null,target:c.newTab?"_blank":null},h=S.marks.link.create(d),u=this.view.state;let p=u.tr;if(t)p=p.removeMark(t.from,t.to,S.marks.link).addMark(t.from,t.to,h);else if(l){const m=String(c.text??"").trim()||f.replace(/^mailto:/,"");p=p.replaceSelectionWith(S.text(m,[h]),!1)}else p=p.addMark(u.selection.from,u.selection.to,h);this.dispatch(p.scrollIntoView())},onClose:()=>this.view.focus()})}removeLink(){const e=yi(this.view.state);e&&this.dispatch(this.view.state.tr.removeMark(e.from,e.to,S.marks.link))}hasFileManager(){return!!this.fileManager}insertImage(e){const t=Pe(e.src);if(!t||this.readOnly||this.sourceMode)return!1;const n=S.nodes.image.create({src:t,alt:e.alt??"",title:e.title??null,width:e.width??null,height:e.width?e.height??null:null,align:e.align??null}),i=this.view.state.tr.replaceSelectionWith(n);return e.caption&&Zl(i,i.selection.from-1,n.attrs),this.dispatch(i.scrollIntoView()),!0}openImageDialog(){if(this.readOnly||this.sourceMode)return;bi(this.view.state)||!this.fileManager?this.openImageUrlDialog():this.openFileManager("image")}openFileManager(e="image"){!this.fileManager||this.readOnly||this.sourceMode||this.fileManager.open({mode:e,accept:e==="image"?this.options.fileManager?.accept??"image/*":"",onFromUrl:e==="image"?()=>this.openImageUrlDialog():void 0,onUpload:t=>this.emit("upload",t),onPick:({file:t,alt:n,width:i,align:s,text:o,caption:l})=>{e==="image"&&mn(t)?this.insertImage({src:t.url,alt:n,width:i,align:s,caption:l}):this.insertFileLink(t,o),this.emit("fileSelect",t)},onClose:()=>this.view.focus()})}openImageUrlDialog(){const e=this.t,t=bi(this.view.state),n=t?.attrs??{};ra(this.root,{title:t?e.imageEdit:e.image,closeLabel:e.close,submitLabel:t?e.save:e.insert,cancelLabel:e.cancel,fields:[{name:"src",label:e.imageUrl,type:"url",value:n.src??"",placeholder:"https://"},{name:"alt",label:e.imageAlt,type:"text",value:n.alt??"",hint:e.imageAltHint},{name:"width",label:e.imageWidth,type:"number",value:n.width?String(n.width):""},{name:"align",label:e.imageAlign,type:"select",value:n.align??"",options:[{value:"",label:e.alignNone},{value:"left",label:e.alignLeftShort},{value:"center",label:e.alignCenterShort},{value:"right",label:e.alignRightShort}]},{name:"caption",label:e.caption,type:"checkbox",value:!!t?.figure}],validate:i=>Pe(String(i.src))&&!/^(mailto|tel):/i.test(String(i.src).trim())?null:e.imageInvalid,onSubmit:i=>{const s=parseInt(String(i.width),10),o={src:Pe(String(i.src)),alt:String(i.alt).trim(),width:s>0?s:null,align:String(i.align)||null},l=!!i.caption;if(t){const a=o.width&&o.width===n.width?n.height??null:null,c={...n,...o,height:a},f=this.view.state.tr;l&&!t.figure?Zl(f,t.pos,c):!l&&t.figure?ou(f,t.pos,t.node,c):f.setNodeMarkup(t.pos,void 0,c).setSelection(M.create(f.doc,t.pos)),this.dispatch(f.scrollIntoView())}else this.insertImage({...o,caption:l})},onClose:()=>this.view.focus()})}openTableMenu(e){if(this.readOnly||this.sourceMode)return;const t=this.t,n=this.view.state;if(!he(n)){Bu(e,this.root,t.tableInsert,(o,l)=>tt(t.tableSize,{rows:String(o),cols:String(l)}),(o,l)=>this.exec(au(o,l)));return}const i=(o,l,a=!1)=>({label:o,danger:a,enabled:l(n),run:()=>this.exec(l)}),s=[i(t.rowAbove,Gd),i(t.rowBelow,yl),i(t.colLeft,Jd),i(t.colRight,Ud),"|",i(t.deleteRow,Xd),i(t.deleteCol,_d),"|",i(t.headerRow,rh),i(t.headerCol,ih),i(t.mergeCells,Qd),i(t.splitCell,eh),"|",i(t.deleteTable,oh,!0)];zu(e,this.root,s,t.table)}openColorPicker(e,t){if(this.readOnly||this.sourceMode)return;const n=this.t,s=((e==="textColor"?this.options.colors?.text:this.options.colors?.highlight)??(e==="textColor"?bh:wh)).map(o=>typeof o=="string"?{color:o,name:o}:o).map(o=>({color:zt(o.color),label:n[o.name]??o.name})).filter(o=>!!o.color);Pu(t,this.root,{label:e==="textColor"?n.textColor:n.highlight,removeLabel:e==="textColor"?n.removeColor:n.removeHighlight,swatches:s,columns:e==="textColor"?5:6,current:wi(this.view.state,e),onPick:o=>this.exec(du(e,o))})}togglePlainPaste(e=!this.plainPaste){this.plainPaste=e,this.refresh(),this.view.focus()}isPlainPaste(){return this.plainPaste}insertFileLink(e,t){const n=Pe(e.url);if(!n||this.readOnly||this.sourceMode)return;const i=S.marks.link.create({href:n}),s=this.view.state,o=s.selection.empty?s.tr.replaceSelectionWith(S.text(t||e.name,[i]),!1):s.tr.addMark(s.selection.from,s.selection.to,i);this.dispatch(o.scrollIntoView())}canUploadInline(){return!!this.fileManager?.api.canUpload&&!this.readOnly&&!this.sourceMode}uploadFiles(e,t){if(!this.canUploadInline())return;const n=this.fileManager.api;for(const i of e){const s={};let o=this.view.state.tr;t===void 0&&!o.selection.empty&&(o=o.deleteSelection());const l=t??o.selection.from;this.dispatch(o.setMeta(pt,{add:{id:s,pos:l}})),n.upload(i,this.fileManager.path).then(a=>{if(this.destroyed)return;const c=yu(this.view.state,s);if(c===null)return;const f=mn(a)?S.nodes.image.create({src:a.url,alt:""}):S.text(a.name,[S.marks.link.create({href:a.url})]);this.dispatch(this.view.state.tr.replaceWith(c,c,f).setMeta(pt,{remove:{id:s}})),this.emit("upload",a)}).catch(a=>{this.destroyed||(this.dispatch(this.view.state.tr.setMeta(pt,{remove:{id:s}})),this.showNotice(tt(this.t.fmUploadFailed,{name:i.name,error:a.message})))})}}showNotice(e){this.notice||(this.notice=document.createElement("div"),this.notice.className="wds-notice",this.notice.setAttribute("role","alert"),this.root.append(this.notice)),this.notice.textContent=e,this.notice.hidden=!1,window.clearTimeout(this.noticeTimer),this.noticeTimer=window.setTimeout(()=>this.notice&&(this.notice.hidden=!0),6e3)}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this}off(e,t){return this.listeners.get(e)?.delete(t),this}destroy(){if(this.destroyed)return;this.emit("destroy");const e=this.getHTML();this.destroyed=!0,window.clearTimeout(this.noticeTimer),na(),this.view.destroy(),document.removeEventListener("keydown",this.onKeydown),this.fullscreen&&document.documentElement.classList.remove("wds-noscroll"),this.textarea?(this.textarea.form?.removeEventListener("submit",this.onFormSubmit),this.textarea.value=e,this.textarea.style.display="",this.root.remove()):this.target.innerHTML=e||this.originalContent,Pt.delete(this.target),this.listeners.clear()}dispatch(e){if(this.destroyed)return;const t=this.view.state.apply(e);if(this.view.updateState(t),e.docChanged){const n=Yn(t.doc);n!==this.lastHtml&&(this.lastHtml=n,this.syncTarget(n),this.options.onChange?.(n,this),this.emit("change"))}this.refresh()}applySource(){const e=this.sourceArea.value,t=Gn(e);if(t.eq(this.view.state.doc))return;const n=this.view.state.tr.replaceWith(0,this.view.state.doc.content.size,t.content),i=this.view.state.apply(n);this.view.updateState(i),this.lastHtml=Yn(i.doc),this.syncTarget(this.lastHtml),this.options.onChange?.(this.lastHtml,this),this.emit("change")}syncTarget(e){this.textarea&&(this.textarea.value=e??this.getHTML())}refresh(){const e=this.view.state;if(this.toolbar.update(e),this.counter){const t=this.getText(),n=(t.match(/[\p{L}\p{N}][\p{L}\p{N}'’-]*/gu)??[]).length,i=t.replace(/\n/g,"").length;this.counter.textContent=`${n} ${this.t.words} · ${i} ${this.t.characters}`}}emit(e,t){this.listeners.get(e)?.forEach(n=>{try{n(this,t)}catch(i){console.error(i)}})}};Ft.version="1.0.1",Ft.addLanguage=Fu;let Ni=Ft;function Gu(r){const e=r.replace(/\r\n?/g,`
|
|
15
|
+
`).split(/\n{2,}/).map(t=>{const i=t.split(`
|
|
16
|
+
`).flatMap((s,o)=>[...o?[S.nodes.hard_break.create()]:[],...s?[S.text(s)]:[]]);return S.nodes.paragraph.create(null,i)});return new x(b.from(e),1,1)}function Yu(r){const e=document.createElement("span");return e.textContent=r,e.innerHTML}return Ni})();
|
|
17
|
+
//# sourceMappingURL=wds-editor.min.js.map
|