1||a==0||m.content.size)&&(f=g,u.push(Bc(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let h=c==l.childCount;h||(p=-1),this.placed=Sr(this.placed,t,w.from(u)),this.frontier[t].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:c}=this.frontier[l],u=Ms(e,l,c,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Sr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Sr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Sr(this.placed,this.frontier.length,t))}};function wr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(wr(n.firstChild.content,e-1,t)))}function Sr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Sr(n.lastChild.content,e-1,t)))}function Ts(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Bc(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Ms(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Bh(t,o.content,s)?l:null}function Bh(n,e,t){for(let r=t;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),c=[],u=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(c.push(h),p==r.openStart)break;d=h.content}for(let d=u-1;d>=0;d--){let p=c[d],h=zh(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))u=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+u+1)%(r.openStart+1),h=c[p];if(h)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),t=o.after(p))}}function zc(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function Fh(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Lh(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new M(w.from(r),0,0))}function Hh(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let s=r.sharedDepth(t),l=!1;for(let a=r.depth;a>s;a--)r.node(a).type.spec.isolating&&(l=!0);for(let a=i.depth;a>s;a--)i.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=r.depth;a>0&&e==r.start(a);a--)e=r.before(a);for(let a=i.depth;a>0&&t==i.start(a);a--)t=i.before(a);r=n.doc.resolve(e),i=n.doc.resolve(t)}}let o=$c(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function $c(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Pi=class n extends he{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ke.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ke.fromReplace(e,this.pos,this.pos+1,new M(w.from(i),0,t.isLeaf?0:1))}getMap(){return Et.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};he.jsonID("attr",Pi);var Li=class n extends he{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ke.ok(r)}getMap(){return Et.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};he.jsonID("docAttr",Li);var jn=class extends Error{};jn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};jn.prototype=Object.create(Error.prototype);jn.prototype.constructor=jn;jn.prototype.name="TransformError";var Wn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Er}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new jn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let r=0;r{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=M.empty){let i=Or(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new M(w.from(r),0,0))}delete(e,t){return this.replace(e,t,M.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return $h(this,e,t,r),this}replaceRangeWith(e,t,r){return Fh(this,e,t,r),this}deleteRange(e,t){return Hh(this,e,t),this}lift(e,t){return Eh(this,e,t),this}join(e,t=1){return Ph(this,e,t),this}wrap(e,t){return Oh(this,e,t),this}setBlockType(e,t=e,r,i=null){return Ah(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Dh(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Pi(e,t,r)),this}setDocAttribute(e,t){return this.step(new Li(e,t)),this}addNodeMark(e,t){return this.step(new Mr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof W)t.isInSet(r.marks)&&this.step(new Vn(e,t));else{let i=r.marks,o,s=[];for(;o=t.isInSet(i);)s.push(new Vn(e,o)),i=o.removeFromSet(i);for(let l=s.length-1;l>=0;l--)this.step(s[l])}return this}split(e,t=1,r){return Rh(this,e,t,r),this}addMark(e,t,r){return wh(this,e,t,r),this}removeMark(e,t,r){return Sh(this,e,t,r),this}clearIncompatible(e,t,r){return Ds(this,e,t,r),this}};var Rs=Object.create(null),L=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new $i(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Un(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Un(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Re(e.node(0))}static atStart(e){return Un(e,e,0,0,1)||new Re(e)}static atEnd(e){return Un(e,e,e.content.size,e.childCount,-1)||new Re(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Rs[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Rs)throw new RangeError("Duplicate use of selection JSON ID "+e);return Rs[e]=t,t.prototype.jsonID=e,t}getBookmark(){return P.between(this.$anchor,this.$head).getBookmark()}};L.prototype.visible=!0;var $i=class{constructor(e,t){this.$from=e,this.$to=t}},Fc=!1;function Hc(n){!Fc&&!n.parent.inlineContent&&(Fc=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var P=class n extends L{constructor(e,t=e){Hc(e),Hc(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return L.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=M.empty){if(super.replace(e,t),t==M.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Fi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=L.findFrom(t,r,!0)||L.findFrom(t,-r,!0);if(o)t=o.$head;else return L.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(L.findFrom(e,-r,!0)||L.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&D.isSelectable(l))return D.create(n,t-(i<0?l.nodeSize:0))}else{let a=Un(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function Vc(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=u)}),n.setSelection(L.near(n.doc.resolve(s),t))}var jc=1,zi=2,Wc=4,Ls=class extends Wn{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|=zi,this}ensureMarks(e){return W.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&zi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~zi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||W.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(L.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Wc,this}get scrolledIntoView(){return(this.updated&Wc)>0}};function _c(n,e){return!e||!n?n:n.bind(e)}var cn=class{constructor(e,t,r){this.name=e,this.init=_c(t.init,r),this.apply=_c(t.apply,r)}},jh=[new cn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new cn("selection",{init(n,e){return n.selection||L.atStart(e.doc)},apply(n){return n.selection}}),new cn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new cn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Ar=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=jh.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new cn(r.key,r.spec.state,r))})}},Hi=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ar(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Ue.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=L.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=c.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function qc(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=qc(i,e,{})),t[r]=i}return t}var _=class{constructor(e){this.spec=e,this.props={},e.props&&qc(e.props,this,this.props),this.key=e.key?e.key.key:Uc("plugin")}getState(e){return e[this.key]}},Is=Object.create(null);function Uc(n){return n in Is?n+"$"+ ++Is[n]:(Is[n]=0,n+"$")}var X=class{constructor(e="key"){this.key=Uc(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ve=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Xn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Vs=null,Ot=function(n,e,t){let r=Vs||(Vs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Wh=function(){Vs=null},gn=function(n,e,t,r){return t&&(Kc(n,e,t,r,-1)||Kc(n,e,t,r,1))},_h=/^(img|br|input|textarea|hr)$/i;function Kc(n,e,t,r,i){for(var o;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ge(n))){let s=n.parentNode;if(!s||s.nodeType!=1||zr(n)||_h.test(n.nodeName)||n.contentEditable=="false")return!1;e=ve(n)+(i<0?0:1),n=s}else if(n.nodeType==1){let s=n.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else n=s,e=i<0?Ge(n):0}else return!1}}function Ge(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function qh(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ge(n)}else if(n.parentNode&&!zr(n))e=ve(n),n=n.parentNode;else return null}}function Uh(n,e){for(;;){if(n.nodeType==3&&e2),Je=Qn||(dt?/Mac/.test(dt.platform):!1),Ou=dt?/Win/.test(dt.platform):!1,At=/Android \d/.test(Ut),$r=!!Jc&&"webkitFontSmoothing"in Jc.documentElement.style,Yh=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Xh(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Mt(n,e){return typeof n=="number"?n:n[e]}function Qh(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Gc(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;){if(s.nodeType!=1){s=Xn(s);continue}let l=s,a=l==o.body,c=a?Xh(o):Qh(l),u=0,f=0;if(e.topc.bottom-Mt(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+Mt(i,"top")-c.top:e.bottom-c.bottom+Mt(i,"bottom")),e.leftc.right-Mt(r,"right")&&(u=e.right-c.right+Mt(i,"right")),u||f)if(a)o.defaultView.scrollBy(u,f);else{let p=l.scrollLeft,h=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let m=l.scrollLeft-p,g=l.scrollTop-h;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=a?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d=="absolute"?s.offsetParent:Xn(s)}}function Zh(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Au(n.dom)}}function Au(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Xn(r));return e}function em({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Nu(t,r==0?0:r-e)}function Nu(n,e){for(let t=0;t=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=u,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?nm(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Du(t,i)}function nm(n,e){let t=n.nodeValue.length,r=document.createRange(),i;for(let o=0;o=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:n,offset:0}}function ol(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function rm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function om(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Ru(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;$r&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=om(n,r,i,e))}l==null&&(l=im(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Yc(n){return n.top=0&&i==r.nodeValue.length?(a--,u=1):t<0?a--:c++,Nr(Vt(Ot(r,a,c),u),u<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==Ge(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Bs(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==Ge(r))){let a=r.childNodes[i-1],c=a.nodeType==3?Ot(a,Ge(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Nr(Vt(c,1),!1)}if(o==null&&i=0)}function Nr(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Bs(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Pu(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function am(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Pu(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Iu(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Ot(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cu.top+1&&(t=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}var cm=/[\u0590-\u08ac]/;function um(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!cm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Pu(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:h,focusOffset:m}=n.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&c==m;try{l.collapse(u,f),a&&(a!=u||c!=f)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var Xc=null,Qc=null,Zc=!1;function fm(n,e,t){return Xc==e&&Qc==t?Zc:(Xc=e,Qc=t,Zc=t=="up"||t=="down"?am(n,e,t):um(n,e,t))}var Xe=0,eu=1,fn=2,pt=3,yn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Xe,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tve(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof Wi){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Vi&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?ve(o.dom)+1:0}}else{let o,s=!0;for(;o=r=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ve(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;uh&&st){let h=l;l=a,a=h}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?fn:eu,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=pt:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?fn:pt}r=s}this.dirty=fn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?fn:eu;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==Xe&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},qs=class extends yn{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Zn=class n extends yn{constructor(e,t,r,i,o){super(e,[],r,i),this.mark=t,this.spec=o}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=Ct.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&pt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=pt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Xe){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Gs(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=Ct.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let d=u;return u=zu(u,r,t),c?a=new Us(e,t,r,i,u,f||null,d,c,o,s+1):t.isText?new ji(e,t,r,i,u,d,o):new n(e,t,r,i,u,f||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Xe&&e.eq(this.node)&&_i(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Js(this,s&&s.node,e);mm(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?W.none:this.node.child(u).marks,r,e,u),a.placeWidget(c,e,i)},(c,u,f,d)=>{a.syncToMarks(c.marks,r,e,d);let p;a.findNodeMatch(c,u,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,u,f,p,e)||a.updateNextNode(c,u,f,e,d,i)||a.addNode(c,u,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==fn)&&(s&&this.protectLocalComposition(e,s),Lu(this.contentDOM,this.children,e),Qn&&gm(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof P)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=ym(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new qs(this,o,t,i);e.input.compositionNodes.push(s),this.children=Gs(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==pt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Xe}updateOuterDeco(e){if(_i(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Bu(this.dom,this.nodeDOM,Ks(this.outerDeco,this.node,t),Ks(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function tu(n,e,t,r,i){zu(r,e,n);let o=new qt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var ji=class n extends qt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==pt||this.dirty!=Xe&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Xe||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=Xe,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=pt)}get domAtom(){return!1}isText(e){return this.node.text==e}},Wi=class extends yn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Xe&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Us=class extends qt{constructor(e,t,r,i,o,s,l,a,c,u){super(e,t,r,i,o,s,l,c,u),this.spec=a}update(e,t,r,i){if(this.dirty==pt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Lu(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,l=Math.min(s,e.length);for(;o-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=Zn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof Zn)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function hm(n,e){return n.type.side-e.type.side}function mm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;co;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let g=h;s!g.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function gm(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function ym(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Gs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||u<=e?o.push(a):(ct&&o.push(a.slice(t-c,a.size,r)))}return o}function sl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(Xi(t)){for(a=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&D.isSelectable(f)&&i.parent&&!(f.isInline&&Kh(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new D(s==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,d=s;for(let p=0;p{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!$u(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function km(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,ve(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&Fe&&_t<=11&&(t.disabled=!0,t.disabled=!1)}function Fu(n,e){if(e instanceof D){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(su(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else su(n)}function su(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function ll(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||P.between(e,t,r)}function lu(n){return n.editable&&!n.hasFocus()?!1:Hu(n)}function Hu(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function xm(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return gn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ys(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&L.findFrom(o,e)}function jt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function au(n,e,t){let r=n.state.selection;if(r instanceof P)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return jt(n,new P(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ys(n.state,e);return i&&i instanceof D?jt(n,i):!1}else if(!(Je&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?D.isSelectable(o)?jt(n,new D(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?jt(n,new P(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof D&&r.node.isInline)return jt(n,new P(e>0?r.$to:r.$from));{let i=Ys(n.state,e);return i?jt(n,i):!1}}}function qi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Rr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Jn(n,e){return e<0?vm(n):wm(n)}function vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Ye&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Rr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Vu(t))break;{let l=t.previousSibling;for(;l&&Rr(l,-1);)i=t.parentNode,o=ve(l),l=l.previousSibling;if(l)t=l,r=qi(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Xs(n,t,r):i&&Xs(n,i,o)}function wm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=qi(t),o,s;for(;;)if(r{n.state==i&&Nt(n)},50)}function cu(n,e){let t=n.state.doc.resolve(e);if(!(we||Ou)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function uu(n,e,t){let r=n.state.selection;if(r instanceof P&&!r.empty||t.indexOf("s")>-1||Je&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ys(n.state,e);if(s&&s instanceof D)return jt(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Re?L.near(s,e):L.findFrom(s,e);return l?jt(n,l):!1}return!1}function fu(n,e){if(!(n.state.selection instanceof P))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function du(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Em(n){if(!Me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;du(n,r,"true"),setTimeout(()=>du(n,r,"false"),20)}return!1}function Tm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Mm(n,e){let t=e.keyCode,r=Tm(e);if(t==8||Je&&t==72&&r=="c")return fu(n,-1)||Jn(n,-1);if(t==46&&!e.shiftKey||Je&&t==68&&r=="c")return fu(n,1)||Jn(n,1);if(t==13||t==27)return!0;if(t==37||Je&&t==66&&r=="c"){let i=t==37?cu(n,n.state.selection.from)=="ltr"?-1:1:-1;return au(n,i,r)||Jn(n,i)}else if(t==39||Je&&t==70&&r=="c"){let i=t==39?cu(n,n.state.selection.from)=="ltr"?1:-1:1;return au(n,i,r)||Jn(n,i)}else{if(t==38||Je&&t==80&&r=="c")return uu(n,-1,r)||Jn(n,-1);if(t==40||Je&&t==78&&r=="c")return Em(n)||uu(n,1,r)||Jn(n,1);if(r==(Je?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function al(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||Ct.fromSchema(n.state.schema),l=Ku(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Uu[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let h=l.createElement(u[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,`
`);return{dom:a,text:d,slice:e}}function ju(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=!!e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,o||r,n)}),o)return l=new M(w.from(n.state.schema.text(e.replace(/\r\n?/g,`
-`))),0,0),n.someProp("transformPasted",d=>{l=d(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,h=Ct.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=Nm(t),$r&&Dm(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||St.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Mm.test(d.parentNode.nodeName)?{ignore:!0}:null}})),u)l=Rm(pu(l,+u[1],+u[2]),u[4]);else if(l=M.maxOpen(Om(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,n,a)}),l}var Mm=/^(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 Om(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&_u(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=qu(s[s.length-1],o.length));let u=Wu(l,a);s.push(u),i=i.matchType(u.type),o=a}}),s)return w.from(s)}return n}function Wu(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function _u(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function pu(n,e,t){return et})),zs.createHTML(n)):n}function Nm(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Ku().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Uu[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>""+o+">").reverse().join("")),t.innerHTML=Am(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=w.from(a.create(r[l+1],i)),o++,s++}return new M(i,o,s)}var Ie={},Pe={},Im={touchstart:!0,touchmove:!0},Qs=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Pm(n){for(let e in Ie){let t=Ie[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Bm(n,r)&&!al(n,r)&&(n.editable||!(r.type in Pe))&&t(n,r)},Im[e]?{passive:!0}:void 0)}Me&&n.dom.addEventListener("input",()=>null),Zs(n)}function Wt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Lm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Zs(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>al(n,r))})}function al(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Bm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function zm(n,e){!al(n,e)&&Ie[e.type]&&(n.editable||!(e.type in Pe))&&Ie[e.type](n,e)}Pe.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Gu(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(At&&ve&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Qn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,un(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Tm(n,t)?t.preventDefault():Wt(n,"key")};Pe.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Pe.keypress=(n,e)=>{let t=e;if(Gu(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Ke&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof P)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),o=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i,o))&&n.dispatch(o()),t.preventDefault()}};function Xi(n){return{left:n.clientX,top:n.clientY}}function $m(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function cl(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Yn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Fm(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&D.isSelectable(r)?(Yn(n,new D(t),"pointer"),!0):!1}function Hm(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof D&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(D.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Yn(n,D.create(n.state.doc,i),"pointer"),!0):!1}function Vm(n,e,t,r,i){return cl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?Hm(n,t):Fm(n,t))}function jm(n,e,t,r){return cl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Wm(n,e,t,r){return cl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||_m(n,t,r)}function _m(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Yn(n,P.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Yn(n,P.create(r,l+1,l+1+s.content.size),"pointer");else if(D.isSelectable(s))Yn(n,D.create(r,l),"pointer");else continue;return!0}}function ul(n){return qi(n)}var Ju=Ke?"metaKey":"ctrlKey";Ie.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ul(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&$m(t,n.input.lastClick)&&!t[Ju]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o,button:t.button};let s=n.posAtCoords(Xi(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new el(n,s,t,!!r)):(o=="doubleClick"?jm:Wm)(n,s.pos,s.inside,t)?t.preventDefault():Wt(n,"pointer"))};var el=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Ju],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let u=e.state.doc.resolve(t.pos);o=u.parent,s=u.depth?u.before():0}let l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;r.button==0&&(o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof D&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ge&&!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)),Wt(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(()=>Nt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Xi(e))),this.updateAllowDefault(e),this.allowDefault||!t?Wt(this.view,"pointer"):Vm(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Me&&this.mightDrag&&!this.mightDrag.node.isAtom||ve&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Yn(this.view,L.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Wt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Wt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};Ie.touchstart=n=>{n.input.lastTouch=Date.now(),ul(n),Wt(n,"pointer")};Ie.touchmove=n=>{n.input.lastTouch=Date.now(),Wt(n,"pointer")};Ie.contextmenu=n=>ul(n);function Gu(n,e){return n.composing?!0:Me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var qm=At?5e3:-1;Pe.compositionstart=Pe.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof P&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||ve&&Ou&&Um(n)))n.markCursor=n.state.storedMarks||t.marks(),qi(n,!0),n.markCursor=null;else if(qi(n,!e.selection.empty),Ge&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Yu(n,qm)};function Um(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}Pe.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Yu(n,20))};function Yu(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>qi(n),e))}function Xu(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Jm());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Km(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=_h(e.focusNode,e.focusOffset),r=qh(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function Jm(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function qi(n,e=!1){if(!(At&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Xu(n),e||n.docView&&n.docView.dirty){let t=ol(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function Gm(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Ir=Fe&&_t<15||Qn&&Gh<604;Ie.copy=Pe.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Ir?null:t.clipboardData,s=r.content(),{dom:l,text:a}=ll(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):Gm(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Ym(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Xm(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Pr(n,r.value,null,i,e):Pr(n,r.textContent,r.innerHTML,i,e)},50)}function Pr(n,e,t,r,i){let o=ju(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||M.empty)))return!0;if(!o)return!1;let s=Ym(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Qu(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Pe.paste=(n,e)=>{let t=e;if(n.composing&&!At)return;let r=Ir?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Pr(n,Qu(r),r.getData("text/html"),i,t)?t.preventDefault():Xm(n,t)};var Ui=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Qm=Ke?"altKey":"ctrlKey";function Zu(n,e){let t;return n.someProp("dragCopies",r=>{t=t||r(e)}),t!=null?!t:!e[Qm]}Ie.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(Xi(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof D?i.to-1:i.to))){if(r&&r.mightDrag)s=D.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=D.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c,slice:u}=ll(n,l);(!t.dataTransfer.files.length||!ve||Mu>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ir?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ir||t.dataTransfer.setData("text/plain",c),n.dragging=new Ui(u,Zu(n,t),s)};Ie.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Pe.dragover=Pe.dragenter=(n,e)=>e.preventDefault();Pe.drop=(n,e)=>{try{Zm(n,e,n.dragging)}finally{n.dragging=null}};function Zm(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(Xi(e));if(!r)return;let i=n.state.doc.resolve(r.pos),o=t&&t.slice;o?n.someProp("transformPasted",p=>{o=p(o,n,!1)}):o=ju(n,Qu(e.dataTransfer),Ir?null:e.dataTransfer.getData("text/html"),!1,i);let s=!!(t&&Zu(n,e));if(n.someProp("handleDrop",p=>p(n,e,o||M.empty,s))){e.preventDefault();return}if(!o)return;e.preventDefault();let l=o?Li(n.state.doc,i.pos,o):i.pos;l==null&&(l=i.pos);let a=n.state.tr;if(s){let{node:p}=t;p?p.replace(a):a.deleteSelection()}let c=a.mapping.map(l),u=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(u?a.replaceRangeWith(c,c,o.content.firstChild):a.replaceRange(c,c,o),a.doc.eq(f))return;let d=a.doc.resolve(c);if(u&&D.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new D(d));else{let p=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((h,m,g,b)=>p=b),a.setSelection(sl(n,d,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Ie.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Nt(n)},20))};Ie.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Ie.beforeinput=(n,e)=>{if(ve&&At&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,un(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Pe)Ie[n]=Pe[n];function Lr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var Ki=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new Xe(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Lr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pn=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new Xe(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==Ee||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let c=a+r,u;if(u=tf(t,l,c)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof pn){let c=Math.max(o,a.from)-o,u=Math.min(s,a.to)-o;ci.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return Te.empty;let r=[];for(let i=0;it instanceof Te)?e:e.reduce((t,r)=>t.concat(r instanceof Te?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-h-(p-d);for(let b=0;bC+u-f)continue;let v=l[b]+u-f;p>=v?l[b+1]=d<=v?-2:-1:d>=u&&g&&(l[b]+=g,l[b+1]+=g)}f+=g}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let d=t.map(n[c+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),g=r.maybeChild(h);if(g&&m==f&&m+g.nodeSize==p){let b=l[c+2].mapInner(t,g,u+1,n[c]+o+1,s);b!=Ee?(l[c]=f,l[c+1]=p,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=tg(l,n,e,t,i,o,s),u=Gi(c,r,0,s);e=u.local;for(let f=0;ft&&s.to{let c=tf(n,l,a+t);if(c){o=!0;let u=Gi(c,l,t+a+1,r);u!=Ee&&i.push(a,a+l.nodeSize,u)}});let s=ef(o?nf(n):n,-t).sort(mn);for(let l=0;l0;)e++;n.splice(e,0,t)}function $s(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=Ee&&e.push(r)}),n.cursorWrapper&&e.push(Te.create(n.state.doc,[n.cursorWrapper.deco])),Ji.from(e)}var ng={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},rg=Fe&&_t<=11,nl=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},rl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new nl,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():Me&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),rg&&(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,ng)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(lu(this.view)){if(this.suppressingSelectionUpdates)return Nt(this.view);if(Fe&&_t<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&gn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=Xn(o))t.add(o);for(let o=e.anchorNode;o;o=Xn(o))if(t.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&lu(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let u=0;uu.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of a)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){u.parentNode.removeChild(u);break}f=f.firstChild}}}else if(Ge&&a.length){let u=a.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,d]=u;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of u){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||sg(e,f)!=p)&&d.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),ig(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,lg(e,a)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Nt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;ui;g--){let b=r.childNodes[g-1],C=b.pmViewDesc;if(b.nodeName=="BR"&&!C){o=g;break}if(!C||C.size)break}let f=n.state.doc,d=n.someProp("domParser")||St.fromSchema(n.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:cg,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),h={anchor:g+s,head:b+s}}return{doc:m,sel:h,from:s,to:l}}function cg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||Me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var ug=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function fg(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let S=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,A=ol(n,S);if(A&&!n.state.selection.eq(A)){if(ve&&At&&n.input.lastKeyCode===13&&Date.now()-100H(n,un(13,"Enter"))))return;let R=n.state.tr.setSelection(A);S=="pointer"?R.setMeta("pointer",!0):S=="key"&&R.scrollIntoView(),o&&R.setMeta("composition",o),n.dispatch(R)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=ag(n,e,t),u=n.state.doc,f=u.slice(c.from,c.to),d,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||At)&&i.some(S=>S.nodeType==1&&!ug.test(S.nodeName))&&(!h||h.endA>=h.endB)&&n.someProp("handleKeyDown",S=>S(n,un(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof P&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let S=ku(n,n.state.doc,c.sel);if(S&&!S.eq(n.state.selection)){let A=n.state.tr.setSelection(S);o&&A.setMeta("composition",o),n.dispatch(A)}}return}n.state.selection.fromn.state.selection.from&&h.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?h.start=n.state.selection.from:h.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(h.endB+=n.state.selection.to-h.endA,h.endA=n.state.selection.to)),Fe&&_t<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),b=u.resolve(h.start),C=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=h.endA;if((Qn&&n.input.lastIOSEnter>Date.now()-225&&(!C||i.some(S=>S.nodeName=="DIV"||S.nodeName=="P"))||!C&&m.posS(n,un(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>h.start&&pg(u,h.start,h.endA,m,g)&&n.someProp("handleKeyDown",S=>S(n,un(8,"Backspace")))){At&&ve&&n.domObserver.suppressSelectionUpdates();return}ve&&h.endB==h.start&&(n.input.lastChromeDelete=Date.now()),At&&!C&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(S){return S(n,un(13,"Enter"))})},20));let v=h.start,y=h.endA,T=S=>{let A=S||n.state.tr.replace(v,y,c.doc.slice(h.start-c.from,h.endB-c.from));if(c.sel){let R=ku(n,A.doc,c.sel);R&&!(ve&&n.composing&&R.empty&&(h.start!=h.endB||n.input.lastChromeDeleteNt(n),20));let S=T(n.state.tr.delete(v,y)),A=u.resolve(h.start).marksAcross(u.resolve(h.endA));A&&S.ensureMarks(A),n.dispatch(S)}else if(h.endA==h.endB&&(x=dg(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,h.endA-b.start())))){let S=T(n.state.tr);x.type=="add"?S.addMark(v,y,x.mark):S.removeMark(v,y,x.mark),n.dispatch(S)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let S=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>T(n.state.tr.insertText(S,v,y));n.someProp("handleTextInput",R=>R(n,v,y,S,A))||n.dispatch(A())}else n.dispatch(T());else n.dispatch(T())}function ku(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:sl(n,e.resolve(t.anchor),e.resolve(t.head))}function dg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let u=0;uu.mark(l.addToSet(u.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;ut||Fs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function hg(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var Br=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Qs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Eu),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Su(this),wu(this),this.nodeViews=Cu(this),this.docView=tu(this.state.doc,vu(this),$s(this),this.dom,this),this.domObserver=new rl(this,(r,i,o,s)=>fg(this,r,i,o,s)),this.domObserver.start(),Pm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Zs(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Eu),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(Xu(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Cu(this);gg(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Zs(this),this.editable=Su(this),wu(this);let a=$s(this),c=vu(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&Qh(this);if(s){this.domObserver.stop();let p=f&&(Fe||ve)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&mg(i.selection,e.selection);if(f){let h=ve?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Km(this)),(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=tu(e.doc,c,a,this.dom,this)),h&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&km(this))?Nt(this,p):(Fu(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():d&&Zh(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof D){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Gc(this,t.getBoundingClientRect(),e)}else Gc(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return om(this,e)}coordsAtPos(e,t=1){return Iu(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return um(this,t||this.state,e)}pasteHTML(e,t){return Pr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Pr(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ll(this,e)}destroy(){this.docView&&(Lm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],$s(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,jh())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return zm(this,e)}domSelectionRange(){let e=this.domSelection();return e?Me&&this.root.nodeType===11&&Kh(this.dom.ownerDocument)==this.dom&&og(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Br.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function vu(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[Xe.node(0,n.state.doc.content.size,e)]}function wu(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Xe.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Su(n){return!n.someProp("editable",e=>e(n.state)===!1)}function mg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Cu(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function gg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Eu(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Dt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Zi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},yg=typeof navigator<"u"&&/Mac/.test(navigator.platform),bg=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(ue=0;ue<10;ue++)Dt[48+ue]=Dt[96+ue]=String(ue);var ue;for(ue=1;ue<=24;ue++)Dt[ue+111]="F"+ue;var ue;for(ue=65;ue<=90;ue++)Dt[ue]=String.fromCharCode(ue+32),Zi[ue]=String.fromCharCode(ue);var ue;for(Qi in Dt)Zi.hasOwnProperty(Qi)||(Zi[Qi]=Dt[Qi]);var Qi;function rf(n){var e=yg&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||bg&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Zi:Dt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var kg=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),xg=typeof navigator<"u"&&/Win/.test(navigator.platform);function vg(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;ln.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function lf(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var ml=(n,e,t)=>{let r=lf(n,t);if(!r)return!1;let i=yl(r);if(!i){let s=r.blockRange(),l=s&&Tt(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(gf(n,i,e,-1))return!0;if(r.parent.content.size==0&&(er(o,"end")||D.isSelectable(o)))for(let s=r.depth;;s--){let l=Or(n.doc,r.before(s),r.after(s),M.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1},af=(n,e,t)=>{let r=lf(n,t);if(!r)return!1;let i=yl(r);return i?uf(n,i,e):!1},cf=(n,e,t)=>{let r=ff(n,t);if(!r)return!1;let i=xl(r);return i?uf(n,i,e):!1};function uf(n,e,t){let r=e.nodeBefore,i=r,o=e.pos-1;for(;!i.isTextblock;o--){if(i.type.spec.isolating)return!1;let u=i.lastChild;if(!u)return!1;i=u}let s=e.nodeAfter,l=s,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let c=Or(n.doc,o,a,M.empty);if(!c||c.from!=o||c instanceof ke&&c.slice.size>=a-o)return!1;if(t){let u=n.tr.step(c);u.setSelection(P.create(u.doc,o)),t(u.scrollIntoView())}return!0}function er(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var gl=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=yl(r)}let s=o&&o.nodeBefore;return!s||!D.isSelectable(s)?!1:(e&&e(n.tr.setSelection(D.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function yl(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function ff(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=ff(n,t);if(!r)return!1;let i=xl(r);if(!i)return!1;let o=i.nodeAfter;if(gf(n,i,e,1))return!0;if(r.parent.content.size==0&&(er(o,"start")||D.isSelectable(o))){let s=Or(n.doc,r.before(),r.after(),M.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof D,i;if(r){if(t.node.isTextblock||!ot(n.doc,t.from))return!1;i=t.from}else if(i=qn(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(D.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},pf=(n,e)=>{let t=n.selection,r;if(t instanceof D){if(t.node.isTextblock||!ot(n.doc,t.to))return!1;r=t.to}else if(r=qn(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},hf=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),o=i&&Tt(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},vl=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
-`).scrollIntoView()),!0)};function wl(n){for(let e=0;e