/* esm.sh - prosemirror-view@1.42.8 */
import{TextSelection as x,NodeSelection as S,Selection as pe,AllSelection as Bn}from"../../../prosemirror-state@^1.0.0?deps=prosemirror-model@1.25.12&target=es2022";import{DOMSerializer as Ke,Fragment as G,Mark as In,Slice as le,DOMParser as vt}from"../../../prosemirror-model@1.25.12/es2022/prosemirror-model.mjs";import{dropPoint as Fn}from"../../../prosemirror-transform@^1.1.0?deps=prosemirror-model@1.25.12&target=es2022";var O=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},me=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},Ye=null,W=function(t,e,n){let o=Ye||(Ye=document.createRange());return o.setEnd(t,n??t.nodeValue.length),o.setStart(t,e||0),o},Ln=function(){Ye=null},ae=function(t,e,n,o){return n&&(Ot(t,e,n,o,-1)||Ot(t,e,n,o,1))},zn=/^(img|br|input|textarea|hr)$/i;function Ot(t,e,n,o,i){for(var s;;){if(t==n&&e==o)return!0;if(e==(i<0?0:T(t))){let r=t.parentNode;if(!r||!b(r)||Te(t)||zn.test(t.nodeName)||t.contentEditable=="false")return!1;e=O(t)+(i<0?0:1),t=r}else if(b(t)){let r=t.childNodes[e+(i<0?-1:0)];if(b(r)&&r.contentEditable=="false")if(!((s=r.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else t=r,e=i<0?T(t):0}else return!1}}function T(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function b(t){return t.nodeType==1}function N(t){return t.nodeType==3}function ce(t,e){return e?t.contains(b(e)?e:e.parentNode):!1}function $n(t,e){for(;;){if(N(t)&&e)return t;if(b(t)&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=T(t)}else if(t.parentNode&&!Te(t))e=O(t),t=t.parentNode;else return null}}function qn(t,e){for(;;){if(N(t)&&e<t.nodeValue.length)return t;if(b(t)&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e],e=0}else if(t.parentNode&&!Te(t))e=O(t)+1,t=t.parentNode;else return null}}function Kn(t,e,n){for(let o=e==0,i=e==T(t);o||i;){if(t==n)return!0;let s=O(t);if(t=t.parentNode,!t)return!1;o=o&&s==0,i=i&&s==T(t)}}function Te(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}var He=function(t){return t.focusNode&&ae(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function ee(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function Hn(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Wn(t,e,n){if(t.caretPositionFromPoint)try{let o=t.caretPositionFromPoint(e,n);if(o)return{node:o.offsetNode,offset:Math.min(T(o.offsetNode),o.offset)}}catch{}if(t.caretRangeFromPoint){let o=t.caretRangeFromPoint(e,n);if(o)return{node:o.startContainer,offset:Math.min(T(o.startContainer),o.startOffset)}}}var K=typeof navigator<"u"?navigator:null,xt=typeof document<"u"?document:null,w=K&&K.userAgent||"",Xe=/Edge\/(\d+)/.exec(w),en=/MSIE \d/.exec(w),Je=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(w),I=!!(en||Je||Xe),J=en?document.documentMode:Je?+Je[1]:Xe?+Xe[1]:0,F=!I&&/gecko\/(\d+)/i.test(w);F&&+(/Firefox\/(\d+)/.exec(w)||[0,0])[1];var Ze=!I&&/Chrome\/(\d+)/.exec(w),M=!!Ze,tn=Ze?+Ze[1]:0,A=!I&&!!K&&/Apple Computer/.test(K.vendor),ge=A&&(/Mobile\/\w+/.test(w)||!!K&&K.maxTouchPoints>2),L=ge||(K?/Mac/.test(K.platform):!1),nn=K?/Win/.test(K.platform):!1,_=/Android \d/.test(w),We=!!xt&&"webkitFontSmoothing"in xt.documentElement.style,_n=We?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Un(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 H(t,e){return typeof t=="number"?t:t[e]}function jn(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,o=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*o}}function Mt(t,e,n){if(!Qe(e)&&e.left==0)return;let o=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let r=n||t.dom;r;){if(!b(r)){r=me(r);continue}let l=r==s.body,a=l?Un(s):jn(r),d=0,c=0;if(e.top<a.top+H(o,"top")?c=-(a.top-e.top+H(i,"top")):e.bottom>a.bottom-H(o,"bottom")&&(c=e.bottom-e.top>a.bottom-a.top?e.top+H(i,"top")-a.top:e.bottom-a.bottom+H(i,"bottom")),e.left<a.left+H(o,"left")?d=-(a.left-e.left+H(i,"left")):e.right>a.right-H(o,"right")&&(d=e.right-a.right+H(i,"right")),d||c)if(l)s.defaultView.scrollBy(d,c);else{let u=r.scrollLeft,p=r.scrollTop;c&&(r.scrollTop+=c),d&&(r.scrollLeft+=d);let h=r.scrollLeft-u,g=r.scrollTop-p;e={left:e.left-h,top:e.top-g,right:e.right-h,bottom:e.bottom-g}}let f=l?"fixed":getComputedStyle(r).position;if(/^(fixed|sticky)$/.test(f))break;r=f=="absolute"?r.offsetParent:me(r)}}function Gn(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),o,i;for(let s=(e.left+e.right)/2,r=n+1;r<Math.min(innerHeight,e.bottom);r+=5){let l=t.root.elementFromPoint(s,r);if(!l||l==t.dom||!t.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=n-20){o=l,i=a.top;break}}return{refDOM:o,refTop:i,stack:on(t.dom)}}function on(t){let e=[],n=t.ownerDocument;for(let o=t;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),t!=n);o=me(o));return e}function Yn({refDOM:t,refTop:e,stack:n}){let o=t?t.getBoundingClientRect().top:0;sn(n,o==0?0:o-e)}function sn(t,e){for(let n=0;n<t.length;n++){let{dom:o,top:i,left:s}=t[n];o.scrollTop!=i+e&&(o.scrollTop=i+e),o.scrollLeft!=s&&(o.scrollLeft=s)}}var fe=null;function Xn(t){if(t.setActive)return t.setActive();if(fe)return t.focus(fe);let e=on(t);t.focus(fe==null?{get preventScroll(){return fe={preventScroll:!0},!0}}:void 0),fe||(fe=!1,sn(e,0))}function rn(t,e){let n,o=2e8,i,s=0,r=e.top,l=e.top,a,d;for(let c=t.firstChild,f=0;c;c=c.nextSibling,f++){let u;if(b(c))u=c.getClientRects();else if(N(c))u=W(c).getClientRects();else continue;for(let p=0;p<u.length;p++){let h=u[p];if(h.top<=r&&h.bottom>=l){r=Math.max(h.bottom,r),l=Math.min(h.top,l);let g=h.left>e.left?h.left-e.left:h.right<e.left?e.left-h.right:0;if(g<o){n=c,o=g,i=g&&N(n)?{left:h.right<e.left?h.right:h.left,top:e.top}:e,b(c)&&g&&(s=f+(e.left>=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,d={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=f+1)}}return!n&&a&&(n=a,i=d,o=0),n&&N(n)?Jn(n,i):!n||o?{node:t,offset:s}:rn(n,i)}function Jn(t,e){let n=t.nodeValue.length,o=document.createRange(),i;for(let s=0;s<n;s++){o.setEnd(t,s+1),o.setStart(t,s);let r=Y(o,1);if(r.top!=r.bottom&&pt(e,r)){i={node:t,offset:s+(e.left>=(r.left+r.right)/2?1:0)};break}}return o.detach(),i||{node:t,offset:0}}function pt(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function Zn(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left<t.getBoundingClientRect().left?n:t}function Qn(t,e,n){let{node:o,offset:i}=rn(e,n),s=-1;if(b(o)&&!o.firstChild){let r=o.getBoundingClientRect();s=r.left!=r.right&&n.left>(r.left+r.right)/2?1:-1}return t.docView.posFromDOM(o,i,s)}function wn(t,e,n,o){let i=-1;for(let s=e,r=!1;s!=t.dom;){let l=t.docView.nearestDesc(s,!0),a;if(!l)return null;if(b(l.dom)&&(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)&&(!r&&a.left>o.left||a.top>o.top?i=l.posBefore:(!r&&a.right<o.left||a.bottom<o.top)&&(i=l.posAfter),r=!0),!l.contentDOM&&i<0&&!l.node.isText))return(l.node.isBlock?o.top<(a.top+a.bottom)/2:o.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return i>-1?i:t.docView.posFromDOM(e,n,-1)}function ln(t,e,n){let o=t.childNodes.length;if(o&&n.top<n.bottom)for(let i=Math.max(0,Math.min(o-1,Math.floor(o*(e.top-n.top)/(n.bottom-n.top))-2)),s=i;;){let r=t.childNodes[s];if(b(r)){let l=r.getClientRects();for(let a=0;a<l.length;a++){let d=l[a];if(pt(e,d))return ln(r,e,d)}}if((s=(s+1)%o)==i)break}return t}function vn(t,e){let n=t.dom.ownerDocument,o,i=0,s=Wn(n,e.left,e.top);s&&({node:o,offset:i}=s);let r=(t.root.elementFromPoint?t.root:n).elementFromPoint(e.left,e.top),l;if(!r||!t.dom.contains(r)){let d=t.dom.getBoundingClientRect();if(!pt(e,d)||(r=ln(t.dom,e,d),!r))return null}if(A)for(let d=r;o&&d;d=me(d))d.draggable&&(o=void 0);if(r=Zn(r,e),o){if(F&&b(o)&&(i=Math.min(i,o.childNodes.length),i<o.childNodes.length)){let c=o.childNodes[i],f;c.nodeName=="IMG"&&(f=c.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&i++}let d;We&&i&&b(o)&&b(d=o.childNodes[i-1])&&d.contentEditable=="false"&&d.getBoundingClientRect().top>=e.top&&i--,o==t.dom&&i==o.childNodes.length-1&&b(o.lastChild)&&e.top>o.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||!b(o)||o.childNodes[i-1].nodeName!="BR")&&(l=wn(t,o,i,e))}l==null&&(l=Qn(t,r,e));let a=t.docView.nearestDesc(r,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Qe(t){return t.top<t.bottom||t.left<t.right}function Y(t,e){let n=t.getClientRects();if(n.length){let o=n[e<0?0:n.length-1];if(Qe(o))return o}return Array.prototype.find.call(n,Qe)||t.getBoundingClientRect()}var eo=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function an(t,e,n){let{node:o,offset:i,atom:s}=t.docView.domFromPos(e,n<0?-1:1),r=We||F;if(N(o))if(r&&(eo.test(o.nodeValue)||(n<0?!i:i==o.nodeValue.length))){let a=Y(W(o,i,i),n);if(F&&i&&/\s/.test(o.nodeValue[i-1])&&i<o.nodeValue.length){let d=Y(W(o,i-1,i-1),-1);if(d.top==a.top){let c=Y(W(o,i,i+1),-1);if(c.top!=a.top)return ye(c,c.left<d.left)}}return a}else{let a=i,d=i,c=n<0?1:-1;return n<0&&!i?(d++,c=-1):n>=0&&i==o.nodeValue.length?(a--,c=1):n<0?a--:d++,ye(Y(W(o,a,d),c),c<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(n<0||i==T(o))){let a=o.childNodes[i-1];if(b(a))return _e(a.getBoundingClientRect(),!1)}if(s==null&&i<T(o)){let a=o.childNodes[i];if(b(a))return _e(a.getBoundingClientRect(),!0)}return _e(o.getBoundingClientRect(),n>=0)}if(s==null&&i&&(n<0||i==T(o))){let a=o.childNodes[i-1],d=N(a)?W(a,T(a)-(r?0:1)):b(a)&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(d)return ye(Y(d,1),!1)}if(s==null&&i<T(o)){let a=o.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let d=a?N(a)?W(a,0,r?0:1):b(a)?a:null:null;if(d)return ye(Y(d,-1),!0)}return ye(Y(N(o)?W(o):o,-n),n>=0)}function ye(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 _e(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 cn(t,e,n){let o=t.state,i=t.root.activeElement;o!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{o!=e&&t.updateState(o),i!=t.dom&&i&&i.focus()}}function to(t,e,n){let o=e.selection,i=n=="up"?o.$from:o.$to;return cn(t,e,()=>{let{node:s}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let r=an(t,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(b(l))a=l.getClientRects();else if(N(l))a=W(l,0,l.nodeValue.length).getClientRects();else continue;for(let d=0;d<a.length;d++){let c=a[d];if(c.bottom>c.top+1&&(n=="up"?r.top-c.top>(c.bottom-r.top)*2:c.bottom-r.bottom>(r.bottom-c.top)*2))return!1}}return!0})}var no=/[\u0590-\u08ac]/;function oo(t,e,n){let{$head:o}=e.selection;if(!o.parent.isTextblock)return!1;let i=o.parentOffset,s=!i,r=i==o.parent.content.size,l=t.domSelection();return l?!no.test(o.parent.textContent)||!l.modify?n=="left"||n=="backward"?s:r:cn(t,e,()=>{let{focusNode:a,focusOffset:d,anchorNode:c,anchorOffset:f}=t.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",n,"character");let p=o.depth?t.docView.domAfterPos(o.before()):t.dom,{focusNode:h,focusOffset:g}=t.domSelectionRange(),m=h&&!ce(p,h)||a==h&&d==g;try{l.collapse(c,f),a&&(a!=c||d!=f)&&l.extend&&l.extend(a,d)}catch{}return u!=null&&(l.caretBidiLevel=u),m}):o.pos==o.start()||o.pos==o.end()}var kt=null,Tt=null,At=!1;function io(t,e,n){return kt==e&&Tt==n?At:(kt=e,Tt=n,At=n=="up"||n=="down"?to(t,e,n):oo(t,e,n))}var z=0,Et=1,te=2,q=3,de=class{constructor(e,n,o,i){this.parent=e,this.children=n,this.dom=o,this.contentDOM=i,this.dirty=z,o.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,o){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n<this.children.length;n++)e+=this.children[n].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let n=0,o=this.posAtStart;;n++){let i=this.children[n];if(i==e)return o;o+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,n,o){if(this.contentDOM&&ce(this.contentDOM,e))if(o<0){let s,r;if(e==this.contentDOM)s=e.childNodes[n-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((r=s.pmViewDesc)&&r.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(r)+r.size:this.posAtStart}else{let s,r;if(e==this.contentDOM)s=e.childNodes[n];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((r=s.pmViewDesc)&&r.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(r):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=n>O(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let s=e.compareDocumentPosition(this.contentDOM);s&16?i=n>Array.from(e.childNodes).findIndex(r=>r.contains(this.contentDOM)):i=!(s&4)}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??o>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let o=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),r;if(s&&(!n||s.node))if(o&&(r=s.nodeDOM)&&!(b(r)?ce(r,e):r==e))o=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let o=n;o;o=o.parent)if(o==this)return n}posFromDOM(e,n,o){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,n,o)}return-1}descAt(e){for(let n=0,o=0;n<this.children.length;n++){let i=this.children[n],s=o+i.size;if(o==e&&s!=o){for(;!i.border&&i.children.length;)for(let r=0;r<i.children.length;r++){let l=i.children[r];if(l.size){i=l;break}}return i}if(e<s)return i.descAt(e-o-i.border);o=s}}domFromPos(e,n){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let o=0,i=0;for(let s=0;o<this.children.length;o++){let r=this.children[o],l=s+r.size;if(l>e){i=e-s;break}s=l}if(i)return this.children[o].domFromPos(i-this.children[o].border,n);for(;o>0;o--){let s=this.children[o-1];if(s.size||!(s instanceof Be||s instanceof Ve&&s.side>=0))break}if(n<=0){let s,r=!0;for(;s=o?this.children[o-1]:null,!(!s||s.dom.parentNode==this.contentDOM);o--,r=!1);return s&&n&&r&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?O(s.dom)+1:0}}else{let s,r=!0;for(;s=o<this.children.length?this.children[o]:null,!(!s||s.dom.parentNode==this.contentDOM);o++,r=!1);return s&&r&&!s.border&&!s.domAtom?s.domFromPos(0,n):{node:this.contentDOM,offset:s?O(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,n,o=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:n,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let r=o,l=0;;l++){let a=this.children[l],d=r+a.size;if(i==-1&&e<=d){let c=r+a.border;if(e>=c&&n<=d-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=r;for(let f=l;f>0;f--){let u=this.children[f-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=O(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(d>n||l==this.children.length-1)){n=d;for(let c=l+1;c<this.children.length;c++){let f=this.children[c];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=O(f.dom);break}n+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}r=d}return{node:this.contentDOM,from:e,to:n,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let n=this.children[e<0?0:this.children.length-1];return n.size==0||n.emptyChildAt(e)}domAfterPos(e){let{node:n,offset:o}=this.domFromPos(e,0);if(!b(n)||o==n.childNodes.length)throw new RangeError("No node after pos "+e);return n.childNodes[o]}setSelection(e,n,o,i=!1){let s=Math.min(e,n),r=Math.max(e,n);for(let p=0,h=0;p<this.children.length;p++){let g=this.children[p],m=h+g.size;if(s>h&&r<m)return g.setSelection(e-h-g.border,n-h-g.border,o,i);h=m}let l=this.domFromPos(e,e?-1:1),a=n==e?l:this.domFromPos(n,n?-1:1),d=o.root.getSelection(),c=o.domSelectionRange(),f=!1;if((F||A)&&e==n){let{node:p,offset:h}=l;if(N(p)){if(f=!!(h&&p.nodeValue[h-1]==`
`),f&&h==p.nodeValue.length)for(let g=p,m;g;g=g.parentNode){if(m=g.nextSibling){m.nodeName=="BR"&&(l=a={node:m.parentNode,offset:O(m)+1});break}let y=g.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let g=p.childNodes[h-1];f=g&&(g.nodeName=="BR"||g.contentEditable=="false")}}if(F&&c.focusNode&&c.focusNode!=a.node&&b(c.focusNode)){let p=c.focusNode.childNodes[c.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||f&&A)&&ae(l.node,l.offset,c.anchorNode,c.anchorOffset)&&ae(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((d.extend||e==n)&&!(f&&F)){d.collapse(l.node,l.offset);try{e!=n&&d.extend(a.node,a.offset),u=!0}catch{}}if(!u){if(e>n){let h=l;l=a,a=h}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),d.removeAllRanges(),d.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,n){for(let o=0,i=0;i<this.children.length;i++){let s=this.children[i],r=o+s.size;if(o==r?e<=r&&n>=o:e<r&&n>o){let l=o+s.border,a=r-s.border;if(e>=l&&n<=a){this.dirty=e==o||n==r?te:Et,e==l&&n==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=q:s.markDirty(e-l,n-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?te:q}o=r}this.dirty=te}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let o=e==1?te:Et;n.dirty<o&&(n.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},Ve=class extends de{constructor(e,n,o,i){let s,r=n.type.toDOM;if(typeof r=="function"&&(r=r(o,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){let l=b(r)?r:document.createElement("span");l!=r&&(l.appendChild(r),r=l),l.hasAttribute("contenteditable")||(l.contentEditable="false"),l.classList.add("ProseMirror-widget")}super(e,[],r,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==z&&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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},we=class extends de{constructor(e,n,o,i){super(e,[],n,null),this.textDOM=o,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}},oe=class t extends de{constructor(e,n,o,i,s){super(e,[],o,i),this.mark=n,this.spec=s}static create(e,n,o,i){let s=i.nodeViews[n.type.name],r=s&&s(n,i,o);return(!r||!r.dom)&&(r=Ke.renderSpec(document,n.type.spec.toDOM(n,o),null,n.attrs)),new t(e,n,r.dom,r.contentDOM||r.dom,r)}parseRule(){return this.dirty&q||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=q&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=z){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=z}}slice(e,n,o){let i=t.create(this.parent,this.mark,!0,o),s=this.children,r=this.size;n<r&&(s=nt(s,n,r,o)),e>0&&(s=nt(s,0,e,o));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},Z=class t extends de{constructor(e,n,o,i,s,r,l){super(e,[],s,r),this.node=n,this.outerDeco=o,this.innerDeco=i,this.nodeDOM=l}static create(e,n,o,i,s,r){let l=s.nodeViews[n.type.name],a,d=l&&l(n,s,()=>{if(!a)return r;if(a.parent)return a.parent.posBeforeChild(a)},o,i),c=d&&d.dom,f=d&&d.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(!N(c))throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=Ke.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let u=c;return c=hn(c,o,n),d?a=new ve(e,n,o,i,c,f||null,u,d):n.isText?new Re(e,n,o,i,c,u):new t(e,n,o,i,c,f||null,u)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let n={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(n.preserveWhitespace="full"),!this.contentDOM)n.getContent=()=>this.node.content;else if(!this.contentLost)n.contentElement=this.contentDOM;else{for(let o=this.children.length-1;o>=0;o--){let i=this.children[o];if(this.dom.contains(i.dom.parentNode)){n.contentElement=i.dom.parentNode;break}}if(!n.contentElement){let o=e&&e.find(i=>b(i)&&e.indexOf(i.parentNode)<0&&this.dom.contains(i));o?n.contentElement=o:n.getContent=()=>G.empty}}return n}matchesNode(e,n,o){return this.dirty==z&&e.eq(this.node)&&Ie(n,this.outerDeco)&&o.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let o=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,r=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new tt(this,r&&r.node,e),d=this.node.inlineContent,c=d&&this.node.isBlock;ao(this.node,this.innerDeco,(f,u,p)=>{f.spec.marks?a.syncToMarks(f.spec.marks,o,e,u):f.type.side>=0&&!p&&a.syncToMarks(u==this.node.childCount?In.none:this.node.child(u).marks,o,e,u),a.placeWidget(f,e,i)},(f,u,p,h)=>{a.syncToMarks(f.marks,o,e,h),c&&f.isAtom&&!f.isText&&a.addHackNode("IMG",a.top);let g;a.findNodeMatch(f,u,p,h)||l&&e.state.selection.from>i&&e.state.selection.to<i+f.nodeSize&&(g=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(f,u,p,g,e)||a.updateNextNode(f,u,p,e,h,i)||a.addNode(f,u,p,e,i),i+=f.nodeSize,d&&(c=f.isAtom&&!f.isText)}),a.syncToMarks([],o,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==te)&&(r&&this.protectLocalComposition(e,r),dn(this.contentDOM,this.children,e),ge&&co(this.dom))}localCompositionInfo(e,n){let{from:o,to:i}=e.state.selection;if(!(e.state.selection instanceof x)||o<n||i>n+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 r=s.nodeValue,l=fo(this.node.content,r,o-n,i-n);return l<0?null:{node:s,pos:l,text:r}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:o,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 r=new we(this,s,n,i);e.input.compositionNodes.push(r),this.children=nt(this.children,o,o+i.length,e,r)}update(e,n,o,i){return this.dirty==q||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,o,i),!0)}updateInner(e,n,o,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=o,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=z}updateOuterDeco(e){if(Ie(e,this.outerDeco))return;let n=!b(this.nodeDOM),o=this.dom;this.dom=fn(this.dom,this.nodeDOM,et(this.outerDeco,this.node,n),et(e,this.node,n)),this.dom!=o&&(o.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){b(this.nodeDOM)&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){b(this.nodeDOM)&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Pt(t,e,n,o,i){hn(o,e,t);let s=new Z(void 0,t,e,n,o,o,o);return s.contentDOM&&s.updateChildren(i,0),s}var Re=class t extends Z{constructor(e,n,o,i,s,r){super(e,n,o,i,s,null,r)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,o,i){return this.dirty==q||this.dirty!=z&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=z||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=z,!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,o){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,o)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,o){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new t(this.parent,i,this.outerDeco,this.innerDeco,s,s)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=q)}get domAtom(){return!1}isText(e){return this.node.text==e}},Be=class extends de{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==z&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},ve=class extends Z{constructor(e,n,o,i,s,r,l,a){super(e,n,o,i,s,r,l),this.spec=a}update(e,n,o,i){if(this.dirty==q)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,o);return s&&this.updateInner(e,n,o,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,o,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,o,i){this.spec.setSelection?this.spec.setSelection(e,n,o.root):super.setSelection(e,n,o,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 dn(t,e,n){let o=t.firstChild,i=!1;for(let s=0;s<e.length;s++){let r=e[s],l=r.dom;if(l.parentNode==t){for(;l!=o;)o=Vt(o),i=!0;o=o.nextSibling}else i=!0,t.insertBefore(l,o);if(r instanceof oe){let a=o?o.previousSibling:t.lastChild;dn(r.contentDOM,r.children,n),o=a?a.nextSibling:t.firstChild}}for(;o;)o=Vt(o),i=!0;i&&n.trackWrites==t&&(n.trackWrites=null)}var Se=function(t){t&&(this.nodeName=t)};Se.prototype=Object.create(null);var ne=[new Se];function et(t,e,n){if(t.length==0)return ne;let o=n?ne[0]:new Se,i=[o];for(let s=0;s<t.length;s++){let r=t[s].type.attrs;if(r){r.nodeName&&i.push(o=new Se(r.nodeName));for(let l in r){let a=r[l];a!=null&&(n&&i.length==1&&i.push(o=new Se(e.isInline?"span":"div")),l=="class"?o.class=(o.class?o.class+" ":"")+a:l=="style"?o.style=(o.style?o.style+";":"")+a:l!="nodeName"&&(o[l]=a))}}}return i}function fn(t,e,n,o){if(n==ne&&o==ne)return e;let i=e;for(let s=0;s<o.length;s++){let r=o[s],l=n[s];if(s){let a;l&&l.nodeName==r.nodeName&&i!=t&&(a=i.parentNode)&&a.nodeName.toLowerCase()==r.nodeName||(a=document.createElement(r.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=ne[0]),i=a}so(i,l||ne[0],r)}return i}function so(t,e,n){for(let o in e)o!="class"&&o!="style"&&o!="nodeName"&&!(o in n)&&t.removeAttribute(o);for(let o in n)o!="class"&&o!="style"&&o!="nodeName"&&n[o]!=e[o]&&t.setAttribute(o,n[o]);if(e.class!=n.class){let o=e.class?e.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let s=0;s<o.length;s++)i.indexOf(o[s])==-1&&t.classList.remove(o[s]);for(let s=0;s<i.length;s++)o.indexOf(i[s])==-1&&t.classList.add(i[s]);t.classList.length==0&&t.removeAttribute("class")}if(e.style!=n.style){if(e.style){let o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=o.exec(e.style);)t.style.removeProperty(i[1])}n.style&&(t.style.cssText+=n.style)}}function hn(t,e,n){return fn(t,t,ne,et(e,n,!b(t)))}function Ie(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].type.eq(e[n].type))return!1;return!0}function Vt(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var tt=class{constructor(e,n,o){this.lock=n,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=ro(e.node.content,e)}destroyBetween(e,n){if(e!=n){for(let o=e;o<n;o++)this.top.children[o].destroy();this.top.children.splice(e,n-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,n,o,i){let s=0,r=this.stack.length>>1,l=Math.min(r,e.length);for(;s<l&&(s==r-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<r;)this.destroyRest(),this.top.dirty=z,this.index=this.stack.pop(),this.top=this.stack.pop(),r--;for(;r<e.length;){this.stack.push(this.top,this.index+1);let a=-1,d=this.top.children.length;i<this.preMatch.index&&(d=Math.min(this.index+3,d));for(let c=this.index;c<d;c++){let f=this.top.children[c];if(f.matchesMark(e[r])&&!this.isLocked(f.dom)){a=c;break}}if(a<0&&this.index<this.top.children.length){let c=this.top.children[this.index];c instanceof oe&&c.dirty!=q&&c.mark.type==e[r].type&&c.spec.update&&!this.isLocked(c.dom)&&c.spec.update(e[r])&&(c.mark=e[r],a=this.index,this.changed=!0)}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let c=oe.create(this.top,e[r],n,o);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,r++}}findNodeMatch(e,n,o,i){let s=-1,r;if(i>=this.preMatch.index&&(r=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&r.matchesNode(e,n,o))s=this.top.children.indexOf(r,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let d=this.top.children[l];if(d.matchesNode(e,n,o)&&!this.preMatch.matched.has(d)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,n,o,i,s){let r=this.top.children[i];return r.dirty==q&&r.dom==r.contentDOM&&(r.dirty=te),r.update(e,n,o,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let n=e.parentNode;if(!n)return-1;if(n==this.top.contentDOM){let o=e.pmViewDesc;if(o){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==o)return i}return-1}e=n}}updateNextNode(e,n,o,i,s,r){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Z){let d=this.preMatch.matched.get(a);if(d!=null&&d!=s)return!1;let c=a.dom,f,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=q&&Ie(n,a.outerDeco));if(!u&&a.update(e,n,o,i))return this.destroyBetween(this.index,l),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(f=this.recreateWrapper(a,e,n,o,i,r)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=te,f.updateChildren(i,r+1),f.dirty=z),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,n,o,i,s,r){if(e.dirty||n.isAtom||!e.children.length||!e.node.content.eq(n.content)||!Ie(o,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Z.create(this.top,n,o,i,s,r);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,n,o,i,s){let r=Z.create(this.top,e,n,o,i,s);r.contentDOM&&r.updateChildren(i,s+1),this.top.children.splice(this.index++,0,r),this.changed=!0}placeWidget(e,n,o){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new Ve(this.top,e,n,o);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],n=this.top;for(;e instanceof oe;)n=e,e=n.children[n.children.length-1];(!e||!(e instanceof Re)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((A||M)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",n),this.addHackNode("BR",this.top))}addHackNode(e,n){if(n==this.top&&this.index<n.children.length&&n.children[this.index].matchesHack(e))this.index++;else{let o=document.createElement(e);e=="IMG"&&(o.className="ProseMirror-separator",o.alt=""),e=="BR"&&(o.className="ProseMirror-trailingBreak");let i=new Be(this.top,[],o,null);n!=this.top?n.children.push(i):n.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||b(e)&&e.contains(this.lock.parentNode))}};function ro(t,e){let n=e,o=n.children.length,i=t.childCount,s=new Map,r=[];e:for(;i>0;){let l;for(;;)if(o){let d=n.children[o-1];if(d instanceof oe)n=d,o=d.children.length;else{l=d,o--;break}}else{if(n==e)break e;o=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(i-1))break;--i,s.set(l,i),r.push(l)}}return{index:i,matched:s,matches:r.reverse()}}function lo(t,e){return t.type.side-e.type.side}function ao(t,e,n,o){let i=e.locals(t),s=0;if(i.length==0){for(let d=0;d<t.childCount;d++){let c=t.child(d);o(c,i,e.forChild(s,c),d),s+=c.nodeSize}return}let r=0,l=[],a=null;for(let d=0;;){let c,f;for(;r<i.length&&i[r].to==s;){let m=i[r++];m.widget&&(c?(f||(f=[c])).push(m):c=m)}if(c)if(f){f.sort(lo);for(let m=0;m<f.length;m++)n(f[m],d,!!a)}else n(c,d,!!a);let u,p;if(a)p=-1,u=a,a=null;else if(d<t.childCount)p=d,u=t.child(d++);else break;for(let m=0;m<l.length;m++)l[m].to<=s&&l.splice(m--,1);for(;r<i.length&&i[r].from<=s&&i[r].to>s;)l.push(i[r++]);let h=s+u.nodeSize;if(u.isText){let m=h;r<i.length&&i[r].from<m&&(m=i[r].from);for(let y=0;y<l.length;y++)l[y].to<m&&(m=l[y].to);m<h&&(a=u.cut(m-s),u=u.cut(0,m-s),h=m,p=-1)}else for(;r<i.length&&i[r].to<h;)r++;let g=u.isInline&&!u.isLeaf?l.filter(m=>!m.inline):l.slice();o(u,g,e.forChild(s,u),p),s=h}}function co(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 fo(t,e,n,o){for(let i=0,s=0;i<t.childCount&&s<=o;){let r=t.child(i++),l=s;if(s+=r.nodeSize,!r.isText)continue;let a=r.text;for(;i<t.childCount;){let d=t.child(i++);if(s+=d.nodeSize,!d.isText)break;a+=d.text}if(s>=n){if(s>=o&&a.slice(o-e.length-l,o-l)==e)return o-e.length;let d=l<o?a.lastIndexOf(e,o-l-1):-1;if(d>=0&&d+e.length+l>=n)return l+d;if(n==o&&a.length>=o+e.length-l&&a.slice(o-l,o-l+e.length)==e)return o}}return-1}function nt(t,e,n,o,i){let s=[];for(let r=0,l=0;r<t.length;r++){let a=t[r],d=l,c=l+=a.size;d>=n||c<=e?s.push(a):(d<e&&s.push(a.slice(0,e-d,o)),i&&(s.push(i),i=void 0),c>n&&s.push(a.slice(n-d,a.size,o)))}return s}function mt(t,e=null){let n=t.domSelectionRange(),o=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,r=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(r<0)return null;let l=o.resolve(r),a,d;if(He(n)){for(a=r;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&S.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&Kn(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;d=new S(r==f?l:o.resolve(f))}else if(F&&e=="key"&&r>t.state.selection.to&&b(n.focusNode)&&n.focusOffset==n.focusNode.childNodes.length&&i&&i.posAtStart>t.state.selection.to)for(let f=n.focusNode;;f=f.parentNode){if(getComputedStyle(f).overflow!="visible"){d=pe.findFrom(o.resolve(i.posAtStart),1);break}if(f==i.dom||f.nextSibling||!f.parentNode||!b(f.parentNode))break}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=r,u=r;for(let p=0;p<n.rangeCount;p++){let h=n.getRangeAt(p);f=Math.min(f,t.docView.posFromDOM(h.startContainer,h.startOffset,1)),u=Math.max(u,t.docView.posFromDOM(h.endContainer,h.endOffset,-1))}if(f<0)return null;[a,r]=u==t.state.selection.anchor?[u,f]:[f,u],l=o.resolve(r)}else a=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(a<0)return null}let c=o.resolve(a);if(!d){let f=e=="pointer"||t.state.selection.head<l.pos&&!s?1:-1;d=gt(t,c,l,f)}return d}function un(t){return t.editable?t.hasFocus():mn(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function j(t,e=!1){let n=t.state.selection;if(pn(t,n),!un(t))return;let o=t.input.mouseDown;if(!e&&M&&o){let i=t.domSelectionRange(),s=t.domObserver.currentSelection;if(i.anchorNode&&s.anchorNode&&ae(i.anchorNode,i.anchorOffset,s.anchorNode,s.anchorOffset)&&o.delaySelUpdate()){t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)uo(t);else{let{anchor:i,head:s}=n,r,l;Rt&&!(n instanceof x)&&(n.$from.parent.inlineContent||(r=Bt(t,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(l=Bt(t,n.to))),t.docView.setSelection(i,s,t,e),Rt&&(r&&It(r),l&&It(l)),n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&ho(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}var Rt=A||M&&tn<63;function Bt(t,e){let{node:n,offset:o}=t.docView.domFromPos(e,0),i=o<n.childNodes.length?n.childNodes[o]:null,s=o?n.childNodes[o-1]:null;if(A&&i&&i.contentEditable=="false")return Ue(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return Ue(i);if(s)return Ue(s)}}function Ue(t){return t.contentEditable="true",A&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function It(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function ho(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let n=t.domSelectionRange(),o=n.anchorNode,i=n.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{(n.anchorNode!=o||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!un(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function uo(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,o=n.nodeName=="IMG";o?e.collapse(n.parentNode,O(n)+1):e.collapse(n,0),!o&&!t.state.selection.visible&&I&&J<=11&&(n.disabled=!0,n.disabled=!1)}function pn(t,e){if(e instanceof S){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Ft(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Ft(t)}function Ft(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function gt(t,e,n,o){return t.someProp("createSelectionBetween",i=>i(t,e,n))||x.between(e,n,o)}function Lt(t){return t.editable&&!t.hasFocus()?!1:mn(t)}function mn(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return ce(t.dom,e.anchorNode)&&(t.editable||ce(t.dom,e.focusNode))}catch{return!1}}function po(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return ae(e.node,e.offset,n.anchorNode,n.anchorOffset)}function ot(t,e){let{$anchor:n,$head:o}=t.selection,i=e>0?n.max(o):n.min(o),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&pe.findFrom(s,e)}function X(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function zt(t,e,n){let o=t.state.selection;if(o instanceof x)if(n.indexOf("s")>-1){let{$head:i}=o,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let r=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return X(t,new x(o.$anchor,r))}else if(o.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=ot(t.state,e);return i&&i instanceof S?X(t,i):!1}else if(!L||n.indexOf("m")<0){let i=o.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,r;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(r=t.docView.descAt(l))&&!r.contentDOM?S.isSelectable(s)?X(t,new S(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):X(t,new x(t.state.doc.resolve(e<0?l:l+s.nodeSize))):!1}}else return!1;else{if(o instanceof S&&o.node.isInline)return X(t,new x(e>0?o.$to:o.$from));{let i=ot(t.state,e);return i?X(t,i):!1}}}function Ne(t,e){let n=t.pmViewDesc;return n?n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR"):b(t)&&t.contentEditable=="false"}function he(t,e){return e<0?mo(t):go(t)}function mo(t){let e=t.domSelectionRange(),n=e.focusNode,o=e.focusOffset;if(!n)return;let i,s,r=!1;for(F&&b(n)&&o<T(n)&&Ne(n.childNodes[o],-1)&&(r=!0);;)if(o>0){if(!b(n))break;let l=n.childNodes[o-1];if(Ne(l,-1))i=n,s=--o;else if(N(l))n=l,o=n.nodeValue.length;else break}else{if(gn(n))break;{let l=n.previousSibling;for(;l&&Ne(l,-1);)i=n.parentNode,s=O(l),l=l.previousSibling;if(l)n=l,o=T(n);else{if(n=n.parentNode,n==t.dom)break;o=0}}}r?it(t,n,o):i&&it(t,i,s)}function go(t){let e=t.domSelectionRange(),n=e.focusNode,o=e.focusOffset;if(!n)return;let i=T(n),s,r;for(;;)if(o<i){if(!b(n))break;let l=n.childNodes[o];if(Ne(l,1))s=n,r=++o;else break}else{if(gn(n))break;{let l=n.nextSibling;for(;l&&Ne(l,1);)s=l.parentNode,r=O(l)+1,l=l.nextSibling;if(l)n=l,o=0,i=T(n);else{if(n=n.parentNode,n==t.dom)break;o=i=0}}}s&&it(t,s,r)}function gn(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function bo(t,e){for(;t&&e==t.childNodes.length&&!Te(t);)e=O(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let n=t.childNodes[e];if(N(n))return n;if(b(n)&&n.contentEditable=="false")break;t=n,e=0}}function yo(t,e){for(;t&&!e&&!Te(t);)e=O(t),t=t.parentNode;for(;t&&e;){let n=t.childNodes[e-1];if(N(n))return n;if(b(n)&&n.contentEditable=="false")break;t=n,e=t.childNodes.length}}function it(t,e,n){if(!N(e)){let r,l;(l=bo(e,n))?(e=l,n=0):(r=yo(e,n))&&(e=r,n=r.nodeValue.length)}let o=t.domSelection(),i=t.domSelectionRange();if(!o)return;He(i)?o.collapse(e,n):o.extend&&(o.collapse(i.anchorNode,i.anchorOffset),o.extend(e,n)),t.domObserver.setCurSelection();let{state:s}=t;setTimeout(()=>{t.state==s&&j(t)},50)}function $t(t,e){let n=t.state.doc.resolve(e);if(!(M||nn)&&n.parent.inlineContent){let s=t.coordsAtPos(e);if(e>n.start()){let r=t.coordsAtPos(e-1),l=(r.top+r.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(r.left-s.left)>1)return r.left<s.left?"ltr":"rtl"}if(e<n.end()){let r=t.coordsAtPos(e+1),l=(r.top+r.bottom)/2;if(l>s.top&&l<s.bottom&&Math.abs(r.left-s.left)>1)return r.left>s.left?"ltr":"rtl"}}let o=t.dom;for(let s=n.depth;s>0;s--)if(n.node(s).isBlock){o=t.nodeDOM(n.before(s))||o;break}return getComputedStyle(o).direction=="rtl"?"rtl":"ltr"}function qt(t,e,n){let o=t.state.selection;if(o instanceof x&&!o.empty||n.indexOf("s")>-1||L&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=o;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let r=ot(t.state,e);if(r&&r instanceof S)return X(t,r)}if(!i.parent.inlineContent){let r=e<0?i:s,l=o instanceof Bn?pe.near(r,e):pe.findFrom(r,e);return l?X(t,l):!1}return!1}function Kt(t,e){if(!(t.state.selection instanceof x))return!0;let{$head:n,$anchor:o,empty:i}=t.state.selection;if(!n.sameParent(o))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 r=t.state.tr;return e<0?r.delete(n.pos-s.nodeSize,n.pos):r.delete(n.pos,n.pos+s.nodeSize),t.dispatch(r),!0}return!1}function Ht(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function Do(t){if(!A||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&b(e)&&n==0&&e.firstChild&&b(e.firstChild)&&e.firstChild.contentEditable=="false"){let o=e.firstChild;Ht(t,o,"true"),setTimeout(()=>Ht(t,o,"false"),20)}return!1}function So(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function No(t,e){let n=e.keyCode,o=So(e);if(n==8||L&&n==72&&o=="c")return Kt(t,-1)||he(t,-1);if(n==46&&!e.shiftKey||L&&n==68&&o=="c")return Kt(t,1)||he(t,1);if(n==13||n==27)return!0;if(n==37||L&&n==66&&o=="c"){let i=n==37?$t(t,t.state.selection.from)=="ltr"?-1:1:-1;return zt(t,i,o)||he(t,i)}else if(n==39||L&&n==70&&o=="c"){let i=n==39?$t(t,t.state.selection.from)=="ltr"?1:-1:1;return zt(t,i,o)||he(t,i)}else{if(n==38||L&&n==80&&o=="c")return qt(t,-1,o)||he(t,-1);if(n==40||L&&n==78&&o=="c")return Do(t)||qt(t,1,o)||he(t,1);if(o==(L?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function bt(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:o,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&o.childCount==1&&o.firstChild.childCount==1;){i--,s--;let p=o.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),o=p.content}let r=t.someProp("clipboardSerializer")||Ke.fromSchema(t.state.schema),l=Nn(),a=l.createElement("div");a.appendChild(r.serializeFragment(o,{document:l}));let d=a.firstChild,c,f=0;for(;d&&b(d)&&(c=Sn[d.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}d=a.firstChild}d&&b(d)&&d.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(n)}`);let u=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,`

`);return{dom:a,text:u,slice:e}}function yt(t,e,n,o,i){let s=i.parent.type.spec.code,r,l;if(!n&&!e)return null;let a=!!e&&(o||s||!n);if(a){if(t.someProp("transformPastedText",u=>{e=u(e,s||o,t)}),s)return l=new le(G.from(t.state.schema.text(e.replace(/\r\n?/g,`
`))),0,0),t.someProp("transformPasted",u=>{l=u(l,t,!0)}),l;let f=t.someProp("clipboardTextParser",u=>u(e,i,o,t));if(f)l=f;else{let u=i.marks(),{schema:p}=t.state,h=Ke.fromSchema(p);r=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let m=r.appendChild(document.createElement("p"));g&&m.appendChild(h.serializeNode(p.text(g,u)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),r=Mo(n),We&&ko(r);let d=r&&r.querySelector("[data-pm-slice]"),c=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let u=r.firstChild;for(;u&&!b(u);)u=u.nextSibling;if(!u)break;r=u}if(l||(l=(t.someProp("clipboardParser")||t.someProp("domParser")||vt.fromSchema(t.state.schema)).parseSlice(r,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!Co.test(u.parentNode.nodeName)?{ignore:!0}:null}})),c)l=To(Wt(l,+c[1],+c[2]),c[4]);else if(l=le.maxOpen(Oo(l.content,i),!0),l.openStart||l.openEnd){let f=0,u=0;for(let p=l.content.firstChild;f<l.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=l.content.lastChild;u<l.openEnd&&!p.type.spec.isolating;u++,p=p.lastChild);l=Wt(l,f,u)}return t.someProp("transformPasted",f=>{l=f(l,t,a)}),l}var Co=/^(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 Oo(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,r=[];if(t.forEach(l=>{if(!r)return;let a=i.findWrapping(l.type),d;if(!a)return r=null;if(d=r.length&&s.length&&yn(a,s,l,r[r.length-1],0))r[r.length-1]=d;else{r.length&&(r[r.length-1]=Dn(r[r.length-1],s.length));let c=bn(l,a);r.push(c),i=i.matchType(c.type),s=a}}),r)return G.from(r)}return t}function bn(t,e,n=0){for(let o=e.length-1;o>=n;o--)t=e[o].create(null,G.from(t));return t}function yn(t,e,n,o,i){if(i<t.length&&i<e.length&&t[i]==e[i]){let s=yn(t,e,n,o.lastChild,i+1);if(s)return o.copy(o.content.replaceChild(o.childCount-1,s));if(o.contentMatchAt(o.childCount).matchType(i==t.length-1?n.type:t[i+1]))return o.copy(o.content.append(G.from(bn(n,t,i+1))))}}function Dn(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Dn(t.lastChild,e-1)),o=t.contentMatchAt(t.childCount).fillBefore(G.empty,!0);return t.copy(n.append(o))}function st(t,e,n,o,i,s){let r=e<0?t.firstChild:t.lastChild,l=r.content;return t.childCount>1&&(s=0),i<o-1&&(l=st(l,e,n,o,i+1,s)),i>=n&&(l=e<0?r.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(r.contentMatchAt(r.childCount).fillBefore(G.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,r.copy(l))}function Wt(t,e,n){return e<t.openStart&&(t=new le(st(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),n<t.openEnd&&(t=new le(st(t.content,1,n,t.openEnd,0,0),t.openStart,n)),t}var Sn={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function Nn(){return document.implementation.createHTMLDocument("title")}var De=null;function xo(t){let e=window.trustedTypes;if(!e)return t;if(!De){if(De=e.defaultPolicy)try{return De.createHTML(t)}catch{}De=e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})}return De.createHTML(t)}function Mo(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Nn(),o=n.body,i=/<([a-z][^>\s]+)/i.exec(t),s;if((s=i&&Sn[i[1].toLowerCase()])&&(t=s.map(r=>"<"+r+">").join("")+t+s.map(r=>"</"+r+">").reverse().join("")),o.innerHTML=xo(t),s)for(let r=0;r<s.length;r++)o=o.querySelector(s[r])||o;for(let r=0;r<n.styleSheets.length;r++){let l=n.styleSheets[r];for(let a=0;a<l.rules.length;a++){let d=l.rules[a];if(d instanceof CSSStyleRule){let c=o.querySelectorAll(d.selectorText);for(let f=0;f<c.length;f++)c[f].style.cssText+=d.style.cssText}}}return o}function ko(t){let e=t.querySelectorAll(M?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<e.length;n++){let o=e[n];o.childNodes.length==1&&o.textContent=="\xA0"&&o.parentNode&&o.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),o)}}function To(t,e){if(!t.size)return t;let n=t.content.firstChild.type.schema,o;try{o=JSON.parse(e)}catch{return t}let{content:i,openStart:s,openEnd:r}=t;for(let l=o.length-2;l>=0;l-=2){let a=n.nodes[o[l]];if(!a||a.hasRequiredAttrs())break;try{i=G.from(a.create(o[l+1],i))}catch{break}s++,r++}return new le(i,s,r)}var V={},R={},Ao={touchstart:!0,touchmove:!0},rt=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 Eo(t){for(let e in V){let n=V[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=o=>{Vo(t,o)&&!Dt(t,o)&&(t.editable||!(o.type in R))&&n(t,o)},Ao[e]?{passive:!0}:void 0)}A&&t.dom.addEventListener("input",()=>null),lt(t)}function U(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Po(t){t.input.mouseDown&&t.input.mouseDown.done(),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 lt(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=o=>Dt(t,o))})}function Dt(t,e){return t.someProp("handleDOMEvents",n=>{let o=n[e.type];return o?o(t,e)||e.defaultPrevented:!1})}function Vo(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 Ro(t,e){!Dt(t,e)&&V[e.type]&&(t.editable||!(e.type in R))&&V[e.type](t,e)}R.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!xn(t)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(_&&M&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),ge&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let o=Date.now();t.input.lastIOSEnter=o,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==o&&(t.someProp("handleKeyDown",i=>i(t,ee(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",o=>o(t,n))||No(t,n)?n.preventDefault():U(t,"key")};R.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};R.keypress=(t,e)=>{let n=e;if(xn(t)||!n.charCode||n.ctrlKey&&!n.altKey||L&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let o=t.state.selection;if(!(o instanceof x)||!o.$from.sameParent(o.$to)){let i=String.fromCharCode(n.charCode),s=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",r=>r(t,o.$from.pos,o.$to.pos,i,s))&&t.dispatch(s()),n.preventDefault()}};function Ae(t){return{left:t.clientX,top:t.clientY}}function Bo(t,e){let n=e.x-t.clientX,o=e.y-t.clientY;return n*n+o*o<100}function St(t,e,n,o,i){if(o==-1)return!1;let s=t.state.doc.resolve(o);for(let r=s.depth+1;r>0;r--)if(t.someProp(e,l=>r>s.depth?l(t,n,s.nodeAfter,s.before(r),i,!0):l(t,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function Ee(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let o=t.state.tr.setSelection(e);o.setMeta("pointer",!0),t.dispatch(o)}function Io(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),o=n.nodeAfter;return o&&o.isAtom&&S.isSelectable(o)?(Ee(t,new S(n)),!0):!1}function Fo(t,e){if(e==-1)return!1;let n=t.state.selection,o,i;n instanceof S&&(o=n.node);let s=t.state.doc.resolve(e);for(let r=s.depth+1;r>0;r--){let l=r>s.depth?s.nodeAfter:s.node(r);if(S.isSelectable(l)){o&&n.$from.depth>0&&r>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?i=s.before(n.$from.depth):i=s.before(r);break}}return i!=null?(Ee(t,S.create(t.state.doc,i)),!0):!1}function Lo(t,e,n,o,i){return St(t,"handleClickOn",e,n,o)||t.someProp("handleClick",s=>s(t,e,o))||(i?Fo(t,n):Io(t,n))}function zo(t,e,n,o){return St(t,"handleDoubleClickOn",e,n,o)||t.someProp("handleDoubleClick",i=>i(t,e,o))}function $o(t,e,n,o){return St(t,"handleTripleClickOn",e,n,o)||t.someProp("handleTripleClick",i=>i(t,e,o))||qo(t,n,o)}function qo(t,e,n){if(n.button!=0)return!1;let o=Cn(t,e,!0),i=t.state.doc;return o?(Ee(t,o),o instanceof x&&i.eq(t.state.doc)&&(t.input.mouseDown=new ct(t,o)),!0):!1}function Cn(t,e,n){let o=t.state.doc;if(e==-1)return o.inlineContent?x.create(o,0,o.content.size):null;let i=o.resolve(e);for(let s=i.depth+1;s>0;s--){let r=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(r.inlineContent)return x.create(o,l+1,l+1+r.content.size);if(n&&S.isSelectable(r))return S.create(o,l)}return null}function Nt(t){return Ce(t)}var On=L?"metaKey":"ctrlKey";V.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let o=Nt(t),i=Date.now(),s="singleClick";i-t.input.lastClick.time<500&&Bo(n,t.input.lastClick)&&!n[On]&&t.input.lastClick.button==n.button&&(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,button:n.button},t.input.mouseDown&&t.input.mouseDown.done();let r=t.posAtCoords(Ae(n));r&&(s=="singleClick"?t.input.mouseDown=new at(t,r,n,!!o):(s=="doubleClick"?zo:$o)(t,r.pos,r.inside,n)?n.preventDefault():U(t,"pointer"))};var Fe=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},at=class extends Fe{constructor(e,n,o,i){super(e),this.pos=n,this.event=o,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!o[On],this.allowDefault=o.shiftKey;let s,r;if(n.inside>-1)s=e.state.doc.nodeAt(n.inside),r=n.inside;else{let c=e.state.doc.resolve(n.pos);s=c.parent,r=c.depth?c.before():0}let l=i?null:o.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&b(a.nodeDOM)?a.nodeDOM:null;let{selection:d}=e.state;o.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||d instanceof S&&d.from<=r&&d.to>r)&&(this.mightDrag={node:s,pos:r,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&F&&!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()),U(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||j(this.view)})}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(Ae(e))),this.updateAllowDefault(e),this.allowDefault||!n?U(this.view,"pointer"):Lo(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||A&&this.mightDrag&&!this.mightDrag.node.isAtom||M&&!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)?(Ee(this.view,pe.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):U(this.view,"pointer")}move(e){this.updateAllowDefault(e),U(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},ct=class extends Fe{constructor(e,n){super(e),this.startSelection=n,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),U(this.view,"pointer");let n=this.view.posAtCoords(Ae(e)),o=n&&Cn(this.view,n.inside,!1);if(!o)return;let{doc:i}=this.view.state,s=this.startSelection,[r,l]=o.from<s.from?[s.to,o.from]:[s.from,o.to];Ee(this.view,x.create(i,r,l))}};V.touchstart=t=>{t.input.lastTouch=Date.now(),Nt(t),U(t,"pointer")};V.touchmove=t=>{t.input.lastTouch=Date.now(),U(t,"pointer")};V.contextmenu=t=>Nt(t);function xn(t,e){return t.composing?!0:A&&Math.abs(Date.now()-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}var Ko=_?5e3:-1;R.compositionstart=R.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof x&&e.selection.empty&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(o=>o.type.spec.inclusive===!1)||M&&nn&&Ho(t)))t.markCursor=t.state.storedMarks||n.marks(),Ce(t,!0),t.markCursor=null;else if(Ce(t,!e.selection.empty),F&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let o=t.domSelectionRange();for(let i=o.focusNode,s=o.focusOffset;i&&b(i)&&s!=0;){let r=s<0?i.lastChild:i.childNodes[s-1];if(!r)break;if(N(r)){let l=t.domSelection();l&&l.collapse(r,r.nodeValue.length);break}else i=r,s=-1}}t.input.composing=!0}Mn(t,Ko)};function Ho(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||!b(e)||n>=e.childNodes.length)return!1;let o=e.childNodes[n];return b(o)&&o.contentEditable=="false"}R.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now(),t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Mn(t,20))};function Mn(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Ce(t),e))}function kn(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Date.now());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Wo(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=$n(e.focusNode,e.focusOffset),o=qn(e.focusNode,e.focusOffset);if(n&&o&&n!=o){let i=o.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(n==s||o==s)return s;if(!i||!i.isText(o.nodeValue))return o;if(t.input.compositionNode==o){let r=n.pmViewDesc;if(!(!r||!r.isText(n.nodeValue)))return o}}return n||o}function Ce(t,e=!1){if(!(_&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),kn(t),e||t.docView&&t.docView.dirty){let n=mt(t),o=t.state.selection;return n&&!n.eq(o)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function _o(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 o=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),o.removeAllRanges(),o.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}var Oe=I&&J<15||ge&&_n<604;V.copy=R.cut=(t,e)=>{let n=e,o=t.state.selection,i=n.type=="cut";if(o.empty)return;let s=Oe?null:n.clipboardData,r=o.content(),{dom:l,text:a}=bt(t,r);s?(n.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):_o(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Uo(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function jo(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,o=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let i=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),o.parentNode&&o.parentNode.removeChild(o),n?xe(t,o.value,null,i,e):xe(t,o.textContent,o.innerHTML,i,e)},50)}function xe(t,e,n,o,i){let s=yt(t,e,n,o,t.state.selection.$from);if(t.someProp("handlePaste",a=>a(t,i,s||le.empty)))return!0;if(!s)return!1;let r=Uo(s),l=r?t.state.tr.replaceSelectionWith(r,o):t.state.tr.replaceSelection(s);return t.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Tn(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," "):""}R.paste=(t,e)=>{let n=e;if(t.composing&&!_)return;let o=Oe?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;o&&xe(t,Tn(o),o.getData("text/html"),i,n)?n.preventDefault():jo(t,n)};var Le=class{constructor(e,n,o){this.slice=e,this.move=n,this.node=o}},Go=L?"altKey":"ctrlKey";function An(t,e){let n;return t.someProp("dragCopies",o=>{n=n||o(e)}),n!=null?!n:!e[Go]}V.dragstart=(t,e)=>{let n=e,o=t.input.mouseDown;if(o&&o.done(),!n.dataTransfer)return;let i=t.state.selection,s=i.empty?null:t.posAtCoords(Ae(n)),r;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(o&&o.mightDrag)r=S.create(t.state.doc,o.mightDrag.pos);else if(n.target&&b(n.target)){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(r=S.create(t.state.doc,f.posBefore))}}let l=(r||t.state.selection).content(),{dom:a,text:d,slice:c}=bt(t,l);(!n.dataTransfer.files.length||!M||tn>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Oe?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Oe||n.dataTransfer.setData("text/plain",d),t.dragging=new Le(c,An(t,n),r)};V.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};R.dragover=R.dragenter=(t,e)=>e.preventDefault();R.drop=(t,e)=>{try{Yo(t,e,t.dragging)}finally{t.dragging=null}};function Yo(t,e,n){if(!e.dataTransfer)return;let o=t.posAtCoords(Ae(e));if(!o)return;let i=t.state.doc.resolve(o.pos),s=n&&n.slice;s?t.someProp("transformPasted",p=>{s=p(s,t,!1)}):s=yt(t,Tn(e.dataTransfer),Oe?null:e.dataTransfer.getData("text/html"),!1,i);let r=!!(n&&An(t,e));if(t.someProp("handleDrop",p=>p(t,e,s||le.empty,r))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Fn(t.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=t.state.tr;if(r){let{node:p}=n;p?p.replace(a):a.deleteSelection()}let d=a.mapping.map(l),c=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(c?a.replaceRangeWith(d,d,s.content.firstChild):a.replaceRange(d,d,s),a.doc.eq(f))return;let u=a.doc.resolve(d);if(c&&S.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new S(u));else{let p=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((h,g,m,y)=>p=y),a.setSelection(gt(t,u,a.doc.resolve(p)))}t.focus(),t.dispatch(a.setMeta("uiEvent","drop"))}V.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())&&j(t)},20))};V.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)};V.beforeinput=(t,e)=>{if(_&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:o}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=o||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",s=>s(t,ee(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 R)V[t]=R[t];function Me(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}var ke=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index<this.frag.childCount;){let n=this.frag.child(this.index);if(this.off==e)return n;this.off+=n.nodeSize,this.index++}return null}},ze=class t{constructor(e,n){this.toDOM=e,this.spec=n||se,this.side=this.spec.side||0}map(e,n,o,i){let{pos:s,deleted:r}=e.mapResult(n.from+i,this.side<0?-1:1);return r?null:new Q(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof t&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Me(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},ie=class t{constructor(e,n){this.attrs=e,this.spec=n||se}map(e,n,o,i){let s=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-o,r=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-o;return s>=r?null:new Q(s,r,this)}valid(e,n){return n.from<n.to}eq(e){return this==e||e instanceof t&&Me(this.attrs,e.attrs)&&Me(this.spec,e.spec)}static is(e){return e.type instanceof t}destroy(){}},dt=class t{constructor(e,n){this.attrs=e,this.spec=n||se}map(e,n,o,i){let s=e.mapResult(n.from+i,1);if(s.deleted)return null;let r=e.mapResult(n.to+i,-1);return r.deleted||r.pos<=s.pos?null:new Q(s.pos-o,r.pos-o,this)}valid(e,n,o){let i=o.nodeAt(n.from);return!!i&&!i.isText&&n.from+i.nodeSize==n.to}eq(e){return this==e||e instanceof t&&Me(this.attrs,e.attrs)&&Me(this.spec,e.spec)}destroy(){}},Q=class t{constructor(e,n,o){this.from=e,this.to=n,this.type=o}copy(e,n){return new t(e,n,this.type)}eq(e,n=0){return this.type.eq(e.type)&&this.from+n==e.from&&this.to+n==e.to}map(e,n,o){return this.type.map(e,this,n,o)}static widget(e,n,o){return new t(e,e,new ze(n,o))}static inline(e,n,o,i){return new t(e,n,new ie(o,i))}static node(e,n,o,i){return new t(e,n,new dt(o,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof ie}get widget(){return this.type instanceof ze}},ue=[],se={},$=class t{constructor(e,n){this.local=e.length?e:ue,this.children=n.length?n:ue}static create(e,n){return n.length?qe(n,e,0,se):k}find(e,n,o){let i=[];return this.findInner(e??0,n??1e9,i,0,o),i}findInner(e,n,o,i,s){for(let r=0;r<this.local.length;r++){let l=this.local[r];l.from<=n&&l.to>=e&&(!s||s(l.spec))&&o.push(l.copy(l.from+i,l.to+i))}for(let r=0;r<this.children.length;r+=3)if(this.children[r]<n&&this.children[r+1]>e){let l=this.children[r]+1;this.children[r+2].findInner(e-l,n-l,o,i+l,s)}}map(e,n,o){return this==k||e.maps.length==0?this:this.mapInner(e,n,0,0,o||se)}mapInner(e,n,o,i,s){let r;if(this.local.length){let l=new ke(n.content);for(let a=0;a<this.local.length;a++){let d=this.local[a].map(e,o,i);d&&d.type.valid(n,d,l)?(r||(r=[])).push(d):s.onRemove&&s.onRemove(this.local[a].spec)}}return this.children.length?Xo(this.children,r||[],e,n,o,i,s):r?new t(r.sort(re),ue):k}add(e,n){return n.length?this==k?t.create(e,n):this.addInner(e,n,0):this}addInner(e,n,o){let i,s=0;e.forEach((l,a)=>{let d=a+o,c;if(c=Pn(n,l,d)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,c,d+1):i.splice(s,0,a,a+l.nodeSize,qe(c,l,d+1,se)),s+=3}});let r=En(s?Vn(n):n,-o);if(r.length){let l=new ke(e.content);for(let a=0;a<r.length;a++)r[a].type.valid(e,r[a],l)||r.splice(a--,1)}return new t(r.length?this.local.concat(r).sort(re):this.local,i||this.children)}remove(e){return e.length==0||this==k?this:this.removeInner(e,0)}removeInner(e,n){let o=this.children,i=this.local;for(let s=0;s<o.length;s+=3){let r,l=o[s]+n,a=o[s+1]+n;for(let c=0,f;c<e.length;c++)(f=e[c])&&f.from>l&&f.to<a&&(e[c]=null,(r||(r=[])).push(f));if(!r)continue;o==this.children&&(o=this.children.slice());let d=o[s+2].removeInner(r,l+1);d!=k?o[s+2]=d:(o.splice(s,3),s-=3)}if(i.length){for(let s=0,r;s<e.length;s++)if(r=e[s])for(let l=0;l<i.length;l++)i[l].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return o==this.children&&i==this.local?this:i.length||o.length?new t(i,o):k}forChild(e,n){if(this==k)return this;if(n.isLeaf)return t.empty;let o,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(o=this.children[l+2]);break}let s=e+1,r=s+n.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<r&&a.to>s&&a.type instanceof ie){let d=Math.max(s,a.from)-s,c=Math.min(r,a.to)-s;d<c&&(i||(i=[])).push(a.copy(d,c))}}if(i){let l=new t(i.sort(re),ue);return o?new $e([l,o]):l}return o||k}eq(e){if(this==e)return!0;if(!(e instanceof t)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let n=0;n<this.local.length;n++)if(!this.local[n].eq(e.local[n]))return!1;for(let n=0;n<this.children.length;n+=3)if(this.children[n]!=e.children[n]||this.children[n+1]!=e.children[n+1]||!this.children[n+2].eq(e.children[n+2]))return!1;return!0}locals(e){return Ct(this.localsInner(e))}localsInner(e){if(this==k)return ue;if(e.inlineContent||!this.local.some(ie.is))return this.local;let n=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof ie||n.push(this.local[o]);return n}forEachSet(e){e(this)}};$.empty=new $([],[]);$.removeOverlap=Ct;var k=$.empty,$e=class t{constructor(e){this.members=e}map(e,n){let o=this.members.map(i=>i.map(e,n,se));return t.from(o)}forChild(e,n){if(n.isLeaf)return $.empty;let o=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,n);s!=k&&(s instanceof t?o=o.concat(s.members):o.push(s))}return t.from(o)}eq(e){if(!(e instanceof t)||e.members.length!=this.members.length)return!1;for(let n=0;n<this.members.length;n++)if(!this.members[n].eq(e.members[n]))return!1;return!0}locals(e){let n,o=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!n)n=s;else{o&&(n=n.slice(),o=!1);for(let r=0;r<s.length;r++)n.push(s[r])}}return n?Ct(o?n:n.sort(re)):ue}static from(e){switch(e.length){case 0:return k;case 1:return e[0];default:return new t(e.every(n=>n instanceof $)?e:e.reduce((n,o)=>n.concat(o instanceof $?o:o.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}};function Xo(t,e,n,o,i,s,r){let l=t.slice();for(let d=0,c=s;d<n.maps.length;d++){let f=0;n.maps[d].forEach((u,p,h,g)=>{let m=g-h-(p-u);for(let y=0;y<l.length;y+=3){let E=l[y+1];if(E<0||u>E+c-f)continue;let P=l[y]+c-f;p>=P?l[y+1]=u<=P?-2:-1:u>=c&&m&&(l[y]+=m,l[y+1]+=m)}f+=m}),c=n.maps[d].map(c,-1)}let a=!1;for(let d=0;d<l.length;d+=3)if(l[d+1]<0){if(l[d+1]==-2){a=!0,l[d+1]=-1;continue}let c=n.map(t[d]+s),f=c-i;if(f<0||f>=o.content.size){a=!0;continue}let u=n.map(t[d+1]+s,-1),p=u-i,{index:h,offset:g}=o.content.findIndex(f),m=o.maybeChild(h);if(m&&g==f&&g+m.nodeSize==p){let y=l[d+2].mapInner(n,m,c+1,t[d]+s+1,r);y!=k?(l[d]=f,l[d+1]=p,l[d+2]=y):(l[d+1]=-2,a=!0)}else a=!0}if(a){let d=Jo(l,t,e,n,i,s,r),c=qe(d,o,0,r);e=c.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,u=0;f<c.children.length;f+=3){let p=c.children[f];for(;u<l.length&&l[u]<p;)u+=3;l.splice(u,0,c.children[f],c.children[f+1],c.children[f+2])}}return new $(e.sort(re),l)}function En(t,e){if(!e||!t.length)return t;let n=[];for(let o=0;o<t.length;o++){let i=t[o];n.push(new Q(i.from+e,i.to+e,i.type))}return n}function Jo(t,e,n,o,i,s,r){function l(a,d){for(let c=0;c<a.local.length;c++){let f=a.local[c].map(o,i,d);f?n.push(f):r.onRemove&&r.onRemove(a.local[c].spec)}for(let c=0;c<a.children.length;c+=3)l(a.children[c+2],a.children[c]+d+1)}for(let a=0;a<t.length;a+=3)t[a+1]==-1&&l(t[a+2],e[a]+s+1);return n}function Pn(t,e,n){if(e.isLeaf)return null;let o=n+e.nodeSize,i=null;for(let s=0,r;s<t.length;s++)(r=t[s])&&r.from>n&&r.to<o&&((i||(i=[])).push(r),t[s]=null);return i}function Vn(t){let e=[];for(let n=0;n<t.length;n++)t[n]!=null&&e.push(t[n]);return e}function qe(t,e,n,o){let i=[],s=!1;e.forEach((l,a)=>{let d=Pn(t,l,a+n);if(d){s=!0;let c=qe(d,l,n+a+1,o);c!=k&&i.push(a,a+l.nodeSize,c)}});let r=En(s?Vn(t):t,-n).sort(re);if(r.length){let l=new ke(e.content);for(let a=0;a<r.length;a++)r[a].type.valid(e,r[a],l)||(o.onRemove&&o.onRemove(r[a].spec),r.splice(a--,1))}return r.length||i.length?new $(r,i):k}function re(t,e){return t.from-e.from||t.to-e.to}function Ct(t){let e=t;for(let n=0;n<e.length-1;n++){let o=e[n];if(o.from!=o.to)for(let i=n+1;i<e.length;i++){let s=e[i];if(s.from==o.from){s.to!=o.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,o.to),_t(e,i+1,s.copy(o.to,s.to)));continue}else{s.from<o.to&&(e==t&&(e=t.slice()),e[n]=o.copy(o.from,s.from),_t(e,i,o.copy(s.from,o.to)));break}}}return e}function _t(t,e,n){for(;e<t.length&&re(n,t[e])>0;)e++;t.splice(e,0,n)}function je(t){let e=[];return t.someProp("decorations",n=>{let o=n(t.state);o&&o!=k&&e.push(o)}),t.cursorWrapper&&e.push($.create(t.state.doc,[t.cursorWrapper.deco])),$e.from(e)}var Zo={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Qo=I&&J<=11,ft=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}},ht=class{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ft,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(o=>{for(let i=0;i<o.length;i++)this.queue.push(o[i]);I&&J<=11&&o.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():A&&e.composing&&o.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Qo&&(this.onCharData=o=>{this.queue.push({target:o.target,type:"characterData",oldValue:o.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,Zo)),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;n<e.length;n++)this.queue.push(e[n]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Lt(this.view)){if(this.suppressingSelectionUpdates)return j(this.view);if(I&&J<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&ae(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,o;for(let s=e.focusNode;s;s=me(s))n.add(s);for(let s=e.anchorNode;s;s=me(s))if(n.has(s)){o=s;break}let i=o&&this.view.docView.nearestDesc(o);if(i&&i.ignoreMutation({type:"selection",target:N(o)?o.parentNode:o}))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 o,i=!1;!this.suppressingSelectionUpdates&&Lt(e)&&(o=e.domSelectionRange(),i=!this.currentSelection.eq(o)&&!this.ignoreSelectionChange(o));let s=-1,r=-1,l=!1,a=[];if(e.editable)for(let c=0;c<n.length;c++){let f=this.registerMutation(n[c],a);f&&(s=s<0?f.from:Math.min(f.from,s),r=r<0?f.to:Math.max(f.to,r),f.typeOver&&(l=!0))}if(a.some(c=>c.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||M&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&n.some(c=>c.type=="childList"&&c.removedNodes.length))){for(let c of a)if(c.nodeName=="BR"&&c.parentNode){let f=c.nextSibling;for(;f&&b(f);){if(f.contentEditable=="false"){c.parentNode.removeChild(c);break}f=f.firstChild}}}else if(F&&a.length){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let[f,u]=c;f.parentNode&&f.parentNode.parentNode==u.parentNode?u.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let u of c){let p=u.parentNode;p&&p.nodeName=="LI"&&(!f||ei(e,f)!=p)&&u.remove()}}}let d=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&He(o)&&(d=mt(e))&&d.eq(pe.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,j(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,r),wo(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,ti(e,a)),this.handleDOMChange(s,r,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):o&&!this.currentSelection.eq(o)&&j(e),o&&this.currentSelection.set(o))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let o=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(o==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!o||o.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;c<e.addedNodes.length;c++){let f=e.addedNodes[c];n.push(f),N(f)&&(this.lastChangedTextNode=f)}if(o.contentDOM&&o.contentDOM!=o.dom&&!o.contentDOM.contains(e.target))return{from:o.posBefore,to:o.posAfter};let i=e.previousSibling,s=e.nextSibling;if(I&&J<=11&&e.addedNodes.length)for(let c=0;c<e.addedNodes.length;c++){let{previousSibling:f,nextSibling:u}=e.addedNodes[c];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(s=u)}let r=i&&i.parentNode==e.target?O(i)+1:0,l=o.localPosFromDOM(e.target,r,-1),a=s&&s.parentNode==e.target?O(s):e.target.childNodes.length,d=o.localPosFromDOM(e.target,a,1);return{from:l,to:d}}else return e.type=="attributes"?{from:o.posAtStart-o.border,to:o.posAtEnd+o.border}:(this.lastChangedTextNode=e.target,{from:o.posAtStart,to:o.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},Ut=new WeakMap,jt=!1;function wo(t){if(!Ut.has(t)&&(Ut.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=F,jt)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),jt=!0}}function Gt(t,e){let n=e.startContainer,o=e.startOffset,i=e.endContainer,s=e.endOffset,r=t.domAtPos(t.state.selection.anchor);return ae(r.node,r.offset,i,s)&&([n,o,i,s]=[i,s,n,o]),{anchorNode:n,anchorOffset:o,focusNode:i,focusOffset:s}}function vo(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return Gt(t,i)}let n;function o(i){i.preventDefault(),i.stopImmediatePropagation(),n=i.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",o,!0),n?Gt(t,n):null}function ei(t,e){for(let n=e.parentNode;n&&n!=t.dom;n=n.parentNode){let o=t.docView.nearestDesc(n,!0);if(o&&o.node.isBlock)return n}return null}function ti(t,e){var n;let{focusNode:o,focusOffset:i}=t.domSelectionRange();for(let s of e)if(((n=s.parentNode)===null||n===void 0?void 0:n.nodeName)=="TR"){let r=s.nextSibling;for(;r&&r.nodeName!="TD"&&r.nodeName!="TH";)r=r.nextSibling;if(r){let l=r;for(;;){let a=l.firstChild;if(!a||!b(a)||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),o==s&&t.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}function ni(t,e,n,o){let{node:i,fromOffset:s,toOffset:r,from:l,to:a}=t.docView.parseRange(e,n),d=t.domSelectionRange(),c,f=d.anchorNode;if(f&&ce(t.dom,f)&&(c=[{node:f,offset:d.anchorOffset}],He(d)||c.push({node:d.focusNode,offset:d.focusOffset})),M&&t.input.lastKeyCode===8)for(let y=r;y>s;y--){let E=i.childNodes[y-1],P=E.pmViewDesc;if(E.nodeName=="BR"&&!P){r=y;break}if(!P||P.size)break}let u=t.state.doc,p=t.someProp("domParser")||vt.fromSchema(t.state.schema),h=u.resolve(l),g=null,m=p.parse(i,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:s,to:r,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:oi(o),context:h});if(c&&c[0].pos!=null){let y=c[0].pos,E=c[1]&&c[1].pos;E==null&&(E=y),g={anchor:y+l,head:E+l}}return{doc:m,sel:g,from:l,to:a}}var oi=t=>e=>{let n=e.pmViewDesc;if(n)return n.parseRule(t);if(e.nodeName=="BR"&&e.parentNode){if(A&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let o=document.createElement("div");return o.appendChild(document.createElement("li")),{skip:o}}else if(e.parentNode.lastChild==e||A&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},ii=/^(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 si(t,e,n,o,i){let s=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let D=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,C=mt(t,D);if(C&&!t.state.selection.eq(C)){if(M&&_&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",Rn=>Rn(t,ee(13,"Enter"))))return;let B=t.state.tr.setSelection(C);D=="pointer"?B.setMeta("pointer",!0):D=="key"&&B.scrollIntoView(),s&&B.setMeta("composition",s),t.dispatch(B)}return}let r=t.state.doc.resolve(e),l=r.sharedDepth(n);e=r.before(l+1),n=t.state.doc.resolve(n).after(l+1);let a=t.state.selection,d=ni(t,e,n,i),c=t.state.doc,f=c.slice(d.from,d.to),u,p;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(u=t.state.selection.to,p="end"):(u=t.state.selection.from,p="start"),t.input.lastKeyCode=null;let h=ci(f.content,d.doc.content,d.from,u,p);if(h&&t.input.domChangeCount++,(ge&&t.input.lastIOSEnter>Date.now()-225||_)&&i.some(D=>b(D)&&!ii.test(D.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",D=>D(t,ee(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(o&&a instanceof x&&!a.empty&&a.$head.sameParent(a.$anchor)&&!t.composing&&!(d.sel&&d.sel.anchor!=d.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(d.sel){let D=Yt(t,t.state.doc,d.sel);if(D&&!D.eq(t.state.selection)){let C=t.state.tr.setSelection(D);s&&C.setMeta("composition",s),t.dispatch(C)}}return}t.state.selection.from<t.state.selection.to&&h.start==h.endB&&t.state.selection instanceof x&&(h.start>t.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=d.from?h.start=t.state.selection.from:h.endA<t.state.selection.to&&h.endA>=t.state.selection.to-2&&t.state.selection.to<=d.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),I&&J<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>d.from&&d.doc.textBetween(h.start-d.from-1,h.start-d.from+1)==" \xA0"&&(h.start--,h.endA--,h.endB--);let g=d.doc.resolveNoCache(h.start-d.from),m=d.doc.resolveNoCache(h.endB-d.from),y=c.resolve(h.start),E=g.sameParent(m)&&g.parent.inlineContent&&y.end()>=h.endA;if((ge&&t.input.lastIOSEnter>Date.now()-225&&(!E||i.some(D=>D.nodeName=="DIV"||D.nodeName=="P"))||!E&&ai(d.doc,g.pos,m.pos))&&t.someProp("handleKeyDown",D=>D(t,ee(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&(E?h.endA>h.start&&h.endB==h.start:li(c,h.start,h.endA,g,m))&&t.someProp("handleKeyDown",D=>D(t,ee(8,"Backspace")))){_&&M&&t.domObserver.suppressSelectionUpdates();return}M&&h.endB==h.start&&(t.input.lastChromeDelete=Date.now()),_&&!E&&g.start()!=m.start()&&m.parentOffset==0&&g.depth==m.depth&&d.sel&&d.sel.anchor==d.sel.head&&d.sel.head==h.endA&&(h.endB-=2,m=d.doc.resolveNoCache(h.endB-d.from),setTimeout(()=>{t.someProp("handleKeyDown",function(D){return D(t,ee(13,"Enter"))})},20));let P=h.start,v=h.endA,be=D=>{let C=D||t.state.tr.replace(P,v,d.doc.slice(h.start-d.from,h.endB-d.from));if(d.sel){let B=Yt(t,C.doc,d.sel);B&&!(M&&t.composing&&B.empty&&(h.start!=h.endB||t.input.lastChromeDelete<Date.now()-100)&&(B.head==P||B.head==C.mapping.map(v)-1)||I&&B.empty&&B.head==P)&&C.setSelection(B)}return s&&C.setMeta("composition",s),C.scrollIntoView()},Pe;if(E)if(g.pos==m.pos){I&&J<=11&&g.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>j(t),20));let D=be(t.state.tr.delete(P,v)),C=c.resolve(h.start).marksAcross(c.resolve(h.endA));C&&D.ensureMarks(C),t.dispatch(D)}else if(h.endA==h.endB&&(Pe=ri(g.parent.content.cut(g.parentOffset,m.parentOffset),y.parent.content.cut(y.parentOffset,h.endA-y.start())))){let D=be(t.state.tr);Pe.type=="add"?D.addMark(P,v,Pe.mark):D.removeMark(P,v,Pe.mark),t.dispatch(D)}else if(g.parent.child(g.index()).isText&&g.index()==m.index()-(m.textOffset?0:1)){let D=g.parent.textBetween(g.parentOffset,m.parentOffset),C=()=>be(t.state.tr.insertText(D,P,v));t.someProp("handleTextInput",B=>B(t,P,v,D,C))||t.dispatch(C())}else t.dispatch(be());else t.dispatch(be())}function Yt(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:gt(t,e.resolve(n.anchor),e.resolve(n.head))}function ri(t,e){let n=t.firstChild.marks,o=e.firstChild.marks,i=n,s=o,r,l,a;for(let c=0;c<o.length;c++)i=o[c].removeFromSet(i);for(let c=0;c<n.length;c++)s=n[c].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],r="add",a=c=>c.mark(l.addToSet(c.marks));else if(i.length==0&&s.length==1)l=s[0],r="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let d=[];for(let c=0;c<e.childCount;c++)d.push(a(e.child(c)));if(G.from(d).eq(t))return{mark:l,type:r}}function li(t,e,n,o,i){if(n-e<=i.pos-o.pos||Ge(o,!0,!1)<i.pos)return!1;let s=t.resolve(e);if(!o.parent.inlineContent){let l=s.nodeAfter;return l!=null&&n==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let r=t.resolve(Ge(s,!0,!0));return!r.parent.isTextblock||r.pos>n||Ge(r,!0,!1)<n?!1:o.parent.content.cut(o.parentOffset).eq(r.parent.content)}function ai(t,e,n){let o=0,i=0;return t.nodesBetween(e,n,(s,r)=>{s.isTextblock&&r>=e&&r<n?o++:(s.isText?/\S/.test(s.text.slice(Math.max(0,e-r),Math.min(s.nodeSize,n-r))):s.isLeaf)&&i++}),i==0&&o==1}function Ge(t,e,n){let o=t.depth,i=e?t.end():t.pos;for(;o>0&&(e||t.indexAfter(o)==t.node(o).childCount);)o--,i++,e=!1;if(n){let s=t.node(o).maybeChild(t.indexAfter(o));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function ci(t,e,n,o,i){let s=t.findDiffStart(e,n),r=n+t.size,l=n+e.size;if(s==null)return null;let{a,b:d}=t.findDiffEnd(e,r,l);if(i=="end"){let c=Math.max(0,s-Math.min(a,d));o-=a+c-s}if(a<s&&r<l){let c=o<=s&&o>=a?s-o:0;s-=c,d=s+(d-a),a=s}else if(d<s){let c=o<=s&&o>=d?s-o:0;s-=c,a=s+(a-d),d=s}return{start:s,endA:a,endB:d}}var mi=yt,gi=Ce,ut=class{constructor(e,n){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 rt,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(wt),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=Zt(this),Jt(this),this.nodeViews=Qt(this),this.docView=Pt(this.state.doc,Xt(this),je(this),this.dom,this),this.domObserver=new ht(this,(o,i,s,r)=>si(this,o,i,s,r)),this.domObserver.start(),Eo(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&lt(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(wt),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let o in this._props)n[o]=this._props[o];n.state=this.state;for(let o in e)n[o]=e[o];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var o;let i=this.state,s=!1,r=!1;e.storedMarks&&this.composing&&(kn(this),r=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(l||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=Qt(this);fi(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&lt(this),this.editable=Zt(this),Jt(this);let a=je(this),d=Xt(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,d,a);(f||!e.selection.eq(i.selection))&&(r=!0);let u=c=="preserve"&&r&&this.dom.style.overflowAnchor==null&&Gn(this);if(r){this.domObserver.stop();let p=f&&(I||M)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&di(i.selection,e.selection);if(f){let g=M?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Wo(this)),(s||!this.docView.update(e.doc,d,a,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=Pt(e.doc,d,a,this.dom,this)),g&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}let h=this.input.mouseDown;p||!(h&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&po(this)&&h.delaySelUpdate())?j(this,p):(pn(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((o=this.dragging)===null||o===void 0)&&o.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():u&&Yn(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!ce(this.dom,e))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof S){let n=this.docView.domAfterPos(this.state.selection.from);b(n)&&Mt(this,n.getBoundingClientRect(),e)}else Mt(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 n=0;n<this.directPlugins.length;n++){let o=this.directPlugins[n];o.spec.view&&this.pluginViews.push(o.spec.view(this))}for(let n=0;n<this.state.plugins.length;n++){let o=this.state.plugins[n];o.spec.view&&this.pluginViews.push(o.spec.view(this))}}else for(let n=0;n<this.pluginViews.length;n++){let o=this.pluginViews[n];o.update&&o.update(this,e)}}updateDraggedNode(e,n){let o=e.node,i=-1;if(o.from<this.state.doc.content.size&&this.state.doc.nodeAt(o.from)==o.node)i=o.from;else{let s=o.from+(this.state.doc.content.size-n.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==o.node&&(i=s)}this.dragging=new Le(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,n){let o=this._props&&this._props[e],i;if(o!=null&&(i=n?n(o):o))return i;for(let r=0;r<this.directPlugins.length;r++){let l=this.directPlugins[r].props[e];if(l!=null&&(i=n?n(l):l))return i}let s=this.state.plugins;if(s)for(let r=0;r<s.length;r++){let l=s[r].props[e];if(l!=null&&(i=n?n(l):l))return i}}hasFocus(){if(I){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&Xn(this.dom),j(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return vn(this,e)}coordsAtPos(e,n=1){return an(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,o=-1){let i=this.docView.posFromDOM(e,n,o);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return io(this,n||this.state,e)}pasteHTML(e,n){return xe(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return xe(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return bt(this,e)}destroy(){this.docView&&(Po(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],je(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ln())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Ro(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?A&&this.root.nodeType===11&&Hn(this.dom.ownerDocument)==this.dom&&vo(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};ut.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Xt(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let o in n)o=="class"?e.class+=" "+n[o]:o=="style"?e.style=(e.style?e.style+";":"")+n[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(n[o]))}),e.translate||(e.translate="no"),[Q.node(0,t.state.doc.content.size,e)]}function Jt(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:Q.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Zt(t){return!t.someProp("editable",e=>e(t.state)===!1)}function di(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Qt(t){let e=Object.create(null);function n(o){for(let i in o)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=o[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function fi(t,e){let n=0,o=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)o++;return n!=o}function wt(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}export{Q as Decoration,$ as DecorationSet,ut as EditorView,gi as __endComposition,mi as __parseFromClipboard};
//# sourceMappingURL=prosemirror-view.mjs.map