/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{NodeSelection as e,Selection as t,TextSelection as n,AllSelection as o}from"../../prosemirror-state/dist/index.js";import{Slice as i,DOMSerializer as s,Fragment as r,DOMParser as l,Mark as d}from"../../prosemirror-model/dist/index.js";import{dropPoint as a}from"../../prosemirror-transform/dist/index.js";const c=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},h=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let f=null;const u=function(e,t,n){let o=f||(f=document.createRange());return o.setEnd(e,null==n?e.nodeValue.length:n),o.setStart(e,t||0),o},p=function(e,t,n,o){return n&&(g(e,t,n,o,-1)||g(e,t,n,o,1))},m=/^(img|br|input|textarea|hr)$/i;function g(e,t,n,o,i){for(var s;;){if(e==n&&t==o)return!0;if(t==(i<0?0:y(e))){let n=e.parentNode;if(!n||1!=n.nodeType||b(e)||m.test(e.nodeName)||"false"==e.contentEditable)return!1;t=c(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(i<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(s=n.pmViewDesc)||void 0===s?void 0:s.ignoreForSelection))return!1;t+=i}else e=n,t=i<0?y(e):0}}}}function y(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function b(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const v=function(e){return e.focusNode&&p(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function w(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const D="undefined"!=typeof navigator?navigator:null,N="undefined"!=typeof document?document:null,S=D&&D.userAgent||"",C=/Edge\/(\d+)/.exec(S),O=/MSIE \d/.exec(S),M=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(S),x=!!(O||M||C),T=O?document.documentMode:M?+M[1]:C?+C[1]:0,k=!x&&/gecko\/(\d+)/i.test(S);k&&(/Firefox\/(\d+)/.exec(S)||[0,0])[1];const E=!x&&/Chrome\/(\d+)/.exec(S),P=!!E,A=E?+E[1]:0,V=!x&&!!D&&/Apple Computer/.test(D.vendor),R=V&&(/Mobile\/\w+/.test(S)||!!D&&D.maxTouchPoints>2),B=R||!!D&&/Mac/.test(D.platform),z=!!D&&/Win/.test(D.platform),I=/Android \d/.test(S),L=!!N&&"webkitFontSmoothing"in N.documentElement.style,F=L?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function $(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function q(e,t){return"number"==typeof e?e:e[t]}function K(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,o=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*o}}function W(e,t,n){let o=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,s=e.dom.ownerDocument;for(let r=n||e.dom;r;){if(1!=r.nodeType){r=h(r);continue}let e=r,n=e==s.body,l=n?$(s):K(e),d=0,a=0;if(t.top<l.top+q(o,"top")?a=-(l.top-t.top+q(i,"top")):t.bottom>l.bottom-q(o,"bottom")&&(a=t.bottom-t.top>l.bottom-l.top?t.top+q(i,"top")-l.top:t.bottom-l.bottom+q(i,"bottom")),t.left<l.left+q(o,"left")?d=-(l.left-t.left+q(i,"left")):t.right>l.right-q(o,"right")&&(d=t.right-l.right+q(i,"right")),d||a)if(n)s.defaultView.scrollBy(d,a);else{let n=e.scrollLeft,o=e.scrollTop;a&&(e.scrollTop+=a),d&&(e.scrollLeft+=d);let i=e.scrollLeft-n,s=e.scrollTop-o;t={left:t.left-i,top:t.top-s,right:t.right-i,bottom:t.bottom-s}}let c=n?"fixed":getComputedStyle(r).position;if(/^(fixed|sticky)$/.test(c))break;r="absolute"==c?r.offsetParent:h(r)}}function H(e){let t=[],n=e.ownerDocument;for(let o=e;o&&(t.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),e!=n);o=h(o));return t}function _(e,t){for(let n=0;n<e.length;n++){let{dom:o,top:i,left:s}=e[n];o.scrollTop!=i+t&&(o.scrollTop=i+t),o.scrollLeft!=s&&(o.scrollLeft=s)}}let G=null;function U(e,t){let n,o,i,s,r=2e8,l=0,d=t.top,a=t.top;for(let c=e.firstChild,h=0;c;c=c.nextSibling,h++){let e;if(1==c.nodeType)e=c.getClientRects();else{if(3!=c.nodeType)continue;e=u(c).getClientRects()}for(let f=0;f<e.length;f++){let u=e[f];if(u.top<=d&&u.bottom>=a){d=Math.max(u.bottom,d),a=Math.min(u.top,a);let e=u.left>t.left?u.left-t.left:u.right<t.left?t.left-u.right:0;if(e<r){n=c,r=e,o=e&&3==n.nodeType?{left:u.right<t.left?u.right:u.left,top:t.top}:t,1==c.nodeType&&e&&(l=h+(t.left>=(u.left+u.right)/2?1:0));continue}}else u.top>t.top&&!i&&u.left<=t.left&&u.right>=t.left&&(i=c,s={left:Math.max(u.left,Math.min(u.right,t.left)),top:u.top});!n&&(t.left>=u.right&&t.top>=u.top||t.left>=u.left&&t.top>=u.bottom)&&(l=h+1)}}return!n&&i&&(n=i,o=s,r=0),n&&3==n.nodeType?function(e,t){let n,o=e.nodeValue.length,i=document.createRange();for(let s=0;s<o;s++){i.setEnd(e,s+1),i.setStart(e,s);let o=Q(i,1);if(o.top!=o.bottom&&j(t,o)){n={node:e,offset:s+(t.left>=(o.left+o.right)/2?1:0)};break}}return i.detach(),n||{node:e,offset:0}}(n,o):!n||r&&1==n.nodeType?{node:e,offset:l}:U(n,o)}function j(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Y(e,t,n){let o=e.childNodes.length;if(o&&n.top<n.bottom)for(let i=Math.max(0,Math.min(o-1,Math.floor(o*(t.top-n.top)/(n.bottom-n.top))-2)),s=i;;){let n=e.childNodes[s];if(1==n.nodeType){let e=n.getClientRects();for(let o=0;o<e.length;o++){let i=e[o];if(j(t,i))return Y(n,t,i)}}if((s=(s+1)%o)==i)break}return e}function X(e,t){let n,o=e.dom.ownerDocument,i=0,s=function(e,t,n){if(e.caretPositionFromPoint)try{let o=e.caretPositionFromPoint(t,n);if(o)return{node:o.offsetNode,offset:Math.min(y(o.offsetNode),o.offset)}}catch(o){}if(e.caretRangeFromPoint){let o=e.caretRangeFromPoint(t,n);if(o)return{node:o.startContainer,offset:Math.min(y(o.startContainer),o.startOffset)}}}(o,t.left,t.top);s&&({node:n,offset:i}=s);let r,l=(e.root.elementFromPoint?e.root:o).elementFromPoint(t.left,t.top);if(!l||!e.dom.contains(1!=l.nodeType?l.parentNode:l)){let n=e.dom.getBoundingClientRect();if(!j(t,n))return null;if(l=Y(e.dom,t,n),!l)return null}if(V)for(let a=l;n&&a;a=h(a))a.draggable&&(n=void 0);if(l=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(l,t),n){if(k&&1==n.nodeType&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let e,o=n.childNodes[i];"IMG"==o.nodeName&&(e=o.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&i++}let o;L&&i&&1==n.nodeType&&1==(o=n.childNodes[i-1]).nodeType&&"false"==o.contentEditable&&o.getBoundingClientRect().top>=t.top&&i--,n==e.dom&&i==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?r=e.state.doc.content.size:0!=i&&1==n.nodeType&&"BR"==n.childNodes[i-1].nodeName||(r=function(e,t,n,o){let i=-1;for(let s=t,r=!1;s!=e.dom;){let t,n=e.docView.nearestDesc(s,!0);if(!n)return null;if(1==n.dom.nodeType&&(n.node.isBlock&&n.parent||!n.contentDOM)&&((t=n.dom.getBoundingClientRect()).width||t.height)&&(n.node.isBlock&&n.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(n.dom.nodeName)&&(!r&&t.left>o.left||t.top>o.top?i=n.posBefore:(!r&&t.right<o.left||t.bottom<o.top)&&(i=n.posAfter),r=!0),!n.contentDOM&&i<0&&!n.node.isText))return(n.node.isBlock?o.top<(t.top+t.bottom)/2:o.left<(t.left+t.right)/2)?n.posBefore:n.posAfter;s=n.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,n,i,t))}null==r&&(r=function(e,t,n){let{node:o,offset:i}=U(t,n),s=-1;if(1==o.nodeType&&!o.firstChild){let e=o.getBoundingClientRect();s=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(o,i,s)}(e,l,t));let d=e.docView.nearestDesc(l,!0);return{pos:r,inside:d?d.posAtStart-d.border:-1}}function J(e){return e.top<e.bottom||e.left<e.right}function Q(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(J(e))return e}return Array.prototype.find.call(n,J)||e.getBoundingClientRect()}const Z=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ee(e,t,n){let{node:o,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),r=L||k;if(3==o.nodeType){if(!r||!Z.test(o.nodeValue)&&(n<0?i:i!=o.nodeValue.length)){let e=i,t=i,s=n<0?1:-1;return n<0&&!i?(t++,s=-1):n>=0&&i==o.nodeValue.length?(e--,s=1):n<0?e--:t++,te(Q(u(o,e,t),s),s<0)}{let e=Q(u(o,i,i),n);if(k&&i&&/\s/.test(o.nodeValue[i-1])&&i<o.nodeValue.length){let t=Q(u(o,i-1,i-1),-1);if(t.top==e.top){let n=Q(u(o,i,i+1),-1);if(n.top!=e.top)return te(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==y(o))){let e=o.childNodes[i-1];if(1==e.nodeType)return ne(e.getBoundingClientRect(),!1)}if(null==s&&i<y(o)){let e=o.childNodes[i];if(1==e.nodeType)return ne(e.getBoundingClientRect(),!0)}return ne(o.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==y(o))){let e=o.childNodes[i-1],t=3==e.nodeType?u(e,y(e)-(r?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return te(Q(t,1),!1)}if(null==s&&i<y(o)){let e=o.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?u(e,0,r?0:1):1==e.nodeType?e:null:null;if(t)return te(Q(t,-1),!0)}return te(Q(3==o.nodeType?u(o):o,-n),n>=0)}function te(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function ne(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function oe(e,t,n){let o=e.state,i=e.root.activeElement;o!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{o!=t&&e.updateState(o),i!=e.dom&&i&&i.focus()}}const ie=/[\u0590-\u08ac]/;let se=null,re=null,le=!1;function de(e,t,n){return se==t&&re==n?le:(se=t,re=n,le="up"==n||"down"==n?function(e,t,n){let o=t.selection,i="up"==n?o.$from:o.$to;return oe(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let o=ee(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=u(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&("up"==n?o.top-i.top>2*(i.bottom-o.top):i.bottom-o.bottom>2*(o.bottom-i.top)))return!1}}return!0})}(e,t,n):function(e,t,n){let{$head:o}=t.selection;if(!o.parent.isTextblock)return!1;let i=o.parentOffset,s=!i,r=i==o.parent.content.size,l=e.domSelection();return l?ie.test(o.parent.textContent)&&l.modify?oe(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:s,anchorOffset:r}=e.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",n,"character");let a=o.depth?e.docView.domAfterPos(o.before()):e.dom,{focusNode:c,focusOffset:h}=e.domSelectionRange(),f=c&&!a.contains(1==c.nodeType?c:c.parentNode)||t==c&&i==h;try{l.collapse(s,r),t&&(t!=s||i!=r)&&l.extend&&l.extend(t,i)}catch(u){}return null!=d&&(l.caretBidiLevel=d),f}):"left"==n||"backward"==n?s:r:o.pos==o.start()||o.pos==o.end()}(e,t,n))}class ae{constructor(e,t,n,o){this.parent=e,this.children=t,this.dom=n,this.contentDOM=o,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let o=this.children[t];if(o==e)return n;n+=o.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode)){if(n<0){let n,o;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(o)+o.size:this.posAtStart}{let n,o;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(o):this.posAtEnd}}let o;if(e==this.dom&&this.contentDOM)o=t>c(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!1;break}if(t.previousSibling)break}if(null==o&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!0;break}if(t.nextSibling)break}}return(null==o?n>0:o)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,o=e;o;o=o.parentNode){let i,s=this.getDesc(o);if(s&&(!t||s.node)){if(!n||!(i=s.nodeDOM)||(1==i.nodeType?i.contains(1==e.nodeType?e:e.parentNode):i==e))return s;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let o=e;o;o=o.parentNode){let i=this.getDesc(o);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let o=this.children[t],i=n+o.size;if(n==e&&i!=n){for(;!o.border&&o.children.length;)for(let e=0;e<o.children.length;e++){let t=o.children[e];if(t.size){o=t;break}}return o}if(e<i)return o.descAt(e-n-o.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,o=0;for(let i=0;n<this.children.length;n++){let t=this.children[n],s=i+t.size;if(s>e||t instanceof ge){o=e-i;break}i=s}if(o)return this.children[n].domFromPos(o-this.children[n].border,t);for(let i;n&&!(i=this.children[n-1]).size&&i instanceof ce&&i.side>=0;n--);if(t<=0){let e,o=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,o=!1);return e&&t&&o&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?c(e.dom)+1:0}}{let e,o=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,o=!1);return e&&o&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?c(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let o=-1,i=-1;for(let s=n,r=0;;r++){let n=this.children[r],l=s+n.size;if(-1==o&&e<=l){let i=s+n.border;if(e>=i&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=s;for(let t=r;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){o=c(n.dom)+1;break}e-=n.size}-1==o&&(o=0)}if(o>-1&&(l>t||r==this.children.length-1)){t=l;for(let e=r+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=c(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}s=l}return{node:this.contentDOM,from:e,to:t,fromOffset:o,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,o=!1){let i=Math.min(e,t),s=Math.max(e,t);for(let c=0,p=0;c<this.children.length;c++){let r=this.children[c],l=p+r.size;if(i>p&&s<l)return r.setSelection(e-p-r.border,t-p-r.border,n,o);p=l}let r=this.domFromPos(e,e?-1:1),l=t==e?r:this.domFromPos(t,t?-1:1),d=n.root.getSelection(),a=n.domSelectionRange(),h=!1;if((k||V)&&e==t){let{node:e,offset:t}=r;if(3==e.nodeType){if(h=!(!t||"\n"!=e.nodeValue[t-1]),h&&t==e.nodeValue.length)for(let n,o=e;o;o=o.parentNode){if(n=o.nextSibling){"BR"==n.nodeName&&(r=l={node:n.parentNode,offset:c(n)+1});break}let e=o.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];h=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(k&&a.focusNode&&a.focusNode!=l.node&&1==a.focusNode.nodeType){let e=a.focusNode.childNodes[a.focusOffset];e&&"false"==e.contentEditable&&(o=!0)}if(!(o||h&&V)&&p(r.node,r.offset,a.anchorNode,a.anchorOffset)&&p(l.node,l.offset,a.focusNode,a.focusOffset))return;let f=!1;if((d.extend||e==t)&&(!h||!k)){d.collapse(r.node,r.offset);try{e!=t&&d.extend(l.node,l.offset),f=!0}catch(u){}}if(!f){if(e>t){let e=r;r=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(r.node,r.offset),d.removeAllRanges(),d.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,o=0;o<this.children.length;o++){let i=this.children[o],s=n+i.size;if(n==s?e<=s&&t>=n:e<s&&t>n){let o=n+i.border,r=s-i.border;if(e>=o&&t<=r)return this.dirty=e==n||t==s?2:1,void(e!=o||t!=r||!i.contentLost&&i.dom.parentNode==this.contentDOM?i.markDirty(e-o,t-o):i.dirty=3);i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=s}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ce extends ae{constructor(e,t,n,o){let i,s=t.type.toDOM;if("function"==typeof s&&(s=s(n,()=>i?i.parent?i.parent.posBeforeChild(i):void 0:o)),!t.type.spec.raw){if(1!=s.nodeType){let e=document.createElement("span");e.appendChild(s),s=e}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class he extends ae{constructor(e,t,n,o){super(e,[],t,null),this.textDOM=n,this.text=o}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class fe extends ae{constructor(e,t,n,o,i){super(e,[],n,o),this.mark=t,this.spec=i}static create(e,t,n,o){let i=o.nodeViews[t.type.name],r=i&&i(t,o,n);return r&&r.dom||(r=s.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new fe(e,t,r.dom,r.contentDOM||r.dom,r)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let o=fe.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=ke(i,t,s,n)),e>0&&(i=ke(i,0,e,n));for(let r=0;r<i.length;r++)i[r].parent=o;return o.children=i,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class ue extends ae{constructor(e,t,n,o,i,s,r,l,d){super(e,[],i,s),this.node=t,this.outerDeco=n,this.innerDeco=o,this.nodeDOM=r}static create(e,t,n,o,i,r){let l,d=i.nodeViews[t.type.name],a=d&&d(t,i,()=>l?l.parent?l.parent.posBeforeChild(l):void 0:r,n,o),c=a&&a.dom,h=a&&a.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=s.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:h}=e)}h||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let f=c;return c=Ce(c,n,t),a?l=new ye(e,t,n,o,c,h||null,f,a,i,r+1):t.isText?new me(e,t,n,o,c,f,i):new ue(e,t,n,o,c,h||null,f,i,r+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>r.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&Oe(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,o=t,i=e.composing?this.localCompositionInfo(e,t):null,s=i&&i.pos>-1?i:null,r=i&&i.pos<0,l=new xe(this,s&&s.node,e);!function(e,t,n,o){let i=t.locals(e),s=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let r=e.child(n);o(r,i,t.forChild(s,r),n),s+=r.nodeSize}return}let r=0,l=[],d=null;for(let a=0;;){let c,h,f,u;for(;r<i.length&&i[r].to==s;){let e=i[r++];e.widget&&(c?(h||(h=[c])).push(e):c=e)}if(c)if(h){h.sort(Te);for(let e=0;e<h.length;e++)n(h[e],a,!!d)}else n(c,a,!!d);if(d)u=-1,f=d,d=null;else{if(!(a<e.childCount))break;u=a,f=e.child(a++)}for(let e=0;e<l.length;e++)l[e].to<=s&&l.splice(e--,1);for(;r<i.length&&i[r].from<=s&&i[r].to>s;)l.push(i[r++]);let p=s+f.nodeSize;if(f.isText){let e=p;r<i.length&&i[r].from<e&&(e=i[r].from);for(let t=0;t<l.length;t++)l[t].to<e&&(e=l[t].to);e<p&&(d=f.cut(e-s),f=f.cut(0,e-s),p=e,u=-1)}else for(;r<i.length&&i[r].to<p;)r++;o(f,f.isInline&&!f.isLeaf?l.filter(e=>!e.inline):l.slice(),t.forChild(s,f),u),s=p}}(this.node,this.innerDeco,(t,i,s)=>{t.spec.marks?l.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!s&&l.syncToMarks(i==this.node.childCount?d.none:this.node.child(i).marks,n,e,i),l.placeWidget(t,e,o)},(t,s,d,a)=>{let c;l.syncToMarks(t.marks,n,e,a),l.findNodeMatch(t,s,d,a)||r&&e.state.selection.from>o&&e.state.selection.to<o+t.nodeSize&&(c=l.findIndexWithChild(i.node))>-1&&l.updateNodeAt(t,s,d,c,e)||l.updateNextNode(t,s,d,e,a,o)||l.addNode(t,s,d,e,o),o+=t.nodeSize}),l.syncToMarks([],n,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||2==this.dirty)&&(s&&this.protectLocalComposition(e,s),be(this.contentDOM,this.children,e),R&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:o,to:i}=e.state.selection;if(!(e.state.selection instanceof n)||o<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let e=s.nodeValue,n=function(e,t,n,o){for(let i=0,s=0;i<e.childCount&&s<=o;){let r=e.child(i++),l=s;if(s+=r.nodeSize,!r.isText)continue;let d=r.text;for(;i<e.childCount;){let t=e.child(i++);if(s+=t.nodeSize,!t.isText)break;d+=t.text}if(s>=n){if(s>=o&&d.slice(o-t.length-l,o-l)==t)return o-t.length;let e=l<o?d.lastIndexOf(t,o-l-1):-1;if(e>=0&&e+t.length+l>=n)return l+e;if(n==o&&d.length>=o+t.length-l&&d.slice(o-l,o-l+t.length)==t)return o}}return-1}(this.node.content,e,o-t,i-t);return n<0?null:{node:s,pos:n,text:e}}return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:o}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let s=new he(this,i,t,o);e.input.compositionNodes.push(s),this.children=ke(this.children,n,n+o.length,e,s)}update(e,t,n,o){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,o),!0)}updateInner(e,t,n,o){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(Oe(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=Ne(this.dom,this.nodeDOM,De(this.outerDeco,this.node,t),De(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function pe(e,t,n,o,i){Ce(o,t,e);let s=new ue(void 0,e,t,n,o,o,o,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class me extends ue{constructor(e,t,n,o,i,s,r){super(e,t,n,o,i,null,s,r,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,o){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,o.trackWrites==this.nodeDOM&&(o.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let o=this.node.cut(e,t),i=document.createTextNode(o.text);return new me(this.parent,o,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ge extends ae{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class ye extends ue{constructor(e,t,n,o,i,s,r,l,d,a){super(e,t,n,o,i,s,r,d,a),this.spec=l}update(e,t,n,o){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,o),i}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,o){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,o)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function be(e,t,n){let o=e.firstChild,i=!1;for(let s=0;s<t.length;s++){let r=t[s],l=r.dom;if(l.parentNode==e){for(;l!=o;)o=Me(o),i=!0;o=o.nextSibling}else i=!0,e.insertBefore(l,o);if(r instanceof fe){let t=o?o.previousSibling:e.lastChild;be(r.contentDOM,r.children,n),o=t?t.nextSibling:e.firstChild}}for(;o;)o=Me(o),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}const ve=function(e){e&&(this.nodeName=e)};ve.prototype=/* @__PURE__ */Object.create(null);const we=[new ve];function De(e,t,n){if(0==e.length)return we;let o=n?we[0]:new ve,i=[o];for(let s=0;s<e.length;s++){let r=e[s].type.attrs;if(r){r.nodeName&&i.push(o=new ve(r.nodeName));for(let e in r){let s=r[e];null!=s&&(n&&1==i.length&&i.push(o=new ve(t.isInline?"span":"div")),"class"==e?o.class=(o.class?o.class+" ":"")+s:"style"==e?o.style=(o.style?o.style+";":"")+s:"nodeName"!=e&&(o[e]=s))}}}return i}function Ne(e,t,n,o){if(n==we&&o==we)return t;let i=t;for(let s=0;s<o.length;s++){let t=o[s],r=n[s];if(s){let n;r&&r.nodeName==t.nodeName&&i!=e&&(n=i.parentNode)&&n.nodeName.toLowerCase()==t.nodeName||(n=document.createElement(t.nodeName),n.pmIsDeco=!0,n.appendChild(i),r=we[0]),i=n}Se(i,r||we[0],t)}return i}function Se(e,t,n){for(let o in t)"class"==o||"style"==o||"nodeName"==o||o in n||e.removeAttribute(o);for(let o in n)"class"!=o&&"style"!=o&&"nodeName"!=o&&n[o]!=t[o]&&e.setAttribute(o,n[o]);if(t.class!=n.class){let o=t.class?t.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<o.length;t++)-1==i.indexOf(o[t])&&e.classList.remove(o[t]);for(let t=0;t<i.length;t++)-1==o.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n,o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=o.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function Ce(e,t,n){return Ne(e,e,we,De(t,n,1!=e.nodeType))}function Oe(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function Me(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class xe{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,o=n.children.length,i=e.childCount,s=/* @__PURE__ */new Map,r=[];e:for(;i>0;){let l;for(;;)if(o){let e=n.children[o-1];if(!(e instanceof fe)){l=e,o--;break}n=e,o=e.children.length}else{if(n==t)break e;o=n.parent.children.indexOf(n),n=n.parent}let d=l.node;if(d){if(d!=e.child(i-1))break;--i,s.set(l,i),r.push(l)}}return{index:i,matched:s,matches:r.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,o){let i=0,s=this.stack.length>>1,r=Math.min(s,e.length);for(;i<r&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&!1!==e[i].type.spec.spanning;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let i=-1,r=this.top.children.length;o<this.preMatch.index&&(r=Math.min(this.index+3,r));for(let t=this.index;t<r;t++){let n=this.top.children[t];if(n.matchesMark(e[s])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let o=fe.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,o),this.top=o,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,o){let i,s=-1;if(o>=this.preMatch.index&&(i=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,n))s=this.top.children.indexOf(i,this.index);else for(let r=this.index,l=Math.min(this.top.children.length,r+5);r<l;r++){let o=this.top.children[r];if(o.matchesNode(e,t,n)&&!this.preMatch.matched.has(o)){s=r;break}}return!(s<0)&&(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,n,o,i){let s=this.top.children[o];return 3==s.dirty&&s.dom==s.contentDOM&&(s.dirty=2),!!s.update(e,t,n,i)&&(this.destroyBetween(this.index,o),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t)for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e;return-1}e=t}}updateNextNode(e,t,n,o,i,s){for(let r=this.index;r<this.top.children.length;r++){let l=this.top.children[r];if(l instanceof ue){let d=this.preMatch.matched.get(l);if(null!=d&&d!=i)return!1;let a,c=l.dom,h=this.isLocked(c)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&3!=l.dirty&&Oe(t,l.outerDeco));if(!h&&l.update(e,t,n,o))return this.destroyBetween(this.index,r),l.dom!=c&&(this.changed=!0),this.index++,!0;if(!h&&(a=this.recreateWrapper(l,e,t,n,o,s)))return this.destroyBetween(this.index,r),this.top.children[this.index]=a,a.contentDOM&&(a.dirty=2,a.updateChildren(o,s+1),a.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,o,i,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Oe(n,e.outerDeco)||!o.eq(e.innerDeco))return null;let r=ue.create(this.top,t,n,o,i,s);if(r.contentDOM){r.children=e.children,e.children=[];for(let e of r.children)e.parent=r}return e.destroy(),r}addNode(e,t,n,o,i){let s=ue.create(this.top,e,t,n,o,i);s.contentDOM&&s.updateChildren(o,i+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,n){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(!o||!o.matchesWidget(e)||e!=o.widget&&o.widget.type.toDOM.parentNode){let o=new ce(this.top,e,t,n);this.top.children.splice(this.index++,0,o),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof fe;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof me)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((V||P)&&e&&"false"==e.dom.contentEditable&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let o=new ge(this.top,[],n,null);t!=this.top?t.children.push(o):t.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function Te(e,t){return e.type.side-t.type.side}function ke(e,t,n,o,i){let s=[];for(let r=0,l=0;r<e.length;r++){let d=e[r],a=l,c=l+=d.size;a>=n||c<=t?s.push(d):(a<t&&s.push(d.slice(0,t-a,o)),i&&(s.push(i),i=void 0),c>n&&s.push(d.slice(n-a,d.size,o)))}return s}function Ee(t,n=null){let o=t.domSelectionRange(),i=t.state.doc;if(!o.focusNode)return null;let s=t.docView.nearestDesc(o.focusNode),r=s&&0==s.size,l=t.docView.posFromDOM(o.focusNode,o.focusOffset,1);if(l<0)return null;let d,a,h=i.resolve(l);if(v(o)){for(d=l;s&&!s.node;)s=s.parent;let t=s.node;if(s&&t.isAtom&&e.isSelectable(t)&&s.parent&&(!t.isInline||!function(e,t,n){for(let o=0==t,i=t==y(e);o||i;){if(e==n)return!0;let t=c(e);if(!(e=e.parentNode))return!1;o=o&&0==t,i=i&&t==y(e)}}(o.focusNode,o.focusOffset,s.dom))){let t=s.posBefore;a=new e(l==t?h:i.resolve(t))}}else{if(o instanceof t.dom.ownerDocument.defaultView.Selection&&o.rangeCount>1){let e=l,n=l;for(let i=0;i<o.rangeCount;i++){let s=o.getRangeAt(i);e=Math.min(e,t.docView.posFromDOM(s.startContainer,s.startOffset,1)),n=Math.max(n,t.docView.posFromDOM(s.endContainer,s.endOffset,-1))}if(e<0)return null;[d,l]=n==t.state.selection.anchor?[n,e]:[e,n],h=i.resolve(l)}else d=t.docView.posFromDOM(o.anchorNode,o.anchorOffset,1);if(d<0)return null}let f=i.resolve(d);if(!a){a=Fe(t,f,h,"pointer"==n||t.state.selection.head<h.pos&&!r?1:-1)}return a}function Pe(e){return e.editable?e.hasFocus():qe(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function Ae(e,t=!1){let o=e.state.selection;if(Ie(e,o),Pe(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&P){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&p(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset))return e.input.mouseDown.delayedSelectionSync=!0,void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,o="IMG"==n.nodeName;o?t.collapse(n.parentNode,c(n)+1):t.collapse(n,0);!o&&!e.state.selection.visible&&x&&T<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let i,s,{anchor:r,head:l}=o;!Ve||o instanceof n||(o.$from.parent.inlineContent||(i=Re(e,o.from)),o.empty||o.$from.parent.inlineContent||(s=Re(e,o.to))),e.docView.setSelection(r,l,e,t),Ve&&(i&&ze(i),s&&ze(s)),o.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),o=n.anchorNode,i=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==i||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{Pe(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const Ve=V||P&&A<63;function Re(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),i=o<n.childNodes.length?n.childNodes[o]:null,s=o?n.childNodes[o-1]:null;if(V&&i&&"false"==i.contentEditable)return Be(i);if(!(i&&"false"!=i.contentEditable||s&&"false"!=s.contentEditable)){if(i)return Be(i);if(s)return Be(s)}}function Be(e){return e.contentEditable="true",V&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ze(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function Ie(t,n){if(n instanceof e){let e=t.docView.descAt(n.from);e!=t.lastSelectedViewDesc&&(Le(t),e&&e.selectNode(),t.lastSelectedViewDesc=e)}else Le(t)}function Le(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Fe(e,t,o,i){return e.someProp("createSelectionBetween",n=>n(e,t,o))||n.between(t,o,i)}function $e(e){return!(e.editable&&!e.hasFocus())&&qe(e)}function qe(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}function Ke(e,n){let{$anchor:o,$head:i}=e.selection,s=n>0?o.max(i):o.min(i),r=s.parent.inlineContent?s.depth?e.doc.resolve(n>0?s.after():s.before()):null:s;return r&&t.findFrom(r,n)}function We(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function He(t,o,i){let s=t.state.selection;if(!(s instanceof n)){if(s instanceof e&&s.node.isInline)return We(t,new n(o>0?s.$to:s.$from));{let e=Ke(t.state,o);return!!e&&We(t,e)}}if(i.indexOf("s")>-1){let{$head:e}=s,i=e.textOffset?null:o<0?e.nodeBefore:e.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let r=t.state.doc.resolve(e.pos+i.nodeSize*(o<0?-1:1));return We(t,new n(s.$anchor,r))}if(!s.empty)return!1;if(t.endOfTextblock(o>0?"forward":"backward")){let n=Ke(t.state,o);return!!(n&&n instanceof e)&&We(t,n)}if(!(B&&i.indexOf("m")>-1)){let i,r=s.$head,l=r.textOffset?null:o<0?r.nodeBefore:r.nodeAfter;if(!l||l.isText)return!1;let d=o<0?r.pos-l.nodeSize:r.pos;return!!(l.isAtom||(i=t.docView.descAt(d))&&!i.contentDOM)&&(e.isSelectable(l)?We(t,new e(o<0?t.state.doc.resolve(r.pos-l.nodeSize):r)):!!L&&We(t,new n(t.state.doc.resolve(o<0?d:d+l.nodeSize))))}}function _e(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Ge(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function Ue(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let i,s,r=!1;k&&1==n.nodeType&&o<_e(n)&&Ge(n.childNodes[o],-1)&&(r=!0);for(;;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(Ge(e,-1))i=n,s=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(je(n))break;{let t=n.previousSibling;for(;t&&Ge(t,-1);)i=n.parentNode,s=c(t),t=t.previousSibling;if(t)n=t,o=_e(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}r?Ye(e,n,o):i&&Ye(e,i,s)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let i,s,r=_e(n);for(;;)if(o<r){if(1!=n.nodeType)break;if(!Ge(n.childNodes[o],1))break;i=n,s=++o}else{if(je(n))break;{let t=n.nextSibling;for(;t&&Ge(t,1);)i=t.parentNode,s=c(t)+1,t=t.nextSibling;if(t)n=t,o=0,r=_e(n);else{if(n=n.parentNode,n==e.dom)break;o=r=0}}}i&&Ye(e,i,s)}(e)}function je(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Ye(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!b(e);)t=c(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!b(e);)t=c(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(v(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&Ae(e)},50)}function Xe(e,t){let n=e.state.doc.resolve(t);if(!P&&!z&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Je(i,s,r){let l=i.state.selection;if(l instanceof n&&!l.empty||r.indexOf("s")>-1)return!1;if(B&&r.indexOf("m")>-1)return!1;let{$from:d,$to:a}=l;if(!d.parent.inlineContent||i.endOfTextblock(s<0?"up":"down")){let t=Ke(i.state,s);if(t&&t instanceof e)return We(i,t)}if(!d.parent.inlineContent){let e=s<0?d:a,n=l instanceof o?t.near(e,s):t.findFrom(e,s);return!!n&&We(i,n)}return!1}function Qe(e,t){if(!(e.state.selection instanceof n))return!0;let{$head:o,$anchor:i,empty:s}=e.state.selection;if(!o.sameParent(i))return!0;if(!s)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let r=!o.textOffset&&(t<0?o.nodeBefore:o.nodeAfter);if(r&&!r.isText){let n=e.state.tr;return t<0?n.delete(o.pos-r.nodeSize,o.pos):n.delete(o.pos,o.pos+r.nodeSize),e.dispatch(n),!0}return!1}function Ze(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function et(e,t){let n=t.keyCode,o=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||B&&72==n&&"c"==o)return Qe(e,-1)||Ue(e,-1);if(46==n&&!t.shiftKey||B&&68==n&&"c"==o)return Qe(e,1)||Ue(e,1);if(13==n||27==n)return!0;if(37==n||B&&66==n&&"c"==o){let t=37==n?"ltr"==Xe(e,e.state.selection.from)?-1:1:-1;return He(e,t,o)||Ue(e,t)}if(39==n||B&&70==n&&"c"==o){let t=39==n?"ltr"==Xe(e,e.state.selection.from)?1:-1:1;return He(e,t,o)||Ue(e,t)}return 38==n||B&&80==n&&"c"==o?Je(e,-1,o)||Ue(e,-1):40==n||B&&78==n&&"c"==o?function(e){if(!V||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Ze(e,n,"true"),setTimeout(()=>Ze(e,n,"false"),20)}return!1}(e)||Je(e,1,o)||Ue(e,1):o==(B?"m":"c")&&(66==n||73==n||89==n||90==n)}function tt(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:o,openStart:i,openEnd:r}=t;for(;i>1&&r>1&&1==o.childCount&&1==o.firstChild.childCount;){i--,r--;let e=o.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),o=e.content}let l=e.someProp("clipboardSerializer")||s.fromSchema(e.state.schema),d=ht(),a=d.createElement("div");a.appendChild(l.serializeFragment(o,{document:d}));let c,h=a.firstChild,f=0;for(;h&&1==h.nodeType&&(c=at[h.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=d.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),f++}h=a.firstChild}return h&&1==h.nodeType&&h.setAttribute("data-pm-slice",`${i} ${r}${f?` -${f}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function nt(e,t,n,o,d){let a,c,h=d.parent.type.spec.code;if(!n&&!t)return null;let f=!!t&&(o||h||!n);if(f){if(e.someProp("transformPastedText",n=>{t=n(t,h||o,e)}),h)return c=new i(r.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{c=t(c,e,!0)}),c;let n=e.someProp("clipboardTextParser",n=>n(t,d,o,e));if(n)c=n;else{let n=d.marks(),{schema:o}=e.state,i=s.fromSchema(o);a=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=a.appendChild(document.createElement("p"));e&&t.appendChild(i.serializeNode(o.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),a=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,o=ht().createElement("div"),i=/<([a-z][^>\s]+)/i.exec(e);(n=i&&at[i[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join(""));if(o.innerHTML=function(e){let t=window.trustedTypes;if(!t)return e;ft||(ft=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e}));return ft.createHTML(e)}(e),n)for(let s=0;s<n.length;s++)o=o.querySelector(n[s])||o;return o}(n),L&&function(e){let t=e.querySelectorAll(P?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let o=t[n];1==o.childNodes.length&&" "==o.textContent&&o.parentNode&&o.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),o)}}(a);let u=a&&a.querySelector("[data-pm-slice]"),p=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(p&&p[3])for(let i=+p[3];i>0;i--){let e=a.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;a=e}if(!c){let t=e.someProp("clipboardParser")||e.someProp("domParser")||l.fromSchema(e.state.schema);c=t.parseSlice(a,{preserveWhitespace:!(!f&&!p),context:d,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||ot.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(p)c=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(a){return e}let{content:s,openStart:l,openEnd:d}=e;for(let i=n.length-2;i>=0;i-=2){let e=o.nodes[n[i]];if(!e||e.hasRequiredAttrs())break;s=r.from(e.create(n[i+1],s)),l++,d++}return new i(s,l,d)}(dt(c,+p[1],+p[2]),p[4]);else if(c=i.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,i=t.node(n).contentMatchAt(t.index(n)),s=[];if(e.forEach(e=>{if(!s)return;let t,n=i.findWrapping(e.type);if(!n)return s=null;if(t=s.length&&o.length&&st(n,o,e,s[s.length-1],0))s[s.length-1]=t;else{s.length&&(s[s.length-1]=rt(s[s.length-1],o.length));let t=it(e,n);s.push(t),i=i.matchType(t.type),o=n}}),s)return r.from(s)}return e}(c.content,d),!0),c.openStart||c.openEnd){let e=0,t=0;for(let n=c.content.firstChild;e<c.openStart&&!n.type.spec.isolating;e++,n=n.firstChild);for(let n=c.content.lastChild;t<c.openEnd&&!n.type.spec.isolating;t++,n=n.lastChild);c=dt(c,e,t)}return e.someProp("transformPasted",t=>{c=t(c,e,f)}),c}const ot=/^(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 it(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,r.from(e));return e}function st(e,t,n,o,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let s=st(e,t,n,o.lastChild,i+1);if(s)return o.copy(o.content.replaceChild(o.childCount-1,s));if(o.contentMatchAt(o.childCount).matchType(i==e.length-1?n.type:e[i+1]))return o.copy(o.content.append(r.from(it(n,e,i+1))))}}function rt(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,rt(e.lastChild,t-1)),o=e.contentMatchAt(e.childCount).fillBefore(r.empty,!0);return e.copy(n.append(o))}function lt(e,t,n,o,i,s){let l=t<0?e.firstChild:e.lastChild,d=l.content;return e.childCount>1&&(s=0),i<o-1&&(d=lt(d,t,n,o,i+1,s)),i>=n&&(d=t<0?l.contentMatchAt(0).fillBefore(d,s<=i).append(d):d.append(l.contentMatchAt(l.childCount).fillBefore(r.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,l.copy(d))}function dt(e,t,n){return t<e.openStart&&(e=new i(lt(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new i(lt(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const at={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let ct=null;function ht(){return ct||(ct=document.implementation.createHTMLDocument("title"))}let ft=null;const ut={},pt={},mt={touchstart:!0,touchmove:!0};class gt{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=/* @__PURE__ */Object.create(null),this.hideSelectionGuard=null}}function yt(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function bt(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>vt(e,t))})}function vt(e,t){return e.someProp("handleDOMEvents",n=>{let o=n[t.type];return!!o&&(o(e,t)||t.defaultPrevented)})}function wt(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Dt(e){return{left:e.clientX,top:e.clientY}}function Nt(e,t,n,o,i){if(-1==o)return!1;let s=e.state.doc.resolve(o);for(let r=s.depth+1;r>0;r--)if(e.someProp(t,t=>r>s.depth?t(e,n,s.nodeAfter,s.before(r),i,!0):t(e,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function St(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let o=e.state.tr.setSelection(t);o.setMeta("pointer",!0),e.dispatch(o)}function Ct(t,n,o,i,s){return Nt(t,"handleClickOn",n,o,i)||t.someProp("handleClick",e=>e(t,n,i))||(s?function(t,n){if(-1==n)return!1;let o,i,s=t.state.selection;s instanceof e&&(o=s.node);let r=t.state.doc.resolve(n);for(let l=r.depth+1;l>0;l--){let t=l>r.depth?r.nodeAfter:r.node(l);if(e.isSelectable(t)){i=o&&s.$from.depth>0&&l>=s.$from.depth&&r.before(s.$from.depth+1)==s.$from.pos?r.before(s.$from.depth):r.before(l);break}}return null!=i&&(St(t,e.create(t.state.doc,i)),!0)}(t,o):function(t,n){if(-1==n)return!1;let o=t.state.doc.resolve(n),i=o.nodeAfter;return!!(i&&i.isAtom&&e.isSelectable(i))&&(St(t,new e(o)),!0)}(t,o))}function Ot(e,t,n,o){return Nt(e,"handleDoubleClickOn",t,n,o)||e.someProp("handleDoubleClick",n=>n(e,t,o))}function Mt(t,o,i,s){return Nt(t,"handleTripleClickOn",o,i,s)||t.someProp("handleTripleClick",e=>e(t,o,s))||function(t,o,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==o)return!!s.inlineContent&&(St(t,n.create(s,0,s.content.size)),!0);let r=s.resolve(o);for(let l=r.depth+1;l>0;l--){let o=l>r.depth?r.nodeAfter:r.node(l),i=r.before(l);if(o.inlineContent)St(t,n.create(s,i+1,i+1+o.content.size));else{if(!e.isSelectable(o))continue;St(t,e.create(s,i))}return!0}}(t,i,s)}function xt(e){return Bt(e)}pt.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!Et(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!I||!P||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!R||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||et(e,n)?n.preventDefault():yt(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,w(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},pt.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},pt.keypress=(e,t)=>{let o=t;if(Et(e,o)||!o.charCode||o.ctrlKey&&!o.altKey||B&&o.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,o)))return void o.preventDefault();let i=e.state.selection;if(!(i instanceof n&&i.$from.sameParent(i.$to))){let t=String.fromCharCode(o.charCode),n=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",o=>o(e,i.$from.pos,i.$to.pos,t,n))||e.dispatch(n()),o.preventDefault()}};const Tt=B?"metaKey":"ctrlKey";ut.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let o=xt(e),i=Date.now(),s="singleClick";i-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,o=t.y-e.clientY;return n*n+o*o<100}(n,e.input.lastClick)&&!n[Tt]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?s="doubleClick":"doubleClick"==e.input.lastClick.type&&(s="tripleClick")),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:s,button:n.button};let r=e.posAtCoords(Dt(n));r&&("singleClick"==s?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new kt(e,r,n,!!o)):("doubleClick"==s?Ot:Mt)(e,r.pos,r.inside,n)?n.preventDefault():yt(e,"pointer"))};class kt{constructor(t,n,o,i){let s,r;if(this.view=t,this.pos=n,this.event=o,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!o[Tt],this.allowDefault=o.shiftKey,n.inside>-1)s=t.state.doc.nodeAt(n.inside),r=n.inside;else{let e=t.state.doc.resolve(n.pos);s=e.parent,r=e.depth?e.before():0}const l=i?null:o.target,d=l?t.docView.nearestDesc(l,!0):null;this.target=d&&1==d.nodeDOM.nodeType?d.nodeDOM:null;let{selection:a}=t.state;(0==o.button&&s.type.spec.draggable&&!1!==s.type.spec.selectable||a instanceof e&&a.from<=r&&a.to>r)&&(this.mightDrag={node:s,pos:r,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!k||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()),t.root.addEventListener("mouseup",this.up=this.up.bind(this)),t.root.addEventListener("mousemove",this.move=this.move.bind(this)),yt(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>Ae(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(Dt(e))),this.updateAllowDefault(e),this.allowDefault||!n?yt(this.view,"pointer"):Ct(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||V&&this.mightDrag&&!this.mightDrag.node.isAtom||P&&!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)?(St(this.view,t.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):yt(this.view,"pointer")}move(e){this.updateAllowDefault(e),yt(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function Et(e,t){return!!e.composing||!!(V&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}ut.touchstart=e=>{e.input.lastTouch=Date.now(),xt(e),yt(e,"pointer")},ut.touchmove=e=>{e.input.lastTouch=Date.now(),yt(e,"pointer")},ut.contextmenu=e=>xt(e);const Pt=I?5e3:-1;function At(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Bt(e),t))}function Vt(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent("Event");return e.initEvent("event",!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Rt(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=y(e=e.childNodes[t-1])}else{if(!e.parentNode||b(e))return null;t=c(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),o=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||b(e))return null;t=c(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&o&&n!=o){let t=o.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||o==i)return i;if(!t||!t.isText(o.nodeValue))return o;if(e.input.compositionNode==o){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return o}}return n||o}function Bt(e,t=!1){if(!(I&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Vt(e),t||e.docView&&e.docView.dirty){let n=Ee(e),o=e.state.selection;return n&&!n.eq(o)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}pt.compositionstart=pt.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,o=t.selection.$to;if(t.selection instanceof n&&(t.storedMarks||!o.textOffset&&o.parentOffset&&o.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||P&&z&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let o=t.childNodes[n];return 1==o.nodeType&&"false"==o.contentEditable}(e)))e.markCursor=e.state.storedMarks||o.marks(),Bt(e,!0),e.markCursor=null;else if(Bt(e,!t.selection.empty),k&&t.selection.empty&&o.parentOffset&&!o.textOffset&&o.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,o=t.focusOffset;n&&1==n.nodeType&&0!=o;){let t=o<0?n.lastChild:n.childNodes[o-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,o=-1}}e.input.composing=!0}At(e,Pt)},pt.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,At(e,20))};const zt=x&&T<15||R&&F<604;function It(e,t,n,o,s){let r=nt(e,t,n,o,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,s,r||i.empty)))return!0;if(!r)return!1;let l=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(r),d=l?e.state.tr.replaceSelectionWith(l,o):e.state.tr.replaceSelection(r);return e.dispatch(d.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Lt(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}ut.copy=pt.cut=(e,t)=>{let n=t,o=e.state.selection,i="cut"==n.type;if(o.empty)return;let s=zt?null:n.clipboardData,r=o.content(),{dom:l,text:d}=tt(e,r);s?(n.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",d)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let o=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),o.removeAllRanges(),o.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,l),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},pt.paste=(e,t)=>{let n=t;if(e.composing&&!I)return;let o=zt?null:n.clipboardData,i=e.input.shiftKey&&45!=e.input.lastKeyCode;o&&It(e,Lt(o),o.getData("text/html"),i,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,o=e.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=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),o.parentNode&&o.parentNode.removeChild(o),n?It(e,o.value,null,i,t):It(e,o.textContent,o.innerHTML,i,t)},50)}(e,n)};class Ft{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const $t=B?"altKey":"ctrlKey";function qt(e,t){let n=e.someProp("dragCopies",e=>!e(t));return null!=n?n:!t[$t]}ut.dragstart=(t,n)=>{let o=n,i=t.input.mouseDown;if(i&&i.done(),!o.dataTransfer)return;let s,r=t.state.selection,l=r.empty?null:t.posAtCoords(Dt(o));if(l&&l.pos>=r.from&&l.pos<=(r instanceof e?r.to-1:r.to));else if(i&&i.mightDrag)s=e.create(t.state.doc,i.mightDrag.pos);else if(o.target&&1==o.target.nodeType){let n=t.docView.nearestDesc(o.target,!0);n&&n.node.type.spec.draggable&&n!=t.docView&&(s=e.create(t.state.doc,n.posBefore))}let d=(s||t.state.selection).content(),{dom:a,text:c,slice:h}=tt(t,d);(!o.dataTransfer.files.length||!P||A>120)&&o.dataTransfer.clearData(),o.dataTransfer.setData(zt?"Text":"text/html",a.innerHTML),o.dataTransfer.effectAllowed="copyMove",zt||o.dataTransfer.setData("text/plain",c),t.dragging=new Ft(h,qt(t,o),s)},ut.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},pt.dragover=pt.dragenter=(e,t)=>t.preventDefault(),pt.drop=(t,n)=>{try{!function(t,n,o){if(!n.dataTransfer)return;let s=t.posAtCoords(Dt(n));if(!s)return;let r=t.state.doc.resolve(s.pos),l=o&&o.slice;l?t.someProp("transformPasted",e=>{l=e(l,t,!1)}):l=nt(t,Lt(n.dataTransfer),zt?null:n.dataTransfer.getData("text/html"),!1,r);let d=!(!o||!qt(t,n));if(t.someProp("handleDrop",e=>e(t,n,l||i.empty,d)))return void n.preventDefault();if(!l)return;n.preventDefault();let c=l?a(t.state.doc,r.pos,l):r.pos;null==c&&(c=r.pos);let h=t.state.tr;if(d){let{node:e}=o;e?e.replace(h):h.deleteSelection()}let f=h.mapping.map(c),u=0==l.openStart&&0==l.openEnd&&1==l.content.childCount,p=h.doc;u?h.replaceRangeWith(f,f,l.content.firstChild):h.replaceRange(f,f,l);if(h.doc.eq(p))return;let m=h.doc.resolve(f);if(u&&e.isSelectable(l.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(l.content.firstChild))h.setSelection(new e(m));else{let e=h.mapping.map(c);h.mapping.maps[h.mapping.maps.length-1].forEach((t,n,o,i)=>e=i),h.setSelection(Fe(t,m,h.doc.resolve(e)))}t.focus(),t.dispatch(h.setMeta("uiEvent","drop"))}(t,n,t.dragging)}finally{t.dragging=null}},ut.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Ae(e)},20))},ut.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},ut.beforeinput=(e,t)=>{if(P&&I&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,w(8,"Backspace"))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let xn in pt)ut[xn]=pt[xn];function Kt(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class Wt{constructor(e,t){this.toDOM=e,this.spec=t||jt,this.side=this.spec.side||0}map(e,t,n,o){let{pos:i,deleted:s}=e.mapResult(t.from+o,this.side<0?-1:1);return s?null:new Gt(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Wt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Kt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Ht{constructor(e,t){this.attrs=e,this.spec=t||jt}map(e,t,n,o){let i=e.map(t.from+o,this.spec.inclusiveStart?-1:1)-n,s=e.map(t.to+o,this.spec.inclusiveEnd?1:-1)-n;return i>=s?null:new Gt(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Ht&&Kt(this.attrs,e.attrs)&&Kt(this.spec,e.spec)}static is(e){return e.type instanceof Ht}destroy(){}}class _t{constructor(e,t){this.attrs=e,this.spec=t||jt}map(e,t,n,o){let i=e.mapResult(t.from+o,1);if(i.deleted)return null;let s=e.mapResult(t.to+o,-1);return s.deleted||s.pos<=i.pos?null:new Gt(i.pos-n,s.pos-n,this)}valid(e,t){let n,{index:o,offset:i}=e.content.findIndex(t.from);return i==t.from&&!(n=e.child(o)).isText&&i+n.nodeSize==t.to}eq(e){return this==e||e instanceof _t&&Kt(this.attrs,e.attrs)&&Kt(this.spec,e.spec)}destroy(){}}class Gt{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Gt(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new Gt(e,e,new Wt(t,n))}static inline(e,t,n,o){return new Gt(e,t,new Ht(n,o))}static node(e,t,n,o){return new Gt(e,t,new _t(n,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ht}get widget(){return this.type instanceof Wt}}const Ut=[],jt={};class Yt{constructor(e,t){this.local=e.length?e:Ut,this.children=t.length?t:Ut}static create(e,t){return t.length?tn(t,e,0,jt):Xt}find(e,t,n){let o=[];return this.findInner(null==e?0:e,null==t?1e9:t,o,0,n),o}findInner(e,t,n,o,i){for(let s=0;s<this.local.length;s++){let r=this.local[s];r.from<=t&&r.to>=e&&(!i||i(r.spec))&&n.push(r.copy(r.from+o,r.to+o))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let r=this.children[s]+1;this.children[s+2].findInner(e-r,t-r,n,o+r,i)}}map(e,t,n){return this==Xt||0==e.maps.length?this:this.mapInner(e,t,0,0,n||jt)}mapInner(e,t,n,o,i){let s;for(let r=0;r<this.local.length;r++){let l=this.local[r].map(e,n,o);l&&l.type.valid(t,l)?(s||(s=[])).push(l):i.onRemove&&i.onRemove(this.local[r].spec)}return this.children.length?function(e,t,n,o,i,s,r){let l=e.slice();for(let a=0,c=s;a<n.maps.length;a++){let e=0;n.maps[a].forEach((t,n,o,i)=>{let s=i-o-(n-t);for(let r=0;r<l.length;r+=3){let o=l[r+1];if(o<0||t>o+c-e)continue;let i=l[r]+c-e;n>=i?l[r+1]=t<=i?-2:-1:t>=c&&s&&(l[r]+=s,l[r+1]+=s)}e+=s}),c=n.maps[a].map(c,-1)}let d=!1;for(let a=0;a<l.length;a+=3)if(l[a+1]<0){if(-2==l[a+1]){d=!0,l[a+1]=-1;continue}let t=n.map(e[a]+s),c=t-i;if(c<0||c>=o.content.size){d=!0;continue}let h=n.map(e[a+1]+s,-1)-i,{index:f,offset:u}=o.content.findIndex(c),p=o.maybeChild(f);if(p&&u==c&&u+p.nodeSize==h){let o=l[a+2].mapInner(n,p,t+1,e[a]+s+1,r);o!=Xt?(l[a]=c,l[a+1]=h,l[a+2]=o):(l[a+1]=-2,d=!0)}else d=!0}if(d){let d=function(e,t,n,o,i,s,r){function l(e,t){for(let s=0;s<e.local.length;s++){let l=e.local[s].map(o,i,t);l?n.push(l):r.onRemove&&r.onRemove(e.local[s].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let d=0;d<e.length;d+=3)-1==e[d+1]&&l(e[d+2],t[d]+s+1);return n}(l,e,t,n,i,s,r),a=tn(d,o,0,r);t=a.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<a.children.length;e+=3){let n=a.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,a.children[e],a.children[e+1],a.children[e+2])}}return new Yt(t.sort(nn),l)}(this.children,s||[],e,t,n,o,i):s?new Yt(s.sort(nn),Ut):Xt}add(e,t){return t.length?this==Xt?Yt.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let o,i=0;e.forEach((e,s)=>{let r,l=s+n;if(r=Zt(t,e,l)){for(o||(o=this.children.slice());i<o.length&&o[i]<s;)i+=3;o[i]==s?o[i+2]=o[i+2].addInner(e,r,l+1):o.splice(i,0,s,s+e.nodeSize,tn(r,e,l+1,jt)),i+=3}});let s=Qt(i?en(t):t,-n);for(let r=0;r<s.length;r++)s[r].type.valid(e,s[r])||s.splice(r--,1);return new Yt(s.length?this.local.concat(s).sort(nn):this.local,o||this.children)}remove(e){return 0==e.length||this==Xt?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,o=this.local;for(let i=0;i<n.length;i+=3){let o,s=n[i]+t,r=n[i+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>s&&t.to<r&&(e[n]=null,(o||(o=[])).push(t));if(!o)continue;n==this.children&&(n=this.children.slice());let l=n[i+2].removeInner(o,s+1);l!=Xt?n[i+2]=l:(n.splice(i,3),i-=3)}if(o.length)for(let i,s=0;s<e.length;s++)if(i=e[s])for(let e=0;e<o.length;e++)o[e].eq(i,t)&&(o==this.local&&(o=this.local.slice()),o.splice(e--,1));return n==this.children&&o==this.local?this:o.length||n.length?new Yt(o,n):Xt}forChild(e,t){if(this==Xt)return this;if(t.isLeaf)return Yt.empty;let n,o;for(let r=0;r<this.children.length;r+=3)if(this.children[r]>=e){this.children[r]==e&&(n=this.children[r+2]);break}let i=e+1,s=i+t.content.size;for(let r=0;r<this.local.length;r++){let e=this.local[r];if(e.from<s&&e.to>i&&e.type instanceof Ht){let t=Math.max(i,e.from)-i,n=Math.min(s,e.to)-i;t<n&&(o||(o=[])).push(e.copy(t,n))}}if(o){let e=new Yt(o.sort(nn),Ut);return n?new Jt([e,n]):e}return n||Xt}eq(e){if(this==e)return!0;if(!(e instanceof Yt)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return on(this.localsInner(e))}localsInner(e){if(this==Xt)return Ut;if(e.inlineContent||!this.local.some(Ht.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Ht||t.push(this.local[n]);return t}forEachSet(e){e(this)}}Yt.empty=new Yt([],[]),Yt.removeOverlap=on;const Xt=Yt.empty;class Jt{constructor(e){this.members=e}map(e,t){const n=this.members.map(n=>n.map(e,t,jt));return Jt.from(n)}forChild(e,t){if(t.isLeaf)return Yt.empty;let n=[];for(let o=0;o<this.members.length;o++){let i=this.members[o].forChild(e,t);i!=Xt&&(i instanceof Jt?n=n.concat(i.members):n.push(i))}return Jt.from(n)}eq(e){if(!(e instanceof Jt)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let o=0;o<this.members.length;o++){let i=this.members[o].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?on(n?t:t.sort(nn)):Ut}static from(e){switch(e.length){case 0:return Xt;case 1:return e[0];default:return new Jt(e.every(e=>e instanceof Yt)?e:e.reduce((e,t)=>e.concat(t instanceof Yt?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Qt(e,t){if(!t||!e.length)return e;let n=[];for(let o=0;o<e.length;o++){let i=e[o];n.push(new Gt(i.from+t,i.to+t,i.type))}return n}function Zt(e,t,n){if(t.isLeaf)return null;let o=n+t.nodeSize,i=null;for(let s,r=0;r<e.length;r++)(s=e[r])&&s.from>n&&s.to<o&&((i||(i=[])).push(s),e[r]=null);return i}function en(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function tn(e,t,n,o){let i=[],s=!1;t.forEach((t,r)=>{let l=Zt(e,t,r+n);if(l){s=!0;let e=tn(l,t,n+r+1,o);e!=Xt&&i.push(r,r+t.nodeSize,e)}});let r=Qt(s?en(e):e,-n).sort(nn);for(let l=0;l<r.length;l++)r[l].type.valid(t,r[l])||(o.onRemove&&o.onRemove(r[l].spec),r.splice(l--,1));return r.length||i.length?new Yt(r,i):Xt}function nn(e,t){return e.from-t.from||e.to-t.to}function on(e){let t=e;for(let n=0;n<t.length-1;n++){let o=t[n];if(o.from!=o.to)for(let i=n+1;i<t.length;i++){let s=t[i];if(s.from!=o.from){s.from<o.to&&(t==e&&(t=e.slice()),t[n]=o.copy(o.from,s.from),sn(t,i,o.copy(s.from,o.to)));break}s.to!=o.to&&(t==e&&(t=e.slice()),t[i]=s.copy(s.from,o.to),sn(t,i+1,s.copy(o.to,s.to)))}}return t}function sn(e,t,n){for(;t<e.length&&nn(n,e[t])>0;)t++;e.splice(t,0,n)}function rn(e){let t=[];return e.someProp("decorations",n=>{let o=n(e.state);o&&o!=Xt&&t.push(o)}),e.cursorWrapper&&t.push(Yt.create(e.state.doc,[e.cursorWrapper.deco])),Jt.from(t)}const ln={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},dn=x&&T<=11;class an{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class cn{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new an,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);x&&T<=11&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():V&&e.composing&&t.some(e=>"childList"==e.type&&"TR"==e.target.nodeName)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),dn&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.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,ln)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if($e(this.view)){if(this.suppressingSelectionUpdates)return Ae(this.view);if(x&&T<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&p(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t,n=/* @__PURE__ */new Set;for(let i=e.focusNode;i;i=h(i))n.add(i);for(let i=e.anchorNode;i;i=h(i))if(n.has(i)){t=i;break}let o=t&&this.view.docView.nearestDesc(t);return o&&o.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 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=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(o)&&$e(e)&&!this.ignoreSelectionChange(o),s=-1,r=-1,l=!1,d=[];if(e.editable)for(let t=0;t<n.length;t++){let e=this.registerMutation(n[t],d);e&&(s=s<0?e.from:Math.min(e.from,s),r=r<0?e.to:Math.max(e.to,r),e.typeOver&&(l=!0))}if(!d.some(e=>"BR"==e.nodeName)||8!=e.input.lastKeyCode&&46!=e.input.lastKeyCode){if(k&&d.length){let t=d.filter(e=>"BR"==e.nodeName);if(2==t.length){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let o of t){let t=o.parentNode;!t||"LI"!=t.nodeName||n&&pn(e,n)==t||o.remove()}}}}else for(let t of d)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;e&&1==e.nodeType&&"false"==e.contentEditable&&t.parentNode.removeChild(t)}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&v(o)&&(a=Ee(e))&&a.eq(t.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Ae(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,r),function(e){if(hn.has(e))return;if(hn.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace)){if(e.requiresGeckoHackNode=k,fn)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."),fn=!0}}(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,function(e,t){var n;let{focusNode:o,focusOffset:i}=e.domSelectionRange();for(let s of t)if("TR"==(null===(n=s.parentNode)||void 0===n?void 0:n.nodeName)){let t=s.nextSibling;for(;t&&"TD"!=t.nodeName&&"TH"!=t.nodeName;)t=t.nextSibling;if(t){let n=t;for(;;){let e=n.firstChild;if(!e||1!=e.nodeType||"false"==e.contentEditable||/^(BR|IMG)$/.test(e.nodeName))break;n=e}n.insertBefore(s,n.firstChild),o==s&&e.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}(e,d)),this.handleDOMChange(s,r,l,d),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||Ae(e),this.currentSelection.set(o))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style")))return null;if(!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let o=e.addedNodes[n];t.push(o),3==o.nodeType&&(this.lastChangedTextNode=o)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let o=e.previousSibling,i=e.nextSibling;if(x&&T<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:s}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(o=n),(!s||Array.prototype.indexOf.call(e.addedNodes,s)<0)&&(i=s)}let s=o&&o.parentNode==e.target?c(o)+1:0,r=n.localPosFromDOM(e.target,s,-1),l=i&&i.parentNode==e.target?c(i):e.target.childNodes.length;return{from:r,to:n.localPosFromDOM(e.target,l,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let hn=/* @__PURE__ */new WeakMap,fn=!1;function un(e,t){let n=t.startContainer,o=t.startOffset,i=t.endContainer,s=t.endOffset,r=e.domAtPos(e.state.selection.anchor);return p(r.node,r.offset,i,s)&&([n,o,i,s]=[i,s,n,o]),{anchorNode:n,anchorOffset:o,focusNode:i,focusOffset:s}}function pn(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function mn(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(V&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}if(e.parentNode.lastChild==e||V&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}const gn=/^(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 yn(e,t,o,i,s){let d=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Ee(e,t);if(n&&!e.state.selection.eq(n)){if(P&&I&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,w(13,"Enter"))))return;let o=e.state.tr.setSelection(n);"pointer"==t?o.setMeta("pointer",!0):"key"==t&&o.scrollIntoView(),d&&o.setMeta("composition",d),e.dispatch(o)}return}let a=e.state.doc.resolve(t),c=a.sharedDepth(o);t=a.before(c+1),o=e.state.doc.resolve(o).after(c+1);let h,f,u=e.state.selection,p=function(e,t,n){let o,{node:i,fromOffset:s,toOffset:r,from:d,to:a}=e.docView.parseRange(t,n),c=e.domSelectionRange(),h=c.anchorNode;if(h&&e.dom.contains(1==h.nodeType?h:h.parentNode)&&(o=[{node:h,offset:c.anchorOffset}],v(c)||o.push({node:c.focusNode,offset:c.focusOffset})),P&&8===e.input.lastKeyCode)for(let l=r;l>s;l--){let e=i.childNodes[l-1],t=e.pmViewDesc;if("BR"==e.nodeName&&!t){r=l;break}if(!t||t.size)break}let f=e.state.doc,u=e.someProp("domParser")||l.fromSchema(e.state.schema),p=f.resolve(d),m=null,g=u.parse(i,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:s,to:r,preserveWhitespace:"pre"!=p.parent.type.whitespace||"full",findPositions:o,ruleFromNode:mn,context:p});if(o&&null!=o[0].pos){let e=o[0].pos,t=o[1]&&o[1].pos;null==t&&(t=e),m={anchor:e+d,head:t+d}}return{doc:g,sel:m,from:d,to:a}}(e,t,o),m=e.state.doc,g=m.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(h=e.state.selection.to,f="end"):(h=e.state.selection.from,f="start"),e.input.lastKeyCode=null;let y=function(e,t,n,o,i){let s=e.findDiffStart(t,n);if(null==s)return null;let{a:r,b:l}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==i){o-=r+Math.max(0,s-Math.min(r,l))-s}if(r<s&&e.size<t.size){let e=o<=s&&o>=r?s-o:0;s-=e,s&&s<t.size&&wn(t.textBetween(s-1,s+1))&&(s+=e?1:-1),l=s+(l-r),r=s}else if(l<s){let t=o<=s&&o>=l?s-o:0;s-=t,s&&s<e.size&&wn(e.textBetween(s-1,s+1))&&(s+=t?1:-1),r=s+(r-l),l=s}return{start:s,endA:r,endB:l}}(g.content,p.doc.content,p.from,h,f);if(y&&e.input.domChangeCount++,(R&&e.input.lastIOSEnter>Date.now()-225||I)&&s.some(e=>1==e.nodeType&&!gn.test(e.nodeName))&&(!y||y.endA>=y.endB)&&e.someProp("handleKeyDown",t=>t(e,w(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(!y){if(!(i&&u instanceof n&&!u.empty&&u.$head.sameParent(u.$anchor))||e.composing||p.sel&&p.sel.anchor!=p.sel.head){if(p.sel){let t=bn(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);d&&n.setMeta("composition",d),e.dispatch(n)}}return}y={start:u.from,endA:u.to,endB:u.to}}e.state.selection.from<e.state.selection.to&&y.start==y.endB&&e.state.selection instanceof n&&(y.start>e.state.selection.from&&y.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?y.start=e.state.selection.from:y.endA<e.state.selection.to&&y.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(y.endB+=e.state.selection.to-y.endA,y.endA=e.state.selection.to)),x&&T<=11&&y.endB==y.start+1&&y.endA==y.start&&y.start>p.from&&"  "==p.doc.textBetween(y.start-p.from-1,y.start-p.from+1)&&(y.start--,y.endA--,y.endB--);let b=p.doc.resolveNoCache(y.start-p.from),D=p.doc.resolveNoCache(y.endB-p.from),N=m.resolve(y.start),S=b.sameParent(D)&&b.parent.inlineContent&&N.end()>=y.endA;if((R&&e.input.lastIOSEnter>Date.now()-225&&(!S||s.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!S&&b.pos<p.doc.content.size&&(!b.sameParent(D)||!b.parent.inlineContent)&&b.pos<D.pos&&!/\S/.test(p.doc.textBetween(b.pos,D.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,w(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>y.start&&function(e,t,n,o,i){if(n-t<=i.pos-o.pos||vn(o,!0,!1)<i.pos)return!1;let s=e.resolve(t);if(!o.parent.isTextblock){let e=s.nodeAfter;return null!=e&&n==t+e.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let r=e.resolve(vn(s,!0,!0));return!(!r.parent.isTextblock||r.pos>n||vn(r,!0,!1)<n)&&o.parent.content.cut(o.parentOffset).eq(r.parent.content)}(m,y.start,y.endA,b,D)&&e.someProp("handleKeyDown",t=>t(e,w(8,"Backspace"))))return void(I&&P&&e.domObserver.suppressSelectionUpdates());P&&y.endB==y.start&&(e.input.lastChromeDelete=Date.now()),I&&!S&&b.start()!=D.start()&&0==D.parentOffset&&b.depth==D.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==y.endA&&(y.endB-=2,D=p.doc.resolveNoCache(y.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,w(13,"Enter"))})},20));let C,O=y.start,M=y.endA,k=t=>{let n=t||e.state.tr.replace(O,M,p.doc.slice(y.start-p.from,y.endB-p.from));if(p.sel){let t=bn(e,n.doc,p.sel);t&&!(P&&e.composing&&t.empty&&(y.start!=y.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==O||t.head==n.mapping.map(M)-1)||x&&t.empty&&t.head==O)&&n.setSelection(t)}return d&&n.setMeta("composition",d),n.scrollIntoView()};if(S)if(b.pos==D.pos){x&&T<=11&&0==b.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>Ae(e),20));let t=k(e.state.tr.delete(O,M)),n=m.resolve(y.start).marksAcross(m.resolve(y.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(y.endA==y.endB&&(C=function(e,t){let n,o,i,s=e.firstChild.marks,l=t.firstChild.marks,d=s,a=l;for(let r=0;r<l.length;r++)d=l[r].removeFromSet(d);for(let r=0;r<s.length;r++)a=s[r].removeFromSet(a);if(1==d.length&&0==a.length)o=d[0],n="add",i=e=>e.mark(o.addToSet(e.marks));else{if(0!=d.length||1!=a.length)return null;o=a[0],n="remove",i=e=>e.mark(o.removeFromSet(e.marks))}let c=[];for(let r=0;r<t.childCount;r++)c.push(i(t.child(r)));if(r.from(c).eq(e))return{mark:o,type:n}}(b.parent.content.cut(b.parentOffset,D.parentOffset),N.parent.content.cut(N.parentOffset,y.endA-N.start())))){let t=k(e.state.tr);"add"==C.type?t.addMark(O,M,C.mark):t.removeMark(O,M,C.mark),e.dispatch(t)}else if(b.parent.child(b.index()).isText&&b.index()==D.index()-(D.textOffset?0:1)){let t=b.parent.textBetween(b.parentOffset,D.parentOffset),n=()=>k(e.state.tr.insertText(t,O,M));e.someProp("handleTextInput",o=>o(e,O,M,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())}function bn(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Fe(e,t.resolve(n.anchor),t.resolve(n.head))}function vn(e,t,n){let o=e.depth,i=t?e.end():e.pos;for(;o>0&&(t||e.indexAfter(o)==e.node(o).childCount);)o--,i++,t=!1;if(n){let t=e.node(o).maybeChild(e.indexAfter(o));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function wn(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class Dn{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new gt,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Mn),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Cn(this),Sn(this),this.nodeViews=On(this),this.docView=pe(this.state.doc,Nn(this),rn(this),this.dom,this),this.domObserver=new cn(this,(e,t,n,o)=>yn(this,e,t,n,o)),this.domObserver.start(),function(e){for(let t in ut){let n=ut[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!wt(e,t)||vt(e,t)||!e.editable&&t.type in pt||n(e,t)},mt[t]?{passive:!0}:void 0)}V&&e.dom.addEventListener("input",()=>null),bt(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&bt(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Mn),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let o=this.state,i=!1,s=!1;e.storedMarks&&this.composing&&(Vt(this),s=!0),this.state=e;let r=o.plugins!=e.plugins||this._props.plugins!=t.plugins;if(r||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=On(this);(function(e,t){let n=0,o=0;for(let i in e){if(e[i]!=t[i])return!0;n++}for(let i in t)o++;return n!=o})(e,this.nodeViews)&&(this.nodeViews=e,i=!0)}(r||t.handleDOMEvents!=this._props.handleDOMEvents)&&bt(this),this.editable=Cn(this),Sn(this);let l=rn(this),d=Nn(this),a=o.plugins==e.plugins||o.doc.eq(e.doc)?e.scrollToSelection>o.scrollToSelection?"to selection":"preserve":"reset",c=i||!this.docView.matchesNode(e.doc,d,l);!c&&e.selection.eq(o.selection)||(s=!0);let h="preserve"==a&&s&&null==this.dom.style.overflowAnchor&&function(e){let t,n,o=e.dom.getBoundingClientRect(),i=Math.max(0,o.top);for(let s=(o.left+o.right)/2,r=i+1;r<Math.min(innerHeight,o.bottom);r+=5){let o=e.root.elementFromPoint(s,r);if(!o||o==e.dom||!e.dom.contains(o))continue;let l=o.getBoundingClientRect();if(l.top>=i-20){t=o,n=l.top;break}}return{refDOM:t,refTop:n,stack:H(e.dom)}}(this);if(s){this.domObserver.stop();let t=c&&(x||P)&&!this.composing&&!o.selection.empty&&!e.selection.empty&&function(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}(o.selection,e.selection);if(c){let n=P?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Rt(this)),!i&&this.docView.update(e.doc,d,l,this)||(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=pe(e.doc,d,l,this.dom,this)),!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return p(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?Ae(this,t):(Ie(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),"reset"==a?this.dom.scrollTop=0:"to selection"==a?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let o=e?e.getBoundingClientRect().top:0;_(n,0==o?0:o-t)}(h)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof e){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&W(this,e.getBoundingClientRect(),t)}else W(this,this.coordsAtPos(this.state.selection.head,1),t);else;}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)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}updateDraggedNode(t,n){let o=t.node,i=-1;if(this.state.doc.nodeAt(o.from)==o.node)i=o.from;else{let e=o.from+(this.state.doc.content.size-n.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==o.node&&(i=e)}this.dragging=new Ft(t.slice,t.move,i<0?void 0:e.create(this.state.doc,i))}someProp(e,t){let n,o=this._props&&this._props[e];if(null!=o&&(n=t?t(o):o))return n;for(let s=0;s<this.directPlugins.length;s++){let o=this.directPlugins[s].props[e];if(null!=o&&(n=t?t(o):o))return n}let i=this.state.plugins;if(i)for(let s=0;s<i.length;s++){let o=i[s].props[e];if(null!=o&&(n=t?t(o):o))return n}}hasFocus(){if(x){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("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(G)return e.focus(G);let t=H(e);e.focus(null==G?{get preventScroll(){return G={preventScroll:!0},!0}}:void 0),G||(G=!1,_(t,0))}(this.dom),Ae(this),this.domObserver.start()}get root(){let e=this._root;if(null==e)for(let t=this.dom.parentNode;t;t=t.parentNode)if(9==t.nodeType||11==t.nodeType&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t;return e||document}updateRoot(){this._root=null}posAtCoords(e){return X(this,e)}coordsAtPos(e,t=1){return ee(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let o=this.docView.posFromDOM(e,t,n);if(null==o)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,t){return de(this,t||this.state,e)}pasteHTML(e,t){return It(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return It(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return tt(this,e)}destroy(){this.docView&&(!function(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],rn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,f=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){vt(e,t)||!ut[t.type]||!e.editable&&t.type in pt||ut[t.type](e,t)}(this,e)}domSelectionRange(){let e=this.domSelection();return e?V&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return un(e,n)}let n;function o(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",o,!0),n?un(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Nn(e){let t=/* @__PURE__ */Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[Gt.node(0,e.state.doc.content.size,t)]}function Sn(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:Gt.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Cn(e){return!e.someProp("editable",t=>!1===t(e.state))}function On(e){let t=/* @__PURE__ */Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function Mn(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}Dn.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};export{Gt as Decoration,Yt as DecorationSet,Dn as EditorView};