From ff0afd14f08681671547cbee56f0d2ca4e47b49d Mon Sep 17 00:00:00 2001 From: Shane Friedman Date: Wed, 4 Sep 2024 19:30:44 -0400 Subject: [PATCH] Better conversion from html attributes to react props (#130) * Disable react/prop-types lint rule * Flesh out conversion from html attributes to react props * Properly merge decorations/props with outputspecs * Use CSSOM to parse style attributes * Re-enable react/prop-types rule --- .../{index-e2175326.js => index-3279a106.js} | 34 +-- docs/index.html | 2 +- src/components/ChildNodeViews.tsx | 44 +--- src/components/OutputSpec.tsx | 23 +- src/props.ts | 223 ++++++++++++++++++ 5 files changed, 258 insertions(+), 68 deletions(-) rename docs/assets/{index-e2175326.js => index-3279a106.js} (73%) create mode 100644 src/props.ts diff --git a/docs/assets/index-e2175326.js b/docs/assets/index-3279a106.js similarity index 73% rename from docs/assets/index-e2175326.js rename to docs/assets/index-3279a106.js index 58436c70..c4ec839f 100644 --- a/docs/assets/index-e2175326.js +++ b/docs/assets/index-3279a106.js @@ -1,4 +1,4 @@ -(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const s of o.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();function f0(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var qh={exports:{}},tl={},Qh={exports:{}},V={};/** +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const s of o.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();function d0(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Kh={exports:{}},tl={},qh={exports:{}},V={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var uo=Symbol.for("react.element"),d0=Symbol.for("react.portal"),h0=Symbol.for("react.fragment"),p0=Symbol.for("react.strict_mode"),m0=Symbol.for("react.profiler"),g0=Symbol.for("react.provider"),y0=Symbol.for("react.context"),S0=Symbol.for("react.forward_ref"),k0=Symbol.for("react.suspense"),w0=Symbol.for("react.memo"),v0=Symbol.for("react.lazy"),mf=Symbol.iterator;function x0(t){return t===null||typeof t!="object"?null:(t=mf&&t[mf]||t["@@iterator"],typeof t=="function"?t:null)}var Yh={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Gh=Object.assign,Xh={};function Kr(t,e,n){this.props=t,this.context=e,this.refs=Xh,this.updater=n||Yh}Kr.prototype.isReactComponent={};Kr.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")};Kr.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function Zh(){}Zh.prototype=Kr.prototype;function _u(t,e,n){this.props=t,this.context=e,this.refs=Xh,this.updater=n||Yh}var Wu=_u.prototype=new Zh;Wu.constructor=_u;Gh(Wu,Kr.prototype);Wu.isPureReactComponent=!0;var gf=Array.isArray,ep=Object.prototype.hasOwnProperty,Uu={current:null},tp={key:!0,ref:!0,__self:!0,__source:!0};function np(t,e,n){var r,i={},o=null,s=null;if(e!=null)for(r in e.ref!==void 0&&(s=e.ref),e.key!==void 0&&(o=""+e.key),e)ep.call(e,r)&&!tp.hasOwnProperty(r)&&(i[r]=e[r]);var l=arguments.length-2;if(l===1)i.children=n;else if(1>1}};de.from=function(t){if(t instanceof de)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new de(e)};function ip(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)n++;return n}if(i.content.size||o.content.size){let s=ip(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function op(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let s=t.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){n-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:n,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,n-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,n-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);oe)for(let o=0,s=0;se&&((sn)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,n-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,n-s-1))),r.push(l),i+=l.nodeSize),s=a}return new v(r,i)}cutByIndex(e,n){return e==n?v.empty:e==0&&n==this.content.length?this:new v(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new v(i,o)}addToStart(e){return new v([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new v(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||n>0?Eo(r+1,s):Eo(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return v.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new v(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return v.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}}W.none=[];class bi extends Error{}class x{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=lp(this.content,e+this.openStart,n);return r&&new x(r,this.openStart,this.openEnd)}removeBetween(e,n){return new x(sp(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return x.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(v.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new x(e,r,i)}}x.empty=new x(v.empty,0,0);function sp(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:l}=t.findIndex(n);if(i==e||o.isText){if(l!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(sp(o.content,e-i-1,n-i-1)))}function lp(t,e,n,r){let{index:i,offset:o}=t.findIndex(e),s=t.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=lp(s.content,e-o-1,n);return l&&t.replaceChild(i,s.copy(l))}function z0(t,e,n){if(n.openStart>t.depth)throw new bi("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new bi("Inconsistent open depths");return ap(t,e,n,0)}function ap(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function ki(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(_n(t.nodeAfter,r),o++));for(let l=o;li&&xa(t,e,i+1),s=r.depth>i&&xa(n,r,i+1),l=[];return ki(null,t,i,l),o&&s&&e.index(i)==n.index(i)?(up(o,s),_n(Wn(o,cp(t,e,n,r,i+1)),l)):(o&&_n(Wn(o,ks(t,e,i+1)),l),ki(e,n,i,l),s&&_n(Wn(s,ks(n,r,i+1)),l)),ki(r,null,i,l),new v(l)}function ks(t,e,n){let r=[];if(ki(null,t,n,r),t.depth>n){let i=xa(t,e,n+1);_n(Wn(i,ks(t,e,n+1)),r)}return ki(e,null,n,r),new v(r)}function I0(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(v.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Fi{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new F0(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new Fi(n,r,o)}static resolveCached(e,n){for(let i=0;ie&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),fp(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=v.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let a=i;an.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=v.fromJSON(e,n.content);return e.nodeType(n.type).create(n.attrs,i,r)}}vt.prototype.text=void 0;class ws extends vt{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):fp(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new ws(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ws(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function fp(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Kn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new B0(e,n);if(r.next==null)return Kn.empty;let i=dp(r);r.next&&r.err("Unexpected trailing text");let o=H0(j0(i));return J0(o,r),o}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}}Kn.empty=new Kn(!0);class B0{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function dp(t){let e=[];do e.push(V0(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function V0(t){let e=[];do e.push($0(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function $0(t){let e=U0(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=_0(t,e);else break;return e}function kf(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function _0(t,e){let n=kf(t),r=n;return t.eat(",")&&(t.next!="}"?r=kf(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function W0(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function U0(t){if(t.eat("(")){let e=dp(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=W0(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function j0(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=n())}else if(s.type=="star"){let a=n();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=n();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{t[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new Kn(r.indexOf(t.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[o]=new yp(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};class K0{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class co{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=gp(i.attrs),this.excluded=null;let o=pp(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,mp(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new co(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}}class Sp{constructor(e){this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=de.from(e.nodes),n.marks=de.from(e.marks||{}),this.nodes=vf.compile(this.spec.nodes,this),this.marks=co.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;o.contentMatch=r[s]||(r[s]=Kn.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.markSet=l=="_"?null:l?xf(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:xf(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof vf){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new ws(r,r.defaultAttrs,e,W.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return vt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function xf(t,e){let n=[];for(let r=0;r-1)&&n.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}class Li{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new Nf(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Nf(this,n,!0);return r.addAll(e,n.from,n.to),x.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(s.getAttrs){let a=s.getAttrs(n);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Mf(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Mf(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Li(e,Li.schemaRules(e)))}}const kp={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},q0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},wp={ol:!0,ul:!0},vs=1,xs=2,wi=4;function Cf(t,e,n){return e!=null?(e?vs:0)|(e==="full"?xs:0):t&&t.whitespace=="pre"?vs|xs:n&~wi}class Oo{constructor(e,n,r,i,o,s,l){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=l,this.content=[],this.activeMarks=W.none,this.stashMarks=[],this.match=s||(l&wi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(v.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&vs)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=v.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(v.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;nthis.addAll(e)),s&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,o,o.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=W.none,r=W.none;for(let i=0;i{s.clearMark(l)&&(r=l.addToSet(r))}):n=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(n),s.consuming===!1)o=s;else break}return[n,r]}addElementByRule(e,n,r){let i,o,s;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):i=this.enter(o,n.attrs||null,n.preserveWhitespace)):(s=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,s&&this.removePendingMark(s,l)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!n||n.length>s.length)&&(n=s,r=o,!s.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;ithis.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=Z0(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==n)break}}}function Q0(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&wp.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Y0(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function G0(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Mf(t){let e={};for(let n in t)e[n]=t[n];return e}function X0(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Lt.renderSpec(Tl(r),i(e,n))}static renderSpec(e,n,r=null){if(typeof n=="string")return{dom:e.createTextNode(n)};if(n.nodeType!=null)return{dom:n};if(n.dom&&n.dom.nodeType!=null)return n;let i=n[0],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=n[1],u=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){u=2;for(let c in a)if(a[c]!=null){let f=c.indexOf(" ");f>0?l.setAttributeNS(c.slice(0,f),c.slice(f+1),a[c]):l.setAttribute(c,a[c])}}for(let c=u;cu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:d,contentDOM:p}=Lt.renderSpec(e,f,r);if(l.appendChild(d),p){if(s)throw new RangeError("Multiple content holes");s=p}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Lt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Ef(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Ef(e.marks)}}function Ef(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Tl(t){return t.document||window.document}const vp=65535,xp=Math.pow(2,16);function e1(t,e){return t+e*xp}function Of(t){return t&vp}function t1(t){return(t-(t&vp))/xp}const Cp=1,Np=2,Zo=4,Mp=8;let Ca=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Mp)>0}get deletedBefore(){return(this.delInfo&(Cp|Zo))>0}get deletedAfter(){return(this.delInfo&(Np|Zo))>0}get deletedAcross(){return(this.delInfo&Zo)>0}},Ar=class sr{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&sr.empty)return sr.empty}recover(e){let n=0,r=Of(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:n:n,p=a+i+(d<0?0:c);if(r)return p;let h=e==(n<0?a:f)?null:e1(l/3,e-a),m=e==a?Np:e==f?Cp:Zo;return(n<0?e!=a:e!=f)&&(m|=Mp),new Ca(p,m,h)}i+=c-u}return r?e+i:new Ca(e+i,0,null)}touches(e,n){let r=0,i=Of(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new es;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Fe.fromReplace(e,this.from,this.to,o)}invert(){return new fo(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new li(n.pos,r.pos,this.mark)}merge(e){return e instanceof li&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new li(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new li(n.from,n.to,e.markFromJSON(n.mark))}};We.jsonID("addMark",qu);let fo=class ai extends We{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new x(Ku(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Fe.fromReplace(e,this.from,this.to,r)}invert(){return new qu(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ai(n.pos,r.pos,this.mark)}merge(e){return e instanceof ai&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ai(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ai(n.from,n.to,e.markFromJSON(n.mark))}};We.jsonID("removeMark",fo);let Qu=class ui extends We{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Fe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Fe.fromReplace(e,this.pos,this.pos+1,new x(v.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new ts(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new ts(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}};We.jsonID("replaceAround",Wt);function Ma(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function r1(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(a)),o.forEach(a=>t.step(a))}function i1(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof co){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new fo(s.from,s.to,s.style)))}function o1(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function s1(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Gu(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),s=t.$to.indexAfter(r);if(rn;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Wt(i,o,i,o,new x(r,0,0),n.length,!0))}function d1(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&h1(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new Wt(u,c,u+1,c-1,new x(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function h1(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function p1(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Wt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new x(v.from(s),0,0),1,!0))}function ns(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,c=n-2;u>o;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function m1(t,e,n=1,r){let i=t.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new Cn(e,e,new x(o.append(s),n,n),!0))}function Xu(t,e){let n=t.resolve(e),r=n.index();return g1(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function g1(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}function y1(t,e,n){let r=new Cn(e-n,e+n,x.empty,!0);t.step(r)}function S1(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Zu(t,e,n=e,r=x.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return Ep(i,o,r)?new Cn(e,n,r):new w1(i,o,r).fit()}function Ep(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}let w1=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=v.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new x(o,s,l);return e>-1?new Wt(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new Cn(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Al(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(n==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Al(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Al(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new x(ci(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new x(ci(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=k,c.push(Op(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=fi(this.placed,n,v.from(c)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,k=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Pl(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=fi(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=fi(this.placed,this.depth,v.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(v.empty,!0);n.childCount&&(this.placed=fi(this.placed,this.frontier.length,n))}};function ci(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(ci(t.firstChild.content,e-1,n)))}function fi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(fi(t.lastChild.content,e-1,n)))}function Al(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Op(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),t.copy(r)}function Pl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!v1(n,o.content,s)?l:null}function v1(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=x1(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function Dp(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return t}function N1(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=S1(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new x(v.from(r),0,0))}function M1(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Tp(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function Tp(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}let Rp=class rs extends We{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Fe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Fe.fromReplace(e,this.pos,this.pos+1,new x(v.from(i),0,n.isLeaf?0:1))}getMap(){return Ar.empty}invert(e){return new rs(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new rs(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new rs(n.pos,n.attr,n.value)}};We.jsonID("attr",Rp);let Pr=class extends Error{};Pr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Pr.prototype=Object.create(Error.prototype);Pr.prototype.constructor=Pr;Pr.prototype.name="TransformError";let E1=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new n1}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Pr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=x.empty){let i=Zu(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new x(v.from(r),0,0))}delete(e,n){return this.replace(e,n,x.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return C1(this,e,n,r),this}replaceRangeWith(e,n,r){return N1(this,e,n,r),this}deleteRange(e,n){return M1(this,e,n),this}lift(e,n){return l1(this,e,n),this}join(e,n=1){return y1(this,e,n),this}wrap(e,n){return f1(this,e,n),this}setBlockType(e,n=e,r,i=null){return d1(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return p1(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Rp(e,n,r)),this}addNodeMark(e,n){return this.step(new Qu(e,n)),this}removeNodeMark(e,n){if(!(n instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new Yu(e,n)),this}split(e,n=1,r){return m1(this,e,n,r),this}addMark(e,n,r){return r1(this,e,n,r),this}removeMark(e,n,r){return i1(this,e,n,r),this}clearIncompatible(e,n,r){return o1(this,e,n,r),this}};const zl=Object.create(null);class b{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Ap(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?lr(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):lr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new Je(e.node(0))}static atStart(e){return lr(e,e,0,0,1)||new Je(e)}static atEnd(e){return lr(e,e,e.content.size,e.childCount,-1)||new Je(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=zl[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in zl)throw new RangeError("Duplicate use of selection JSON ID "+e);return zl[e]=n,n.prototype.jsonID=e,n}getBookmark(){return B.between(this.$anchor,this.$head).getBookmark()}}b.prototype.visible=!0;class Ap{constructor(e,n){this.$from=e,this.$to=n}}let Tf=!1;function Rf(t){!Tf&&!t.parent.inlineContent&&(Tf=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class B extends b{constructor(e,n=e){Rf(e),Rf(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return b.near(r);let i=e.resolve(n.map(this.anchor));return new B(i.parent.inlineContent?i:r,r)}replace(e,n=x.empty){if(super.replace(e,n),n==x.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof B&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new nl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new B(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=b.findFrom(n,r,!0)||b.findFrom(n,-r,!0);if(o)n=o.$head;else return b.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(b.findFrom(e,-r,!0)||b.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&I.isSelectable(l))return I.create(t,n-(i<0?l.nodeSize:0))}else{let a=lr(t,l,n+i,i<0?l.childCount:0,i,o);if(a)return a}n+=l.nodeSize*i}return null}function Af(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=c)}),t.setSelection(b.near(t.doc.resolve(s),n))}const Pf=1,Do=2,zf=4;class D1 extends E1{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Do,this}ensureMarks(e){return W.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Do)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Do,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||W.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),this.selection.empty||this.setSelection(b.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=zf,this}get scrolledIntoView(){return(this.updated&zf)>0}}function If(t,e){return!e||!t?t:t.bind(e)}class di{constructor(e,n,r){this.name=e,this.init=If(n.init,r),this.apply=If(n.apply,r)}}const T1=[new di("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new di("selection",{init(t,e){return t.selection||b.atStart(e.doc)},apply(t){return t.selection}}),new di("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new di("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class Il{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=T1.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new di(r.key,r.spec.state,r))})}}class on{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Il(e.schema,e.plugins),o=new on(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=vt.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=b.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){o[s.name]=u.fromJSON.call(a,e,n[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Pp(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Pp(i,e,{})),n[r]=i}return n}class Tt{constructor(e){this.spec=e,this.props={},e.props&&Pp(e.props,this,this.props),this.key=e.key?e.key.key:zp("plugin")}getState(e){return e[this.key]}}const bl=Object.create(null);function zp(t){return t in bl?t+"$"+ ++bl[t]:(bl[t]=0,t+"$")}class ho{constructor(e="key"){this.key=zp(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ip=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function R1(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const A1=(t,e,n)=>{let r=R1(t,n);if(!r)return!1;let i=bp(r);if(!i){let s=r.blockRange(),l=s&&Gu(s);return l==null?!1:(e&&e(t.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Lp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"end")||I.isSelectable(o))){let s=Zu(t.doc,r.before(),r.after(),x.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=bp(r)}let s=o&&o.nodeBefore;return!s||!I.isSelectable(s)?!1:(e&&e(t.tr.setSelection(I.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function bp(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function z1(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=z1(t,n);if(!r)return!1;let i=Fp(r);if(!i)return!1;let o=i.nodeAfter;if(Lp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"start")||I.isSelectable(o))){let s=Zu(t.doc,r.before(),r.after(),x.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` -`).scrollIntoView()),!0)};function tc(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=tc(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=n.after(),a=t.tr.replaceWith(l,l,s.createAndFill());a.setSelection(b.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},B1=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof Je||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=tc(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(ns(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Gu(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function $1(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof I&&e.selection.node.isBlock)return!r.parentOffset||!ns(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(n){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof B||e.selection instanceof Je)&&s.deleteSelection();let l=r.depth==0?null:tc(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=t&&t(i.parent,o),u=a?[a]:o&&l?[{type:l}]:void 0,c=ns(s.doc,s.mapping.map(r.pos),1,u);if(!u&&!c&&ns(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(u=[{type:l}]),c=!0),c&&(s.split(s.mapping.map(r.pos),1,u),!o&&!r.parentOffset&&r.parent.type!=l)){let f=s.mapping.map(r.before()),d=s.doc.resolve(f);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}n(s.scrollIntoView())}return!0}}const _1=$1(),W1=(t,e)=>(e&&e(t.tr.setSelection(new Je(t.doc))),!0);function U1(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Xu(t.doc,e.pos))?!1:(n&&n(t.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Lp(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(U1(t,e,n))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(n){let f=e.pos+i.nodeSize,d=v.empty;for(let m=o.length-1;m>=0;m--)d=v.from(o[m].create(null,d));d=v.from(r.copy(d));let p=t.tr.step(new Wt(e.pos-1,f,e.pos,f,new x(d,1,0),o.length,!0)),h=f+2*o.length;Xu(p.doc,h)&&p.join(h),n(p.scrollIntoView())}return!0}let a=b.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&Gu(u);if(c!=null&&c>=e.depth)return n&&n(t.tr.lift(u,c).scrollIntoView()),!0;if(l&&zr(i,"start",!0)&&zr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(n){let m=v.empty;for(let g=d.length-1;g>=0;g--)m=v.from(d[g].copy(m));let k=t.tr.step(new Wt(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new x(m,d.length,0),0,!0));n(k.scrollIntoView())}return!0}}return!1}function Bp(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(B.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}const j1=Bp(-1),H1=Bp(1);function J1(t,e,n){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(n)}),s)return!0}return!1}function bf(t,e=null){return function(n,r){let{empty:i,$cursor:o,ranges:s}=n.selection;if(i&&!o||!J1(n.doc,s,t))return!1;if(r)if(o)t.isInSet(n.storedMarks||o.marks())?r(n.tr.removeStoredMark(t)):r(n.tr.addStoredMark(t.create(e)));else{let l=!1,a=n.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Lf=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),Q1=typeof navigator<"u"&&/Mac/.test(navigator.platform),Y1=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),G1=Q1||Lf&&+Lf[1]<57;for(var pe=0;pe<10;pe++)Ut[48+pe]=Ut[96+pe]=String(pe);for(var pe=1;pe<=24;pe++)Ut[pe+111]="F"+pe;for(var pe=65;pe<=90;pe++)Ut[pe]=String.fromCharCode(pe+32),Cs[pe]=String.fromCharCode(pe);for(var Ll in Ut)Cs.hasOwnProperty(Ll)||(Cs[Ll]=Ut[Ll]);function $p(t){var e=G1&&(t.ctrlKey||t.altKey||t.metaKey)||Y1&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Cs:Ut)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}const X1=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Z1(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let l=0;l127)&&(o=Ut[r.keyCode])&&o!=i){let l=e[Bl(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Oe=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Bi=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let Bf=null;const zt=function(t,e,n){let r=Bf||(Bf=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},qn=function(t,e,n,r){return n&&(Vf(t,e,n,r,-1)||Vf(t,e,n,r,1))},tS=/^(img|br|input|textarea|hr)$/i;function Vf(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:St(t))){let o=t.parentNode;if(!o||o.nodeType!=1||rc(t)||tS.test(t.nodeName)||t.contentEditable=="false")return!1;e=Oe(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?St(t):0}else return!1}}function St(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function nS(t,e,n){for(let r=e==0,i=e==St(t);r||i;){if(t==n)return!0;let o=Oe(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==St(t)}}function rc(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const rl=function(t){return t.focusNode&&qn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function In(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function rS(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function iS(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:r.startOffset}}}const Mt=typeof navigator<"u"?navigator:null,$f=typeof document<"u"?document:null,Nn=Mt&&Mt.userAgent||"",Ea=/Edge\/(\d+)/.exec(Nn),Wp=/MSIE \d/.exec(Nn),Oa=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Nn),Be=!!(Wp||Oa||Ea),fn=Wp?document.documentMode:Oa?+Oa[1]:Ea?+Ea[1]:0,pt=!Be&&/gecko\/(\d+)/i.test(Nn);pt&&+(/Firefox\/(\d+)/.exec(Nn)||[0,0])[1];const Da=!Be&&/Chrome\/(\d+)/.exec(Nn),xe=!!Da,oS=Da?+Da[1]:0,Re=!Be&&!!Mt&&/Apple Computer/.test(Mt.vendor),Ir=Re&&(/Mobile\/\w+/.test(Nn)||!!Mt&&Mt.maxTouchPoints>2),Ge=Ir||(Mt?/Mac/.test(Mt.platform):!1),sS=Mt?/Win/.test(Mt.platform):!1,ct=/Android \d/.test(Nn),po=!!$f&&"webkitFontSmoothing"in $f.documentElement.style,lS=po?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function aS(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function At(t,e){return typeof t=="number"?t:t[e]}function uS(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function _f(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;s=Bi(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?aS(o):uS(l),c=0,f=0;if(e.topu.bottom-At(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+At(i,"top")-u.top:e.bottom-u.bottom+At(i,"bottom")),e.leftu.right-At(r,"right")&&(c=e.right-u.right+At(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function cS(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Up(t.dom)}}function Up(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Bi(r));return e}function fS({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;jp(n,r==0?0:r-e)}function jp(t,e){for(let n=0;n=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&a&&(n=a,i=u,r=0),n&&n.nodeType==3?hS(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Hp(n,i)}function hS(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:t,offset:0}}function ic(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function pS(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function gS(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let l=t.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:t.docView.posFromDOM(e,n,-1)}function Jp(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;po&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=gS(t,r,i,e))}l==null&&(l=mS(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Wf(t){return t.top=0&&i==r.nodeValue.length?(a--,c=1):n<0?a--:u++,Gr(Yt(zt(r,a,u),c),c<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==St(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Vl(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==St(r))){let a=r.childNodes[i-1],u=a.nodeType==3?zt(a,St(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Gr(Yt(u,1),!1)}if(o==null&&i=0)}function Gr(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Vl(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function qp(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function kS(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return qp(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Kp(t,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=zt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(n=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const wS=/[\u0590-\u08ac]/;function vS(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=t.domSelection();return!wS.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?o:s:qp(t,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=t.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),k=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),k})}let Uf=null,jf=null,Hf=!1;function xS(t,e,n){return Uf==e&&jf==n?Hf:(Uf=e,jf=n,Hf=n=="up"||n=="down"?kS(t,e,n):vS(t,e,n))}const nt=0,Jf=1,Fn=2,Et=3;let mo=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=nt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nOe(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof Zp){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Qp&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?Oe(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=Oe(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;cp&&sn){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&n<=a){this.dirty=e==r||n==s?Fn:Jf,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Et:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Fn:Et}r=s}this.dirty=Fn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Fn:Jf;n.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==nt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},CS=class extends mo{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ns=class Ta extends mo{constructor(e,n,r,i){super(e,[],r,i),this.mark=n}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=Lt.renderSpec(document,n.type.spec.toDOM(n,r))),new Ta(e,n,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Et&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=nt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Pa(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=Lt.renderSpec(document,n.type.spec.toDOM(n)));!f&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let d=c;return c=nm(c,r,n),u?a=new NS(e,n,r,i,c,f||null,d,u,o,s+1):n.isText?new Gp(e,n,r,i,c,d,o):new Yp(e,n,r,i,c,f||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,n,r){return this.dirty==nt&&e.eq(this.node)&&Aa(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new ES(this,s&&s.node,e);TS(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Fn)&&(s&&this.protectLocalComposition(e,s),em(this.contentDOM,this.children,e),Ir&&RS(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof B)||rn+this.node.content.size)return null;let o=e.domSelectionRange(),s=AS(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=PS(this.node.content,l,r-n,i-n);return a<0?null:{node:s,pos:a,text:l}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new CS(this,o,n,i);e.input.compositionNodes.push(s),this.children=Pa(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==Et||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=nt}updateOuterDeco(e){if(Aa(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=tm(this.dom,this.nodeDOM,Ra(this.outerDeco,this.node,n),Ra(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Kf(t,e,n,r,i){nm(r,e,t);let o=new xr(void 0,t,e,n,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Gp=class Xp extends xr{constructor(e,n,r,i,o,s,l){super(e,n,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Et||this.dirty!=nt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=nt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=nt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new Xp(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Et)}get domAtom(){return!1}},Zp=class extends mo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==nt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class NS extends xr{constructor(e,n,r,i,o,s,l,a,u,c){super(e,n,r,i,o,s,l,u,c),this.spec=a}update(e,n,r,i){if(this.dirty==Et)return!1;if(this.spec.update){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function em(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Ns.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=n.children[r-1];if(u instanceof Ns)n=u,r=u.children.length;else{l=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function DS(t,e){return t.type.side-e.type.side}function TS(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let k=h;s!k.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function RS(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function AS(t,e){for(;;){if(t.nodeType==3)return t;if(t.nodeType==1&&e>0){if(t.childNodes.length>e&&t.childNodes[e].nodeType==3)return t.childNodes[e];t=t.childNodes[e-1],e=St(t)}else if(t.nodeType==1&&e=n){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=n)return l+u;if(n==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Pa(t,e,n,r,i){let o=[];for(let s=0,l=0;s=n||c<=e?o.push(a):(un&&o.push(a.slice(n-u,a.size,r)))}return o}function oc(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(rl(n)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&I.isSelectable(c)&&i.parent&&!(c.isInline&&nS(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;u=new I(s==f?l:r.resolve(f))}}else{let c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||t.state.selection.head{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!rm(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function IS(t){let e=t.domSelection(),n=document.createRange(),r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setEnd(r.parentNode,Oe(r)+1):n.setEnd(r,0),n.collapse(!1),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&Be&&fn<=11&&(r.disabled=!0,r.disabled=!1)}function im(t,e){if(e instanceof I){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Xf(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Xf(t)}function Xf(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function sc(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function Zf(t){return t.editable&&!t.hasFocus()?!1:om(t)}function om(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function bS(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return qn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function za(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&b.findFrom(o,e)}function Gt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function ed(t,e,n){let r=t.state.selection;if(r instanceof B)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Gt(t,new B(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=za(t.state,e);return i&&i instanceof I?Gt(t,i):!1}else if(!(Ge&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(l))&&!s.contentDOM?I.isSelectable(o)?Gt(t,new I(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):po?Gt(t,new B(t.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof I&&r.node.isInline)return Gt(t,new B(e>0?r.$to:r.$from));{let i=za(t.state,e);return i?Gt(t,i):!1}}}function Ms(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function xi(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function ir(t,e){return e<0?FS(t):LS(t)}function FS(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(pt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let l=n.childNodes[r-1];if(xi(l,-1))i=n,o=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(sm(n))break;{let l=n.previousSibling;for(;l&&xi(l,-1);)i=n.parentNode,o=Oe(l),l=l.previousSibling;if(l)n=l,r=Ms(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Ia(t,n,r):i&&Ia(t,i,o)}function LS(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Ms(n),o,s;for(;;)if(r{t.state==i&&$t(t)},50)}function td(t,e){let n=t.state.doc.resolve(e);if(!(xe||sS)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function nd(t,e,n){let r=t.state.selection;if(r instanceof B&&!r.empty||n.indexOf("s")>-1||Ge&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=za(t.state,e);if(s&&s instanceof I)return Gt(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Je?b.near(s,e):b.findFrom(s,e);return l?Gt(t,l):!1}return!1}function rd(t,e){if(!(t.state.selection instanceof B))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function id(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function $S(t){if(!Re||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;id(t,r,"true"),setTimeout(()=>id(t,r,"false"),20)}return!1}function _S(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function WS(t,e){let n=e.keyCode,r=_S(e);if(n==8||Ge&&n==72&&r=="c")return rd(t,-1)||ir(t,-1);if(n==46&&!e.shiftKey||Ge&&n==68&&r=="c")return rd(t,1)||ir(t,1);if(n==13||n==27)return!0;if(n==37||Ge&&n==66&&r=="c"){let i=n==37?td(t,t.state.selection.from)=="ltr"?-1:1:-1;return ed(t,i,r)||ir(t,i)}else if(n==39||Ge&&n==70&&r=="c"){let i=n==39?td(t,t.state.selection.from)=="ltr"?1:-1:1;return ed(t,i,r)||ir(t,i)}else{if(n==38||Ge&&n==80&&r=="c")return nd(t,-1,r)||ir(t,-1);if(n==40||Ge&&n==78&&r=="c")return $S(t)||nd(t,1,r)||ir(t,1);if(r==(Ge?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function lm(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||Lt.fromSchema(t.state.schema),l=hm(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=dm[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` + */var D0=C,T0=Symbol.for("react.element"),R0=Symbol.for("react.fragment"),A0=Object.prototype.hasOwnProperty,P0=D0.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,z0={key:!0,ref:!0,__self:!0,__source:!0};function np(t,e,n){var r,i={},o=null,s=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(r in e)A0.call(e,r)&&!z0.hasOwnProperty(r)&&(i[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:T0,type:t,key:o,ref:s,props:i,_owner:P0.current}}tl.Fragment=R0;tl.jsx=np;tl.jsxs=np;Kh.exports=tl;var Hu=Kh.exports;const Ju=Hu.Fragment,z=Hu.jsx,kf=Hu.jsxs;function de(t){this.content=t}de.prototype={constructor:de,find:function(t){for(var e=0;e>1}};de.from=function(t){if(t instanceof de)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new de(e)};function rp(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),o=e.child(r);if(i==o){n+=i.nodeSize;continue}if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)n++;return n}if(i.content.size||o.content.size){let s=rp(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function ip(t,e,n,r){for(let i=t.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:n,b:r};let s=t.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){n-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:n,b:r};if(s.isText&&s.text!=l.text){let u=0,c=Math.min(s.text.length,l.text.length);for(;ue&&r(a,i+l,o||null,s)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,n-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,n-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=u},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),o=1);oe)for(let o=0,s=0;se&&((sn)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,n-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,n-s-1))),r.push(l),i+=l.nodeSize),s=a}return new v(r,i)}cutByIndex(e,n){return e==n?v.empty:e==0&&n==this.content.length?this:new v(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new v(i,o)}addToStart(e){return new v([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new v(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||n>0?Eo(r+1,s):Eo(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return v.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new v(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return v.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}}W.none=[];class Ii extends Error{}class x{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=sp(this.content,e+this.openStart,n);return r&&new x(r,this.openStart,this.openEnd)}removeBetween(e,n){return new x(op(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return x.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(v.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)i++;return new x(e,r,i)}}x.empty=new x(v.empty,0,0);function op(t,e,n){let{index:r,offset:i}=t.findIndex(e),o=t.maybeChild(r),{index:s,offset:l}=t.findIndex(n);if(i==e||o.isText){if(l!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(op(o.content,e-i-1,n-i-1)))}function sp(t,e,n,r){let{index:i,offset:o}=t.findIndex(e),s=t.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=sp(s.content,e-o-1,n);return l&&t.replaceChild(i,s.copy(l))}function b0(t,e,n){if(n.openStart>t.depth)throw new Ii("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Ii("Inconsistent open depths");return lp(t,e,n,0)}function lp(t,e,n,r){let i=t.index(r),o=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Si(t,e,n,r){let i=(e||t).node(n),o=0,s=e?e.index(n):i.childCount;t&&(o=t.index(n),t.depth>n?o++:t.textOffset&&(_n(t.nodeAfter,r),o++));for(let l=o;li&&xa(t,e,i+1),s=r.depth>i&&xa(n,r,i+1),l=[];return Si(null,t,i,l),o&&s&&e.index(i)==n.index(i)?(ap(o,s),_n(Wn(o,up(t,e,n,r,i+1)),l)):(o&&_n(Wn(o,Ss(t,e,i+1)),l),Si(e,n,i,l),s&&_n(Wn(s,Ss(n,r,i+1)),l)),Si(r,null,i,l),new v(l)}function Ss(t,e,n){let r=[];if(Si(null,t,n,r),t.depth>n){let i=xa(t,e,n+1);_n(Wn(i,Ss(t,e,n+1)),r)}return Si(e,null,n,r),new v(r)}function I0(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let o=n-1;o>=0;o--)i=e.node(o).copy(v.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Fi{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let o=0;o0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new L0(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,o=n;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),u=o-a;if(r.push(s,l,i+a),!u||(s=s.child(l),s.isText))break;o=u-1,i+=a+1}return new Fi(n,r,o)}static resolveCached(e,n){for(let i=0;ie&&this.nodesBetween(e,n,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),cp(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=v.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let a=i;an.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=v.fromJSON(e,n.content);return e.nodeType(n.type).create(n.attrs,i,r)}}vt.prototype.text=void 0;class ws extends vt{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):cp(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new ws(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ws(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function cp(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Kn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new V0(e,n);if(r.next==null)return Kn.empty;let i=fp(r);r.next&&r.err("Unexpected trailing text");let o=J0(H0(i));return K0(o,r),o}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}}Kn.empty=new Kn(!0);class V0{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function fp(t){let e=[];do e.push($0(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function $0(t){let e=[];do e.push(_0(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function _0(t){let e=j0(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=W0(t,e);else break;return e}function Sf(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function W0(t,e){let n=Sf(t),r=n;return t.eat(",")&&(t.next!="}"?r=Sf(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function U0(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let o in n){let s=n[o];s.groups.indexOf(e)>-1&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function j0(t){if(t.eat("(")){let e=fp(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=U0(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function H0(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,l,a){let u={term:a,to:l};return e[s].push(u),u}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,u)=>a.concat(o(u,l)),[]);if(s.type=="seq")for(let a=0;;a++){let u=o(s.exprs[a],l);if(a==s.exprs.length-1)return u;i(u,l=n())}else if(s.type=="star"){let a=n();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=n();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let u=0;u{t[s].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let o=e[r.join(",")]=new Kn(r.indexOf(t.length-1)>-1);for(let s=0;s-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[o]=new gp(o,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};class q0{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class co{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=mp(i.attrs),this.excluded=null;let o=hp(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,pp(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new co(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}}class yp{constructor(e){this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=de.from(e.nodes),n.marks=de.from(e.marks||{}),this.nodes=vf.compile(this.spec.nodes,this),this.marks=co.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;o.contentMatch=r[s]||(r[s]=Kn.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.markSet=l=="_"?null:l?xf(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:xf(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof vf){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new ws(r,r.defaultAttrs,e,W.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return vt.fromJSON(this,e)}markFromJSON(e){return W.fromJSON(this,e)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function xf(t,e){let n=[];for(let r=0;r-1)&&n.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}class Li{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,n={}){let r=new Nf(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Nf(this,n,!0);return r.addAll(e,n.from,n.to),x.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(s.getAttrs){let a=s.getAttrs(n);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=Mf(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=Mf(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Li(e,Li.schemaRules(e)))}}const kp={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Q0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Sp={ol:!0,ul:!0},vs=1,xs=2,wi=4;function Cf(t,e,n){return e!=null?(e?vs:0)|(e==="full"?xs:0):t&&t.whitespace=="pre"?vs|xs:n&~wi}class Oo{constructor(e,n,r,i,o,s,l){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=i,this.solid=o,this.options=l,this.content=[],this.activeMarks=W.none,this.stashMarks=[],this.match=s||(l&wi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(v.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&vs)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let n=v.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(v.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;nthis.addAll(e)),s&&this.sync(l),this.needsBlock=a}else this.withStyleRules(e,()=>{this.addElementByRule(e,o,o.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=W.none,r=W.none;for(let i=0;i{s.clearMark(l)&&(r=l.addToSet(r))}):n=this.parser.schema.marks[s.mark].create(s.attrs).addToSet(n),s.consuming===!1)o=s;else break}return[n,r]}addElementByRule(e,n,r){let i,o,s;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):i=this.enter(o,n.attrs||null,n.preserveWhitespace)):(s=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(s));let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a)}i&&this.sync(l)&&this.open--,s&&this.removePendingMark(s,l)}addAll(e,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o);this.findAtPoint(e,i)}findPlace(e){let n,r;for(let i=this.open;i>=0;i--){let o=this.nodes[i],s=o.findWrapping(e);if(s&&(!n||n.length>s.length)&&(n=s,r=o,!s.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let i=0;ithis.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!c||c.name!=u&&c.groups.indexOf(u)==-1)return!1;a--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=e1(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let s=i.popFromStashMark(e);s&&i.type&&i.type.allowsMarkType(s.type)&&(i.activeMarks=s.addToSet(i.activeMarks))}if(i==n)break}}}function Y0(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Sp.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function G0(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function X0(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function Mf(t){let e={};for(let n in t)e[n]=t[n];return e}function Z0(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,n);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Lt.renderSpec(Tl(r),i(e,n))}static renderSpec(e,n,r=null){if(typeof n=="string")return{dom:e.createTextNode(n)};if(n.nodeType!=null)return{dom:n};if(n.dom&&n.dom.nodeType!=null)return n;let i=n[0],o=i.indexOf(" ");o>0&&(r=i.slice(0,o),i=i.slice(o+1));let s,l=r?e.createElementNS(r,i):e.createElement(i),a=n[1],u=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){u=2;for(let c in a)if(a[c]!=null){let f=c.indexOf(" ");f>0?l.setAttributeNS(c.slice(0,f),c.slice(f+1),a[c]):l.setAttribute(c,a[c])}}for(let c=u;cu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:d,contentDOM:p}=Lt.renderSpec(e,f,r);if(l.appendChild(d),p){if(s)throw new RangeError("Multiple content holes");s=p}}}return{dom:l,contentDOM:s}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Lt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Ef(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Ef(e.marks)}}function Ef(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Tl(t){return t.document||window.document}const wp=65535,vp=Math.pow(2,16);function t1(t,e){return t+e*vp}function Of(t){return t&wp}function n1(t){return(t-(t&wp))/vp}const xp=1,Cp=2,Zo=4,Np=8;let Ca=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Np)>0}get deletedBefore(){return(this.delInfo&(xp|Zo))>0}get deletedAfter(){return(this.delInfo&(Cp|Zo))>0}get deletedAcross(){return(this.delInfo&Zo)>0}},Ar=class sr{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&sr.empty)return sr.empty}recover(e){let n=0,r=Of(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:n:n,p=a+i+(d<0?0:c);if(r)return p;let h=e==(n<0?a:f)?null:t1(l/3,e-a),m=e==a?Cp:e==f?xp:Zo;return(n<0?e!=a:e!=f)&&(m|=Np),new Ca(p,m,h)}i+=c-u}return r?e+i:new Ca(e+i,0,null)}touches(e,n){let r=0,i=Of(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new es;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return Fe.fromReplace(e,this.from,this.to,o)}invert(){return new fo(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new li(n.pos,r.pos,this.mark)}merge(e){return e instanceof li&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new li(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new li(n.from,n.to,e.markFromJSON(n.mark))}};We.jsonID("addMark",qu);let fo=class ai extends We{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new x(Ku(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Fe.fromReplace(e,this.from,this.to,r)}invert(){return new qu(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ai(n.pos,r.pos,this.mark)}merge(e){return e instanceof ai&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ai(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ai(n.from,n.to,e.markFromJSON(n.mark))}};We.jsonID("removeMark",fo);let Qu=class ui extends We{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Fe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Fe.fromReplace(e,this.pos,this.pos+1,new x(v.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new ts(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new ts(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}};We.jsonID("replaceAround",Wt);function Ma(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function i1(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(a)),o.forEach(a=>t.step(a))}function o1(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof co){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new fo(s.from,s.to,s.style)))}function s1(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function l1(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Gu(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let i=t.$from.node(r),o=t.$from.index(r),s=t.$to.indexAfter(r);if(rn;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new Wt(i,o,i,o,new x(r,0,0),n.length,!0))}function h1(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&p1(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new Wt(u,c,u+1,c-1,new x(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function p1(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function m1(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Wt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new x(v.from(s),0,0),1,!0))}function ns(t,e,n=1,r){let i=t.resolve(e),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,c=n-2;u>o;u--,c--){let f=i.node(u),d=i.index(u);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),h=r&&r[c]||f;if(h!=f&&(p=p.replaceChild(0,h.type.create(h.attrs))),!f.canReplace(d+1,f.childCount)||!h.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function g1(t,e,n=1,r){let i=t.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new Cn(e,e,new x(o.append(s),n,n),!0))}function Xu(t,e){let n=t.resolve(e),r=n.index();return y1(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function y1(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}function k1(t,e,n){let r=new Cn(e-n,e+n,x.empty,!0);t.step(r)}function S1(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),u=r.node(s),c=!1;if(o==1)c=u.canReplace(a,a,i);else{let f=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=f&&u.canReplaceWith(a,a,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Zu(t,e,n=e,r=x.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return Mp(i,o,r)?new Cn(e,n,r):new v1(i,o,r).fit()}function Mp(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}let v1=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=v.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new x(o,s,l);return e>-1?new Wt(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new Cn(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Al(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(n==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Al(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Al(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new x(ci(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new x(ci(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=S,c.push(Ep(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=fi(this.placed,n,v.from(c)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,S=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Pl(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=fi(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=fi(this.placed,this.depth,v.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(v.empty,!0);n.childCount&&(this.placed=fi(this.placed,this.frontier.length,n))}};function ci(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(ci(t.firstChild.content,e-1,n)))}function fi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(fi(t.lastChild.content,e-1,n)))}function Al(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Ep(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),t.copy(r)}function Pl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!x1(n,o.content,s)?l:null}function x1(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d].type,h=C1(p);if(h&&i.node(a).type!=p)c=d;else if(h||!p.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function Op(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return t}function M1(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=S1(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new x(v.from(r),0,0))}function E1(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Dp(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function Dp(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}let Tp=class rs extends We{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Fe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Fe.fromReplace(e,this.pos,this.pos+1,new x(v.from(i),0,n.isLeaf?0:1))}getMap(){return Ar.empty}invert(e){return new rs(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new rs(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new rs(n.pos,n.attr,n.value)}};We.jsonID("attr",Tp);let Pr=class extends Error{};Pr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Pr.prototype=Object.create(Error.prototype);Pr.prototype.constructor=Pr;Pr.prototype.name="TransformError";let O1=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new r1}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Pr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=x.empty){let i=Zu(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new x(v.from(r),0,0))}delete(e,n){return this.replace(e,n,x.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return N1(this,e,n,r),this}replaceRangeWith(e,n,r){return M1(this,e,n,r),this}deleteRange(e,n){return E1(this,e,n),this}lift(e,n){return a1(this,e,n),this}join(e,n=1){return k1(this,e,n),this}wrap(e,n){return d1(this,e,n),this}setBlockType(e,n=e,r,i=null){return h1(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return m1(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Tp(e,n,r)),this}addNodeMark(e,n){return this.step(new Qu(e,n)),this}removeNodeMark(e,n){if(!(n instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new Yu(e,n)),this}split(e,n=1,r){return g1(this,e,n,r),this}addMark(e,n,r){return i1(this,e,n,r),this}removeMark(e,n,r){return o1(this,e,n,r),this}clearIncompatible(e,n,r){return s1(this,e,n,r),this}};const zl=Object.create(null);class I{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Rp(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;o--){let s=n<0?lr(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):lr(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(s)return s}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new Je(e.node(0))}static atStart(e){return lr(e,e,0,0,1)||new Je(e)}static atEnd(e){return lr(e,e,e.content.size,e.childCount,-1)||new Je(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=zl[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in zl)throw new RangeError("Duplicate use of selection JSON ID "+e);return zl[e]=n,n.prototype.jsonID=e,n}getBookmark(){return B.between(this.$anchor,this.$head).getBookmark()}}I.prototype.visible=!0;class Rp{constructor(e,n){this.$from=e,this.$to=n}}let Tf=!1;function Rf(t){!Tf&&!t.parent.inlineContent&&(Tf=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class B extends I{constructor(e,n=e){Rf(e),Rf(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return I.near(r);let i=e.resolve(n.map(this.anchor));return new B(i.parent.inlineContent?i:r,r)}replace(e,n=x.empty){if(super.replace(e,n),n==x.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof B&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new nl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new B(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let o=I.findFrom(n,r,!0)||I.findFrom(n,-r,!0);if(o)n=o.$head;else return I.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(I.findFrom(e,-r,!0)||I.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&b.isSelectable(l))return b.create(t,n-(i<0?l.nodeSize:0))}else{let a=lr(t,l,n+i,i<0?l.childCount:0,i,o);if(a)return a}n+=l.nodeSize*i}return null}function Af(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=c)}),t.setSelection(I.near(t.doc.resolve(s),n))}const Pf=1,Do=2,zf=4;class T1 extends O1{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Do,this}ensureMarks(e){return W.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Do)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Do,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||W.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),r=r??n,!e)return this.deleteRange(n,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(n);o=r==n?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,o)),this.selection.empty||this.setSelection(I.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=zf,this}get scrolledIntoView(){return(this.updated&zf)>0}}function bf(t,e){return!e||!t?t:t.bind(e)}class di{constructor(e,n,r){this.name=e,this.init=bf(n.init,r),this.apply=bf(n.apply,r)}}const R1=[new di("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new di("selection",{init(t,e){return t.selection||I.atStart(e.doc)},apply(t){return t.selection}}),new di("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new di("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class bl{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=R1.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new di(r.key,r.spec.state,r))})}}class on{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(n[r]=o.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new bl(e.schema,e.plugins),o=new on(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=vt.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=I.fromJSON(o.doc,n.selection);else if(s.name=="storedMarks")n.storedMarks&&(o.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==s.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){o[s.name]=u.fromJSON.call(a,e,n[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Ap(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ap(i,e,{})),n[r]=i}return n}class Tt{constructor(e){this.spec=e,this.props={},e.props&&Ap(e.props,this,this.props),this.key=e.key?e.key.key:Pp("plugin")}getState(e){return e[this.key]}}const Il=Object.create(null);function Pp(t){return t in Il?t+"$"+ ++Il[t]:(Il[t]=0,t+"$")}class ho{constructor(e="key"){this.key=Pp(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const zp=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function A1(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const P1=(t,e,n)=>{let r=A1(t,n);if(!r)return!1;let i=bp(r);if(!i){let s=r.blockRange(),l=s&&Gu(s);return l==null?!1:(e&&e(t.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Fp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"end")||b.isSelectable(o))){let s=Zu(t.doc,r.before(),r.after(),x.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;o=bp(r)}let s=o&&o.nodeBefore;return!s||!b.isSelectable(s)?!1:(e&&e(t.tr.setSelection(b.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function bp(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function b1(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=b1(t,n);if(!r)return!1;let i=Ip(r);if(!i)return!1;let o=i.nodeAfter;if(Fp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"start")||b.isSelectable(o))){let s=Zu(t.doc,r.before(),r.after(),x.empty);if(s&&s.slice.size{let{$head:r,empty:i}=t.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` +`).scrollIntoView()),!0)};function tc(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=tc(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=n.after(),a=t.tr.replaceWith(l,l,s.createAndFill());a.setSelection(I.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},V1=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof Je||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=tc(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if(ns(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Gu(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function _1(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof b&&e.selection.node.isBlock)return!r.parentOffset||!ns(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(n){let o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof B||e.selection instanceof Je)&&s.deleteSelection();let l=r.depth==0?null:tc(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=t&&t(i.parent,o),u=a?[a]:o&&l?[{type:l}]:void 0,c=ns(s.doc,s.mapping.map(r.pos),1,u);if(!u&&!c&&ns(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(u=[{type:l}]),c=!0),c&&(s.split(s.mapping.map(r.pos),1,u),!o&&!r.parentOffset&&r.parent.type!=l)){let f=s.mapping.map(r.before()),d=s.doc.resolve(f);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}n(s.scrollIntoView())}return!0}}const W1=_1(),U1=(t,e)=>(e&&e(t.tr.setSelection(new Je(t.doc))),!0);function j1(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||Xu(t.doc,e.pos))?!1:(n&&n(t.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Fp(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(j1(t,e,n))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(o=(s=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&s.matchType(o[0]||i.type).validEnd){if(n){let f=e.pos+i.nodeSize,d=v.empty;for(let m=o.length-1;m>=0;m--)d=v.from(o[m].create(null,d));d=v.from(r.copy(d));let p=t.tr.step(new Wt(e.pos-1,f,e.pos,f,new x(d,1,0),o.length,!0)),h=f+2*o.length;Xu(p.doc,h)&&p.join(h),n(p.scrollIntoView())}return!0}let a=I.findFrom(e,1),u=a&&a.$from.blockRange(a.$to),c=u&&Gu(u);if(c!=null&&c>=e.depth)return n&&n(t.tr.lift(u,c).scrollIntoView()),!0;if(l&&zr(i,"start",!0)&&zr(r,"end")){let f=r,d=[];for(;d.push(f),!f.isTextblock;)f=f.lastChild;let p=i,h=1;for(;!p.isTextblock;p=p.firstChild)h++;if(f.canReplace(f.childCount,f.childCount,p.content)){if(n){let m=v.empty;for(let g=d.length-1;g>=0;g--)m=v.from(d[g].copy(m));let S=t.tr.step(new Wt(e.pos-d.length,e.pos+i.nodeSize,e.pos+h,e.pos+i.nodeSize-h,new x(m,d.length,0),0,!0));n(S.scrollIntoView())}return!0}}return!1}function Lp(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(n&&n(e.tr.setSelection(B.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}const H1=Lp(-1),J1=Lp(1);function K1(t,e,n){for(let r=0;r{if(s)return!1;s=l.inlineContent&&l.type.allowsMarkType(n)}),s)return!0}return!1}function If(t,e=null){return function(n,r){let{empty:i,$cursor:o,ranges:s}=n.selection;if(i&&!o||!K1(n.doc,s,t))return!1;if(r)if(o)t.isInSet(n.storedMarks||o.marks())?r(n.tr.removeStoredMark(t)):r(n.tr.addStoredMark(t.create(e)));else{let l=!1,a=n.tr;for(let u=0;!l&&u",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Lf=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),Y1=typeof navigator<"u"&&/Mac/.test(navigator.platform),G1=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),X1=Y1||Lf&&+Lf[1]<57;for(var pe=0;pe<10;pe++)Ut[48+pe]=Ut[96+pe]=String(pe);for(var pe=1;pe<=24;pe++)Ut[pe+111]="F"+pe;for(var pe=65;pe<=90;pe++)Ut[pe]=String.fromCharCode(pe+32),Cs[pe]=String.fromCharCode(pe);for(var Ll in Ut)Cs.hasOwnProperty(Ll)||(Cs[Ll]=Ut[Ll]);function Vp(t){var e=X1&&(t.ctrlKey||t.altKey||t.metaKey)||G1&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Cs:Ut)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}const Z1=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function ek(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let l=0;l127)&&(o=Ut[r.keyCode])&&o!=i){let l=e[Bl(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Oe=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Bi=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let Bf=null;const zt=function(t,e,n){let r=Bf||(Bf=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},qn=function(t,e,n,r){return n&&(Vf(t,e,n,r,-1)||Vf(t,e,n,r,1))},nk=/^(img|br|input|textarea|hr)$/i;function Vf(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:kt(t))){let o=t.parentNode;if(!o||o.nodeType!=1||rc(t)||nk.test(t.nodeName)||t.contentEditable=="false")return!1;e=Oe(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?kt(t):0}else return!1}}function kt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function rk(t,e,n){for(let r=e==0,i=e==kt(t);r||i;){if(t==n)return!0;let o=Oe(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==kt(t)}}function rc(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const rl=function(t){return t.focusNode&&qn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function bn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function ik(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function ok(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:r.startOffset}}}const Mt=typeof navigator<"u"?navigator:null,$f=typeof document<"u"?document:null,Nn=Mt&&Mt.userAgent||"",Ea=/Edge\/(\d+)/.exec(Nn),_p=/MSIE \d/.exec(Nn),Oa=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Nn),Be=!!(_p||Oa||Ea),fn=_p?document.documentMode:Oa?+Oa[1]:Ea?+Ea[1]:0,pt=!Be&&/gecko\/(\d+)/i.test(Nn);pt&&+(/Firefox\/(\d+)/.exec(Nn)||[0,0])[1];const Da=!Be&&/Chrome\/(\d+)/.exec(Nn),xe=!!Da,sk=Da?+Da[1]:0,Re=!Be&&!!Mt&&/Apple Computer/.test(Mt.vendor),br=Re&&(/Mobile\/\w+/.test(Nn)||!!Mt&&Mt.maxTouchPoints>2),Ge=br||(Mt?/Mac/.test(Mt.platform):!1),lk=Mt?/Win/.test(Mt.platform):!1,ct=/Android \d/.test(Nn),po=!!$f&&"webkitFontSmoothing"in $f.documentElement.style,ak=po?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function uk(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function At(t,e){return typeof t=="number"?t:t[e]}function ck(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function _f(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,o=t.dom.ownerDocument;for(let s=n||t.dom;s;s=Bi(s)){if(s.nodeType!=1)continue;let l=s,a=l==o.body,u=a?uk(o):ck(l),c=0,f=0;if(e.topu.bottom-At(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+At(i,"top")-u.top:e.bottom-u.bottom+At(i,"bottom")),e.leftu.right-At(r,"right")&&(c=e.right-u.right+At(i,"right")),c||f)if(a)o.defaultView.scrollBy(c,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),c&&(l.scrollLeft+=c);let h=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function fk(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=n+1;s=n-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Wp(t.dom)}}function Wp(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Bi(r));return e}function dk({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Up(n,r==0?0:r-e)}function Up(t,e){for(let n=0;n=l){s=Math.max(h.bottom,s),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=c,u={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!n&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(o=f+1)}}return!n&&a&&(n=a,i=u,r=0),n&&n.nodeType==3?pk(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:jp(n,i)}function pk(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:t,offset:0}}function ic(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function mk(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(s.left+s.right)/2?1:-1}return t.docView.posFromDOM(r,i,o)}function yk(t,e,n,r){let i=-1;for(let o=e,s=!1;o!=t.dom;){let l=t.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!s||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,a.left>r.left||a.top>r.top?i=l.posBefore:(a.right-1?i:t.docView.posFromDOM(e,n,-1)}function Hp(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;po&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=yk(t,r,i,e))}l==null&&(l=gk(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Wf(t){return t.top=0&&i==r.nodeValue.length?(a--,c=1):n<0?a--:u++,Gr(Yt(zt(r,a,u),c),c<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==kt(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Vl(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==kt(r))){let a=r.childNodes[i-1],u=a.nodeType==3?zt(a,kt(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Gr(Yt(u,1),!1)}if(o==null&&i=0)}function Gr(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Vl(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Kp(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function wk(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Kp(t,e,()=>{let{node:o}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Jp(t,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=zt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(n=="up"?s.top-c.top>(c.bottom-s.top)*2:c.bottom-s.bottom>(s.bottom-c.top)*2))return!1}}return!0})}const vk=/[\u0590-\u08ac]/;function xk(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=t.domSelection();return!vk.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?o:s:Kp(t,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:f}=t.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",n,"character");let p=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:h,focusOffset:m}=t.domSelectionRange(),S=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&u==m;try{l.collapse(c,f),a&&(a!=c||u!=f)&&l.extend&&l.extend(a,u)}catch{}return d!=null&&(l.caretBidiLevel=d),S})}let Uf=null,jf=null,Hf=!1;function Ck(t,e,n){return Uf==e&&jf==n?Hf:(Uf=e,jf=n,Hf=n=="up"||n=="down"?wk(t,e,n):xk(t,e,n))}const nt=0,Jf=1,Fn=2,Et=3;let mo=class{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=nt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nOe(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof Xp){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof qp&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?Oe(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=Oe(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;cp&&sn){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&n<=a){this.dirty=e==r||n==s?Fn:Jf,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Et:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Fn:Et}r=s}this.dirty=Fn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?Fn:Jf;n.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!n.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=n,this.widget=n,o=this}matchesWidget(e){return this.dirty==nt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Nk=class extends mo{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Ns=class Ta extends mo{constructor(e,n,r,i){super(e,[],r,i),this.mark=n}static create(e,n,r,i){let o=i.nodeViews[n.type.name],s=o&&o(n,i,r);return(!s||!s.dom)&&(s=Lt.renderSpec(document,n.type.spec.toDOM(n,r))),new Ta(e,n,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Et&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=nt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Pa(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,f=u&&u.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:f}=Lt.renderSpec(document,n.type.spec.toDOM(n)));!f&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let d=c;return c=tm(c,r,n),u?a=new Mk(e,n,r,i,c,f||null,d,u,o,s+1):n.isText?new Yp(e,n,r,i,c,d,o):new Qp(e,n,r,i,c,f||null,d,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,n,r){return this.dirty==nt&&e.eq(this.node)&&Aa(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,o=e.composing?this.localCompositionInfo(e,n):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Ok(this,s&&s.node,e);Rk(this.node,this.innerDeco,(u,c,f)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&a.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),a.placeWidget(u,e,i)},(u,c,f,d)=>{a.syncToMarks(u.marks,r,e);let p;a.findNodeMatch(u,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,f,p,e)||a.updateNextNode(u,c,f,e,d,i)||a.addNode(u,c,f,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Fn)&&(s&&this.protectLocalComposition(e,s),Zp(this.contentDOM,this.children,e),br&&Ak(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof B)||rn+this.node.content.size)return null;let o=e.domSelectionRange(),s=Pk(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=zk(this.node.content,l,r-n,i-n);return a<0?null:{node:s,pos:a,text:l}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let o=n;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Nk(this,o,n,i);e.input.compositionNodes.push(s),this.children=Pa(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==Et||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=nt}updateOuterDeco(e){if(Aa(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=em(this.dom,this.nodeDOM,Ra(this.outerDeco,this.node,n),Ra(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Kf(t,e,n,r,i){tm(r,e,t);let o=new xr(void 0,t,e,n,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let Yp=class Gp extends xr{constructor(e,n,r,i,o,s,l){super(e,n,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Et||this.dirty!=nt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=nt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=nt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),o=document.createTextNode(i.text);return new Gp(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Et)}get domAtom(){return!1}},Xp=class extends mo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==nt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}};class Mk extends xr{constructor(e,n,r,i,o,s,l,a,u,c){super(e,n,r,i,o,s,l,u,c),this.spec=a}update(e,n,r,i){if(this.dirty==Et)return!1;if(this.spec.update){let o=this.spec.update(e,n,r);return o&&this.updateInner(e,n,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Zp(t,e,n){let r=t.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Ns.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,n,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,n,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=n.children[r-1];if(u instanceof Ns)n=u,r=u.children.length;else{l=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Tk(t,e){return t.type.side-e.type.side}function Rk(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let h=o+d.nodeSize;if(d.isText){let S=h;s!S.inline):l.slice();r(d,m,e.forChild(o,d),p),o=h}}function Ak(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function Pk(t,e){for(;;){if(t.nodeType==3)return t;if(t.nodeType==1&&e>0){if(t.childNodes.length>e&&t.childNodes[e].nodeType==3)return t.childNodes[e];t=t.childNodes[e-1],e=kt(t)}else if(t.nodeType==1&&e=n){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=n)return l+u;if(n==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Pa(t,e,n,r,i){let o=[];for(let s=0,l=0;s=n||c<=e?o.push(a):(un&&o.push(a.slice(n-u,a.size,r)))}return o}function oc(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,u;if(rl(n)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&b.isSelectable(c)&&i.parent&&!(c.isInline&&rk(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;u=new b(s==f?l:r.resolve(f))}}else{let c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){let c=e=="pointer"||t.state.selection.head{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!nm(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ik(t){let e=t.domSelection(),n=document.createRange(),r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setEnd(r.parentNode,Oe(r)+1):n.setEnd(r,0),n.collapse(!1),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&Be&&fn<=11&&(r.disabled=!0,r.disabled=!1)}function rm(t,e){if(e instanceof b){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Xf(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Xf(t)}function Xf(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function sc(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function Zf(t){return t.editable&&!t.hasFocus()?!1:im(t)}function im(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Fk(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return qn(e.node,e.offset,n.anchorNode,n.anchorOffset)}function za(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return o&&I.findFrom(o,e)}function Gt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function ed(t,e,n){let r=t.state.selection;if(r instanceof B)if(n.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=t.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Gt(t,new B(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=za(t.state,e);return i&&i instanceof b?Gt(t,i):!1}else if(!(Ge&&n.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=t.docView.descAt(l))&&!s.contentDOM?b.isSelectable(o)?Gt(t,new b(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):po?Gt(t,new B(t.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof b&&r.node.isInline)return Gt(t,new B(e>0?r.$to:r.$from));{let i=za(t.state,e);return i?Gt(t,i):!1}}}function Ms(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function xi(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function ir(t,e){return e<0?Lk(t):Bk(t)}function Lk(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,o,s=!1;for(pt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let l=n.childNodes[r-1];if(xi(l,-1))i=n,o=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(om(n))break;{let l=n.previousSibling;for(;l&&xi(l,-1);)i=n.parentNode,o=Oe(l),l=l.previousSibling;if(l)n=l,r=Ms(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?ba(t,n,r):i&&ba(t,i,o)}function Bk(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Ms(n),o,s;for(;;)if(r{t.state==i&&$t(t)},50)}function td(t,e){let n=t.state.doc.resolve(e);if(!(xe||lk)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let o=t.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function nd(t,e,n){let r=t.state.selection;if(r instanceof B&&!r.empty||n.indexOf("s")>-1||Ge&&n.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let s=za(t.state,e);if(s&&s instanceof b)return Gt(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Je?I.near(s,e):I.findFrom(s,e);return l?Gt(t,l):!1}return!1}function rd(t,e){if(!(t.state.selection instanceof B))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let s=t.state.tr;return e<0?s.delete(n.pos-o.nodeSize,n.pos):s.delete(n.pos,n.pos+o.nodeSize),t.dispatch(s),!0}return!1}function id(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function _k(t){if(!Re||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;id(t,r,"true"),setTimeout(()=>id(t,r,"false"),20)}return!1}function Wk(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function Uk(t,e){let n=e.keyCode,r=Wk(e);if(n==8||Ge&&n==72&&r=="c")return rd(t,-1)||ir(t,-1);if(n==46&&!e.shiftKey||Ge&&n==68&&r=="c")return rd(t,1)||ir(t,1);if(n==13||n==27)return!0;if(n==37||Ge&&n==66&&r=="c"){let i=n==37?td(t,t.state.selection.from)=="ltr"?-1:1:-1;return ed(t,i,r)||ir(t,i)}else if(n==39||Ge&&n==70&&r=="c"){let i=n==39?td(t,t.state.selection.from)=="ltr"?1:-1:1;return ed(t,i,r)||ir(t,i)}else{if(n==38||Ge&&n==80&&r=="c")return nd(t,-1,r)||ir(t,-1);if(n==40||Ge&&n==78&&r=="c")return _k(t)||nd(t,1,r)||ir(t,1);if(r==(Ge?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function sm(t,e){t.someProp("transformCopied",p=>{e=p(e,t)});let n=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;n.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=t.someProp("clipboardSerializer")||Lt.fromSchema(t.state.schema),l=dm(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=fm[u.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),f++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(n)}`);let d=t.someProp("clipboardTextSerializer",p=>p(e,t))||e.content.textBetween(0,e.content.size,` -`);return{dom:a,text:d}}function am(t,e,n,r,i){let o=i.parent.type.spec.code,s,l;if(!n&&!e)return null;let a=e&&(r||o||!n);if(a){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return e?new x(v.from(t.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):x.empty;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)l=f;else{let d=i.marks(),{schema:p}=t.state,h=Lt.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let k=s.appendChild(document.createElement("p"));m&&k.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=HS(n),po&&JS(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(t.someProp("clipboardParser")||t.someProp("domParser")||Li.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!US.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=KS(od(l,+c[1],+c[2]),c[4]);else if(l=x.maxOpen(jS(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,t)}),l}const US=/^(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 jS(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&cm(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=fm(s[s.length-1],o.length));let c=um(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return v.from(s)}return t}function um(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,v.from(t));return t}function cm(t,e,n,r,i){if(i1&&(o=0),i=n&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(v.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(l))}function od(t,e,n){return e]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=hm().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&dm[r[1].toLowerCase()])&&(t=i.map(o=>"<"+o+">").join("")+t+i.map(o=>"").reverse().join("")),n.innerHTML=t,i)for(let o=0;o=0;l-=2){let a=n.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=v.from(a.create(r[l+1],i)),o++,s++}return new x(i,o,s)}const Ae={},Pe={},qS={touchstart:!0,touchmove:!0};class QS{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function YS(t){for(let e in Ae){let n=Ae[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{XS(t,r)&&!lc(t,r)&&(t.editable||!(r.type in Pe))&&n(t,r)},qS[e]?{passive:!0}:void 0)}Re&&t.dom.addEventListener("input",()=>null),Fa(t)}function sn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function GS(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Fa(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>lc(t,r))})}function lc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function XS(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function ZS(t,e){!lc(t,e)&&Ae[e.type]&&(t.editable||!(e.type in Pe))&&Ae[e.type](t,e)}Pe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!mm(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(ct&&xe&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),Ir&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,In(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||WS(t,n)?n.preventDefault():sn(t,"key")};Pe.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Pe.keypress=(t,e)=>{let n=e;if(mm(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||Ge&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof B)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode);!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",o=>o(t,r.$from.pos,r.$to.pos,i))&&t.dispatch(t.state.tr.insertText(i).scrollIntoView()),n.preventDefault()}};function il(t){return{left:t.clientX,top:t.clientY}}function ek(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function ac(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,l=>s>o.depth?l(t,n,o.nodeAfter,o.before(s),i,!0):l(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function Cr(t,e,n){t.focused||t.focus();let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function tk(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&I.isSelectable(r)?(Cr(t,new I(n),"pointer"),!0):!1}function nk(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof I&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(I.isSelectable(l)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?(Cr(t,I.create(t.state.doc,i),"pointer"),!0):!1}function rk(t,e,n,r,i){return ac(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?nk(t,n):tk(t,n))}function ik(t,e,n,r){return ac(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function ok(t,e,n,r){return ac(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||sk(t,n,r)}function sk(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(Cr(t,B.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Cr(t,B.create(r,l+1,l+1+s.content.size),"pointer");else if(I.isSelectable(s))Cr(t,I.create(r,l),"pointer");else continue;return!0}}function uc(t){return Es(t)}const pm=Ge?"metaKey":"ctrlKey";Ae.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=uc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&ek(n,t.input.lastClick)&&!n[pm]&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o};let s=t.posAtCoords(il(n));s&&(o=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new lk(t,s,n,!!r)):(o=="doubleClick"?ik:ok)(t,s.pos,s.inside,n)?n.preventDefault():sn(t,"pointer"))};class lk{constructor(e,n,r,i){this.view=e,this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[pm],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let c=e.state.doc.resolve(n.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof I&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&pt&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),sn(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>$t(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(il(e))),this.updateAllowDefault(e),this.allowDefault||!n?sn(this.view,"pointer"):rk(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Re&&this.mightDrag&&!this.mightDrag.node.isAtom||xe&&!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)?(Cr(this.view,b.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):sn(this.view,"pointer")}move(e){this.updateAllowDefault(e),sn(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ae.touchstart=t=>{t.input.lastTouch=Date.now(),uc(t),sn(t,"pointer")};Ae.touchmove=t=>{t.input.lastTouch=Date.now(),sn(t,"pointer")};Ae.contextmenu=t=>uc(t);function mm(t,e){return t.composing?!0:Re&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const ak=ct?5e3:-1;Pe.compositionstart=Pe.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))t.markCursor=t.state.storedMarks||n.marks(),Es(t,!0),t.markCursor=null;else if(Es(t),pt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){t.domSelection().collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}gm(t,ak)};Pe.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,gm(t,20))};function gm(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Es(t),e))}function ym(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=uk());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function uk(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function Es(t,e=!1){if(!(ct&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),ym(t),e||t.docView&&t.docView.dirty){let n=oc(t);return n&&!n.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(n)):t.updateState(t.state),!0}return!1}}function ck(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const Vi=Be&&fn<15||Ir&&lS<604;Ae.copy=Pe.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=Vi?null:n.clipboardData,s=r.content(),{dom:l,text:a}=lm(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):ck(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function fk(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function dk(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?$i(t,r.value,null,i,e):$i(t,r.textContent,r.innerHTML,i,e)},50)}function $i(t,e,n,r,i){let o=am(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",a=>a(t,i,o||x.empty)))return!0;if(!o)return!1;let s=fk(o),l=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Sm(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Pe.paste=(t,e)=>{let n=e;if(t.composing&&!ct)return;let r=Vi?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&$i(t,Sm(r),r.getData("text/html"),i,n)?n.preventDefault():dk(t,n)};class km{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const wm=Ge?"altKey":"ctrlKey";Ae.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(il(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof I?i.to-1:i.to))){if(r&&r.mightDrag)s=I.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let c=t.docView.nearestDesc(n.target,!0);c&&c.node.type.spec.draggable&&c!=t.docView&&(s=I.create(t.state.doc,c.posBefore))}}let l=(s||t.state.selection).content(),{dom:a,text:u}=lm(t,l);n.dataTransfer.clearData(),n.dataTransfer.setData(Vi?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Vi||n.dataTransfer.setData("text/plain",u),t.dragging=new km(l,!n[wm],s)};Ae.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Pe.dragover=Pe.dragenter=(t,e)=>e.preventDefault();Pe.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let i=t.posAtCoords(il(n));if(!i)return;let o=t.state.doc.resolve(i.pos),s=r&&r.slice;s?t.someProp("transformPasted",h=>{s=h(s,t)}):s=am(t,Sm(n.dataTransfer),Vi?null:n.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!n[wm]);if(t.someProp("handleDrop",h=>h(t,n,s||x.empty,l))){n.preventDefault();return}if(!s)return;n.preventDefault();let a=s?k1(t.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=t.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&I.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new I(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,k,g,y)=>h=y),u.setSelection(sc(t,p,u.doc.resolve(h)))}t.focus(),t.dispatch(u.setMeta("uiEvent","drop"))};Ae.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&$t(t)},20))};Ae.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Ae.beforeinput=(t,e)=>{if(xe&&ct&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,In(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Pe)Ae[t]=Pe[t];function _i(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Os{constructor(e,n){this.toDOM=e,this.spec=n||Un,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new me(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Os&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&_i(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class dn{constructor(e,n){this.attrs=e,this.spec=n||Un}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new me(o,s,this)}valid(e,n){return n.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,n-l,r,i+l,o)}}map(e,n,r){return this==we||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Un)}mapInner(e,n,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=Cm(n,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+n.content.size;for(let l=0;lo&&a.type instanceof dn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,n,Un));return ur.from(r)}forChild(e,n){if(n.isLeaf)return U.empty;let r=[];for(let i=0;in instanceof U)?e:e.reduce((n,r)=>n.concat(r instanceof U?r:r.members),[]))}}};function hk(t,e,n,r,i,o,s){let l=t.slice();for(let u=0,c=o;u{let k=m-h-(p-d);for(let g=0;gy+c-f)continue;let S=l[g]+c-f;p>=S?l[g+1]=d<=S?-2:-1:d>=c&&k&&(l[g]+=k,l[g+1]+=k)}f+=k}),c=n.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=n.map(t[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),k=r.maybeChild(h);if(k&&m==f&&m+k.nodeSize==p){let g=l[u+2].mapInner(n,k,c+1,t[u]+o+1,s);g!=we?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=pk(l,t,e,n,i,o,s),c=Ds(u,r,0,s);e=c.local;for(let f=0;fn&&s.to{let u=Cm(t,l,a+n);if(u){o=!0;let c=Ds(u,l,n+a+1,r);c!=we&&i.push(a,a+l.nodeSize,c)}});let s=xm(o?Nm(t):t,-n).sort(jn);for(let l=0;l0;)e++;t.splice(e,0,n)}function _l(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=we&&e.push(r)}),t.cursorWrapper&&e.push(U.create(t.state.doc,[t.cursorWrapper.deco])),vm.from(e)}const mk={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},gk=Be&&fn<=11;let yk=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}};class Sk{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new yk,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),gk&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,mk)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let n=0;nthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Zf(this.view)){if(this.suppressingSelectionUpdates)return $t(this.view);if(Be&&fn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&qn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let n=new Set,r;for(let o=e.focusNode;o;o=Bi(o))n.add(o);for(let o=e.anchorNode;o;o=Bi(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Zf(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;c1){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let f=c[0],d=c[1];f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),kk(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||$t(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;ci;k--){let g=r.childNodes[k-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=k;break}if(!y||y.size)break}let f=t.state.doc,d=t.someProp("domParser")||Li.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:xk,context:p});if(u&&u[0].pos!=null){let k=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=k),h={anchor:k+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function xk(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Re&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Re&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Ck=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Nk(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let E=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,P=oc(t,E);if(P&&!t.state.selection.eq(P)){if(xe&&ct&&t.input.lastKeyCode===13&&Date.now()-100Rt(t,In(13,"Enter"))))return;let ne=t.state.tr.setSelection(P);E=="pointer"?ne.setMeta("pointer",!0):E=="key"&&ne.scrollIntoView(),o&&ne.setMeta("composition",o),t.dispatch(ne)}return}let s=t.state.doc.resolve(e),l=s.sharedDepth(n);e=s.before(l+1),n=t.state.doc.resolve(n).after(l+1);let a=t.state.selection,u=vk(t,e,n),c=t.state.doc,f=c.slice(u.from,u.to),d,p;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ct)&&i.some(E=>E.nodeType==1&&!Ck.test(E.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",E=>E(t,In(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof B&&!a.empty&&a.$head.sameParent(a.$anchor)&&!t.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let E=cd(t,t.state.doc,u.sel);if(E&&!E.eq(t.state.selection)){let P=t.state.tr.setSelection(E);o&&P.setMeta("composition",o),t.dispatch(P)}}return}if(xe&&t.cursorWrapper&&u.sel&&u.sel.anchor==t.cursorWrapper.deco.from&&u.sel.head==u.sel.anchor){let E=h.endB-h.start;u.sel={anchor:u.sel.anchor+E,head:u.sel.anchor+E}}t.input.domChangeCount++,t.state.selection.fromt.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=u.from?h.start=t.state.selection.from:h.endA=t.state.selection.to-2&&t.state.selection.to<=u.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),Be&&fn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),k=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(k)&&m.parent.inlineContent&&g.end()>=h.endA,S;if((Ir&&t.input.lastIOSEnter>Date.now()-225&&(!y||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!y&&m.posE(t,In(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&Ek(c,h.start,h.endA,m,k)&&t.someProp("handleKeyDown",E=>E(t,In(8,"Backspace")))){ct&&xe&&t.domObserver.suppressSelectionUpdates();return}xe&&ct&&h.endB==h.start&&(t.input.lastAndroidDelete=Date.now()),ct&&!y&&m.start()!=k.start()&&k.parentOffset==0&&m.depth==k.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,k=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{t.someProp("handleKeyDown",function(E){return E(t,In(13,"Enter"))})},20));let w=h.start,M=h.endA,O,D,R;if(y){if(m.pos==k.pos)Be&&fn<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>$t(t),20)),O=t.state.tr.delete(w,M),D=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(R=Mk(m.parent.content.cut(m.parentOffset,k.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))O=t.state.tr,R.type=="add"?O.addMark(w,M,R.mark):O.removeMark(w,M,R.mark);else if(m.parent.child(m.index()).isText&&m.index()==k.index()-(k.textOffset?0:1)){let E=m.parent.textBetween(m.parentOffset,k.parentOffset);if(t.someProp("handleTextInput",P=>P(t,w,M,E)))return;O=t.state.tr.insertText(E,w,M)}}if(O||(O=t.state.tr.replace(w,M,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let E=cd(t,O.doc,u.sel);E&&!(xe&&ct&&t.composing&&E.empty&&(h.start!=h.endB||t.input.lastAndroidDeletee.content.size?null:sc(t,e.resolve(n.anchor),e.resolve(n.head))}function Mk(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;cn||Wl(s,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Ok(t,e,n,r,i){let o=t.findDiffStart(e,n);if(o==null)return null;let{a:s,b:l}=t.findDiffEnd(e,n+t.size,n+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&n>=55296&&n<=56319}class Dk{constructor(e,n){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new QS,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(gd),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=pd(this),hd(this),this.nodeViews=md(this),this.docView=Kf(this.state.doc,dd(this),_l(this),this.dom,this),this.domObserver=new Sk(this,(r,i,o,s)=>Nk(this,r,i,o,s)),this.domObserver.start(),YS(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Fa(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(gd),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(ym(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(l||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=md(this);Rk(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&Fa(this),this.editable=pd(this),hd(this);let a=_l(this),u=dd(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&cS(this);if(s){this.domObserver.stop();let p=f&&(Be||xe)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Tk(i.selection,e.selection);if(f){let h=xe?this.trackWrites=this.domSelectionRange().focusNode:null;(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Kf(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&bS(this))?$t(this,p):(im(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&fS(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof I){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&_f(this,n.getBoundingClientRect(),e)}else _f(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let n=0;n0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new km(e.slice,e.move,i<0?void 0:I.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let s=0;sn.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return yS(this,e)}coordsAtPos(e,n=1){return Kp(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return xS(this,n||this.state,e)}pasteHTML(e,n){return $i(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return $i(this,e,null,!0,n||new ClipboardEvent("paste"))}destroy(){this.docView&&(GS(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],_l(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ZS(this,e)}dispatch(e){let n=this._props.dispatchTransaction;n?n.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return Re&&this.root.nodeType===11&&rS(this.dom.ownerDocument)==this.dom?wk(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function dd(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[me.node(0,t.state.doc.content.size,e)]}function hd(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:me.widget(t.state.selection.head,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function pd(t){return!t.someProp("editable",e=>e(t.state)===!1)}function Tk(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function md(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function Rk(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function gd(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}class Z extends b{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return Z.valid(r)?new Z(r):b.near(r)}content(){return x.empty}eq(e){return e instanceof Z&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new Z(e.resolve(n.pos))}getBookmark(){return new dc(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!Ak(e)||!Pk(e))return!1;let r=n.type.spec.allowGapCursor;if(r!=null)return r;let i=n.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,n,r=!1){e:for(;;){if(!r&&Z.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(n>0?e.indexAfter(s)0){o=l.child(n>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=n;let a=e.doc.resolve(i);if(Z.valid(a))return a}for(;;){let s=n>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!I.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*n),r=!1;continue e}break}o=s,i+=n;let l=e.doc.resolve(i);if(Z.valid(l))return l}return null}}}Z.prototype.visible=!1;Z.findFrom=Z.findGapCursorFrom;b.jsonID("gapcursor",Z);class dc{constructor(e){this.pos=e}map(e){return new dc(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Z.valid(n)?new Z(n):b.near(n)}}function Ak(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),r=t.node(e);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Pk(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),r=t.node(e);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function zk(){return new Tt({props:{decorations:Lk,createSelectionBetween(t,e,n){return e.pos==n.pos&&Z.valid(n)?new Z(n):null},handleClick:bk,handleKeyDown:Ik,handleDOMEvents:{beforeinput:Fk}}})}const Ik=_p({ArrowLeft:To("horiz",-1),ArrowRight:To("horiz",1),ArrowUp:To("vert",-1),ArrowDown:To("vert",1)});function To(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof B){if(!o.endOfTextblock(n)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=Z.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new Z(u))),!0):!1}}function bk(t,e,n){if(!t||!t.editable)return!1;let r=t.state.doc.resolve(e);if(!Z.valid(r))return!1;let i=t.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&I.isSelectable(t.state.doc.nodeAt(i.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Z(r))),!0)}function Fk(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof Z))return!1;let{$from:n}=t.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!r)return!1;let i=v.empty;for(let s=r.length-1;s>=0;s--)i=v.from(r[s].createAndFill(null,i));let o=t.state.tr.replace(n.pos,n.pos,new x(i,0,0));return o.setSelection(B.near(o.doc.resolve(n.pos+1))),t.dispatch(o),!1}function Lk(t){if(!(t.selection instanceof Z))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",U.create(t.doc,[me.widget(t.selection.head,e,{key:"gapcursor"})])}class er{constructor(e,n,r={}){this.match=e,this.match=e,this.handler=typeof n=="string"?Bk(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function Bk(t){return function(e,n,r,i){let o=t;if(n[1]){let s=n[0].lastIndexOf(n[1]);o+=n[0].slice(s+n[1].length),r+=s;let l=r-i;l>0&&(o=n[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const Vk=500;function $k({rules:t}){let e=new Tt({state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return yd(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&yd(n,r.pos,r.pos,"",t,e)})}}},isInputRules:!0});return e}function yd(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-Vk),l.parentOffset,null,"")+r;for(let u=0;u{let a=n instanceof Function?n(o):n,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&a1(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Xu(u.doc,s-1)&&(!r||r(o,p))&&u.join(s-1),u})}const Wk=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Uk(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let l=0;l127)&&(o=Ut[r.keyCode])&&o!=i){let l=e[Ul(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Mm=65535,Em=Math.pow(2,16);function Kk(t,e){return t+e*Em}function Sd(t){return t&Mm}function qk(t){return(t-(t&Mm))/Em}const Om=1,Dm=2,is=4,Tm=8;class La{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Tm)>0}get deletedBefore(){return(this.delInfo&(Om|is))>0}get deletedAfter(){return(this.delInfo&(Dm|is))>0}get deletedAcross(){return(this.delInfo&is)>0}}class je{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&je.empty)return je.empty}recover(e){let n=0,r=Sd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:n:n,p=a+i+(d<0?0:c);if(r)return p;let h=e==(n<0?a:f)?null:Kk(l/3,e-a),m=e==a?Dm:e==f?Om:is;return(n<0?e!=a:e!=f)&&(m|=Tm),new La(p,m,h)}i+=c-u}return r?e+i:new La(e+i,0,null)}touches(e,n){let r=0,i=Sd(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new Ci;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new wt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ln(n.pos,r.pos,this.mark)}merge(e){return e instanceof ln&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ln(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new ln(n.from,n.to,e.markFromJSON(n.mark))}}Me.jsonID("addMark",ln);class wt extends Me{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new x(hc(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new ln(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new wt(n.pos,r.pos,this.mark)}merge(e){return e instanceof wt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new wt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new wt(n.from,n.to,e.markFromJSON(n.mark))}}Me.jsonID("removeMark",wt);class an extends Me{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return oe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return oe.fromReplace(e,this.pos,this.pos+1,new x(v.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new xt(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new xt(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}}Me.jsonID("replaceAround",xt);function Ba(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Qk(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(a)),o.forEach(a=>t.step(a))}function Yk(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof co){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new wt(s.from,s.to,s.style)))}function Gk(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function Xk(t,e,n){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=v.empty,f=0;for(let h=o,m=!1;h>n;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new xt(i,o,i,o,new x(r,0,0),n.length,!0))}function ew(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&tw(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new xt(u,c,u+1,c-1,new x(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function tw(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function nw(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new xt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new x(v.from(s),0,0),1,!0))}function rw(t,e,n=1,r){let i=t.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new De(e,e,new x(o.append(s),n,n),!0))}function iw(t,e,n){let r=new De(e-n,e+n,x.empty,!0);t.step(r)}function ow(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new x(o,s,l);return e>-1?new xt(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new De(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Hl(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(n==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Hl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Hl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new x(hi(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new x(hi(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=k,c.push(Am(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=pi(this.placed,n,v.from(c)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,k=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Jl(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=pi(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=pi(this.placed,this.depth,v.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(v.empty,!0);n.childCount&&(this.placed=pi(this.placed,this.frontier.length,n))}}function hi(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(hi(t.firstChild.content,e-1,n)))}function pi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(pi(t.lastChild.content,e-1,n)))}function Hl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Am(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),t.copy(r)}function Jl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!aw(n,o.content,s)?l:null}function aw(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=uw(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function Pm(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return t}function fw(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=ow(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new x(v.from(r),0,0))}function dw(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=zm(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function zm(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}class Nr extends Me{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return oe.fromReplace(e,this.pos,this.pos+1,new x(v.from(i),0,n.isLeaf?0:1))}getMap(){return je.empty}invert(e){return new Nr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Nr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Nr(n.pos,n.attr,n.value)}}Me.jsonID("attr",Nr);class Wi extends Me{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return oe.ok(r)}getMap(){return je.empty}invert(e){return new Wi(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Wi(n.attr,n.value)}}Me.jsonID("docAttr",Wi);let Fr=class extends Error{};Fr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Fr.prototype=Object.create(Error.prototype);Fr.prototype.constructor=Fr;Fr.prototype.name="TransformError";class hw{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Ci}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Fr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=x.empty){let i=sw(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new x(v.from(r),0,0))}delete(e,n){return this.replace(e,n,x.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return cw(this,e,n,r),this}replaceRangeWith(e,n,r){return fw(this,e,n,r),this}deleteRange(e,n){return dw(this,e,n),this}lift(e,n){return Xk(this,e,n),this}join(e,n=1){return iw(this,e,n),this}wrap(e,n){return Zk(this,e,n),this}setBlockType(e,n=e,r,i=null){return ew(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return nw(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Nr(e,n,r)),this}setDocAttribute(e,n){return this.step(new Wi(e,n)),this}addNodeMark(e,n){return this.step(new an(e,n)),this}removeNodeMark(e,n){if(!(n instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new br(e,n)),this}split(e,n=1,r){return rw(this,e,n,r),this}addMark(e,n,r){return Qk(this,e,n,r),this}removeMark(e,n,r){return Yk(this,e,n,r),this}clearIncompatible(e,n,r){return Gk(this,e,n,r),this}}var Va,$a;if(typeof WeakMap<"u"){let t=new WeakMap;Va=e=>t.get(e),$a=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;Va=r=>{for(let i=0;i(n==10&&(n=0),t[n++]=r,t[n++]=i)}var re=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e=n){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-S});break}const w=i+S*e;for(let M=0;Mr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function gw(t,e,n){t.problems||(t.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(t);a!=null&&(o[s]=a)}return o}function wd(t,e){const n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function Sw(t){const e=t.cellAttributes||{},n={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)n[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>kd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>kd(r,e)}],toDOM(r){return["th",wd(r,e),0]}}}}function Ot(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const n in t.nodes){const r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var tn=new ho("selectingCells");function go(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function pc(t){const e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function Im(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const n=go(e.$head)||kw(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function kw(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function _a(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function mc(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function bm(t,e,n){const r=t.node(-1),i=re.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function Lr(t,e,n=1){const r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var ce=class Pt extends b{constructor(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=n.pos-o);a.unshift(n.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new Ap(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=n}map(e,n){const r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(_a(r)&&_a(i)&&mc(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Pt.rowSelection(r,i):o&&this.isColSelection()?Pt.colSelection(r,i):new Pt(r,i)}return B.between(r,i)}content(){const e=this.$anchorCell.node(-1),n=re.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||k>0){let g=h.attrs;if(m>0&&(g=Lr(g,0,m)),k>0&&(g=Lr(g,g.colspan-k,k)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(n.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(n=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==n.width}eq(e){return e instanceof Pt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(n.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(n=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(me.node(r,r+n.nodeSize,{class:"selectedCell"}))}),U.create(t.doc,e)}function xw({$from:t,$to:e}){if(t.pos==e.pos||t.pos=0&&!(t.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function Cw({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){const o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function Nw(t,e,n){const r=(e||t).selection,i=(e||t).doc;let o,s;if(r instanceof I&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=ce.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=ce.rowSelection(l,l)}else if(!n){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=ce.create(i,a+1,u)}}else r instanceof B&&xw(r)?o=B.create(i,r.from):r instanceof B&&Cw(r)&&(o=B.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var Mw=new ho("fix-tables");function Lm(t,e,n,r){const i=t.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(n=Ow(t,i,o,n))};return e?e.doc!=t.doc&&Lm(e.doc,t.doc,0,r):t.doc.descendants(r),n}function Ow(t,e,n,r){const i=re.get(e);if(!i.problems)return r;r||(r=t.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let k=0;k0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(v.empty),n[i]r&&(d=d.type.createChecked(Lr(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(v.from(a))}n=o,e=i}return{width:t,height:e,rows:n}}function Aw(t,e,n,r,i,o,s){const l=t.doc.type.schema,a=Ot(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:n.nodeAt(e.map[m+h]).type==a.header_cell;f.push(k?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,v.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=n.selection;if(o instanceof ce)return ss(n,r,b.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;const s=Bm(i,t,e);if(s==null)return!1;if(t=="horiz")return ss(n,r,b.near(n.doc.resolve(o.head+e),e));{const l=n.doc.resolve(s),a=bm(l,t,e);let u;return a?u=b.near(a,1):e<0?u=b.near(n.doc.resolve(l.before(-1)),-1):u=b.near(n.doc.resolve(l.after(-1)),1),ss(n,r,u)}}}function Ao(t,e){return(n,r,i)=>{if(!i)return!1;const o=n.selection;let s;if(o instanceof ce)s=o;else{const a=Bm(i,t,e);if(a==null)return!1;s=new ce(n.doc.resolve(a))}const l=bm(s.$headCell,t,e);return l?ss(n,r,new ce(s.$anchorCell,l)):!1}}function Po(t,e){const n=t.selection;if(!(n instanceof ce))return!1;if(e){const r=t.tr,i=Ot(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new x(i,0,0))}),r.docChanged&&e(r)}return!0}function zw(t,e){const n=t.state.doc,r=go(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new ce(r))),!0):!1}function Iw(t,e,n){if(!pc(t.state))return!1;let r=Dw(n);const i=t.state.selection;if(i instanceof ce){r||(r={width:1,height:1,rows:[v.from(Wa(Ot(t.state.schema).cell,n))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Rw(r,l.right-l.left,l.bottom-l.top),Cd(t.state,t.dispatch,s,l,r),!0}else if(r){const o=Im(t.state),s=o.start(-1);return Cd(t.state,t.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function bw(t,e){var n;if(e.ctrlKey||e.metaKey)return;const r=Nd(t,e.target);let i;if(e.shiftKey&&t.state.selection instanceof ce)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=go(t.state.selection.$anchor))!=null&&((n=Kl(t,e))==null?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Kl(t,u);const f=tn.getState(t.state)==null;if(!c||!mc(a,c))if(f)c=a;else return;const d=new ce(a,c);if(f||!t.state.selection.eq(d)){const p=t.state.tr.setSelection(d);f&&p.setMeta(tn,a.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",l),tn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(tn,-1))}function l(a){const u=a,c=tn.getState(t.state);let f;if(c!=null)f=t.state.doc.resolve(c);else if(Nd(t,u.target)!=r&&(f=Kl(t,e),!f))return s();f&&o(f,u)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",l)}function Bm(t,e,n){if(!(t.state.selection instanceof B))return null;const{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?l:null}}return null}function Nd(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Kl(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});return n&&n?go(t.state.doc.resolve(n.pos)):null}var Fw=class{constructor(t,e){this.node=t,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Ua(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Ua(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Ua(t,e,n,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=t.firstChild;if(c){for(let f=0,d=0;fnew n(l,e,a),new Bw(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=et.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{Vw(o,s,t,e,r)},mouseleave:o=>{$w(o)},mousedown:(o,s)=>{_w(o,s,e)}},decorations:o=>{const s=et.getState(o);if(s&&s.activeHandle>-1)return Kw(o,s.activeHandle)},nodeViews:{}}});return i}var Bw=class ls{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){const n=this,r=e.getMeta(et);if(r&&r.setHandle!=null)return new ls(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ls(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return _a(e.doc.resolve(i))||(i=-1),new ls(i,n.dragging)}return n}};function Vw(t,e,n,r,i){const o=et.getState(t.state);if(o&&!o.dragging){const s=Uw(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=n?l=Md(t,e,"left",n):u-e.clientX<=n&&(l=Md(t,e,"right",n))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=t.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Vm(t,l)}}}function $w(t){const e=et.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Vm(t,-1)}function _w(t,e,n){var r;const i=(r=t.dom.ownerDocument.defaultView)!=null?r:window,o=et.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=t.state.doc.nodeAt(o.activeHandle),l=Ww(t,o.activeHandle,s.attrs);t.dispatch(t.state.tr.setMeta(et,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=et.getState(t.state);f!=null&&f.dragging&&(jw(t,f.activeHandle,Ed(f.dragging,c,n)),t.dispatch(t.state.tr.setMeta(et,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=et.getState(t.state);if(f&&f.dragging){const d=Ed(f.dragging,c,n);Hw(t,f.activeHandle,d,n)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function Ww(t,e,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=t.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}gc("row",{useDeprecatedLogic:!0});gc("column",{useDeprecatedLogic:!0});gc("cell",{useDeprecatedLogic:!0});function Qw({allowTableNodeSelection:t=!1}={}){return new Tt({key:tn,state:{init(){return null},apply(e,n){const r=e.getMeta(tn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;const{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:vw,handleDOMEvents:{mousedown:bw},createSelectionBetween(e){return tn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:zw,handleKeyDown:Pw,handlePaste:Iw},appendTransaction(e,n,r){return Nw(r,Ew(r,n),t)}})}var _m={exports:{}},Qe={},Wm={exports:{}},Um={};/** +`);return{dom:a,text:d}}function lm(t,e,n,r,i){let o=i.parent.type.spec.code,s,l;if(!n&&!e)return null;let a=e&&(r||o||!n);if(a){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return e?new x(v.from(t.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):x.empty;let f=t.someProp("clipboardTextParser",d=>d(e,i,r,t));if(f)l=f;else{let d=i.marks(),{schema:p}=t.state,h=Lt.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let S=s.appendChild(document.createElement("p"));m&&S.appendChild(h.serializeNode(p.text(m,d)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),s=Jk(n),po&&Kk(s);let u=s&&s.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let f=+c[3];f>0;f--){let d=s.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;s=d}if(l||(l=(t.someProp("clipboardParser")||t.someProp("domParser")||Li.fromSchema(t.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!jk.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=qk(od(l,+c[1],+c[2]),c[4]);else if(l=x.maxOpen(Hk(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f{l=f(l,t)}),l}const jk=/^(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 Hk(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),o,s=[];if(t.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),u;if(!a)return s=null;if(u=s.length&&o.length&&um(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=cm(s[s.length-1],o.length));let c=am(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return v.from(s)}return t}function am(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,v.from(t));return t}function um(t,e,n,r,i){if(i1&&(o=0),i=n&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(v.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(l))}function od(t,e,n){return e]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=dm().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&fm[r[1].toLowerCase()])&&(t=i.map(o=>"<"+o+">").join("")+t+i.map(o=>"").reverse().join("")),n.innerHTML=t,i)for(let o=0;o=0;l-=2){let a=n.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=v.from(a.create(r[l+1],i)),o++,s++}return new x(i,o,s)}const Ae={},Pe={},Qk={touchstart:!0,touchmove:!0};class Yk{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Gk(t){for(let e in Ae){let n=Ae[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{Zk(t,r)&&!lc(t,r)&&(t.editable||!(r.type in Pe))&&n(t,r)},Qk[e]?{passive:!0}:void 0)}Re&&t.dom.addEventListener("input",()=>null),Fa(t)}function sn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Xk(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Fa(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>lc(t,r))})}function lc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function Zk(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function eS(t,e){!lc(t,e)&&Ae[e.type]&&(t.editable||!(e.type in Pe))&&Ae[e.type](t,e)}Pe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!pm(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(ct&&xe&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),br&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,bn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||Uk(t,n)?n.preventDefault():sn(t,"key")};Pe.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Pe.keypress=(t,e)=>{let n=e;if(pm(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||Ge&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof B)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode);!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",o=>o(t,r.$from.pos,r.$to.pos,i))&&t.dispatch(t.state.tr.insertText(i).scrollIntoView()),n.preventDefault()}};function il(t){return{left:t.clientX,top:t.clientY}}function tS(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function ac(t,e,n,r,i){if(r==-1)return!1;let o=t.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(t.someProp(e,l=>s>o.depth?l(t,n,o.nodeAfter,o.before(s),i,!0):l(t,n,o.node(s),o.before(s),i,!1)))return!0;return!1}function Cr(t,e,n){t.focused||t.focus();let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function nS(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&b.isSelectable(r)?(Cr(t,new b(n),"pointer"),!0):!1}function rS(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof b&&(r=n.node);let o=t.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(b.isSelectable(l)){r&&n.$from.depth>0&&s>=n.$from.depth&&o.before(n.$from.depth+1)==n.$from.pos?i=o.before(n.$from.depth):i=o.before(s);break}}return i!=null?(Cr(t,b.create(t.state.doc,i),"pointer"),!0):!1}function iS(t,e,n,r,i){return ac(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?rS(t,n):nS(t,n))}function oS(t,e,n,r){return ac(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function sS(t,e,n,r){return ac(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||lS(t,n,r)}function lS(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(Cr(t,B.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Cr(t,B.create(r,l+1,l+1+s.content.size),"pointer");else if(b.isSelectable(s))Cr(t,b.create(r,l),"pointer");else continue;return!0}}function uc(t){return Es(t)}const hm=Ge?"metaKey":"ctrlKey";Ae.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=uc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&tS(n,t.input.lastClick)&&!n[hm]&&(t.input.lastClick.type=="singleClick"?o="doubleClick":t.input.lastClick.type=="doubleClick"&&(o="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o};let s=t.posAtCoords(il(n));s&&(o=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new aS(t,s,n,!!r)):(o=="doubleClick"?oS:sS)(t,s.pos,s.inside,n)?n.preventDefault():sn(t,"pointer"))};class aS{constructor(e,n,r,i){this.view=e,this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[hm],this.allowDefault=r.shiftKey;let o,s;if(n.inside>-1)o=e.state.doc.nodeAt(n.inside),s=n.inside;else{let c=e.state.doc.resolve(n.pos);o=c.parent,s=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a?a.dom:null;let{selection:u}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||u instanceof b&&u.from<=s&&u.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&pt&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),sn(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>$t(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(il(e))),this.updateAllowDefault(e),this.allowDefault||!n?sn(this.view,"pointer"):iS(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Re&&this.mightDrag&&!this.mightDrag.node.isAtom||xe&&!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)?(Cr(this.view,I.near(this.view.state.doc.resolve(n.pos)),"pointer"),e.preventDefault()):sn(this.view,"pointer")}move(e){this.updateAllowDefault(e),sn(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ae.touchstart=t=>{t.input.lastTouch=Date.now(),uc(t),sn(t,"pointer")};Ae.touchmove=t=>{t.input.lastTouch=Date.now(),sn(t,"pointer")};Ae.contextmenu=t=>uc(t);function pm(t,e){return t.composing?!0:Re&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const uS=ct?5e3:-1;Pe.compositionstart=Pe.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))t.markCursor=t.state.storedMarks||n.marks(),Es(t,!0),t.markCursor=null;else if(Es(t),pt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){t.domSelection().collapse(s,s.nodeValue.length);break}else i=s,o=-1}}t.input.composing=!0}mm(t,uS)};Pe.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,mm(t,20))};function mm(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Es(t),e))}function gm(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=cS());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function cS(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function Es(t,e=!1){if(!(ct&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),gm(t),e||t.docView&&t.docView.dirty){let n=oc(t);return n&&!n.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(n)):t.updateState(t.state),!0}return!1}}function fS(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const Vi=Be&&fn<15||br&&ak<604;Ae.copy=Pe.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=Vi?null:n.clipboardData,s=r.content(),{dom:l,text:a}=sm(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):fS(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dS(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function hS(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?$i(t,r.value,null,i,e):$i(t,r.textContent,r.innerHTML,i,e)},50)}function $i(t,e,n,r,i){let o=lm(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",a=>a(t,i,o||x.empty)))return!0;if(!o)return!1;let s=dS(o),l=s?t.state.tr.replaceSelectionWith(s,r):t.state.tr.replaceSelection(o);return t.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ym(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Pe.paste=(t,e)=>{let n=e;if(t.composing&&!ct)return;let r=Vi?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&$i(t,ym(r),r.getData("text/html"),i,n)?n.preventDefault():hS(t,n)};class km{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const Sm=Ge?"altKey":"ctrlKey";Ae.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,o=i.empty?null:t.posAtCoords(il(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof b?i.to-1:i.to))){if(r&&r.mightDrag)s=b.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let c=t.docView.nearestDesc(n.target,!0);c&&c.node.type.spec.draggable&&c!=t.docView&&(s=b.create(t.state.doc,c.posBefore))}}let l=(s||t.state.selection).content(),{dom:a,text:u}=sm(t,l);n.dataTransfer.clearData(),n.dataTransfer.setData(Vi?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Vi||n.dataTransfer.setData("text/plain",u),t.dragging=new km(l,!n[Sm],s)};Ae.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Pe.dragover=Pe.dragenter=(t,e)=>e.preventDefault();Pe.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let i=t.posAtCoords(il(n));if(!i)return;let o=t.state.doc.resolve(i.pos),s=r&&r.slice;s?t.someProp("transformPasted",h=>{s=h(s,t)}):s=lm(t,ym(n.dataTransfer),Vi?null:n.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!n[Sm]);if(t.someProp("handleDrop",h=>h(t,n,s||x.empty,l))){n.preventDefault();return}if(!s)return;n.preventDefault();let a=s?w1(t.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let u=t.state.tr;if(l){let{node:h}=r;h?h.replace(u):u.deleteSelection()}let c=u.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=u.doc;if(f?u.replaceRangeWith(c,c,s.content.firstChild):u.replaceRange(c,c,s),u.doc.eq(d))return;let p=u.doc.resolve(c);if(f&&b.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new b(p));else{let h=u.mapping.map(a);u.mapping.maps[u.mapping.maps.length-1].forEach((m,S,g,y)=>h=y),u.setSelection(sc(t,p,u.doc.resolve(h)))}t.focus(),t.dispatch(u.setMeta("uiEvent","drop"))};Ae.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&$t(t)},20))};Ae.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Ae.beforeinput=(t,e)=>{if(xe&&ct&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",o=>o(t,bn(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Pe)Ae[t]=Pe[t];function _i(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Os{constructor(e,n){this.toDOM=e,this.spec=n||Un,this.side=this.spec.side||0}map(e,n,r,i){let{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new me(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Os&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&_i(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class dn{constructor(e,n){this.attrs=e,this.spec=n||Un}map(e,n,r,i){let o=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new me(o,s,this)}valid(e,n){return n.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,n-l,r,i+l,o)}}map(e,n,r){return this==we||e.maps.length==0?this:this.mapInner(e,n,0,0,r||Un)}mapInner(e,n,r,i,o){let s;for(let l=0;l{let u=a+r,c;if(c=xm(n,l,u)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+n.content.size;for(let l=0;lo&&a.type instanceof dn){let u=Math.max(o,a.from)-o,c=Math.min(s,a.to)-o;ui.map(e,n,Un));return ur.from(r)}forChild(e,n){if(n.isLeaf)return U.empty;let r=[];for(let i=0;in instanceof U)?e:e.reduce((n,r)=>n.concat(r instanceof U?r:r.members),[]))}}};function pS(t,e,n,r,i,o,s){let l=t.slice();for(let u=0,c=o;u{let S=m-h-(p-d);for(let g=0;gy+c-f)continue;let k=l[g]+c-f;p>=k?l[g+1]=d<=k?-2:-1:d>=c&&S&&(l[g]+=S,l[g+1]+=S)}f+=S}),c=n.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let d=n.map(t[u+1]+o,-1),p=d-i,{index:h,offset:m}=r.content.findIndex(f),S=r.maybeChild(h);if(S&&m==f&&m+S.nodeSize==p){let g=l[u+2].mapInner(n,S,c+1,t[u]+o+1,s);g!=we?(l[u]=f,l[u+1]=p,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=mS(l,t,e,n,i,o,s),c=Ds(u,r,0,s);e=c.local;for(let f=0;fn&&s.to{let u=xm(t,l,a+n);if(u){o=!0;let c=Ds(u,l,n+a+1,r);c!=we&&i.push(a,a+l.nodeSize,c)}});let s=vm(o?Cm(t):t,-n).sort(jn);for(let l=0;l0;)e++;t.splice(e,0,n)}function _l(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=we&&e.push(r)}),t.cursorWrapper&&e.push(U.create(t.state.doc,[t.cursorWrapper.deco])),wm.from(e)}const gS={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yS=Be&&fn<=11;let kS=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}};class SS{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new kS,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),yS&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,gS)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let n=0;nthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Zf(this.view)){if(this.suppressingSelectionUpdates)return $t(this.view);if(Be&&fn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&qn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let n=new Set,r;for(let o=e.focusNode;o;o=Bi(o))n.add(o);for(let o=e.anchorNode;o;o=Bi(o))if(n.has(o)){r=o;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Zf(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let c=0;c1){let c=a.filter(f=>f.nodeName=="BR");if(c.length==2){let f=c[0],d=c[1];f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}}let u=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),wS(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||$t(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;ci;S--){let g=r.childNodes[S-1],y=g.pmViewDesc;if(g.nodeName=="BR"&&!y){o=S;break}if(!y||y.size)break}let f=t.state.doc,d=t.someProp("domParser")||Li.fromSchema(t.state.schema),p=f.resolve(s),h=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:CS,context:p});if(u&&u[0].pos!=null){let S=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=S),h={anchor:S+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function CS(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Re&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Re&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const NS=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function MS(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let E=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,P=oc(t,E);if(P&&!t.state.selection.eq(P)){if(xe&&ct&&t.input.lastKeyCode===13&&Date.now()-100Rt(t,bn(13,"Enter"))))return;let ne=t.state.tr.setSelection(P);E=="pointer"?ne.setMeta("pointer",!0):E=="key"&&ne.scrollIntoView(),o&&ne.setMeta("composition",o),t.dispatch(ne)}return}let s=t.state.doc.resolve(e),l=s.sharedDepth(n);e=s.before(l+1),n=t.state.doc.resolve(n).after(l+1);let a=t.state.selection,u=xS(t,e,n),c=t.state.doc,f=c.slice(u.from,u.to),d,p;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ct)&&i.some(E=>E.nodeType==1&&!NS.test(E.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",E=>E(t,bn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&a instanceof B&&!a.empty&&a.$head.sameParent(a.$anchor)&&!t.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let E=cd(t,t.state.doc,u.sel);if(E&&!E.eq(t.state.selection)){let P=t.state.tr.setSelection(E);o&&P.setMeta("composition",o),t.dispatch(P)}}return}if(xe&&t.cursorWrapper&&u.sel&&u.sel.anchor==t.cursorWrapper.deco.from&&u.sel.head==u.sel.anchor){let E=h.endB-h.start;u.sel={anchor:u.sel.anchor+E,head:u.sel.anchor+E}}t.input.domChangeCount++,t.state.selection.fromt.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=u.from?h.start=t.state.selection.from:h.endA=t.state.selection.to-2&&t.state.selection.to<=u.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),Be&&fn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>u.from&&u.doc.textBetween(h.start-u.from-1,h.start-u.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=u.doc.resolveNoCache(h.start-u.from),S=u.doc.resolveNoCache(h.endB-u.from),g=c.resolve(h.start),y=m.sameParent(S)&&m.parent.inlineContent&&g.end()>=h.endA,k;if((br&&t.input.lastIOSEnter>Date.now()-225&&(!y||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!y&&m.posE(t,bn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&OS(c,h.start,h.endA,m,S)&&t.someProp("handleKeyDown",E=>E(t,bn(8,"Backspace")))){ct&&xe&&t.domObserver.suppressSelectionUpdates();return}xe&&ct&&h.endB==h.start&&(t.input.lastAndroidDelete=Date.now()),ct&&!y&&m.start()!=S.start()&&S.parentOffset==0&&m.depth==S.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==h.endA&&(h.endB-=2,S=u.doc.resolveNoCache(h.endB-u.from),setTimeout(()=>{t.someProp("handleKeyDown",function(E){return E(t,bn(13,"Enter"))})},20));let w=h.start,M=h.endA,O,D,R;if(y){if(m.pos==S.pos)Be&&fn<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>$t(t),20)),O=t.state.tr.delete(w,M),D=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(R=ES(m.parent.content.cut(m.parentOffset,S.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))O=t.state.tr,R.type=="add"?O.addMark(w,M,R.mark):O.removeMark(w,M,R.mark);else if(m.parent.child(m.index()).isText&&m.index()==S.index()-(S.textOffset?0:1)){let E=m.parent.textBetween(m.parentOffset,S.parentOffset);if(t.someProp("handleTextInput",P=>P(t,w,M,E)))return;O=t.state.tr.insertText(E,w,M)}}if(O||(O=t.state.tr.replace(w,M,u.doc.slice(h.start-u.from,h.endB-u.from))),u.sel){let E=cd(t,O.doc,u.sel);E&&!(xe&&ct&&t.composing&&E.empty&&(h.start!=h.endB||t.input.lastAndroidDeletee.content.size?null:sc(t,e.resolve(n.anchor),e.resolve(n.head))}function ES(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;cn||Wl(s,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let o=t.node(r).maybeChild(t.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function DS(t,e,n,r,i){let o=t.findDiffStart(e,n);if(o==null)return null;let{a:s,b:l}=t.findDiffEnd(e,n+t.size,n+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&n>=55296&&n<=56319}class TS{constructor(e,n){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Yk,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(gd),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=pd(this),hd(this),this.nodeViews=md(this),this.docView=Kf(this.state.doc,dd(this),_l(this),this.dom,this),this.domObserver=new SS(this,(r,i,o,s)=>MS(this,r,i,o,s)),this.domObserver.start(),Gk(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Fa(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(gd),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(gm(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(l||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let p=md(this);AS(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&Fa(this),this.editable=pd(this),hd(this);let a=_l(this),u=dd(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,u,a);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&fk(this);if(s){this.domObserver.stop();let p=f&&(Be||xe)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&RS(i.selection,e.selection);if(f){let h=xe?this.trackWrites=this.domSelectionRange().focusNode:null;(o||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Kf(e.doc,u,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Fk(this))?$t(this,p):(rm(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():d&&dk(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof b){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&_f(this,n.getBoundingClientRect(),e)}else _f(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let n=0;n0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new km(e.slice,e.move,i<0?void 0:b.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let s=0;sn.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return kk(this,e)}coordsAtPos(e,n=1){return Jp(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return Ck(this,n||this.state,e)}pasteHTML(e,n){return $i(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return $i(this,e,null,!0,n||new ClipboardEvent("paste"))}destroy(){this.docView&&(Xk(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],_l(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return this.docView==null}dispatchEvent(e){return eS(this,e)}dispatch(e){let n=this._props.dispatchTransaction;n?n.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return Re&&this.root.nodeType===11&&ik(this.dom.ownerDocument)==this.dom?vS(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function dd(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[me.node(0,t.state.doc.content.size,e)]}function hd(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:me.widget(t.state.selection.head,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function pd(t){return!t.someProp("editable",e=>e(t.state)===!1)}function RS(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function md(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function AS(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function gd(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}class Z extends I{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return Z.valid(r)?new Z(r):I.near(r)}content(){return x.empty}eq(e){return e instanceof Z&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new Z(e.resolve(n.pos))}getBookmark(){return new dc(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!PS(e)||!zS(e))return!1;let r=n.type.spec.allowGapCursor;if(r!=null)return r;let i=n.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,n,r=!1){e:for(;;){if(!r&&Z.valid(e))return e;let i=e.pos,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(n>0?e.indexAfter(s)0){o=l.child(n>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=n;let a=e.doc.resolve(i);if(Z.valid(a))return a}for(;;){let s=n>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!b.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*n),r=!1;continue e}break}o=s,i+=n;let l=e.doc.resolve(i);if(Z.valid(l))return l}return null}}}Z.prototype.visible=!1;Z.findFrom=Z.findGapCursorFrom;I.jsonID("gapcursor",Z);class dc{constructor(e){this.pos=e}map(e){return new dc(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Z.valid(n)?new Z(n):I.near(n)}}function PS(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),r=t.node(e);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function zS(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),r=t.node(e);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function bS(){return new Tt({props:{decorations:BS,createSelectionBetween(t,e,n){return e.pos==n.pos&&Z.valid(n)?new Z(n):null},handleClick:FS,handleKeyDown:IS,handleDOMEvents:{beforeinput:LS}}})}const IS=$p({ArrowLeft:To("horiz",-1),ArrowRight:To("horiz",1),ArrowUp:To("vert",-1),ArrowDown:To("vert",1)});function To(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,a=s.empty;if(s instanceof B){if(!o.endOfTextblock(n)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=Z.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new Z(u))),!0):!1}}function FS(t,e,n){if(!t||!t.editable)return!1;let r=t.state.doc.resolve(e);if(!Z.valid(r))return!1;let i=t.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&b.isSelectable(t.state.doc.nodeAt(i.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Z(r))),!0)}function LS(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof Z))return!1;let{$from:n}=t.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!r)return!1;let i=v.empty;for(let s=r.length-1;s>=0;s--)i=v.from(r[s].createAndFill(null,i));let o=t.state.tr.replace(n.pos,n.pos,new x(i,0,0));return o.setSelection(B.near(o.doc.resolve(n.pos+1))),t.dispatch(o),!1}function BS(t){if(!(t.selection instanceof Z))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",U.create(t.doc,[me.widget(t.selection.head,e,{key:"gapcursor"})])}class er{constructor(e,n,r={}){this.match=e,this.match=e,this.handler=typeof n=="string"?VS(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function VS(t){return function(e,n,r,i){let o=t;if(n[1]){let s=n[0].lastIndexOf(n[1]);o+=n[0].slice(s+n[1].length),r+=s;let l=r-i;l>0&&(o=n[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const $S=500;function _S({rules:t}){let e=new Tt({state:{init(){return null},apply(n,r){let i=n.getMeta(this);return i||(n.selectionSet||n.docChanged?null:r)}},props:{handleTextInput(n,r,i,o){return yd(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&yd(n,r.pos,r.pos,"",t,e)})}}},isInputRules:!0});return e}function yd(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-$S),l.parentOffset,null,"")+r;for(let u=0;u{let a=n instanceof Function?n(o):n,u=i.tr.delete(s,l),c=u.doc.resolve(s),f=c.blockRange(),d=f&&u1(f,e,a);if(!d)return null;u.wrap(f,d);let p=u.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&Xu(u.doc,s-1)&&(!r||r(o,p))&&u.join(s-1),u})}const US=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function jS(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,o,s;for(let l=0;l127)&&(o=Ut[r.keyCode])&&o!=i){let l=e[Ul(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Nm=65535,Mm=Math.pow(2,16);function qS(t,e){return t+e*Mm}function kd(t){return t&Nm}function QS(t){return(t-(t&Nm))/Mm}const Em=1,Om=2,is=4,Dm=8;class La{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Dm)>0}get deletedBefore(){return(this.delInfo&(Em|is))>0}get deletedAfter(){return(this.delInfo&(Om|is))>0}get deletedAcross(){return(this.delInfo&is)>0}}class je{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&je.empty)return je.empty}recover(e){let n=0,r=kd(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+o],c=this.ranges[l+s],f=a+u;if(e<=f){let d=u?e==a?-1:e==f?1:n:n,p=a+i+(d<0?0:c);if(r)return p;let h=e==(n<0?a:f)?null:qS(l/3,e-a),m=e==a?Om:e==f?Em:is;return(n<0?e!=a:e!=f)&&(m|=Dm),new La(p,m,h)}i+=c-u}return r?e+i:new La(e+i,0,null)}touches(e,n){let r=0,i=kd(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+o],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e.maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new Ci;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return oe.fromReplace(e,this.from,this.to,o)}invert(){return new wt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ln(n.pos,r.pos,this.mark)}merge(e){return e instanceof ln&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ln(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new ln(n.from,n.to,e.markFromJSON(n.mark))}}Me.jsonID("addMark",ln);class wt extends Me{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new x(hc(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return oe.fromReplace(e,this.from,this.to,r)}invert(){return new ln(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new wt(n.pos,r.pos,this.mark)}merge(e){return e instanceof wt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new wt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new wt(n.from,n.to,e.markFromJSON(n.mark))}}Me.jsonID("removeMark",wt);class an extends Me{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return oe.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return oe.fromReplace(e,this.pos,this.pos+1,new x(v.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new xt(n.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new xt(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}}Me.jsonID("replaceAround",xt);function Ba(t,e,n){let r=t.resolve(e),i=n-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function YS(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(u,e),p=Math.min(u+a.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(a)),o.forEach(a=>t.step(a))}function GS(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof co){let u=s.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let u=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new wt(s.from,s.to,s.style)))}function XS(t,e,n,r=n.contentMatch){let i=t.doc.nodeAt(e),o=[],s=e+1;for(let l=0;l=0;l--)t.step(o[l])}function ZS(t,e,n){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),a=s,u=l,c=v.empty,f=0;for(let h=o,m=!1;h>n;h--)m||r.index(h)>0?(m=!0,c=v.from(r.node(h).copy(c)),f++):a--;let d=v.empty,p=0;for(let h=o,m=!1;h>n;h--)m||i.after(h+1)=0;s--){if(r.size){let l=n[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=v.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new xt(i,o,i,o,new x(r,0,0),n.length,!0))}function tw(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=t.steps.length;t.doc.nodesBetween(e,n,(s,l)=>{if(s.isTextblock&&!s.hasMarkup(r,i)&&nw(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let a=t.mapping.slice(o),u=a.map(l,1),c=a.map(l+s.nodeSize,1);return t.step(new xt(u,c,u+1,c-1,new x(v.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function nw(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function rw(t,e,n,r,i){let o=t.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return t.replaceWith(e,e+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new xt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new x(v.from(s),0,0),1,!0))}function iw(t,e,n=1,r){let i=t.doc.resolve(e),o=v.empty,s=v.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){o=v.from(i.node(l).copy(o));let c=r&&r[u];s=v.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new De(e,e,new x(o.append(s),n,n),!0))}function ow(t,e,n){let r=new De(e-n,e+n,x.empty,!0);t.step(r)}function sw(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,n))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,n))return r.after(i+1);if(o0;i--)this.placed=v.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new x(o,s,l);return e>-1?new xt(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new De(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}n=o.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Hl(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,f=null;if(n==1&&(s?u.matchType(s.type)||(f=u.fillBefore(v.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=u.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&u.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Hl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Hl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new x(hi(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new x(hi(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:o}){for(;this.depth>n;)this.closeFrontierNode();if(o)for(let m=0;m1||a==0||m.content.size)&&(f=S,c.push(Rm(m.mark(d.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?p:-1)))}let h=u==l.childCount;h||(p=-1),this.placed=pi(this.placed,n,v.from(c)),this.frontier[n].match=f,h&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,S=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],o=n=0;l--){let{match:a,type:u}=this.frontier[l],c=Jl(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:s,move:o?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=pi(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=pi(this.placed,this.depth,v.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(v.empty,!0);n.childCount&&(this.placed=pi(this.placed,this.frontier.length,n))}}function hi(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(hi(t.firstChild.content,e-1,n)))}function pi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(pi(t.lastChild.content,e-1,n)))}function Hl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Rm(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(v.empty,!0)))),t.copy(r)}function Jl(t,e,n,r,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!uw(n,o.content,s)?l:null}function uw(t,e,n){for(let r=n;r0;d--,p--){let h=i.node(d).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;s.indexOf(d)>-1?l=d:i.before(d)==p&&s.splice(1,0,-d)}let a=s.indexOf(l),u=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(u.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=u[d],h=cw(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))c=d;else if(h||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+c+1)%(r.openStart+1),h=u[p];if(h)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>f));d--){let p=s[d];p<0||(e=i.before(p),n=o.after(p))}}function Am(t,e,n,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(t).append(t);t=s.append(o.matchFragment(s).fillBefore(v.empty,!0))}return t}function dw(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=sw(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new x(v.from(r),0,0))}function hw(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Pm(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s)return t.delete(r.before(s),n);t.delete(e,n)}function Pm(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let o=t.start(i);if(oe.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&n.push(i)}return n}class Nr extends Me{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return oe.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return oe.fromReplace(e,this.pos,this.pos+1,new x(v.from(i),0,n.isLeaf?0:1))}getMap(){return je.empty}invert(e){return new Nr(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Nr(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Nr(n.pos,n.attr,n.value)}}Me.jsonID("attr",Nr);class Wi extends Me{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return oe.ok(r)}getMap(){return je.empty}invert(e){return new Wi(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Wi(n.attr,n.value)}}Me.jsonID("docAttr",Wi);let Fr=class extends Error{};Fr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Fr.prototype=Object.create(Error.prototype);Fr.prototype.constructor=Fr;Fr.prototype.name="TransformError";class pw{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Ci}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Fr(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=x.empty){let i=lw(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new x(v.from(r),0,0))}delete(e,n){return this.replace(e,n,x.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return fw(this,e,n,r),this}replaceRangeWith(e,n,r){return dw(this,e,n,r),this}deleteRange(e,n){return hw(this,e,n),this}lift(e,n){return ZS(this,e,n),this}join(e,n=1){return ow(this,e,n),this}wrap(e,n){return ew(this,e,n),this}setBlockType(e,n=e,r,i=null){return tw(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return rw(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Nr(e,n,r)),this}setDocAttribute(e,n){return this.step(new Wi(e,n)),this}addNodeMark(e,n){return this.step(new an(e,n)),this}removeNodeMark(e,n){if(!(n instanceof W)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n=n.isInSet(r.marks),!n)return this}return this.step(new Ir(e,n)),this}split(e,n=1,r){return iw(this,e,n,r),this}addMark(e,n,r){return YS(this,e,n,r),this}removeMark(e,n,r){return GS(this,e,n,r),this}clearIncompatible(e,n,r){return XS(this,e,n,r),this}}var Va,$a;if(typeof WeakMap<"u"){let t=new WeakMap;Va=e=>t.get(e),$a=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;Va=r=>{for(let i=0;i(n==10&&(n=0),t[n++]=r,t[n++]=i)}var re=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e=n){(o||(o=[])).push({type:"overlong_rowspan",pos:c,n:g-k});break}const w=i+k*e;for(let M=0;Mr&&(o+=u.attrs.colspan)}}for(let s=0;s1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function yw(t,e,n){t.problems||(t.problems=[]);const r={};for(let i=0;iNumber(s)):null,i=Number(t.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(t.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const s in e){const l=e[s].getFromDOM,a=l&&l(t);a!=null&&(o[s]=a)}return o}function wd(t,e){const n={};t.attrs.colspan!=1&&(n.colspan=t.attrs.colspan),t.attrs.rowspan!=1&&(n.rowspan=t.attrs.rowspan),t.attrs.colwidth&&(n["data-colwidth"]=t.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(t.attrs[r],n)}return n}function Sw(t){const e=t.cellAttributes||{},n={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)n[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:t.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:t.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Sd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Sd(r,e)}],toDOM(r){return["th",wd(r,e),0]}}}}function Ot(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const n in t.nodes){const r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var tn=new ho("selectingCells");function go(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function pc(t){const e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function zm(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const n=go(e.$head)||ww(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function ww(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function _a(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function mc(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function bm(t,e,n){const r=t.node(-1),i=re.get(r),o=t.start(-1),s=i.nextCell(t.pos-o,e,n);return s==null?null:t.node(0).resolve(o+s)}function Lr(t,e,n=1){const r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var ce=class Pt extends I{constructor(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.rectBetween(e.pos-o,n.pos-o),l=e.node(0),a=i.cellsInRect(s).filter(c=>c!=n.pos-o);a.unshift(n.pos-o);const u=a.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new Rp(l.resolve(d),l.resolve(d+f.content.size))});super(u[0].$from,u[0].$to,u),this.$anchorCell=e,this.$headCell=n}map(e,n){const r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(_a(r)&&_a(i)&&mc(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Pt.rowSelection(r,i):o&&this.isColSelection()?Pt.colSelection(r,i):new Pt(r,i)}return B.between(r,i)}content(){const e=this.$anchorCell.node(-1),n=re.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];for(let a=i.top;a0||S>0){let g=h.attrs;if(m>0&&(g=Lr(g,0,m)),S>0&&(g=Lr(g,g.colspan-S,S)),p.lefti.bottom){const g={...h.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(n.pos-o),a=e.node(0);return s.top<=l.top?(s.top>0&&(e=a.resolve(o+i.map[s.left])),l.bottom0&&(n=a.resolve(o+i.map[l.left])),s.bottom0)return!1;const s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==n.width}eq(e){return e instanceof Pt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){const r=e.node(-1),i=re.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(n.pos-o),a=e.node(0);return s.left<=l.left?(s.left>0&&(e=a.resolve(o+i.map[s.top*i.width])),l.right0&&(n=a.resolve(o+i.map[l.top*i.width])),s.right{e.push(me.node(r,r+n.nodeSize,{class:"selectedCell"}))}),U.create(t.doc,e)}function Cw({$from:t,$to:e}){if(t.pos==e.pos||t.pos=0&&!(t.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function Nw({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){const o=t.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){n=o;break}}for(let i=e.depth;i>0;i--){const o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return n!==r&&e.parentOffset===0}function Mw(t,e,n){const r=(e||t).selection,i=(e||t).doc;let o,s;if(r instanceof b&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=ce.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=ce.rowSelection(l,l)}else if(!n){const l=re.get(r.node),a=r.from+1,u=a+l.map[l.width*l.height-1];o=ce.create(i,a+1,u)}}else r instanceof B&&Cw(r)?o=B.create(i,r.from):r instanceof B&&Nw(r)&&(o=B.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var Ew=new ho("fix-tables");function Fm(t,e,n,r){const i=t.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(n=Dw(t,i,o,n))};return e?e.doc!=t.doc&&Fm(e.doc,t.doc,0,r):t.doc.descendants(r),n}function Dw(t,e,n,r){const i=re.get(e);if(!i.problems)return r;r||(r=t.tr);const o=[];for(let a=0;a0){let p="cell";c.firstChild&&(p=c.firstChild.type.spec.tableRole);const h=[];for(let S=0;S0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;const i=e.child(0),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let a=0;a=0;s--){const{rowspan:l,colspan:a}=o.child(s).attrs;for(let u=i;u=e.length&&e.push(v.empty),n[i]r&&(d=d.type.createChecked(Lr(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),u.push(d),c+=d.attrs.colspan;for(let p=1;pi&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}o.push(v.from(a))}n=o,e=i}return{width:t,height:e,rows:n}}function Pw(t,e,n,r,i,o,s){const l=t.doc.type.schema,a=Ot(l);let u,c;if(i>e.width)for(let f=0,d=0;fe.height){const f=[];for(let h=0,m=(e.height-1)*e.width;h=e.width?!1:n.nodeAt(e.map[m+h]).type==a.header_cell;f.push(S?c||(c=a.header_cell.createAndFill()):u||(u=a.cell.createAndFill()))}const d=a.row.create(null,v.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=n.selection;if(o instanceof ce)return ss(n,r,I.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;const s=Lm(i,t,e);if(s==null)return!1;if(t=="horiz")return ss(n,r,I.near(n.doc.resolve(o.head+e),e));{const l=n.doc.resolve(s),a=bm(l,t,e);let u;return a?u=I.near(a,1):e<0?u=I.near(n.doc.resolve(l.before(-1)),-1):u=I.near(n.doc.resolve(l.after(-1)),1),ss(n,r,u)}}}function Ao(t,e){return(n,r,i)=>{if(!i)return!1;const o=n.selection;let s;if(o instanceof ce)s=o;else{const a=Lm(i,t,e);if(a==null)return!1;s=new ce(n.doc.resolve(a))}const l=bm(s.$headCell,t,e);return l?ss(n,r,new ce(s.$anchorCell,l)):!1}}function Po(t,e){const n=t.selection;if(!(n instanceof ce))return!1;if(e){const r=t.tr,i=Ot(t.schema).cell.createAndFill().content;n.forEachCell((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new x(i,0,0))}),r.docChanged&&e(r)}return!0}function bw(t,e){const n=t.state.doc,r=go(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new ce(r))),!0):!1}function Iw(t,e,n){if(!pc(t.state))return!1;let r=Tw(n);const i=t.state.selection;if(i instanceof ce){r||(r={width:1,height:1,rows:[v.from(Wa(Ot(t.state.schema).cell,n))]});const o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=re.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=Aw(r,l.right-l.left,l.bottom-l.top),Cd(t.state,t.dispatch,s,l,r),!0}else if(r){const o=zm(t.state),s=o.start(-1);return Cd(t.state,t.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function Fw(t,e){var n;if(e.ctrlKey||e.metaKey)return;const r=Nd(t,e.target);let i;if(e.shiftKey&&t.state.selection instanceof ce)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=go(t.state.selection.$anchor))!=null&&((n=Kl(t,e))==null?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=Kl(t,u);const f=tn.getState(t.state)==null;if(!c||!mc(a,c))if(f)c=a;else return;const d=new ce(a,c);if(f||!t.state.selection.eq(d)){const p=t.state.tr.setSelection(d);f&&p.setMeta(tn,a.pos),t.dispatch(p)}}function s(){t.root.removeEventListener("mouseup",s),t.root.removeEventListener("dragstart",s),t.root.removeEventListener("mousemove",l),tn.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(tn,-1))}function l(a){const u=a,c=tn.getState(t.state);let f;if(c!=null)f=t.state.doc.resolve(c);else if(Nd(t,u.target)!=r&&(f=Kl(t,e),!f))return s();f&&o(f,u)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",l)}function Lm(t,e,n){if(!(t.state.selection instanceof B))return null;const{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){const o=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?l:null}}return null}function Nd(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Kl(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});return n&&n?go(t.state.doc.resolve(n.pos)):null}var Lw=class{constructor(t,e){this.node=t,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Ua(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!=this.node.type?!1:(this.node=t,Ua(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Ua(t,e,n,r,i,o){var s;let l=0,a=!0,u=e.firstChild;const c=t.firstChild;if(c){for(let f=0,d=0;fnew n(l,e,a),new Vw(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{const s=et.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{$w(o,s,t,e,r)},mouseleave:o=>{_w(o)},mousedown:(o,s)=>{Ww(o,s,e)}},decorations:o=>{const s=et.getState(o);if(s&&s.activeHandle>-1)return qw(o,s.activeHandle)},nodeViews:{}}});return i}var Vw=class ls{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){const n=this,r=e.getMeta(et);if(r&&r.setHandle!=null)return new ls(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ls(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return _a(e.doc.resolve(i))||(i=-1),new ls(i,n.dragging)}return n}};function $w(t,e,n,r,i){const o=et.getState(t.state);if(o&&!o.dragging){const s=jw(e.target);let l=-1;if(s){const{left:a,right:u}=s.getBoundingClientRect();e.clientX-a<=n?l=Md(t,e,"left",n):u-e.clientX<=n&&(l=Md(t,e,"right",n))}if(l!=o.activeHandle){if(!i&&l!==-1){const a=t.state.doc.resolve(l),u=a.node(-1),c=re.get(u),f=a.start(-1);if(c.colCount(a.pos-f)+a.nodeAfter.attrs.colspan-1==c.width-1)return}Bm(t,l)}}}function _w(t){const e=et.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Bm(t,-1)}function Ww(t,e,n){var r;const i=(r=t.dom.ownerDocument.defaultView)!=null?r:window,o=et.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const s=t.state.doc.nodeAt(o.activeHandle),l=Uw(t,o.activeHandle,s.attrs);t.dispatch(t.state.tr.setMeta(et,{setDragging:{startX:e.clientX,startWidth:l}}));function a(c){i.removeEventListener("mouseup",a),i.removeEventListener("mousemove",u);const f=et.getState(t.state);f!=null&&f.dragging&&(Hw(t,f.activeHandle,Ed(f.dragging,c,n)),t.dispatch(t.state.tr.setMeta(et,{setDragging:null})))}function u(c){if(!c.which)return a(c);const f=et.getState(t.state);if(f&&f.dragging){const d=Ed(f.dragging,c,n);Jw(t,f.activeHandle,d,n)}}return i.addEventListener("mouseup",a),i.addEventListener("mousemove",u),e.preventDefault(),!0}function Uw(t,e,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const o=t.domAtPos(e);let l=o.node.childNodes[o.offset].offsetWidth,a=n;if(r)for(let u=0;ui.table.nodeAt(a));for(let a=0;a{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}gc("row",{useDeprecatedLogic:!0});gc("column",{useDeprecatedLogic:!0});gc("cell",{useDeprecatedLogic:!0});function Yw({allowTableNodeSelection:t=!1}={}){return new Tt({key:tn,state:{init(){return null},apply(e,n){const r=e.getMeta(tn);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;const{deleted:i,pos:o}=e.mapping.mapResult(n);return i?null:o}},props:{decorations:xw,handleDOMEvents:{mousedown:Fw},createSelectionBetween(e){return tn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:bw,handleKeyDown:zw,handlePaste:Iw},appendTransaction(e,n,r){return Mw(r,Ow(r,n),t)}})}var $m={exports:{}},Qe={},_m={exports:{}},Wm={};/** * @license React * scheduler.production.min.js * @@ -30,7 +30,7 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */(function(t){function e(A,F){var L=A.length;A.push(F);e:for(;0>>1,ae=A[ee];if(0>>1;eei(Nl,L))Rni(No,Nl)?(A[ee]=No,A[Rn]=L,ee=Rn):(A[ee]=Nl,A[Tn]=L,ee=Tn);else if(Rni(No,L))A[ee]=No,A[Rn]=L,ee=Rn;else break e}}return F}function i(A,F){var L=A.sortIndex-F.sortIndex;return L!==0?L:A.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;t.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();t.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,k=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function S(A){for(var F=n(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=A)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=n(u)}}function w(A){if(m=!1,S(A),!h)if(n(a)!==null)h=!0,xl(M);else{var F=n(u);F!==null&&Cl(w,F.startTime-A)}}function M(A,F){h=!1,m&&(m=!1,g(R),R=-1),p=!0;var L=d;try{for(S(F),f=n(a);f!==null&&(!(f.expirationTime>F)||A&&!ne());){var ee=f.callback;if(typeof ee=="function"){f.callback=null,d=f.priorityLevel;var ae=ee(f.expirationTime<=F);F=t.unstable_now(),typeof ae=="function"?f.callback=ae:f===n(a)&&r(a),S(F)}else r(a);f=n(a)}if(f!==null)var Co=!0;else{var Tn=n(u);Tn!==null&&Cl(w,Tn.startTime-F),Co=!1}return Co}finally{f=null,d=L,p=!1}}var O=!1,D=null,R=-1,E=5,P=-1;function ne(){return!(t.unstable_now()-PA||125ee?(A.sortIndex=L,e(u,A),n(a)===null&&A===n(u)&&(m?(g(R),R=-1):m=!0,Cl(w,L-ee))):(A.sortIndex=ae,e(a,A),h||p||(h=!0,xl(M))),A},t.unstable_shouldYield=ne,t.unstable_wrapCallback=function(A){var F=d;return function(){var L=d;d=F;try{return A.apply(this,arguments)}finally{d=L}}}})(Um);Wm.exports=Um;var Yw=Wm.exports;/** + */(function(t){function e(A,F){var L=A.length;A.push(F);e:for(;0>>1,ae=A[ee];if(0>>1;eei(Nl,L))Rni(No,Nl)?(A[ee]=No,A[Rn]=L,ee=Rn):(A[ee]=Nl,A[Tn]=L,ee=Tn);else if(Rni(No,L))A[ee]=No,A[Rn]=L,ee=Rn;else break e}}return F}function i(A,F){var L=A.sortIndex-F.sortIndex;return L!==0?L:A.id-F.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;t.unstable_now=function(){return o.now()}}else{var s=Date,l=s.now();t.unstable_now=function(){return s.now()-l}}var a=[],u=[],c=1,f=null,d=3,p=!1,h=!1,m=!1,S=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function k(A){for(var F=n(u);F!==null;){if(F.callback===null)r(u);else if(F.startTime<=A)r(u),F.sortIndex=F.expirationTime,e(a,F);else break;F=n(u)}}function w(A){if(m=!1,k(A),!h)if(n(a)!==null)h=!0,xl(M);else{var F=n(u);F!==null&&Cl(w,F.startTime-A)}}function M(A,F){h=!1,m&&(m=!1,g(R),R=-1),p=!0;var L=d;try{for(k(F),f=n(a);f!==null&&(!(f.expirationTime>F)||A&&!ne());){var ee=f.callback;if(typeof ee=="function"){f.callback=null,d=f.priorityLevel;var ae=ee(f.expirationTime<=F);F=t.unstable_now(),typeof ae=="function"?f.callback=ae:f===n(a)&&r(a),k(F)}else r(a);f=n(a)}if(f!==null)var Co=!0;else{var Tn=n(u);Tn!==null&&Cl(w,Tn.startTime-F),Co=!1}return Co}finally{f=null,d=L,p=!1}}var O=!1,D=null,R=-1,E=5,P=-1;function ne(){return!(t.unstable_now()-PA||125ee?(A.sortIndex=L,e(u,A),n(a)===null&&A===n(u)&&(m?(g(R),R=-1):m=!0,Cl(w,L-ee))):(A.sortIndex=ae,e(a,A),h||p||(h=!0,xl(M))),A},t.unstable_shouldYield=ne,t.unstable_wrapCallback=function(A){var F=d;return function(){var L=d;d=F;try{return A.apply(this,arguments)}finally{d=L}}}})(Wm);_m.exports=Wm;var Gw=_m.exports;/** * @license React * react-dom.production.min.js * @@ -38,16 +38,16 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var jm=C,qe=Yw;function N(t){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+t,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ja=Object.prototype.hasOwnProperty,Gw=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,Dd={},Td={};function Xw(t){return ja.call(Td,t)?!0:ja.call(Dd,t)?!1:Gw.test(t)?Td[t]=!0:(Dd[t]=!0,!1)}function Zw(t,e,n,r){if(n!==null&&n.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function ev(t,e,n,r){if(e===null||typeof e>"u"||Zw(t,e,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function Ie(t,e,n,r,i,o,s){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=t,this.type=e,this.sanitizeURL=o,this.removeEmptyString=s}var ye={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){ye[t]=new Ie(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];ye[e]=new Ie(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){ye[t]=new Ie(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){ye[t]=new Ie(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){ye[t]=new Ie(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){ye[t]=new Ie(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){ye[t]=new Ie(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){ye[t]=new Ie(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){ye[t]=new Ie(t,5,!1,t.toLowerCase(),null,!1,!1)});var yc=/[\-:]([a-z])/g;function Sc(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(yc,Sc);ye[e]=new Ie(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(yc,Sc);ye[e]=new Ie(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(yc,Sc);ye[e]=new Ie(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){ye[t]=new Ie(t,1,!1,t.toLowerCase(),null,!1,!1)});ye.xlinkHref=new Ie("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){ye[t]=new Ie(t,1,!1,t.toLowerCase(),null,!0,!0)});function kc(t,e,n,r){var i=ye.hasOwnProperty(e)?ye[e]:null;(i!==null?i.type!==0:r||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ja=Object.prototype.hasOwnProperty,Xw=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,Dd={},Td={};function Zw(t){return ja.call(Td,t)?!0:ja.call(Dd,t)?!1:Xw.test(t)?Td[t]=!0:(Dd[t]=!0,!1)}function ev(t,e,n,r){if(n!==null&&n.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function tv(t,e,n,r){if(e===null||typeof e>"u"||ev(t,e,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function be(t,e,n,r,i,o,s){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=t,this.type=e,this.sanitizeURL=o,this.removeEmptyString=s}var ye={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){ye[t]=new be(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];ye[e]=new be(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){ye[t]=new be(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){ye[t]=new be(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){ye[t]=new be(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){ye[t]=new be(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){ye[t]=new be(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){ye[t]=new be(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){ye[t]=new be(t,5,!1,t.toLowerCase(),null,!1,!1)});var yc=/[\-:]([a-z])/g;function kc(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(yc,kc);ye[e]=new be(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(yc,kc);ye[e]=new be(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(yc,kc);ye[e]=new be(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){ye[t]=new be(t,1,!1,t.toLowerCase(),null,!1,!1)});ye.xlinkHref=new be("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){ye[t]=new be(t,1,!1,t.toLowerCase(),null,!0,!0)});function Sc(t,e,n,r){var i=ye.hasOwnProperty(e)?ye[e]:null;(i!==null?i.type!==0:r||!(2l||i[s]!==o[l]){var a=` -`+i[s].replace(" at new "," at ");return t.displayName&&a.includes("")&&(a=a.replace("",t.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ql=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?mi(t):""}function tv(t){switch(t.tag){case 5:return mi(t.type);case 16:return mi("Lazy");case 13:return mi("Suspense");case 19:return mi("SuspenseList");case 0:case 2:case 15:return t=Yl(t.type,!1),t;case 11:return t=Yl(t.type.render,!1),t;case 1:return t=Yl(t.type,!0),t;default:return""}}function qa(t){if(t==null)return null;if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case fr:return"Fragment";case cr:return"Portal";case Ha:return"Profiler";case wc:return"StrictMode";case Ja:return"Suspense";case Ka:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case Km:return(t.displayName||"Context")+".Consumer";case Jm:return(t._context.displayName||"Context")+".Provider";case vc:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case xc:return e=t.displayName||null,e!==null?e:qa(t.type)||"Memo";case Xt:e=t._payload,t=t._init;try{return qa(t(e))}catch{}}return null}function nv(t){var e=t.type;switch(t.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return t=e.render,t=t.displayName||t.name||"",e.displayName||(t!==""?"ForwardRef("+t+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return qa(e);case 8:return e===wc?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function vn(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function Qm(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function rv(t){var e=Qm(t)?"checked":"value",n=Object.getOwnPropertyDescriptor(t.constructor.prototype,e),r=""+t[e];if(!t.hasOwnProperty(e)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var i=n.get,o=n.set;return Object.defineProperty(t,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(t,e,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){t._valueTracker=null,delete t[e]}}}}function Io(t){t._valueTracker||(t._valueTracker=rv(t))}function Ym(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=Qm(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Ts(t){if(t=t||(typeof document<"u"?document:void 0),typeof t>"u")return null;try{return t.activeElement||t.body}catch{return t.body}}function Qa(t,e){var n=e.checked;return G({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function Ad(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=vn(e.value!=null?e.value:n),t._wrapperState={initialChecked:r,initialValue:n,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function Gm(t,e){e=e.checked,e!=null&&kc(t,"checked",e,!1)}function Ya(t,e){Gm(t,e);var n=vn(e.value),r=e.type;if(n!=null)r==="number"?(n===0&&t.value===""||t.value!=n)&&(t.value=""+n):t.value!==""+n&&(t.value=""+n);else if(r==="submit"||r==="reset"){t.removeAttribute("value");return}e.hasOwnProperty("value")?Ga(t,e.type,n):e.hasOwnProperty("defaultValue")&&Ga(t,e.type,vn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function Pd(t,e,n){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+t._wrapperState.initialValue,n||e===t.value||(t.value=e),t.defaultValue=e}n=t.name,n!==""&&(t.name=""),t.defaultChecked=!!t._wrapperState.initialChecked,n!==""&&(t.name=n)}function Ga(t,e,n){(e!=="number"||Ts(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var gi=Array.isArray;function Mr(t,e,n,r){if(t=t.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=bo.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function ji(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Ni={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},iv=["Webkit","ms","Moz","O"];Object.keys(Ni).forEach(function(t){iv.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Ni[e]=Ni[t]})});function tg(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Ni.hasOwnProperty(t)&&Ni[t]?(""+e).trim():e+"px"}function ng(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=tg(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,i):t[n]=i}}var ov=G({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function eu(t,e){if(e){if(ov[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(N(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(N(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(N(61))}if(e.style!=null&&typeof e.style!="object")throw Error(N(62))}}function tu(t,e){if(t.indexOf("-")===-1)return typeof e.is=="string";switch(t){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var nu=null;function Cc(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var ru=null,Er=null,Or=null;function bd(t){if(t=ko(t)){if(typeof ru!="function")throw Error(N(280));var e=t.stateNode;e&&(e=ul(e),ru(t.stateNode,t.type,e))}}function rg(t){Er?Or?Or.push(t):Or=[t]:Er=t}function ig(){if(Er){var t=Er,e=Or;if(Or=Er=null,bd(t),e)for(t=0;t>>=0,t===0?32:31-(gv(t)/yv|0)|0}var Fo=64,Lo=4194304;function yi(t){switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return t&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return t}}function zs(t,e){var n=t.pendingLanes;if(n===0)return 0;var r=0,i=t.suspendedLanes,o=t.pingedLanes,s=n&268435455;if(s!==0){var l=s&~i;l!==0?r=yi(l):(o&=s,o!==0&&(r=yi(o)))}else s=n&~i,s!==0?r=yi(s):o!==0&&(r=yi(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=n&16),e=t.entangledLanes,e!==0)for(t=t.entanglements,e&=r;0n;n++)e.push(t);return e}function yo(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-dt(e),t[e]=n}function vv(t,e){var n=t.pendingLanes&~e;t.pendingLanes=e,t.suspendedLanes=0,t.pingedLanes=0,t.expiredLanes&=e,t.mutableReadLanes&=e,t.entangledLanes&=e,e=t.entanglements;var r=t.eventTimes;for(t=t.expirationTimes;0=Ei),jd=String.fromCharCode(32),Hd=!1;function Ng(t,e){switch(t){case"keyup":return Qv.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Mg(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var dr=!1;function Gv(t,e){switch(t){case"compositionend":return Mg(e);case"keypress":return e.which!==32?null:(Hd=!0,jd);case"textInput":return t=e.data,t===jd&&Hd?null:t;default:return null}}function Xv(t,e){if(dr)return t==="compositionend"||!Ac&&Ng(t,e)?(t=xg(),us=Dc=un=null,dr=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:n,offset:e-t};t=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Qd(n)}}function Tg(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?Tg(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function Rg(){for(var t=window,e=Ts();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Ts(t.document)}return e}function Pc(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e&&(e==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||e==="textarea"||t.contentEditable==="true")}function lx(t){var e=Rg(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&Tg(n.ownerDocument.documentElement,n)){if(r!==null&&Pc(n)){if(e=r.start,t=r.end,t===void 0&&(t=e),"selectionStart"in n)n.selectionStart=e,n.selectionEnd=Math.min(t,n.value.length);else if(t=(e=n.ownerDocument||document)&&e.defaultView||window,t.getSelection){t=t.getSelection();var i=n.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!t.extend&&o>r&&(i=r,r=o,o=i),i=Yd(n,o);var s=Yd(n,r);i&&s&&(t.rangeCount!==1||t.anchorNode!==i.node||t.anchorOffset!==i.offset||t.focusNode!==s.node||t.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),t.removeAllRanges(),o>r?(t.addRange(e),t.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),t.addRange(e)))}}for(e=[],t=n;t=t.parentNode;)t.nodeType===1&&e.push({element:t,left:t.scrollLeft,top:t.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,hr=null,uu=null,Di=null,cu=!1;function Gd(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;cu||hr==null||hr!==Ts(r)||(r=hr,"selectionStart"in r&&Pc(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Di&&Yi(Di,r)||(Di=r,r=Fs(uu,"onSelect"),0gr||(t.current=gu[gr],gu[gr]=null,gr--)}function H(t,e){gr++,gu[gr]=t.current,t.current=e}var xn={},Ne=En(xn),Ve=En(!1),Qn=xn;function Vr(t,e){var n=t.type.contextTypes;if(!n)return xn;var r=t.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in n)i[o]=e[o];return r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=e,t.__reactInternalMemoizedMaskedChildContext=i),i}function $e(t){return t=t.childContextTypes,t!=null}function Bs(){K(Ve),K(Ne)}function ih(t,e,n){if(Ne.current!==xn)throw Error(N(168));H(Ne,e),H(Ve,n)}function Vg(t,e,n){var r=t.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(N(108,nv(t)||"Unknown",i));return G({},n,r)}function Vs(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||xn,Qn=Ne.current,H(Ne,t),H(Ve,Ve.current),!0}function oh(t,e,n){var r=t.stateNode;if(!r)throw Error(N(169));n?(t=Vg(t,e,Qn),r.__reactInternalMemoizedMergedChildContext=t,K(Ve),K(Ne),H(Ne,t)):K(Ve),H(Ve,n)}var Ft=null,cl=!1,ca=!1;function $g(t){Ft===null?Ft=[t]:Ft.push(t)}function kx(t){cl=!0,$g(t)}function On(){if(!ca&&Ft!==null){ca=!0;var t=0,e=j;try{var n=Ft;for(j=1;t>=s,i-=s,Bt=1<<32-dt(e)+i|n<R?(E=D,D=null):E=D.sibling;var P=d(g,D,S[R],w);if(P===null){D===null&&(D=E);break}t&&D&&P.alternate===null&&e(g,D),y=o(P,y,R),O===null?M=P:O.sibling=P,O=P,D=E}if(R===S.length)return n(g,D),q&&Pn(g,R),M;if(D===null){for(;RR?(E=D,D=null):E=D.sibling;var ne=d(g,D,P.value,w);if(ne===null){D===null&&(D=E);break}t&&D&&ne.alternate===null&&e(g,D),y=o(ne,y,R),O===null?M=ne:O.sibling=ne,O=ne,D=E}if(P.done)return n(g,D),q&&Pn(g,R),M;if(D===null){for(;!P.done;R++,P=S.next())P=f(g,P.value,w),P!==null&&(y=o(P,y,R),O===null?M=P:O.sibling=P,O=P);return q&&Pn(g,R),M}for(D=r(g,D);!P.done;R++,P=S.next())P=p(D,g,R,P.value,w),P!==null&&(t&&P.alternate!==null&&D.delete(P.key===null?R:P.key),y=o(P,y,R),O===null?M=P:O.sibling=P,O=P);return t&&D.forEach(function(Rt){return e(g,Rt)}),q&&Pn(g,R),M}function k(g,y,S,w){if(typeof S=="object"&&S!==null&&S.type===fr&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case zo:e:{for(var M=S.key,O=y;O!==null;){if(O.key===M){if(M=S.type,M===fr){if(O.tag===7){n(g,O.sibling),y=i(O,S.props.children),y.return=g,g=y;break e}}else if(O.elementType===M||typeof M=="object"&&M!==null&&M.$$typeof===Xt&&dh(M)===O.type){n(g,O.sibling),y=i(O,S.props),y.ref=ri(g,O,S),y.return=g,g=y;break e}n(g,O);break}else e(g,O);O=O.sibling}S.type===fr?(y=Jn(S.props.children,g.mode,w,S.key),y.return=g,g=y):(w=ys(S.type,S.key,S.props,null,g.mode,w),w.ref=ri(g,y,S),w.return=g,g=w)}return s(g);case cr:e:{for(O=S.key;y!==null;){if(y.key===O)if(y.tag===4&&y.stateNode.containerInfo===S.containerInfo&&y.stateNode.implementation===S.implementation){n(g,y.sibling),y=i(y,S.children||[]),y.return=g,g=y;break e}else{n(g,y);break}else e(g,y);y=y.sibling}y=Sa(S,g.mode,w),y.return=g,g=y}return s(g);case Xt:return O=S._init,k(g,y,O(S._payload),w)}if(gi(S))return h(g,y,S,w);if(Xr(S))return m(g,y,S,w);jo(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,y!==null&&y.tag===6?(n(g,y.sibling),y=i(y,S),y.return=g,g=y):(n(g,y),y=ya(S,g.mode,w),y.return=g,g=y),s(g)):n(g,y)}return k}var _r=qg(!0),Qg=qg(!1),wo={},Nt=En(wo),eo=En(wo),to=En(wo);function $n(t){if(t===wo)throw Error(N(174));return t}function _c(t,e){switch(H(to,e),H(eo,t),H(Nt,wo),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:Za(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=Za(e,t)}K(Nt),H(Nt,e)}function Wr(){K(Nt),K(eo),K(to)}function Yg(t){$n(to.current);var e=$n(Nt.current),n=Za(e,t.type);e!==n&&(H(eo,t),H(Nt,n))}function Wc(t){eo.current===t&&(K(Nt),K(eo))}var Q=En(0);function Hs(t){for(var e=t;e!==null;){if(e.tag===13){var n=e.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break;for(;e.sibling===null;){if(e.return===null||e.return===t)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var fa=[];function Uc(){for(var t=0;tn?n:4,t(!0);var r=da.transition;da.transition={};try{t(!1),e()}finally{j=n,da.transition=r}}function dy(){return ot().memoizedState}function Cx(t,e,n){var r=kn(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},hy(t))py(e,n);else if(n=jg(t,e,n,r),n!==null){var i=Te();ht(n,t,r,i),my(n,e,r)}}function Nx(t,e,n){var r=kn(t),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(hy(t))py(e,i);else{var o=t.alternate;if(t.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,n);if(i.hasEagerState=!0,i.eagerState=l,mt(l,s)){var a=e.interleaved;a===null?(i.next=i,Vc(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}n=jg(t,e,i,r),n!==null&&(i=Te(),ht(n,t,r,i),my(n,e,r))}}function hy(t){var e=t.alternate;return t===Y||e!==null&&e===Y}function py(t,e){Ti=Js=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function my(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Mc(t,n)}}var Ks={readContext:it,useCallback:Se,useContext:Se,useEffect:Se,useImperativeHandle:Se,useInsertionEffect:Se,useLayoutEffect:Se,useMemo:Se,useReducer:Se,useRef:Se,useState:Se,useDebugValue:Se,useDeferredValue:Se,useTransition:Se,useMutableSource:Se,useSyncExternalStore:Se,useId:Se,unstable_isNewReconciler:!1},Mx={readContext:it,useCallback:function(t,e){return yt().memoizedState=[t,e===void 0?null:e],t},useContext:it,useEffect:ph,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,hs(4194308,4,ly.bind(null,e,t),n)},useLayoutEffect:function(t,e){return hs(4194308,4,t,e)},useInsertionEffect:function(t,e){return hs(4,2,t,e)},useMemo:function(t,e){var n=yt();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=yt();return e=n!==void 0?n(e):e,r.memoizedState=r.baseState=e,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:e},r.queue=t,t=t.dispatch=Cx.bind(null,Y,t),[r.memoizedState,t]},useRef:function(t){var e=yt();return t={current:t},e.memoizedState=t},useState:hh,useDebugValue:qc,useDeferredValue:function(t){return yt().memoizedState=t},useTransition:function(){var t=hh(!1),e=t[0];return t=xx.bind(null,t[1]),yt().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=Y,i=yt();if(q){if(n===void 0)throw Error(N(407));n=n()}else{if(n=e(),fe===null)throw Error(N(349));Gn&30||Zg(r,e,n)}i.memoizedState=n;var o={value:n,getSnapshot:e};return i.queue=o,ph(ty.bind(null,r,o,t),[t]),r.flags|=2048,io(9,ey.bind(null,r,o,n,e),void 0,null),n},useId:function(){var t=yt(),e=fe.identifierPrefix;if(q){var n=Vt,r=Bt;n=(r&~(1<<32-dt(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=no++,0")&&(a=a.replace("",t.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ql=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?mi(t):""}function nv(t){switch(t.tag){case 5:return mi(t.type);case 16:return mi("Lazy");case 13:return mi("Suspense");case 19:return mi("SuspenseList");case 0:case 2:case 15:return t=Yl(t.type,!1),t;case 11:return t=Yl(t.type.render,!1),t;case 1:return t=Yl(t.type,!0),t;default:return""}}function qa(t){if(t==null)return null;if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case fr:return"Fragment";case cr:return"Portal";case Ha:return"Profiler";case wc:return"StrictMode";case Ja:return"Suspense";case Ka:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case Jm:return(t.displayName||"Context")+".Consumer";case Hm:return(t._context.displayName||"Context")+".Provider";case vc:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case xc:return e=t.displayName||null,e!==null?e:qa(t.type)||"Memo";case Xt:e=t._payload,t=t._init;try{return qa(t(e))}catch{}}return null}function rv(t){var e=t.type;switch(t.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return t=e.render,t=t.displayName||t.name||"",e.displayName||(t!==""?"ForwardRef("+t+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return qa(e);case 8:return e===wc?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function vn(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function qm(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function iv(t){var e=qm(t)?"checked":"value",n=Object.getOwnPropertyDescriptor(t.constructor.prototype,e),r=""+t[e];if(!t.hasOwnProperty(e)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var i=n.get,o=n.set;return Object.defineProperty(t,e,{configurable:!0,get:function(){return i.call(this)},set:function(s){r=""+s,o.call(this,s)}}),Object.defineProperty(t,e,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){t._valueTracker=null,delete t[e]}}}}function bo(t){t._valueTracker||(t._valueTracker=iv(t))}function Qm(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=qm(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Ts(t){if(t=t||(typeof document<"u"?document:void 0),typeof t>"u")return null;try{return t.activeElement||t.body}catch{return t.body}}function Qa(t,e){var n=e.checked;return G({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function Ad(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=vn(e.value!=null?e.value:n),t._wrapperState={initialChecked:r,initialValue:n,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function Ym(t,e){e=e.checked,e!=null&&Sc(t,"checked",e,!1)}function Ya(t,e){Ym(t,e);var n=vn(e.value),r=e.type;if(n!=null)r==="number"?(n===0&&t.value===""||t.value!=n)&&(t.value=""+n):t.value!==""+n&&(t.value=""+n);else if(r==="submit"||r==="reset"){t.removeAttribute("value");return}e.hasOwnProperty("value")?Ga(t,e.type,n):e.hasOwnProperty("defaultValue")&&Ga(t,e.type,vn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function Pd(t,e,n){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+t._wrapperState.initialValue,n||e===t.value||(t.value=e),t.defaultValue=e}n=t.name,n!==""&&(t.name=""),t.defaultChecked=!!t._wrapperState.initialChecked,n!==""&&(t.name=n)}function Ga(t,e,n){(e!=="number"||Ts(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var gi=Array.isArray;function Mr(t,e,n,r){if(t=t.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=Io.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function ji(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Ni={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},ov=["Webkit","ms","Moz","O"];Object.keys(Ni).forEach(function(t){ov.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Ni[e]=Ni[t]})});function eg(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Ni.hasOwnProperty(t)&&Ni[t]?(""+e).trim():e+"px"}function tg(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=eg(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,i):t[n]=i}}var sv=G({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function eu(t,e){if(e){if(sv[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(N(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(N(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(N(61))}if(e.style!=null&&typeof e.style!="object")throw Error(N(62))}}function tu(t,e){if(t.indexOf("-")===-1)return typeof e.is=="string";switch(t){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var nu=null;function Cc(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var ru=null,Er=null,Or=null;function Id(t){if(t=So(t)){if(typeof ru!="function")throw Error(N(280));var e=t.stateNode;e&&(e=ul(e),ru(t.stateNode,t.type,e))}}function ng(t){Er?Or?Or.push(t):Or=[t]:Er=t}function rg(){if(Er){var t=Er,e=Or;if(Or=Er=null,Id(t),e)for(t=0;t>>=0,t===0?32:31-(yv(t)/kv|0)|0}var Fo=64,Lo=4194304;function yi(t){switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return t&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return t}}function zs(t,e){var n=t.pendingLanes;if(n===0)return 0;var r=0,i=t.suspendedLanes,o=t.pingedLanes,s=n&268435455;if(s!==0){var l=s&~i;l!==0?r=yi(l):(o&=s,o!==0&&(r=yi(o)))}else s=n&~i,s!==0?r=yi(s):o!==0&&(r=yi(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,o=e&-e,i>=o||i===16&&(o&4194240)!==0))return e;if(r&4&&(r|=n&16),e=t.entangledLanes,e!==0)for(t=t.entanglements,e&=r;0n;n++)e.push(t);return e}function yo(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-dt(e),t[e]=n}function xv(t,e){var n=t.pendingLanes&~e;t.pendingLanes=e,t.suspendedLanes=0,t.pingedLanes=0,t.expiredLanes&=e,t.mutableReadLanes&=e,t.entangledLanes&=e,e=t.entanglements;var r=t.eventTimes;for(t=t.expirationTimes;0=Ei),jd=String.fromCharCode(32),Hd=!1;function Cg(t,e){switch(t){case"keyup":return Yv.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Ng(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var dr=!1;function Xv(t,e){switch(t){case"compositionend":return Ng(e);case"keypress":return e.which!==32?null:(Hd=!0,jd);case"textInput":return t=e.data,t===jd&&Hd?null:t;default:return null}}function Zv(t,e){if(dr)return t==="compositionend"||!Ac&&Cg(t,e)?(t=vg(),us=Dc=un=null,dr=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:n,offset:e-t};t=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Qd(n)}}function Dg(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?Dg(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function Tg(){for(var t=window,e=Ts();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Ts(t.document)}return e}function Pc(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e&&(e==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||e==="textarea"||t.contentEditable==="true")}function ax(t){var e=Tg(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&Dg(n.ownerDocument.documentElement,n)){if(r!==null&&Pc(n)){if(e=r.start,t=r.end,t===void 0&&(t=e),"selectionStart"in n)n.selectionStart=e,n.selectionEnd=Math.min(t,n.value.length);else if(t=(e=n.ownerDocument||document)&&e.defaultView||window,t.getSelection){t=t.getSelection();var i=n.textContent.length,o=Math.min(r.start,i);r=r.end===void 0?o:Math.min(r.end,i),!t.extend&&o>r&&(i=r,r=o,o=i),i=Yd(n,o);var s=Yd(n,r);i&&s&&(t.rangeCount!==1||t.anchorNode!==i.node||t.anchorOffset!==i.offset||t.focusNode!==s.node||t.focusOffset!==s.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),t.removeAllRanges(),o>r?(t.addRange(e),t.extend(s.node,s.offset)):(e.setEnd(s.node,s.offset),t.addRange(e)))}}for(e=[],t=n;t=t.parentNode;)t.nodeType===1&&e.push({element:t,left:t.scrollLeft,top:t.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,hr=null,uu=null,Di=null,cu=!1;function Gd(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;cu||hr==null||hr!==Ts(r)||(r=hr,"selectionStart"in r&&Pc(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Di&&Yi(Di,r)||(Di=r,r=Fs(uu,"onSelect"),0gr||(t.current=gu[gr],gu[gr]=null,gr--)}function H(t,e){gr++,gu[gr]=t.current,t.current=e}var xn={},Ne=En(xn),Ve=En(!1),Qn=xn;function Vr(t,e){var n=t.type.contextTypes;if(!n)return xn;var r=t.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},o;for(o in n)i[o]=e[o];return r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=e,t.__reactInternalMemoizedMaskedChildContext=i),i}function $e(t){return t=t.childContextTypes,t!=null}function Bs(){K(Ve),K(Ne)}function ih(t,e,n){if(Ne.current!==xn)throw Error(N(168));H(Ne,e),H(Ve,n)}function Bg(t,e,n){var r=t.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(N(108,rv(t)||"Unknown",i));return G({},n,r)}function Vs(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||xn,Qn=Ne.current,H(Ne,t),H(Ve,Ve.current),!0}function oh(t,e,n){var r=t.stateNode;if(!r)throw Error(N(169));n?(t=Bg(t,e,Qn),r.__reactInternalMemoizedMergedChildContext=t,K(Ve),K(Ne),H(Ne,t)):K(Ve),H(Ve,n)}var Ft=null,cl=!1,ca=!1;function Vg(t){Ft===null?Ft=[t]:Ft.push(t)}function wx(t){cl=!0,Vg(t)}function On(){if(!ca&&Ft!==null){ca=!0;var t=0,e=j;try{var n=Ft;for(j=1;t>=s,i-=s,Bt=1<<32-dt(e)+i|n<R?(E=D,D=null):E=D.sibling;var P=d(g,D,k[R],w);if(P===null){D===null&&(D=E);break}t&&D&&P.alternate===null&&e(g,D),y=o(P,y,R),O===null?M=P:O.sibling=P,O=P,D=E}if(R===k.length)return n(g,D),q&&Pn(g,R),M;if(D===null){for(;RR?(E=D,D=null):E=D.sibling;var ne=d(g,D,P.value,w);if(ne===null){D===null&&(D=E);break}t&&D&&ne.alternate===null&&e(g,D),y=o(ne,y,R),O===null?M=ne:O.sibling=ne,O=ne,D=E}if(P.done)return n(g,D),q&&Pn(g,R),M;if(D===null){for(;!P.done;R++,P=k.next())P=f(g,P.value,w),P!==null&&(y=o(P,y,R),O===null?M=P:O.sibling=P,O=P);return q&&Pn(g,R),M}for(D=r(g,D);!P.done;R++,P=k.next())P=p(D,g,R,P.value,w),P!==null&&(t&&P.alternate!==null&&D.delete(P.key===null?R:P.key),y=o(P,y,R),O===null?M=P:O.sibling=P,O=P);return t&&D.forEach(function(Rt){return e(g,Rt)}),q&&Pn(g,R),M}function S(g,y,k,w){if(typeof k=="object"&&k!==null&&k.type===fr&&k.key===null&&(k=k.props.children),typeof k=="object"&&k!==null){switch(k.$$typeof){case zo:e:{for(var M=k.key,O=y;O!==null;){if(O.key===M){if(M=k.type,M===fr){if(O.tag===7){n(g,O.sibling),y=i(O,k.props.children),y.return=g,g=y;break e}}else if(O.elementType===M||typeof M=="object"&&M!==null&&M.$$typeof===Xt&&dh(M)===O.type){n(g,O.sibling),y=i(O,k.props),y.ref=ri(g,O,k),y.return=g,g=y;break e}n(g,O);break}else e(g,O);O=O.sibling}k.type===fr?(y=Jn(k.props.children,g.mode,w,k.key),y.return=g,g=y):(w=ys(k.type,k.key,k.props,null,g.mode,w),w.ref=ri(g,y,k),w.return=g,g=w)}return s(g);case cr:e:{for(O=k.key;y!==null;){if(y.key===O)if(y.tag===4&&y.stateNode.containerInfo===k.containerInfo&&y.stateNode.implementation===k.implementation){n(g,y.sibling),y=i(y,k.children||[]),y.return=g,g=y;break e}else{n(g,y);break}else e(g,y);y=y.sibling}y=ka(k,g.mode,w),y.return=g,g=y}return s(g);case Xt:return O=k._init,S(g,y,O(k._payload),w)}if(gi(k))return h(g,y,k,w);if(Xr(k))return m(g,y,k,w);jo(g,k)}return typeof k=="string"&&k!==""||typeof k=="number"?(k=""+k,y!==null&&y.tag===6?(n(g,y.sibling),y=i(y,k),y.return=g,g=y):(n(g,y),y=ya(k,g.mode,w),y.return=g,g=y),s(g)):n(g,y)}return S}var _r=Kg(!0),qg=Kg(!1),wo={},Nt=En(wo),eo=En(wo),to=En(wo);function $n(t){if(t===wo)throw Error(N(174));return t}function _c(t,e){switch(H(to,e),H(eo,t),H(Nt,wo),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:Za(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=Za(e,t)}K(Nt),H(Nt,e)}function Wr(){K(Nt),K(eo),K(to)}function Qg(t){$n(to.current);var e=$n(Nt.current),n=Za(e,t.type);e!==n&&(H(eo,t),H(Nt,n))}function Wc(t){eo.current===t&&(K(Nt),K(eo))}var Q=En(0);function Hs(t){for(var e=t;e!==null;){if(e.tag===13){var n=e.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break;for(;e.sibling===null;){if(e.return===null||e.return===t)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var fa=[];function Uc(){for(var t=0;tn?n:4,t(!0);var r=da.transition;da.transition={};try{t(!1),e()}finally{j=n,da.transition=r}}function fy(){return ot().memoizedState}function Nx(t,e,n){var r=Sn(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},dy(t))hy(e,n);else if(n=Ug(t,e,n,r),n!==null){var i=Te();ht(n,t,r,i),py(n,e,r)}}function Mx(t,e,n){var r=Sn(t),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(dy(t))hy(e,i);else{var o=t.alternate;if(t.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var s=e.lastRenderedState,l=o(s,n);if(i.hasEagerState=!0,i.eagerState=l,mt(l,s)){var a=e.interleaved;a===null?(i.next=i,Vc(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}n=Ug(t,e,i,r),n!==null&&(i=Te(),ht(n,t,r,i),py(n,e,r))}}function dy(t){var e=t.alternate;return t===Y||e!==null&&e===Y}function hy(t,e){Ti=Js=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function py(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Mc(t,n)}}var Ks={readContext:it,useCallback:ke,useContext:ke,useEffect:ke,useImperativeHandle:ke,useInsertionEffect:ke,useLayoutEffect:ke,useMemo:ke,useReducer:ke,useRef:ke,useState:ke,useDebugValue:ke,useDeferredValue:ke,useTransition:ke,useMutableSource:ke,useSyncExternalStore:ke,useId:ke,unstable_isNewReconciler:!1},Ex={readContext:it,useCallback:function(t,e){return yt().memoizedState=[t,e===void 0?null:e],t},useContext:it,useEffect:ph,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,hs(4194308,4,sy.bind(null,e,t),n)},useLayoutEffect:function(t,e){return hs(4194308,4,t,e)},useInsertionEffect:function(t,e){return hs(4,2,t,e)},useMemo:function(t,e){var n=yt();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=yt();return e=n!==void 0?n(e):e,r.memoizedState=r.baseState=e,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:e},r.queue=t,t=t.dispatch=Nx.bind(null,Y,t),[r.memoizedState,t]},useRef:function(t){var e=yt();return t={current:t},e.memoizedState=t},useState:hh,useDebugValue:qc,useDeferredValue:function(t){return yt().memoizedState=t},useTransition:function(){var t=hh(!1),e=t[0];return t=Cx.bind(null,t[1]),yt().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=Y,i=yt();if(q){if(n===void 0)throw Error(N(407));n=n()}else{if(n=e(),fe===null)throw Error(N(349));Gn&30||Xg(r,e,n)}i.memoizedState=n;var o={value:n,getSnapshot:e};return i.queue=o,ph(ey.bind(null,r,o,t),[t]),r.flags|=2048,io(9,Zg.bind(null,r,o,n,e),void 0,null),n},useId:function(){var t=yt(),e=fe.identifierPrefix;if(q){var n=Vt,r=Bt;n=(r&~(1<<32-dt(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=no++,0<\/script>",t=t.removeChild(t.firstChild)):typeof r.is=="string"?t=s.createElement(n,{is:r.is}):(t=s.createElement(n),n==="select"&&(s=t,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):t=s.createElementNS(t,n),t[kt]=e,t[Zi]=r,Ny(t,e,!1,!1),e.stateNode=t;e:{switch(s=tu(n,r),n){case"dialog":J("cancel",t),J("close",t),i=r;break;case"iframe":case"object":case"embed":J("load",t),i=r;break;case"video":case"audio":for(i=0;ijr&&(e.flags|=128,r=!0,ii(o,!1),e.lanes=4194304)}else{if(!r)if(t=Hs(s),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),ii(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!q)return ke(e),null}else 2*te()-o.renderingStartTime>jr&&n!==1073741824&&(e.flags|=128,r=!0,ii(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(n=o.last,n!==null?n.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=te(),e.sibling=null,n=Q.current,H(Q,r?n&1|2:n&1),e):(ke(e),null);case 22:case 23:return ef(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ue&1073741824&&(ke(e),e.subtreeFlags&6&&(e.flags|=8192)):ke(e),null;case 24:return null;case 25:return null}throw Error(N(156,e.tag))}function zx(t,e){switch(Ic(e),e.tag){case 1:return $e(e.type)&&Bs(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Wr(),K(Ve),K(Ne),Uc(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Wc(e),null;case 13:if(K(Q),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(N(340));$r()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return K(Q),null;case 4:return Wr(),null;case 10:return Bc(e.type._context),null;case 22:case 23:return ef(),null;case 24:return null;default:return null}}var Jo=!1,ve=!1,Ix=typeof WeakSet=="function"?WeakSet:Set,T=null;function wr(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){X(t,e,r)}else n.current=null}function Du(t,e,n){try{n()}catch(r){X(t,e,r)}}var Ch=!1;function bx(t,e){if(fu=Is,t=Rg(),Pc(t)){if("selectionStart"in t)var n={start:t.selectionStart,end:t.selectionEnd};else e:{n=(n=t.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=t,d=null;t:for(;;){for(var p;f!==n||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===t)break t;if(d===n&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}n=l===-1||a===-1?null:{start:l,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(du={focusedElem:t,selectionRange:n},Is=!1,T=e;T!==null;)if(e=T,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,T=t;else for(;T!==null;){e=T;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,k=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:at(e.type,m),k);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(N(163))}}catch(w){X(e,e.return,w)}if(t=e.sibling,t!==null){t.return=e.return,T=t;break}T=e.return}return h=Ch,Ch=!1,h}function Ri(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&t)===t){var o=i.destroy;i.destroy=void 0,o!==void 0&&Du(e,n,o)}i=i.next}while(i!==r)}}function hl(t,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var n=e=e.next;do{if((n.tag&t)===t){var r=n.create;n.destroy=r()}n=n.next}while(n!==e)}}function Tu(t){var e=t.ref;if(e!==null){var n=t.stateNode;switch(t.tag){case 5:t=n;break;default:t=n}typeof e=="function"?e(t):e.current=t}}function Oy(t){var e=t.alternate;e!==null&&(t.alternate=null,Oy(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[kt],delete e[Zi],delete e[mu],delete e[yx],delete e[Sx])),t.stateNode=null,t.return=null,t.dependencies=null,t.memoizedProps=null,t.memoizedState=null,t.pendingProps=null,t.stateNode=null,t.updateQueue=null}function Dy(t){return t.tag===5||t.tag===3||t.tag===4}function Nh(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Dy(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function Ru(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.nodeType===8?n.parentNode.insertBefore(t,e):n.insertBefore(t,e):(n.nodeType===8?(e=n.parentNode,e.insertBefore(t,n)):(e=n,e.appendChild(t)),n=n._reactRootContainer,n!=null||e.onclick!==null||(e.onclick=Ls));else if(r!==4&&(t=t.child,t!==null))for(Ru(t,e,n),t=t.sibling;t!==null;)Ru(t,e,n),t=t.sibling}function Au(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.insertBefore(t,e):n.appendChild(t);else if(r!==4&&(t=t.child,t!==null))for(Au(t,e,n),t=t.sibling;t!==null;)Au(t,e,n),t=t.sibling}var he=null,ut=!1;function Qt(t,e,n){for(n=n.child;n!==null;)Ty(t,e,n),n=n.sibling}function Ty(t,e,n){if(Ct&&typeof Ct.onCommitFiberUnmount=="function")try{Ct.onCommitFiberUnmount(ol,n)}catch{}switch(n.tag){case 5:ve||wr(n,e);case 6:var r=he,i=ut;he=null,Qt(t,e,n),he=r,ut=i,he!==null&&(ut?(t=he,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):he.removeChild(n.stateNode));break;case 18:he!==null&&(ut?(t=he,n=n.stateNode,t.nodeType===8?ua(t.parentNode,n):t.nodeType===1&&ua(t,n),qi(t)):ua(he,n.stateNode));break;case 4:r=he,i=ut,he=n.stateNode.containerInfo,ut=!0,Qt(t,e,n),he=r,ut=i;break;case 0:case 11:case 14:case 15:if(!ve&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Du(n,e,s),i=i.next}while(i!==r)}Qt(t,e,n);break;case 1:if(!ve&&(wr(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){X(n,e,l)}Qt(t,e,n);break;case 21:Qt(t,e,n);break;case 22:n.mode&1?(ve=(r=ve)||n.memoizedState!==null,Qt(t,e,n),ve=r):Qt(t,e,n);break;default:Qt(t,e,n)}}function Mh(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Ix),e.forEach(function(r){var i=jx.bind(null,t,r);n.has(r)||(n.add(r),r.then(i,i))})}}function lt(t,e){var n=e.deletions;if(n!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=te()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Lx(r/1960))-r,10t?16:t,cn===null)var r=!1;else{if(t=cn,cn=null,Ys=0,$&6)throw Error(N(331));var i=$;for($|=4,T=t.current;T!==null;){var o=T,s=o.child;if(T.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ate()-Xc?Hn(t,0):Gc|=n),_e(t,e)}function Ly(t,e){e===0&&(t.mode&1?(e=Lo,Lo<<=1,!(Lo&130023424)&&(Lo=4194304)):e=1);var n=Te();t=Jt(t,e),t!==null&&(yo(t,e,n),_e(t,n))}function Ux(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),Ly(t,n)}function jx(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,i=t.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(N(314))}r!==null&&r.delete(e),Ly(t,n)}var By;By=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Ve.current)Le=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Le=!1,Ax(t,e,n);Le=!!(t.flags&131072)}else Le=!1,q&&e.flags&1048576&&_g(e,_s,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ps(t,e),t=e.pendingProps;var i=Vr(e,Ne.current);Tr(e,n),i=Hc(null,e,r,t,i,n);var o=Jc();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,$e(r)?(o=!0,Vs(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,$c(e),i.updater=fl,e.stateNode=i,i._reactInternals=e,vu(e,r,t,n),e=Nu(null,e,r,!0,o,n)):(e.tag=0,q&&o&&zc(e),Ee(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(ps(t,e),t=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=Jx(r),t=at(r,t),i){case 0:e=Cu(null,e,r,t,n);break e;case 1:e=wh(null,e,r,t,n);break e;case 11:e=Sh(null,e,r,t,n);break e;case 14:e=kh(null,e,r,at(r.type,t),n);break e}throw Error(N(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),Cu(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),wh(t,e,r,i,n);case 3:e:{if(vy(e),t===null)throw Error(N(387));r=e.pendingProps,o=e.memoizedState,i=o.element,Hg(t,e),js(e,r,null,n);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=Ur(Error(N(423)),e),e=vh(t,e,r,n,i);break e}else if(r!==i){i=Ur(Error(N(424)),e),e=vh(t,e,r,n,i);break e}else for(He=gn(e.stateNode.containerInfo.firstChild),Ke=e,q=!0,ft=null,n=Qg(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if($r(),r===i){e=Kt(t,e,n);break e}Ee(t,e,r,n)}e=e.child}return e;case 5:return Yg(e),t===null&&Su(e),r=e.type,i=e.pendingProps,o=t!==null?t.memoizedProps:null,s=i.children,hu(r,i)?s=null:o!==null&&hu(r,o)&&(e.flags|=32),wy(t,e),Ee(t,e,s,n),e.child;case 6:return t===null&&Su(e),null;case 13:return xy(t,e,n);case 4:return _c(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=_r(e,null,r,n):Ee(t,e,r,n),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),Sh(t,e,r,i,n);case 7:return Ee(t,e,e.pendingProps,n),e.child;case 8:return Ee(t,e,e.pendingProps.children,n),e.child;case 12:return Ee(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H(Ws,r._currentValue),r._currentValue=s,o!==null)if(mt(o.value,s)){if(o.children===i.children&&!Ve.current){e=Kt(t,e,n);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=_t(-1,n&-n),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),ku(o.return,n,e),l.lanes|=n;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(N(341));s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),ku(s,n,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Ee(t,e,i.children,n),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,Tr(e,n),i=it(i),r=r(i),e.flags|=1,Ee(t,e,r,n),e.child;case 14:return r=e.type,i=at(r,e.pendingProps),i=at(r.type,i),kh(t,e,r,i,n);case 15:return Sy(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),ps(t,e),e.tag=1,$e(r)?(t=!0,Vs(e)):t=!1,Tr(e,n),Kg(e,r,i),vu(e,r,i,n),Nu(null,e,r,!0,t,n);case 19:return Cy(t,e,n);case 22:return ky(t,e,n)}throw Error(N(156,e.tag))};function Vy(t,e){return fg(t,e)}function Hx(t,e,n,r){this.tag=t,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function tt(t,e,n,r){return new Hx(t,e,n,r)}function nf(t){return t=t.prototype,!(!t||!t.isReactComponent)}function Jx(t){if(typeof t=="function")return nf(t)?1:0;if(t!=null){if(t=t.$$typeof,t===vc)return 11;if(t===xc)return 14}return 2}function wn(t,e){var n=t.alternate;return n===null?(n=tt(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function ys(t,e,n,r,i,o){var s=2;if(r=t,typeof t=="function")nf(t)&&(s=1);else if(typeof t=="string")s=5;else e:switch(t){case fr:return Jn(n.children,i,o,e);case wc:s=8,i|=8;break;case Ha:return t=tt(12,n,e,i|2),t.elementType=Ha,t.lanes=o,t;case Ja:return t=tt(13,n,e,i),t.elementType=Ja,t.lanes=o,t;case Ka:return t=tt(19,n,e,i),t.elementType=Ka,t.lanes=o,t;case qm:return ml(n,i,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case Jm:s=10;break e;case Km:s=9;break e;case vc:s=11;break e;case xc:s=14;break e;case Xt:s=16,r=null;break e}throw Error(N(130,t==null?t:typeof t,""))}return e=tt(s,n,e,i),e.elementType=t,e.type=r,e.lanes=o,e}function Jn(t,e,n,r){return t=tt(7,t,r,e),t.lanes=n,t}function ml(t,e,n,r){return t=tt(22,t,r,e),t.elementType=qm,t.lanes=n,t.stateNode={isHidden:!1},t}function ya(t,e,n){return t=tt(6,t,null,e),t.lanes=n,t}function Sa(t,e,n){return e=tt(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function Kx(t,e,n,r,i){this.tag=e,this.containerInfo=t,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Xl(0),this.expirationTimes=Xl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Xl(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function rf(t,e,n,r,i,o,s,l,a){return t=new Kx(t,e,n,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=tt(3,null,null,e),t.current=o,o.stateNode=t,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},$c(o),t}function qx(t,e,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Uy)}catch(t){console.error(t)}}Uy(),_m.exports=Qe;var Hr=_m.exports,jy,zh=Hr;jy=zh.createRoot,zh.hydrateRoot;const vo=C.createContext(null),Hy=C.createContext(null);function Zx(t){const e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(const r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[me.node(0,t.state.doc.content.size,e)]}const eC=[],tC={},Fu=U.empty;class bn{constructor(e){this.members=e}map(e,n){const r=this.members.map(i=>i.map(e,n,tC));return bn.from(r)}forChild(e,n){if(n.isLeaf)return U.empty;let r=[];for(let i=0;in instanceof U)?e:e.reduce((n,r)=>n.concat(r instanceof U?r:r.members),[]))}}}function Jy(t,e){return t.from-e.from||t.to-e.to}function nC(t){let e=t;for(let n=0;n0;)e++;t.splice(e,0,n)}function rC(t,e){const n=[];return t.someProp("decorations",r=>{const i=r(t.state);i&&i!=Fu&&n.push(i)}),e&&n.push(U.create(t.state.doc,[e])),bn.from(n)}const af=function(t){for(let e=0;;e++)if(t=t.previousSibling,!t)return e},bh=function(t){const e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},iC=function(t,e,n,r){return n&&(Fh(t,e,n,r,-1)||Fh(t,e,n,r,1))},oC=/^(img|br|input|textarea|hr)$/i;function Fh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Zs(t))){const o=t.parentNode;if(!o||o.nodeType!=1||lC(t)||oC.test(t.nodeName)||t.contentEditable=="false")return!1;e=af(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?Zs(t):0}else return!1}}function Zs(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function sC(t,e,n){for(let r=e==0,i=e==Zs(t);r||i;){if(t==n)return!0;const o=af(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==Zs(t)}return!1}function lC(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Ky=function(t){return t.focusNode&&iC(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)},qy=C.createContext(null);function aC(t,e){const n=C.useContext(qy);C.useLayoutEffect(()=>n(t),e)}function Qy(t,e){const{view:n}=C.useContext(vo);aC(()=>{if(n)return t(n)},e&&[n,...e])}const uC=C.forwardRef(function({widget:e,pos:n,...r},i){const[o,s]=C.useState(!0),l=C.useRef(null);return C.useImperativeHandle(i,()=>l.current,[]),Qy(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,af(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?z("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function cC(t,e){if(t==e)return!0;for(const n in t)if(t[n]!==e[n])return!1;for(const n in e)if(!(n in t))return!1;return!0}const fC={side:0};class so{constructor(e,n){this.Component=e,this.spec=n??fC,this.side=this.spec.side??0}map(e,n,r,i){const{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new me(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof so&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&cC(this.spec,e.spec))}destroy(){}}function Yy(t,e,n){return new me(t,t,new so(e,n))}function ka(){return Math.floor(Math.random()*16777215).toString(16)}const lo=new ho("@nytimes/react-prosemirror/reactKeys");function dC(){let t=!1;return new Tt({key:lo,state:{init(e,n){const r={posToKey:new Map,keyToPos:new Map};return n.doc.descendants((i,o)=>{const s=ka();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,n,r,i){if(!e.docChanged||t)return n;const o=e.getMeta(lo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(n.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=ka()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=ka();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{t=!0},compositionend:()=>{t=!1}}}})}function wa(t,e,n={}){var s;if(e===null)return!1;const r=n.from??t.state.selection.from,i=n.to??t.state.selection.to;if(t.someProp("handleTextInput",l=>l(t,r,i,e)))return!0;const{tr:o}=t.state;if(n.marks&&o.ensureMarks(n.marks),o.insertText(e,r,i),n.bust){const l=t.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=lo.getState(t.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(lo,{type:"bustKey",payload:{key:c}})}return t.dispatch(o),!0}function hC(t){let e=null,n=null;return new Tt({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&t(Yy(i.selection.from,uC,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),n=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return wa(r,e,{bust:!0,marks:n}),e=null,n=null,t(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);wa(r,a,{from:c,to:f})}});break}case"insertText":{wa(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Dt=typeof navigator<"u"?navigator:null,Lh=typeof document<"u"?document:null,Dn=Dt&&Dt.userAgent||"",Lu=/Edge\/(\d+)/.exec(Dn),Gy=/MSIE \d/.exec(Dn),Bu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Dn),wl=!!(Gy||Bu||Lu),pC=Gy?document.documentMode:Bu?+Bu[1]:Lu?+Lu[1]:0,Xy=!wl&&/gecko\/(\d+)/i.test(Dn),mC=Xy&&+(/Firefox\/(\d+)/.exec(Dn)||[0,0])[1],Vu=!wl&&/Chrome\/(\d+)/.exec(Dn),gC=!!Vu,yC=Vu?+Vu[1]:0,Zy=!wl&&!!Dt&&/Apple Computer/.test(Dt.vendor),e0=Zy&&(/Mobile\/\w+/.test(Dn)||!!Dt&&Dt.maxTouchPoints>2),SC=e0||(Dt?/Mac/.test(Dt.platform):!1),kC=Dt?/Win/.test(Dt.platform):!1,wC=/Android \d/.test(Dn),t0=!!Lh&&"webkitFontSmoothing"in Lh.documentElement.style,vC=t0?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ce={ie:wl,ie_version:pC,gecko:Xy,gecko_version:mC,chrome:gC,chrome_version:yC,safari:Zy,ios:e0,mac:SC,windows:kC,android:wC,webkit:t0,webkit_version:vC};function Bh(t){return t.editable&&!t.hasFocus()?!1:xC(t)}function xC(t){var n,r;const e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(((n=e.focusNode)==null?void 0:n.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function CC(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function Vh(t,e=null){const n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode);const o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;const l=r.resolve(s);let a,u;if(Ky(n)){for(a=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&I.isSelectable(c)&&i.parent&&!(c.isInline&&sC(n.focusNode,n.focusOffset,i.dom))){const f=i.posBefore;u=new I(s==f?l:r.resolve(f))}}else{const c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){const c=e=="pointer"||t.state.selection.head{(r.anchorNode!=i||r.anchorOffset!=o)&&(n.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!n0(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const Hh=Ce.safari||Ce.chrome&&Ce.chrome_version<63;function Qo(t,e=!1){const n=t,r=n.state.selection;if(EC(n,r),!!n0(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Ce.chrome){const i=n.domSelectionRange(),o=n.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&el(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)DC(n);else{const{anchor:i,head:o}=r;let s,l;Hh&&!(r instanceof B)&&(r.$from.parent.inlineContent||(s=Uh(n,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=Uh(n,r.to))),n.docView.setSelection(i,o,n.root,e),Hh&&(s&&jh(s),l&&jh(l)),r.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&TC(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}class RC{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 AC{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new RC,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const n=new Set;let r;for(let o=e.focusNode;o;o=bh(o))n.add(o);for(let o=e.anchorNode;o;o=bh(o))if(n.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,n=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=Vh(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),n&&o.setMeta("composition",n),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Qo(e);const n=e.domSelectionRange();this.currentSelection.set(n)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Bh(e)&&!this.ignoreSelectionChange(n);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(Bh(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Qo(this.view);if(Ce.ie&&Ce.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&el(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const Jr=0,Jh=1,Yo=2,ao=3;class xo{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Jr,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nen(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof ff){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof uf&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?en(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=en(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;ch&&sn){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&n<=a){this.dirty=e==r||n==s?Yo:Jh,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=ao:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Yo:ao}r=s}this.dirty=Yo}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){const r=e==1?Yo:Jh;n.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){const r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,n,r){return this.dirty==Jr&&e.eq(this.node)&&bC(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,n,r,i){return!0}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}class IC extends cf{constructor(e,n,r,i,o,s,l){super(e,n,r,i,o,s,null,l)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=ao)}get domAtom(){return!1}}class ff extends xo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Jr&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function bC(t,e){if(t.length!=e.length)return!1;for(let n=0;n{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new Tt({key:new ho("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function LC(){const[t,e]=C.useState(new Map),n=C.useCallback((o,s)=>{const l=t.get(o)??[];l.unshift(s),t.has(o)||(t.set(o,l),e(new Map(t)))},[t]),r=C.useCallback((o,s)=>{const l=t.get(o);l==null||l.splice(l.indexOf(s),1)},[t]),i=C.useMemo(()=>FC(t),[t]);return{registerEventListener:n,unregisterEventListener:r,componentEventListenersPlugin:i}}function r0(){const[,t]=C.useReducer(e=>e+1,0);return t}class BC extends Dk{constructor(e,n){super(e,{state:on.create({schema:n.state.schema,plugins:n.state.plugins}),plugins:n.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=n,this.oldProps={state:n.state},this.state=n.state,this.domObserver.stop(),this.domObserver=new AC(this),this.domObserver.start(),this.docView.dom.replaceChildren(),this.docView=n.docView}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state}runPendingEffects(){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}update(e){super.update(e),this.oldProps=e}updatePluginViews(){this.shouldUpdatePluginViews&&super.updatePluginViews()}}const VC=new Sp({nodes:{doc:{content:"text*"},text:{inline:!0}}}),$C=on.create({schema:VC});function _C(t,e){const[n,r]=C.useState(null),[i,o]=C.useState(null),s=r0(),l=e.defaultState??$C,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=LC(),h=C.useCallback(w=>{Hr.flushSync(()=>{o(w)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,hC(h)],[e.plugins,f,h]);function k(w){Hr.flushSync(()=>{e.state||u(M=>M.apply(w)),e.dispatchTransaction&&e.dispatchTransaction.call(this,w)})}const g=document.createElement("div"),y=C.useRef(new cf(void 0,[],c.doc,[],U.empty,g,null,g)),S={...e,state:c,plugins:m,dispatchTransaction:k,docView:y.current};return C.useLayoutEffect(()=>{if(n&&n.dom!==t&&r(null),!!t&&!n){const w=new BC({mount:t},S);r(w),w.dom.addEventListener("compositionend",s);return}}),n==null||n.pureSetProps(S),C.useMemo(()=>({view:n,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[n,c,d,p,i])}function WC(t){C.useLayoutEffect(()=>{t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()},[t,t==null?void 0:t.props])}function UC({children:t}){const e=C.useRef(new Set).current,n=C.useRef(new Set).current,r=C.useRef(!1),i=r0(),o=C.useRef(!0),s=C.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=C.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(n.add(u),s()):u())}},[e,n,s]);return C.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{n.forEach(a=>a()),n.clear()})),C.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),z(qy.Provider,{value:l,children:t})}const st=C.createContext([]);function i0(t,e,n,r,i,o,s){const l=C.useRef(o),a=C.useContext(st),u=[];return C.useLayoutEffect(()=>{if(!t||!n.current)return;const c=u[0];l.current?(l.current.parent=void 0,l.current.children=u,l.current.node=t,l.current.outerDeco=i,l.current.innerDeco=r,l.current.dom=(e==null?void 0:e.current)??n.current,l.current.dom.pmViewDesc=l.current,l.current.contentDOM=(s==null?void 0:s.current)??l.current.contentDOM??(c==null?void 0:c.dom.parentElement)??null,l.current.nodeDOM=n.current):l.current=new cf(void 0,u,t,i,r,(e==null?void 0:e.current)??n.current,(c==null?void 0:c.dom.parentElement)??null,n.current),a.push(l.current);for(const f of u)f.parent=l.current}),u}var o0={exports:{}};/*! +`+o.stack}return{value:t,source:e,stack:i,digest:null}}function ma(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function xu(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var Tx=typeof WeakMap=="function"?WeakMap:Map;function my(t,e,n){n=_t(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){Qs||(Qs=!0,Pu=r),xu(t,e)},n}function gy(t,e,n){n=_t(-1,n),n.tag=3;var r=t.type.getDerivedStateFromError;if(typeof r=="function"){var i=e.value;n.payload=function(){return r(i)},n.callback=function(){xu(t,e)}}var o=t.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){xu(t,e),typeof r!="function"&&(kn===null?kn=new Set([this]):kn.add(this));var s=e.stack;this.componentDidCatch(e.value,{componentStack:s!==null?s:""})}),n}function mh(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new Tx;var i=new Set;r.set(e,i)}else i=r.get(e),i===void 0&&(i=new Set,r.set(e,i));i.has(n)||(i.add(n),t=Ux.bind(null,t,e,n),e.then(t,t))}function gh(t){do{var e;if((e=t.tag===13)&&(e=t.memoizedState,e=e!==null?e.dehydrated!==null:!0),e)return t;t=t.return}while(t!==null);return null}function yh(t,e,n,r,i){return t.mode&1?(t.flags|=65536,t.lanes=i,t):(t===e?t.flags|=65536:(t.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(e=_t(-1,1),e.tag=2,yn(n,e,1))),n.lanes|=1),t)}var Rx=qt.ReactCurrentOwner,Le=!1;function Ee(t,e,n,r){e.child=t===null?qg(e,null,n,r):_r(e,t.child,n,r)}function kh(t,e,n,r,i){n=n.render;var o=e.ref;return Tr(e,i),r=Hc(t,e,n,r,o,i),n=Jc(),t!==null&&!Le?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~i,Kt(t,e,i)):(q&&n&&zc(e),e.flags|=1,Ee(t,e,r,i),e.child)}function Sh(t,e,n,r,i){if(t===null){var o=n.type;return typeof o=="function"&&!nf(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=o,yy(t,e,o,r,i)):(t=ys(n.type,null,r,e,e.mode,i),t.ref=e.ref,t.return=e,e.child=t)}if(o=t.child,!(t.lanes&i)){var s=o.memoizedProps;if(n=n.compare,n=n!==null?n:Yi,n(s,r)&&t.ref===e.ref)return Kt(t,e,i)}return e.flags|=1,t=wn(o,r),t.ref=e.ref,t.return=e,e.child=t}function yy(t,e,n,r,i){if(t!==null){var o=t.memoizedProps;if(Yi(o,r)&&t.ref===e.ref)if(Le=!1,e.pendingProps=r=o,(t.lanes&i)!==0)t.flags&131072&&(Le=!0);else return e.lanes=t.lanes,Kt(t,e,i)}return Cu(t,e,n,r,i)}function ky(t,e,n){var r=e.pendingProps,i=r.children,o=t!==null?t.memoizedState:null;if(r.mode==="hidden")if(!(e.mode&1))e.memoizedState={baseLanes:0,cachePool:null,transitions:null},H(vr,Ue),Ue|=n;else{if(!(n&1073741824))return t=o!==null?o.baseLanes|n:n,e.lanes=e.childLanes=1073741824,e.memoizedState={baseLanes:t,cachePool:null,transitions:null},e.updateQueue=null,H(vr,Ue),Ue|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,H(vr,Ue),Ue|=r}else o!==null?(r=o.baseLanes|n,e.memoizedState=null):r=n,H(vr,Ue),Ue|=r;return Ee(t,e,i,n),e.child}function Sy(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function Cu(t,e,n,r,i){var o=$e(n)?Qn:Ne.current;return o=Vr(e,o),Tr(e,i),n=Hc(t,e,n,r,o,i),r=Jc(),t!==null&&!Le?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~i,Kt(t,e,i)):(q&&r&&zc(e),e.flags|=1,Ee(t,e,n,i),e.child)}function wh(t,e,n,r,i){if($e(n)){var o=!0;Vs(e)}else o=!1;if(Tr(e,i),e.stateNode===null)ps(t,e),Jg(e,n,r),vu(e,n,r,i),r=!0;else if(t===null){var s=e.stateNode,l=e.memoizedProps;s.props=l;var a=s.context,u=n.contextType;typeof u=="object"&&u!==null?u=it(u):(u=$e(n)?Qn:Ne.current,u=Vr(e,u));var c=n.getDerivedStateFromProps,f=typeof c=="function"||typeof s.getSnapshotBeforeUpdate=="function";f||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==r||a!==u)&&fh(e,s,r,u),Zt=!1;var d=e.memoizedState;s.state=d,js(e,r,s,i),a=e.memoizedState,l!==r||d!==a||Ve.current||Zt?(typeof c=="function"&&(wu(e,n,c,r),a=e.memoizedState),(l=Zt||ch(e,n,l,r,d,a,u))?(f||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(e.flags|=4194308)):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),e.memoizedProps=r,e.memoizedState=a),s.props=r,s.state=a,s.context=u,r=l):(typeof s.componentDidMount=="function"&&(e.flags|=4194308),r=!1)}else{s=e.stateNode,jg(t,e),l=e.memoizedProps,u=e.type===e.elementType?l:at(e.type,l),s.props=u,f=e.pendingProps,d=s.context,a=n.contextType,typeof a=="object"&&a!==null?a=it(a):(a=$e(n)?Qn:Ne.current,a=Vr(e,a));var p=n.getDerivedStateFromProps;(c=typeof p=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(l!==f||d!==a)&&fh(e,s,r,a),Zt=!1,d=e.memoizedState,s.state=d,js(e,r,s,i);var h=e.memoizedState;l!==f||d!==h||Ve.current||Zt?(typeof p=="function"&&(wu(e,n,p,r),h=e.memoizedState),(u=Zt||ch(e,n,u,r,d,h,a)||!1)?(c||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,h,a),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,h,a)),typeof s.componentDidUpdate=="function"&&(e.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(e.flags|=1024)):(typeof s.componentDidUpdate!="function"||l===t.memoizedProps&&d===t.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===t.memoizedProps&&d===t.memoizedState||(e.flags|=1024),e.memoizedProps=r,e.memoizedState=h),s.props=r,s.state=h,s.context=a,r=u):(typeof s.componentDidUpdate!="function"||l===t.memoizedProps&&d===t.memoizedState||(e.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||l===t.memoizedProps&&d===t.memoizedState||(e.flags|=1024),r=!1)}return Nu(t,e,n,r,o,i)}function Nu(t,e,n,r,i,o){Sy(t,e);var s=(e.flags&128)!==0;if(!r&&!s)return i&&oh(e,n,!1),Kt(t,e,o);r=e.stateNode,Rx.current=e;var l=s&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&s?(e.child=_r(e,t.child,null,o),e.child=_r(e,null,l,o)):Ee(t,e,l,o),e.memoizedState=r.state,i&&oh(e,n,!0),e.child}function wy(t){var e=t.stateNode;e.pendingContext?ih(t,e.pendingContext,e.pendingContext!==e.context):e.context&&ih(t,e.context,!1),_c(t,e.containerInfo)}function vh(t,e,n,r,i){return $r(),Ic(i),e.flags|=256,Ee(t,e,n,r),e.child}var Mu={dehydrated:null,treeContext:null,retryLane:0};function Eu(t){return{baseLanes:t,cachePool:null,transitions:null}}function vy(t,e,n){var r=e.pendingProps,i=Q.current,o=!1,s=(e.flags&128)!==0,l;if((l=s)||(l=t!==null&&t.memoizedState===null?!1:(i&2)!==0),l?(o=!0,e.flags&=-129):(t===null||t.memoizedState!==null)&&(i|=1),H(Q,i&1),t===null)return ku(e),t=e.memoizedState,t!==null&&(t=t.dehydrated,t!==null)?(e.mode&1?t.data==="$!"?e.lanes=8:e.lanes=1073741824:e.lanes=1,null):(s=r.children,t=r.fallback,o?(r=e.mode,o=e.child,s={mode:"hidden",children:s},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=s):o=ml(s,r,0,null),t=Jn(t,r,n,null),o.return=e,t.return=e,o.sibling=t,e.child=o,e.child.memoizedState=Eu(n),e.memoizedState=Mu,t):Qc(e,s));if(i=t.memoizedState,i!==null&&(l=i.dehydrated,l!==null))return Ax(t,e,s,r,l,i,n);if(o){o=r.fallback,s=e.mode,i=t.child,l=i.sibling;var a={mode:"hidden",children:r.children};return!(s&1)&&e.child!==i?(r=e.child,r.childLanes=0,r.pendingProps=a,e.deletions=null):(r=wn(i,a),r.subtreeFlags=i.subtreeFlags&14680064),l!==null?o=wn(l,o):(o=Jn(o,s,n,null),o.flags|=2),o.return=e,r.return=e,r.sibling=o,e.child=r,r=o,o=e.child,s=t.child.memoizedState,s=s===null?Eu(n):{baseLanes:s.baseLanes|n,cachePool:null,transitions:s.transitions},o.memoizedState=s,o.childLanes=t.childLanes&~n,e.memoizedState=Mu,r}return o=t.child,t=o.sibling,r=wn(o,{mode:"visible",children:r.children}),!(e.mode&1)&&(r.lanes=n),r.return=e,r.sibling=null,t!==null&&(n=e.deletions,n===null?(e.deletions=[t],e.flags|=16):n.push(t)),e.child=r,e.memoizedState=null,r}function Qc(t,e){return e=ml({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Ho(t,e,n,r){return r!==null&&Ic(r),_r(e,t.child,null,n),t=Qc(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function Ax(t,e,n,r,i,o,s){if(n)return e.flags&256?(e.flags&=-257,r=ma(Error(N(422))),Ho(t,e,s,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(o=r.fallback,i=e.mode,r=ml({mode:"visible",children:r.children},i,0,null),o=Jn(o,i,s,null),o.flags|=2,r.return=e,o.return=e,r.sibling=o,e.child=r,e.mode&1&&_r(e,t.child,null,s),e.child.memoizedState=Eu(s),e.memoizedState=Mu,o);if(!(e.mode&1))return Ho(t,e,s,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var l=r.dgst;return r=l,o=Error(N(419)),r=ma(o,r,void 0),Ho(t,e,s,r)}if(l=(s&t.childLanes)!==0,Le||l){if(r=fe,r!==null){switch(s&-s){case 4:i=2;break;case 16:i=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|s)?0:i,i!==0&&i!==o.retryLane&&(o.retryLane=i,Jt(t,i),ht(r,t,i,-1))}return tf(),r=ma(Error(N(421))),Ho(t,e,s,r)}return i.data==="$?"?(e.flags|=128,e.child=t.child,e=jx.bind(null,t),i._reactRetry=e,null):(t=o.treeContext,He=gn(i.nextSibling),Ke=e,q=!0,ft=null,t!==null&&(Xe[Ze++]=Bt,Xe[Ze++]=Vt,Xe[Ze++]=Yn,Bt=t.id,Vt=t.overflow,Yn=e),e=Qc(e,r.children),e.flags|=4096,e)}function xh(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),Su(t.return,e,n)}function ga(t,e,n,r,i){var o=t.memoizedState;o===null?t.memoizedState={isBackwards:e,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(o.isBackwards=e,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=i)}function xy(t,e,n){var r=e.pendingProps,i=r.revealOrder,o=r.tail;if(Ee(t,e,r.children,n),r=Q.current,r&2)r=r&1|2,e.flags|=128;else{if(t!==null&&t.flags&128)e:for(t=e.child;t!==null;){if(t.tag===13)t.memoizedState!==null&&xh(t,n,e);else if(t.tag===19)xh(t,n,e);else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break e;for(;t.sibling===null;){if(t.return===null||t.return===e)break e;t=t.return}t.sibling.return=t.return,t=t.sibling}r&=1}if(H(Q,r),!(e.mode&1))e.memoizedState=null;else switch(i){case"forwards":for(n=e.child,i=null;n!==null;)t=n.alternate,t!==null&&Hs(t)===null&&(i=n),n=n.sibling;n=i,n===null?(i=e.child,e.child=null):(i=n.sibling,n.sibling=null),ga(e,!1,i,n,o);break;case"backwards":for(n=null,i=e.child,e.child=null;i!==null;){if(t=i.alternate,t!==null&&Hs(t)===null){e.child=i;break}t=i.sibling,i.sibling=n,n=i,i=t}ga(e,!0,n,null,o);break;case"together":ga(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function ps(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function Kt(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),Xn|=e.lanes,!(n&e.childLanes))return null;if(t!==null&&e.child!==t.child)throw Error(N(153));if(e.child!==null){for(t=e.child,n=wn(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=wn(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function Px(t,e,n){switch(e.tag){case 3:wy(e),$r();break;case 5:Qg(e);break;case 1:$e(e.type)&&Vs(e);break;case 4:_c(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,i=e.memoizedProps.value;H(Ws,r._currentValue),r._currentValue=i;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(H(Q,Q.current&1),e.flags|=128,null):n&e.child.childLanes?vy(t,e,n):(H(Q,Q.current&1),t=Kt(t,e,n),t!==null?t.sibling:null);H(Q,Q.current&1);break;case 19:if(r=(n&e.childLanes)!==0,t.flags&128){if(r)return xy(t,e,n);e.flags|=128}if(i=e.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),H(Q,Q.current),r)break;return null;case 22:case 23:return e.lanes=0,ky(t,e,n)}return Kt(t,e,n)}var Cy,Ou,Ny,My;Cy=function(t,e){for(var n=e.child;n!==null;){if(n.tag===5||n.tag===6)t.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Ou=function(){};Ny=function(t,e,n,r){var i=t.memoizedProps;if(i!==r){t=e.stateNode,$n(Nt.current);var o=null;switch(n){case"input":i=Qa(t,i),r=Qa(t,r),o=[];break;case"select":i=G({},i,{value:void 0}),r=G({},r,{value:void 0}),o=[];break;case"textarea":i=Xa(t,i),r=Xa(t,r),o=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Ls)}eu(n,r);var s;n=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var l=i[u];for(s in l)l.hasOwnProperty(s)&&(n||(n={}),n[s]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Ui.hasOwnProperty(u)?o||(o=[]):(o=o||[]).push(u,null));for(u in r){var a=r[u];if(l=i!=null?i[u]:void 0,r.hasOwnProperty(u)&&a!==l&&(a!=null||l!=null))if(u==="style")if(l){for(s in l)!l.hasOwnProperty(s)||a&&a.hasOwnProperty(s)||(n||(n={}),n[s]="");for(s in a)a.hasOwnProperty(s)&&l[s]!==a[s]&&(n||(n={}),n[s]=a[s])}else n||(o||(o=[]),o.push(u,n)),n=a;else u==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,l=l?l.__html:void 0,a!=null&&l!==a&&(o=o||[]).push(u,a)):u==="children"?typeof a!="string"&&typeof a!="number"||(o=o||[]).push(u,""+a):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Ui.hasOwnProperty(u)?(a!=null&&u==="onScroll"&&J("scroll",t),o||l===a||(o=[])):(o=o||[]).push(u,a))}n&&(o=o||[]).push("style",n);var u=o;(e.updateQueue=u)&&(e.flags|=4)}};My=function(t,e,n,r){n!==r&&(e.flags|=4)};function ii(t,e){if(!q)switch(t.tailMode){case"hidden":e=t.tail;for(var n=null;e!==null;)e.alternate!==null&&(n=e),e=e.sibling;n===null?t.tail=null:n.sibling=null;break;case"collapsed":n=t.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?e||t.tail===null?t.tail=null:t.tail.sibling=null:r.sibling=null}}function Se(t){var e=t.alternate!==null&&t.alternate.child===t.child,n=0,r=0;if(e)for(var i=t.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=t,i=i.sibling;else for(i=t.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=t,i=i.sibling;return t.subtreeFlags|=r,t.childLanes=n,e}function zx(t,e,n){var r=e.pendingProps;switch(bc(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Se(e),null;case 1:return $e(e.type)&&Bs(),Se(e),null;case 3:return r=e.stateNode,Wr(),K(Ve),K(Ne),Uc(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(Uo(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,ft!==null&&(Iu(ft),ft=null))),Ou(t,e),Se(e),null;case 5:Wc(e);var i=$n(to.current);if(n=e.type,t!==null&&e.stateNode!=null)Ny(t,e,n,r,i),t.ref!==e.ref&&(e.flags|=512,e.flags|=2097152);else{if(!r){if(e.stateNode===null)throw Error(N(166));return Se(e),null}if(t=$n(Nt.current),Uo(e)){r=e.stateNode,n=e.type;var o=e.memoizedProps;switch(r[St]=e,r[Zi]=o,t=(e.mode&1)!==0,n){case"dialog":J("cancel",r),J("close",r);break;case"iframe":case"object":case"embed":J("load",r);break;case"video":case"audio":for(i=0;i<\/script>",t=t.removeChild(t.firstChild)):typeof r.is=="string"?t=s.createElement(n,{is:r.is}):(t=s.createElement(n),n==="select"&&(s=t,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):t=s.createElementNS(t,n),t[St]=e,t[Zi]=r,Cy(t,e,!1,!1),e.stateNode=t;e:{switch(s=tu(n,r),n){case"dialog":J("cancel",t),J("close",t),i=r;break;case"iframe":case"object":case"embed":J("load",t),i=r;break;case"video":case"audio":for(i=0;ijr&&(e.flags|=128,r=!0,ii(o,!1),e.lanes=4194304)}else{if(!r)if(t=Hs(s),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),ii(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!q)return Se(e),null}else 2*te()-o.renderingStartTime>jr&&n!==1073741824&&(e.flags|=128,r=!0,ii(o,!1),e.lanes=4194304);o.isBackwards?(s.sibling=e.child,e.child=s):(n=o.last,n!==null?n.sibling=s:e.child=s,o.last=s)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=te(),e.sibling=null,n=Q.current,H(Q,r?n&1|2:n&1),e):(Se(e),null);case 22:case 23:return ef(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?Ue&1073741824&&(Se(e),e.subtreeFlags&6&&(e.flags|=8192)):Se(e),null;case 24:return null;case 25:return null}throw Error(N(156,e.tag))}function bx(t,e){switch(bc(e),e.tag){case 1:return $e(e.type)&&Bs(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Wr(),K(Ve),K(Ne),Uc(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Wc(e),null;case 13:if(K(Q),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(N(340));$r()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return K(Q),null;case 4:return Wr(),null;case 10:return Bc(e.type._context),null;case 22:case 23:return ef(),null;case 24:return null;default:return null}}var Jo=!1,ve=!1,Ix=typeof WeakSet=="function"?WeakSet:Set,T=null;function wr(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){X(t,e,r)}else n.current=null}function Du(t,e,n){try{n()}catch(r){X(t,e,r)}}var Ch=!1;function Fx(t,e){if(fu=bs,t=Tg(),Pc(t)){if("selectionStart"in t)var n={start:t.selectionStart,end:t.selectionEnd};else e:{n=(n=t.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var s=0,l=-1,a=-1,u=0,c=0,f=t,d=null;t:for(;;){for(var p;f!==n||i!==0&&f.nodeType!==3||(l=s+i),f!==o||r!==0&&f.nodeType!==3||(a=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(p=f.firstChild)!==null;)d=f,f=p;for(;;){if(f===t)break t;if(d===n&&++u===i&&(l=s),d===o&&++c===r&&(a=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}n=l===-1||a===-1?null:{start:l,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(du={focusedElem:t,selectionRange:n},bs=!1,T=e;T!==null;)if(e=T,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,T=t;else for(;T!==null;){e=T;try{var h=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var m=h.memoizedProps,S=h.memoizedState,g=e.stateNode,y=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:at(e.type,m),S);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var k=e.stateNode.containerInfo;k.nodeType===1?k.textContent="":k.nodeType===9&&k.documentElement&&k.removeChild(k.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(N(163))}}catch(w){X(e,e.return,w)}if(t=e.sibling,t!==null){t.return=e.return,T=t;break}T=e.return}return h=Ch,Ch=!1,h}function Ri(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&t)===t){var o=i.destroy;i.destroy=void 0,o!==void 0&&Du(e,n,o)}i=i.next}while(i!==r)}}function hl(t,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var n=e=e.next;do{if((n.tag&t)===t){var r=n.create;n.destroy=r()}n=n.next}while(n!==e)}}function Tu(t){var e=t.ref;if(e!==null){var n=t.stateNode;switch(t.tag){case 5:t=n;break;default:t=n}typeof e=="function"?e(t):e.current=t}}function Ey(t){var e=t.alternate;e!==null&&(t.alternate=null,Ey(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[St],delete e[Zi],delete e[mu],delete e[kx],delete e[Sx])),t.stateNode=null,t.return=null,t.dependencies=null,t.memoizedProps=null,t.memoizedState=null,t.pendingProps=null,t.stateNode=null,t.updateQueue=null}function Oy(t){return t.tag===5||t.tag===3||t.tag===4}function Nh(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Oy(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function Ru(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.nodeType===8?n.parentNode.insertBefore(t,e):n.insertBefore(t,e):(n.nodeType===8?(e=n.parentNode,e.insertBefore(t,n)):(e=n,e.appendChild(t)),n=n._reactRootContainer,n!=null||e.onclick!==null||(e.onclick=Ls));else if(r!==4&&(t=t.child,t!==null))for(Ru(t,e,n),t=t.sibling;t!==null;)Ru(t,e,n),t=t.sibling}function Au(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.insertBefore(t,e):n.appendChild(t);else if(r!==4&&(t=t.child,t!==null))for(Au(t,e,n),t=t.sibling;t!==null;)Au(t,e,n),t=t.sibling}var he=null,ut=!1;function Qt(t,e,n){for(n=n.child;n!==null;)Dy(t,e,n),n=n.sibling}function Dy(t,e,n){if(Ct&&typeof Ct.onCommitFiberUnmount=="function")try{Ct.onCommitFiberUnmount(ol,n)}catch{}switch(n.tag){case 5:ve||wr(n,e);case 6:var r=he,i=ut;he=null,Qt(t,e,n),he=r,ut=i,he!==null&&(ut?(t=he,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):he.removeChild(n.stateNode));break;case 18:he!==null&&(ut?(t=he,n=n.stateNode,t.nodeType===8?ua(t.parentNode,n):t.nodeType===1&&ua(t,n),qi(t)):ua(he,n.stateNode));break;case 4:r=he,i=ut,he=n.stateNode.containerInfo,ut=!0,Qt(t,e,n),he=r,ut=i;break;case 0:case 11:case 14:case 15:if(!ve&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var o=i,s=o.destroy;o=o.tag,s!==void 0&&(o&2||o&4)&&Du(n,e,s),i=i.next}while(i!==r)}Qt(t,e,n);break;case 1:if(!ve&&(wr(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){X(n,e,l)}Qt(t,e,n);break;case 21:Qt(t,e,n);break;case 22:n.mode&1?(ve=(r=ve)||n.memoizedState!==null,Qt(t,e,n),ve=r):Qt(t,e,n);break;default:Qt(t,e,n)}}function Mh(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Ix),e.forEach(function(r){var i=Hx.bind(null,t,r);n.has(r)||(n.add(r),r.then(i,i))})}}function lt(t,e){var n=e.deletions;if(n!==null)for(var r=0;ri&&(i=s),r&=~o}if(r=i,r=te()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Bx(r/1960))-r,10t?16:t,cn===null)var r=!1;else{if(t=cn,cn=null,Ys=0,$&6)throw Error(N(331));var i=$;for($|=4,T=t.current;T!==null;){var o=T,s=o.child;if(T.flags&16){var l=o.deletions;if(l!==null){for(var a=0;ate()-Xc?Hn(t,0):Gc|=n),_e(t,e)}function Fy(t,e){e===0&&(t.mode&1?(e=Lo,Lo<<=1,!(Lo&130023424)&&(Lo=4194304)):e=1);var n=Te();t=Jt(t,e),t!==null&&(yo(t,e,n),_e(t,n))}function jx(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),Fy(t,n)}function Hx(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,i=t.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(N(314))}r!==null&&r.delete(e),Fy(t,n)}var Ly;Ly=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Ve.current)Le=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Le=!1,Px(t,e,n);Le=!!(t.flags&131072)}else Le=!1,q&&e.flags&1048576&&$g(e,_s,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ps(t,e),t=e.pendingProps;var i=Vr(e,Ne.current);Tr(e,n),i=Hc(null,e,r,t,i,n);var o=Jc();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,$e(r)?(o=!0,Vs(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,$c(e),i.updater=fl,e.stateNode=i,i._reactInternals=e,vu(e,r,t,n),e=Nu(null,e,r,!0,o,n)):(e.tag=0,q&&o&&zc(e),Ee(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(ps(t,e),t=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=Kx(r),t=at(r,t),i){case 0:e=Cu(null,e,r,t,n);break e;case 1:e=wh(null,e,r,t,n);break e;case 11:e=kh(null,e,r,t,n);break e;case 14:e=Sh(null,e,r,at(r.type,t),n);break e}throw Error(N(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),Cu(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),wh(t,e,r,i,n);case 3:e:{if(wy(e),t===null)throw Error(N(387));r=e.pendingProps,o=e.memoizedState,i=o.element,jg(t,e),js(e,r,null,n);var s=e.memoizedState;if(r=s.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){i=Ur(Error(N(423)),e),e=vh(t,e,r,n,i);break e}else if(r!==i){i=Ur(Error(N(424)),e),e=vh(t,e,r,n,i);break e}else for(He=gn(e.stateNode.containerInfo.firstChild),Ke=e,q=!0,ft=null,n=qg(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if($r(),r===i){e=Kt(t,e,n);break e}Ee(t,e,r,n)}e=e.child}return e;case 5:return Qg(e),t===null&&ku(e),r=e.type,i=e.pendingProps,o=t!==null?t.memoizedProps:null,s=i.children,hu(r,i)?s=null:o!==null&&hu(r,o)&&(e.flags|=32),Sy(t,e),Ee(t,e,s,n),e.child;case 6:return t===null&&ku(e),null;case 13:return vy(t,e,n);case 4:return _c(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=_r(e,null,r,n):Ee(t,e,r,n),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),kh(t,e,r,i,n);case 7:return Ee(t,e,e.pendingProps,n),e.child;case 8:return Ee(t,e,e.pendingProps.children,n),e.child;case 12:return Ee(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,o=e.memoizedProps,s=i.value,H(Ws,r._currentValue),r._currentValue=s,o!==null)if(mt(o.value,s)){if(o.children===i.children&&!Ve.current){e=Kt(t,e,n);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var l=o.dependencies;if(l!==null){s=o.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(o.tag===1){a=_t(-1,n&-n),a.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),Su(o.return,n,e),l.lanes|=n;break}a=a.next}}else if(o.tag===10)s=o.type===e.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(N(341));s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),Su(s,n,e),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===e){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}Ee(t,e,i.children,n),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,Tr(e,n),i=it(i),r=r(i),e.flags|=1,Ee(t,e,r,n),e.child;case 14:return r=e.type,i=at(r,e.pendingProps),i=at(r.type,i),Sh(t,e,r,i,n);case 15:return yy(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),ps(t,e),e.tag=1,$e(r)?(t=!0,Vs(e)):t=!1,Tr(e,n),Jg(e,r,i),vu(e,r,i,n),Nu(null,e,r,!0,t,n);case 19:return xy(t,e,n);case 22:return ky(t,e,n)}throw Error(N(156,e.tag))};function By(t,e){return cg(t,e)}function Jx(t,e,n,r){this.tag=t,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function tt(t,e,n,r){return new Jx(t,e,n,r)}function nf(t){return t=t.prototype,!(!t||!t.isReactComponent)}function Kx(t){if(typeof t=="function")return nf(t)?1:0;if(t!=null){if(t=t.$$typeof,t===vc)return 11;if(t===xc)return 14}return 2}function wn(t,e){var n=t.alternate;return n===null?(n=tt(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function ys(t,e,n,r,i,o){var s=2;if(r=t,typeof t=="function")nf(t)&&(s=1);else if(typeof t=="string")s=5;else e:switch(t){case fr:return Jn(n.children,i,o,e);case wc:s=8,i|=8;break;case Ha:return t=tt(12,n,e,i|2),t.elementType=Ha,t.lanes=o,t;case Ja:return t=tt(13,n,e,i),t.elementType=Ja,t.lanes=o,t;case Ka:return t=tt(19,n,e,i),t.elementType=Ka,t.lanes=o,t;case Km:return ml(n,i,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case Hm:s=10;break e;case Jm:s=9;break e;case vc:s=11;break e;case xc:s=14;break e;case Xt:s=16,r=null;break e}throw Error(N(130,t==null?t:typeof t,""))}return e=tt(s,n,e,i),e.elementType=t,e.type=r,e.lanes=o,e}function Jn(t,e,n,r){return t=tt(7,t,r,e),t.lanes=n,t}function ml(t,e,n,r){return t=tt(22,t,r,e),t.elementType=Km,t.lanes=n,t.stateNode={isHidden:!1},t}function ya(t,e,n){return t=tt(6,t,null,e),t.lanes=n,t}function ka(t,e,n){return e=tt(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function qx(t,e,n,r,i){this.tag=e,this.containerInfo=t,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Xl(0),this.expirationTimes=Xl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Xl(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function rf(t,e,n,r,i,o,s,l,a){return t=new qx(t,e,n,l,a),e===1?(e=1,o===!0&&(e|=8)):e=0,o=tt(3,null,null,e),t.current=o,o.stateNode=t,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},$c(o),t}function Qx(t,e,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Wy)}catch(t){console.error(t)}}Wy(),$m.exports=Qe;var Hr=$m.exports,Uy,zh=Hr;Uy=zh.createRoot,zh.hydrateRoot;const vo=C.createContext(null),jy=C.createContext(null);function eC(t){const e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(const r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[me.node(0,t.state.doc.content.size,e)]}const tC=[],nC={},Fu=U.empty;class In{constructor(e){this.members=e}map(e,n){const r=this.members.map(i=>i.map(e,n,nC));return In.from(r)}forChild(e,n){if(n.isLeaf)return U.empty;let r=[];for(let i=0;in instanceof U)?e:e.reduce((n,r)=>n.concat(r instanceof U?r:r.members),[]))}}}function Hy(t,e){return t.from-e.from||t.to-e.to}function rC(t){let e=t;for(let n=0;n0;)e++;t.splice(e,0,n)}function iC(t,e){const n=[];return t.someProp("decorations",r=>{const i=r(t.state);i&&i!=Fu&&n.push(i)}),e&&n.push(U.create(t.state.doc,[e])),In.from(n)}const af=function(t){for(let e=0;;e++)if(t=t.previousSibling,!t)return e},Ih=function(t){const e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},oC=function(t,e,n,r){return n&&(Fh(t,e,n,r,-1)||Fh(t,e,n,r,1))},sC=/^(img|br|input|textarea|hr)$/i;function Fh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Zs(t))){const o=t.parentNode;if(!o||o.nodeType!=1||aC(t)||sC.test(t.nodeName)||t.contentEditable=="false")return!1;e=af(t)+(i<0?0:1),t=o}else if(t.nodeType==1){if(t=t.childNodes[e+(i<0?-1:0)],t.contentEditable=="false")return!1;e=i<0?Zs(t):0}else return!1}}function Zs(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function lC(t,e,n){for(let r=e==0,i=e==Zs(t);r||i;){if(t==n)return!0;const o=af(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==Zs(t)}return!1}function aC(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Jy=function(t){return t.focusNode&&oC(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)},Ky=C.createContext(null);function uC(t,e){const n=C.useContext(Ky);C.useLayoutEffect(()=>n(t),e)}function qy(t,e){const{view:n}=C.useContext(vo);uC(()=>{if(n)return t(n)},e&&[n,...e])}const cC=C.forwardRef(function({widget:e,pos:n,...r},i){const[o,s]=C.useState(!0),l=C.useRef(null);return C.useImperativeHandle(i,()=>l.current,[]),qy(a=>{if(!a||!l.current)return;a.domObserver.disconnectSelection();const u=a.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,af(f)+1):c.setEnd(f,0),c.collapse(!1),u.removeAllRanges(),u.addRange(c),s(!1),a.domObserver.connectSelection()},[]),o?z("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function fC(t,e){if(t==e)return!0;for(const n in t)if(t[n]!==e[n])return!1;for(const n in e)if(!(n in t))return!1;return!0}const dC={side:0};class so{constructor(e,n){this.Component=e,this.spec=n??dC,this.side=this.spec.side??0}map(e,n,r,i){const{pos:o,deleted:s}=e.mapResult(n.from+i,this.side<0?-1:1);return s?null:new me(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof so&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&fC(this.spec,e.spec))}destroy(){}}function Qy(t,e,n){return new me(t,t,new so(e,n))}function Sa(){return Math.floor(Math.random()*16777215).toString(16)}const lo=new ho("@nytimes/react-prosemirror/reactKeys");function hC(){let t=!1;return new Tt({key:lo,state:{init(e,n){const r={posToKey:new Map,keyToPos:new Map};return n.doc.descendants((i,o)=>{const s=Sa();return r.posToKey.set(o,s),r.keyToPos.set(s,o),!0}),r},apply(e,n,r,i){if(!e.docChanged||t)return n;const o=e.getMeta(lo),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},a=Array.from(n.posToKey.entries()).sort(([u],[c])=>u-c);for(const[u,c]of a){const{pos:f,deleted:d}=e.mapping.mapResult(u);if(d)continue;let p=c;s===c&&(p=Sa()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((u,c)=>{if(l.posToKey.has(c))return!0;const f=Sa();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{t=!0},compositionend:()=>{t=!1}}}})}function wa(t,e,n={}){var s;if(e===null)return!1;const r=n.from??t.state.selection.from,i=n.to??t.state.selection.to;if(t.someProp("handleTextInput",l=>l(t,r,i,e)))return!0;const{tr:o}=t.state;if(n.marks&&o.ensureMarks(n.marks),o.insertText(e,r,i),n.bust){const l=t.state.doc.resolve(r),a=l.sharedDepth(i),u=l.start(a),c=(s=lo.getState(t.state))==null?void 0:s.posToKey.get(u-1);o.setMeta(lo,{type:"bustKey",payload:{key:c}})}return t.dispatch(o),!0}function pC(t){let e=null,n=null;return new Tt({props:{handleDOMEvents:{compositionstart(r){var s;const{state:i}=r;r.dispatch(i.tr.deleteSelection());const o=i.selection.$from;return i.selection.empty&&(i.storedMarks||!o.textOffset&&o.parentOffset&&((s=o.nodeBefore)!=null&&s.marks.some(l=>l.type.spec.inclusive===!1)))&&t(Qy(i.selection.from,cC,{key:"cursor-wrapper",marks:i.storedMarks??o.marks()})),n=i.storedMarks??o.marks(),r.input.composing=!0,!0},compositionupdate(){return!0},compositionend(r){if(r.input.composing=!1,e!==null)return wa(r,e,{bust:!0,marks:n}),e=null,n=null,t(null),!0},beforeinput(r,i){var o,s;switch(i.preventDefault(),i.inputType){case"insertCompositionText":{if(i.data===null)break;e=i.data;break}case"insertReplacementText":{const l=i.getTargetRanges();(s=(o=i.dataTransfer)==null?void 0:o.items[0])==null||s.getAsString(a=>{for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset,1),f=r.posAtDOM(u.endContainer,u.endOffset,1);wa(r,a,{from:c,to:f})}});break}case"insertText":{wa(r,i.data);break}case"deleteWordBackward":case"deleteContentBackward":case"deleteWordForward":case"deleteContentForward":case"deleteContent":{const l=i.getTargetRanges(),{tr:a}=r.state;for(const u of l){const c=r.posAtDOM(u.startContainer,u.startOffset),f=r.posAtDOM(u.endContainer,u.endOffset),{doc:d}=r.state,p=d.resolve(c).marksAcross(d.resolve(f));a.delete(c,f).setStoredMarks(p)}r.dispatch(a);break}}return!0}}}})}const Dt=typeof navigator<"u"?navigator:null,Lh=typeof document<"u"?document:null,Dn=Dt&&Dt.userAgent||"",Lu=/Edge\/(\d+)/.exec(Dn),Yy=/MSIE \d/.exec(Dn),Bu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Dn),wl=!!(Yy||Bu||Lu),mC=Yy?document.documentMode:Bu?+Bu[1]:Lu?+Lu[1]:0,Gy=!wl&&/gecko\/(\d+)/i.test(Dn),gC=Gy&&+(/Firefox\/(\d+)/.exec(Dn)||[0,0])[1],Vu=!wl&&/Chrome\/(\d+)/.exec(Dn),yC=!!Vu,kC=Vu?+Vu[1]:0,Xy=!wl&&!!Dt&&/Apple Computer/.test(Dt.vendor),Zy=Xy&&(/Mobile\/\w+/.test(Dn)||!!Dt&&Dt.maxTouchPoints>2),SC=Zy||(Dt?/Mac/.test(Dt.platform):!1),wC=Dt?/Win/.test(Dt.platform):!1,vC=/Android \d/.test(Dn),e0=!!Lh&&"webkitFontSmoothing"in Lh.documentElement.style,xC=e0?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ce={ie:wl,ie_version:mC,gecko:Gy,gecko_version:gC,chrome:yC,chrome_version:kC,safari:Xy,ios:Zy,mac:SC,windows:wC,android:vC,webkit:e0,webkit_version:xC};function Bh(t){return t.editable&&!t.hasFocus()?!1:CC(t)}function CC(t){var n,r;const e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(((n=e.focusNode)==null?void 0:n.nodeType)==3?(r=e.focusNode)==null?void 0:r.parentNode:e.focusNode))}catch{return!1}}function NC(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function Vh(t,e=null){const n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode);const o=i&&i.size==0,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;const l=r.resolve(s);let a,u;if(Jy(n)){for(a=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&b.isSelectable(c)&&i.parent&&!(c.isInline&&lC(n.focusNode,n.focusOffset,i.dom))){const f=i.posBefore;u=new b(s==f?l:r.resolve(f))}}else{const c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;a=r.resolve(c)}if(!u){const c=e=="pointer"||t.state.selection.head{(r.anchorNode!=i||r.anchorOffset!=o)&&(n.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!t0(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const Hh=Ce.safari||Ce.chrome&&Ce.chrome_version<63;function Qo(t,e=!1){const n=t,r=n.state.selection;if(OC(n,r),!!t0(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Ce.chrome){const i=n.domSelectionRange(),o=n.domObserver.currentSelection;if(i.anchorNode&&o.anchorNode&&el(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)TC(n);else{const{anchor:i,head:o}=r;let s,l;Hh&&!(r instanceof B)&&(r.$from.parent.inlineContent||(s=Uh(n,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=Uh(n,r.to))),n.docView.setSelection(i,o,n.root,e),Hh&&(s&&jh(s),l&&jh(l)),r.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&RC(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}class AC{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 PC{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new AC,this.suppressingSelectionUpdates=!1,this.view=e,this.onSelectionChange=this.onSelectionChange.bind(this)}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}stop(){this.disconnectSelection()}start(){this.connectSelection()}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;const n=new Set;let r;for(let o=e.focusNode;o;o=Ih(o))n.add(o);for(let o=e.anchorNode;o;o=Ih(o))if(n.has(o)){r=o;break}const i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:(r==null?void 0:r.nodeType)==3?r==null?void 0:r.parentNode:r}))return this.setCurSelection(),!0}registerMutation(){}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}updateSelection(){const{view:e}=this,n=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);e.input.compositionPendingChanges=0;const r=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,i=Vh(e,r);if(i&&!e.state.selection.eq(i)){const o=e.state.tr.setSelection(i);r=="pointer"?o.setMeta("pointer",!0):r=="key"&&o.scrollIntoView(),n&&o.setMeta("composition",n),e.dispatch(o)}}selectionToDOM(){const{view:e}=this;Qo(e);const n=e.domSelectionRange();this.currentSelection.set(n)}flush(){const{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;const n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Bh(e)&&!this.ignoreSelectionChange(n);let i=null;r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}onSelectionChange(){if(Bh(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Qo(this.view);if(Ce.ie&&Ce.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&el(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const Jr=0,Jh=1,Yo=2,ao=3;class xo{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Jr,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nen(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){const o=this.getDesc(i);let s;if(o&&(!n||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){const n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){const o=this.getDesc(i);if(o)return o.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||s instanceof ff){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof uf&&o.side>=0;r--);if(n<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&n&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,n):{node:this.contentDOM,offset:o?en(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=s;for(let f=l;f>0;f--){const d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=en(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;ch&&sn){const h=l;l=a,a=h}const p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){const l=r+o.border,a=s-o.border;if(e>=l&&n<=a){this.dirty=e==r||n==s?Yo:Jh,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=ao:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Yo:ao}r=s}this.dirty=Yo}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){const r=e==1?Yo:Jh;n.dirtythis.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){const r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>v.empty)}return e}matchesNode(e,n,r){return this.dirty==Jr&&e.eq(this.node)&&FC(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}update(e,n,r,i){return!0}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}}class IC extends cf{constructor(e,n,r,i,o,s,l){super(e,n,r,i,o,s,null,l)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return!0}inParent(){const e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=ao)}get domAtom(){return!1}}class ff extends xo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Jr&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function FC(t,e){if(t.length!=e.length)return!1;for(let n=0;n{u=!!a.call(this,s,l)}),u||l.defaultPrevented)return!0}return!1};e[r]=o}return new Tt({key:new ho("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function BC(){const[t,e]=C.useState(new Map),n=C.useCallback((o,s)=>{const l=t.get(o)??[];l.unshift(s),t.has(o)||(t.set(o,l),e(new Map(t)))},[t]),r=C.useCallback((o,s)=>{const l=t.get(o);l==null||l.splice(l.indexOf(s),1)},[t]),i=C.useMemo(()=>LC(t),[t]);return{registerEventListener:n,unregisterEventListener:r,componentEventListenersPlugin:i}}function n0(){const[,t]=C.useReducer(e=>e+1,0);return t}class VC extends TS{constructor(e,n){super(e,{state:on.create({schema:n.state.schema,plugins:n.state.plugins}),plugins:n.plugins}),this.shouldUpdatePluginViews=!1,this.shouldUpdatePluginViews=!0,this._props=n,this.oldProps={state:n.state},this.state=n.state,this.domObserver.stop(),this.domObserver=new PC(this),this.domObserver.start(),this.docView.dom.replaceChildren(),this.docView=n.docView}pureSetProps(e){this._props={...this._props,...e},this.state=this._props.state}runPendingEffects(){const e=this.props;this._props=this.oldProps,this.state=this._props.state,this.update(e)}update(e){super.update(e),this.oldProps=e}updatePluginViews(){this.shouldUpdatePluginViews&&super.updatePluginViews()}}const $C=new yp({nodes:{doc:{content:"text*"},text:{inline:!0}}}),_C=on.create({schema:$C});function WC(t,e){const[n,r]=C.useState(null),[i,o]=C.useState(null),s=n0(),l=e.defaultState??_C,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=BC(),h=C.useCallback(w=>{Hr.flushSync(()=>{o(w)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,pC(h)],[e.plugins,f,h]);function S(w){Hr.flushSync(()=>{e.state||u(M=>M.apply(w)),e.dispatchTransaction&&e.dispatchTransaction.call(this,w)})}const g=document.createElement("div"),y=C.useRef(new cf(void 0,[],c.doc,[],U.empty,g,null,g)),k={...e,state:c,plugins:m,dispatchTransaction:S,docView:y.current};return C.useLayoutEffect(()=>{if(n&&n.dom!==t&&r(null),!!t&&!n){const w=new VC({mount:t},k);r(w),w.dom.addEventListener("compositionend",s);return}}),n==null||n.pureSetProps(k),C.useMemo(()=>({view:n,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[n,c,d,p,i])}function UC(t){C.useLayoutEffect(()=>{t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()},[t,t==null?void 0:t.props])}function jC({children:t}){const e=C.useRef(new Set).current,n=C.useRef(new Set).current,r=C.useRef(!1),i=n0(),o=C.useRef(!0),s=C.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=C.useCallback(a=>{let u;const c=()=>{u=a()};return e.add(c),s(),()=>{e.delete(c),u&&(r.current?(n.add(u),s()):u())}},[e,n,s]);return C.useLayoutEffect(()=>(o.current=!1,e.forEach(a=>a()),e.clear(),()=>{n.forEach(a=>a()),n.clear()})),C.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),z(Ky.Provider,{value:l,children:t})}const st=C.createContext([]);function r0(t,e,n,r,i,o,s){const l=C.useRef(o),a=C.useContext(st),u=[];return C.useLayoutEffect(()=>{if(!t||!n.current)return;const c=u[0];l.current?(l.current.parent=void 0,l.current.children=u,l.current.node=t,l.current.outerDeco=i,l.current.innerDeco=r,l.current.dom=(e==null?void 0:e.current)??n.current,l.current.dom.pmViewDesc=l.current,l.current.contentDOM=(s==null?void 0:s.current)??l.current.contentDOM??(c==null?void 0:c.dom.parentElement)??null,l.current.nodeDOM=n.current):l.current=new cf(void 0,u,t,i,r,(e==null?void 0:e.current)??n.current,(c==null?void 0:c.dom.parentElement)??null,n.current),a.push(l.current);for(const f of u)f.parent=l.current}),u}function HC(t,e){return t.type.side-e.type.side}function JC(t,e,n,r){const i=e.locals(t);let o=0;if(i.length==0){for(let u=0;uo;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function vl(){const{state:t}=C.useContext(vo);return t}function i0(){const t=vl();return t&&lo.getState(t)}var o0={exports:{}};/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(t){(function(){var e=function(){function n(){}n.prototype=Object.create(null);function r(f,d){for(var p=d.length,h=0;ho;)l.push(i[s++]);let d=o+c.nodeSize;if(c.isText){let h=d;s!h.inline):l.slice();r(c,p,e.forChild(o,c),o,f),o=d}}function vl(){const{state:t}=C.useContext(vo);return t}function s0(){const t=vl();return t&&lo.getState(t)}const df=C.forwardRef(function({outputSpec:e,children:n,...r},i){if(typeof e=="string")return z(Ju,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1],a={...r,ref:i};let u=1;if(l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)){u=2;for(const f in l)if(l[f]!=null){const d=f==="class"?"className":f.replace(" ",":");a[d]=l[f]}}const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return C.createElement(s,a,n)}c.push(z(df,{ref:void 0,outputSpec:d,children:n}))}return C.createElement(s,a,...c)}),l0=C.forwardRef(function({mark:e,children:n},r){var a,u;const i=C.useContext(st),o=[],s=C.useRef(null);C.useImperativeHandle(r,()=>s.current,[]);const l=(u=(a=e.type.spec).toDOM)==null?void 0:u.call(a,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return C.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new zC(void 0,o,e,s.current,(c==null?void 0:c.dom.parentElement)??s.current);i.push(f);for(const d of o)d.parent=f}),z(df,{ref:s,outputSpec:l,children:z(st.Provider,{value:o,children:n})})});function qC({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null),i=C.useRef(e);return i.current=e,Qy(o=>{if(!r.current)return;const s=t.type.toDOM;let l=typeof s=="function"?s(o,()=>i.current):s;if(!t.type.spec.raw){if(l.nodeType!=1){const a=document.createElement("span");a.appendChild(l),l=a}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),C.useLayoutEffect(()=>{if(!r.current)return;const o=new uf(void 0,t,r.current);n.push(o)}),z("span",{ref:r})}function a0({outerDeco:t,pos:e,node:n,innerDeco:r,...i}){var D,R;const o=C.useRef(null),s=C.useRef(null),l=C.useRef(null),a=C.useRef(n),u=C.useRef(t),c=C.useRef(r),f=C.useRef(e);f.current=e;const d=C.useRef(null),p=C.useRef(null),h=vl(),{nodeViews:m}=C.useContext(Hy),{view:k}=C.useContext(vo);let g=null;const y=m[n.type.name],S=k==null?void 0:k.someProp("nodeViews",E=>E==null?void 0:E[n.type.name]);C.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:E}=p.current;return s.current=d.current,d.current.appendChild(E),()=>{var P,ne;(ne=(P=p.current)==null?void 0:P.destroy)==null||ne.call(P)}},[]),C.useLayoutEffect(()=>{if(!S||!p.current)return;const{destroy:E,update:P}=p.current;if(((P==null?void 0:P.call(p.current,n,t,r))??!0)||(E==null||E.call(p.current),!d.current))return;a.current=n,u.current=t,c.current=r,p.current=S(a.current,k,()=>f.current,u.current,c.current);const{dom:Rt}=p.current;s.current=d.current,d.current.appendChild(Rt)},[S,k,r,n,t]);const w=i0(n,o,s,r,t,void 0,l);if(y)g=z(y,{...i,ref:s,nodeProps:{node:n,pos:e,decorations:t,innerDecorations:r,isSelected:(h==null?void 0:h.selection)instanceof I&&h.selection.node===n},children:z(Ii,{pos:e,node:n,innerDecorations:r})});else if(S){p.current||(p.current=S(a.current,k,()=>f.current,u.current,c.current));const{contentDOM:E}=p.current;l.current=E??null,g=C.createElement(n.isInline?"span":"div",{ref:d,contentEditable:!!E,suppressContentEditableWarning:!0},E&&Hr.createPortal(z(Ii,{pos:e,node:n,innerDecorations:r}),E))}else{const E=(R=(D=n.type.spec).toDOM)==null?void 0:R.call(D,n);E&&(g=z(df,{...i,ref:s,outputSpec:E,children:z(Ii,{pos:e,node:n,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${n.type.name} is missing toDOM`);const M=C.cloneElement(t.reduce(hf,g),t.some(E=>E.type.attrs.nodeName)?{ref:o}:void 0),O=n.marks.reduce((E,P)=>z(l0,{mark:P,children:E}),M);return z(st.Provider,{value:w,children:C.cloneElement(O,n.marks.length||t.some(E=>E.type.attrs.nodeName)?{ref:o}:void 0)})}function QC(){const t=C.useContext(st),e=C.useRef(null),[n,r]=C.useState(!1);return C.useLayoutEffect(()=>{var s;const i=t[t.length-1];if((Ce.safari||Ce.chrome)&&((s=i==null?void 0:i.dom)==null?void 0:s.contentEditable)=="false"){r(!0);return}if(!e.current)return;const o=new ff(void 0,[],e.current,null);t.push(o)}),n?z("img",{ref:e,className:"ProseMirror-separator"}):null}class YC extends C.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:n,node:r}=this.props,i=Hr.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof PC?this.viewDescRef=new IC(void 0,[],r,e,U.empty,i,o):(this.viewDescRef.parent=void 0,this.viewDescRef.children=[],this.viewDescRef.node=r,this.viewDescRef.outerDeco=e,this.viewDescRef.innerDeco=U.empty,this.viewDescRef.dom=i,this.viewDescRef.nodeDOM=o),n.push(this.viewDescRef)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}render(){const{node:e,decorations:n}=this.props;return n.reduce(hf,e.text)}}function GC(){const t=C.useContext(st),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const n=new ff(void 0,[],e.current,null);t.push(n)}),z("br",{ref:e,className:"ProseMirror-trailingBreak"})}function XC({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new uf(void 0,t,r.current);n.push(o)});const{Component:i}=t.type;return i&&z(i,{ref:r,widget:t,pos:e,contentEditable:!1})}function Kh(t){const e=`{"${t.replace(/;? *$/,"").replace(/;+ */g,'","').replace(/: */g,'":"')}"}`,n=JSON.parse(e);return Object.keys(n).reduce((r,i)=>{const o=i.startsWith("--")?i:i.replace(/-[a-z]/g,s=>{var l;return((l=s[1])==null?void 0:l.toUpperCase())??""});return{...r,[o]:n[i]}},{})}function hf(t,e){const{nodeName:n,class:r,style:i,contenteditable:o,spellcheck:s,...l}=e.type.attrs;return n||typeof t=="string"?C.createElement(n??"span",{className:r,contentEditable:o,spellCheck:s,style:i&&Kh(i),...l},t):C.cloneElement(t,{className:HC(t.props.className,r),contentEditable:o,spellCheck:s,style:{...t.props.style,...i&&Kh(i)},...l})}function $u({innerPos:t,childViews:e}){const{view:n}=C.useContext(vo),r=vl(),i=s0(),o=e.reduce((s,l)=>{var c;const a=s[s.length-1];if(!a)return[[l]];const u=a[a.length-1];return u?!l.marks.length&&!u.marks.length||l.marks.length&&u.marks.length&&((c=l.marks[0])!=null&&c.eq(u.marks[0]))?[...s.slice(0,s.length-1),[...a.slice(0,a.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return z(Ju,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?z(l0,{mark:a,children:z($u,{innerPos:t,childViews:s.map(u=>({...u,marks:u.marks.slice(1)}))},zi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey))},zi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey)):s.map(u=>{const c=t+u.offset,f=u.type==="widget"?z(XC,{widget:u.widget,pos:c}):u.type==="native-widget"?z(qC,{widget:u.widget,pos:c}):u.node.isText?z(st.Consumer,{children:d=>z(YC,{view:n,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):z(a0,{node:u.node,pos:c,outerDeco:u.outerDeco,innerDeco:u.innerDeco});return C.cloneElement(f,{key:zi(r==null?void 0:r.doc,t,u,i==null?void 0:i.posToKey)})})})})}function zi(t,e,n,r){const i=e+n.offset,o=r==null?void 0:r.get(i);if(n.type==="widget"||n.type==="native-widget")return n.widget.type.spec.key?n.widget.type.spec.key:(console.warn(`Widget at position ${i} doesn't have a key specified. This has negative performance implications.`),`${o}-${n.index}`);if(o)return o;if(!t)return i;const s=t.resolve(i).start()-1,l=r==null?void 0:r.get(s);return l?`${l}-${n.offset}`:i}function ZC(t){const e=t[t.length-1];if((e==null?void 0:e.type)!=="widget"&&(e==null?void 0:e.type)!=="native-widget"||e.widget.type.side>=0)return;let n=null;for(let i=t.length-2;i>=0;i--){const o=t[i];if((o==null?void 0:o.type)==="node"){n=o;break}}if(!n||!n.node.isInline)return;const r=n.marks;e.marks=e.marks.reduce((i,o)=>o.addToSet(i),r)}function eN(t){const e=t[t.length-1];if((e==null?void 0:e.type)!=="node"||!e.node.isInline)return;const n=e.marks;for(let r=t.length-2;r>=0;r--){const i=t[r];if((i==null?void 0:i.type)!=="widget"&&(i==null?void 0:i.type)!=="native-widget"||i.widget.type.side<0)break;i.marks=i.marks.reduce((o,s)=>s.addToSet(o),n)}}function tN(t,e,n,r){return t.length?t.every(i=>i.type!=="node"||i.node.isInline)?[z($u,{childViews:t,innerPos:e},zi(n,e,t[0],r))]:t.map(i=>{if(i.type==="node"){const o=e+i.offset,s=(r==null?void 0:r.get(o))??o;return z(a0,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return z($u,{childViews:[i],innerPos:e},zi(n,e,i,r))}):[]}function Ii({pos:t,node:e,innerDecorations:n}){const r=vl(),i=s0();if(!e)return null;const o=t+1,s=[];KC(e,n,(u,c,f,d)=>{const p=u.type.spec.marks??[];c?s.push({type:"native-widget",widget:u,marks:p,offset:f,index:d}):s.push({type:"widget",widget:u,marks:p,offset:f,index:d}),ZC(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),eN(s)});const l=tN(s,o,r==null?void 0:r.doc,i==null?void 0:i.posToKey),a=s[s.length-1];return(!a||a.type!=="node"||a.node.isInline&&!a.node.isText||/\n$/.test(a.node.text))&&l.push(z(QC,{},"trailing-hack-img"),z(GC,{},"trailing-hack-br")),z(Ju,{children:l})}const nN=C.forwardRef(function({className:e,node:n,innerDeco:r,outerDeco:i,as:o,viewDesc:s},l){const a=C.useRef(null);C.useImperativeHandle(l,()=>a.current,[]);const u=i0(n,a,a,r,i,s),c={ref:a,className:e,suppressContentEditableWarning:!0},f=o?C.cloneElement(o,c,z(st.Provider,{value:u,children:z(Ii,{pos:-1,node:n,innerDecorations:r})})):C.createElement("div",c,z(st.Provider,{value:u,children:z(Ii,{pos:-1,node:n,innerDecorations:r})}));if(!n)return f;const d=i.filter(h=>!h.inline);return d.length?d.reduce(hf,f):f}),u0=C.createContext(null);function rN({as:t},e){const n=C.useRef(null),{setMount:r,...i}=C.useContext(u0);return C.useImperativeHandle(e,()=>n.current,[]),z(st.Provider,{value:[],children:z(nN,{ref:o=>{n.current=o,r(o)},...i,as:t})})}const iN=C.forwardRef(rN);function oN({className:t,children:e,nodeViews:n={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=_C(o,{...i,nodeViews:r});WC(l.view);const a=l.view?rC(l.view,l.cursorWrapper):U.empty,u=l.view?Zx(l.view):[];return z(UC,{children:z(vo.Provider,{value:l,children:z(Hy.Provider,{value:{nodeViews:n},children:z(u0.Provider,{value:{className:t,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:a,outerDeco:u,viewDesc:l.docViewDescRef.current},children:e})})})})}const _=new Sp({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Sw({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),sN=on.create({schema:_,doc:_.nodes.doc.create({},[_.nodes.paragraph.create({},[_.text("This ",[_.marks.em.create()]),_.text("is",[_.marks.em.create(),_.marks.strong.create()]),_.text(" the first paragraph")]),_.nodes.paragraph.create({},[_.text("This is the second paragraph"),_.nodes.footnote.create({number:1},_.text("Footnote"))]),_.nodes.paragraph.create(),_.nodes.image.create(),_.nodes.image.create(),_.nodes.paragraph.create({},_.text("This is the third paragraph 🫵")),_.nodes.table.create({},[_.nodes.table_row.create({},[_.nodes.table_header.create({},_.text("h1")),_.nodes.table_header.create({},_.text("h2"))]),_.nodes.table_row.create({},[_.nodes.table_cell.create({},_.text("c1")),_.nodes.table_cell.create({},_.text("c2"))])])]),plugins:[dC(),$k({rules:[_k(/^\s*([-+*])\s$/,_.nodes.list)]}),Lw(),Qw()]}),lN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("p",{ref:i,...r,children:e})}),aN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("ul",{ref:i,...r,children:e})}),uN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("li",{ref:i,...r,children:e})}),cN=C.forwardRef(function({nodeProps:e,...n},r){return z("span",{ref:r,...n,suppressContentEditableWarning:!0,contentEditable:"false",children:z("button",{children:e.node.attrs.number})})}),fN=C.forwardRef(function({widget:e,pos:n,...r},i){return z("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),dN=new Tt({view(t){const e=t.coordsAtPos(t.state.selection.from),n=document.createElement("div");return n.style.width="4px",n.style.height="4px",n.style.position="absolute",n.style.top=`${e.top-2}px`,n.style.left=`${e.left-2}px`,n.style.backgroundColor="blue",document.body.appendChild(n),{update(r){const i=r.coordsAtPos(r.state.selection.from);n.style.top=`${i.top-2}px`,n.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(n)}}}});new Tt({props:{decorations(t){return U.create(t.doc,[Yy(t.selection.from,fN,{side:0,key:"widget-plugin-widget"})])}},view(t){const e=t.coordsAtPos(t.state.selection.from),n=document.createElement("div");return n.style.width="4px",n.style.height="4px",n.style.position="absolute",n.style.top=`${e.top-2}px`,n.style.left=`${e.left-2}px`,n.style.backgroundColor="blue",document.body.appendChild(n),{update(r){const i=r.coordsAtPos(r.state.selection.from);n.style.top=`${i.top-2}px`,n.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(n)}}}});const hN=[Hk({...q1,"Mod-i":bf(_.marks.em),"Mod-b":bf(_.marks.strong)}),dN,zk()],pN={paragraph:()=>{const t=document.createElement("p");return{dom:t,contentDOM:t}}};function mN(){const[t,e]=C.useState(sN),[n,r]=C.useState(!0);return Sf("main",{children:[z("h1",{children:"React ProseMirror Demo"}),Sf("button",{onClick:()=>{n?r(i=>!i):window.location.reload()},children:["Switch to"," ",n?"ProseMirror node views":"React node views (requires reload)"]}),z(oN,{className:"ProseMirror",state:t,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:hN,nodeViews:n?{paragraph:lN,list:aN,list_item:uN,footnote:cN}:void 0,customNodeViews:n?void 0:pN,children:z(iN,{as:z("article",{})})},`${n}`)]})}const gN=jy(document.getElementById("root"));gN.render(z(mN,{})); +*/(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var r=[],i=0;i{var n;return((n=e[1])==null?void 0:n.toUpperCase())??""})}function YC(t){const e=new CSSStyleSheet;e.insertRule(`* { ${t} }`);const r=e.cssRules[0].style,i={};for(let o=0;o0&&(e.step=r);break}case"disabled":{e.disabled=r!=null;break}case"rows":{const i=parseInt(r,10);Number.isNaN(i)||(e.rows=r);break}default:{e[n]=r;break}}return e}const df=C.forwardRef(function({outputSpec:e,children:n,...r},i){if(typeof e=="string")return z(Ju,{children:e});if(!Array.isArray(e))throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");const s=e[0].replace(" ",":"),l=e[1];let a={ref:i,...r},u=1;l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)&&(u=2,a=s0(l0(l),r));const c=[];for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return C.createElement(s,a,n)}c.push(z(df,{ref:void 0,outputSpec:d,children:n}))}return C.createElement(s,a,...c)}),a0=C.forwardRef(function({mark:e,children:n},r){var a,u;const i=C.useContext(st),o=[],s=C.useRef(null);C.useImperativeHandle(r,()=>s.current,[]);const l=(u=(a=e.type.spec).toDOM)==null?void 0:u.call(a,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return C.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new bC(void 0,o,e,s.current,(c==null?void 0:c.dom.parentElement)??s.current);i.push(f);for(const d of o)d.parent=f}),z(df,{ref:s,outputSpec:l,children:z(st.Provider,{value:o,children:n})})});function GC({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null),i=C.useRef(e);return i.current=e,qy(o=>{if(!r.current)return;const s=t.type.toDOM;let l=typeof s=="function"?s(o,()=>i.current):s;if(!t.type.spec.raw){if(l.nodeType!=1){const a=document.createElement("span");a.appendChild(l),l=a}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),C.useLayoutEffect(()=>{if(!r.current)return;const o=new uf(void 0,t,r.current);n.push(o)}),z("span",{ref:r})}function u0({outerDeco:t,pos:e,node:n,innerDeco:r,...i}){var D,R;const o=C.useRef(null),s=C.useRef(null),l=C.useRef(null),a=C.useRef(n),u=C.useRef(t),c=C.useRef(r),f=C.useRef(e);f.current=e;const d=C.useRef(null),p=C.useRef(null),h=vl(),{nodeViews:m}=C.useContext(jy),{view:S}=C.useContext(vo);let g=null;const y=m[n.type.name],k=S==null?void 0:S.someProp("nodeViews",E=>E==null?void 0:E[n.type.name]);C.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:E}=p.current;return s.current=d.current,d.current.appendChild(E),()=>{var P,ne;(ne=(P=p.current)==null?void 0:P.destroy)==null||ne.call(P)}},[]),C.useLayoutEffect(()=>{if(!k||!p.current)return;const{destroy:E,update:P}=p.current;if(((P==null?void 0:P.call(p.current,n,t,r))??!0)||(E==null||E.call(p.current),!d.current))return;a.current=n,u.current=t,c.current=r,p.current=k(a.current,S,()=>f.current,u.current,c.current);const{dom:Rt}=p.current;s.current=d.current,d.current.appendChild(Rt)},[k,S,r,n,t]);const w=r0(n,o,s,r,t,void 0,l);if(y)g=z(y,{...i,ref:s,nodeProps:{node:n,pos:e,decorations:t,innerDecorations:r,isSelected:(h==null?void 0:h.selection)instanceof b&&h.selection.node===n},children:z(bi,{pos:e,node:n,innerDecorations:r})});else if(k){p.current||(p.current=k(a.current,S,()=>f.current,u.current,c.current));const{contentDOM:E}=p.current;l.current=E??null,g=C.createElement(n.isInline?"span":"div",{ref:d,contentEditable:!!E,suppressContentEditableWarning:!0},E&&Hr.createPortal(z(bi,{pos:e,node:n,innerDecorations:r}),E))}else{const E=(R=(D=n.type.spec).toDOM)==null?void 0:R.call(D,n);E&&(g=z(df,{...i,ref:s,outputSpec:E,children:z(bi,{pos:e,node:n,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${n.type.name} is missing toDOM`);const M=C.cloneElement(t.reduce(hf,g),t.some(E=>E.type.attrs.nodeName)?{ref:o}:void 0),O=n.marks.reduce((E,P)=>z(a0,{mark:P,children:E}),M);return z(st.Provider,{value:w,children:C.cloneElement(O,n.marks.length||t.some(E=>E.type.attrs.nodeName)?{ref:o}:void 0)})}function XC(){const t=C.useContext(st),e=C.useRef(null),[n,r]=C.useState(!1);return C.useLayoutEffect(()=>{var s;const i=t[t.length-1];if((Ce.safari||Ce.chrome)&&((s=i==null?void 0:i.dom)==null?void 0:s.contentEditable)=="false"){r(!0);return}if(!e.current)return;const o=new ff(void 0,[],e.current,null);t.push(o)}),n?z("img",{ref:e,className:"ProseMirror-separator"}):null}class ZC extends C.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:n,node:r}=this.props,i=Hr.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof zC?this.viewDescRef=new IC(void 0,[],r,e,U.empty,i,o):(this.viewDescRef.parent=void 0,this.viewDescRef.children=[],this.viewDescRef.node=r,this.viewDescRef.outerDeco=e,this.viewDescRef.innerDeco=U.empty,this.viewDescRef.dom=i,this.viewDescRef.dom.pmViewDesc=this.viewDescRef,this.viewDescRef.nodeDOM=o),n.push(this.viewDescRef)}componentDidMount(){this.updateEffect()}componentDidUpdate(){this.updateEffect()}render(){const{node:e,decorations:n}=this.props;return n.reduce(hf,e.text)}}function eN(){const t=C.useContext(st),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const n=new ff(void 0,[],e.current,null);t.push(n)}),z("br",{ref:e,className:"ProseMirror-trailingBreak"})}function tN({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new uf(void 0,t,r.current);n.push(o)});const{Component:i}=t.type;return i&&z(i,{ref:r,widget:t,pos:e,contentEditable:!1})}function hf(t,e){const{nodeName:n,...r}=e.type.attrs,i=l0(r);return n||typeof t=="string"?C.createElement(n??"span",i,t):C.cloneElement(t,s0(t.props,i))}function $u({innerPos:t,childViews:e}){const{view:n}=C.useContext(vo),r=vl(),i=i0(),o=e.reduce((s,l)=>{var c;const a=s[s.length-1];if(!a)return[[l]];const u=a[a.length-1];return u?!l.marks.length&&!u.marks.length||l.marks.length&&u.marks.length&&((c=l.marks[0])!=null&&c.eq(u.marks[0]))?[...s.slice(0,s.length-1),[...a.slice(0,a.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return z(Ju,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?z(a0,{mark:a,children:z($u,{innerPos:t,childViews:s.map(u=>({...u,marks:u.marks.slice(1)}))},zi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey))},zi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey)):s.map(u=>{const c=t+u.offset,f=u.type==="widget"?z(tN,{widget:u.widget,pos:c}):u.type==="native-widget"?z(GC,{widget:u.widget,pos:c}):u.node.isText?z(st.Consumer,{children:d=>z(ZC,{view:n,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):z(u0,{node:u.node,pos:c,outerDeco:u.outerDeco,innerDeco:u.innerDeco});return C.cloneElement(f,{key:zi(r==null?void 0:r.doc,t,u,i==null?void 0:i.posToKey)})})})})}function zi(t,e,n,r){const i=e+n.offset,o=r==null?void 0:r.get(i);if(n.type==="widget"||n.type==="native-widget")return n.widget.type.spec.key?n.widget.type.spec.key:(console.warn(`Widget at position ${i} doesn't have a key specified. This has negative performance implications.`),`${o}-${n.index}`);if(o)return o;if(!t)return i;const s=t.resolve(i).start()-1,l=r==null?void 0:r.get(s);return l?`${l}-${n.offset}`:i}function nN(t){const e=t[t.length-1];if((e==null?void 0:e.type)!=="widget"&&(e==null?void 0:e.type)!=="native-widget"||e.widget.type.side>=0)return;let n=null;for(let i=t.length-2;i>=0;i--){const o=t[i];if((o==null?void 0:o.type)==="node"){n=o;break}}if(!n||!n.node.isInline)return;const r=n.marks;e.marks=e.marks.reduce((i,o)=>o.addToSet(i),r)}function rN(t){const e=t[t.length-1];if((e==null?void 0:e.type)!=="node"||!e.node.isInline)return;const n=e.marks;for(let r=t.length-2;r>=0;r--){const i=t[r];if((i==null?void 0:i.type)!=="widget"&&(i==null?void 0:i.type)!=="native-widget"||i.widget.type.side<0)break;i.marks=i.marks.reduce((o,s)=>s.addToSet(o),n)}}function iN(t,e,n,r){return t.length?t.every(i=>i.type!=="node"||i.node.isInline)?[z($u,{childViews:t,innerPos:e},zi(n,e,t[0],r))]:t.map(i=>{if(i.type==="node"){const o=e+i.offset,s=(r==null?void 0:r.get(o))??o;return z(u0,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return z($u,{childViews:[i],innerPos:e},zi(n,e,i,r))}):[]}function bi({pos:t,node:e,innerDecorations:n}){const r=vl(),i=i0();if(!e)return null;const o=t+1,s=[];JC(e,n,(u,c,f,d)=>{const p=u.type.spec.marks??[];c?s.push({type:"native-widget",widget:u,marks:p,offset:f,index:d}):s.push({type:"widget",widget:u,marks:p,offset:f,index:d}),nN(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),rN(s)});const l=iN(s,o,r==null?void 0:r.doc,i==null?void 0:i.posToKey),a=s[s.length-1];return(!a||a.type!=="node"||a.node.isInline&&!a.node.isText||/\n$/.test(a.node.text))&&l.push(z(XC,{},"trailing-hack-img"),z(eN,{},"trailing-hack-br")),z(Ju,{children:l})}const oN=C.forwardRef(function({className:e,node:n,innerDeco:r,outerDeco:i,as:o,viewDesc:s},l){const a=C.useRef(null);C.useImperativeHandle(l,()=>a.current,[]);const u=r0(n,a,a,r,i,s),c={ref:a,className:e,suppressContentEditableWarning:!0},f=o?C.cloneElement(o,c,z(st.Provider,{value:u,children:z(bi,{pos:-1,node:n,innerDecorations:r})})):C.createElement("div",c,z(st.Provider,{value:u,children:z(bi,{pos:-1,node:n,innerDecorations:r})}));if(!n)return f;const d=i.filter(h=>!h.inline);return d.length?d.reduce(hf,f):f}),c0=C.createContext(null);function sN({as:t},e){const n=C.useRef(null),{setMount:r,...i}=C.useContext(c0);return C.useImperativeHandle(e,()=>n.current,[]),z(st.Provider,{value:[],children:z(oN,{ref:o=>{n.current=o,r(o)},...i,as:t})})}const lN=C.forwardRef(sN);function aN({className:t,children:e,nodeViews:n={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=WC(o,{...i,nodeViews:r});UC(l.view);const a=l.view?iC(l.view,l.cursorWrapper):U.empty,u=l.view?eC(l.view):[];return z(jC,{children:z(vo.Provider,{value:l,children:z(jy.Provider,{value:{nodeViews:n},children:z(c0.Provider,{value:{className:t,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:a,outerDeco:u,viewDesc:l.docViewDescRef.current},children:e})})})})}const _=new yp({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...Sw({cellContent:"inline*",cellAttributes:{},tableGroup:"block"}),footnote:{group:"inline",content:"text*",inline:!0,atom:!0,attrs:{number:{default:0}}},list:{group:"block",content:"list_item+",toDOM(){return["ul",0]}},list_item:{content:"paragraph+",toDOM(){return["li",0]}},image:{group:"block",toDOM(){return["div",["img",{src:"https://smoores.gitlab.io/storyteller/img/Storyteller_Logo.png",height:150,width:150}]]}},text:{group:"inline"}},marks:{em:{toDOM(){return["em",0]}},strong:{toDOM(){return["strong",0]}}}}),uN=on.create({schema:_,doc:_.nodes.doc.create({},[_.nodes.paragraph.create({},[_.text("This ",[_.marks.em.create()]),_.text("is",[_.marks.em.create(),_.marks.strong.create()]),_.text(" the first paragraph")]),_.nodes.paragraph.create({},[_.text("This is the second paragraph"),_.nodes.footnote.create({number:1},_.text("Footnote"))]),_.nodes.paragraph.create(),_.nodes.image.create(),_.nodes.image.create(),_.nodes.paragraph.create({},_.text("This is the third paragraph 🫵")),_.nodes.table.create({},[_.nodes.table_row.create({},[_.nodes.table_header.create({},_.text("h1")),_.nodes.table_header.create({},_.text("h2"))]),_.nodes.table_row.create({},[_.nodes.table_cell.create({},_.text("c1")),_.nodes.table_cell.create({},_.text("c2"))])])]),plugins:[hC(),_S({rules:[WS(/^\s*([-+*])\s$/,_.nodes.list)]}),Bw(),Yw()]}),cN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("p",{ref:i,...r,children:e})}),fN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("ul",{ref:i,...r,children:e})}),dN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("li",{ref:i,...r,children:e})}),hN=C.forwardRef(function({nodeProps:e,...n},r){return z("span",{ref:r,...n,suppressContentEditableWarning:!0,contentEditable:"false",children:z("button",{children:e.node.attrs.number})})}),pN=C.forwardRef(function({widget:e,pos:n,...r},i){return z("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),mN=new Tt({view(t){const e=t.coordsAtPos(t.state.selection.from),n=document.createElement("div");return n.style.width="4px",n.style.height="4px",n.style.position="absolute",n.style.top=`${e.top-2}px`,n.style.left=`${e.left-2}px`,n.style.backgroundColor="blue",document.body.appendChild(n),{update(r){const i=r.coordsAtPos(r.state.selection.from);n.style.top=`${i.top-2}px`,n.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(n)}}}});new Tt({props:{decorations(t){return U.create(t.doc,[Qy(t.selection.from,pN,{side:0,key:"widget-plugin-widget"})])}},view(t){const e=t.coordsAtPos(t.state.selection.from),n=document.createElement("div");return n.style.width="4px",n.style.height="4px",n.style.position="absolute",n.style.top=`${e.top-2}px`,n.style.left=`${e.left-2}px`,n.style.backgroundColor="blue",document.body.appendChild(n),{update(r){const i=r.coordsAtPos(r.state.selection.from);n.style.top=`${i.top-2}px`,n.style.left=`${i.left-2}px`},destroy(){document.body.removeChild(n)}}}});const gN=[JS({...Q1,"Mod-i":If(_.marks.em),"Mod-b":If(_.marks.strong)}),mN,bS()],yN={paragraph:()=>{const t=document.createElement("p");return{dom:t,contentDOM:t}}};function kN(){const[t,e]=C.useState(uN),[n,r]=C.useState(!0);return kf("main",{children:[z("h1",{children:"React ProseMirror Demo"}),kf("button",{onClick:()=>{n?r(i=>!i):window.location.reload()},children:["Switch to"," ",n?"ProseMirror node views":"React node views (requires reload)"]}),z(aN,{className:"ProseMirror",state:t,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:gN,nodeViews:n?{paragraph:cN,list:fN,list_item:dN,footnote:hN}:void 0,customNodeViews:n?void 0:yN,children:z(lN,{as:z("article",{})})},`${n}`)]})}const SN=Uy(document.getElementById("root"));SN.render(z(kN,{})); diff --git a/docs/index.html b/docs/index.html index ac8d19d3..a53b4657 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ React-ProseMirror Demo - + diff --git a/src/components/ChildNodeViews.tsx b/src/components/ChildNodeViews.tsx index d28394b0..7c5cd386 100644 --- a/src/components/ChildNodeViews.tsx +++ b/src/components/ChildNodeViews.tsx @@ -1,4 +1,3 @@ -import classnames from "classnames/dedupe"; import { Mark, Node } from "prosemirror-model"; import { Decoration, DecorationSource } from "prosemirror-view"; import React, { @@ -14,6 +13,7 @@ import { ReactWidgetDecoration } from "../decorations/ReactWidgetType.js"; import { iterDeco } from "../decorations/iterDeco.js"; import { useEditorState } from "../hooks/useEditorState.js"; import { useReactKeys } from "../hooks/useReactKeys.js"; +import { htmlAttrsToReactProps, mergeReactProps } from "../props.js"; import { MarkView } from "./MarkView.js"; import { NativeWidgetView } from "./NativeWidgetView.js"; @@ -23,57 +23,23 @@ import { TextNodeView } from "./TextNodeView.js"; import { TrailingHackView } from "./TrailingHackView.js"; import { WidgetView } from "./WidgetView.js"; -function cssToStyles(css: string) { - const cssJson = `{"${css - .replace(/;? *$/, "") - .replace(/;+ */g, '","') - .replace(/: */g, '":"')}"}`; - - const obj = JSON.parse(cssJson); - - return Object.keys(obj).reduce((acc, key) => { - const camelCased = key.startsWith("--") - ? key - : key.replace(/-[a-z]/g, (g) => g[1]?.toUpperCase() ?? ""); - return { ...acc, [camelCased]: obj[key] }; - }, {}); -} - export function wrapInDeco(reactNode: JSX.Element | string, deco: Decoration) { const { nodeName, - class: className, - style: css, - contenteditable: contentEditable, - spellcheck: spellCheck, ...attrs // eslint-disable-next-line @typescript-eslint/no-explicit-any } = (deco as any).type.attrs; + const props = htmlAttrsToReactProps(attrs); + // We auto-wrap text nodes in spans so that we can apply attributes // and styles, but we want to avoid double-wrapping the same // text node if (nodeName || typeof reactNode === "string") { - return createElement( - nodeName ?? "span", - { - className, - contentEditable, - spellCheck, - style: css && cssToStyles(css), - ...attrs, - }, - reactNode - ); + return createElement(nodeName ?? "span", props, reactNode); } - return cloneElement(reactNode, { - className: classnames(reactNode.props.className, className), - contentEditable, - spellCheck, - style: { ...reactNode.props.style, ...(css && cssToStyles(css)) }, - ...attrs, - }); + return cloneElement(reactNode, mergeReactProps(reactNode.props, props)); } type ChildWidget = { diff --git a/src/components/OutputSpec.tsx b/src/components/OutputSpec.tsx index 09b1206c..a8999270 100644 --- a/src/components/OutputSpec.tsx +++ b/src/components/OutputSpec.tsx @@ -1,13 +1,15 @@ import { DOMOutputSpec } from "prosemirror-model"; -import React, { ReactNode, createElement, forwardRef } from "react"; +import React, { HTMLProps, ReactNode, createElement, forwardRef } from "react"; -type Props = { +import { htmlAttrsToReactProps, mergeReactProps } from "../props.js"; + +type Props = HTMLProps & { outputSpec: DOMOutputSpec; children?: ReactNode; }; -const ForwardedOutputSpec = forwardRef(function OutputSpec( - { outputSpec, children, ...initialProps }: Props, +const ForwardedOutputSpec = forwardRef(function OutputSpec( + { outputSpec, children, ...propOverrides }: Props, ref ) { if (typeof outputSpec === "string") { @@ -24,7 +26,10 @@ const ForwardedOutputSpec = forwardRef(function OutputSpec( const tagName = tagSpec.replace(" ", ":"); const attrs = outputSpec[1]; - const props: Record = { ...initialProps, ref }; + let props: HTMLProps = { + ref, + ...propOverrides, + }; let start = 1; if ( attrs && @@ -33,13 +38,9 @@ const ForwardedOutputSpec = forwardRef(function OutputSpec( !Array.isArray(attrs) ) { start = 2; - for (const name in attrs) - if (attrs[name] != null) { - const attrName = - name === "class" ? "className" : name.replace(" ", ":"); - props[attrName] = attrs[name]; - } + props = mergeReactProps(htmlAttrsToReactProps(attrs), propOverrides); } + const content: ReactNode[] = []; for (let i = start; i < outputSpec.length; i++) { const child = outputSpec[i] as DOMOutputSpec | 0; diff --git a/src/props.ts b/src/props.ts new file mode 100644 index 00000000..f8e4853a --- /dev/null +++ b/src/props.ts @@ -0,0 +1,223 @@ +import cx from "classnames"; +import { HTMLProps } from "react"; + +export function kebabCaseToCamelCase(str: string) { + return str.replaceAll(/-[a-z]/g, (g) => g[1]?.toUpperCase() ?? ""); +} + +/** + * Converts a CSS style string to an object + * that can be passed to a React component's + * `style` prop. + */ +export function cssToStyles(css: string) { + const stylesheet = new CSSStyleSheet(); + stylesheet.insertRule(`* { ${css} }`); + + const insertedRule = stylesheet.cssRules[0] as CSSStyleRule; + const declaration = insertedRule.style; + const styles: Record = {}; + + for (let i = 0; i < declaration.length; i++) { + const property = declaration.item(i); + const value = declaration.getPropertyValue(property); + const camelCasePropertyName = kebabCaseToCamelCase(property); + styles[camelCasePropertyName] = value; + } + + return styles; +} + +/** + * Merges two sets of React props. Class names + * will be concatenated and style objects + * will be merged. + */ +export function mergeReactProps( + a: HTMLProps, + b: HTMLProps +) { + return { + ...a, + ...b, + className: cx(a.className, b.className), + style: { + ...a.style, + ...b.style, + }, + }; +} + +/** + * Given a record of HTML attributes, returns tho + * equivalent React props. + */ +export function htmlAttrsToReactProps( + attrs: Record +): HTMLProps { + const props: Record = {}; + for (const [attrName, attrValue] of Object.entries(attrs)) { + switch (attrName.toLowerCase()) { + case "class": { + props.className = attrValue; + break; + } + case "style": { + props.style = cssToStyles(attrValue); + break; + } + case "autocapitalize": { + props.autoCapitalize = attrValue; + break; + } + case "contenteditable": { + props.contentEditable = attrValue != null; + break; + } + case "draggable": { + props.draggable = attrValue != null; + break; + } + case "enterkeyhint": { + props.enterKeyHint = attrValue; + break; + } + case "for": { + props.htmlFor = attrValue; + break; + } + case "hidden": { + props.hidden = attrValue; + break; + } + case "inputmode": { + props.inputMode = attrValue; + break; + } + case "itemprop": { + props.itemProp = attrValue; + break; + } + case "spellcheck": { + if (attrValue === "" || attrValue === "true") { + props.spellCheck = true; + break; + } + if (attrValue === "false") { + props.spellCheck = false; + } + props.spellCheck = null; + break; + } + case "tabindex": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.tabIndex = numValue; + } + break; + } + case "autocomplete": { + props.autoComplete = attrValue; + break; + } + case "autofocus": { + props.autoFocus = attrValue != null; + break; + } + case "formaction": { + props.formAction = attrValue; + break; + } + case "formenctype": { + props.formEnctype = attrValue; + break; + } + case "formmethod": { + props.formMethod = attrValue; + break; + } + case "formnovalidate": { + props.formNoValidate = attrValue; + break; + } + case "formtarget": { + props.formTarget = attrValue; + break; + } + case "maxlength": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.maxLength = attrValue; + } + break; + } + case "minlength": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.minLength = attrValue; + } + break; + } + case "max": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.max = attrValue; + } + break; + } + case "min": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.min = attrValue; + } + break; + } + case "multiple": { + props.multiple = attrValue != null; + break; + } + case "readonly": { + props.readOnly = attrValue != null; + break; + } + case "required": { + props.required = attrValue != null; + break; + } + case "size": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.size = attrValue; + } + break; + } + case "step": { + if (attrValue === "any") { + props.step = attrValue; + break; + } + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue) && numValue > 0) { + props.step = attrValue; + } + break; + } + case "disabled": { + props.disabled = attrValue != null; + break; + } + case "rows": { + const numValue = parseInt(attrValue, 10); + if (!Number.isNaN(numValue)) { + props.rows = attrValue; + } + break; + } + default: { + props[attrName] = attrValue; + break; + } + } + } + return props; +}