1||u==0||m.content.size)&&(d=g,c.push(Cd(m.mark(f.allowedMarks(m.marks)),l==1?u:0,l==a.childCount?p:-1)))}let h=l==a.childCount;h||(p=-1),this.placed=Rr(this.placed,n,C.from(c)),this.frontier[n].match=d,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],s=n=0;a--){let{match:u,type:l}=this.frontier[a],c=ho(e,a,l,u,!0);if(!c||c.childCount)continue e}return{depth:n,fit:o,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Rr(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Rr(this.placed,this.depth,C.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(C.empty,!0);n.childCount&&(this.placed=Rr(this.placed,this.frontier.length,n))}}function Mr(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Mr(t.firstChild.content,e-1,n)))}function Rr(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Rr(t.lastChild.content,e-1,n)))}function po(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Cd(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),t.copy(r)}function ho(t,e,n,r,i){let s=t.node(e),o=i?t.indexAfter(e):t.index(e);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!S0(n,s.content,o)?a:null}function S0(t,e,n){for(let r=n;r0;f--,p--){let h=i.node(f).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;o.indexOf(f)>-1?a=f:i.before(f)==p&&o.splice(1,0,-f)}let u=o.indexOf(a),l=[],c=r.openStart;for(let f=r.content,p=0;;p++){let h=f.firstChild;if(l.push(h),p==r.openStart)break;f=h.content}for(let f=c-1;f>=0;f--){let p=l[f],h=_0(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))c=f;else if(h||!p.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let p=(f+c+1)%(r.openStart+1),h=l[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>d));f--){let p=o[f];p<0||(e=i.before(p),n=s.after(p))}}function Md(t,e,n,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(t).append(t);t=o.append(s.matchFragment(o).fillBefore(C.empty,!0))}return t}function T0(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=v0(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new B(C.from(r),0,0))}function k0(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),s=Rd(r,i);for(let o=0;o0&&(u||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&n>r.end(o)&&i.end(o)-n!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return t.delete(r.before(o),n);t.delete(e,n)}function Rd(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let s=t.start(i);if(se.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&n.push(i)}return n}class cr extends qe{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new B(C.from(i),0,n.isLeaf?0:1))}getMap(){return st.empty}invert(e){return new cr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new cr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new cr(n.pos,n.attr,n.value)}}qe.jsonID("attr",cr);class Kr extends qe{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return _e.ok(r)}getMap(){return st.empty}invert(e){return new Kr(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Kr(n.attr,n.value)}}qe.jsonID("docAttr",Kr);let pr=class extends Error{};pr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};pr.prototype=Object.create(Error.prototype);pr.prototype.constructor=pr;pr.prototype.name="TransformError";class Dd{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new lr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new pr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=B.empty){let i=Hs(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new B(C.from(r),0,0))}delete(e,n){return this.replace(e,n,B.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return N0(this,e,n,r),this}replaceRangeWith(e,n,r){return T0(this,e,n,r),this}deleteRange(e,n){return k0(this,e,n),this}lift(e,n){return d0(this,e,n),this}join(e,n=1){return x0(this,e,n),this}wrap(e,n){return h0(this,e,n),this}setBlockType(e,n=e,r,i=null){return m0(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return b0(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new cr(e,n,r)),this}setDocAttribute(e,n){return this.step(new Kr(e,n)),this}addNodeMark(e,n){return this.step(new on(e,n)),this}removeNodeMark(e,n){if(!(n instanceof he)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new fr(e,n)),this}split(e,n=1,r){return y0(this,e,n,r),this}addMark(e,n,r){return u0(this,e,n,r),this}removeMark(e,n,r){return l0(this,e,n,r),this}clearIncompatible(e,n,r){return La(this,e,n,r),this}}const mo=Object.create(null);class te{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new O0(e.min(n),e.max(n))]}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 n=0;n=0;s--){let o=n<0?er(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):er(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(o)return o}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new bt(e.node(0))}static atStart(e){return er(e,e,0,0,1)||new bt(e)}static atEnd(e){return er(e,e,e.content.size,e.childCount,-1)||new bt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=mo[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in mo)throw new RangeError("Duplicate use of selection JSON ID "+e);return mo[e]=n,n.prototype.jsonID=e,n}getBookmark(){return j.between(this.$anchor,this.$head).getBookmark()}}te.prototype.visible=!0;class O0{constructor(e,n){this.$from=e,this.$to=n}}let Vu=!1;function Ku(t){!Vu&&!t.parent.inlineContent&&(Vu=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class j extends te{constructor(e,n=e){Ku(e),Ku(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return te.near(r);let i=e.resolve(n.map(this.anchor));return new j(i.parent.inlineContent?i:r,r)}replace(e,n=B.empty){if(super.replace(e,n),n==B.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof j&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new qs(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new j(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let s=te.findFrom(n,r,!0)||te.findFrom(n,-r,!0);if(s)n=s.$head;else return te.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(te.findFrom(e,-r,!0)||te.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let a=e.child(o);if(a.isAtom){if(!s&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let u=er(t,a,n+i,i<0?a.childCount:0,i,s);if(u)return u}n+=a.nodeSize*i}return null}function Wu(t,e,n){let r=t.steps.length-1;if(r{o==null&&(o=c)}),t.setSelection(te.near(t.doc.resolve(o),n))}const Gu=1,mi=2,ju=4;class C0 extends Dd{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=mi,this}ensureMarks(e){return he.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&mi)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~mi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||he.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(n);s=r==n?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,s)),this.selection.empty||this.setSelection(te.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,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|=ju,this}get scrolledIntoView(){return(this.updated&ju)>0}}function Yu(t,e){return!e||!t?t:t.bind(e)}class Dr{constructor(e,n,r){this.name=e,this.init=Yu(n.init,r),this.apply=Yu(n.apply,r)}}const M0=[new Dr("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Dr("selection",{init(t,e){return t.selection||te.atStart(e.doc)},apply(t){return t.selection}}),new Dr("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Dr("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class go{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=M0.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Dr(r.key,r.spec.state,r))})}}class ar{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,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new go(e.schema,e.plugins),s=new ar(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=dn.fromJSON(e.schema,n.doc);else if(o.name=="selection")s.selection=te.fromJSON(s.doc,n.selection);else if(o.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let u=r[a],l=u.spec.state;if(u.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){s[o.name]=l.fromJSON.call(u,e,n[a],s);return}}s[o.name]=o.init(e,s)}}),s}}function Id(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Id(i,e,{})),n[r]=i}return n}class Ee{constructor(e){this.spec=e,this.props={},e.props&&Id(e.props,this,this.props),this.key=e.key?e.key.key:Ld("plugin")}getState(e){return e[this.key]}}const bo=Object.create(null);function Ld(t){return t in bo?t+"$"+ ++bo[t]:(bo[t]=0,t+"$")}class Le{constructor(e="key"){this.key=Ld(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const $e=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Wr=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let ea=null;const qt=function(t,e,n){let r=ea||(ea=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},R0=function(){ea=null},zn=function(t,e,n,r){return n&&(Ju(t,e,n,r,-1)||Ju(t,e,n,r,1))},D0=/^(img|br|input|textarea|hr)$/i;function Ju(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:gt(t))){let s=t.parentNode;if(!s||s.nodeType!=1||oi(t)||D0.test(t.nodeName)||t.contentEditable=="false")return!1;e=$e(t)+(i<0?0:1),t=s}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?gt(t):0}else return!1}}function gt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function I0(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=gt(t)}else if(t.parentNode&&!oi(t))e=$e(t),t=t.parentNode;else return null}}function L0(t,e){for(;;){if(t.nodeType==3&&e2),ht=hr||(Lt?/Mac/.test(Lt.platform):!1),F0=Lt?/Win/.test(Lt.platform):!1,St=/Android \d/.test(xn),ai=!!Zu&&"webkitFontSmoothing"in Zu.documentElement.style,U0=ai?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function z0(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Ut(t,e){return typeof t=="number"?t:t[e]}function H0(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function Xu(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let o=n||t.dom;o;o=Wr(o)){if(o.nodeType!=1)continue;let a=o,u=a==s.body,l=u?z0(s):H0(a),c=0,d=0;if(e.topl.bottom-Ut(r,"bottom")&&(d=e.bottom-e.top>l.bottom-l.top?e.top+Ut(i,"top")-l.top:e.bottom-l.bottom+Ut(i,"bottom")),e.leftl.right-Ut(r,"right")&&(c=e.right-l.right+Ut(i,"right")),c||d)if(u)s.defaultView.scrollBy(c,d);else{let f=a.scrollLeft,p=a.scrollTop;d&&(a.scrollTop+=d),c&&(a.scrollLeft+=c);let h=a.scrollLeft-f,m=a.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(u||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function q0(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=n+1;o=n-20){r=a,i=u.top;break}}return{refDOM:r,refTop:i,stack:$d(t.dom)}}function $d(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Wr(r));return e}function V0({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Fd(n,r==0?0:r-e)}function Fd(t,e){for(let n=0;n=a){o=Math.max(h.bottom,o),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!u&&h.left<=e.left&&h.right>=e.left&&(u=c,l={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(s=d+1)}}return!n&&u&&(n=u,i=l,r=0),n&&n.nodeType==3?W0(n,i):!n||r&&n.nodeType==1?{node:t,offset:s}:Ud(n,i)}function W0(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:t,offset:0}}function $a(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function G0(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(o.left+o.right)/2?1:-1}return t.docView.posFromDOM(r,i,s)}function Y0(t,e,n,r){let i=-1;for(let s=e,o=!1;s!=t.dom;){let a=t.docView.nearestDesc(s,!0);if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)){let u=a.dom.getBoundingClientRect();if(a.node.isBlock&&a.parent&&(!o&&u.left>r.left||u.top>r.top?i=a.posBefore:(!o&&u.right-1?i:t.docView.posFromDOM(e,n,-1)}function zd(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let l;ai&&i&&r.nodeType==1&&(l=r.childNodes[i-1]).nodeType==1&&l.contentEditable=="false"&&l.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=Y0(t,r,i,e))}a==null&&(a=j0(t,o,e));let u=t.docView.nearestDesc(o,!0);return{pos:a,inside:u?u.posAtStart-u.border:-1}}function Qu(t){return t.top=0&&i==r.nodeValue.length?(u--,c=1):n<0?u--:l++,kr(Zt(qt(r,u,l),c),c<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(n<0||i==gt(r))){let u=r.childNodes[i-1];if(u.nodeType==1)return yo(u.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(n<0||i==gt(r))){let u=r.childNodes[i-1],l=u.nodeType==3?qt(u,gt(u)-(o?0:1)):u.nodeType==1&&(u.nodeName!="BR"||!u.nextSibling)?u:null;if(l)return kr(Zt(l,1),!1)}if(s==null&&i=0)}function kr(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function yo(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function qd(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function X0(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return qd(t,e,()=>{let{node:s}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(s,!0);if(!a)break;if(a.node.isBlock){s=a.contentDOM||a.dom;break}s=a.dom.parentNode}let o=Hd(t,i.pos,1);for(let a=s.firstChild;a;a=a.nextSibling){let u;if(a.nodeType==1)u=a.getClientRects();else if(a.nodeType==3)u=qt(a,0,a.nodeValue.length).getClientRects();else continue;for(let l=0;lc.top+1&&(n=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}const Q0=/[\u0590-\u08ac]/;function em(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,a=t.domSelection();return a?!Q0.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?s:o:qd(t,e,()=>{let{focusNode:u,focusOffset:l,anchorNode:c,anchorOffset:d}=t.domSelectionRange(),f=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||u==h&&l==m;try{a.collapse(c,d),u&&(u!=c||l!=d)&&a.extend&&a.extend(u,l)}catch{}return f!=null&&(a.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}let el=null,tl=null,nl=!1;function tm(t,e,n){return el==e&&tl==n?nl:(el=e,tl=n,nl=n=="up"||n=="down"?X0(t,e,n):em(t,e,n))}const yt=0,rl=1,kn=2,Pt=3;class ui{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=yt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n$e(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!n||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||o instanceof Kd){i=e-s;break}s=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Vd&&s.side>=0;r--);if(n<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&n&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?$e(s.dom)+1:0}}else{let s,o=!0;for(;s=r=c&&n<=l-u.border&&u.node&&u.contentDOM&&this.contentDOM.contains(u.contentDOM))return u.parseRange(e,n,c);e=o;for(let d=a;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=$e(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(l>n||a==this.children.length-1)){n=l;for(let c=a+1;cp&&on){let p=a;a=u,u=p}let f=document.createRange();f.setEnd(u.node,u.offset),f.setStart(a.node,a.offset),l.removeAllRanges(),l.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let a=r+s.border,u=o-s.border;if(e>=a&&n<=u){this.dirty=e==r||n==o?kn:rl,e==a&&n==u&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Pt:s.markDirty(e-a,n-a);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?kn:Pt}r=o}this.dirty=kn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?kn:rl;n.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(o.nodeType!=1){let a=document.createElement("span");a.appendChild(o),o=a}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==yt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class nm extends ui{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Hn extends ui{constructor(e,n,r,i,s){super(e,[],r,i),this.mark=n,this.spec=s}static create(e,n,r,i){let s=i.nodeViews[n.type.name],o=s&&s(n,i,r);return(!o||!o.dom)&&(o=yn.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Hn(e,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pt&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=yt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=sa(s,0,e,r));for(let a=0;a{if(!u)return o;if(u.parent)return u.parent.posBeforeChild(u)},r,i),c=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:d}=yn.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!d&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let f=c;return c=jd(c,r,n),l?u=new rm(e,n,r,i,c,d||null,f,l,s,o+1):n.isText?new Ks(e,n,r,i,c,f,s):new hn(e,n,r,i,c,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,n,r){return this.dirty==yt&&e.eq(this.node)&&ji(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,o=s&&s.pos>-1?s:null,a=s&&s.pos<0,u=new sm(this,o&&o.node,e);um(this.node,this.innerDeco,(l,c,d)=>{l.spec.marks?u.syncToMarks(l.spec.marks,r,e):l.type.side>=0&&!d&&u.syncToMarks(c==this.node.childCount?he.none:this.node.child(c).marks,r,e),u.placeWidget(l,e,i)},(l,c,d,f)=>{u.syncToMarks(l.marks,r,e);let p;u.findNodeMatch(l,c,d,f)||a&&e.state.selection.from>i&&e.state.selection.to-1&&u.updateNodeAt(l,c,d,p,e)||u.updateNextNode(l,c,d,e,f,i)||u.addNode(l,c,d,e,i),i+=l.nodeSize}),u.syncToMarks([],r,e),this.node.isTextblock&&u.addTextblockHacks(),u.destroyRest(),(u.changed||this.dirty==kn)&&(o&&this.protectLocalComposition(e,o),Wd(this.contentDOM,this.children,e),hr&&lm(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof j)||rn+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,a=cm(this.node.content,o,r-n,i-n);return a<0?null:{node:s,pos:a,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let s=n;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 nm(this,s,n,i);e.input.compositionNodes.push(o),this.children=sa(this.children,r,r+i.length,e,o)}update(e,n,r,i){return this.dirty==Pt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=yt}updateOuterDeco(e){if(ji(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Gd(this.dom,this.nodeDOM,ia(this.outerDeco,this.node,n),ia(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function il(t,e,n,r,i){jd(r,e,t);let s=new hn(void 0,t,e,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Ks extends hn{constructor(e,n,r,i,s,o,a){super(e,n,r,i,s,null,o,a,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Pt||this.dirty!=yt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=yt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=yt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new Ks(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Pt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Kd extends ui{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==yt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class rm extends hn{constructor(e,n,r,i,s,o,a,u,l,c){super(e,n,r,i,s,o,a,l,c),this.spec=u}update(e,n,r,i){if(this.dirty==Pt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Wd(t,e,n){let r=t.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=Hn.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,n,r))s=this.top.children.indexOf(o,this.index);else for(let a=this.index,u=Math.min(this.top.children.length,a+5);a0;){let a;for(;;)if(r){let l=n.children[r-1];if(l instanceof Hn)n=l,r=l.children.length;else{a=l,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let u=a.node;if(u){if(u!=t.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}function am(t,e){return t.type.side-e.type.side}function um(t,e,n,r){let i=e.locals(t),s=0;if(i.length==0){for(let l=0;ls;)a.push(i[o++]);let h=s+f.nodeSize;if(f.isText){let g=h;o!g.inline):a.slice();r(f,m,e.forChild(s,f),p),s=h}}function lm(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function cm(t,e,n,r){for(let i=0,s=0;i=n){if(s>=r&&u.slice(r-e.length-a,r-a)==e)return r-e.length;let l=a=0&&l+e.length+a>=n)return a+l;if(n==r&&u.length>=r+e.length-a&&u.slice(r-a,r-a+e.length)==e)return r}}return-1}function sa(t,e,n,r,i){let s=[];for(let o=0,a=0;o=n||c<=e?s.push(u):(ln&&s.push(u.slice(n-l,u.size,r)))}return s}function Fa(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,o=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),u,l;if(Vs(n)){for(u=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&H.isSelectable(d)&&i.parent&&!(d.isInline&&P0(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;l=new H(o==f?a:r.resolve(f))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let d=o,f=o;for(let p=0;p{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Yd(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function fm(t){let e=t.domSelection(),n=document.createRange();if(!e)return;let r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setStart(r.parentNode,$e(r)+1):n.setStart(r,0),n.collapse(!0),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&nt&&pn<=11&&(r.disabled=!0,r.disabled=!1)}function Jd(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(ll(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else ll(t)}function ll(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Ua(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||j.between(e,n,r)}function cl(t){return t.editable&&!t.hasFocus()?!1:Zd(t)}function Zd(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function pm(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return zn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function oa(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&te.findFrom(s,e)}function Xt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function dl(t,e,n){let r=t.state.selection;if(r instanceof j)if(n.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Xt(t,new j(r.$anchor,o))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=oa(t.state,e);return i&&i instanceof H?Xt(t,i):!1}else if(!(ht&&n.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let a=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=t.docView.descAt(a))&&!o.contentDOM?H.isSelectable(s)?Xt(t,new H(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):ai?Xt(t,new j(t.state.doc.resolve(e<0?a:a+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return Xt(t,new j(e>0?r.$to:r.$from));{let i=oa(t.state,e);return i?Xt(t,i):!1}}}function Yi(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Br(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Jn(t,e){return e<0?hm(t):mm(t)}function hm(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,s,o=!1;for(Tt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Br(a,-1))i=n,s=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Xd(n))break;{let a=n.previousSibling;for(;a&&Br(a,-1);)i=n.parentNode,s=$e(a),a=a.previousSibling;if(a)n=a,r=Yi(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}o?aa(t,n,r):i&&aa(t,i,s)}function mm(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Yi(n),s,o;for(;;)if(r{t.state==i&&Wt(t)},50)}function fl(t,e){let n=t.state.doc.resolve(e);if(!(He||F0)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function pl(t,e,n){let r=t.state.selection;if(r instanceof j&&!r.empty||n.indexOf("s")>-1||ht&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let o=oa(t.state,e);if(o&&o instanceof H)return Xt(t,o)}if(!i.parent.inlineContent){let o=e<0?i:s,a=r instanceof bt?te.near(o,e):te.findFrom(o,e);return a?Xt(t,a):!1}return!1}function hl(t,e){if(!(t.state.selection instanceof j))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let o=t.state.tr;return e<0?o.delete(n.pos-s.nodeSize,n.pos):o.delete(n.pos,n.pos+s.nodeSize),t.dispatch(o),!0}return!1}function ml(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function ym(t){if(!Ge||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ml(t,r,"true"),setTimeout(()=>ml(t,r,"false"),20)}return!1}function Em(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function xm(t,e){let n=e.keyCode,r=Em(e);if(n==8||ht&&n==72&&r=="c")return hl(t,-1)||Jn(t,-1);if(n==46&&!e.shiftKey||ht&&n==68&&r=="c")return hl(t,1)||Jn(t,1);if(n==13||n==27)return!0;if(n==37||ht&&n==66&&r=="c"){let i=n==37?fl(t,t.state.selection.from)=="ltr"?-1:1:-1;return dl(t,i,r)||Jn(t,i)}else if(n==39||ht&&n==70&&r=="c"){let i=n==39?fl(t,t.state.selection.from)=="ltr"?1:-1:1;return dl(t,i,r)||Jn(t,i)}else{if(n==38||ht&&n==80&&r=="c")return pl(t,-1,r)||Jn(t,-1);if(n==40||ht&&n==78&&r=="c")return ym(t)||pl(t,1,r)||Jn(t,1);if(r==(ht?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function za(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let o=t.someProp("clipboardSerializer")||yn.fromSchema(t.state.schema),a=sf(),u=a.createElement("div");u.appendChild(o.serializeFragment(r,{document:a}));let l=u.firstChild,c,d=0;for(;l&&l.nodeType==1&&(c=rf[l.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=a.createElement(c[p]);for(;u.firstChild;)h.appendChild(u.firstChild);u.appendChild(h),d++}l=u.firstChild}l&&l.nodeType==1&&l.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(n)}`);let f=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,`
+import{b as ed,a as Rh,O as Dh,d as Ih,g as td,e as Cr,c as ce,u as Lh}from"./hoisted.DnwpQtlg.js";/* empty css */function Be(t){this.content=t}Be.prototype={constructor:Be,find:function(t){for(var e=0;e>1}};Be.from=function(t){if(t instanceof Be)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Be(e)};function nd(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),s=e.child(r);if(i==s){n+=i.nodeSize;continue}if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)n++;return n}if(i.content.size||s.content.size){let o=nd(i.content,s.content,n+1);if(o!=null)return o}n+=i.nodeSize}}function rd(t,e,n,r){for(let i=t.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:n,b:r};let o=t.child(--i),a=e.child(--s),u=o.nodeSize;if(o==a){n-=u,r-=u;continue}if(!o.sameMarkup(a))return{a:n,b:r};if(o.isText&&o.text!=a.text){let l=0,c=Math.min(o.text.length,a.text.length);for(;le&&r(u,i+a,s||null,o)!==!1&&u.content.size){let c=a+1;u.nodesBetween(Math.max(0,e-c),Math.min(u.content.size,n-c),r,i+c)}a=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let s="",o=!0;return this.nodesBetween(e,n,(a,u)=>{let l=a.isText?a.text.slice(Math.max(e,u)-u,n-u):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&l||a.isTextblock)&&r&&(o?o=!1:s+=r),s+=l},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),s=1);se)for(let s=0,o=0;oe&&((on)&&(a.isText?a=a.cut(Math.max(0,e-o),Math.min(a.text.length,n-o)):a=a.cut(Math.max(0,e-o-1),Math.min(a.content.size,n-o-1))),r.push(a),i+=a.nodeSize),o=u}return new C(r,i)}cutByIndex(e,n){return e==n?C.empty:e==0&&n==this.content.length?this:new C(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new C(i,s)}addToStart(e){return new C([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new C(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||n>0?pi(r+1,o):pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return C.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new C(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return C.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};he.none=[];class Hi extends Error{}class B{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=sd(this.content,e+this.openStart,n);return r&&new B(r,this.openStart,this.openEnd)}removeBetween(e,n){return new B(id(this.content,e+this.openStart,n+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,n){if(!n)return B.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new B(C.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)i++;return new B(e,r,i)}}B.empty=new B(C.empty,0,0);function id(t,e,n){let{index:r,offset:i}=t.findIndex(e),s=t.maybeChild(r),{index:o,offset:a}=t.findIndex(n);if(i==e||s.isText){if(a!=n&&!t.child(o).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(id(s.content,e-i-1,n-i-1)))}function sd(t,e,n,r){let{index:i,offset:s}=t.findIndex(e),o=t.maybeChild(i);if(s==e||o.isText)return t.cut(0,e).append(n).append(t.cut(e));let a=sd(o.content,e-s-1,n);return a&&t.replaceChild(i,o.copy(a))}function Ph(t,e,n){if(n.openStart>t.depth)throw new Hi("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Hi("Inconsistent open depths");return od(t,e,n,0)}function od(t,e,n,r){let i=t.index(r),s=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Ir(t,e,n,r){let i=(e||t).node(n),s=0,o=e?e.index(n):i.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(Mn(t.nodeAfter,r),s++));for(let a=s;ai&&Jo(t,e,i+1),o=r.depth>i&&Jo(n,r,i+1),a=[];return Ir(null,t,i,a),s&&o&&e.index(i)==n.index(i)?(ad(s,o),Mn(Rn(s,ud(t,e,n,r,i+1)),a)):(s&&Mn(Rn(s,qi(t,e,i+1)),a),Ir(e,n,i,a),o&&Mn(Rn(o,qi(n,r,i+1)),a)),Ir(r,null,i,a),new C(a)}function qi(t,e,n){let r=[];if(Ir(null,t,n,r),t.depth>n){let i=Jo(t,e,n+1);Mn(Rn(i,qi(t,e,n+1)),r)}return Ir(e,null,n,r),new C(r)}function Bh(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)i=e.node(s).copy(C.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Vr{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.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,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let s=0;s0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Vi(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,s=n;for(let o=e;;){let{index:a,offset:u}=o.content.findIndex(s),l=s-u;if(r.push(o,a,i+u),!l||(o=o.child(a),o.isText))break;s=l-1,i+=u+1}return new Vr(n,r,s)}static resolveCached(e,n){let r=Mu.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ld(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=C.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),a=o&&o.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let u=i;un.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n 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(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=C.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};dn.prototype.text=void 0;class Ki extends dn{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ld(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Ki(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Ki(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function ld(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Un{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new zh(e,n);if(r.next==null)return Un.empty;let i=cd(r);r.next&&r.err("Unexpected trailing text");let s=jh(Gh(i));return Yh(s,r),s}matchType(e){for(let n=0;nl.createAndFill()));for(let l=0;l=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(`
+`)}}Un.empty=new Un(!0);class zh{constructor(e,n){this.string=e,this.nodeTypes=n,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 cd(t){let e=[];do e.push(Hh(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Hh(t){let e=[];do e.push(qh(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function qh(t){let e=Wh(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=Vh(t,e);else break;return e}function Ru(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Vh(t,e){let n=Ru(t),r=n;return t.eat(",")&&(t.next!="}"?r=Ru(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function Kh(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let s in n){let o=n[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function Wh(t){if(t.eat("(")){let e=cd(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=Kh(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Gh(t){let e=[[]];return i(s(t,0),n()),e;function n(){return e.push([])-1}function r(o,a,u){let l={term:u,to:a};return e[o].push(l),l}function i(o,a){o.forEach(u=>u.to=a)}function s(o,a){if(o.type=="choice")return o.exprs.reduce((u,l)=>u.concat(s(l,a)),[]);if(o.type=="seq")for(let u=0;;u++){let l=s(o.exprs[u],a);if(u==o.exprs.length-1)return l;i(l,a=n())}else if(o.type=="star"){let u=n();return r(a,u),i(s(o.expr,u),u),[r(u)]}else if(o.type=="plus"){let u=n();return i(s(o.expr,a),u),i(s(o.expr,u),u),[r(u)]}else{if(o.type=="opt")return[r(a)].concat(s(o.expr,a));if(o.type=="range"){let u=a;for(let l=0;l{t[o].forEach(({term:a,to:u})=>{if(!a)return;let l;for(let c=0;c{l||i.push([a,l=[]]),l.indexOf(c)==-1&&l.push(c)})})});let s=e[r.join(",")]=new Un(r.indexOf(t.length-1)>-1);for(let o=0;o-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:pd(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new dn(this,this.computeAttrs(e),C.from(n),he.setFrom(r))}createChecked(e=null,n,r){return n=C.from(n),this.checkContent(n),new dn(this,this.computeAttrs(e),n,he.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=C.from(n),n.size){let o=this.contentMatch.fillBefore(n);if(!o)return null;n=o.append(n)}let i=this.contentMatch.matchFragment(n),s=i&&i.fillBefore(C.empty,!0);return s?new dn(this,e,n.append(s),he.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[s]=new gd(s,n,o));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Jh(t,e,n){let r=n.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class Zh{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Jh(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Us{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=md(e,i.attrs),this.excluded=null;let s=fd(this.attrs);this.instance=s?new he(this,s):null}create(e=null){return!e&&this.instance?this.instance:new he(this,pd(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new Us(s,i++,n,o)),r}removeFromSet(e){for(var n=0;n-1}}class bd{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Be.from(e.nodes),n.marks=Be.from(e.marks||{}),this.nodes=Iu.compile(this.spec.nodes,this),this.marks=Us.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",a=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=Un.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=a=="_"?null:a?Lu(this,a.split(" ")):a==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Lu(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Iu){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(n,r,i)}text(e,n){let r=this.nodes.text;return new Ki(r,r.defaultAttrs,e,he.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return dn.fromJSON(this,e)}markFromJSON(e){return he.fromJSON(this,e)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function Lu(t,e){let n=[];for(let r=0;r-1)&&n.push(o=u)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function Xh(t){return t.tag!=null}function Qh(t){return t.style!=null}class fn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(Xh(i))this.tags.push(i);else if(Qh(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.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,n={}){let r=new Bu(this,n,!1);return r.addAll(e,he.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Bu(this,n,!0);return r.addAll(e,he.none,n.from,n.to),B.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(o.getAttrs){let u=o.getAttrs(n);if(u===!1)continue;o.attrs=u||void 0}return o}}}static schemaRules(e){let n=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=$u(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=$u(o)),o.node||o.ignore||o.mark||(o.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new fn(e,fn.schemaRules(e)))}}const yd={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},e0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ed={ol:!0,ul:!0},Wi=1,Gi=2,Lr=4;function Pu(t,e,n){return e!=null?(e?Wi:0)|(e==="full"?Gi:0):t&&t.whitespace=="pre"?Wi|Gi:n&~Lr}class hi{constructor(e,n,r,i,s,o){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=he.none,this.match=s||(o&Lr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(C.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Wi)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let n=C.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!yd.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Bu{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let i=n.topNode,s,o=Pu(null,n.preserveWhitespace,0)|(r?Lr:0);i?s=new hi(i.type,i.attrs,he.none,!0,n.topMatch||i.type.contentMatch,o):r?s=new hi(null,null,he.none,!0,null,o):s=new hi(e.schema.topNodeType,null,he.none,!0,null,o),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top;if(i.options&Gi||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Wi)i.options&Gi?r=r.replace(/\r\n?/g,`
+`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),n),this.findInText(e)}else this.findInside(e)}addElement(e,n,r){let i=e.nodeName.toLowerCase(),s;Ed.hasOwnProperty(i)&&this.parser.normalizeLists&&t0(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:e0.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,n);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let a,u=this.top,l=this.needsBlock;if(yd.hasOwnProperty(i))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),a=!0,u.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);return}let c=o&&o.skip?n:this.readStyles(e,n);c&&this.addAll(e,c),a&&this.sync(u),this.needsBlock=l}else{let a=this.readStyles(e,n);a&&this.addElementByRule(e,o,a,o.consuming===!1?s:void 0)}}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
+`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let i=0;i!u.clearMark(l)):n=n.concat(this.parser.schema.marks[u.mark].create(u.attrs)),u.consuming===!1)a=u;else break}}return n}addElementByRule(e,n,r,i){let s,o;if(n.node)if(o=this.parser.schema.nodes[n.node],o.isLeaf)this.insertNode(o.create(n.attrs),r)||this.leafFallback(e,r);else{let u=this.enter(o,n.attrs||null,r,n.preserveWhitespace);u&&(s=!0,r=u)}else{let u=this.parser.schema.marks[n.mark];r=r.concat(u.create(n.attrs))}let a=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(u=>this.insertNode(u,r));else{let u=e;typeof n.contentElement=="string"?u=e.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(e):n.contentElement&&(u=n.contentElement),this.findAround(e,u,!0),this.addAll(u,r),this.findAround(e,u,!1)}s&&this.sync(a)&&this.open--}addAll(e,n,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];o!=a;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,n);this.findAtPoint(e,s)}findPlace(e,n){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],a=o.findWrapping(e);if(a&&(!r||r.length>a.length)&&(r=a,i=o,!a.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(l.type):Fu(l.type,e))?(u=l.addToSet(u),!1):!0),this.nodes.push(new hi(e,n,u,i,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].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 n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(a,u)=>{for(;a>=0;a--){let l=n[a];if(l==""){if(a==n.length-1||a==0)continue;for(;u>=s;u--)if(o(a-1,u))return!0;return!1}else{let c=u>0||u==0&&i?this.nodes[u].type:r&&u>=s?r.node(u-s).type:null;if(!c||c.name!=l&&!c.isInGroup(l))return!1;u--}}return!0};return o(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function t0(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ed.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function n0(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function $u(t){let e={};for(let n in t)e[n]=t[n];return e}function Fu(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let s=[],o=a=>{s.push(a);for(let u=0;u{if(s.length||o.marks.length){let a=0,u=0;for(;a=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,n);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Di(co(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return Di(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new yn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Uu(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Uu(e.marks)}}function Uu(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function co(t){return t.document||window.document}const zu=new WeakMap;function r0(t){let e=zu.get(t);return e===void 0&&zu.set(t,e=i0(t)),e}function i0(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(n=i.slice(0,o),i=i.slice(o+1));let a,u=n?t.createElementNS(n,i):t.createElement(i),l=e[1],c=1;if(l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)){c=2;for(let d in l)if(l[d]!=null){let f=d.indexOf(" ");f>0?u.setAttributeNS(d.slice(0,f),d.slice(f+1),l[d]):u.setAttribute(d,l[d])}}for(let d=c;dc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:u,contentDOM:u}}else{let{dom:p,contentDOM:h}=Di(t,f,n,r);if(u.appendChild(p),h){if(a)throw new RangeError("Multiple content holes");a=h}}}return{dom:u,contentDOM:a}}const xd=65535,vd=Math.pow(2,16);function s0(t,e){return t+e*vd}function Hu(t){return t&xd}function o0(t){return(t-(t&xd))/vd}const wd=1,Sd=2,Ii=4,_d=8;class Xo{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&_d)>0}get deletedBefore(){return(this.delInfo&(wd|Ii))>0}get deletedAfter(){return(this.delInfo&(Sd|Ii))>0}get deletedAcross(){return(this.delInfo&Ii)>0}}class st{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&st.empty)return st.empty}recover(e){let n=0,r=Hu(e);if(!this.inverted)for(let i=0;ie)break;let l=this.ranges[a+s],c=this.ranges[a+o],d=u+l;if(e<=d){let f=l?e==u?-1:e==d?1:n:n,p=u+i+(f<0?0:c);if(r)return p;let h=e==(n<0?u:d)?null:s0(a/3,e-u),m=e==u?Sd:e==d?wd:Ii;return(n<0?e!=u:e!=d)&&(m|=_d),new Xo(p,m,h)}i+=c-l}return r?e+i:new Xo(e+i,0,null)}touches(e,n){let r=0,i=Hu(n),s=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;ae)break;let l=this.ranges[a+s],c=u+l;if(e<=c&&a==i*3)return!0;r+=this.ranges[a+o]-l}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new lr;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;rs&&u!o.isAtom||!a.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,s)}invert(){return new Dt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new sn(n.pos,r.pos,this.mark)}merge(e){return e instanceof sn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new sn(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,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new sn(n.from,n.to,e.markFromJSON(n.mark))}}qe.jsonID("addMark",sn);class Dt extends qe{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new B(Ia(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,r)}invert(){return new sn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Dt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Dt(n.from,n.to,e.markFromJSON(n.mark))}}qe.jsonID("removeMark",Dt);class on extends qe{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new B(C.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new Re(n.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Re(n.from,n.to,n.gapFrom,n.gapTo,B.fromJSON(e,n.slice),n.insert,!!n.structure)}}qe.jsonID("replaceAround",Re);function Qo(t,e,n){let r=t.resolve(e),i=n-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function a0(t,e,n,r){let i=[],s=[],o,a;t.doc.nodesBetween(e,n,(u,l,c)=>{if(!u.isInline)return;let d=u.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let f=Math.max(l,e),p=Math.min(l+u.nodeSize,n),h=r.addToSet(d);for(let m=0;mt.step(u)),s.forEach(u=>t.step(u))}function u0(t,e,n,r){let i=[],s=0;t.doc.nodesBetween(e,n,(o,a)=>{if(!o.isInline)return;s++;let u=null;if(r instanceof Us){let l=o.marks,c;for(;c=r.isInSet(l);)(u||(u=[])).push(c),l=c.removeFromSet(l)}else r?r.isInSet(o.marks)&&(u=[r]):u=o.marks;if(u&&u.length){let l=Math.min(a+o.nodeSize,n);for(let c=0;ct.step(new Dt(o.from,o.to,o.style)))}function La(t,e,n,r=n.contentMatch,i=!0){let s=t.doc.nodeAt(e),o=[],a=e+1;for(let u=0;u=0;u--)t.step(o[u])}function l0(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function _r(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),s=t.$from.index(r),o=t.$to.indexAfter(r);if(rn;h--)m||r.index(h)>0?(m=!0,c=C.from(r.node(h).copy(c)),d++):u--;let f=C.empty,p=0;for(let h=s,m=!1;h>n;h--)m||i.after(h+1)=0;o--){if(r.size){let a=n[o].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=C.from(n[o].type.create(n[o].attrs,r))}let i=e.start,s=e.end;t.step(new Re(i,s,i,s,new B(r,0,0),n.length,!0))}function h0(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=t.steps.length;t.doc.nodesBetween(e,n,(o,a)=>{let u=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,u)&&m0(t.doc,t.mapping.slice(s).map(a),r)){let l=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!h?l=!1:!p&&h&&(l=!0)}l===!1&&Td(t,o,a,s),La(t,t.mapping.slice(s).map(a,1),r,void 0,l===null);let c=t.mapping.slice(s),d=c.map(a,1),f=c.map(a+o.nodeSize,1);return t.step(new Re(d,f,d+1,f-1,new B(C.from(r.create(u,null,o.marks)),0,0),1,!0)),l===!0&&Nd(t,o,a,s),!1}})}function Nd(t,e,n,r){e.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let u=t.mapping.slice(r).map(n+1+s+o.index);t.replaceWith(u,u+1,e.type.schema.linebreakReplacement.create())}}})}function Td(t,e,n,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=t.mapping.slice(r).map(n+1+s);t.replaceWith(o,o+1,e.type.schema.text(`
+`))}})}function m0(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function g0(t,e,n,r,i){let s=t.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return t.replaceWith(e,e+s.nodeSize,o);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Re(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new B(C.from(o),0,0),1,!0))}function Kt(t,e,n=1,r){let i=t.resolve(e),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let l=i.depth-1,c=n-2;l>s;l--,c--){let d=i.node(l),f=i.index(l);if(d.type.spec.isolating)return!1;let p=d.content.cutByIndex(f,d.childCount),h=r&&r[c+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=r&&r[c]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(p))return!1}let a=i.indexAfter(s),u=r&&r[0];return i.node(s).canReplaceWith(a,a,u?u.type:i.node(s+1).type)}function b0(t,e,n=1,r){let i=t.doc.resolve(e),s=C.empty,o=C.empty;for(let a=i.depth,u=i.depth-n,l=n-1;a>u;a--,l--){s=C.from(i.node(a).copy(s));let c=r&&r[l];o=C.from(c?c.type.create(c.attrs,o):i.node(a).copy(o))}t.step(new Ce(e,e,new B(s.append(o),n,n),!0))}function En(t,e){let n=t.resolve(e),r=n.index();return kd(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function y0(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i0?(s=r.node(i+1),a++,o=r.node(i).maybeChild(a)):(s=r.node(i).maybeChild(a-1),o=r.node(i+1)),s&&!s.isTextblock&&kd(s,o)&&r.node(i).canReplace(a,a+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function E0(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,s=t.doc.resolve(e-n),o=s.node().type;if(i&&o.inlineContent){let c=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);c&&!d?r=!1:!c&&d&&(r=!0)}let a=t.steps.length;if(r===!1){let c=t.doc.resolve(e+n);Td(t,c.node(),c.before(),a)}o.inlineContent&&La(t,e+n-1,o,s.node().contentMatchAt(s.index()),r==null);let u=t.mapping.slice(a),l=u.map(e-n);if(t.step(new Ce(l,u.map(e+n,-1),B.empty,!0)),r===!0){let c=t.doc.resolve(l);Nd(t,c.node(),c.before(),t.steps.length)}return t}function x0(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,n))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,n))return r.after(i+1);if(s=0;o--){let a=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,u=r.index(o)+(a>0?1:0),l=r.node(o),c=!1;if(s==1)c=l.canReplace(u,u,i);else{let d=l.contentMatchAt(u).findWrapping(i.firstChild.type);c=d&&l.canReplaceWith(u,u,d[0])}if(c)return a==0?r.pos:a<0?r.before(o+1):r.after(o+1)}return null}function Hs(t,e,n=e,r=B.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),s=t.resolve(n);return Ad(i,s,r)?new Ce(e,n,r):new v0(i,s,r).fit()}function Ad(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class v0{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=C.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=C.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let l=this.findFittable();l?this.placeNodes(l):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,a=i.depth;for(;o&&a&&s.childCount==1;)s=s.firstChild.content,o--,a--;let u=new B(s,o,a);return e>-1?new Re(r.pos,e,this.$to.pos,this.$to.end(),u,n):u.size||r.pos!=this.$to.pos?new Ce(r.pos,i.pos,u):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}n=s.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=po(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let a=this.depth;a>=0;a--){let{type:u,match:l}=this.frontier[a],c,d=null;if(n==1&&(o?l.matchType(o.type)||(d=l.fillBefore(C.from(o),!1)):s&&u.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:a,parent:s,inject:d};if(n==2&&o&&(c=l.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:a,parent:s,wrap:c};if(s&&l.matchType(s.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=po(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new B(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=po(e,n);if(i.childCount<=1&&n>0){let s=e.size-n<=n+i.size;this.unplaced=new B(Mr(e,n-1,1),n-1,s?n-1:r)}else this.unplaced=new B(Mr(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:s}){for(;this.depth>n;)this.closeFrontierNode();if(s)for(let m=0;m1||u==0||m.content.size)&&(d=g,c.push(Cd(m.mark(f.allowedMarks(m.marks)),l==1?u:0,l==a.childCount?p:-1)))}let h=l==a.childCount;h||(p=-1),this.placed=Rr(this.placed,n,C.from(c)),this.frontier[n].match=d,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=a;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],s=n=0;a--){let{match:u,type:l}=this.frontier[a],c=ho(e,a,l,u,!0);if(!c||c.childCount)continue e}return{depth:n,fit:o,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Rr(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Rr(this.placed,this.depth,C.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(C.empty,!0);n.childCount&&(this.placed=Rr(this.placed,this.frontier.length,n))}}function Mr(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Mr(t.firstChild.content,e-1,n)))}function Rr(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Rr(t.lastChild.content,e-1,n)))}function po(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Cd(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(C.empty,!0)))),t.copy(r)}function ho(t,e,n,r,i){let s=t.node(e),o=i?t.indexAfter(e):t.index(e);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!w0(n,s.content,o)?a:null}function w0(t,e,n){for(let r=n;r0;f--,p--){let h=i.node(f).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;o.indexOf(f)>-1?a=f:i.before(f)==p&&o.splice(1,0,-f)}let u=o.indexOf(a),l=[],c=r.openStart;for(let f=r.content,p=0;;p++){let h=f.firstChild;if(l.push(h),p==r.openStart)break;f=h.content}for(let f=c-1;f>=0;f--){let p=l[f],h=S0(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(a)-1)))c=f;else if(h||!p.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let p=(f+c+1)%(r.openStart+1),h=l[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>d));f--){let p=o[f];p<0||(e=i.before(p),n=s.after(p))}}function Md(t,e,n,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(t).append(t);t=o.append(s.matchFragment(o).fillBefore(C.empty,!0))}return t}function N0(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=x0(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new B(C.from(r),0,0))}function T0(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),s=Rd(r,i);for(let o=0;o0&&(u||r.node(a-1).canReplace(r.index(a-1),i.indexAfter(a-1))))return t.delete(r.before(a),i.after(a))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&n>r.end(o)&&i.end(o)-n!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return t.delete(r.before(o),n);t.delete(e,n)}function Rd(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let s=t.start(i);if(se.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&n.push(i)}return n}class cr extends qe{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new B(C.from(i),0,n.isLeaf?0:1))}getMap(){return st.empty}invert(e){return new cr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new cr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new cr(n.pos,n.attr,n.value)}}qe.jsonID("attr",cr);class Kr extends qe{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return _e.ok(r)}getMap(){return st.empty}invert(e){return new Kr(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Kr(n.attr,n.value)}}qe.jsonID("docAttr",Kr);let pr=class extends Error{};pr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};pr.prototype=Object.create(Error.prototype);pr.prototype.constructor=pr;pr.prototype.name="TransformError";class Dd{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new lr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new pr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=B.empty){let i=Hs(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new B(C.from(r),0,0))}delete(e,n){return this.replace(e,n,B.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return _0(this,e,n,r),this}replaceRangeWith(e,n,r){return N0(this,e,n,r),this}deleteRange(e,n){return T0(this,e,n),this}lift(e,n){return c0(this,e,n),this}join(e,n=1){return E0(this,e,n),this}wrap(e,n){return p0(this,e,n),this}setBlockType(e,n=e,r,i=null){return h0(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return g0(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new cr(e,n,r)),this}setDocAttribute(e,n){return this.step(new Kr(e,n)),this}addNodeMark(e,n){return this.step(new on(e,n)),this}removeNodeMark(e,n){if(!(n instanceof he)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new fr(e,n)),this}split(e,n=1,r){return b0(this,e,n,r),this}addMark(e,n,r){return a0(this,e,n,r),this}removeMark(e,n,r){return u0(this,e,n,r),this}clearIncompatible(e,n,r){return La(this,e,n,r),this}}const mo=Object.create(null);class te{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new k0(e.min(n),e.max(n))]}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 n=0;n=0;s--){let o=n<0?er(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):er(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(o)return o}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new bt(e.node(0))}static atStart(e){return er(e,e,0,0,1)||new bt(e)}static atEnd(e){return er(e,e,e.content.size,e.childCount,-1)||new bt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=mo[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in mo)throw new RangeError("Duplicate use of selection JSON ID "+e);return mo[e]=n,n.prototype.jsonID=e,n}getBookmark(){return j.between(this.$anchor,this.$head).getBookmark()}}te.prototype.visible=!0;class k0{constructor(e,n){this.$from=e,this.$to=n}}let Vu=!1;function Ku(t){!Vu&&!t.parent.inlineContent&&(Vu=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class j extends te{constructor(e,n=e){Ku(e),Ku(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return te.near(r);let i=e.resolve(n.map(this.anchor));return new j(i.parent.inlineContent?i:r,r)}replace(e,n=B.empty){if(super.replace(e,n),n==B.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof j&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new qs(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new j(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let s=te.findFrom(n,r,!0)||te.findFrom(n,-r,!0);if(s)n=s.$head;else return te.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(te.findFrom(e,-r,!0)||te.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let a=e.child(o);if(a.isAtom){if(!s&&H.isSelectable(a))return H.create(t,n-(i<0?a.nodeSize:0))}else{let u=er(t,a,n+i,i<0?a.childCount:0,i,s);if(u)return u}n+=a.nodeSize*i}return null}function Wu(t,e,n){let r=t.steps.length-1;if(r{o==null&&(o=c)}),t.setSelection(te.near(t.doc.resolve(o),n))}const Gu=1,mi=2,ju=4;class A0 extends Dd{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=mi,this}ensureMarks(e){return he.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&mi)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~mi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||he.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(n);s=r==n?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,s)),this.selection.empty||this.setSelection(te.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,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|=ju,this}get scrolledIntoView(){return(this.updated&ju)>0}}function Yu(t,e){return!e||!t?t:t.bind(e)}class Dr{constructor(e,n,r){this.name=e,this.init=Yu(n.init,r),this.apply=Yu(n.apply,r)}}const C0=[new Dr("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Dr("selection",{init(t,e){return t.selection||te.atStart(e.doc)},apply(t){return t.selection}}),new Dr("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Dr("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class go{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=C0.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Dr(r.key,r.spec.state,r))})}}class ar{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,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new go(e.schema,e.plugins),s=new ar(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=dn.fromJSON(e.schema,n.doc);else if(o.name=="selection")s.selection=te.fromJSON(s.doc,n.selection);else if(o.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let u=r[a],l=u.spec.state;if(u.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){s[o.name]=l.fromJSON.call(u,e,n[a],s);return}}s[o.name]=o.init(e,s)}}),s}}function Id(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Id(i,e,{})),n[r]=i}return n}class Ee{constructor(e){this.spec=e,this.props={},e.props&&Id(e.props,this,this.props),this.key=e.key?e.key.key:Ld("plugin")}getState(e){return e[this.key]}}const bo=Object.create(null);function Ld(t){return t in bo?t+"$"+ ++bo[t]:(bo[t]=0,t+"$")}class Le{constructor(e="key"){this.key=Ld(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const $e=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Wr=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let ea=null;const qt=function(t,e,n){let r=ea||(ea=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},M0=function(){ea=null},zn=function(t,e,n,r){return n&&(Ju(t,e,n,r,-1)||Ju(t,e,n,r,1))},R0=/^(img|br|input|textarea|hr)$/i;function Ju(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:gt(t))){let s=t.parentNode;if(!s||s.nodeType!=1||oi(t)||R0.test(t.nodeName)||t.contentEditable=="false")return!1;e=$e(t)+(i<0?0:1),t=s}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?gt(t):0}else return!1}}function gt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function D0(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=gt(t)}else if(t.parentNode&&!oi(t))e=$e(t),t=t.parentNode;else return null}}function I0(t,e){for(;;){if(t.nodeType==3&&e2),ht=hr||(Lt?/Mac/.test(Lt.platform):!1),$0=Lt?/Win/.test(Lt.platform):!1,St=/Android \d/.test(xn),ai=!!Zu&&"webkitFontSmoothing"in Zu.documentElement.style,F0=ai?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function U0(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Ut(t,e){return typeof t=="number"?t:t[e]}function z0(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function Xu(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let o=n||t.dom;o;o=Wr(o)){if(o.nodeType!=1)continue;let a=o,u=a==s.body,l=u?U0(s):z0(a),c=0,d=0;if(e.topl.bottom-Ut(r,"bottom")&&(d=e.bottom-e.top>l.bottom-l.top?e.top+Ut(i,"top")-l.top:e.bottom-l.bottom+Ut(i,"bottom")),e.leftl.right-Ut(r,"right")&&(c=e.right-l.right+Ut(i,"right")),c||d)if(u)s.defaultView.scrollBy(c,d);else{let f=a.scrollLeft,p=a.scrollTop;d&&(a.scrollTop+=d),c&&(a.scrollLeft+=c);let h=a.scrollLeft-f,m=a.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(u||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function H0(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=n+1;o=n-20){r=a,i=u.top;break}}return{refDOM:r,refTop:i,stack:$d(t.dom)}}function $d(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Wr(r));return e}function q0({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Fd(n,r==0?0:r-e)}function Fd(t,e){for(let n=0;n=a){o=Math.max(h.bottom,o),a=Math.min(h.top,a);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!u&&h.left<=e.left&&h.right>=e.left&&(u=c,l={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(s=d+1)}}return!n&&u&&(n=u,i=l,r=0),n&&n.nodeType==3?K0(n,i):!n||r&&n.nodeType==1?{node:t,offset:s}:Ud(n,i)}function K0(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:t,offset:0}}function $a(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function W0(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(o.left+o.right)/2?1:-1}return t.docView.posFromDOM(r,i,s)}function j0(t,e,n,r){let i=-1;for(let s=e,o=!1;s!=t.dom;){let a=t.docView.nearestDesc(s,!0);if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)){let u=a.dom.getBoundingClientRect();if(a.node.isBlock&&a.parent&&(!o&&u.left>r.left||u.top>r.top?i=a.posBefore:(!o&&u.right-1?i:t.docView.posFromDOM(e,n,-1)}function zd(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let l;ai&&i&&r.nodeType==1&&(l=r.childNodes[i-1]).nodeType==1&&l.contentEditable=="false"&&l.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(a=j0(t,r,i,e))}a==null&&(a=G0(t,o,e));let u=t.docView.nearestDesc(o,!0);return{pos:a,inside:u?u.posAtStart-u.border:-1}}function Qu(t){return t.top=0&&i==r.nodeValue.length?(u--,c=1):n<0?u--:l++,kr(Zt(qt(r,u,l),c),c<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(n<0||i==gt(r))){let u=r.childNodes[i-1];if(u.nodeType==1)return yo(u.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(n<0||i==gt(r))){let u=r.childNodes[i-1],l=u.nodeType==3?qt(u,gt(u)-(o?0:1)):u.nodeType==1&&(u.nodeName!="BR"||!u.nextSibling)?u:null;if(l)return kr(Zt(l,1),!1)}if(s==null&&i=0)}function kr(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function yo(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function qd(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function Z0(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return qd(t,e,()=>{let{node:s}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(s,!0);if(!a)break;if(a.node.isBlock){s=a.contentDOM||a.dom;break}s=a.dom.parentNode}let o=Hd(t,i.pos,1);for(let a=s.firstChild;a;a=a.nextSibling){let u;if(a.nodeType==1)u=a.getClientRects();else if(a.nodeType==3)u=qt(a,0,a.nodeValue.length).getClientRects();else continue;for(let l=0;lc.top+1&&(n=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}const X0=/[\u0590-\u08ac]/;function Q0(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,a=t.domSelection();return a?!X0.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?s:o:qd(t,e,()=>{let{focusNode:u,focusOffset:l,anchorNode:c,anchorOffset:d}=t.domSelectionRange(),f=a.caretBidiLevel;a.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||u==h&&l==m;try{a.collapse(c,d),u&&(u!=c||l!=d)&&a.extend&&a.extend(u,l)}catch{}return f!=null&&(a.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}let el=null,tl=null,nl=!1;function em(t,e,n){return el==e&&tl==n?nl:(el=e,tl=n,nl=n=="up"||n=="down"?Z0(t,e,n):Q0(t,e,n))}const yt=0,rl=1,kn=2,Pt=3;class ui{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=yt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n$e(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!n||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||o instanceof Kd){i=e-s;break}s=a}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Vd&&s.side>=0;r--);if(n<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&n&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?$e(s.dom)+1:0}}else{let s,o=!0;for(;s=r=c&&n<=l-u.border&&u.node&&u.contentDOM&&this.contentDOM.contains(u.contentDOM))return u.parseRange(e,n,c);e=o;for(let d=a;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=$e(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(l>n||a==this.children.length-1)){n=l;for(let c=a+1;cp&&on){let p=a;a=u,u=p}let f=document.createRange();f.setEnd(u.node,u.offset),f.setStart(a.node,a.offset),l.removeAllRanges(),l.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let a=r+s.border,u=o-s.border;if(e>=a&&n<=u){this.dirty=e==r||n==o?kn:rl,e==a&&n==u&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Pt:s.markDirty(e-a,n-a);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?kn:Pt}r=o}this.dirty=kn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?kn:rl;n.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(o.nodeType!=1){let a=document.createElement("span");a.appendChild(o),o=a}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==yt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class tm extends ui{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Hn extends ui{constructor(e,n,r,i,s){super(e,[],r,i),this.mark=n,this.spec=s}static create(e,n,r,i){let s=i.nodeViews[n.type.name],o=s&&s(n,i,r);return(!o||!o.dom)&&(o=yn.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Hn(e,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Pt&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=yt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=sa(s,0,e,r));for(let a=0;a{if(!u)return o;if(u.parent)return u.parent.posBeforeChild(u)},r,i),c=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:d}=yn.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!d&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let f=c;return c=jd(c,r,n),l?u=new nm(e,n,r,i,c,d||null,f,l,s,o+1):n.isText?new Ks(e,n,r,i,c,f,s):new hn(e,n,r,i,c,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>C.empty)}return e}matchesNode(e,n,r){return this.dirty==yt&&e.eq(this.node)&&ji(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,o=s&&s.pos>-1?s:null,a=s&&s.pos<0,u=new im(this,o&&o.node,e);am(this.node,this.innerDeco,(l,c,d)=>{l.spec.marks?u.syncToMarks(l.spec.marks,r,e):l.type.side>=0&&!d&&u.syncToMarks(c==this.node.childCount?he.none:this.node.child(c).marks,r,e),u.placeWidget(l,e,i)},(l,c,d,f)=>{u.syncToMarks(l.marks,r,e);let p;u.findNodeMatch(l,c,d,f)||a&&e.state.selection.from>i&&e.state.selection.to-1&&u.updateNodeAt(l,c,d,p,e)||u.updateNextNode(l,c,d,e,f,i)||u.addNode(l,c,d,e,i),i+=l.nodeSize}),u.syncToMarks([],r,e),this.node.isTextblock&&u.addTextblockHacks(),u.destroyRest(),(u.changed||this.dirty==kn)&&(o&&this.protectLocalComposition(e,o),Wd(this.contentDOM,this.children,e),hr&&um(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof j)||rn+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,a=lm(this.node.content,o,r-n,i-n);return a<0?null:{node:s,pos:a,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let s=n;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 tm(this,s,n,i);e.input.compositionNodes.push(o),this.children=sa(this.children,r,r+i.length,e,o)}update(e,n,r,i){return this.dirty==Pt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=yt}updateOuterDeco(e){if(ji(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Gd(this.dom,this.nodeDOM,ia(this.outerDeco,this.node,n),ia(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function il(t,e,n,r,i){jd(r,e,t);let s=new hn(void 0,t,e,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Ks extends hn{constructor(e,n,r,i,s,o,a){super(e,n,r,i,s,null,o,a,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Pt||this.dirty!=yt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=yt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=yt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new Ks(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Pt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Kd extends ui{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==yt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class nm extends hn{constructor(e,n,r,i,s,o,a,u,l,c){super(e,n,r,i,s,o,a,l,c),this.spec=u}update(e,n,r,i){if(this.dirty==Pt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Wd(t,e,n){let r=t.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=Hn.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,n,r))s=this.top.children.indexOf(o,this.index);else for(let a=this.index,u=Math.min(this.top.children.length,a+5);a0;){let a;for(;;)if(r){let l=n.children[r-1];if(l instanceof Hn)n=l,r=l.children.length;else{a=l,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let u=a.node;if(u){if(u!=t.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}function om(t,e){return t.type.side-e.type.side}function am(t,e,n,r){let i=e.locals(t),s=0;if(i.length==0){for(let l=0;ls;)a.push(i[o++]);let h=s+f.nodeSize;if(f.isText){let g=h;o!g.inline):a.slice();r(f,m,e.forChild(s,f),p),s=h}}function um(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function lm(t,e,n,r){for(let i=0,s=0;i=n){if(s>=r&&u.slice(r-e.length-a,r-a)==e)return r-e.length;let l=a=0&&l+e.length+a>=n)return a+l;if(n==r&&u.length>=r+e.length-a&&u.slice(r-a,r-a+e.length)==e)return r}}return-1}function sa(t,e,n,r,i){let s=[];for(let o=0,a=0;o=n||c<=e?s.push(u):(ln&&s.push(u.slice(n-l,u.size,r)))}return s}function Fa(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,o=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),u,l;if(Vs(n)){for(u=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&H.isSelectable(d)&&i.parent&&!(d.isInline&&L0(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;l=new H(o==f?a:r.resolve(f))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let d=o,f=o;for(let p=0;p{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Yd(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function dm(t){let e=t.domSelection(),n=document.createRange();if(!e)return;let r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setStart(r.parentNode,$e(r)+1):n.setStart(r,0),n.collapse(!0),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&nt&&pn<=11&&(r.disabled=!0,r.disabled=!1)}function Jd(t,e){if(e instanceof H){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(ll(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else ll(t)}function ll(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Ua(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||j.between(e,n,r)}function cl(t){return t.editable&&!t.hasFocus()?!1:Zd(t)}function Zd(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function fm(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return zn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function oa(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&te.findFrom(s,e)}function Xt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function dl(t,e,n){let r=t.state.selection;if(r instanceof j)if(n.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Xt(t,new j(r.$anchor,o))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=oa(t.state,e);return i&&i instanceof H?Xt(t,i):!1}else if(!(ht&&n.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let a=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=t.docView.descAt(a))&&!o.contentDOM?H.isSelectable(s)?Xt(t,new H(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):ai?Xt(t,new j(t.state.doc.resolve(e<0?a:a+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof H&&r.node.isInline)return Xt(t,new j(e>0?r.$to:r.$from));{let i=oa(t.state,e);return i?Xt(t,i):!1}}}function Yi(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Br(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Jn(t,e){return e<0?pm(t):hm(t)}function pm(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,s,o=!1;for(Tt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(Br(a,-1))i=n,s=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if(Xd(n))break;{let a=n.previousSibling;for(;a&&Br(a,-1);)i=n.parentNode,s=$e(a),a=a.previousSibling;if(a)n=a,r=Yi(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}o?aa(t,n,r):i&&aa(t,i,s)}function hm(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Yi(n),s,o;for(;;)if(r{t.state==i&&Wt(t)},50)}function fl(t,e){let n=t.state.doc.resolve(e);if(!(He||$0)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function pl(t,e,n){let r=t.state.selection;if(r instanceof j&&!r.empty||n.indexOf("s")>-1||ht&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let o=oa(t.state,e);if(o&&o instanceof H)return Xt(t,o)}if(!i.parent.inlineContent){let o=e<0?i:s,a=r instanceof bt?te.near(o,e):te.findFrom(o,e);return a?Xt(t,a):!1}return!1}function hl(t,e){if(!(t.state.selection instanceof j))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let o=t.state.tr;return e<0?o.delete(n.pos-s.nodeSize,n.pos):o.delete(n.pos,n.pos+s.nodeSize),t.dispatch(o),!0}return!1}function ml(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function bm(t){if(!Ge||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ml(t,r,"true"),setTimeout(()=>ml(t,r,"false"),20)}return!1}function ym(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function Em(t,e){let n=e.keyCode,r=ym(e);if(n==8||ht&&n==72&&r=="c")return hl(t,-1)||Jn(t,-1);if(n==46&&!e.shiftKey||ht&&n==68&&r=="c")return hl(t,1)||Jn(t,1);if(n==13||n==27)return!0;if(n==37||ht&&n==66&&r=="c"){let i=n==37?fl(t,t.state.selection.from)=="ltr"?-1:1:-1;return dl(t,i,r)||Jn(t,i)}else if(n==39||ht&&n==70&&r=="c"){let i=n==39?fl(t,t.state.selection.from)=="ltr"?1:-1:1;return dl(t,i,r)||Jn(t,i)}else{if(n==38||ht&&n==80&&r=="c")return pl(t,-1,r)||Jn(t,-1);if(n==40||ht&&n==78&&r=="c")return bm(t)||pl(t,1,r)||Jn(t,1);if(r==(ht?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function za(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let o=t.someProp("clipboardSerializer")||yn.fromSchema(t.state.schema),a=sf(),u=a.createElement("div");u.appendChild(o.serializeFragment(r,{document:a}));let l=u.firstChild,c,d=0;for(;l&&l.nodeType==1&&(c=rf[l.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=a.createElement(c[p]);for(;u.firstChild;)h.appendChild(u.firstChild);u.appendChild(h),d++}l=u.firstChild}l&&l.nodeType==1&&l.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(n)}`);let f=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,`
`);return{dom:u,text:f,slice:e}}function Qd(t,e,n,r,i){let s=i.parent.type.spec.code,o,a;if(!n&&!e)return null;let u=e&&(r||s||!n);if(u){if(t.someProp("transformPastedText",f=>{e=f(e,s||r,t)}),s)return e?new B(C.from(t.state.schema.text(e.replace(/\r\n?/g,`
-`))),0,0):B.empty;let d=t.someProp("clipboardTextParser",f=>f(e,i,r,t));if(d)a=d;else{let f=i.marks(),{schema:p}=t.state,h=yn.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,f)))})}}else t.someProp("transformPastedHTML",d=>{n=d(n,t)}),o=_m(n),ai&&Nm(o);let l=o&&o.querySelector("[data-pm-slice]"),c=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let d=+c[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||fn.fromSchema(t.state.schema)).parseSlice(o,{preserveWhitespace:!!(u||c),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!vm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),c)a=Tm(gl(a,+c[1],+c[2]),c[4]);else if(a=B.maxOpen(wm(a.content,i),!0),a.openStart||a.openEnd){let d=0,f=0;for(let p=a.content.firstChild;d{a=d(a,t)}),a}const vm=/^(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 wm(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),s,o=[];if(t.forEach(a=>{if(!o)return;let u=i.findWrapping(a.type),l;if(!u)return o=null;if(l=o.length&&s.length&&tf(u,s,a,o[o.length-1],0))o[o.length-1]=l;else{o.length&&(o[o.length-1]=nf(o[o.length-1],s.length));let c=ef(a,u);o.push(c),i=i.matchType(c.type),s=u}}),o)return C.from(o)}return t}function ef(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,C.from(t));return t}function tf(t,e,n,r,i){if(i1&&(s=0),i=n&&(a=e<0?o.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(C.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(a))}function gl(t,e,n){return en})),xo.createHTML(t)):t}function _m(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=sf().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&rf[r[1].toLowerCase()])&&(t=i.map(s=>"<"+s+">").join("")+t+i.map(s=>""+s+">").reverse().join("")),n.innerHTML=Sm(t),i)for(let s=0;s=0;a-=2){let u=n.nodes[r[a]];if(!u||u.hasRequiredAttrs())break;i=C.from(u.create(r[a+1],i)),s++,o++}return new B(i,s,o)}const je={},Ye={},km={touchstart:!0,touchmove:!0};class Om{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Am(t){for(let e in je){let n=je[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{Mm(t,r)&&!Ha(t,r)&&(t.editable||!(r.type in Ye))&&n(t,r)},km[e]?{passive:!0}:void 0)}Ge&&t.dom.addEventListener("input",()=>null),la(t)}function an(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Cm(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function la(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>Ha(t,r))})}function Ha(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function Mm(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function Rm(t,e){!Ha(t,e)&&je[e.type]&&(t.editable||!(e.type in Ye))&&je[e.type](t,e)}Ye.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!af(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(St&&He&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),hr&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,Nn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||xm(t,n)?n.preventDefault():an(t,"key")};Ye.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Ye.keypress=(t,e)=>{let n=e;if(af(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||ht&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof j)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode);!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",s=>s(t,r.$from.pos,r.$to.pos,i))&&t.dispatch(t.state.tr.insertText(i).scrollIntoView()),n.preventDefault()}};function Ws(t){return{left:t.clientX,top:t.clientY}}function Dm(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function qa(t,e,n,r,i){if(r==-1)return!1;let s=t.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(t.someProp(e,a=>o>s.depth?a(t,n,s.nodeAfter,s.before(o),i,!0):a(t,n,s.node(o),s.before(o),i,!1)))return!0;return!1}function dr(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",!0),t.dispatch(r)}function Im(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&H.isSelectable(r)?(dr(t,new H(n)),!0):!1}function Lm(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof H&&(r=n.node);let s=t.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let a=o>s.depth?s.nodeAfter:s.node(o);if(H.isSelectable(a)){r&&n.$from.depth>0&&o>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?i=s.before(n.$from.depth):i=s.before(o);break}}return i!=null?(dr(t,H.create(t.state.doc,i)),!0):!1}function Pm(t,e,n,r,i){return qa(t,"handleClickOn",e,n,r)||t.someProp("handleClick",s=>s(t,e,r))||(i?Lm(t,n):Im(t,n))}function Bm(t,e,n,r){return qa(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function $m(t,e,n,r){return qa(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||Fm(t,n,r)}function Fm(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(dr(t,j.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),a=i.before(s);if(o.inlineContent)dr(t,j.create(r,a+1,a+1+o.content.size));else if(H.isSelectable(o))dr(t,H.create(r,a));else continue;return!0}}function Va(t){return Ji(t)}const of=ht?"metaKey":"ctrlKey";je.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=Va(t),i=Date.now(),s="singleClick";i-t.input.lastClick.time<500&&Dm(n,t.input.lastClick)&&!n[of]&&(t.input.lastClick.type=="singleClick"?s="doubleClick":t.input.lastClick.type=="doubleClick"&&(s="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:s};let o=t.posAtCoords(Ws(n));o&&(s=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Um(t,o,n,!!r)):(s=="doubleClick"?Bm:$m)(t,o.pos,o.inside,n)?n.preventDefault():an(t,"pointer"))};class Um{constructor(e,n,r,i){this.view=e,this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[of],this.allowDefault=r.shiftKey;let s,o;if(n.inside>-1)s=e.state.doc.nodeAt(n.inside),o=n.inside;else{let c=e.state.doc.resolve(n.pos);s=c.parent,o=c.depth?c.before():0}const a=i?null:r.target,u=a?e.docView.nearestDesc(a,!0):null;this.target=u&&u.dom.nodeType==1?u.dom:null;let{selection:l}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||l instanceof H&&l.from<=o&&l.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Tt&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),an(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>Wt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(Ws(e))),this.updateAllowDefault(e),this.allowDefault||!n?an(this.view,"pointer"):Pm(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Ge&&this.mightDrag&&!this.mightDrag.node.isAtom||He&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(dr(this.view,te.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):an(this.view,"pointer")}move(e){this.updateAllowDefault(e),an(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}je.touchstart=t=>{t.input.lastTouch=Date.now(),Va(t),an(t,"pointer")};je.touchmove=t=>{t.input.lastTouch=Date.now(),an(t,"pointer")};je.contextmenu=t=>Va(t);function af(t,e){return t.composing?!0:Ge&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const zm=St?5e3:-1;Ye.compositionstart=Ye.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof j&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))t.markCursor=t.state.storedMarks||n.marks(),Ji(t,!0),t.markCursor=null;else if(Ji(t,!e.selection.empty),Tt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let a=t.domSelection();a&&a.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}t.input.composing=!0}uf(t,zm)};Ye.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,uf(t,20))};function uf(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ji(t),e))}function lf(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=qm());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Hm(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=I0(e.focusNode,e.focusOffset),r=L0(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(n==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let o=n.pmViewDesc;if(!(!o||!o.isText(n.nodeValue)))return r}}return n||r}function qm(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function Ji(t,e=!1){if(!(St&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),lf(t),e||t.docView&&t.docView.dirty){let n=Fa(t);return n&&!n.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!t.state.selection.empty?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function Vm(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const Gr=nt&&pn<15||hr&&U0<604;je.copy=Ye.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let s=Gr?null:n.clipboardData,o=r.content(),{dom:a,text:u}=za(t,o);s?(n.preventDefault(),s.clearData(),s.setData("text/html",a.innerHTML),s.setData("text/plain",u)):Vm(t,a),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Km(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function Wm(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?jr(t,r.value,null,i,e):jr(t,r.textContent,r.innerHTML,i,e)},50)}function jr(t,e,n,r,i){let s=Qd(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",u=>u(t,i,s||B.empty)))return!0;if(!s)return!1;let o=Km(s),a=o?t.state.tr.replaceSelectionWith(o,r):t.state.tr.replaceSelection(s);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function cf(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Ye.paste=(t,e)=>{let n=e;if(t.composing&&!St)return;let r=Gr?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&jr(t,cf(r),r.getData("text/html"),i,n)?n.preventDefault():Wm(t,n)};class df{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const ff=ht?"altKey":"ctrlKey";je.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,s=i.empty?null:t.posAtCoords(Ws(n)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof H?i.to-1:i.to))){if(r&&r.mightDrag)o=H.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let d=t.docView.nearestDesc(n.target,!0);d&&d.node.type.spec.draggable&&d!=t.docView&&(o=H.create(t.state.doc,d.posBefore))}}let a=(o||t.state.selection).content(),{dom:u,text:l,slice:c}=za(t,a);(!n.dataTransfer.files.length||!He||Bd>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Gr?"Text":"text/html",u.innerHTML),n.dataTransfer.effectAllowed="copyMove",Gr||n.dataTransfer.setData("text/plain",l),t.dragging=new df(c,!n[ff],o)};je.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Ye.dragover=Ye.dragenter=(t,e)=>e.preventDefault();Ye.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let i=t.posAtCoords(Ws(n));if(!i)return;let s=t.state.doc.resolve(i.pos),o=r&&r.slice;o?t.someProp("transformPasted",h=>{o=h(o,t)}):o=Qd(t,cf(n.dataTransfer),Gr?null:n.dataTransfer.getData("text/html"),!1,s);let a=!!(r&&!n[ff]);if(t.someProp("handleDrop",h=>h(t,n,o||B.empty,a))){n.preventDefault();return}if(!o)return;n.preventDefault();let u=o?Od(t.state.doc,s.pos,o):s.pos;u==null&&(u=s.pos);let l=t.state.tr;if(a){let{node:h}=r;h?h.replace(l):l.deleteSelection()}let c=l.mapping.map(u),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=l.doc;if(d?l.replaceRangeWith(c,c,o.content.firstChild):l.replaceRange(c,c,o),l.doc.eq(f))return;let p=l.doc.resolve(c);if(d&&H.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))l.setSelection(new H(p));else{let h=l.mapping.map(u);l.mapping.maps[l.mapping.maps.length-1].forEach((m,g,y,v)=>h=v),l.setSelection(Ua(t,p,l.doc.resolve(h)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))};je.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Wt(t)},20))};je.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};je.beforeinput=(t,e)=>{if(He&&St&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",s=>s(t,Nn(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Ye)je[t]=Ye[t];function Yr(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Zi{constructor(e,n){this.toDOM=e,this.spec=n||Dn,this.side=this.spec.side||0}map(e,n,r,i){let{pos:s,deleted:o}=e.mapResult(n.from+i,this.side<0?-1:1);return o?null:new We(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Zi&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Yr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class mn{constructor(e,n){this.attrs=e,this.spec=n||Dn}map(e,n,r,i){let s=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new We(s,o,this)}valid(e,n){return n.from=e&&(!s||s(a.spec))&&r.push(a.copy(a.from+i,a.to+i))}for(let o=0;oe){let a=this.children[o]+1;this.children[o+2].findInner(e-a,n-a,r,i+a,s)}}map(e,n,r){return this==ze||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Dn)}mapInner(e,n,r,i,s){let o;for(let a=0;a{let l=u+r,c;if(c=hf(n,a,l)){for(i||(i=this.children.slice());sa&&d.to=e){this.children[a]==e&&(r=this.children[a+2]);break}let s=e+1,o=s+n.content.size;for(let a=0;as&&u.type instanceof mn){let l=Math.max(s,u.from)-s,c=Math.min(o,u.to)-s;li.map(e,n,Dn));return tn.from(r)}forChild(e,n){if(n.isLeaf)return be.empty;let r=[];for(let i=0;in instanceof be)?e:e.reduce((n,r)=>n.concat(r instanceof be?r:r.members),[]))}}forEachSet(e){for(let n=0;n{let g=m-h-(p-f);for(let y=0;yv+c-d)continue;let _=a[y]+c-d;p>=_?a[y+1]=f<=_?-2:-1:f>=c&&g&&(a[y]+=g,a[y+1]+=g)}d+=g}),c=n.maps[l].map(c,-1)}let u=!1;for(let l=0;l=r.content.size){u=!0;continue}let f=n.map(t[l+1]+s,-1),p=f-i,{index:h,offset:m}=r.content.findIndex(d),g=r.maybeChild(h);if(g&&m==d&&m+g.nodeSize==p){let y=a[l+2].mapInner(n,g,c+1,t[l]+s+1,o);y!=ze?(a[l]=d,a[l+1]=p,a[l+2]=y):(a[l+1]=-2,u=!0)}else u=!0}if(u){let l=jm(a,t,e,n,i,s,o),c=Xi(l,r,0,o);e=c.local;for(let d=0;dn&&o.to{let l=hf(t,a,u+n);if(l){s=!0;let c=Xi(l,a,n+u+1,r);c!=ze&&i.push(u,u+a.nodeSize,c)}});let o=pf(s?mf(t):t,-n).sort(In);for(let a=0;a0;)e++;t.splice(e,0,n)}function vo(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=ze&&e.push(r)}),t.cursorWrapper&&e.push(be.create(t.state.doc,[t.cursorWrapper.deco])),tn.from(e)}const Ym={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Jm=nt&&pn<=11;class Zm{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class Xm{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Zm,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Jm&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ym)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let n=0;nthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(cl(this.view)){if(this.suppressingSelectionUpdates)return Wt(this.view);if(nt&&pn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&zn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let n=new Set,r;for(let s=e.focusNode;s;s=Wr(s))n.add(s);for(let s=e.anchorNode;s;s=Wr(s))if(n.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&cl(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,a=!1,u=[];if(e.editable)for(let c=0;cd.nodeName=="BR");if(c.length==2){let[d,f]=c;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of c){let p=f.parentNode;p&&p.nodeName=="LI"&&(!d||tg(e,d)!=p)&&f.remove()}}}let l=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)