From 53ad39a27c49a121467d56854e0e379e72fd829a Mon Sep 17 00:00:00 2001 From: Shane Friedman Date: Thu, 23 May 2024 10:45:23 -0400 Subject: [PATCH] Add support for multi-code-point unicode characters. Previously, `deleteContentBackward|Forward` inputs would delete exactly one code point. This created invalid strings when the last code point was part of a multi-code-point character. To resolve this, we now determine the length of the unicode character, and delete by that many code points, which matches default contentEditable behavior. --- demo/main.tsx | 2 +- docs/assets/index-43bfecdd.js | 53 ++++++ docs/assets/index-474d9858.js | 53 ------ docs/index.html | 2 +- src/plugins/beforeInputPlugin.ts | 112 ++++++------- src/strings/characters.ts | 280 +++++++++++++++++++++++++++++++ src/strings/direction.ts | 32 ++++ src/strings/words.ts | 59 +++++++ 8 files changed, 480 insertions(+), 113 deletions(-) create mode 100644 docs/assets/index-43bfecdd.js delete mode 100644 docs/assets/index-474d9858.js create mode 100644 src/strings/characters.ts create mode 100644 src/strings/direction.ts create mode 100644 src/strings/words.ts diff --git a/demo/main.tsx b/demo/main.tsx index fc328c4..924d563 100644 --- a/demo/main.tsx +++ b/demo/main.tsx @@ -117,7 +117,7 @@ const editorState = EditorState.create({ schema.nodes.image.create(), schema.nodes.paragraph.create( {}, - schema.text("This is the third paragraph") + schema.text("This is the third paragraph 🫵") ), schema.nodes.table.create({}, [ schema.nodes.table_row.create({}, [ diff --git a/docs/assets/index-43bfecdd.js b/docs/assets/index-43bfecdd.js new file mode 100644 index 0000000..9ddeb26 --- /dev/null +++ b/docs/assets/index-43bfecdd.js @@ -0,0 +1,53 @@ +(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 y1(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ep={exports:{}},rl={},tp={exports:{}},V={};/** + * @license React + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var fo=Symbol.for("react.element"),C1=Symbol.for("react.portal"),S1=Symbol.for("react.fragment"),k1=Symbol.for("react.strict_mode"),w1=Symbol.for("react.profiler"),v1=Symbol.for("react.provider"),D1=Symbol.for("react.context"),x1=Symbol.for("react.forward_ref"),E1=Symbol.for("react.suspense"),B1=Symbol.for("react.memo"),N1=Symbol.for("react.lazy"),Cf=Symbol.iterator;function A1(t){return t===null||typeof t!="object"?null:(t=Cf&&t[Cf]||t["@@iterator"],typeof t=="function"?t:null)}var np={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},rp=Object.assign,ip={};function qr(t,e,n){this.props=t,this.context=e,this.refs=ip,this.updater=n||np}qr.prototype.isReactComponent={};qr.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")};qr.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function op(){}op.prototype=qr.prototype;function ja(t,e,n){this.props=t,this.context=e,this.refs=ip,this.updater=n||np}var Ha=ja.prototype=new op;Ha.constructor=ja;rp(Ha,qr.prototype);Ha.isPureReactComponent=!0;var Sf=Array.isArray,sp=Object.prototype.hasOwnProperty,Ja={current:null},lp={key:!0,ref:!0,__self:!0,__source:!0};function up(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)sp.call(e,r)&&!lp.hasOwnProperty(r)&&(i[r]=e[r]);var l=arguments.length-2;if(l===1)i.children=n;else if(1>1}};he.from=function(t){if(t instanceof he)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new he(e)};function cp(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=cp(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function fp(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),u=s.nodeSize;if(s==l){n-=u,r-=u;continue}if(!s.sameMarkup(l))return{a:n,b:r};if(s.isText&&s.text!=l.text){let a=0,c=Math.min(s.text.length,l.text.length);for(;ae&&r(u,i+l,o||null,s)!==!1&&u.content.size){let c=l+1;u.nodesBetween(Math.max(0,e-c),Math.min(u.content.size,n-c),r,i+c)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let o="",s=!0;return this.nodesBetween(e,n,(l,u)=>{let a=l.isText?l.text.slice(Math.max(e,u)-u,n-u):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},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=u}return new w(r,i)}cutByIndex(e,n){return e==n?w.empty:e==0&&n==this.content.length?this:new w(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 w(i,o)}addToStart(e){return new w([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new w(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?Ao(r+1,s):Ao(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 w.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new w(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return w.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 v{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=hp(this.content,e+this.openStart,n);return r&&new v(r,this.openStart,this.openEnd)}removeBetween(e,n){return new v(dp(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 v.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 v(w.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 v(e,r,i)}}v.empty=new v(w.empty,0,0);function dp(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(dp(o.content,e-i-1,n-i-1)))}function hp(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=hp(s.content,e-o-1,n);return l&&t.replaceChild(i,s.copy(l))}function V1(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 pp(t,e,n,0)}function pp(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&&Eu(t,e,i+1),s=r.depth>i&&Eu(n,r,i+1),l=[];return ki(null,t,i,l),o&&s&&e.index(i)==n.index(i)?(mp(o,s),_n(Wn(o,gp(t,e,n,r,i+1)),l)):(o&&_n(Wn(o,ws(t,e,i+1)),l),ki(e,n,i,l),s&&_n(Wn(s,ws(n,r,i+1)),l)),ki(r,null,i,l),new w(l)}function ws(t,e,n){let r=[];if(ki(null,t,n,r),t.depth>n){let i=Eu(t,e,n+1);_n(Wn(i,ws(t,e,n+1)),r)}return ki(e,null,n,r),new w(r)}function $1(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(w.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Ii{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 W1(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:u}=s.content.findIndex(o),a=o-u;if(r.push(s,l,i+u),!a||(s=s.child(l),s.isText))break;o=a-1,i+=u+1}return new Ii(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()+")"),yp(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=w.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 u=i;un.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r=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=w.fromJSON(e,n.content);return e.nodeType(n.type).create(n.attrs,i,r)}}wt.prototype.text=void 0;class vs extends wt{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):yp(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 vs(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new vs(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 yp(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 j1(e,n);if(r.next==null)return Kn.empty;let i=Cp(r);r.next&&r.err("Unexpected trailing text");let o=G1(Y1(i));return X1(o,r),o}matchType(e){for(let n=0;na.createAndFill()));for(let a=0;a=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 j1{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 Cp(t){let e=[];do e.push(H1(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function H1(t){let e=[];do e.push(J1(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function J1(t){let e=Q1(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=K1(t,e);else break;return e}function vf(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function K1(t,e){let n=vf(t),r=n;return t.eat(",")&&(t.next!="}"?r=vf(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function q1(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 Q1(t){if(t.eat("(")){let e=Cp(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=q1(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 Y1(t){let e=[[]];return i(o(t,0),n()),e;function n(){return e.push([])-1}function r(s,l,u){let a={term:u,to:l};return e[s].push(a),a}function i(s,l){s.forEach(u=>u.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((u,a)=>u.concat(o(a,l)),[]);if(s.type=="seq")for(let u=0;;u++){let a=o(s.exprs[u],l);if(u==s.exprs.length-1)return a;i(a,l=n())}else if(s.type=="star"){let u=n();return r(l,u),i(o(s.expr,u),u),[r(u)]}else if(s.type=="plus"){let u=n();return i(o(s.expr,l),u),i(o(s.expr,u),u),[r(u)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let u=l;for(let a=0;a{t[s].forEach(({term:l,to:u})=>{if(!l)return;let a;for(let c=0;c{a||i.push([l,a=[]]),a.indexOf(c)==-1&&a.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 Dp(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 Z1{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class ho{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=vp(i.attrs),this.excluded=null;let o=kp(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,wp(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new ho(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}}class xp{constructor(e){this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=he.from(e.nodes),n.marks=he.from(e.marks||{}),this.nodes=xf.compile(this.spec.nodes,this),this.marks=ho.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?Ef(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==""?[]:Ef(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 xf){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 vs(r,r.defaultAttrs,e,W.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return wt.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 Ef(t,e){let n=[];for(let r=0;r-1)&&n.push(s=u)}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),v.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 u=s.getAttrs(n);if(u===!1)continue;s.attrs=u||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=Af(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=Af(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 Ep={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},ey={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Bp={ol:!0,ul:!0},Ds=1,xs=2,wi=4;function Bf(t,e,n){return e!=null?(e?Ds:0)|(e==="full"?xs:0):t&&t.whitespace=="pre"?Ds|xs:n&~wi}class Mo{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(w.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&Ds)){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=w.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(w.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=u}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(u=>this.insertNode(u));else{let u=e;typeof n.contentElement=="string"?u=e.querySelector(n.contentElement):typeof n.contentElement=="function"?u=n.contentElement(e):n.contentElement&&(u=n.contentElement),this.findAround(e,u,!0),this.addAll(u)}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,u)=>{for(;l>=0;l--){let a=n[l];if(a==""){if(l==n.length-1||l==0)continue;for(;u>=o;u--)if(s(l-1,u))return!0;return!1}else{let c=u>0||u==0&&i?this.nodes[u].type:r&&u>=o?r.node(u-o).type:null;if(!c||c.name!=a&&c.groups.indexOf(a)==-1)return!1;u--}}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=oy(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 ty(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Bp.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function ny(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ry(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 Af(t){let e={};for(let n in t)e[n]=t[n];return e}function iy(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 u=0;u{if(o.length||s.marks.length){let l=0,u=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&&It.renderSpec(Fl(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),u=n[1],a=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){a=2;for(let c in u)if(u[c]!=null){let f=c.indexOf(" ");f>0?l.setAttributeNS(c.slice(0,f),c.slice(f+1),u[c]):l.setAttribute(c,u[c])}}for(let c=a;ca)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}=It.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 It(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Mf(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Mf(e.marks)}}function Mf(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Fl(t){return t.document||window.document}const Np=65535,Ap=Math.pow(2,16);function sy(t,e){return t+e*Ap}function Of(t){return t&Np}function ly(t){return(t-(t&Np))/Ap}const Mp=1,Op=2,ts=4,Fp=8;let Bu=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Fp)>0}get deletedBefore(){return(this.delInfo&(Mp|ts))>0}get deletedAfter(){return(this.delInfo&(Op|ts))>0}get deletedAcross(){return(this.delInfo&ts)>0}},Tr=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 a=this.ranges[l+o],c=this.ranges[l+s],f=u+a;if(e<=f){let d=a?e==u?-1:e==f?1:n:n,p=u+i+(d<0?0:c);if(r)return p;let h=e==(n<0?u:f)?null:sy(l/3,e-u),m=e==u?Op:e==f?Mp:ts;return(n<0?e!=u:e!=f)&&(m|=Fp),new Bu(p,m,h)}i+=c-a}return r?e+i:new Bu(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 a=this.ranges[l+o],c=u+a;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-a}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 ns;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&u!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return be.fromReplace(e,this.from,this.to,o)}invert(){return new po(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 ui(n.pos,r.pos,this.mark)}merge(e){return e instanceof ui&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ui(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 ui(n.from,n.to,e.markFromJSON(n.mark))}};We.jsonID("addMark",Ga);let po=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 v(Ya(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return be.fromReplace(e,this.from,this.to,r)}invert(){return new Ga(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",po);let Xa=class ci extends We{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return be.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return be.fromReplace(e,this.pos,this.pos+1,new v(w.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 rs(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 rs(n.from,n.to,n.gapFrom,n.gapTo,v.fromJSON(e,n.slice),n.insert,!!n.structure)}};We.jsonID("replaceAround",Wt);function Au(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 ay(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(u,a,c)=>{if(!u.isInline)return;let f=u.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(a,e),p=Math.min(a+u.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(u)),o.forEach(u=>t.step(u))}function cy(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let u=null;if(r instanceof ho){let a=s.marks,c;for(;c=r.isInSet(a);)(u||(u=[])).push(c),a=c.removeFromSet(a)}else r?r.isInSet(s.marks)&&(u=[r]):u=s.marks;if(u&&u.length){let a=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new po(s.from,s.to,s.style)))}function fy(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 dy(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function ec(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=w.from(r.node(h).copy(c)),f++):u--;let d=w.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=w.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 v(r,0,0),n.length,!0))}function Cy(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)&&Sy(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let u=t.mapping.slice(o),a=u.map(l,1),c=u.map(l+s.nodeSize,1);return t.step(new Wt(a,c,a+1,c-1,new v(w.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function Sy(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function ky(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 v(w.from(s),0,0),1,!0))}function is(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 a=i.depth-1,c=n-2;a>o;a--,c--){let f=i.node(a),d=i.index(a);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),u=r&&r[0];return i.node(o).canReplaceWith(l,l,u?u.type:i.node(o+1).type)}function wy(t,e,n=1,r){let i=t.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,u=i.depth-n,a=n-1;l>u;l--,a--){o=w.from(i.node(l).copy(o));let c=r&&r[a];s=w.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new Dn(e,e,new v(o.append(s),n,n),!0))}function tc(t,e){let n=t.resolve(e),r=n.index();return vy(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function vy(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}function Dy(t,e,n){let r=new Dn(e-n,e+n,v.empty,!0);t.step(r)}function xy(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,u=r.index(s)+(l>0?1:0),a=r.node(s),c=!1;if(o==1)c=a.canReplace(u,u,i);else{let f=a.contentMatchAt(u).findWrapping(i.firstChild.type);c=f&&a.canReplaceWith(u,u,f[0])}if(c)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function nc(t,e,n=e,r=v.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return Tp(i,o,r)?new Dn(e,n,r):new By(i,o,r).fit()}function Tp(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}let By=class{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=w.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=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):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 u=new v(o,s,l);return e>-1?new Wt(r.pos,e,this.$to.pos,this.$to.end(),u,n):u.size||r.pos!=this.$to.pos?new Dn(r.pos,i.pos,u):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),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=Rl(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:u,match:a}=this.frontier[l],c,f=null;if(n==1&&(s?a.matchType(s.type)||(f=a.fillBefore(w.from(s),!1)):o&&u.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Rl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Rl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new v(fi(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new v(fi(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||u==0||m.content.size)&&(f=S,c.push(Rp(m.mark(d.allowedMarks(m.marks)),a==1?u:0,a==l.childCount?p:-1)))}let h=a==l.childCount;h||(p=-1),this.placed=di(this.placed,n,w.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:u,type:a}=this.frontier[l],c=Pl(e,l,a,u,!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=di(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=di(this.placed,this.depth,w.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(w.empty,!0);n.childCount&&(this.placed=di(this.placed,this.frontier.length,n))}};function fi(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(fi(t.firstChild.content,e-1,n)))}function di(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(di(t.lastChild.content,e-1,n)))}function Rl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Rp(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(w.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&&!Ny(n,o.content,s)?l:null}function Ny(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 u=s.indexOf(l),a=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(a.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=a[d].type,h=Ay(p);if(h&&i.node(u).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=a[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 Pp(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(w.empty,!0))}return t}function Oy(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=xy(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new v(w.from(r),0,0))}function Fy(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=zp(r,i);for(let s=0;s0&&(u||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 zp(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 bp=class ss 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 be.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 be.fromReplace(e,this.pos,this.pos+1,new v(w.from(i),0,n.isLeaf?0:1))}getMap(){return Tr.empty}invert(e){return new ss(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 ss(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 ss(n.pos,n.attr,n.value)}};We.jsonID("attr",bp);let Rr=class extends Error{};Rr=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Rr.prototype=Object.create(Error.prototype);Rr.prototype.constructor=Rr;Rr.prototype.name="TransformError";let Ty=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new uy}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Rr(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=v.empty){let i=nc(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new v(w.from(r),0,0))}delete(e,n){return this.replace(e,n,v.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return My(this,e,n,r),this}replaceRangeWith(e,n,r){return Oy(this,e,n,r),this}deleteRange(e,n){return Fy(this,e,n),this}lift(e,n){return hy(this,e,n),this}join(e,n=1){return Dy(this,e,n),this}wrap(e,n){return yy(this,e,n),this}setBlockType(e,n=e,r,i=null){return Cy(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return ky(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new bp(e,n,r)),this}addNodeMark(e,n){return this.step(new Xa(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 Za(e,n)),this}split(e,n=1,r){return wy(this,e,n,r),this}addMark(e,n,r){return ay(this,e,n,r),this}removeMark(e,n,r){return cy(this,e,n,r),this}clearIncompatible(e,n,r){return fy(this,e,n,r),this}};const zl=Object.create(null);class z{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Ip(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 L.between(this.$anchor,this.$head).getBookmark()}}z.prototype.visible=!0;class Ip{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 L extends z{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 z.near(r);let i=e.resolve(n.map(this.anchor));return new L(i.parent.inlineContent?i:r,r)}replace(e,n=v.empty){if(super.replace(e,n),n==v.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof L&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new il(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 L(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=z.findFrom(n,r,!0)||z.findFrom(n,-r,!0);if(o)n=o.$head;else return z.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(z.findFrom(e,-r,!0)||z.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&&P.isSelectable(l))return P.create(t,n-(i<0?l.nodeSize:0))}else{let u=lr(t,l,n+i,i<0?l.childCount:0,i,o);if(u)return u}n+=l.nodeSize*i}return null}function Pf(t,e,n){let r=t.steps.length-1;if(r{s==null&&(s=c)}),t.setSelection(z.near(t.doc.resolve(s),n))}const zf=1,Oo=2,bf=4;class Py extends Ty{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|=Oo,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&Oo)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Oo,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(z.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|=bf,this}get scrolledIntoView(){return(this.updated&bf)>0}}function If(t,e){return!e||!t?t:t.bind(e)}class hi{constructor(e,n,r){this.name=e,this.init=If(n.init,r),this.apply=If(n.apply,r)}}const zy=[new hi("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new hi("selection",{init(t,e){return t.selection||z.atStart(e.doc)},apply(t){return t.selection}}),new hi("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new hi("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=zy.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 hi(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=wt.fromJSON(e.schema,n.doc);else if(s.name=="selection")o.selection=z.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 u=r[l],a=u.spec.state;if(u.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){o[s.name]=a.fromJSON.call(u,e,n[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function Lp(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Lp(i,e,{})),n[r]=i}return n}class Mt{constructor(e){this.spec=e,this.props={},e.props&&Lp(e.props,this,this.props),this.key=e.key?e.key.key:Vp("plugin")}getState(e){return e[this.key]}}const Il=Object.create(null);function Vp(t){return t in Il?t+"$"+ ++Il[t]:(Il[t]=0,t+"$")}class mo{constructor(e="key"){this.key=Vp(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const $p=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function by(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const Iy=(t,e,n)=>{let r=by(t,n);if(!r)return!1;let i=_p(r);if(!i){let s=r.blockRange(),l=s&&ec(s);return l==null?!1:(e&&e(t.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Up(t,i,e))return!0;if(r.parent.content.size==0&&(Pr(o,"end")||P.isSelectable(o))){let s=nc(t.doc,r.before(),r.after(),v.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=_p(r)}let s=o&&o.nodeBefore;return!s||!P.isSelectable(s)?!1:(e&&e(t.tr.setSelection(P.create(t.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function _p(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 Vy(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=Vy(t,n);if(!r)return!1;let i=Wp(r);if(!i)return!1;let o=i.nodeAfter;if(Up(t,i,e))return!0;if(r.parent.content.size==0&&(Pr(o,"start")||P.isSelectable(o))){let s=nc(t.doc,r.before(),r.after(),v.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 ic(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=ic(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=n.after(),u=t.tr.replaceWith(l,l,s.createAndFill());u.setSelection(z.near(u.doc.resolve(l),1)),e(u.scrollIntoView())}return!0},jy=(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=ic(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(is(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&ec(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function Jy(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof P&&e.selection.node.isBlock)return!r.parentOffset||!is(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 L||e.selection instanceof Je)&&s.deleteSelection();let l=r.depth==0?null:ic(r.node(-1).contentMatchAt(r.indexAfter(-1))),u=t&&t(i.parent,o),a=u?[u]:o&&l?[{type:l}]:void 0,c=is(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!c&&is(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),c=!0),c&&(s.split(s.mapping.map(r.pos),1,a),!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 Ky=Jy(),qy=(t,e)=>(e&&e(t.tr.setSelection(new Je(t.doc))),!0);function Qy(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||tc(t.doc,e.pos))?!1:(n&&n(t.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Up(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,o,s;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Qy(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=w.empty;for(let m=o.length-1;m>=0;m--)d=w.from(o[m].create(null,d));d=w.from(r.copy(d));let p=t.tr.step(new Wt(e.pos-1,f,e.pos,f,new v(d,1,0),o.length,!0)),h=f+2*o.length;tc(p.doc,h)&&p.join(h),n(p.scrollIntoView())}return!0}let u=z.findFrom(e,1),a=u&&u.$from.blockRange(u.$to),c=a&&ec(a);if(c!=null&&c>=e.depth)return n&&n(t.tr.lift(a,c).scrollIntoView()),!0;if(l&&Pr(i,"start",!0)&&Pr(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=w.empty;for(let g=d.length-1;g>=0;g--)m=w.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 v(m,d.length,0),0,!0));n(S.scrollIntoView())}return!0}}return!1}function jp(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(L.create(e.doc,t<0?i.start(o):i.end(o)))),!0):!1}}const Yy=jp(-1),Gy=jp(1);function Xy(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 Lf(t,e=null){return function(n,r){let{empty:i,$cursor:o,ranges:s}=n.selection;if(i&&!o||!Xy(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,u=n.tr;for(let a=0;!l&&a",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},$f=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent),tC=typeof navigator<"u"&&/Mac/.test(navigator.platform),nC=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),rC=tC||$f&&+$f[1]<57;for(var me=0;me<10;me++)Ut[48+me]=Ut[96+me]=String(me);for(var me=1;me<=24;me++)Ut[me+111]="F"+me;for(var me=65;me<=90;me++)Ut[me]=String.fromCharCode(me+32),Es[me]=String.fromCharCode(me);for(var Vl in Ut)Es.hasOwnProperty(Vl)||(Es[Vl]=Ut[Vl]);function Jp(t){var e=rC&&(t.ctrlKey||t.altKey||t.metaKey)||nC&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Es: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 iC=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function oC(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[$l(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Ne=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},Vi=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let _f=null;const Rt=function(t,e,n){let r=_f||(_f=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},qn=function(t,e,n,r){return n&&(Wf(t,e,n,r,-1)||Wf(t,e,n,r,1))},lC=/^(img|br|input|textarea|hr)$/i;function Wf(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Ct(t))){let o=t.parentNode;if(!o||o.nodeType!=1||sc(t)||lC.test(t.nodeName)||t.contentEditable=="false")return!1;e=Ne(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?Ct(t):0}else return!1}}function Ct(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function uC(t,e,n){for(let r=e==0,i=e==Ct(t);r||i;){if(t==n)return!0;let o=Ne(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==Ct(t)}}function sc(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 ol=function(t){return t.focusNode&&qn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Pn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function aC(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function cC(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 Et=typeof navigator<"u"?navigator:null,Uf=typeof document<"u"?document:null,xn=Et&&Et.userAgent||"",Mu=/Edge\/(\d+)/.exec(xn),qp=/MSIE \d/.exec(xn),Ou=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(xn),Le=!!(qp||Ou||Mu),fn=qp?document.documentMode:Ou?+Ou[1]:Mu?+Mu[1]:0,pt=!Le&&/gecko\/(\d+)/i.test(xn);pt&&+(/Firefox\/(\d+)/.exec(xn)||[0,0])[1];const Fu=!Le&&/Chrome\/(\d+)/.exec(xn),De=!!Fu,fC=Fu?+Fu[1]:0,Oe=!Le&&!!Et&&/Apple Computer/.test(Et.vendor),zr=Oe&&(/Mobile\/\w+/.test(xn)||!!Et&&Et.maxTouchPoints>2),Ge=zr||(Et?/Mac/.test(Et.platform):!1),dC=Et?/Win/.test(Et.platform):!1,ct=/Android \d/.test(xn),go=!!Uf&&"webkitFontSmoothing"in Uf.documentElement.style,hC=go?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pC(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Ft(t,e){return typeof t=="number"?t:t[e]}function mC(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 jf(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=Vi(s)){if(s.nodeType!=1)continue;let l=s,u=l==o.body,a=u?pC(o):mC(l),c=0,f=0;if(e.topa.bottom-Ft(r,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+Ft(i,"top")-a.top:e.bottom-a.bottom+Ft(i,"bottom")),e.lefta.right-Ft(r,"right")&&(c=e.right-a.right+Ft(i,"right")),c||f)if(u)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(u||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gC(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=u.top;break}}return{refDOM:r,refTop:i,stack:Qp(t.dom)}}function Qp(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=Vi(r));return e}function yC({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Yp(n,r==0?0:r-e)}function Yp(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&&!u&&h.left<=e.left&&h.right>=e.left&&(u=c,a={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&&u&&(n=u,i=a,r=0),n&&n.nodeType==3?SC(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Gp(n,i)}function SC(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 lc(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function kC(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 vC(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 u=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!s&&(s=!0,u.left>r.left||u.top>r.top?i=l.posBefore:(u.right-1?i:t.docView.posFromDOM(e,n,-1)}function Xp(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let a;go&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.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=vC(t,r,i,e))}l==null&&(l=wC(t,s,e));let u=t.docView.nearestDesc(s,!0);return{pos:l,inside:u?u.posAtStart-u.border:-1}}function Hf(t){return t.top=0&&i==r.nodeValue.length?(u--,c=1):n<0?u--:a++,Xr(Yt(Rt(r,u,a),c),c<0)}if(!t.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(n<0||i==Ct(r))){let u=r.childNodes[i-1];if(u.nodeType==1)return _l(u.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(n<0||i==Ct(r))){let u=r.childNodes[i-1],a=u.nodeType==3?Rt(u,Ct(u)-(s?0:1)):u.nodeType==1&&(u.nodeName!="BR"||!u.nextSibling)?u:null;if(a)return Xr(Yt(a,1),!1)}if(o==null&&i=0)}function Xr(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 _l(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 em(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 EC(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return em(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=Zp(t,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let u;if(l.nodeType==1)u=l.getClientRects();else if(l.nodeType==3)u=Rt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ac.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 BC=/[\u0590-\u08ac]/;function NC(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!BC.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?o:s:em(t,e,()=>{let{focusNode:u,focusOffset:a,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)||u==h&&a==m;try{l.collapse(c,f),u&&(u!=c||a!=f)&&l.extend&&l.extend(u,a)}catch{}return d!=null&&(l.caretBidiLevel=d),S})}let Jf=null,Kf=null,qf=!1;function AC(t,e,n){return Jf==e&&Kf==n?qf:(Jf=e,Kf=n,qf=n=="up"||n=="down"?EC(t,e,n):NC(t,e,n))}const nt=0,Qf=1,bn=2,Bt=3;let yo=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;nNe(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 om){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 tm&&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?Ne(o.dom)+1:0}}else{let o,s=!0;for(;o=r=c&&n<=a-u.border&&u.node&&u.contentDOM&&this.contentDOM.contains(u.contentDOM))return u.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=Ne(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(a>n||l==this.children.length-1)){n=a;for(let c=l+1;cp&&sn){let p=l;l=u,u=p}let d=document.createRange();d.setEnd(u.node,u.offset),d.setStart(l.node,l.offset),a.removeAllRanges(),a.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,u=s-o.border;if(e>=l&&n<=u){this.dirty=e==r||n==s?bn:Qf,e==l&&n==u&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Bt:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?bn:Bt}r=s}this.dirty=bn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?bn:Qf;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}},MC=class extends yo{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}},Bs=class Tu extends yo{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=It.renderSpec(document,n.type.spec.toDOM(n,r))),new Tu(e,n,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Bt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Bt&&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=zu(o,0,e,r));for(let l=0;l{if(!u)return s;if(u.parent)return u.parent.posBeforeChild(u)},r,i),c=a&&a.dom,f=a&&a.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}=It.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=um(c,r,n),a?u=new OC(e,n,r,i,c,f||null,d,a,o,s+1):n.isText?new rm(e,n,r,i,c,d,o):new nm(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=()=>w.empty)}return e}matchesNode(e,n,r){return this.dirty==nt&&e.eq(this.node)&&Pu(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,u=new TC(this,s&&s.node,e);zC(this.node,this.innerDeco,(a,c,f)=>{a.spec.marks?u.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!f&&u.syncToMarks(c==this.node.childCount?W.none:this.node.child(c).marks,r,e),u.placeWidget(a,e,i)},(a,c,f,d)=>{u.syncToMarks(a.marks,r,e);let p;u.findNodeMatch(a,c,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&u.updateNodeAt(a,c,f,p,e)||u.updateNextNode(a,c,f,e,d,i)||u.addNode(a,c,f,e,i),i+=a.nodeSize}),u.syncToMarks([],r,e),this.node.isTextblock&&u.addTextblockHacks(),u.destroyRest(),(u.changed||this.dirty==bn)&&(s&&this.protectLocalComposition(e,s),sm(this.contentDOM,this.children,e),zr&&bC(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof L)||rn+this.node.content.size)return null;let o=e.domSelectionRange(),s=IC(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,u=LC(this.node.content,l,r-n,i-n);return u<0?null:{node:s,pos:u,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 MC(this,o,n,i);e.input.compositionNodes.push(s),this.children=zu(this.children,r,r+i.length,e,s)}update(e,n,r,i){return this.dirty==Bt||!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(Pu(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=lm(this.dom,this.nodeDOM,Ru(this.outerDeco,this.node,n),Ru(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 Yf(t,e,n,r,i){um(r,e,t);let o=new Dr(void 0,t,e,n,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}let rm=class im extends Dr{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==Bt||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 im(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=Bt)}get domAtom(){return!1}},om=class extends yo{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 OC extends Dr{constructor(e,n,r,i,o,s,l,u,a,c){super(e,n,r,i,o,s,l,a,c),this.spec=u}update(e,n,r,i){if(this.dirty==Bt)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 sm(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 u=Bs.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,u),this.top=u,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,u=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=n.children[r-1];if(a instanceof Bs)n=a,r=a.children.length;else{l=a,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let u=l.node;if(u){if(u!=t.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function PC(t,e){return t.type.side-e.type.side}function zC(t,e,n,r){let i=e.locals(t),o=0;if(i.length==0){for(let a=0;ao;)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 bC(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 IC(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=Ct(t)}else if(t.nodeType==1&&e=n){if(o>=r&&u.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=n)return l+a;if(n==r&&u.length>=r+e.length-l&&u.slice(r-l,r-l+e.length)==e)return r}}return-1}function zu(t,e,n,r,i){let o=[];for(let s=0,l=0;s=n||c<=e?o.push(u):(an&&o.push(u.slice(n-a,u.size,r)))}return o}function uc(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),u,a;if(ol(n)){for(u=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&P.isSelectable(c)&&i.parent&&!(c.isInline&&uC(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;a=new P(s==f?l:r.resolve(f))}}else{let c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;u=r.resolve(c)}if(!a){let c=e=="pointer"||t.state.selection.head{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!am(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function $C(t){let e=t.domSelection(),n=document.createRange(),r=t.cursorWrapper.dom,i=r.nodeName=="IMG";i?n.setEnd(r.parentNode,Ne(r)+1):n.setEnd(r,0),n.collapse(!1),e.removeAllRanges(),e.addRange(n),!i&&!t.state.selection.visible&&Le&&fn<=11&&(r.disabled=!0,r.disabled=!1)}function cm(t,e){if(e instanceof P){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(td(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else td(t)}function td(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function ac(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||L.between(e,n,r)}function nd(t){return t.editable&&!t.hasFocus()?!1:fm(t)}function fm(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 _C(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 bu(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&&z.findFrom(o,e)}function Gt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function rd(t,e,n){let r=t.state.selection;if(r instanceof L)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 L(r.$anchor,s))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=bu(t.state,e);return i&&i instanceof P?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?P.isSelectable(o)?Gt(t,new P(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):go?Gt(t,new L(t.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof P&&r.node.isInline)return Gt(t,new L(e>0?r.$to:r.$from));{let i=bu(t.state,e);return i?Gt(t,i):!1}}}function Ns(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Di(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?WC(t):UC(t)}function WC(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(Di(l,-1))i=n,o=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(dm(n))break;{let l=n.previousSibling;for(;l&&Di(l,-1);)i=n.parentNode,o=Ne(l),l=l.previousSibling;if(l)n=l,r=Ns(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Iu(t,n,r):i&&Iu(t,i,o)}function UC(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Ns(n),o,s;for(;;)if(r{t.state==i&&$t(t)},50)}function id(t,e){let n=t.state.doc.resolve(e);if(!(De||dC)&&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 od(t,e,n){let r=t.state.selection;if(r instanceof L&&!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=bu(t.state,e);if(s&&s instanceof P)return Gt(t,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Je?z.near(s,e):z.findFrom(s,e);return l?Gt(t,l):!1}return!1}function sd(t,e){if(!(t.state.selection instanceof L))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 ld(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function JC(t){if(!Oe||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;ld(t,r,"true"),setTimeout(()=>ld(t,r,"false"),20)}return!1}function KC(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function qC(t,e){let n=e.keyCode,r=KC(e);if(n==8||Ge&&n==72&&r=="c")return sd(t,-1)||ir(t,-1);if(n==46&&!e.shiftKey||Ge&&n==68&&r=="c")return sd(t,1)||ir(t,1);if(n==13||n==27)return!0;if(n==37||Ge&&n==66&&r=="c"){let i=n==37?id(t,t.state.selection.from)=="ltr"?-1:1:-1;return rd(t,i,r)||ir(t,i)}else if(n==39||Ge&&n==70&&r=="c"){let i=n==39?id(t,t.state.selection.from)=="ltr"?1:-1:1;return rd(t,i,r)||ir(t,i)}else{if(n==38||Ge&&n==80&&r=="c")return od(t,-1,r)||ir(t,-1);if(n==40||Ge&&n==78&&r=="c")return JC(t)||od(t,1,r)||ir(t,1);if(r==(Ge?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function hm(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")||It.fromSchema(t.state.schema),l=Sm(),u=l.createElement("div");u.appendChild(s.serializeFragment(r,{document:l}));let a=u.firstChild,c,f=0;for(;a&&a.nodeType==1&&(c=Cm[a.nodeName.toLowerCase()]);){for(let p=c.length-1;p>=0;p--){let h=l.createElement(c[p]);for(;u.firstChild;)h.appendChild(u.firstChild);u.appendChild(h),f++}a=u.firstChild}a&&a.nodeType==1&&a.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:u,text:d}}function pm(t,e,n,r,i){let o=i.parent.type.spec.code,s,l;if(!n&&!e)return null;let u=e&&(r||o||!n);if(u){if(t.someProp("transformPastedText",d=>{e=d(e,o||r,t)}),o)return e?new v(w.from(t.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):v.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=It.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=GC(n),go&&XC(s);let a=s&&s.querySelector("[data-pm-slice]"),c=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.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:!!(u||c),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!QC.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=ZC(ud(l,+c[1],+c[2]),c[4]);else if(l=v.maxOpen(YC(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 QC=/^(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 YC(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 u=i.findWrapping(l.type),a;if(!u)return s=null;if(a=s.length&&o.length&&gm(u,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=ym(s[s.length-1],o.length));let c=mm(l,u);s.push(c),i=i.matchType(c.type),o=u}}),s)return w.from(s)}return t}function mm(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,w.from(t));return t}function gm(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(w.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,s.copy(l))}function ud(t,e,n){return e]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Sm().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&Cm[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 u=n.nodes[r[l]];if(!u||u.hasRequiredAttrs())break;i=w.from(u.create(r[l+1],i)),o++,s++}return new v(i,o,s)}const Fe={},Te={},eS={touchstart:!0,touchmove:!0};class tS{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 nS(t){for(let e in Fe){let n=Fe[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{iS(t,r)&&!cc(t,r)&&(t.editable||!(r.type in Te))&&n(t,r)},eS[e]?{passive:!0}:void 0)}Oe&&t.dom.addEventListener("input",()=>null),Vu(t)}function sn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function rS(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 Vu(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>cc(t,r))})}function cc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function iS(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 oS(t,e){!cc(t,e)&&Fe[e.type]&&(t.editable||!(e.type in Te))&&Fe[e.type](t,e)}Te.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!wm(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(ct&&De&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),zr&&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,Pn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||qC(t,n)?n.preventDefault():sn(t,"key")};Te.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Te.keypress=(t,e)=>{let n=e;if(wm(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 L)||!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 sl(t){return{left:t.clientX,top:t.clientY}}function sS(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function fc(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 xr(t,e,n){t.focused||t.focus();let r=t.state.tr.setSelection(e);n=="pointer"&&r.setMeta("pointer",!0),t.dispatch(r)}function lS(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&P.isSelectable(r)?(xr(t,new P(n),"pointer"),!0):!1}function uS(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof P&&(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(P.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?(xr(t,P.create(t.state.doc,i),"pointer"),!0):!1}function aS(t,e,n,r,i){return fc(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?uS(t,n):lS(t,n))}function cS(t,e,n,r){return fc(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function fS(t,e,n,r){return fc(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||dS(t,n,r)}function dS(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(xr(t,L.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)xr(t,L.create(r,l+1,l+1+s.content.size),"pointer");else if(P.isSelectable(s))xr(t,P.create(r,l),"pointer");else continue;return!0}}function dc(t){return As(t)}const km=Ge?"metaKey":"ctrlKey";Fe.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=dc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&sS(n,t.input.lastClick)&&!n[km]&&(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(sl(n));s&&(o=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new hS(t,s,n,!!r)):(o=="doubleClick"?cS:fS)(t,s.pos,s.inside,n)?n.preventDefault():sn(t,"pointer"))};class hS{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[km],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,u=l?e.docView.nearestDesc(l,!0):null;this.target=u?u.dom:null;let{selection:a}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof P&&a.from<=s&&a.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(sl(e))),this.updateAllowDefault(e),this.allowDefault||!n?sn(this.view,"pointer"):aS(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Oe&&this.mightDrag&&!this.mightDrag.node.isAtom||De&&!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)?(xr(this.view,z.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)}}Fe.touchstart=t=>{t.input.lastTouch=Date.now(),dc(t),sn(t,"pointer")};Fe.touchmove=t=>{t.input.lastTouch=Date.now(),sn(t,"pointer")};Fe.contextmenu=t=>dc(t);function wm(t,e){return t.composing?!0:Oe&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const pS=ct?5e3:-1;Te.compositionstart=Te.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(),As(t,!0),t.markCursor=null;else if(As(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}vm(t,pS)};Te.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++,vm(t,20))};function vm(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>As(t),e))}function Dm(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=mS());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function mS(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function As(t,e=!1){if(!(ct&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Dm(t),e||t.docView&&t.docView.dirty){let n=uc(t);return n&&!n.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(n)):t.updateState(t.state),!0}return!1}}function gS(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 $i=Le&&fn<15||zr&&hC<604;Fe.copy=Te.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let o=$i?null:n.clipboardData,s=r.content(),{dom:l,text:u}=hm(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",u)):gS(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function yS(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function CS(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=pm(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",u=>u(t,i,o||v.empty)))return!0;if(!o)return!1;let s=yS(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 xm(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," "):""}Te.paste=(t,e)=>{let n=e;if(t.composing&&!ct)return;let r=$i?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&_i(t,xm(r),r.getData("text/html"),i,n)?n.preventDefault():CS(t,n)};class Em{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const Bm=Ge?"altKey":"ctrlKey";Fe.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(sl(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof P?i.to-1:i.to))){if(r&&r.mightDrag)s=P.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=P.create(t.state.doc,c.posBefore))}}let l=(s||t.state.selection).content(),{dom:u,text:a}=hm(t,l);n.dataTransfer.clearData(),n.dataTransfer.setData($i?"Text":"text/html",u.innerHTML),n.dataTransfer.effectAllowed="copyMove",$i||n.dataTransfer.setData("text/plain",a),t.dragging=new Em(l,!n[Bm],s)};Fe.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Te.dragover=Te.dragenter=(t,e)=>e.preventDefault();Te.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let i=t.posAtCoords(sl(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=pm(t,xm(n.dataTransfer),$i?null:n.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!n[Bm]);if(t.someProp("handleDrop",h=>h(t,n,s||v.empty,l))){n.preventDefault();return}if(!s)return;n.preventDefault();let u=s?Ey(t.state.doc,o.pos,s):o.pos;u==null&&(u=o.pos);let a=t.state.tr;if(l){let{node:h}=r;h?h.replace(a):a.deleteSelection()}let c=a.mapping.map(u),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(d))return;let p=a.doc.resolve(c);if(f&&P.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new P(p));else{let h=a.mapping.map(u);a.mapping.maps[a.mapping.maps.length-1].forEach((m,S,g,y)=>h=y),a.setSelection(ac(t,p,a.doc.resolve(h)))}t.focus(),t.dispatch(a.setMeta("uiEvent","drop"))};Fe.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))};Fe.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)};Fe.beforeinput=(t,e)=>{if(De&&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,Pn(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 Te)Fe[t]=Te[t];function Wi(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 Ms{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 ge(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Ms&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Wi(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 ge(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 a=u+r,c;if(c=Mm(n,l,a)){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&&u.type instanceof dn){let a=Math.max(o,u.from)-o,c=Math.min(s,u.to)-o;ai.map(e,n,Un));return ar.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 SS(t,e,n,r,i,o,s){let l=t.slice();for(let a=0,c=o;a{let S=m-h-(p-d);for(let g=0;gy+c-f)continue;let C=l[g]+c-f;p>=C?l[g+1]=d<=C?-2:-1:d>=c&&S&&(l[g]+=S,l[g+1]+=S)}f+=S}),c=n.maps[a].map(c,-1)}let u=!1;for(let a=0;a=r.content.size){u=!0;continue}let d=n.map(t[a+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[a+2].mapInner(n,S,c+1,t[a]+o+1,s);g!=we?(l[a]=f,l[a+1]=p,l[a+2]=g):(l[a+1]=-2,u=!0)}else u=!0}if(u){let a=kS(l,t,e,n,i,o,s),c=Os(a,r,0,s);e=c.local;for(let f=0;fn&&s.to{let a=Mm(t,l,u+n);if(a){o=!0;let c=Os(a,l,n+u+1,r);c!=we&&i.push(u,u+l.nodeSize,c)}});let s=Am(o?Om(t):t,-n).sort(jn);for(let l=0;l0;)e++;t.splice(e,0,n)}function Ul(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])),Nm.from(e)}const wS={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},vS=Le&&fn<=11;let DS=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 xS{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new DS,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()}),vS&&(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,wS)),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(nd(this.view)){if(this.suppressingSelectionUpdates)return $t(this.view);if(Le&&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=Vi(o))n.add(o);for(let o=e.anchorNode;o;o=Vi(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)&&nd(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,u=[];if(e.editable)for(let c=0;c1){let c=u.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 a=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),ES(e)),this.handleDOMChange(o,s,l,u),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:a,ruleFromNode:AS,context:p});if(a&&a[0].pos!=null){let S=a[0].pos,g=a[1]&&a[1].pos;g==null&&(g=S),h={anchor:S+s,head:g+s}}return{doc:m,sel:h,from:s,to:l}}function AS(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Oe&&/^(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||Oe&&/^(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 MS=/^(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 OS(t,e,n,r,i){let o=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let B=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,T=uc(t,B);if(T&&!t.state.selection.eq(T)){if(De&&ct&&t.input.lastKeyCode===13&&Date.now()-100Ot(t,Pn(13,"Enter"))))return;let ne=t.state.tr.setSelection(T);B=="pointer"?ne.setMeta("pointer",!0):B=="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 u=t.state.selection,a=NS(t,e,n),c=t.state.doc,f=c.slice(a.from,a.to),d,p;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ct)&&i.some(B=>B.nodeType==1&&!MS.test(B.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",B=>B(t,Pn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!h)if(r&&u instanceof L&&!u.empty&&u.$head.sameParent(u.$anchor)&&!t.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))h={start:u.from,endA:u.to,endB:u.to};else{if(a.sel){let B=hd(t,t.state.doc,a.sel);if(B&&!B.eq(t.state.selection)){let T=t.state.tr.setSelection(B);o&&T.setMeta("composition",o),t.dispatch(T)}}return}if(De&&t.cursorWrapper&&a.sel&&a.sel.anchor==t.cursorWrapper.deco.from&&a.sel.head==a.sel.anchor){let B=h.endB-h.start;a.sel={anchor:a.sel.anchor+B,head:a.sel.anchor+B}}t.input.domChangeCount++,t.state.selection.fromt.state.selection.from&&h.start<=t.state.selection.from+2&&t.state.selection.from>=a.from?h.start=t.state.selection.from:h.endA=t.state.selection.to-2&&t.state.selection.to<=a.to&&(h.endB+=t.state.selection.to-h.endA,h.endA=t.state.selection.to)),Le&&fn<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>a.from&&a.doc.textBetween(h.start-a.from-1,h.start-a.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=a.doc.resolveNoCache(h.start-a.from),S=a.doc.resolveNoCache(h.endB-a.from),g=c.resolve(h.start),y=m.sameParent(S)&&m.parent.inlineContent&&g.end()>=h.endA,C;if((zr&&t.input.lastIOSEnter>Date.now()-225&&(!y||i.some(B=>B.nodeName=="DIV"||B.nodeName=="P"))||!y&&m.posB(t,Pn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&TS(c,h.start,h.endA,m,S)&&t.someProp("handleKeyDown",B=>B(t,Pn(8,"Backspace")))){ct&&De&&t.domObserver.suppressSelectionUpdates();return}De&&ct&&h.endB==h.start&&(t.input.lastAndroidDelete=Date.now()),ct&&!y&&m.start()!=S.start()&&S.parentOffset==0&&m.depth==S.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==h.endA&&(h.endB-=2,S=a.doc.resolveNoCache(h.endB-a.from),setTimeout(()=>{t.someProp("handleKeyDown",function(B){return B(t,Pn(13,"Enter"))})},20));let k=h.start,E=h.endA,N,A,O;if(y){if(m.pos==S.pos)Le&&fn<=11&&m.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>$t(t),20)),N=t.state.tr.delete(k,E),A=c.resolve(h.start).marksAcross(c.resolve(h.endA));else if(h.endA==h.endB&&(O=FS(m.parent.content.cut(m.parentOffset,S.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))N=t.state.tr,O.type=="add"?N.addMark(k,E,O.mark):N.removeMark(k,E,O.mark);else if(m.parent.child(m.index()).isText&&m.index()==S.index()-(S.textOffset?0:1)){let B=m.parent.textBetween(m.parentOffset,S.parentOffset);if(t.someProp("handleTextInput",T=>T(t,k,E,B)))return;N=t.state.tr.insertText(B,k,E)}}if(N||(N=t.state.tr.replace(k,E,a.doc.slice(h.start-a.from,h.endB-a.from))),a.sel){let B=hd(t,N.doc,a.sel);B&&!(De&&ct&&t.composing&&B.empty&&(h.start!=h.endB||t.input.lastAndroidDeletee.content.size?null:ac(t,e.resolve(n.anchor),e.resolve(n.head))}function FS(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,o=r,s,l,u;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",u=c=>c.mark(l.removeFromSet(c.marks));else return null;let a=[];for(let c=0;cn||jl(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 RS(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 u=Math.max(0,o-Math.min(s,l));r-=s+u-o}if(s=s?o-r:0;o-=u,o&&o=l?o-r:0;o-=u,o&&o=56320&&e<=57343&&n>=55296&&n<=56319}class PS{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 tS,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Sd),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=yd(this),gd(this),this.nodeViews=Cd(this),this.docView=Yf(this.state.doc,md(this),Ul(this),this.dom,this),this.domObserver=new xS(this,(r,i,o,s)=>OS(this,r,i,o,s)),this.domObserver.start(),nS(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&&Vu(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Sd),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&&(Dm(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=Cd(this);bS(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&Vu(this),this.editable=yd(this),gd(this);let u=Ul(this),a=md(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,a,u);(f||!e.selection.eq(i.selection))&&(s=!0);let d=c=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gC(this);if(s){this.domObserver.stop();let p=f&&(Le||De)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&zS(i.selection,e.selection);if(f){let h=De?this.trackWrites=this.domSelectionRange().focusNode:null;(o||!this.docView.update(e.doc,a,u,this))&&(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Yf(e.doc,a,u,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_C(this))?$t(this,p):(cm(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&&yC(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof P){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&jf(this,n.getBoundingClientRect(),e)}else jf(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 Em(e.slice,e.move,i<0?void 0:P.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 DC(this,e)}coordsAtPos(e,n=1){return Zp(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 AC(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&&(rS(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ul(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 oS(this,e)}dispatch(e){let n=this._props.dispatchTransaction;n?n.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return Oe&&this.root.nodeType===11&&aC(this.dom.ownerDocument)==this.dom?BS(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function md(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"),[ge.node(0,t.state.doc.content.size,e)]}function gd(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:ge.widget(t.state.selection.head,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function yd(t){return!t.someProp("editable",e=>e(t.state)===!1)}function zS(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 Cd(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 bS(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 Sd(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 z{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return Z.valid(r)?new Z(r):z.near(r)}content(){return v.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 mc(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!IS(e)||!LS(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 u=e.doc.resolve(i);if(Z.valid(u))return u}for(;;){let s=n>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!P.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;z.jsonID("gapcursor",Z);class mc{constructor(e){this.pos=e}map(e){return new mc(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Z.valid(n)?new Z(n):z.near(n)}}function IS(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 LS(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 VS(){return new Mt({props:{decorations:US,createSelectionBetween(t,e,n){return e.pos==n.pos&&Z.valid(n)?new Z(n):null},handleClick:_S,handleKeyDown:$S,handleDOMEvents:{beforeinput:WS}}})}const $S=Kp({ArrowLeft:Fo("horiz",-1),ArrowRight:Fo("horiz",1),ArrowUp:Fo("vert",-1),ArrowDown:Fo("vert",1)});function Fo(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,u=s.empty;if(s instanceof L){if(!o.endOfTextblock(n)||l.depth==0)return!1;u=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=Z.findGapCursorFrom(l,e,u);return a?(i&&i(r.tr.setSelection(new Z(a))),!0):!1}}function _S(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&&P.isSelectable(t.state.doc.nodeAt(i.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Z(r))),!0)}function WS(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=w.empty;for(let s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=t.state.tr.replace(n.pos,n.pos,new v(i,0,0));return o.setSelection(L.near(o.doc.resolve(n.pos+1))),t.dispatch(o),!1}function US(t){if(!(t.selection instanceof Z))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",U.create(t.doc,[ge.widget(t.selection.head,e,{key:"gapcursor"})])}class er{constructor(e,n,r={}){this.match=e,this.match=e,this.handler=typeof n=="string"?jS(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function jS(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 HS=500;function JS({rules:t}){let e=new Mt({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 kd(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&kd(n,r.pos,r.pos,"",t,e)})}}},isInputRules:!0});return e}function kd(t,e,n,r,i,o){if(t.composing)return!1;let s=t.state,l=s.doc.resolve(e),u=l.parent.textBetween(Math.max(0,l.parentOffset-HS),l.parentOffset,null,"")+r;for(let a=0;a{let u=n instanceof Function?n(o):n,a=i.tr.delete(s,l),c=a.doc.resolve(s),f=c.blockRange(),d=f&&py(f,e,u);if(!d)return null;a.wrap(f,d);let p=a.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&tc(a.doc,s-1)&&(!r||r(o,p))&&a.join(s-1),a})}const qS=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function QS(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[Hl(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Fm=65535,Tm=Math.pow(2,16);function ZS(t,e){return t+e*Tm}function wd(t){return t&Fm}function ek(t){return(t-(t&Fm))/Tm}const Rm=1,Pm=2,ls=4,zm=8;class $u{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&zm)>0}get deletedBefore(){return(this.delInfo&(Rm|ls))>0}get deletedAfter(){return(this.delInfo&(Pm|ls))>0}get deletedAcross(){return(this.delInfo&ls)>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=wd(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],c=this.ranges[l+s],f=u+a;if(e<=f){let d=a?e==u?-1:e==f?1:n:n,p=u+i+(d<0?0:c);if(r)return p;let h=e==(n<0?u:f)?null:ZS(l/3,e-u),m=e==u?Pm:e==f?Rm:ls;return(n<0?e!=u:e!=f)&&(m|=zm),new $u(p,m,h)}i+=c-a}return r?e+i:new $u(e+i,0,null)}touches(e,n){let r=0,i=wd(n),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],c=u+a;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+s]-a}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 xi;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;ro&&u!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 kt(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))}}Ee.jsonID("addMark",ln);class kt extends Ee{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 v(gc(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 kt(n.pos,r.pos,this.mark)}merge(e){return e instanceof kt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new kt(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 kt(n.from,n.to,e.markFromJSON(n.mark))}}Ee.jsonID("removeMark",kt);class un extends Ee{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 v(w.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 vt(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 vt(n.from,n.to,n.gapFrom,n.gapTo,v.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ee.jsonID("replaceAround",vt);function _u(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 tk(t,e,n,r){let i=[],o=[],s,l;t.doc.nodesBetween(e,n,(u,a,c)=>{if(!u.isInline)return;let f=u.marks;if(!r.isInSet(f)&&c.type.allowsMarkType(r.type)){let d=Math.max(a,e),p=Math.min(a+u.nodeSize,n),h=r.addToSet(f);for(let m=0;mt.step(u)),o.forEach(u=>t.step(u))}function nk(t,e,n,r){let i=[],o=0;t.doc.nodesBetween(e,n,(s,l)=>{if(!s.isInline)return;o++;let u=null;if(r instanceof ho){let a=s.marks,c;for(;c=r.isInSet(a);)(u||(u=[])).push(c),a=c.removeFromSet(a)}else r?r.isInSet(s.marks)&&(u=[r]):u=s.marks;if(u&&u.length){let a=Math.min(l+s.nodeSize,n);for(let c=0;ct.step(new kt(s.from,s.to,s.style)))}function rk(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 ik(t,e,n){let{$from:r,$to:i,depth:o}=e,s=r.before(o+1),l=i.after(o+1),u=s,a=l,c=w.empty,f=0;for(let h=o,m=!1;h>n;h--)m||r.index(h)>0?(m=!0,c=w.from(r.node(h).copy(c)),f++):u--;let d=w.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=w.from(n[s].type.create(n[s].attrs,r))}let i=e.start,o=e.end;t.step(new vt(i,o,i,o,new v(r,0,0),n.length,!0))}function sk(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)&&lk(t.doc,t.mapping.slice(o).map(l),r)){t.clearIncompatible(t.mapping.slice(o).map(l,1),r);let u=t.mapping.slice(o),a=u.map(l,1),c=u.map(l+s.nodeSize,1);return t.step(new vt(a,c,a+1,c-1,new v(w.from(r.create(i,null,s.marks)),0,0),1,!0)),!1}})}function lk(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function uk(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 vt(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new v(w.from(s),0,0),1,!0))}function ak(t,e,n=1,r){let i=t.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,u=i.depth-n,a=n-1;l>u;l--,a--){o=w.from(i.node(l).copy(o));let c=r&&r[a];s=w.from(c?c.type.create(c.attrs,s):i.node(l).copy(s))}t.step(new Ae(e,e,new v(o.append(s),n,n),!0))}function ck(t,e,n){let r=new Ae(e-n,e+n,v.empty,!0);t.step(r)}function fk(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=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):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 u=new v(o,s,l);return e>-1?new vt(r.pos,e,this.$to.pos,this.$to.end(),u,n):u.size||r.pos!=this.$to.pos?new Ae(r.pos,i.pos,u):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),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=Kl(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:u,match:a}=this.frontier[l],c,f=null;if(n==1&&(s?a.matchType(s.type)||(f=a.fillBefore(w.from(s),!1)):o&&u.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(n==2&&s&&(c=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:c};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Kl(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new v(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=Kl(e,n);if(i.childCount<=1&&n>0){let o=e.size-n<=n+i.size;this.unplaced=new v(pi(e,n-1,1),n-1,o?n-1:r)}else this.unplaced=new v(pi(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||u==0||m.content.size)&&(f=S,c.push(Im(m.mark(d.allowedMarks(m.marks)),a==1?u:0,a==l.childCount?p:-1)))}let h=a==l.childCount;h||(p=-1),this.placed=mi(this.placed,n,w.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:u,type:a}=this.frontier[l],c=ql(e,l,a,u,!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=mi(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=mi(this.placed,this.depth,w.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(w.empty,!0);n.childCount&&(this.placed=mi(this.placed,this.frontier.length,n))}}function pi(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(pi(t.firstChild.content,e-1,n)))}function mi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(mi(t.lastChild.content,e-1,n)))}function Kl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Im(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(w.empty,!0)))),t.copy(r)}function ql(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&&!pk(n,o.content,s)?l:null}function pk(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 u=s.indexOf(l),a=[],c=r.openStart;for(let d=r.content,p=0;;p++){let h=d.firstChild;if(a.push(h),p==r.openStart)break;d=h.content}for(let d=c-1;d>=0;d--){let p=a[d],h=mk(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=a[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 Lm(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(w.empty,!0))}return t}function yk(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=fk(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new v(w.from(r),0,0))}function Ck(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),o=Vm(r,i);for(let s=0;s0&&(u||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 Vm(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 Er extends Ee{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 v(w.from(i),0,n.isLeaf?0:1))}getMap(){return je.empty}invert(e){return new Er(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 Er(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 Er(n.pos,n.attr,n.value)}}Ee.jsonID("attr",Er);class Ui extends Ee{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 Ui(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 Ui(n.attr,n.value)}}Ee.jsonID("docAttr",Ui);let Ir=class extends Error{};Ir=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};Ir.prototype=Object.create(Error.prototype);Ir.prototype.constructor=Ir;Ir.prototype.name="TransformError";class Sk{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new xi}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new Ir(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=v.empty){let i=dk(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new v(w.from(r),0,0))}delete(e,n){return this.replace(e,n,v.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return gk(this,e,n,r),this}replaceRangeWith(e,n,r){return yk(this,e,n,r),this}deleteRange(e,n){return Ck(this,e,n),this}lift(e,n){return ik(this,e,n),this}join(e,n=1){return ck(this,e,n),this}wrap(e,n){return ok(this,e,n),this}setBlockType(e,n=e,r,i=null){return sk(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return uk(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Er(e,n,r)),this}setDocAttribute(e,n){return this.step(new Ui(e,n)),this}addNodeMark(e,n){return this.step(new un(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 ak(this,e,n,r),this}addMark(e,n,r){return tk(this,e,n,r),this}removeMark(e,n,r){return nk(this,e,n,r),this}clearIncompatible(e,n,r){return rk(this,e,n,r),this}}var Wu,Uu;if(typeof WeakMap<"u"){let t=new WeakMap;Wu=e=>t.get(e),Uu=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;Wu=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-C});break}const k=i+C*e;for(let E=0;Er&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(n=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function vk(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,u=l&&l(t);u!=null&&(o[s]=u)}return o}function Dd(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 xk(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=>vd(r,e)}],toDOM(r){return["td",Dd(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>vd(r,e)}],toDOM(r){return["th",Dd(r,e),0]}}}}function Nt(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 mo("selectingCells");function Co(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 yc(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 $m(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=Co(e.$head)||Ek(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function Ek(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 ju(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function Cc(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function _m(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 fe=class Tt extends z{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),u=i.cellsInRect(s).filter(c=>c!=n.pos-o);u.unshift(n.pos-o);const a=u.map(c=>{const f=r.nodeAt(c);if(!f)throw RangeError(`No cell with offset ${c} found`);const d=o+c+1;return new Ip(l.resolve(d),l.resolve(d+f.content.size))});super(a[0].$from,a[0].$to,a),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(ju(r)&&ju(i)&&Cc(r,i)){const o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?Tt.rowSelection(r,i):o&&this.isColSelection()?Tt.colSelection(r,i):new Tt(r,i)}return L.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 u=i.top;u0||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),u=e.node(0);return s.top<=l.top?(s.top>0&&(e=u.resolve(o+i.map[s.left])),l.bottom0&&(n=u.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 Tt&&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),u=e.node(0);return s.left<=l.left?(s.left>0&&(e=u.resolve(o+i.map[s.top*i.width])),l.right0&&(n=u.resolve(o+i.map[l.top*i.width])),s.right{e.push(ge.node(r,r+n.nodeSize,{class:"selectedCell"}))}),U.create(t.doc,e)}function Ak({$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 Mk({$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 Ok(t,e,n){const r=(e||t).selection,i=(e||t).doc;let o,s;if(r instanceof P&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=fe.create(i,r.from);else if(s=="row"){const l=i.resolve(r.from+1);o=fe.rowSelection(l,l)}else if(!n){const l=re.get(r.node),u=r.from+1,a=u+l.map[l.width*l.height-1];o=fe.create(i,u+1,a)}}else r instanceof L&&Ak(r)?o=L.create(i,r.from):r instanceof L&&Mk(r)&&(o=L.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=t.tr)).setSelection(o),e}var Fk=new mo("fix-tables");function Um(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=Rk(t,i,o,n))};return e?e.doc!=t.doc&&Um(e.doc,t.doc,0,r):t.doc.descendants(r),n}function Rk(t,e,n,r){const i=re.get(e);if(!i.problems)return r;r||(r=t.tr);const o=[];for(let u=0;u0){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 u=0;u=0;s--){const{rowspan:l,colspan:u}=o.child(s).attrs;for(let a=i;a=e.length&&e.push(w.empty),n[i]r&&(d=d.type.createChecked(Lr(d.attrs,d.attrs.colspan,c+d.attrs.colspan-r),d.content)),a.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)),u.push(f)}o.push(w.from(u))}n=o,e=i}return{width:t,height:e,rows:n}}function Ik(t,e,n,r,i,o,s){const l=t.doc.type.schema,u=Nt(l);let a,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==u.header_cell;f.push(S?c||(c=u.header_cell.createAndFill()):a||(a=u.cell.createAndFill()))}const d=u.row.create(null,w.from(f)),p=[];for(let h=e.height;h{if(!i)return!1;const o=n.selection;if(o instanceof fe)return us(n,r,z.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;const s=jm(i,t,e);if(s==null)return!1;if(t=="horiz")return us(n,r,z.near(n.doc.resolve(o.head+e),e));{const l=n.doc.resolve(s),u=_m(l,t,e);let a;return u?a=z.near(u,1):e<0?a=z.near(n.doc.resolve(l.before(-1)),-1):a=z.near(n.doc.resolve(l.after(-1)),1),us(n,r,a)}}}function Ro(t,e){return(n,r,i)=>{if(!i)return!1;const o=n.selection;let s;if(o instanceof fe)s=o;else{const u=jm(i,t,e);if(u==null)return!1;s=new fe(n.doc.resolve(u))}const l=_m(s.$headCell,t,e);return l?us(n,r,new fe(s.$anchorCell,l)):!1}}function Po(t,e){const n=t.selection;if(!(n instanceof fe))return!1;if(e){const r=t.tr,i=Nt(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 v(i,0,0))}),r.docChanged&&e(r)}return!0}function Vk(t,e){const n=t.state.doc,r=Co(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new fe(r))),!0):!1}function $k(t,e,n){if(!yc(t.state))return!1;let r=Pk(n);const i=t.state.selection;if(i instanceof fe){r||(r={width:1,height:1,rows:[w.from(Hu(Nt(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=bk(r,l.right-l.left,l.bottom-l.top),Bd(t.state,t.dispatch,s,l,r),!0}else if(r){const o=$m(t.state),s=o.start(-1);return Bd(t.state,t.dispatch,s,re.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function _k(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 fe)o(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Co(t.state.selection.$anchor))!=null&&((n=Ql(t,e))==null?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(u,a){let c=Ql(t,a);const f=tn.getState(t.state)==null;if(!c||!Cc(u,c))if(f)c=u;else return;const d=new fe(u,c);if(f||!t.state.selection.eq(d)){const p=t.state.tr.setSelection(d);f&&p.setMeta(tn,u.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(u){const a=u,c=tn.getState(t.state);let f;if(c!=null)f=t.state.doc.resolve(c);else if(Nd(t,a.target)!=r&&(f=Ql(t,e),!f))return s();f&&o(f,a)}t.root.addEventListener("mouseup",s),t.root.addEventListener("dragstart",s),t.root.addEventListener("mousemove",l)}function jm(t,e,n){if(!(t.state.selection instanceof L))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),u=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(u)?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 Ql(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});return n&&n?Co(t.state.doc.resolve(n.pos)):null}var Wk=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")),Ju(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,Ju(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function Ju(t,e,n,r,i,o){var s;let l=0,u=!0,a=e.firstChild;const c=t.firstChild;if(c){for(let f=0,d=0;fnew n(l,e,u),new jk(-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)=>{Hk(o,s,t,e,r)},mouseleave:o=>{Jk(o)},mousedown:(o,s)=>{Kk(o,s,e)}},decorations:o=>{const s=et.getState(o);if(s&&s.activeHandle>-1)return Zk(o,s.activeHandle)},nodeViews:{}}});return i}var jk=class as{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 as(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new as(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return ju(e.doc.resolve(i))||(i=-1),new as(i,n.dragging)}return n}};function Hk(t,e,n,r,i){const o=et.getState(t.state);if(o&&!o.dragging){const s=Qk(e.target);let l=-1;if(s){const{left:u,right:a}=s.getBoundingClientRect();e.clientX-u<=n?l=Ad(t,e,"left",n):a-e.clientX<=n&&(l=Ad(t,e,"right",n))}if(l!=o.activeHandle){if(!i&&l!==-1){const u=t.state.doc.resolve(l),a=u.node(-1),c=re.get(a),f=u.start(-1);if(c.colCount(u.pos-f)+u.nodeAfter.attrs.colspan-1==c.width-1)return}Hm(t,l)}}}function Jk(t){const e=et.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&Hm(t,-1)}function Kk(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=qk(t,o.activeHandle,s.attrs);t.dispatch(t.state.tr.setMeta(et,{setDragging:{startX:e.clientX,startWidth:l}}));function u(c){i.removeEventListener("mouseup",u),i.removeEventListener("mousemove",a);const f=et.getState(t.state);f!=null&&f.dragging&&(Yk(t,f.activeHandle,Md(f.dragging,c,n)),t.dispatch(t.state.tr.setMeta(et,{setDragging:null})))}function a(c){if(!c.which)return u(c);const f=et.getState(t.state);if(f&&f.dragging){const d=Md(f.dragging,c,n);Gk(t,f.activeHandle,d,n)}}return i.addEventListener("mouseup",u),i.addEventListener("mousemove",a),e.preventDefault(),!0}function qk(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,u=n;if(r)for(let a=0;ai.table.nodeAt(u));for(let u=0;u{const h=p+o.tableStart,m=s.doc.nodeAt(h);m&&s.setNodeMarkup(h,d,m.attrs)}),r(s)}return!0}}Sc("row",{useDeprecatedLogic:!0});Sc("column",{useDeprecatedLogic:!0});Sc("cell",{useDeprecatedLogic:!0});function tw({allowTableNodeSelection:t=!1}={}){return new Mt({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:Nk,handleDOMEvents:{mousedown:_k},createSelectionBetween(e){return tn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Vk,handleKeyDown:Lk,handlePaste:$k},appendTransaction(e,n,r){return Ok(r,Tk(r,n),t)}})}var Km={exports:{}},Qe={},qm={exports:{}},Qm={};/** + * @license React + * scheduler.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * 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(F,b){var I=F.length;F.push(b);e:for(;0>>1,ue=F[ee];if(0>>1;eei(Bl,I))Oni(Bo,Bl)?(F[ee]=Bo,F[On]=I,ee=On):(F[ee]=Bl,F[Mn]=I,ee=Mn);else if(Oni(Bo,I))F[ee]=Bo,F[On]=I,ee=On;else break e}}return b}function i(F,b){var I=F.sortIndex-b.sortIndex;return I!==0?I:F.id-b.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 u=[],a=[],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 C(F){for(var b=n(a);b!==null;){if(b.callback===null)r(a);else if(b.startTime<=F)r(a),b.sortIndex=b.expirationTime,e(u,b);else break;b=n(a)}}function k(F){if(m=!1,C(F),!h)if(n(u)!==null)h=!0,xl(E);else{var b=n(a);b!==null&&El(k,b.startTime-F)}}function E(F,b){h=!1,m&&(m=!1,g(O),O=-1),p=!0;var I=d;try{for(C(b),f=n(u);f!==null&&(!(f.expirationTime>b)||F&&!ne());){var ee=f.callback;if(typeof ee=="function"){f.callback=null,d=f.priorityLevel;var ue=ee(f.expirationTime<=b);b=t.unstable_now(),typeof ue=="function"?f.callback=ue:f===n(u)&&r(u),C(b)}else r(u);f=n(u)}if(f!==null)var Eo=!0;else{var Mn=n(a);Mn!==null&&El(k,Mn.startTime-b),Eo=!1}return Eo}finally{f=null,d=I,p=!1}}var N=!1,A=null,O=-1,B=5,T=-1;function ne(){return!(t.unstable_now()-TF||125ee?(F.sortIndex=I,e(a,F),n(u)===null&&F===n(a)&&(m?(g(O),O=-1):m=!0,El(k,I-ee))):(F.sortIndex=ue,e(u,F),h||p||(h=!0,xl(E))),F},t.unstable_shouldYield=ne,t.unstable_wrapCallback=function(F){var b=d;return function(){var I=d;d=b;try{return F.apply(this,arguments)}finally{d=I}}}})(Qm);qm.exports=Qm;var nw=qm.exports;/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Ym=D,qe=nw;function x(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"),Ku=Object.prototype.hasOwnProperty,rw=/^[: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]*$/,Fd={},Td={};function iw(t){return Ku.call(Td,t)?!0:Ku.call(Fd,t)?!1:rw.test(t)?Td[t]=!0:(Fd[t]=!0,!1)}function ow(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 sw(t,e,n,r){if(e===null||typeof e>"u"||ow(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 Pe(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 Ce={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){Ce[t]=new Pe(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];Ce[e]=new Pe(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Ce[t]=new Pe(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Ce[t]=new Pe(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){Ce[t]=new Pe(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Ce[t]=new Pe(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Ce[t]=new Pe(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Ce[t]=new Pe(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Ce[t]=new Pe(t,5,!1,t.toLowerCase(),null,!1,!1)});var kc=/[\-:]([a-z])/g;function wc(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(kc,wc);Ce[e]=new Pe(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(kc,wc);Ce[e]=new Pe(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(kc,wc);Ce[e]=new Pe(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Ce[t]=new Pe(t,1,!1,t.toLowerCase(),null,!1,!1)});Ce.xlinkHref=new Pe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Ce[t]=new Pe(t,1,!1,t.toLowerCase(),null,!0,!0)});function vc(t,e,n,r){var i=Ce.hasOwnProperty(e)?Ce[e]:null;(i!==null?i.type!==0:r||!(2l||i[s]!==o[l]){var u=` +`+i[s].replace(" at new "," at ");return t.displayName&&u.includes("")&&(u=u.replace("",t.displayName)),u}while(1<=s&&0<=l);break}}}finally{Gl=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?gi(t):""}function lw(t){switch(t.tag){case 5:return gi(t.type);case 16:return gi("Lazy");case 13:return gi("Suspense");case 19:return gi("SuspenseList");case 0:case 2:case 15:return t=Xl(t.type,!1),t;case 11:return t=Xl(t.type.render,!1),t;case 1:return t=Xl(t.type,!0),t;default:return""}}function Gu(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 qu:return"Profiler";case Dc:return"StrictMode";case Qu:return"Suspense";case Yu:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case Zm:return(t.displayName||"Context")+".Consumer";case Xm:return(t._context.displayName||"Context")+".Provider";case xc:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Ec:return e=t.displayName||null,e!==null?e:Gu(t.type)||"Memo";case Xt:e=t._payload,t=t._init;try{return Gu(t(e))}catch{}}return null}function uw(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 Gu(e);case 8:return e===Dc?"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 wn(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function tg(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function aw(t){var e=tg(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=aw(t))}function ng(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=tg(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Fs(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 Xu(t,e){var n=e.checked;return G({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function Pd(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=wn(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 rg(t,e){e=e.checked,e!=null&&vc(t,"checked",e,!1)}function Zu(t,e){rg(t,e);var n=wn(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")?ea(t,e.type,n):e.hasOwnProperty("defaultValue")&&ea(t,e.type,wn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function zd(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 ea(t,e,n){(e!=="number"||Fs(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var yi=Array.isArray;function Br(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 Hi(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Ei={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},cw=["Webkit","ms","Moz","O"];Object.keys(Ei).forEach(function(t){cw.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Ei[e]=Ei[t]})});function lg(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Ei.hasOwnProperty(t)&&Ei[t]?(""+e).trim():e+"px"}function ug(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=lg(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,i):t[n]=i}}var fw=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 ra(t,e){if(e){if(fw[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(x(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(x(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(x(61))}if(e.style!=null&&typeof e.style!="object")throw Error(x(62))}}function ia(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 oa=null;function Bc(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var sa=null,Nr=null,Ar=null;function Ld(t){if(t=wo(t)){if(typeof sa!="function")throw Error(x(280));var e=t.stateNode;e&&(e=fl(e),sa(t.stateNode,t.type,e))}}function ag(t){Nr?Ar?Ar.push(t):Ar=[t]:Nr=t}function cg(){if(Nr){var t=Nr,e=Ar;if(Ar=Nr=null,Ld(t),e)for(t=0;t>>=0,t===0?32:31-(vw(t)/Dw|0)|0}var Lo=64,Vo=4194304;function Ci(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=Ci(l):(o&=s,o!==0&&(r=Ci(o)))}else s=n&~i,s!==0?r=Ci(s):o!==0&&(r=Ci(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 So(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 Nw(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=Ni),Kd=String.fromCharCode(32),qd=!1;function Og(t,e){switch(t){case"keyup":return tv.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Fg(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var dr=!1;function rv(t,e){switch(t){case"compositionend":return Fg(e);case"keypress":return e.which!==32?null:(qd=!0,Kd);case"textInput":return t=e.data,t===Kd&&qd?null:t;default:return null}}function iv(t,e){if(dr)return t==="compositionend"||!Pc&&Og(t,e)?(t=Ag(),fs=Fc=an=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=Xd(n)}}function zg(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?zg(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function bg(){for(var t=window,e=Fs();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Fs(t.document)}return e}function zc(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 hv(t){var e=bg(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&zg(n.ownerDocument.documentElement,n)){if(r!==null&&zc(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=Zd(n,o);var s=Zd(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,da=null,Mi=null,ha=!1;function eh(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;ha||hr==null||hr!==Fs(r)||(r=hr,"selectionStart"in r&&zc(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}),Mi&&Gi(Mi,r)||(Mi=r,r=Ls(da,"onSelect"),0gr||(t.current=Sa[gr],Sa[gr]=null,gr--)}function H(t,e){gr++,Sa[gr]=t.current,t.current=e}var vn={},xe=Bn(vn),Ve=Bn(!1),Qn=vn;function $r(t,e){var n=t.type.contextTypes;if(!n)return vn;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 $s(){K(Ve),K(xe)}function lh(t,e,n){if(xe.current!==vn)throw Error(x(168));H(xe,e),H(Ve,n)}function Hg(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(x(108,uw(t)||"Unknown",i));return G({},n,r)}function _s(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||vn,Qn=xe.current,H(xe,t),H(Ve,Ve.current),!0}function uh(t,e,n){var r=t.stateNode;if(!r)throw Error(x(169));n?(t=Hg(t,e,Qn),r.__reactInternalMemoizedMergedChildContext=t,K(Ve),K(xe),H(xe,t)):K(Ve),H(Ve,n)}var bt=null,dl=!1,du=!1;function Jg(t){bt===null?bt=[t]:bt.push(t)}function Ev(t){dl=!0,Jg(t)}function Nn(){if(!du&&bt!==null){du=!0;var t=0,e=j;try{var n=bt;for(j=1;t>=s,i-=s,Lt=1<<32-dt(e)+i|n<O?(B=A,A=null):B=A.sibling;var T=d(g,A,C[O],k);if(T===null){A===null&&(A=B);break}t&&A&&T.alternate===null&&e(g,A),y=o(T,y,O),N===null?E=T:N.sibling=T,N=T,A=B}if(O===C.length)return n(g,A),q&&Tn(g,O),E;if(A===null){for(;OO?(B=A,A=null):B=A.sibling;var ne=d(g,A,T.value,k);if(ne===null){A===null&&(A=B);break}t&&A&&ne.alternate===null&&e(g,A),y=o(ne,y,O),N===null?E=ne:N.sibling=ne,N=ne,A=B}if(T.done)return n(g,A),q&&Tn(g,O),E;if(A===null){for(;!T.done;O++,T=C.next())T=f(g,T.value,k),T!==null&&(y=o(T,y,O),N===null?E=T:N.sibling=T,N=T);return q&&Tn(g,O),E}for(A=r(g,A);!T.done;O++,T=C.next())T=p(A,g,O,T.value,k),T!==null&&(t&&T.alternate!==null&&A.delete(T.key===null?O:T.key),y=o(T,y,O),N===null?E=T:N.sibling=T,N=T);return t&&A.forEach(function(Ot){return e(g,Ot)}),q&&Tn(g,O),E}function S(g,y,C,k){if(typeof C=="object"&&C!==null&&C.type===fr&&C.key===null&&(C=C.props.children),typeof C=="object"&&C!==null){switch(C.$$typeof){case zo:e:{for(var E=C.key,N=y;N!==null;){if(N.key===E){if(E=C.type,E===fr){if(N.tag===7){n(g,N.sibling),y=i(N,C.props.children),y.return=g,g=y;break e}}else if(N.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===Xt&&mh(E)===N.type){n(g,N.sibling),y=i(N,C.props),y.ref=ii(g,N,C),y.return=g,g=y;break e}n(g,N);break}else e(g,N);N=N.sibling}C.type===fr?(y=Jn(C.props.children,g.mode,k,C.key),y.return=g,g=y):(k=Ss(C.type,C.key,C.props,null,g.mode,k),k.ref=ii(g,y,C),k.return=g,g=k)}return s(g);case cr:e:{for(N=C.key;y!==null;){if(y.key===N)if(y.tag===4&&y.stateNode.containerInfo===C.containerInfo&&y.stateNode.implementation===C.implementation){n(g,y.sibling),y=i(y,C.children||[]),y.return=g,g=y;break e}else{n(g,y);break}else e(g,y);y=y.sibling}y=ku(C,g.mode,k),y.return=g,g=y}return s(g);case Xt:return N=C._init,S(g,y,N(C._payload),k)}if(yi(C))return h(g,y,C,k);if(Zr(C))return m(g,y,C,k);Jo(g,C)}return typeof C=="string"&&C!==""||typeof C=="number"?(C=""+C,y!==null&&y.tag===6?(n(g,y.sibling),y=i(y,C),y.return=g,g=y):(n(g,y),y=Su(C,g.mode,k),y.return=g,g=y),s(g)):n(g,y)}return S}var Wr=e0(!0),t0=e0(!1),vo={},xt=Bn(vo),to=Bn(vo),no=Bn(vo);function $n(t){if(t===vo)throw Error(x(174));return t}function jc(t,e){switch(H(no,e),H(to,t),H(xt,vo),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:na(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=na(e,t)}K(xt),H(xt,e)}function Ur(){K(xt),K(to),K(no)}function n0(t){$n(no.current);var e=$n(xt.current),n=na(e,t.type);e!==n&&(H(to,t),H(xt,n))}function Hc(t){to.current===t&&(K(xt),K(to))}var Q=Bn(0);function Ks(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 hu=[];function Jc(){for(var t=0;tn?n:4,t(!0);var r=pu.transition;pu.transition={};try{t(!1),e()}finally{j=n,pu.transition=r}}function C0(){return ot().memoizedState}function Mv(t,e,n){var r=Sn(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},S0(t))k0(e,n);else if(n=Yg(t,e,n,r),n!==null){var i=Me();ht(n,t,r,i),w0(n,e,r)}}function Ov(t,e,n){var r=Sn(t),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(S0(t))k0(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 u=e.interleaved;u===null?(i.next=i,Wc(e)):(i.next=u.next,u.next=i),e.interleaved=i;return}}catch{}finally{}n=Yg(t,e,i,r),n!==null&&(i=Me(),ht(n,t,r,i),w0(n,e,r))}}function S0(t){var e=t.alternate;return t===Y||e!==null&&e===Y}function k0(t,e){Oi=qs=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function w0(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Ac(t,n)}}var Qs={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},Fv={readContext:it,useCallback:function(t,e){return yt().memoizedState=[t,e===void 0?null:e],t},useContext:it,useEffect:yh,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,ms(4194308,4,h0.bind(null,e,t),n)},useLayoutEffect:function(t,e){return ms(4194308,4,t,e)},useInsertionEffect:function(t,e){return ms(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=Mv.bind(null,Y,t),[r.memoizedState,t]},useRef:function(t){var e=yt();return t={current:t},e.memoizedState=t},useState:gh,useDebugValue:Gc,useDeferredValue:function(t){return yt().memoizedState=t},useTransition:function(){var t=gh(!1),e=t[0];return t=Av.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(x(407));n=n()}else{if(n=e(),de===null)throw Error(x(349));Gn&30||o0(r,e,n)}i.memoizedState=n;var o={value:n,getSnapshot:e};return i.queue=o,yh(l0.bind(null,r,o,t),[t]),r.flags|=2048,oo(9,s0.bind(null,r,o,n,e),void 0,null),n},useId:function(){var t=yt(),e=de.identifierPrefix;if(q){var n=Vt,r=Lt;n=(r&~(1<<32-dt(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=ro++,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[St]=e,t[eo]=r,O0(t,e,!1,!1),e.stateNode=t;e:{switch(s=ia(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;iHr&&(e.flags|=128,r=!0,oi(o,!1),e.lanes=4194304)}else{if(!r)if(t=Ks(s),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),oi(o,!0),o.tail===null&&o.tailMode==="hidden"&&!s.alternate&&!q)return ke(e),null}else 2*te()-o.renderingStartTime>Hr&&n!==1073741824&&(e.flags|=128,r=!0,oi(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 rf(),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(x(156,e.tag))}function Vv(t,e){switch(Ic(e),e.tag){case 1:return $e(e.type)&&$s(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Ur(),K(Ve),K(xe),Jc(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Hc(e),null;case 13:if(K(Q),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(x(340));_r()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return K(Q),null;case 4:return Ur(),null;case 10:return _c(e.type._context),null;case 22:case 23:return rf(),null;case 24:return null;default:return null}}var qo=!1,ve=!1,$v=typeof WeakSet=="function"?WeakSet:Set,M=null;function kr(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 Fa(t,e,n){try{n()}catch(r){X(t,e,r)}}var Bh=!1;function _v(t,e){if(pa=bs,t=bg(),zc(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,u=-1,a=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||(u=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&&++a===i&&(l=s),d===o&&++c===r&&(u=s),(p=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=p}n=l===-1||u===-1?null:{start:l,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(ma={focusedElem:t,selectionRange:n},bs=!1,M=e;M!==null;)if(e=M,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,M=t;else for(;M!==null;){e=M;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:ut(e.type,m),S);g.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var C=e.stateNode.containerInfo;C.nodeType===1?C.textContent="":C.nodeType===9&&C.documentElement&&C.removeChild(C.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(x(163))}}catch(k){X(e,e.return,k)}if(t=e.sibling,t!==null){t.return=e.return,M=t;break}M=e.return}return h=Bh,Bh=!1,h}function Fi(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&&Fa(e,n,o)}i=i.next}while(i!==r)}}function ml(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 Ta(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 R0(t){var e=t.alternate;e!==null&&(t.alternate=null,R0(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[St],delete e[eo],delete e[Ca],delete e[Dv],delete e[xv])),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 P0(t){return t.tag===5||t.tag===3||t.tag===4}function Nh(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||P0(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 Ra(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=Vs));else if(r!==4&&(t=t.child,t!==null))for(Ra(t,e,n),t=t.sibling;t!==null;)Ra(t,e,n),t=t.sibling}function Pa(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(Pa(t,e,n),t=t.sibling;t!==null;)Pa(t,e,n),t=t.sibling}var pe=null,at=!1;function Qt(t,e,n){for(n=n.child;n!==null;)z0(t,e,n),n=n.sibling}function z0(t,e,n){if(Dt&&typeof Dt.onCommitFiberUnmount=="function")try{Dt.onCommitFiberUnmount(ll,n)}catch{}switch(n.tag){case 5:ve||kr(n,e);case 6:var r=pe,i=at;pe=null,Qt(t,e,n),pe=r,at=i,pe!==null&&(at?(t=pe,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):pe.removeChild(n.stateNode));break;case 18:pe!==null&&(at?(t=pe,n=n.stateNode,t.nodeType===8?fu(t.parentNode,n):t.nodeType===1&&fu(t,n),Qi(t)):fu(pe,n.stateNode));break;case 4:r=pe,i=at,pe=n.stateNode.containerInfo,at=!0,Qt(t,e,n),pe=r,at=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)&&Fa(n,e,s),i=i.next}while(i!==r)}Qt(t,e,n);break;case 1:if(!ve&&(kr(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 Ah(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new $v),e.forEach(function(r){var i=Yv.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*Uv(r/1960))-r,10t?16:t,cn===null)var r=!1;else{if(t=cn,cn=null,Xs=0,$&6)throw Error(x(331));var i=$;for($|=4,M=t.current;M!==null;){var o=M,s=o.child;if(M.flags&16){var l=o.deletions;if(l!==null){for(var u=0;ute()-tf?Hn(t,0):ef|=n),_e(t,e)}function U0(t,e){e===0&&(t.mode&1?(e=Vo,Vo<<=1,!(Vo&130023424)&&(Vo=4194304)):e=1);var n=Me();t=Jt(t,e),t!==null&&(So(t,e,n),_e(t,n))}function Qv(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),U0(t,n)}function Yv(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(x(314))}r!==null&&r.delete(e),U0(t,n)}var j0;j0=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Ve.current)Ie=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Ie=!1,Iv(t,e,n);Ie=!!(t.flags&131072)}else Ie=!1,q&&e.flags&1048576&&Kg(e,Us,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;gs(t,e),t=e.pendingProps;var i=$r(e,xe.current);Or(e,n),i=qc(null,e,r,t,i,n);var o=Qc();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,_s(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Uc(e),i.updater=hl,e.stateNode=i,i._reactInternals=e,xa(e,r,t,n),e=Na(null,e,r,!0,o,n)):(e.tag=0,q&&o&&bc(e),Be(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(gs(t,e),t=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=Xv(r),t=ut(r,t),i){case 0:e=Ba(null,e,r,t,n);break e;case 1:e=Dh(null,e,r,t,n);break e;case 11:e=wh(null,e,r,t,n);break e;case 14:e=vh(null,e,r,ut(r.type,t),n);break e}throw Error(x(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:ut(r,i),Ba(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:ut(r,i),Dh(t,e,r,i,n);case 3:e:{if(N0(e),t===null)throw Error(x(387));r=e.pendingProps,o=e.memoizedState,i=o.element,Gg(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=jr(Error(x(423)),e),e=xh(t,e,r,n,i);break e}else if(r!==i){i=jr(Error(x(424)),e),e=xh(t,e,r,n,i);break e}else for(He=gn(e.stateNode.containerInfo.firstChild),Ke=e,q=!0,ft=null,n=t0(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}Be(t,e,r,n)}e=e.child}return e;case 5:return n0(e),t===null&&wa(e),r=e.type,i=e.pendingProps,o=t!==null?t.memoizedProps:null,s=i.children,ga(r,i)?s=null:o!==null&&ga(r,o)&&(e.flags|=32),B0(t,e),Be(t,e,s,n),e.child;case 6:return t===null&&wa(e),null;case 13:return A0(t,e,n);case 4:return jc(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=Wr(e,null,r,n):Be(t,e,r,n),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:ut(r,i),wh(t,e,r,i,n);case 7:return Be(t,e,e.pendingProps,n),e.child;case 8:return Be(t,e,e.pendingProps.children,n),e.child;case 12:return Be(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(js,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 u=l.firstContext;u!==null;){if(u.context===r){if(o.tag===1){u=_t(-1,n&-n),u.tag=2;var a=o.updateQueue;if(a!==null){a=a.shared;var c=a.pending;c===null?u.next=u:(u.next=c.next,c.next=u),a.pending=u}}o.lanes|=n,u=o.alternate,u!==null&&(u.lanes|=n),va(o.return,n,e),l.lanes|=n;break}u=u.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(x(341));s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),va(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}Be(t,e,i.children,n),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,Or(e,n),i=it(i),r=r(i),e.flags|=1,Be(t,e,r,n),e.child;case 14:return r=e.type,i=ut(r,e.pendingProps),i=ut(r.type,i),vh(t,e,r,i,n);case 15:return x0(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:ut(r,i),gs(t,e),e.tag=1,$e(r)?(t=!0,_s(e)):t=!1,Or(e,n),Zg(e,r,i),xa(e,r,i,n),Na(null,e,r,!0,t,n);case 19:return M0(t,e,n);case 22:return E0(t,e,n)}throw Error(x(156,e.tag))};function H0(t,e){return yg(t,e)}function Gv(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 Gv(t,e,n,r)}function sf(t){return t=t.prototype,!(!t||!t.isReactComponent)}function Xv(t){if(typeof t=="function")return sf(t)?1:0;if(t!=null){if(t=t.$$typeof,t===xc)return 11;if(t===Ec)return 14}return 2}function kn(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 Ss(t,e,n,r,i,o){var s=2;if(r=t,typeof t=="function")sf(t)&&(s=1);else if(typeof t=="string")s=5;else e:switch(t){case fr:return Jn(n.children,i,o,e);case Dc:s=8,i|=8;break;case qu:return t=tt(12,n,e,i|2),t.elementType=qu,t.lanes=o,t;case Qu:return t=tt(13,n,e,i),t.elementType=Qu,t.lanes=o,t;case Yu:return t=tt(19,n,e,i),t.elementType=Yu,t.lanes=o,t;case eg:return yl(n,i,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case Xm:s=10;break e;case Zm:s=9;break e;case xc:s=11;break e;case Ec:s=14;break e;case Xt:s=16,r=null;break e}throw Error(x(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 yl(t,e,n,r){return t=tt(22,t,r,e),t.elementType=eg,t.lanes=n,t.stateNode={isHidden:!1},t}function Su(t,e,n){return t=tt(6,t,null,e),t.lanes=n,t}function ku(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 Zv(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=eu(0),this.expirationTimes=eu(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=eu(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function lf(t,e,n,r,i,o,s,l,u){return t=new Zv(t,e,n,l,u),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},Uc(o),t}function eD(t,e,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Q0)}catch(t){console.error(t)}}Q0(),Km.exports=Qe;var Jr=Km.exports,Y0,bh=Jr;Y0=bh.createRoot,bh.hydrateRoot;const Do=D.createContext(null),G0=D.createContext(null);function oD(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"),[ge.node(0,t.state.doc.content.size,e)]}const sD=[],lD={},Va=U.empty;class zn{constructor(e){this.members=e}map(e,n){const r=this.members.map(i=>i.map(e,n,lD));return zn.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 X0(t,e){return t.from-e.from||t.to-e.to}function uD(t){let e=t;for(let n=0;n0;)e++;t.splice(e,0,n)}function aD(t,e){const n=[];return t.someProp("decorations",r=>{const i=r(t.state);i&&i!=Va&&n.push(i)}),e&&n.push(U.create(t.state.doc,[e])),zn.from(n)}const ff=function(t){for(let e=0;;e++)if(t=t.previousSibling,!t)return e},Lh=function(t){const e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e},cD=function(t,e,n,r){return n&&(Vh(t,e,n,r,-1)||Vh(t,e,n,r,1))},fD=/^(img|br|input|textarea|hr)$/i;function Vh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:tl(t))){const o=t.parentNode;if(!o||o.nodeType!=1||hD(t)||fD.test(t.nodeName)||t.contentEditable=="false")return!1;e=ff(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?tl(t):0}else return!1}}function tl(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function dD(t,e,n){for(let r=e==0,i=e==tl(t);r||i;){if(t==n)return!0;const o=ff(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==tl(t)}return!1}function hD(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 Z0=function(t){return t.focusNode&&cD(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)},e1=D.createContext(null);function pD(t,e){const n=D.useContext(e1);D.useLayoutEffect(()=>n(t),e)}function t1(t,e){const{view:n}=D.useContext(Do);pD(()=>{if(n)return t(n)},e&&[n,...e])}const mD=D.forwardRef(function({widget:e,pos:n,...r},i){const[o,s]=D.useState(!0),l=D.useRef(null);return D.useImperativeHandle(i,()=>l.current,[]),t1(u=>{if(!u||!l.current)return;u.domObserver.disconnectSelection();const a=u.domSelection(),c=document.createRange(),f=l.current;f.nodeName=="IMG"&&f.parentNode?c.setEnd(f.parentNode,ff(f)+1):c.setEnd(f,0),c.collapse(!1),a.removeAllRanges(),a.addRange(c),s(!1),u.domObserver.connectSelection()},[]),o?R("img",{ref:l,className:"ProseMirror-separator","mark-placeholder":"true",alt:"",...r}):null});function gD(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 yD={side:0};class lo{constructor(e,n){this.Component=e,this.spec=n??yD,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 ge(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof lo&&(this.spec.key&&this.spec.key==e.spec.key||this.Component==e.Component&&gD(this.spec,e.spec))}destroy(){}}function n1(t,e,n){return new ge(t,t,new lo(e,n))}function $h(t,e,n){if(e==="leading")return wu(t,n);const r=t[t.length-1];if(r&&CD(r))return 1;let i=wu(t,!1),o=t.slice(i);for(;o.length;)i=wu(o,!1),o=o.slice(i);return i}function CD(t){return t.match(/[\u0E00-\u0E7F]/)}function wu(t,e=!1){const n=!e,r=e?SD(t):t;let i=0,o=0,s=0,l=null,u=null;for(const a of r){const c=a.codePointAt(0);if(!c)break;const f=FD(a,c);if([i,o]=n?[o,f]:[f,i],vr(i,2)&&vr(o,1024)&&(n?l=_h(t.substring(0,s)):l=_h(t.substring(0,t.length-s)),!l)||vr(i,4)&&vr(o,4)&&(u!==null?u=!u:n?u=!0:u=bD(t.substring(0,t.length-s)),!u)||i!==0&&o!==0&&RD(i,o))break;s+=a.length}return s||1}function*SD(t){const e=t.length-1;for(let n=0;nt>=55296&&t<=56319,wD=t=>t>=56320&&t<=57343,vD=/^[\p{Gr_Ext}\p{EMod}]$/u,DD=/^[\u0600-\u0605\u06DD\u070F\u0890-\u0891\u08E2\u0D4E\u{110BD}\u{110CD}\u{111C2}-\u{111C3}\u{1193F}\u{11941}\u{11A3A}\u{11A84}-\u{11A89}\u{11D46}]$/u,xD=/^[\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0982-\u0983\u09BF-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0B02-\u0B03\u0B40\u0B47-\u0B48\u0B4B-\u0B4C\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0C01-\u0C03\u0C41-\u0C44\u0C82-\u0C83\u0CBE\u0CC0-\u0CC1\u0CC3-\u0CC4\u0CC7-\u0CC8\u0CCA-\u0CCB\u0D02-\u0D03\u0D3F-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D82-\u0D83\u0DD0-\u0DD1\u0DD8-\u0DDE\u0DF2-\u0DF3\u0E33\u0EB3\u0F3E-\u0F3F\u0F7F\u1031\u103B-\u103C\u1056-\u1057\u1084\u1715\u1734\u17B6\u17BE-\u17C5\u17C7-\u17C8\u1923-\u1926\u1929-\u192B\u1930-\u1931\u1933-\u1938\u1A19-\u1A1A\u1A55\u1A57\u1A6D-\u1A72\u1B04\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B82\u1BA1\u1BA6-\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1C24-\u1C2B\u1C34-\u1C35\u1CE1\u1CF7\uA823-\uA824\uA827\uA880-\uA881\uA8B4-\uA8C3\uA952-\uA953\uA983\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BE-\uA9C0\uAA2F-\uAA30\uAA33-\uAA34\uAA4D\uAAEB\uAAEE-\uAAEF\uAAF5\uABE3-\uABE4\uABE6-\uABE7\uABE9-\uABEA\uABEC\u{11000}\u{11002}\u{11082}\u{110B0}-\u{110B2}\u{110B7}-\u{110B8}\u{1112C}\u{11145}-\u{11146}\u{11182}\u{111B3}-\u{111B5}\u{111BF}-\u{111C0}\u{111CE}\u{1122C}-\u{1122E}\u{11232}-\u{11233}\u{11235}\u{112E0}-\u{112E2}\u{11302}-\u{11303}\u{1133F}\u{11341}-\u{11344}\u{11347}-\u{11348}\u{1134B}-\u{1134D}\u{11362}-\u{11363}\u{11435}-\u{11437}\u{11440}-\u{11441}\u{11445}\u{114B1}-\u{114B2}\u{114B9}\u{114BB}-\u{114BC}\u{114BE}\u{114C1}\u{115B0}-\u{115B1}\u{115B8}-\u{115BB}\u{115BE}\u{11630}-\u{11632}\u{1163B}-\u{1163C}\u{1163E}\u{116AC}\u{116AE}-\u{116AF}\u{116B6}\u{11726}\u{1182C}-\u{1182E}\u{11838}\u{11931}-\u{11935}\u{11937}-\u{11938}\u{1193D}\u{11940}\u{11942}\u{119D1}-\u{119D3}\u{119DC}-\u{119DF}\u{119E4}\u{11A39}\u{11A57}-\u{11A58}\u{11A97}\u{11C2F}\u{11C3E}\u{11CA9}\u{11CB1}\u{11CB4}\u{11D8A}-\u{11D8E}\u{11D93}-\u{11D94}\u{11D96}\u{11EF5}-\u{11EF6}\u{16F51}-\u{16F87}\u{16FF0}-\u{16FF1}\u{1D166}\u{1D16D}]$/u,ED=/^[\u1100-\u115F\uA960-\uA97C]$/u,BD=/^[\u1160-\u11A7\uD7B0-\uD7C6]$/u,ND=/^[\u11A8-\u11FF\uD7CB-\uD7FB]$/u,AD=/^[\uAC00\uAC1C\uAC38\uAC54\uAC70\uAC8C\uACA8\uACC4\uACE0\uACFC\uAD18\uAD34\uAD50\uAD6C\uAD88\uADA4\uADC0\uADDC\uADF8\uAE14\uAE30\uAE4C\uAE68\uAE84\uAEA0\uAEBC\uAED8\uAEF4\uAF10\uAF2C\uAF48\uAF64\uAF80\uAF9C\uAFB8\uAFD4\uAFF0\uB00C\uB028\uB044\uB060\uB07C\uB098\uB0B4\uB0D0\uB0EC\uB108\uB124\uB140\uB15C\uB178\uB194\uB1B0\uB1CC\uB1E8\uB204\uB220\uB23C\uB258\uB274\uB290\uB2AC\uB2C8\uB2E4\uB300\uB31C\uB338\uB354\uB370\uB38C\uB3A8\uB3C4\uB3E0\uB3FC\uB418\uB434\uB450\uB46C\uB488\uB4A4\uB4C0\uB4DC\uB4F8\uB514\uB530\uB54C\uB568\uB584\uB5A0\uB5BC\uB5D8\uB5F4\uB610\uB62C\uB648\uB664\uB680\uB69C\uB6B8\uB6D4\uB6F0\uB70C\uB728\uB744\uB760\uB77C\uB798\uB7B4\uB7D0\uB7EC\uB808\uB824\uB840\uB85C\uB878\uB894\uB8B0\uB8CC\uB8E8\uB904\uB920\uB93C\uB958\uB974\uB990\uB9AC\uB9C8\uB9E4\uBA00\uBA1C\uBA38\uBA54\uBA70\uBA8C\uBAA8\uBAC4\uBAE0\uBAFC\uBB18\uBB34\uBB50\uBB6C\uBB88\uBBA4\uBBC0\uBBDC\uBBF8\uBC14\uBC30\uBC4C\uBC68\uBC84\uBCA0\uBCBC\uBCD8\uBCF4\uBD10\uBD2C\uBD48\uBD64\uBD80\uBD9C\uBDB8\uBDD4\uBDF0\uBE0C\uBE28\uBE44\uBE60\uBE7C\uBE98\uBEB4\uBED0\uBEEC\uBF08\uBF24\uBF40\uBF5C\uBF78\uBF94\uBFB0\uBFCC\uBFE8\uC004\uC020\uC03C\uC058\uC074\uC090\uC0AC\uC0C8\uC0E4\uC100\uC11C\uC138\uC154\uC170\uC18C\uC1A8\uC1C4\uC1E0\uC1FC\uC218\uC234\uC250\uC26C\uC288\uC2A4\uC2C0\uC2DC\uC2F8\uC314\uC330\uC34C\uC368\uC384\uC3A0\uC3BC\uC3D8\uC3F4\uC410\uC42C\uC448\uC464\uC480\uC49C\uC4B8\uC4D4\uC4F0\uC50C\uC528\uC544\uC560\uC57C\uC598\uC5B4\uC5D0\uC5EC\uC608\uC624\uC640\uC65C\uC678\uC694\uC6B0\uC6CC\uC6E8\uC704\uC720\uC73C\uC758\uC774\uC790\uC7AC\uC7C8\uC7E4\uC800\uC81C\uC838\uC854\uC870\uC88C\uC8A8\uC8C4\uC8E0\uC8FC\uC918\uC934\uC950\uC96C\uC988\uC9A4\uC9C0\uC9DC\uC9F8\uCA14\uCA30\uCA4C\uCA68\uCA84\uCAA0\uCABC\uCAD8\uCAF4\uCB10\uCB2C\uCB48\uCB64\uCB80\uCB9C\uCBB8\uCBD4\uCBF0\uCC0C\uCC28\uCC44\uCC60\uCC7C\uCC98\uCCB4\uCCD0\uCCEC\uCD08\uCD24\uCD40\uCD5C\uCD78\uCD94\uCDB0\uCDCC\uCDE8\uCE04\uCE20\uCE3C\uCE58\uCE74\uCE90\uCEAC\uCEC8\uCEE4\uCF00\uCF1C\uCF38\uCF54\uCF70\uCF8C\uCFA8\uCFC4\uCFE0\uCFFC\uD018\uD034\uD050\uD06C\uD088\uD0A4\uD0C0\uD0DC\uD0F8\uD114\uD130\uD14C\uD168\uD184\uD1A0\uD1BC\uD1D8\uD1F4\uD210\uD22C\uD248\uD264\uD280\uD29C\uD2B8\uD2D4\uD2F0\uD30C\uD328\uD344\uD360\uD37C\uD398\uD3B4\uD3D0\uD3EC\uD408\uD424\uD440\uD45C\uD478\uD494\uD4B0\uD4CC\uD4E8\uD504\uD520\uD53C\uD558\uD574\uD590\uD5AC\uD5C8\uD5E4\uD600\uD61C\uD638\uD654\uD670\uD68C\uD6A8\uD6C4\uD6E0\uD6FC\uD718\uD734\uD750\uD76C\uD788]$/u,MD=/^[\uAC01-\uAC1B\uAC1D-\uAC37\uAC39-\uAC53\uAC55-\uAC6F\uAC71-\uAC8B\uAC8D-\uACA7\uACA9-\uACC3\uACC5-\uACDF\uACE1-\uACFB\uACFD-\uAD17\uAD19-\uAD33\uAD35-\uAD4F\uAD51-\uAD6B\uAD6D-\uAD87\uAD89-\uADA3\uADA5-\uADBF\uADC1-\uADDB\uADDD-\uADF7\uADF9-\uAE13\uAE15-\uAE2F\uAE31-\uAE4B\uAE4D-\uAE67\uAE69-\uAE83\uAE85-\uAE9F\uAEA1-\uAEBB\uAEBD-\uAED7\uAED9-\uAEF3\uAEF5-\uAF0F\uAF11-\uAF2B\uAF2D-\uAF47\uAF49-\uAF63\uAF65-\uAF7F\uAF81-\uAF9B\uAF9D-\uAFB7\uAFB9-\uAFD3\uAFD5-\uAFEF\uAFF1-\uB00B\uB00D-\uB027\uB029-\uB043\uB045-\uB05F\uB061-\uB07B\uB07D-\uB097\uB099-\uB0B3\uB0B5-\uB0CF\uB0D1-\uB0EB\uB0ED-\uB107\uB109-\uB123\uB125-\uB13F\uB141-\uB15B\uB15D-\uB177\uB179-\uB193\uB195-\uB1AF\uB1B1-\uB1CB\uB1CD-\uB1E7\uB1E9-\uB203\uB205-\uB21F\uB221-\uB23B\uB23D-\uB257\uB259-\uB273\uB275-\uB28F\uB291-\uB2AB\uB2AD-\uB2C7\uB2C9-\uB2E3\uB2E5-\uB2FF\uB301-\uB31B\uB31D-\uB337\uB339-\uB353\uB355-\uB36F\uB371-\uB38B\uB38D-\uB3A7\uB3A9-\uB3C3\uB3C5-\uB3DF\uB3E1-\uB3FB\uB3FD-\uB417\uB419-\uB433\uB435-\uB44F\uB451-\uB46B\uB46D-\uB487\uB489-\uB4A3\uB4A5-\uB4BF\uB4C1-\uB4DB\uB4DD-\uB4F7\uB4F9-\uB513\uB515-\uB52F\uB531-\uB54B\uB54D-\uB567\uB569-\uB583\uB585-\uB59F\uB5A1-\uB5BB\uB5BD-\uB5D7\uB5D9-\uB5F3\uB5F5-\uB60F\uB611-\uB62B\uB62D-\uB647\uB649-\uB663\uB665-\uB67F\uB681-\uB69B\uB69D-\uB6B7\uB6B9-\uB6D3\uB6D5-\uB6EF\uB6F1-\uB70B\uB70D-\uB727\uB729-\uB743\uB745-\uB75F\uB761-\uB77B\uB77D-\uB797\uB799-\uB7B3\uB7B5-\uB7CF\uB7D1-\uB7EB\uB7ED-\uB807\uB809-\uB823\uB825-\uB83F\uB841-\uB85B\uB85D-\uB877\uB879-\uB893\uB895-\uB8AF\uB8B1-\uB8CB\uB8CD-\uB8E7\uB8E9-\uB903\uB905-\uB91F\uB921-\uB93B\uB93D-\uB957\uB959-\uB973\uB975-\uB98F\uB991-\uB9AB\uB9AD-\uB9C7\uB9C9-\uB9E3\uB9E5-\uB9FF\uBA01-\uBA1B\uBA1D-\uBA37\uBA39-\uBA53\uBA55-\uBA6F\uBA71-\uBA8B\uBA8D-\uBAA7\uBAA9-\uBAC3\uBAC5-\uBADF\uBAE1-\uBAFB\uBAFD-\uBB17\uBB19-\uBB33\uBB35-\uBB4F\uBB51-\uBB6B\uBB6D-\uBB87\uBB89-\uBBA3\uBBA5-\uBBBF\uBBC1-\uBBDB\uBBDD-\uBBF7\uBBF9-\uBC13\uBC15-\uBC2F\uBC31-\uBC4B\uBC4D-\uBC67\uBC69-\uBC83\uBC85-\uBC9F\uBCA1-\uBCBB\uBCBD-\uBCD7\uBCD9-\uBCF3\uBCF5-\uBD0F\uBD11-\uBD2B\uBD2D-\uBD47\uBD49-\uBD63\uBD65-\uBD7F\uBD81-\uBD9B\uBD9D-\uBDB7\uBDB9-\uBDD3\uBDD5-\uBDEF\uBDF1-\uBE0B\uBE0D-\uBE27\uBE29-\uBE43\uBE45-\uBE5F\uBE61-\uBE7B\uBE7D-\uBE97\uBE99-\uBEB3\uBEB5-\uBECF\uBED1-\uBEEB\uBEED-\uBF07\uBF09-\uBF23\uBF25-\uBF3F\uBF41-\uBF5B\uBF5D-\uBF77\uBF79-\uBF93\uBF95-\uBFAF\uBFB1-\uBFCB\uBFCD-\uBFE7\uBFE9-\uC003\uC005-\uC01F\uC021-\uC03B\uC03D-\uC057\uC059-\uC073\uC075-\uC08F\uC091-\uC0AB\uC0AD-\uC0C7\uC0C9-\uC0E3\uC0E5-\uC0FF\uC101-\uC11B\uC11D-\uC137\uC139-\uC153\uC155-\uC16F\uC171-\uC18B\uC18D-\uC1A7\uC1A9-\uC1C3\uC1C5-\uC1DF\uC1E1-\uC1FB\uC1FD-\uC217\uC219-\uC233\uC235-\uC24F\uC251-\uC26B\uC26D-\uC287\uC289-\uC2A3\uC2A5-\uC2BF\uC2C1-\uC2DB\uC2DD-\uC2F7\uC2F9-\uC313\uC315-\uC32F\uC331-\uC34B\uC34D-\uC367\uC369-\uC383\uC385-\uC39F\uC3A1-\uC3BB\uC3BD-\uC3D7\uC3D9-\uC3F3\uC3F5-\uC40F\uC411-\uC42B\uC42D-\uC447\uC449-\uC463\uC465-\uC47F\uC481-\uC49B\uC49D-\uC4B7\uC4B9-\uC4D3\uC4D5-\uC4EF\uC4F1-\uC50B\uC50D-\uC527\uC529-\uC543\uC545-\uC55F\uC561-\uC57B\uC57D-\uC597\uC599-\uC5B3\uC5B5-\uC5CF\uC5D1-\uC5EB\uC5ED-\uC607\uC609-\uC623\uC625-\uC63F\uC641-\uC65B\uC65D-\uC677\uC679-\uC693\uC695-\uC6AF\uC6B1-\uC6CB\uC6CD-\uC6E7\uC6E9-\uC703\uC705-\uC71F\uC721-\uC73B\uC73D-\uC757\uC759-\uC773\uC775-\uC78F\uC791-\uC7AB\uC7AD-\uC7C7\uC7C9-\uC7E3\uC7E5-\uC7FF\uC801-\uC81B\uC81D-\uC837\uC839-\uC853\uC855-\uC86F\uC871-\uC88B\uC88D-\uC8A7\uC8A9-\uC8C3\uC8C5-\uC8DF\uC8E1-\uC8FB\uC8FD-\uC917\uC919-\uC933\uC935-\uC94F\uC951-\uC96B\uC96D-\uC987\uC989-\uC9A3\uC9A5-\uC9BF\uC9C1-\uC9DB\uC9DD-\uC9F7\uC9F9-\uCA13\uCA15-\uCA2F\uCA31-\uCA4B\uCA4D-\uCA67\uCA69-\uCA83\uCA85-\uCA9F\uCAA1-\uCABB\uCABD-\uCAD7\uCAD9-\uCAF3\uCAF5-\uCB0F\uCB11-\uCB2B\uCB2D-\uCB47\uCB49-\uCB63\uCB65-\uCB7F\uCB81-\uCB9B\uCB9D-\uCBB7\uCBB9-\uCBD3\uCBD5-\uCBEF\uCBF1-\uCC0B\uCC0D-\uCC27\uCC29-\uCC43\uCC45-\uCC5F\uCC61-\uCC7B\uCC7D-\uCC97\uCC99-\uCCB3\uCCB5-\uCCCF\uCCD1-\uCCEB\uCCED-\uCD07\uCD09-\uCD23\uCD25-\uCD3F\uCD41-\uCD5B\uCD5D-\uCD77\uCD79-\uCD93\uCD95-\uCDAF\uCDB1-\uCDCB\uCDCD-\uCDE7\uCDE9-\uCE03\uCE05-\uCE1F\uCE21-\uCE3B\uCE3D-\uCE57\uCE59-\uCE73\uCE75-\uCE8F\uCE91-\uCEAB\uCEAD-\uCEC7\uCEC9-\uCEE3\uCEE5-\uCEFF\uCF01-\uCF1B\uCF1D-\uCF37\uCF39-\uCF53\uCF55-\uCF6F\uCF71-\uCF8B\uCF8D-\uCFA7\uCFA9-\uCFC3\uCFC5-\uCFDF\uCFE1-\uCFFB\uCFFD-\uD017\uD019-\uD033\uD035-\uD04F\uD051-\uD06B\uD06D-\uD087\uD089-\uD0A3\uD0A5-\uD0BF\uD0C1-\uD0DB\uD0DD-\uD0F7\uD0F9-\uD113\uD115-\uD12F\uD131-\uD14B\uD14D-\uD167\uD169-\uD183\uD185-\uD19F\uD1A1-\uD1BB\uD1BD-\uD1D7\uD1D9-\uD1F3\uD1F5-\uD20F\uD211-\uD22B\uD22D-\uD247\uD249-\uD263\uD265-\uD27F\uD281-\uD29B\uD29D-\uD2B7\uD2B9-\uD2D3\uD2D5-\uD2EF\uD2F1-\uD30B\uD30D-\uD327\uD329-\uD343\uD345-\uD35F\uD361-\uD37B\uD37D-\uD397\uD399-\uD3B3\uD3B5-\uD3CF\uD3D1-\uD3EB\uD3ED-\uD407\uD409-\uD423\uD425-\uD43F\uD441-\uD45B\uD45D-\uD477\uD479-\uD493\uD495-\uD4AF\uD4B1-\uD4CB\uD4CD-\uD4E7\uD4E9-\uD503\uD505-\uD51F\uD521-\uD53B\uD53D-\uD557\uD559-\uD573\uD575-\uD58F\uD591-\uD5AB\uD5AD-\uD5C7\uD5C9-\uD5E3\uD5E5-\uD5FF\uD601-\uD61B\uD61D-\uD637\uD639-\uD653\uD655-\uD66F\uD671-\uD68B\uD68D-\uD6A7\uD6A9-\uD6C3\uD6C5-\uD6DF\uD6E1-\uD6FB\uD6FD-\uD717\uD719-\uD733\uD735-\uD74F\uD751-\uD76B\uD76D-\uD787\uD789-\uD7A3]$/u,OD=/^\p{ExtPict}$/u,FD=(t,e)=>{let n=2048;return t.search(vD)!==-1&&(n|=1),e===8205&&(n|=2),e>=127462&&e<=127487&&(n|=4),t.search(DD)!==-1&&(n|=8),t.search(xD)!==-1&&(n|=16),t.search(ED)!==-1&&(n|=32),t.search(BD)!==-1&&(n|=64),t.search(ND)!==-1&&(n|=128),t.search(AD)!==-1&&(n|=256),t.search(MD)!==-1&&(n|=512),t.search(OD)!==-1&&(n|=1024),n};function vr(t,e){return(t&e)!==0}const TD=[[32,864],[320,192],[640,128],[2048,3],[2048,16],[8,2048],[2,1024],[4,4]];function RD(t,e){return TD.findIndex(n=>vr(t,n[0])&&vr(e,n[1]))===-1}const PD=/\p{ExtPict}[\p{Gr_Ext}\p{EMod}]*\u200D$/u,_h=t=>t.search(PD)!==-1,zD=/\p{RI}+$/gu,bD=t=>{const e=t.match(zD);return e===null?!1:e[0].length/2%2===1},At=typeof navigator<"u"?navigator:null,Wh=typeof document<"u"?document:null,An=At&&At.userAgent||"",$a=/Edge\/(\d+)/.exec(An),r1=/MSIE \d/.exec(An),_a=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(An),vl=!!(r1||_a||$a),ID=r1?document.documentMode:_a?+_a[1]:$a?+$a[1]:0,i1=!vl&&/gecko\/(\d+)/i.test(An),LD=i1&&+(/Firefox\/(\d+)/.exec(An)||[0,0])[1],Wa=!vl&&/Chrome\/(\d+)/.exec(An),VD=!!Wa,$D=Wa?+Wa[1]:0,o1=!vl&&!!At&&/Apple Computer/.test(At.vendor),s1=o1&&(/Mobile\/\w+/.test(An)||!!At&&At.maxTouchPoints>2),_D=s1||(At?/Mac/.test(At.platform):!1),WD=At?/Win/.test(At.platform):!1,UD=/Android \d/.test(An),l1=!!Wh&&"webkitFontSmoothing"in Wh.documentElement.style,jD=l1?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,ce={ie:vl,ie_version:ID,gecko:i1,gecko_version:LD,chrome:VD,chrome_version:$D,safari:o1,ios:s1,mac:_D,windows:WD,android:UD,webkit:l1,webkit_version:jD};function Uh(t,e){const n=t.state.doc.resolve(e);if(!(ce.chrome||ce.windows)&&n.parent.inlineContent){const i=t.coordsAtPos(e);if(e>n.start()){const 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"}const HD=/\s/,JD=/[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/,KD=/['\u2018\u2019]/;function uo(t,e,n=-1){if(t.resolve(e).parentOffset===0)return!1;const i=t.textBetween(e+n,e,null," ");return HD.test(i)?!1:KD.test(i)&&uo(t,e-1)?!0:!JD.test(i)}function qD(t,e){let n=e;for(;!uo(t,n);)n--;for(;uo(t,n);)n--;return n}function QD(t,e){let n=e;for(;!uo(t,n,1);)n++;for(;uo(t,n,1);)n++;return n}function vu(){return Math.floor(Math.random()*16777215).toString(16)}const ao=new mo("@nytimes/react-prosemirror/reactKeys");function YD(){let t=!1;return new Mt({key:ao,state:{init(e,n){const r={posToKey:new Map,keyToPos:new Map};return n.doc.descendants((i,o)=>{const s=vu();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(ao),s=(o==null?void 0:o.type)==="bustKey"&&o.payload.key,l={posToKey:new Map,keyToPos:new Map},u=Array.from(n.posToKey.entries()).sort(([a],[c])=>a-c);for(const[a,c]of u){const{pos:f,deleted:d}=e.mapping.mapResult(a);if(d)continue;let p=c;s===c&&(p=vu()),l.posToKey.set(f,p),l.keyToPos.set(p,f)}return i.doc.descendants((a,c)=>{if(l.posToKey.has(c))return!0;const f=vu();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{t=!0},compositionend:()=>{t=!1}}}})}function Du(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),u=l.sharedDepth(i),a=l.start(u),c=(s=ao.getState(t.state))==null?void 0:s.posToKey.get(a-1);o.setMeta(ao,{type:"bustKey",payload:{key:c}})}return t.dispatch(o),!0}function GD(t){let e=null,n=null;return new Mt({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(n1(i.selection.from,mD,{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 Du(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(u=>{for(const a of l){const c=r.docView.posFromDOM(a.startContainer,a.startOffset,1),f=r.docView.posFromDOM(a.endContainer,a.endOffset,1);Du(r,u,{from:c,to:f})}});break}case"insertText":{Du(r,i.data);break}case"deleteWordBackward":{const{tr:l,doc:u,selection:a}=r.state,c=a.empty?qD(r.state.doc,a.from):a.from,f=a.to,d=u.resolve(c).marksAcross(u.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteWordForward":{const{tr:l,doc:u,selection:a}=r.state,c=a.empty?QD(r.state.doc,a.from):a.from,f=a.to,d=u.resolve(c).marksAcross(u.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteContentBackward":{const{tr:l,doc:u,selection:a}=r.state;if(a.empty){const p=a.$anchor.nodeBefore,h=p==null?void 0:p.text;if(!h)break;const m=$h(h,"trailing",Uh(r,a.anchor)==="rtl"),S=a.to,g=S-m,y=u.resolve(g).marksAcross(u.resolve(S));l.delete(g,S).setStoredMarks(y),r.dispatch(l);break}const c=a.empty?a.from-1:a.from,f=a.to,d=u.resolve(c).marksAcross(u.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteContentForward":{const{tr:l,doc:u,selection:a}=r.state;if(a.empty){const p=a.$anchor.nodeAfter,h=p==null?void 0:p.text;if(!h)break;const m=$h(h,"leading",Uh(r,a.anchor)==="rtl"),S=a.from,g=S+m,y=u.resolve(S).marksAcross(u.resolve(g));l.delete(S,g).setStoredMarks(y),r.dispatch(l);break}const c=a.from,f=a.to,d=u.resolve(c).marksAcross(u.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteContent":{const{tr:l,doc:u,selection:a}=r.state,c=u.resolve(a.from).marksAcross(u.resolve(a.to));l.delete(a.from,a.to).setStoredMarks(c),r.dispatch(l);break}}return!0}}}})}function jh(t){return t.editable&&!t.hasFocus()?!1:XD(t)}function XD(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 ZD(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||L.between(e,n,r)}function Hh(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 u,a;if(Z0(n)){for(u=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&P.isSelectable(c)&&i.parent&&!(c.isInline&&dD(n.focusNode,n.focusOffset,i.dom))){const f=i.posBefore;a=new P(s==f?l:r.resolve(f))}}else{const c=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null;u=r.resolve(c)}if(!a){const c=e=="pointer"||t.state.selection.head{(r.anchorNode!=i||r.anchorOffset!=o)&&(n.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{(!u1(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const Gh=ce.safari||ce.chrome&&ce.chrome_version<63;function Go(t,e=!1){const n=t,r=n.state.selection;if(nx(n,r),!!u1(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&&nl(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)ix(n);else{const{anchor:i,head:o}=r;let s,l;Gh&&!(r instanceof L)&&(r.$from.parent.inlineContent||(s=Qh(n,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=Qh(n,r.to))),n.docView.setSelection(i,o,n.root,e),Gh&&(s&&Yh(s),l&&Yh(l)),r.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&ox(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}class sx{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 lx{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new sx,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=Lh(o))n.add(o);for(let o=e.anchorNode;o;o=Lh(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=Hh(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;Go(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)&&jh(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(jh(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Go(this.view);if(ce.ie&&ce.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&nl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const Kr=0,Xh=1,Xo=2,co=3;class xo{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Kr,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 pf){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 df&&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<=a-u.border&&u.node&&u.contentDOM&&this.contentDOM.contains(u.contentDOM))return u.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&&(a>n||l==this.children.length-1)){n=a;for(let c=l+1;ch&&sn){const h=l;l=u,u=h}const p=document.createRange();p.setEnd(u.node,u.offset),p.setStart(l.node,l.offset),a.removeAllRanges(),a.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,u=s-o.border;if(e>=l&&n<=u){this.dirty=e==r||n==s?Xo:Xh,e==l&&n==u&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=co:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Xo:co}r=s}this.dirty=Xo}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){const r=e==1?Xo:Xh;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=()=>w.empty)}return e}matchesNode(e,n,r){return this.dirty==Kr&&e.eq(this.node)&&fx(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 cx extends hf{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=co)}get domAtom(){return!1}}class pf extends xo{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Kr&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}function fx(t,e){if(t.length!=e.length)return!1;for(let n=0;n{a=!!u.call(this,s,l)}),a||l.defaultPrevented)return!0}return!1};e[r]=o}return new Mt({key:new mo("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function hx(){const[t,e]=D.useState(new Map),n=D.useCallback((o,s)=>{const l=t.get(o)??[];l.unshift(s),t.has(o)||(t.set(o,l),e(new Map(t)))},[t]),r=D.useCallback((o,s)=>{const l=t.get(o);l==null||l.splice(l.indexOf(s),1)},[t]),i=D.useMemo(()=>dx(t),[t]);return{registerEventListener:n,unregisterEventListener:r,componentEventListenersPlugin:i}}function a1(){const[,t]=D.useReducer(e=>e+1,0);return t}class px extends PS{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 lx(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 mx=new xp({nodes:{doc:{content:"text*"},text:{inline:!0}}}),gx=on.create({schema:mx});function yx(t,e){const[n,r]=D.useState(null),[i,o]=D.useState(null),s=a1(),l=e.defaultState??gx,[u,a]=D.useState(l),c=e.state??u,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=hx(),h=D.useCallback(k=>{Jr.flushSync(()=>{o(k)})},[]),m=D.useMemo(()=>[...e.plugins??[],f,GD(h)],[e.plugins,f,h]);function S(k){Jr.flushSync(()=>{e.state||a(E=>E.apply(k)),e.dispatchTransaction&&e.dispatchTransaction.call(this,k)})}const g=document.createElement("div"),y=D.useRef(new hf(void 0,[],c.doc,[],U.empty,g,null,g)),C={...e,state:c,plugins:m,dispatchTransaction:S,docView:y.current};return D.useLayoutEffect(()=>{if(n&&n.dom!==t&&r(null),!!t&&!n){const k=new px({mount:t},C);r(k),k.dom.addEventListener("compositionend",s);return}}),n==null||n.pureSetProps(C),D.useMemo(()=>({view:n,state:c,registerEventListener:d,unregisterEventListener:p,cursorWrapper:i,docViewDescRef:y}),[n,c,d,p,i])}function Cx(t){D.useLayoutEffect(()=>{t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()},[t,t==null?void 0:t.props])}function Sx({children:t}){const e=D.useRef(new Set).current,n=D.useRef(new Set).current,r=D.useRef(!1),i=a1(),o=D.useRef(!0),s=D.useCallback(()=>{o.current||(i(),o.current=!0)},[i]),l=D.useCallback(u=>{let a;const c=()=>{a=u()};return e.add(c),s(),()=>{e.delete(c),a&&(r.current?(n.add(a),s()):a())}},[e,n,s]);return D.useLayoutEffect(()=>(o.current=!1,e.forEach(u=>u()),e.clear(),()=>{n.forEach(u=>u()),n.clear()})),D.useLayoutEffect(()=>(r.current=!0,()=>{r.current=!1}),[]),R(e1.Provider,{value:l,children:t})}const st=D.createContext([]);function c1(t,e,n,r,i,o,s){const l=D.useRef(o),u=D.useContext(st),a=[];return D.useLayoutEffect(()=>{if(!t||!n.current)return;const c=a[0];l.current?(l.current.parent=void 0,l.current.children=a,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 hf(void 0,a,t,i,r,(e==null?void 0:e.current)??n.current,(c==null?void 0:c.dom.parentElement)??null,n.current),u.push(l.current);for(const f of a)f.parent=l.current}),a}var f1={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 Dl(){const{state:t}=D.useContext(Do);return t}function d1(){const t=Dl();return t&&ao.getState(t)}const mf=D.forwardRef(function({outputSpec:e,children:n,...r},i){if(typeof e=="string")return R(Qa,{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],u={...r,ref:i};let a=1;if(l&&typeof l=="object"&&l.nodeType==null&&!Array.isArray(l)){a=2;for(const f in l)if(l[f]!=null){const d=f==="class"?"className":f.replace(" ",":");u[d]=l[f]}}const c=[];for(let f=a;fa)throw new RangeError("Content hole must be the only child of its parent node");return D.createElement(s,u,n)}c.push(R(mf,{ref:void 0,outputSpec:d,children:n}))}return D.createElement(s,u,...c)}),h1=D.forwardRef(function({mark:e,children:n},r){var u,a;const i=D.useContext(st),o=[],s=D.useRef(null);D.useImperativeHandle(r,()=>s.current,[]);const l=(a=(u=e.type.spec).toDOM)==null?void 0:a.call(u,e,!0);if(!l)throw new Error(`Mark spec for ${e.type.name} is missing toDOM`);return D.useLayoutEffect(()=>{if(!s.current)return;const c=o[0],f=new ax(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}),R(mf,{ref:s,outputSpec:l,children:R(st.Provider,{value:o,children:n})})});function xx({widget:t,pos:e}){const n=D.useContext(st),r=D.useRef(null),i=D.useRef(e);return i.current=e,t1(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 u=document.createElement("span");u.appendChild(l),l=u}l.contentEditable="false",l.classList.add("ProseMirror-widget")}r.current.firstElementChild!==l&&r.current.replaceChildren(l)}),D.useLayoutEffect(()=>{if(!r.current)return;const o=new df(void 0,t,r.current);n.push(o)}),R("span",{ref:r})}function p1({outerDeco:t,pos:e,node:n,innerDeco:r,...i}){var A,O;const o=D.useRef(null),s=D.useRef(null),l=D.useRef(null),u=D.useRef(n),a=D.useRef(t),c=D.useRef(r),f=D.useRef(e);f.current=e;const d=D.useRef(null),p=D.useRef(null),h=Dl(),{nodeViews:m}=D.useContext(G0),{view:S}=D.useContext(Do);let g=null;const y=m[n.type.name],C=S==null?void 0:S.someProp("nodeViews",B=>B==null?void 0:B[n.type.name]);D.useLayoutEffect(()=>{if(!p.current||!d.current)return;const{dom:B}=p.current;return s.current=d.current,d.current.appendChild(B),()=>{var T,ne;(ne=(T=p.current)==null?void 0:T.destroy)==null||ne.call(T)}},[]),D.useLayoutEffect(()=>{if(!C||!p.current)return;const{destroy:B,update:T}=p.current;if(((T==null?void 0:T.call(p.current,n,t,r))??!0)||(B==null||B.call(p.current),!d.current))return;u.current=n,a.current=t,c.current=r,p.current=C(u.current,S,()=>f.current,a.current,c.current);const{dom:Ot}=p.current;s.current=d.current,d.current.appendChild(Ot)},[C,S,r,n,t]);const k=c1(n,o,s,r,t,void 0,l);if(y)g=R(y,{...i,ref:s,nodeProps:{node:n,pos:e,decorations:t,innerDecorations:r,isSelected:(h==null?void 0:h.selection)instanceof P&&h.selection.node===n},children:R(zi,{pos:e,node:n,innerDecorations:r})});else if(C){p.current||(p.current=C(u.current,S,()=>f.current,a.current,c.current));const{contentDOM:B}=p.current;l.current=B??null,g=D.createElement(n.isInline?"span":"div",{ref:d,contentEditable:!!B,suppressContentEditableWarning:!0},B&&Jr.createPortal(R(zi,{pos:e,node:n,innerDecorations:r}),B))}else{const B=(O=(A=n.type.spec).toDOM)==null?void 0:O.call(A,n);B&&(g=R(mf,{...i,ref:s,outputSpec:B,children:R(zi,{pos:e,node:n,innerDecorations:r})}))}if(!g)throw new Error(`Node spec for ${n.type.name} is missing toDOM`);const E=D.cloneElement(t.reduce(gf,g),t.some(B=>B.type.attrs.nodeName)?{ref:o}:void 0),N=n.marks.reduce((B,T)=>R(h1,{mark:T,children:B}),E);return R(st.Provider,{value:k,children:D.cloneElement(N,n.marks.length||t.some(B=>B.type.attrs.nodeName)?{ref:o}:void 0)})}function Ex(){const t=D.useContext(st),e=D.useRef(null),[n,r]=D.useState(!1);return D.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 pf(void 0,[],e.current,null);t.push(o)}),n?R("img",{ref:e,className:"ProseMirror-separator"}):null}class Bx extends D.Component{constructor(){super(...arguments),this.viewDescRef=null}updateEffect(){const{decorations:e,siblingDescriptors:n,node:r}=this.props,i=Jr.findDOMNode(this);if(!i)return;let o=i;for(;o.firstChild;)o=o.firstChild;!this.viewDescRef||this.viewDescRef instanceof ux?this.viewDescRef=new cx(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(gf,e.text)}}function Nx(){const t=D.useContext(st),e=D.useRef(null);return D.useLayoutEffect(()=>{if(!e.current)return;const n=new pf(void 0,[],e.current,null);t.push(n)}),R("br",{ref:e,className:"ProseMirror-trailingBreak"})}function Ax({widget:t,pos:e}){const n=D.useContext(st),r=D.useRef(null);D.useLayoutEffect(()=>{if(!r.current)return;const o=new df(void 0,t,r.current);n.push(o)});const{Component:i}=t.type;return i&&R(i,{ref:r,widget:t,pos:e,contentEditable:!1})}function Zh(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 gf(t,e){const{nodeName:n,class:r,style:i,contenteditable:o,spellcheck:s,...l}=e.type.attrs;return n||typeof t=="string"?D.createElement(n??"span",{className:r,contentEditable:o,spellCheck:s,style:i&&Zh(i),...l},t):D.cloneElement(t,{className:wx(t.props.className,r),contentEditable:o,spellCheck:s,style:{...t.props.style,...i&&Zh(i)},...l})}function Ua({innerPos:t,childViews:e}){const{view:n}=D.useContext(Do),r=Dl(),i=d1(),o=e.reduce((s,l)=>{var c;const u=s[s.length-1];if(!u)return[[l]];const a=u[u.length-1];return a?!l.marks.length&&!a.marks.length||l.marks.length&&a.marks.length&&((c=l.marks[0])!=null&&c.eq(a.marks[0]))?[...s.slice(0,s.length-1),[...u.slice(0,u.length),l]]:[...s,[l]]:[...s.slice(0,s.length),[l]]},[]);return R(Qa,{children:o.map(s=>{const l=s[0];if(!l)return null;const u=l.marks[0];return u?R(h1,{mark:u,children:R(Ua,{innerPos:t,childViews:s.map(a=>({...a,marks:a.marks.slice(1)}))},Pi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey))},Pi(r==null?void 0:r.doc,t,l,i==null?void 0:i.posToKey)):s.map(a=>{const c=t+a.offset,f=a.type==="widget"?R(Ax,{widget:a.widget,pos:c}):a.type==="native-widget"?R(xx,{widget:a.widget,pos:c}):a.node.isText?R(st.Consumer,{children:d=>R(Bx,{view:n,node:a.node,pos:c,siblingDescriptors:d,decorations:a.outerDeco})}):R(p1,{node:a.node,pos:c,outerDeco:a.outerDeco,innerDeco:a.innerDeco});return D.cloneElement(f,{key:Pi(r==null?void 0:r.doc,t,a,i==null?void 0:i.posToKey)})})})})}function Pi(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 Mx(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 Ox(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 Fx(t,e,n,r){return t.length?t.every(i=>i.type!=="node"||i.node.isInline)?[R(Ua,{childViews:t,innerPos:e},Pi(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 R(p1,{outerDeco:i.outerDeco,node:i.node,innerDeco:i.innerDeco,pos:o},s)}else return R(Ua,{childViews:[i],innerPos:e},Pi(n,e,i,r))}):[]}function zi({pos:t,node:e,innerDecorations:n}){const r=Dl(),i=d1();if(!e)return null;const o=t+1,s=[];Dx(e,n,(a,c,f,d)=>{const p=a.type.spec.marks??[];c?s.push({type:"native-widget",widget:a,marks:p,offset:f,index:d}):s.push({type:"widget",widget:a,marks:p,offset:f,index:d}),Mx(s)},(a,c,f,d)=>{s.push({type:"node",node:a,marks:a.marks,innerDeco:f,outerDeco:c,offset:d}),Ox(s)});const l=Fx(s,o,r==null?void 0:r.doc,i==null?void 0:i.posToKey),u=s[s.length-1];return(!u||u.type!=="node"||u.node.isInline&&!u.node.isText||/\n$/.test(u.node.text))&&l.push(R(Ex,{},"trailing-hack-img"),R(Nx,{},"trailing-hack-br")),R(Qa,{children:l})}const Tx=D.forwardRef(function({className:e,node:n,innerDeco:r,outerDeco:i,as:o,viewDesc:s},l){const u=D.useRef(null);D.useImperativeHandle(l,()=>u.current,[]);const a=c1(n,u,u,r,i,s),c={ref:u,className:e,suppressContentEditableWarning:!0},f=o?D.cloneElement(o,c,R(st.Provider,{value:a,children:R(zi,{pos:-1,node:n,innerDecorations:r})})):D.createElement("div",c,R(st.Provider,{value:a,children:R(zi,{pos:-1,node:n,innerDecorations:r})}));if(!n)return f;const d=i.filter(h=>!h.inline);return d.length?d.reduce(gf,f):f}),m1=D.createContext(null);function Rx({as:t},e){const n=D.useRef(null),{setMount:r,...i}=D.useContext(m1);return D.useImperativeHandle(e,()=>n.current,[]),R(st.Provider,{value:[],children:R(Tx,{ref:o=>{n.current=o,r(o)},...i,as:t})})}const Px=D.forwardRef(Rx);function zx({className:t,children:e,nodeViews:n={},customNodeViews:r,...i}){var c;const[o,s]=D.useState(null),l=yx(o,{...i,nodeViews:r});Cx(l.view);const u=l.view?aD(l.view,l.cursorWrapper):U.empty,a=l.view?oD(l.view):[];return R(Sx,{children:R(Do.Provider,{value:l,children:R(G0.Provider,{value:{nodeViews:n},children:R(m1.Provider,{value:{className:t,setMount:s,node:(c=l.view)==null?void 0:c.state.doc,innerDeco:u,outerDeco:a,viewDesc:l.docViewDescRef.current},children:e})})})})}const _=new xp({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...xk({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]}}}}),bx=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:[YD(),JS({rules:[KS(/^\s*([-+*])\s$/,_.nodes.list)]}),Uk(),tw()]}),Ix=D.forwardRef(function({children:e,nodeProps:n,...r},i){return R("p",{ref:i,...r,children:e})}),Lx=D.forwardRef(function({children:e,nodeProps:n,...r},i){return R("ul",{ref:i,...r,children:e})}),Vx=D.forwardRef(function({children:e,nodeProps:n,...r},i){return R("li",{ref:i,...r,children:e})}),$x=D.forwardRef(function({nodeProps:e,...n},r){return R("span",{ref:r,...n,suppressContentEditableWarning:!0,contentEditable:"false",children:R("button",{children:e.node.attrs.number})})}),_x=D.forwardRef(function({widget:e,pos:n,...r},i){return R("span",{...r,ref:i,style:{display:"block",backgroundColor:"blue",width:"4px",height:"4px",position:"absolute",transform:"translateX(-2px)"},children:"Widget"})}),Wx=new Mt({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 Mt({props:{decorations(t){return U.create(t.doc,[n1(t.selection.from,_x,{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 Ux=[GS({...eC,"Mod-i":Lf(_.marks.em),"Mod-b":Lf(_.marks.strong)}),Wx,VS()],jx={paragraph:()=>{const t=document.createElement("p");return{dom:t,contentDOM:t}}};function Hx(){const[t,e]=D.useState(bx),[n,r]=D.useState(!0);return wf("main",{children:[R("h1",{children:"React ProseMirror Demo"}),wf("button",{onClick:()=>{n?r(i=>!i):window.location.reload()},children:["Switch to"," ",n?"ProseMirror node views":"React node views (requires reload)"]}),R(zx,{className:"ProseMirror",state:t,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:Ux,nodeViews:n?{paragraph:Ix,list:Lx,list_item:Vx,footnote:$x}:void 0,customNodeViews:n?void 0:jx,children:R(Px,{as:R("article",{})})},`${n}`)]})}const Jx=Y0(document.getElementById("root"));Jx.render(R(Hx,{})); diff --git a/docs/assets/index-474d9858.js b/docs/assets/index-474d9858.js deleted file mode 100644 index 0adbdd7..0000000 --- a/docs/assets/index-474d9858.js +++ /dev/null @@ -1,53 +0,0 @@ -(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 dy(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Qh={exports:{}},nl={},Yh={exports:{}},V={};/** - * @license React - * react.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var co=Symbol.for("react.element"),hy=Symbol.for("react.portal"),py=Symbol.for("react.fragment"),my=Symbol.for("react.strict_mode"),gy=Symbol.for("react.profiler"),yy=Symbol.for("react.provider"),Sy=Symbol.for("react.context"),ky=Symbol.for("react.forward_ref"),wy=Symbol.for("react.suspense"),vy=Symbol.for("react.memo"),xy=Symbol.for("react.lazy"),gf=Symbol.iterator;function Cy(t){return t===null||typeof t!="object"?null:(t=gf&&t[gf]||t["@@iterator"],typeof t=="function"?t:null)}var Gh={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Xh=Object.assign,Zh={};function Kr(t,e,n){this.props=t,this.context=e,this.refs=Zh,this.updater=n||Gh}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 ep(){}ep.prototype=Kr.prototype;function Wu(t,e,n){this.props=t,this.context=e,this.refs=Zh,this.updater=n||Gh}var Uu=Wu.prototype=new ep;Uu.constructor=Wu;Xh(Uu,Kr.prototype);Uu.isPureReactComponent=!0;var yf=Array.isArray,tp=Object.prototype.hasOwnProperty,ju={current:null},np={key:!0,ref:!0,__self:!0,__source:!0};function rp(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)tp.call(e,r)&&!np.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 op(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=op(i.content,o.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function sp(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?Oo(r+1,s):Oo(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=ap(this.content,e+this.openStart,n);return r&&new x(r,this.openStart,this.openEnd)}removeBetween(e,n){return new x(lp(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 lp(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(lp(o.content,e-i-1,n-i-1)))}function ap(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=ap(s.content,e-o-1,n);return l&&t.replaceChild(i,s.copy(l))}function Fy(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 up(t,e,n,0)}function up(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&&Ca(t,e,i+1),s=r.depth>i&&Ca(n,r,i+1),l=[];return ki(null,t,i,l),o&&s&&e.index(i)==n.index(i)?(cp(o,s),_n(Wn(o,fp(t,e,n,r,i+1)),l)):(o&&_n(Wn(o,ws(t,e,i+1)),l),ki(e,n,i,l),s&&_n(Wn(s,ws(n,r,i+1)),l)),ki(r,null,i,l),new v(l)}function ws(t,e,n){let r=[];if(ki(null,t,n,r),t.depth>n){let i=Ca(t,e,n+1);_n(Wn(i,ws(t,e,n+1)),r)}return ki(e,null,n,r),new v(r)}function Iy(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 bi{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 Ly(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 bi(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()+")"),dp(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 vs 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):dp(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 vs(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new vs(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 dp(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 Vy(e,n);if(r.next==null)return Kn.empty;let i=hp(r);r.next&&r.err("Unexpected trailing text");let o=Jy(Hy(i));return Ky(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 Vy{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 hp(t){let e=[];do e.push($y(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function $y(t){let e=[];do e.push(_y(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function _y(t){let e=jy(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=Wy(t,e);else break;return e}function wf(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function Wy(t,e){let n=wf(t),r=n;return t.eat(",")&&(t.next!="}"?r=wf(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function Uy(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 jy(t){if(t.eat("(")){let e=hp(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=Uy(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 Hy(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 Sp(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 qy{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class fo{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=yp(i.attrs),this.excluded=null;let o=mp(this.attrs);this.instance=o?new W(this,o):null}create(e=null){return!e&&this.instance?this.instance:new W(this,gp(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new fo(o,i++,n,s)),r}removeFromSet(e){for(var n=0;n-1}}class kp{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=xf.compile(this.spec.nodes,this),this.marks=fo.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?Cf(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==""?[]:Cf(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 xf){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 vs(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 Cf(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 Mf(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new Mf(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=Ef(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=Ef(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 wp={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},Qy={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},vp={ol:!0,ul:!0},xs=1,Cs=2,wi=4;function Nf(t,e,n){return e!=null?(e?xs:0)|(e==="full"?Cs:0):t&&t.whitespace=="pre"?xs|Cs:n&~wi}class Do{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&xs)){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 Yy(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&vp.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function Gy(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Xy(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 Ef(t){let e={};for(let n in t)e[n]=t[n];return e}function Zy(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(Al(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=Of(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return Of(e.marks)}}function Of(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Al(t){return t.document||window.document}const xp=65535,Cp=Math.pow(2,16);function t1(t,e){return t+e*Cp}function Df(t){return t&xp}function n1(t){return(t-(t&xp))/Cp}const Np=1,Mp=2,es=4,Ep=8;let Na=class{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Ep)>0}get deletedBefore(){return(this.delInfo&(Np|es))>0}get deletedAfter(){return(this.delInfo&(Mp|es))>0}get deletedAcross(){return(this.delInfo&es)>0}},Rr=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=Df(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?Mp:e==f?Np:es;return(n<0?e!=a:e!=f)&&(m|=Ep),new Na(p,m,h)}i+=c-u}return r?e+i:new Na(e+i,0,null)}touches(e,n){let r=0,i=Df(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 ts;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 be.fromReplace(e,this.from,this.to,o)}invert(){return new ho(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 ho=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(qu(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return be.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",ho);let Yu=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 be.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return be.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 ns(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 ns(n.from,n.to,n.gapFrom,n.gapTo,x.fromJSON(e,n.slice),n.insert,!!n.structure)}};We.jsonID("replaceAround",Wt);function Ea(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 fo){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 ho(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 Xu(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 rs(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 Zu(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 S1(t,e,n){let r=new Cn(e-n,e+n,x.empty,!0);t.step(r)}function k1(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 ec(t,e,n=e,r=x.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),o=t.resolve(n);return Op(i,o,r)?new Cn(e,n,r):new v1(i,o,r).fit()}function Op(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=Pl(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=Pl(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=Pl(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(Dp(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=zl(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 Pl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Dp(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 zl(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 Tp(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=k1(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=Ap(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 Ap(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 is 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 be.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 be.fromReplace(e,this.pos,this.pos+1,new x(v.from(i),0,n.isLeaf?0:1))}getMap(){return Rr.empty}invert(e){return new is(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 is(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 is(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 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=ec(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 S1(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 Rp(e,n,r)),this}addNodeMark(e,n){return this.step(new Yu(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 Gu(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 Fl=Object.create(null);class I{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Pp(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=Fl[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 Fl)throw new RangeError("Duplicate use of selection JSON ID "+e);return Fl[e]=n,n.prototype.jsonID=e,n}getBookmark(){return B.between(this.$anchor,this.$head).getBookmark()}}I.prototype.visible=!0;class Pp{constructor(e,n){this.$from=e,this.$to=n}}let Af=!1;function Rf(t){!Af&&!t.parent.inlineContent&&(Af=!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 rl(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&&F.isSelectable(l))return F.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 Pf(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 zf=1,To=2,Ff=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|=To,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&To)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~To,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|=Ff,this}get scrolledIntoView(){return(this.updated&Ff)>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 A1=[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 Il{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=A1.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=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 zp(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=zp(i,e,{})),n[r]=i}return n}class Tt{constructor(e){this.spec=e,this.props={},e.props&&zp(e.props,this,this.props),this.key=e.key?e.key.key:Fp("plugin")}getState(e){return e[this.key]}}const bl=Object.create(null);function Fp(t){return t in bl?t+"$"+ ++bl[t]:(bl[t]=0,t+"$")}class po{constructor(e="key"){this.key=Fp(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 P1=(t,e,n)=>{let r=R1(t,n);if(!r)return!1;let i=bp(r);if(!i){let s=r.blockRange(),l=s&&Xu(s);return l==null?!1:(e&&e(t.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Bp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"end")||F.isSelectable(o))){let s=ec(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||!F.isSelectable(s)?!1:(e&&e(t.tr.setSelection(F.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 F1(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=F1(t,n);if(!r)return!1;let i=Lp(r);if(!i)return!1;let o=i.nodeAfter;if(Bp(t,i,e))return!0;if(r.parent.content.size==0&&(zr(o,"start")||F.isSelectable(o))){let s=ec(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 nc(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=nc(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=nc(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(rs(t.doc,o))return e&&e(t.tr.split(o).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Xu(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 F&&e.selection.node.isBlock)return!r.parentOffset||!rs(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:nc(r.node(-1).contentMatchAt(r.indexAfter(-1))),a=t&&t(i.parent,o),u=a?[a]:o&&l?[{type:l}]:void 0,c=rs(s.doc,s.mapping.map(r.pos),1,u);if(!u&&!c&&rs(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||Zu(t.doc,e.pos))?!1:(n&&n(t.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Bp(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;Zu(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&&Xu(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 Vp(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=Vp(-1),J1=Vp(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 bf(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:'"'},Bf=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||Bf&&+Bf[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),Ns[pe]=String.fromCharCode(pe);for(var Bl in Ut)Ns.hasOwnProperty(Bl)||(Ns[Bl]=Ut[Bl]);function _p(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?Ns: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 eS(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[Vl(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 Vf=null;const zt=function(t,e,n){let r=Vf||(Vf=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},qn=function(t,e,n,r){return n&&($f(t,e,n,r,-1)||$f(t,e,n,r,1))},nS=/^(img|br|input|textarea|hr)$/i;function $f(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||ic(t)||nS.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 rS(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 ic(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 il=function(t){return t.focusNode&&qn(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Fn(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function iS(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function oS(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||"",Oa=/Edge\/(\d+)/.exec(Nn),Up=/MSIE \d/.exec(Nn),Da=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Nn),Be=!!(Up||Da||Oa),fn=Up?document.documentMode:Da?+Da[1]:Oa?+Oa[1]:0,pt=!Be&&/gecko\/(\d+)/i.test(Nn);pt&&+(/Firefox\/(\d+)/.exec(Nn)||[0,0])[1];const Ta=!Be&&/Chrome\/(\d+)/.exec(Nn),xe=!!Ta,sS=Ta?+Ta[1]:0,Ae=!Be&&!!Mt&&/Apple Computer/.test(Mt.vendor),Fr=Ae&&(/Mobile\/\w+/.test(Nn)||!!Mt&&Mt.maxTouchPoints>2),Ge=Fr||(Mt?/Mac/.test(Mt.platform):!1),lS=Mt?/Win/.test(Mt.platform):!1,ct=/Android \d/.test(Nn),mo=!!_f&&"webkitFontSmoothing"in _f.documentElement.style,aS=mo?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function uS(t){return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Rt(t,e){return typeof t=="number"?t:t[e]}function cS(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 Wf(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?uS(o):cS(l),c=0,f=0;if(e.topu.bottom-Rt(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+Rt(i,"top")-u.top:e.bottom-u.bottom+Rt(i,"bottom")),e.leftu.right-Rt(r,"right")&&(c=e.right-u.right+Rt(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 fS(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:jp(t.dom)}}function jp(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 dS({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Hp(n,r==0?0:r-e)}function Hp(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?pS(n,i):!n||r&&n.nodeType==1?{node:t,offset:o}:Jp(n,i)}function pS(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 oc(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function mS(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 yS(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 Kp(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;mo&&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=yS(t,r,i,e))}l==null&&(l=gS(t,s,e));let a=t.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Uf(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 $l(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 $l(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 wS(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=qp(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 vS=/[\u0590-\u08ac]/;function xS(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!vS.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 jf=null,Hf=null,Jf=!1;function CS(t,e,n){return jf==e&&Hf==n?Jf:(jf=e,Hf=n,Jf=n=="up"||n=="down"?wS(t,e,n):xS(t,e,n))}const nt=0,Kf=1,bn=2,Et=3;let go=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 em){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 Yp&&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?bn:Kf,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?bn:Et}r=s}this.dirty=bn}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?bn:Kf;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}},NS=class extends go{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}},Ms=class Aa extends go{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 Aa(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=za(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=rm(c,r,n),u?a=new MS(e,n,r,i,c,f||null,d,u,o,s+1):n.isText?new Xp(e,n,r,i,c,d,o):new Gp(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)&&Pa(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 OS(this,s&&s.node,e);AS(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==bn)&&(s&&this.protectLocalComposition(e,s),tm(this.contentDOM,this.children,e),Fr&&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=PS(o.focusNode,o.focusOffset);if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let l=s.nodeValue,a=zS(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 NS(this,o,n,i);e.input.compositionNodes.push(s),this.children=za(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(Pa(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=nm(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 qf(t,e,n,r,i){rm(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 Xp=class Zp 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 Zp(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}},em=class extends go{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 MS 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 tm(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=Ms.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 Ms)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 TS(t,e){return t.type.side-e.type.side}function AS(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 PS(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 za(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 sc(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(il(n)){for(a=l;i&&!i.node;)i=i.parent;let c=i.node;if(i&&c.isAtom&&F.isSelectable(c)&&i.parent&&!(c.isInline&&rS(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;u=new F(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(()=>{(!im(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 om(t,e){if(e instanceof F){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Zf(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Zf(t)}function Zf(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function lc(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function ed(t){return t.editable&&!t.hasFocus()?!1:sm(t)}function sm(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 Fa(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 td(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=Fa(t.state,e);return i&&i instanceof F?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?F.isSelectable(o)?Gt(t,new F(e<0?t.state.doc.resolve(i.pos-o.nodeSize):i)):mo?Gt(t,new B(t.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof F&&r.node.isInline)return Gt(t,new B(e>0?r.$to:r.$from));{let i=Fa(t.state,e);return i?Gt(t,i):!1}}}function Es(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?LS(t):BS(t)}function LS(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(lm(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=Es(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?Ia(t,n,r):i&&Ia(t,i,o)}function BS(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=Es(n),o,s;for(;;)if(r{t.state==i&&$t(t)},50)}function nd(t,e){let n=t.state.doc.resolve(e);if(!(xe||lS)&&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 rd(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=Fa(t.state,e);if(s&&s instanceof F)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 id(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 od(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function _S(t){if(!Ae||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;od(t,r,"true"),setTimeout(()=>od(t,r,"false"),20)}return!1}function WS(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function US(t,e){let n=e.keyCode,r=WS(e);if(n==8||Ge&&n==72&&r=="c")return id(t,-1)||ir(t,-1);if(n==46&&!e.shiftKey||Ge&&n==68&&r=="c")return id(t,1)||ir(t,1);if(n==13||n==27)return!0;if(n==37||Ge&&n==66&&r=="c"){let i=n==37?nd(t,t.state.selection.from)=="ltr"?-1:1:-1;return td(t,i,r)||ir(t,i)}else if(n==39||Ge&&n==70&&r=="c"){let i=n==39?nd(t,t.state.selection.from)=="ltr"?1:-1:1;return td(t,i,r)||ir(t,i)}else{if(n==38||Ge&&n==80&&r=="c")return rd(t,-1,r)||ir(t,-1);if(n==40||Ge&&n==78&&r=="c")return _S(t)||rd(t,1,r)||ir(t,1);if(r==(Ge?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function am(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=pm(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let u=a.firstChild,c,f=0;for(;u&&u.nodeType==1&&(c=hm[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 um(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=JS(n),mo&&KS(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&&!jS.test(d.parentNode.nodeName)?{ignore:!0}:null}})),c)l=qS(sd(l,+c[1],+c[2]),c[4]);else if(l=x.maxOpen(HS(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 jS=/^(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 HS(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&&fm(a,o,l,s[s.length-1],0))s[s.length-1]=u;else{s.length&&(s[s.length-1]=dm(s[s.length-1],o.length));let c=cm(l,a);s.push(c),i=i.matchType(c.type),o=a}}),s)return v.from(s)}return t}function cm(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,v.from(t));return t}function fm(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 sd(t,e,n){return e]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=pm().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&hm[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 Re={},Pe={},QS={touchstart:!0,touchmove:!0};class YS{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 GS(t){for(let e in Re){let n=Re[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{ZS(t,r)&&!ac(t,r)&&(t.editable||!(r.type in Pe))&&n(t,r)},QS[e]?{passive:!0}:void 0)}Ae&&t.dom.addEventListener("input",()=>null),La(t)}function sn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function XS(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function La(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>ac(t,r))})}function ac(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function ZS(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 ek(t,e){!ac(t,e)&&Re[e.type]&&(t.editable||!(e.type in Pe))&&Re[e.type](t,e)}Pe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!gm(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(ct&&xe&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),Fr&&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,Fn(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||US(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(gm(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 ol(t){return{left:t.clientX,top:t.clientY}}function tk(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function uc(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 nk(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&F.isSelectable(r)?(Cr(t,new F(n),"pointer"),!0):!1}function rk(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof F&&(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(F.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,F.create(t.state.doc,i),"pointer"),!0):!1}function ik(t,e,n,r,i){return uc(t,"handleClickOn",e,n,r)||t.someProp("handleClick",o=>o(t,e,r))||(i?rk(t,n):nk(t,n))}function ok(t,e,n,r){return uc(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function sk(t,e,n,r){return uc(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||lk(t,n,r)}function lk(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(F.isSelectable(s))Cr(t,F.create(r,l),"pointer");else continue;return!0}}function cc(t){return Os(t)}const mm=Ge?"metaKey":"ctrlKey";Re.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=cc(t),i=Date.now(),o="singleClick";i-t.input.lastClick.time<500&&tk(n,t.input.lastClick)&&!n[mm]&&(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(ol(n));s&&(o=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new ak(t,s,n,!!r)):(o=="doubleClick"?ok:sk)(t,s.pos,s.inside,n)?n.preventDefault():sn(t,"pointer"))};class ak{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[mm],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 F&&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(ol(e))),this.updateAllowDefault(e),this.allowDefault||!n?sn(this.view,"pointer"):ik(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Ae&&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)}}Re.touchstart=t=>{t.input.lastTouch=Date.now(),cc(t),sn(t,"pointer")};Re.touchmove=t=>{t.input.lastTouch=Date.now(),sn(t,"pointer")};Re.contextmenu=t=>cc(t);function gm(t,e){return t.composing?!0:Ae&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const uk=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(),Os(t,!0),t.markCursor=null;else if(Os(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}ym(t,uk)};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++,ym(t,20))};function ym(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Os(t),e))}function Sm(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=ck());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function ck(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function Os(t,e=!1){if(!(ct&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Sm(t),e||t.docView&&t.docView.dirty){let n=sc(t);return n&&!n.eq(t.state.selection)?t.dispatch(t.state.tr.setSelection(n)):t.updateState(t.state),!0}return!1}}function fk(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||Fr&&aS<604;Re.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}=am(t,s);o?(n.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):fk(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dk(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function hk(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=um(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=dk(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 km(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,km(r),r.getData("text/html"),i,n)?n.preventDefault():hk(t,n)};class wm{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const vm=Ge?"altKey":"ctrlKey";Re.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(ol(n)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof F?i.to-1:i.to))){if(r&&r.mightDrag)s=F.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=F.create(t.state.doc,c.posBefore))}}let l=(s||t.state.selection).content(),{dom:a,text:u}=am(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 wm(l,!n[vm],s)};Re.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(ol(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=um(t,km(n.dataTransfer),Vi?null:n.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!n[vm]);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&&F.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))u.setSelection(new F(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(lc(t,p,u.doc.resolve(h)))}t.focus(),t.dispatch(u.setMeta("uiEvent","drop"))};Re.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))};Re.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)};Re.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,Fn(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)Re[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 Ds{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 Ds&&(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=Nm(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 pk(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=mk(l,t,e,n,i,o,s),c=Ts(u,r,0,s);e=c.local;for(let f=0;fn&&s.to{let u=Nm(t,l,a+n);if(u){o=!0;let c=Ts(u,l,n+a+1,r);c!=we&&i.push(a,a+l.nodeSize,c)}});let s=Cm(o?Mm(t):t,-n).sort(jn);for(let l=0;l0;)e++;t.splice(e,0,n)}function Wl(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])),xm.from(e)}const gk={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yk=Be&&fn<=11;let Sk=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 kk{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Sk,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()}),yk&&(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,gk)),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(ed(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)&&ed(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),wk(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:Ck,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 Ck(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Ae&&/^(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||Ae&&/^(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 Nk=/^(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 Mk(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=sc(t,E);if(P&&!t.state.selection.eq(P)){if(xe&&ct&&t.input.lastKeyCode===13&&Date.now()-100At(t,Fn(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=xk(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&&!Nk.test(E.nodeName))&&(!h||h.endA>=h.endB)&&t.someProp("handleKeyDown",E=>E(t,Fn(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=fd(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((Fr&&t.input.lastIOSEnter>Date.now()-225&&(!y||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!y&&m.posE(t,Fn(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>h.start&&Ok(c,h.start,h.endA,m,k)&&t.someProp("handleKeyDown",E=>E(t,Fn(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,Fn(13,"Enter"))})},20));let w=h.start,M=h.endA,O,D,A;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&&(A=Ek(m.parent.content.cut(m.parentOffset,k.parentOffset),g.parent.content.cut(g.parentOffset,h.endA-g.start()))))O=t.state.tr,A.type=="add"?O.addMark(w,M,A.mark):O.removeMark(w,M,A.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=fd(t,O.doc,u.sel);E&&!(xe&&ct&&t.composing&&E.empty&&(h.start!=h.endB||t.input.lastAndroidDeletee.content.size?null:lc(t,e.resolve(n.anchor),e.resolve(n.head))}function Ek(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||Ul(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 Dk(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 Tk{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 YS,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(yd),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=md(this),pd(this),this.nodeViews=gd(this),this.docView=qf(this.state.doc,hd(this),Wl(this),this.dom,this),this.domObserver=new kk(this,(r,i,o,s)=>Mk(this,r,i,o,s)),this.domObserver.start(),GS(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&&La(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(yd),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&&(Sm(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=gd(this);Rk(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&La(this),this.editable=md(this),pd(this);let a=Wl(this),u=hd(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&&fS(this);if(s){this.domObserver.stop();let p=f&&(Be||xe)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ak(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=qf(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):(om(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&&dS(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof F){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&Wf(this,n.getBoundingClientRect(),e)}else Wf(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 wm(e.slice,e.move,i<0?void 0:F.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 SS(this,e)}coordsAtPos(e,n=1){return qp(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 CS(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&&(XS(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Wl(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 ek(this,e)}dispatch(e){let n=this._props.dispatchTransaction;n?n.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return Ae&&this.root.nodeType===11&&iS(this.dom.ownerDocument)==this.dom?vk(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function hd(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 pd(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 md(t){return!t.someProp("editable",e=>e(t.state)===!1)}function Ak(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 gd(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 yd(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 hc(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!Pk(e)||!zk(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&&!F.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 hc{constructor(e){this.pos=e}map(e){return new hc(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return Z.valid(n)?new Z(n):I.near(n)}}function Pk(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 zk(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 Fk(){return new Tt({props:{decorations:Bk,createSelectionBetween(t,e,n){return e.pos==n.pos&&Z.valid(n)?new Z(n):null},handleClick:bk,handleKeyDown:Ik,handleDOMEvents:{beforeinput:Lk}}})}const Ik=Wp({ArrowLeft:Ao("horiz",-1),ArrowRight:Ao("horiz",1),ArrowUp:Ao("vert",-1),ArrowDown:Ao("vert",1)});function Ao(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&&F.isSelectable(t.state.doc.nodeAt(i.inside))?!1:(t.dispatch(t.state.tr.setSelection(new Z(r))),!0)}function Lk(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 Bk(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"?Vk(n):n,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function Vk(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 $k=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 Sd(n,r,i,o,t,e)},handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:r}=n.state.selection;r&&Sd(n,r.pos,r.pos,"",t,e)})}}},isInputRules:!0});return e}function Sd(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-$k),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&&Zu(u.doc,s-1)&&(!r||r(o,p))&&u.join(s-1),u})}const Uk=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function jk(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[jl(o,r)];if(l&&l(n.state,n.dispatch,n))return!0}}return!1}}const Em=65535,Om=Math.pow(2,16);function qk(t,e){return t+e*Om}function kd(t){return t&Em}function Qk(t){return(t-(t&Em))/Om}const Dm=1,Tm=2,ss=4,Am=8;class Ba{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Am)>0}get deletedBefore(){return(this.delInfo&(Dm|ss))>0}get deletedAfter(){return(this.delInfo&(Tm|ss))>0}get deletedAcross(){return(this.delInfo&ss)>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:qk(l/3,e-a),m=e==a?Tm:e==f?Dm:ss;return(n<0?e!=a:e!=f)&&(m|=Am),new Ba(p,m,h)}i+=c-u}return r?e+i:new Ba(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(pc(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 Va(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 Yk(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 Gk(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 fo){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 Xk(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 Zk(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=Jl(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=Jl(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=Jl(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(Pm(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=Kl(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 Jl(t,e){for(let n=0;n1&&(r=r.replaceChild(0,Pm(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 Kl(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 zm(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=Fm(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 Fm(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 br=class extends Error{};br=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};br.prototype=Object.create(Error.prototype);br.prototype.constructor=br;br.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 br(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 Zk(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 Yk(this,e,n,r),this}removeMark(e,n,r){return Gk(this,e,n,r),this}clearIncompatible(e,n,r){return Xk(this,e,n,r),this}}var $a,_a;if(typeof WeakMap<"u"){let t=new WeakMap;$a=e=>t.get(e),_a=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;$a=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 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 vd(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 kw(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=>wd(r,e)}],toDOM(r){return["td",vd(r,e),0]}},table_header:{content:t.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>wd(r,e)}],toDOM(r){return["th",vd(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 po("selectingCells");function yo(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 mc(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=yo(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 Wa(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function gc(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 Pp(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(Wa(r)&&Wa(i)&&gc(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 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 F&&(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 po("fix-tables");function Bm(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&&Bm(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 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 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(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 ls(n,r,I.near(o.$headCell,e));if(t!="horiz"&&!o.empty)return!1;const s=Vm(i,t,e);if(s==null)return!1;if(t=="horiz")return ls(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),ls(n,r,u)}}}function Po(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=Vm(i,t,e);if(a==null)return!1;s=new ce(n.doc.resolve(a))}const l=bm(s.$headCell,t,e);return l?ls(n,r,new ce(s.$anchorCell,l)):!1}}function zo(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 Fw(t,e){const n=t.state.doc,r=yo(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new ce(r))),!0):!1}function Iw(t,e,n){if(!mc(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(Ua(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),Nd(t.state,t.dispatch,s,l,r),!0}else if(r){const o=Im(t.state),s=o.start(-1);return Nd(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=Md(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=yo(t.state.selection.$anchor))!=null&&((n=ql(t,e))==null?void 0:n.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(a,u){let c=ql(t,u);const f=tn.getState(t.state)==null;if(!c||!gc(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(Md(t,u.target)!=r&&(f=ql(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 Vm(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 Md(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function ql(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});return n&&n?yo(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")),ja(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,ja(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){return t.type=="attributes"&&(t.target==this.table||this.colgroup.contains(t.target))}};function ja(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 as{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 as(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new as(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return Wa(e.doc.resolve(i))||(i=-1),new as(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=Ed(t,e,"left",n):u-e.clientX<=n&&(l=Ed(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}$m(t,l)}}}function _w(t){const e=et.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&$m(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,Od(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=Od(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}}yc("row",{useDeprecatedLogic:!0});yc("column",{useDeprecatedLogic:!0});yc("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:bw},createSelectionBetween(e){return tn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Fw,handleKeyDown:zw,handlePaste:Iw},appendTransaction(e,n,r){return Mw(r,Ow(r,n),t)}})}var Wm={exports:{}},Qe={},Um={exports:{}},jm={};/** - * @license React - * scheduler.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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(R,b){var L=R.length;R.push(b);e:for(;0>>1,ae=R[ee];if(0>>1;eei(Ml,L))Ani(Mo,Ml)?(R[ee]=Mo,R[An]=L,ee=An):(R[ee]=Ml,R[Tn]=L,ee=Tn);else if(Ani(Mo,L))R[ee]=Mo,R[An]=L,ee=An;else break e}}return b}function i(R,b){var L=R.sortIndex-b.sortIndex;return L!==0?L:R.id-b.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(R){for(var b=n(u);b!==null;){if(b.callback===null)r(u);else if(b.startTime<=R)r(u),b.sortIndex=b.expirationTime,e(a,b);else break;b=n(u)}}function w(R){if(m=!1,S(R),!h)if(n(a)!==null)h=!0,Cl(M);else{var b=n(u);b!==null&&Nl(w,b.startTime-R)}}function M(R,b){h=!1,m&&(m=!1,g(A),A=-1),p=!0;var L=d;try{for(S(b),f=n(a);f!==null&&(!(f.expirationTime>b)||R&&!ne());){var ee=f.callback;if(typeof ee=="function"){f.callback=null,d=f.priorityLevel;var ae=ee(f.expirationTime<=b);b=t.unstable_now(),typeof ae=="function"?f.callback=ae:f===n(a)&&r(a),S(b)}else r(a);f=n(a)}if(f!==null)var No=!0;else{var Tn=n(u);Tn!==null&&Nl(w,Tn.startTime-b),No=!1}return No}finally{f=null,d=L,p=!1}}var O=!1,D=null,A=-1,E=5,P=-1;function ne(){return!(t.unstable_now()-PR||125ee?(R.sortIndex=L,e(u,R),n(a)===null&&R===n(u)&&(m?(g(A),A=-1):m=!0,Nl(w,L-ee))):(R.sortIndex=ae,e(a,R),h||p||(h=!0,Cl(M))),R},t.unstable_shouldYield=ne,t.unstable_wrapCallback=function(R){var b=d;return function(){var L=d;d=b;try{return R.apply(this,arguments)}finally{d=L}}}})(jm);Um.exports=jm;var Gw=Um.exports;/** - * @license React - * react-dom.production.min.js - * - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Hm=C,qe=Gw;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"),Ha=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]*$/,Td={},Ad={};function Zw(t){return Ha.call(Ad,t)?!0:Ha.call(Td,t)?!1:Xw.test(t)?Ad[t]=!0:(Td[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 Fe(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 Fe(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 Fe(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){ye[t]=new Fe(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){ye[t]=new Fe(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 Fe(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){ye[t]=new Fe(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){ye[t]=new Fe(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){ye[t]=new Fe(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){ye[t]=new Fe(t,5,!1,t.toLowerCase(),null,!1,!1)});var Sc=/[\-:]([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(Sc,kc);ye[e]=new Fe(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(Sc,kc);ye[e]=new Fe(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(Sc,kc);ye[e]=new Fe(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){ye[t]=new Fe(t,1,!1,t.toLowerCase(),null,!1,!1)});ye.xlinkHref=new Fe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){ye[t]=new Fe(t,1,!1,t.toLowerCase(),null,!0,!0)});function wc(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{Yl=!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=Gl(t.type,!1),t;case 11:return t=Gl(t.type.render,!1),t;case 1:return t=Gl(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 Ja:return"Profiler";case vc:return"StrictMode";case Ka:return"Suspense";case qa:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case qm:return(t.displayName||"Context")+".Consumer";case Km:return(t._context.displayName||"Context")+".Provider";case xc:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Cc: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===vc?"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 Ym(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function iv(t){var e=Ym(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=iv(t))}function Gm(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=Ym(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function As(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 Ya(t,e){var n=e.checked;return G({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function Pd(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 Xm(t,e){e=e.checked,e!=null&&wc(t,"checked",e,!1)}function Ga(t,e){Xm(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")?Xa(t,e.type,n):e.hasOwnProperty("defaultValue")&&Xa(t,e.type,vn(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function zd(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 Xa(t,e,n){(e!=="number"||As(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},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 ng(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 rg(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=ng(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 tu(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 nu(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 ru=null;function Nc(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var iu=null,Er=null,Or=null;function bd(t){if(t=wo(t)){if(typeof iu!="function")throw Error(N(280));var e=t.stateNode;e&&(e=cl(e),iu(t.stateNode,t.type,e))}}function ig(t){Er?Or?Or.push(t):Or=[t]:Er=t}function og(){if(Er){var t=Er,e=Or;if(Or=Er=null,bd(t),e)for(t=0;t>>=0,t===0?32:31-(yv(t)/Sv|0)|0}var Lo=64,Bo=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 Fs(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 So(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),Hd=String.fromCharCode(32),Jd=!1;function Mg(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 Eg(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 Eg(e);case"keypress":return e.which!==32?null:(Jd=!0,Hd);case"textInput":return t=e.data,t===Hd&&Jd?null:t;default:return null}}function Zv(t,e){if(dr)return t==="compositionend"||!Pc&&Mg(t,e)?(t=Cg(),cs=Tc=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=Yd(n)}}function Ag(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?Ag(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function Rg(){for(var t=window,e=As();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=As(t.document)}return e}function zc(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=Rg(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&Ag(n.ownerDocument.documentElement,n)){if(r!==null&&zc(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=Gd(n,o);var s=Gd(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,cu=null,Di=null,fu=!1;function Xd(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;fu||hr==null||hr!==As(r)||(r=hr,"selectionStart"in r&&zc(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=Ls(cu,"onSelect"),0gr||(t.current=yu[gr],yu[gr]=null,gr--)}function H(t,e){gr++,yu[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 Vs(){K(Ve),K(Ne)}function oh(t,e,n){if(Ne.current!==xn)throw Error(N(168));H(Ne,e),H(Ve,n)}function $g(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 $s(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||xn,Qn=Ne.current,H(Ne,t),H(Ve,Ve.current),!0}function sh(t,e,n){var r=t.stateNode;if(!r)throw Error(N(169));n?(t=$g(t,e,Qn),r.__reactInternalMemoizedMergedChildContext=t,K(Ve),K(Ne),H(Ne,t)):K(Ve),H(Ve,n)}var bt=null,fl=!1,fa=!1;function _g(t){bt===null?bt=[t]:bt.push(t)}function wx(t){fl=!0,_g(t)}function On(){if(!fa&&bt!==null){fa=!0;var t=0,e=j;try{var n=bt;for(j=1;t>=s,i-=s,Bt=1<<32-dt(e)+i|n<A?(E=D,D=null):E=D.sibling;var P=d(g,D,S[A],w);if(P===null){D===null&&(D=E);break}t&&D&&P.alternate===null&&e(g,D),y=o(P,y,A),O===null?M=P:O.sibling=P,O=P,D=E}if(A===S.length)return n(g,D),q&&Pn(g,A),M;if(D===null){for(;AA?(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,A),O===null?M=ne:O.sibling=ne,O=ne,D=E}if(P.done)return n(g,D),q&&Pn(g,A),M;if(D===null){for(;!P.done;A++,P=S.next())P=f(g,P.value,w),P!==null&&(y=o(P,y,A),O===null?M=P:O.sibling=P,O=P);return q&&Pn(g,A),M}for(D=r(g,D);!P.done;A++,P=S.next())P=p(D,g,A,P.value,w),P!==null&&(t&&P.alternate!==null&&D.delete(P.key===null?A:P.key),y=o(P,y,A),O===null?M=P:O.sibling=P,O=P);return t&&D.forEach(function(At){return e(g,At)}),q&&Pn(g,A),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 Fo: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&&hh(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=Ss(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=ka(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);Ho(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=Sa(S,g.mode,w),y.return=g,g=y),s(g)):n(g,y)}return k}var _r=Qg(!0),Yg=Qg(!1),vo={},Nt=En(vo),eo=En(vo),to=En(vo);function $n(t){if(t===vo)throw Error(N(174));return t}function Wc(t,e){switch(H(to,e),H(eo,t),H(Nt,vo),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:eu(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=eu(e,t)}K(Nt),H(Nt,e)}function Wr(){K(Nt),K(eo),K(to)}function Gg(t){$n(to.current);var e=$n(Nt.current),n=eu(e,t.type);e!==n&&(H(eo,t),H(Nt,n))}function Uc(t){eo.current===t&&(K(Nt),K(eo))}var Q=En(0);function Js(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 da=[];function jc(){for(var t=0;tn?n:4,t(!0);var r=ha.transition;ha.transition={};try{t(!1),e()}finally{j=n,ha.transition=r}}function h0(){return ot().memoizedState}function Nx(t,e,n){var r=kn(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},p0(t))m0(e,n);else if(n=Hg(t,e,n,r),n!==null){var i=Te();ht(n,t,r,i),g0(n,e,r)}}function Mx(t,e,n){var r=kn(t),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(p0(t))m0(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,$c(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}n=Hg(t,e,i,r),n!==null&&(i=Te(),ht(n,t,r,i),g0(n,e,r))}}function p0(t){var e=t.alternate;return t===Y||e!==null&&e===Y}function m0(t,e){Ti=Ks=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function g0(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Ec(t,n)}}var qs={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},Ex={readContext:it,useCallback:function(t,e){return yt().memoizedState=[t,e===void 0?null:e],t},useContext:it,useEffect:mh,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,ps(4194308,4,a0.bind(null,e,t),n)},useLayoutEffect:function(t,e){return ps(4194308,4,t,e)},useInsertionEffect:function(t,e){return ps(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:ph,useDebugValue:Qc,useDeferredValue:function(t){return yt().memoizedState=t},useTransition:function(){var t=ph(!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||e0(r,e,n)}i.memoizedState=n;var o={value:n,getSnapshot:e};return i.queue=o,mh(n0.bind(null,r,o,t),[t]),r.flags|=2048,io(9,t0.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,M0(t,e,!1,!1),e.stateNode=t;e:{switch(s=nu(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=Js(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 tf(),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 Fx(t,e){switch(Ic(e),e.tag){case 1:return $e(e.type)&&Vs(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Wr(),K(Ve),K(Ne),jc(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Uc(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 Vc(e.type._context),null;case 22:case 23:return tf(),null;case 24:return null;default:return null}}var Ko=!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 Tu(t,e,n){try{n()}catch(r){X(t,e,r)}}var Nh=!1;function bx(t,e){if(du=Is,t=Rg(),zc(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(hu={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=Nh,Nh=!1,h}function Ai(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&&Tu(e,n,o)}i=i.next}while(i!==r)}}function pl(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 Au(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 D0(t){var e=t.alternate;e!==null&&(t.alternate=null,D0(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[gu],delete e[Sx],delete e[kx])),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 T0(t){return t.tag===5||t.tag===3||t.tag===4}function Mh(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||T0(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=Bs));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 Pu(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(Pu(t,e,n),t=t.sibling;t!==null;)Pu(t,e,n),t=t.sibling}var he=null,ut=!1;function Qt(t,e,n){for(n=n.child;n!==null;)A0(t,e,n),n=n.sibling}function A0(t,e,n){if(Ct&&typeof Ct.onCommitFiberUnmount=="function")try{Ct.onCommitFiberUnmount(sl,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?ca(t.parentNode,n):t.nodeType===1&&ca(t,n),qi(t)):ca(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)&&Tu(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 Eh(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,Gs=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()-Zc?Hn(t,0):Xc|=n),_e(t,e)}function B0(t,e){e===0&&(t.mode&1?(e=Bo,Bo<<=1,!(Bo&130023424)&&(Bo=4194304)):e=1);var n=Te();t=Jt(t,e),t!==null&&(So(t,e,n),_e(t,n))}function jx(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),B0(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),B0(t,n)}var V0;V0=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&&Wg(e,Ws,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;ms(t,e),t=e.pendingProps;var i=Vr(e,Ne.current);Tr(e,n),i=Jc(null,e,r,t,i,n);var o=Kc();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,$s(e)):o=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,_c(e),i.updater=dl,e.stateNode=i,i._reactInternals=e,xu(e,r,t,n),e=Mu(null,e,r,!0,o,n)):(e.tag=0,q&&o&&Fc(e),Ee(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(ms(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=Nu(null,e,r,t,n);break e;case 1:e=vh(null,e,r,t,n);break e;case 11:e=kh(null,e,r,t,n);break e;case 14:e=wh(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),Nu(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),vh(t,e,r,i,n);case 3:e:{if(x0(e),t===null)throw Error(N(387));r=e.pendingProps,o=e.memoizedState,i=o.element,Jg(t,e),Hs(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=xh(t,e,r,n,i);break e}else if(r!==i){i=Ur(Error(N(424)),e),e=xh(t,e,r,n,i);break e}else for(He=gn(e.stateNode.containerInfo.firstChild),Ke=e,q=!0,ft=null,n=Yg(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 Gg(e),t===null&&ku(e),r=e.type,i=e.pendingProps,o=t!==null?t.memoizedProps:null,s=i.children,pu(r,i)?s=null:o!==null&&pu(r,o)&&(e.flags|=32),v0(t,e),Ee(t,e,s,n),e.child;case 6:return t===null&&ku(e),null;case 13:return C0(t,e,n);case 4:return Wc(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(Us,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),wu(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),wu(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),wh(t,e,r,i,n);case 15:return k0(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:at(r,i),ms(t,e),e.tag=1,$e(r)?(t=!0,$s(e)):t=!1,Tr(e,n),qg(e,r,i),xu(e,r,i,n),Mu(null,e,r,!0,t,n);case 19:return N0(t,e,n);case 22:return w0(t,e,n)}throw Error(N(156,e.tag))};function $0(t,e){return dg(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 rf(t){return t=t.prototype,!(!t||!t.isReactComponent)}function Kx(t){if(typeof t=="function")return rf(t)?1:0;if(t!=null){if(t=t.$$typeof,t===xc)return 11;if(t===Cc)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 Ss(t,e,n,r,i,o){var s=2;if(r=t,typeof t=="function")rf(t)&&(s=1);else if(typeof t=="string")s=5;else e:switch(t){case fr:return Jn(n.children,i,o,e);case vc:s=8,i|=8;break;case Ja:return t=tt(12,n,e,i|2),t.elementType=Ja,t.lanes=o,t;case Ka:return t=tt(13,n,e,i),t.elementType=Ka,t.lanes=o,t;case qa:return t=tt(19,n,e,i),t.elementType=qa,t.lanes=o,t;case Qm:return gl(n,i,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case Km:s=10;break e;case qm:s=9;break e;case xc:s=11;break e;case Cc: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 gl(t,e,n,r){return t=tt(22,t,r,e),t.elementType=Qm,t.lanes=n,t.stateNode={isHidden:!1},t}function Sa(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=Zl(0),this.expirationTimes=Zl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Zl(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function of(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(j0)}catch(t){console.error(t)}}j0(),Wm.exports=Qe;var Hr=Wm.exports,H0,Fh=Hr;H0=Fh.createRoot,Fh.hydrateRoot;const xo=C.createContext(null),J0=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={},Lu=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 K0(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!=Lu&&n.push(i)}),e&&n.push(U.create(t.state.doc,[e])),In.from(n)}const uf=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},oC=function(t,e,n,r){return n&&(Lh(t,e,n,r,-1)||Lh(t,e,n,r,1))},sC=/^(img|br|input|textarea|hr)$/i;function Lh(t,e,n,r,i){for(;;){if(t==n&&e==r)return!0;if(e==(i<0?0:el(t))){const o=t.parentNode;if(!o||o.nodeType!=1||aC(t)||sC.test(t.nodeName)||t.contentEditable=="false")return!1;e=uf(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?el(t):0}else return!1}}function el(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function lC(t,e,n){for(let r=e==0,i=e==el(t);r||i;){if(t==n)return!0;const o=uf(t);if(t=t.parentNode,!t)return!1;r=r&&o==0,i=i&&o==el(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 q0=function(t){return t.focusNode&&oC(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)},Q0=C.createContext(null);function uC(t,e){const n=C.useContext(Q0);C.useLayoutEffect(()=>n(t),e)}function Y0(t,e){const{view:n}=C.useContext(xo);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,[]),Y0(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,uf(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 G0(t,e,n){return new me(t,t,new so(e,n))}function wa(){return Math.floor(Math.random()*16777215).toString(16)}const lo=new po("@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=wa();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=wa()),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=wa();return l.posToKey.set(c,f),l.keyToPos.set(f,c),!0}),l}},props:{handleDOMEvents:{compositionstart:()=>{t=!0},compositionend:()=>{t=!1}}}})}const pC=/\s/,mC=/[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/,gC=/['\u2018\u2019]/,ao=(t,e,n=-1)=>{if(t.resolve(e).parentOffset===0)return!1;const i=t.textBetween(e+n,e,null," ");return pC.test(i)?!1:gC.test(i)&&ao(t,e-1)?!0:!mC.test(i)};function va(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 yC(t,e){let n=e;for(;!ao(t,n);)n--;for(;ao(t,n);)n--;return n}function SC(t,e){let n=e;for(;!ao(t,n,1);)n++;for(;ao(t,n,1);)n++;return n}function kC(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(G0(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 va(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.docView.posFromDOM(u.startContainer,u.startOffset,1),f=r.docView.posFromDOM(u.endContainer,u.endOffset,1);va(r,a,{from:c,to:f})}});break}case"insertText":{va(r,i.data);break}case"deleteWordBackward":{const{tr:l,doc:a,selection:u}=r.state,c=u.empty?yC(r.state.doc,u.from):u.from,f=u.to,d=a.resolve(c).marksAcross(a.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteWordForward":{const{tr:l,doc:a,selection:u}=r.state,c=u.empty?SC(r.state.doc,u.from):u.from,f=u.to,d=a.resolve(c).marksAcross(a.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteContentBackward":{const{tr:l,doc:a,selection:u}=r.state,c=u.empty?u.from-1:u.from,f=u.to,d=a.resolve(c).marksAcross(a.resolve(f));l.delete(c,f).setStoredMarks(d),r.dispatch(l);break}case"deleteContentForward":{const{tr:l,doc:a,selection:u}=r.state,c=u.from,f=u.empty?u.to+1:u.to,d=a.resolve(c).marksAcross(a.resolve(f));l.delete(c,f).setStoredMarks(d);break}case"deleteContent":{const{tr:l,doc:a,selection:u}=r.state,c=a.resolve(u.from).marksAcross(a.resolve(u.to));l.delete(u.from,u.to).setStoredMarks(c),r.dispatch(l);break}}return!0}}}})}const Dt=typeof navigator<"u"?navigator:null,Bh=typeof document<"u"?document:null,Dn=Dt&&Dt.userAgent||"",Bu=/Edge\/(\d+)/.exec(Dn),X0=/MSIE \d/.exec(Dn),Vu=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Dn),vl=!!(X0||Vu||Bu),wC=X0?document.documentMode:Vu?+Vu[1]:Bu?+Bu[1]:0,Z0=!vl&&/gecko\/(\d+)/i.test(Dn),vC=Z0&&+(/Firefox\/(\d+)/.exec(Dn)||[0,0])[1],$u=!vl&&/Chrome\/(\d+)/.exec(Dn),xC=!!$u,CC=$u?+$u[1]:0,ey=!vl&&!!Dt&&/Apple Computer/.test(Dt.vendor),ty=ey&&(/Mobile\/\w+/.test(Dn)||!!Dt&&Dt.maxTouchPoints>2),NC=ty||(Dt?/Mac/.test(Dt.platform):!1),MC=Dt?/Win/.test(Dt.platform):!1,EC=/Android \d/.test(Dn),ny=!!Bh&&"webkitFontSmoothing"in Bh.documentElement.style,OC=ny?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Ce={ie:vl,ie_version:wC,gecko:Z0,gecko_version:vC,chrome:xC,chrome_version:CC,safari:ey,ios:ty,mac:NC,windows:MC,android:EC,webkit:ny,webkit_version:OC};function Vh(t){return t.editable&&!t.hasFocus()?!1:DC(t)}function DC(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 TC(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||B.between(e,n,r)}function $h(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(q0(n)){for(a=l;i&&!i.node;)i=i.parent;const c=i.node;if(i&&c.isAtom&&F.isSelectable(c)&&i.parent&&!(c.isInline&&lC(n.focusNode,n.focusOffset,i.dom))){const f=i.posBefore;u=new F(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(()=>{(!ry(e)||e.state.selection.visible)&&e.dom.classList.remove("ProseMirror-hideselection")},20))})}const Jh=Ce.safari||Ce.chrome&&Ce.chrome_version<63;function Yo(t,e=!1){const n=t,r=n.state.selection;if(PC(n,r),!!ry(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&&tl(i.anchorNode,i.anchorOffset,o.anchorNode,o.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)FC(n);else{const{anchor:i,head:o}=r;let s,l;Jh&&!(r instanceof B)&&(r.$from.parent.inlineContent||(s=jh(n,r.from)),!r.empty&&!r.$from.parent.inlineContent&&(l=jh(n,r.to))),n.docView.setSelection(i,o,n.root,e),Jh&&(s&&Hh(s),l&&Hh(l)),r.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&IC(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}class bC{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 LC{constructor(e){this.view=e,this.flushingSoon=-1,this.currentSelection=new bC,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=$h(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;Yo(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)&&Vh(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(Vh(this.view)&&!this.view.composing){if(this.suppressingSelectionUpdates)return Yo(this.view);if(Ce.ie&&Ce.ie_version<=11&&!this.view.state.selection.empty){const e=this.view.domSelectionRange();if(e.focusNode&&tl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}}const Jr=0,Kh=1,Go=2,uo=3;class Co{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 df){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 cf&&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?Go:Kh,e==l&&n==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=uo:o.markDirty(e-l,n-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Go:uo}r=s}this.dirty=Go}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){const r=e==1?Go:Kh;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)&&_C(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 $C extends ff{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=uo)}get domAtom(){return!1}}class df extends Co{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 _C(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 po("@nytimes/react-prosemirror/componentEventListeners"),props:{handleDOMEvents:e}})}function UC(){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(()=>WC(t),[t]);return{registerEventListener:n,unregisterEventListener:r,componentEventListenersPlugin:i}}function iy(){const[,t]=C.useReducer(e=>e+1,0);return t}class jC extends Tk{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 LC(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 HC=new kp({nodes:{doc:{content:"text*"},text:{inline:!0}}}),JC=on.create({schema:HC});function KC(t,e){const[n,r]=C.useState(null),[i,o]=C.useState(null),s=iy(),l=e.defaultState??JC,[a,u]=C.useState(l),c=e.state??a,{componentEventListenersPlugin:f,registerEventListener:d,unregisterEventListener:p}=UC(),h=C.useCallback(w=>{Hr.flushSync(()=>{o(w)})},[]),m=C.useMemo(()=>[...e.plugins??[],f,kC(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 ff(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 jC({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 qC(t){C.useLayoutEffect(()=>{t==null||t.domObserver.selectionToDOM(),t==null||t.runPendingEffects()},[t,t==null?void 0:t.props])}function QC({children:t}){const e=C.useRef(new Set).current,n=C.useRef(new Set).current,r=C.useRef(!1),i=iy(),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(Q0.Provider,{value:l,children:t})}const st=C.createContext([]);function oy(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 ff(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 sy={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 xl(){const{state:t}=C.useContext(xo);return t}function ly(){const t=xl();return t&&lo.getState(t)}const hf=C.forwardRef(function({outputSpec:e,children:n,...r},i){if(typeof e=="string")return z(Ku,{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(hf,{ref:void 0,outputSpec:d,children:n}))}return C.createElement(s,a,...c)}),ay=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 VC(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(hf,{ref:s,outputSpec:l,children:z(st.Provider,{value:o,children:n})})});function eN({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null),i=C.useRef(e);return i.current=e,Y0(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 cf(void 0,t,r.current);n.push(o)}),z("span",{ref:r})}function uy({outerDeco:t,pos:e,node:n,innerDeco:r,...i}){var D,A;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=xl(),{nodeViews:m}=C.useContext(J0),{view:k}=C.useContext(xo);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:At}=p.current;s.current=d.current,d.current.appendChild(At)},[S,k,r,n,t]);const w=oy(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 F&&h.selection.node===n},children:z(Fi,{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(Fi,{pos:e,node:n,innerDecorations:r}),E))}else{const E=(A=(D=n.type.spec).toDOM)==null?void 0:A.call(D,n);E&&(g=z(hf,{...i,ref:s,outputSpec:E,children:z(Fi,{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(pf,g),t.some(E=>E.type.attrs.nodeName)?{ref:o}:void 0),O=n.marks.reduce((E,P)=>z(ay,{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 tN(){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 df(void 0,[],e.current,null);t.push(o)}),n?z("img",{ref:e,className:"ProseMirror-separator"}):null}class nN 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 BC?this.viewDescRef=new $C(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(pf,e.text)}}function rN(){const t=C.useContext(st),e=C.useRef(null);return C.useLayoutEffect(()=>{if(!e.current)return;const n=new df(void 0,[],e.current,null);t.push(n)}),z("br",{ref:e,className:"ProseMirror-trailingBreak"})}function iN({widget:t,pos:e}){const n=C.useContext(st),r=C.useRef(null);C.useLayoutEffect(()=>{if(!r.current)return;const o=new cf(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 qh(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 pf(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&&qh(i),...l},t):C.cloneElement(t,{className:GC(t.props.className,r),contentEditable:o,spellCheck:s,style:{...t.props.style,...i&&qh(i)},...l})}function _u({innerPos:t,childViews:e}){const{view:n}=C.useContext(xo),r=xl(),i=ly(),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(Ku,{children:o.map(s=>{const l=s[0];if(!l)return null;const a=l.marks[0];return a?z(ay,{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(iN,{widget:u.widget,pos:c}):u.type==="native-widget"?z(eN,{widget:u.widget,pos:c}):u.node.isText?z(st.Consumer,{children:d=>z(nN,{view:n,node:u.node,pos:c,siblingDescriptors:d,decorations:u.outerDeco})}):z(uy,{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 oN(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 sN(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 lN(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(uy,{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 Fi({pos:t,node:e,innerDecorations:n}){const r=xl(),i=ly();if(!e)return null;const o=t+1,s=[];ZC(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}),oN(s)},(u,c,f,d)=>{s.push({type:"node",node:u,marks:u.marks,innerDeco:f,outerDeco:c,offset:d}),sN(s)});const l=lN(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(tN,{},"trailing-hack-img"),z(rN,{},"trailing-hack-br")),z(Ku,{children:l})}const aN=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=oy(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(Fi,{pos:-1,node:n,innerDecorations:r})})):C.createElement("div",c,z(st.Provider,{value:u,children:z(Fi,{pos:-1,node:n,innerDecorations:r})}));if(!n)return f;const d=i.filter(h=>!h.inline);return d.length?d.reduce(pf,f):f}),cy=C.createContext(null);function uN({as:t},e){const n=C.useRef(null),{setMount:r,...i}=C.useContext(cy);return C.useImperativeHandle(e,()=>n.current,[]),z(st.Provider,{value:[],children:z(aN,{ref:o=>{n.current=o,r(o)},...i,as:t})})}const cN=C.forwardRef(uN);function fN({className:t,children:e,nodeViews:n={},customNodeViews:r,...i}){var c;const[o,s]=C.useState(null),l=KC(o,{...i,nodeViews:r});qC(l.view);const a=l.view?iC(l.view,l.cursorWrapper):U.empty,u=l.view?eC(l.view):[];return z(QC,{children:z(xo.Provider,{value:l,children:z(J0.Provider,{value:{nodeViews:n},children:z(cy.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 kp({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",toDOM(){return["p",0]}},...kw({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]}}}}),dN=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(),_k({rules:[Wk(/^\s*([-+*])\s$/,_.nodes.list)]}),Bw(),Yw()]}),hN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("p",{ref:i,...r,children:e})}),pN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("ul",{ref:i,...r,children:e})}),mN=C.forwardRef(function({children:e,nodeProps:n,...r},i){return z("li",{ref:i,...r,children:e})}),gN=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})})}),yN=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"})}),SN=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,[G0(t.selection.from,yN,{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 kN=[Jk({...Q1,"Mod-i":bf(_.marks.em),"Mod-b":bf(_.marks.strong)}),SN,Fk()],wN={paragraph:()=>{const t=document.createElement("p");return{dom:t,contentDOM:t}}};function vN(){const[t,e]=C.useState(dN),[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(fN,{className:"ProseMirror",state:t,dispatchTransaction:function(i){e(o=>o.apply(i))},plugins:kN,nodeViews:n?{paragraph:hN,list:pN,list_item:mN,footnote:gN}:void 0,customNodeViews:n?void 0:wN,children:z(cN,{as:z("article",{})})},`${n}`)]})}const xN=H0(document.getElementById("root"));xN.render(z(vN,{})); diff --git a/docs/index.html b/docs/index.html index 2e38f10..0f09fec 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ React-ProseMirror Demo - + diff --git a/src/plugins/beforeInputPlugin.ts b/src/plugins/beforeInputPlugin.ts index 4c042b9..ea82747 100644 --- a/src/plugins/beforeInputPlugin.ts +++ b/src/plugins/beforeInputPlugin.ts @@ -1,44 +1,18 @@ -import { Mark, Node } from "prosemirror-model"; +import { Mark } from "prosemirror-model"; import { Plugin } from "prosemirror-state"; import { Decoration, EditorView } from "prosemirror-view"; import { CursorWrapper } from "../components/CursorWrapper.js"; import { widget } from "../decorations/ReactWidgetType.js"; +import { getEdgeCharacterSize } from "../strings/characters.js"; +import { findDirection } from "../strings/direction.js"; +import { + findWordBoundaryBackward, + findWordBoundaryForward, +} from "../strings/words.js"; import { reactKeysPluginKey } from "./reactKeys.js"; -const SPACE = /\s/; -const PUNCTUATION = - /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/; -const CHAMELEON = /['\u2018\u2019]/; - -const isWordCharacter = (doc: Node, pos: number, checkDir = -1): boolean => { - const $pos = doc.resolve(pos); - - // The position is at the beginning of a node - if ($pos.parentOffset === 0) return false; - - const char = doc.textBetween(pos + checkDir, pos, null, " "); - - if (SPACE.test(char)) { - return false; - } - - // Chameleons count as word characters as long as they're in a word, so - // recurse to see if the next one is a word character or not. - if (CHAMELEON.test(char)) { - if (isWordCharacter(doc, pos - 1)) { - return true; - } - } - - if (PUNCTUATION.test(char)) { - return false; - } - - return true; -}; - function insertText( view: EditorView, eventData: string | null, @@ -82,28 +56,6 @@ function insertText( return true; } -function findWordBoundaryBackward(doc: Node, start: number) { - let pos = start; - while (!isWordCharacter(doc, pos)) { - pos--; - } - while (isWordCharacter(doc, pos)) { - pos--; - } - return pos; -} - -function findWordBoundaryForward(doc: Node, start: number) { - let pos = start; - while (!isWordCharacter(doc, pos, 1)) { - pos++; - } - while (isWordCharacter(doc, pos, 1)) { - pos++; - } - return pos; -} - export function beforeInputPlugin( setCursorWrapper: (deco: Decoration | null) => void ) { @@ -195,8 +147,6 @@ export function beforeInputPlugin( insertText(view, data, { from, to }); } }); - // We have to unilaterally prevent default here, because there's no way - // to synchronously check the contents of the data. break; } case "insertText": { @@ -235,6 +185,29 @@ export function beforeInputPlugin( } case "deleteContentBackward": { const { tr, doc, selection } = view.state; + + if (selection.empty) { + const textNode = selection.$anchor.nodeBefore; + const text = textNode?.text; + if (!text) break; + + const characterSize = getEdgeCharacterSize( + text, + "trailing", + findDirection(view, selection.anchor) === "rtl" + ); + + const to = selection.to; + const from = to - characterSize; + const storedMarks = doc + .resolve(from) + .marksAcross(doc.resolve(to)); + + tr.delete(from, to).setStoredMarks(storedMarks); + view.dispatch(tr); + break; + } + const from = selection.empty ? selection.from - 1 : selection.from; @@ -250,13 +223,36 @@ export function beforeInputPlugin( } case "deleteContentForward": { const { tr, doc, selection } = view.state; + if (selection.empty) { + const textNode = selection.$anchor.nodeAfter; + const text = textNode?.text; + if (!text) break; + + const characterEnd = getEdgeCharacterSize( + text, + "leading", + findDirection(view, selection.anchor) === "rtl" + ); + + const from = selection.from; + const to = from + characterEnd; + const storedMarks = doc + .resolve(from) + .marksAcross(doc.resolve(to)); + + tr.delete(from, to).setStoredMarks(storedMarks); + view.dispatch(tr); + break; + } + const from = selection.from; - const to = selection.empty ? selection.to + 1 : selection.to; + const to = selection.to; const storedMarks = doc .resolve(from) .marksAcross(doc.resolve(to)); tr.delete(from, to).setStoredMarks(storedMarks); + view.dispatch(tr); break; } case "deleteContent": { diff --git a/src/strings/characters.ts b/src/strings/characters.ts new file mode 100644 index 0000000..78fd584 --- /dev/null +++ b/src/strings/characters.ts @@ -0,0 +1,280 @@ +// Character (grapheme cluster) boundaries are determined according to +// the default grapheme cluster boundary specification, extended grapheme clusters variant[1]. +// +// References: +// +// [1] https://www.unicode.org/reports/tr29/#Default_Grapheme_Cluster_Table +// [2] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakProperty.txt +// [3] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.html +// [4] https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt + +/** + * Returns the character size (in unicode code points) of the + * character at the leading or trailing edge of the provided string. + */ +export function getEdgeCharacterSize( + str: string, + edge: "leading" | "trailing", + isRTL?: boolean +) { + if (edge === "leading") { + return getCharacterDistance(str, isRTL); + } + + // For Thai script, deleting N character(s) backward should delete + // N code point(s) instead of an entire grapheme cluster. + const lastChar = str[str.length - 1]; + if (lastChar && isThaiScript(lastChar)) { + return 1; + } + + let characterEnd = getCharacterDistance(str, false); + let remaining = str.slice(characterEnd); + + while (remaining.length) { + characterEnd = getCharacterDistance(remaining, false); + remaining = remaining.slice(characterEnd); + } + + return characterEnd; +} + +/** + * Determines whether the character is a part of the Thai script + */ +export function isThaiScript(char: string) { + return char.match(/[\u0E00-\u0E7F]/); +} + +// Taken from https://github.com/ianstormtaylor/slate/blob/main/packages/slate/src/utils/string.ts + +/** + * Get the distance to the end of the first character in a string of text. + */ + +export function getCharacterDistance(str: string, isRTL = false): number { + const isLTR = !isRTL; + const codepoints = isRTL ? codepointsIteratorRTL(str) : str; + + let left: CodepointType = CodepointType.None; + let right: CodepointType = CodepointType.None; + let distance = 0; + // Evaluation of these conditions are deferred. + let gb11: boolean | null = null; // Is GB11 applicable? + let gb12Or13: boolean | null = null; // Is GB12 or GB13 applicable? + + for (const char of codepoints) { + const code = char.codePointAt(0); + if (!code) break; + + const type = getCodepointType(char, code); + [left, right] = isLTR ? [right, type] : [type, left]; + + if ( + intersects(left, CodepointType.ZWJ) && + intersects(right, CodepointType.ExtPict) + ) { + if (isLTR) { + gb11 = endsWithEmojiZWJ(str.substring(0, distance)); + } else { + gb11 = endsWithEmojiZWJ(str.substring(0, str.length - distance)); + } + if (!gb11) break; + } + + if ( + intersects(left, CodepointType.RI) && + intersects(right, CodepointType.RI) + ) { + if (gb12Or13 !== null) { + gb12Or13 = !gb12Or13; + } else { + if (isLTR) { + gb12Or13 = true; + } else { + gb12Or13 = endsWithOddNumberOfRIs( + str.substring(0, str.length - distance) + ); + } + } + if (!gb12Or13) break; + } + + if ( + left !== CodepointType.None && + right !== CodepointType.None && + isBoundaryPair(left, right) + ) { + break; + } + + distance += char.length; + } + + return distance || 1; +} + +/** + * Iterate on codepoints from right to left. + */ + +export function* codepointsIteratorRTL(str: string) { + const end = str.length - 1; + + for (let i = 0; i < str.length; i++) { + const char1 = str.charAt(end - i); + + if (isLowSurrogate(char1.charCodeAt(0))) { + const char2 = str.charAt(end - i - 1); + if (isHighSurrogate(char2.charCodeAt(0))) { + yield char2 + char1; + + i++; + continue; + } + } + + yield char1; + } +} + +/** + * Is `charCode` a high surrogate. + * + * https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates + */ + +const isHighSurrogate = (charCode: number) => { + return charCode >= 0xd800 && charCode <= 0xdbff; +}; + +/** + * Is `charCode` a low surrogate. + * + * https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates + */ + +const isLowSurrogate = (charCode: number) => { + return charCode >= 0xdc00 && charCode <= 0xdfff; +}; + +enum CodepointType { + None = 0, + Extend = 1 << 0, + ZWJ = 1 << 1, + RI = 1 << 2, + Prepend = 1 << 3, + SpacingMark = 1 << 4, + L = 1 << 5, + V = 1 << 6, + T = 1 << 7, + LV = 1 << 8, + LVT = 1 << 9, + ExtPict = 1 << 10, + Any = 1 << 11, +} + +const reExtend = /^[\p{Gr_Ext}\p{EMod}]$/u; +const rePrepend = + /^[\u0600-\u0605\u06DD\u070F\u0890-\u0891\u08E2\u0D4E\u{110BD}\u{110CD}\u{111C2}-\u{111C3}\u{1193F}\u{11941}\u{11A3A}\u{11A84}-\u{11A89}\u{11D46}]$/u; +const reSpacingMark = + // eslint-disable-next-line no-misleading-character-class + /^[\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0982-\u0983\u09BF-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0B02-\u0B03\u0B40\u0B47-\u0B48\u0B4B-\u0B4C\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0C01-\u0C03\u0C41-\u0C44\u0C82-\u0C83\u0CBE\u0CC0-\u0CC1\u0CC3-\u0CC4\u0CC7-\u0CC8\u0CCA-\u0CCB\u0D02-\u0D03\u0D3F-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D82-\u0D83\u0DD0-\u0DD1\u0DD8-\u0DDE\u0DF2-\u0DF3\u0E33\u0EB3\u0F3E-\u0F3F\u0F7F\u1031\u103B-\u103C\u1056-\u1057\u1084\u1715\u1734\u17B6\u17BE-\u17C5\u17C7-\u17C8\u1923-\u1926\u1929-\u192B\u1930-\u1931\u1933-\u1938\u1A19-\u1A1A\u1A55\u1A57\u1A6D-\u1A72\u1B04\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B82\u1BA1\u1BA6-\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1C24-\u1C2B\u1C34-\u1C35\u1CE1\u1CF7\uA823-\uA824\uA827\uA880-\uA881\uA8B4-\uA8C3\uA952-\uA953\uA983\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BE-\uA9C0\uAA2F-\uAA30\uAA33-\uAA34\uAA4D\uAAEB\uAAEE-\uAAEF\uAAF5\uABE3-\uABE4\uABE6-\uABE7\uABE9-\uABEA\uABEC\u{11000}\u{11002}\u{11082}\u{110B0}-\u{110B2}\u{110B7}-\u{110B8}\u{1112C}\u{11145}-\u{11146}\u{11182}\u{111B3}-\u{111B5}\u{111BF}-\u{111C0}\u{111CE}\u{1122C}-\u{1122E}\u{11232}-\u{11233}\u{11235}\u{112E0}-\u{112E2}\u{11302}-\u{11303}\u{1133F}\u{11341}-\u{11344}\u{11347}-\u{11348}\u{1134B}-\u{1134D}\u{11362}-\u{11363}\u{11435}-\u{11437}\u{11440}-\u{11441}\u{11445}\u{114B1}-\u{114B2}\u{114B9}\u{114BB}-\u{114BC}\u{114BE}\u{114C1}\u{115B0}-\u{115B1}\u{115B8}-\u{115BB}\u{115BE}\u{11630}-\u{11632}\u{1163B}-\u{1163C}\u{1163E}\u{116AC}\u{116AE}-\u{116AF}\u{116B6}\u{11726}\u{1182C}-\u{1182E}\u{11838}\u{11931}-\u{11935}\u{11937}-\u{11938}\u{1193D}\u{11940}\u{11942}\u{119D1}-\u{119D3}\u{119DC}-\u{119DF}\u{119E4}\u{11A39}\u{11A57}-\u{11A58}\u{11A97}\u{11C2F}\u{11C3E}\u{11CA9}\u{11CB1}\u{11CB4}\u{11D8A}-\u{11D8E}\u{11D93}-\u{11D94}\u{11D96}\u{11EF5}-\u{11EF6}\u{16F51}-\u{16F87}\u{16FF0}-\u{16FF1}\u{1D166}\u{1D16D}]$/u; +const reL = /^[\u1100-\u115F\uA960-\uA97C]$/u; +const reV = /^[\u1160-\u11A7\uD7B0-\uD7C6]$/u; +const reT = /^[\u11A8-\u11FF\uD7CB-\uD7FB]$/u; +const reLV = + /^[\uAC00\uAC1C\uAC38\uAC54\uAC70\uAC8C\uACA8\uACC4\uACE0\uACFC\uAD18\uAD34\uAD50\uAD6C\uAD88\uADA4\uADC0\uADDC\uADF8\uAE14\uAE30\uAE4C\uAE68\uAE84\uAEA0\uAEBC\uAED8\uAEF4\uAF10\uAF2C\uAF48\uAF64\uAF80\uAF9C\uAFB8\uAFD4\uAFF0\uB00C\uB028\uB044\uB060\uB07C\uB098\uB0B4\uB0D0\uB0EC\uB108\uB124\uB140\uB15C\uB178\uB194\uB1B0\uB1CC\uB1E8\uB204\uB220\uB23C\uB258\uB274\uB290\uB2AC\uB2C8\uB2E4\uB300\uB31C\uB338\uB354\uB370\uB38C\uB3A8\uB3C4\uB3E0\uB3FC\uB418\uB434\uB450\uB46C\uB488\uB4A4\uB4C0\uB4DC\uB4F8\uB514\uB530\uB54C\uB568\uB584\uB5A0\uB5BC\uB5D8\uB5F4\uB610\uB62C\uB648\uB664\uB680\uB69C\uB6B8\uB6D4\uB6F0\uB70C\uB728\uB744\uB760\uB77C\uB798\uB7B4\uB7D0\uB7EC\uB808\uB824\uB840\uB85C\uB878\uB894\uB8B0\uB8CC\uB8E8\uB904\uB920\uB93C\uB958\uB974\uB990\uB9AC\uB9C8\uB9E4\uBA00\uBA1C\uBA38\uBA54\uBA70\uBA8C\uBAA8\uBAC4\uBAE0\uBAFC\uBB18\uBB34\uBB50\uBB6C\uBB88\uBBA4\uBBC0\uBBDC\uBBF8\uBC14\uBC30\uBC4C\uBC68\uBC84\uBCA0\uBCBC\uBCD8\uBCF4\uBD10\uBD2C\uBD48\uBD64\uBD80\uBD9C\uBDB8\uBDD4\uBDF0\uBE0C\uBE28\uBE44\uBE60\uBE7C\uBE98\uBEB4\uBED0\uBEEC\uBF08\uBF24\uBF40\uBF5C\uBF78\uBF94\uBFB0\uBFCC\uBFE8\uC004\uC020\uC03C\uC058\uC074\uC090\uC0AC\uC0C8\uC0E4\uC100\uC11C\uC138\uC154\uC170\uC18C\uC1A8\uC1C4\uC1E0\uC1FC\uC218\uC234\uC250\uC26C\uC288\uC2A4\uC2C0\uC2DC\uC2F8\uC314\uC330\uC34C\uC368\uC384\uC3A0\uC3BC\uC3D8\uC3F4\uC410\uC42C\uC448\uC464\uC480\uC49C\uC4B8\uC4D4\uC4F0\uC50C\uC528\uC544\uC560\uC57C\uC598\uC5B4\uC5D0\uC5EC\uC608\uC624\uC640\uC65C\uC678\uC694\uC6B0\uC6CC\uC6E8\uC704\uC720\uC73C\uC758\uC774\uC790\uC7AC\uC7C8\uC7E4\uC800\uC81C\uC838\uC854\uC870\uC88C\uC8A8\uC8C4\uC8E0\uC8FC\uC918\uC934\uC950\uC96C\uC988\uC9A4\uC9C0\uC9DC\uC9F8\uCA14\uCA30\uCA4C\uCA68\uCA84\uCAA0\uCABC\uCAD8\uCAF4\uCB10\uCB2C\uCB48\uCB64\uCB80\uCB9C\uCBB8\uCBD4\uCBF0\uCC0C\uCC28\uCC44\uCC60\uCC7C\uCC98\uCCB4\uCCD0\uCCEC\uCD08\uCD24\uCD40\uCD5C\uCD78\uCD94\uCDB0\uCDCC\uCDE8\uCE04\uCE20\uCE3C\uCE58\uCE74\uCE90\uCEAC\uCEC8\uCEE4\uCF00\uCF1C\uCF38\uCF54\uCF70\uCF8C\uCFA8\uCFC4\uCFE0\uCFFC\uD018\uD034\uD050\uD06C\uD088\uD0A4\uD0C0\uD0DC\uD0F8\uD114\uD130\uD14C\uD168\uD184\uD1A0\uD1BC\uD1D8\uD1F4\uD210\uD22C\uD248\uD264\uD280\uD29C\uD2B8\uD2D4\uD2F0\uD30C\uD328\uD344\uD360\uD37C\uD398\uD3B4\uD3D0\uD3EC\uD408\uD424\uD440\uD45C\uD478\uD494\uD4B0\uD4CC\uD4E8\uD504\uD520\uD53C\uD558\uD574\uD590\uD5AC\uD5C8\uD5E4\uD600\uD61C\uD638\uD654\uD670\uD68C\uD6A8\uD6C4\uD6E0\uD6FC\uD718\uD734\uD750\uD76C\uD788]$/u; +const reLVT = + /^[\uAC01-\uAC1B\uAC1D-\uAC37\uAC39-\uAC53\uAC55-\uAC6F\uAC71-\uAC8B\uAC8D-\uACA7\uACA9-\uACC3\uACC5-\uACDF\uACE1-\uACFB\uACFD-\uAD17\uAD19-\uAD33\uAD35-\uAD4F\uAD51-\uAD6B\uAD6D-\uAD87\uAD89-\uADA3\uADA5-\uADBF\uADC1-\uADDB\uADDD-\uADF7\uADF9-\uAE13\uAE15-\uAE2F\uAE31-\uAE4B\uAE4D-\uAE67\uAE69-\uAE83\uAE85-\uAE9F\uAEA1-\uAEBB\uAEBD-\uAED7\uAED9-\uAEF3\uAEF5-\uAF0F\uAF11-\uAF2B\uAF2D-\uAF47\uAF49-\uAF63\uAF65-\uAF7F\uAF81-\uAF9B\uAF9D-\uAFB7\uAFB9-\uAFD3\uAFD5-\uAFEF\uAFF1-\uB00B\uB00D-\uB027\uB029-\uB043\uB045-\uB05F\uB061-\uB07B\uB07D-\uB097\uB099-\uB0B3\uB0B5-\uB0CF\uB0D1-\uB0EB\uB0ED-\uB107\uB109-\uB123\uB125-\uB13F\uB141-\uB15B\uB15D-\uB177\uB179-\uB193\uB195-\uB1AF\uB1B1-\uB1CB\uB1CD-\uB1E7\uB1E9-\uB203\uB205-\uB21F\uB221-\uB23B\uB23D-\uB257\uB259-\uB273\uB275-\uB28F\uB291-\uB2AB\uB2AD-\uB2C7\uB2C9-\uB2E3\uB2E5-\uB2FF\uB301-\uB31B\uB31D-\uB337\uB339-\uB353\uB355-\uB36F\uB371-\uB38B\uB38D-\uB3A7\uB3A9-\uB3C3\uB3C5-\uB3DF\uB3E1-\uB3FB\uB3FD-\uB417\uB419-\uB433\uB435-\uB44F\uB451-\uB46B\uB46D-\uB487\uB489-\uB4A3\uB4A5-\uB4BF\uB4C1-\uB4DB\uB4DD-\uB4F7\uB4F9-\uB513\uB515-\uB52F\uB531-\uB54B\uB54D-\uB567\uB569-\uB583\uB585-\uB59F\uB5A1-\uB5BB\uB5BD-\uB5D7\uB5D9-\uB5F3\uB5F5-\uB60F\uB611-\uB62B\uB62D-\uB647\uB649-\uB663\uB665-\uB67F\uB681-\uB69B\uB69D-\uB6B7\uB6B9-\uB6D3\uB6D5-\uB6EF\uB6F1-\uB70B\uB70D-\uB727\uB729-\uB743\uB745-\uB75F\uB761-\uB77B\uB77D-\uB797\uB799-\uB7B3\uB7B5-\uB7CF\uB7D1-\uB7EB\uB7ED-\uB807\uB809-\uB823\uB825-\uB83F\uB841-\uB85B\uB85D-\uB877\uB879-\uB893\uB895-\uB8AF\uB8B1-\uB8CB\uB8CD-\uB8E7\uB8E9-\uB903\uB905-\uB91F\uB921-\uB93B\uB93D-\uB957\uB959-\uB973\uB975-\uB98F\uB991-\uB9AB\uB9AD-\uB9C7\uB9C9-\uB9E3\uB9E5-\uB9FF\uBA01-\uBA1B\uBA1D-\uBA37\uBA39-\uBA53\uBA55-\uBA6F\uBA71-\uBA8B\uBA8D-\uBAA7\uBAA9-\uBAC3\uBAC5-\uBADF\uBAE1-\uBAFB\uBAFD-\uBB17\uBB19-\uBB33\uBB35-\uBB4F\uBB51-\uBB6B\uBB6D-\uBB87\uBB89-\uBBA3\uBBA5-\uBBBF\uBBC1-\uBBDB\uBBDD-\uBBF7\uBBF9-\uBC13\uBC15-\uBC2F\uBC31-\uBC4B\uBC4D-\uBC67\uBC69-\uBC83\uBC85-\uBC9F\uBCA1-\uBCBB\uBCBD-\uBCD7\uBCD9-\uBCF3\uBCF5-\uBD0F\uBD11-\uBD2B\uBD2D-\uBD47\uBD49-\uBD63\uBD65-\uBD7F\uBD81-\uBD9B\uBD9D-\uBDB7\uBDB9-\uBDD3\uBDD5-\uBDEF\uBDF1-\uBE0B\uBE0D-\uBE27\uBE29-\uBE43\uBE45-\uBE5F\uBE61-\uBE7B\uBE7D-\uBE97\uBE99-\uBEB3\uBEB5-\uBECF\uBED1-\uBEEB\uBEED-\uBF07\uBF09-\uBF23\uBF25-\uBF3F\uBF41-\uBF5B\uBF5D-\uBF77\uBF79-\uBF93\uBF95-\uBFAF\uBFB1-\uBFCB\uBFCD-\uBFE7\uBFE9-\uC003\uC005-\uC01F\uC021-\uC03B\uC03D-\uC057\uC059-\uC073\uC075-\uC08F\uC091-\uC0AB\uC0AD-\uC0C7\uC0C9-\uC0E3\uC0E5-\uC0FF\uC101-\uC11B\uC11D-\uC137\uC139-\uC153\uC155-\uC16F\uC171-\uC18B\uC18D-\uC1A7\uC1A9-\uC1C3\uC1C5-\uC1DF\uC1E1-\uC1FB\uC1FD-\uC217\uC219-\uC233\uC235-\uC24F\uC251-\uC26B\uC26D-\uC287\uC289-\uC2A3\uC2A5-\uC2BF\uC2C1-\uC2DB\uC2DD-\uC2F7\uC2F9-\uC313\uC315-\uC32F\uC331-\uC34B\uC34D-\uC367\uC369-\uC383\uC385-\uC39F\uC3A1-\uC3BB\uC3BD-\uC3D7\uC3D9-\uC3F3\uC3F5-\uC40F\uC411-\uC42B\uC42D-\uC447\uC449-\uC463\uC465-\uC47F\uC481-\uC49B\uC49D-\uC4B7\uC4B9-\uC4D3\uC4D5-\uC4EF\uC4F1-\uC50B\uC50D-\uC527\uC529-\uC543\uC545-\uC55F\uC561-\uC57B\uC57D-\uC597\uC599-\uC5B3\uC5B5-\uC5CF\uC5D1-\uC5EB\uC5ED-\uC607\uC609-\uC623\uC625-\uC63F\uC641-\uC65B\uC65D-\uC677\uC679-\uC693\uC695-\uC6AF\uC6B1-\uC6CB\uC6CD-\uC6E7\uC6E9-\uC703\uC705-\uC71F\uC721-\uC73B\uC73D-\uC757\uC759-\uC773\uC775-\uC78F\uC791-\uC7AB\uC7AD-\uC7C7\uC7C9-\uC7E3\uC7E5-\uC7FF\uC801-\uC81B\uC81D-\uC837\uC839-\uC853\uC855-\uC86F\uC871-\uC88B\uC88D-\uC8A7\uC8A9-\uC8C3\uC8C5-\uC8DF\uC8E1-\uC8FB\uC8FD-\uC917\uC919-\uC933\uC935-\uC94F\uC951-\uC96B\uC96D-\uC987\uC989-\uC9A3\uC9A5-\uC9BF\uC9C1-\uC9DB\uC9DD-\uC9F7\uC9F9-\uCA13\uCA15-\uCA2F\uCA31-\uCA4B\uCA4D-\uCA67\uCA69-\uCA83\uCA85-\uCA9F\uCAA1-\uCABB\uCABD-\uCAD7\uCAD9-\uCAF3\uCAF5-\uCB0F\uCB11-\uCB2B\uCB2D-\uCB47\uCB49-\uCB63\uCB65-\uCB7F\uCB81-\uCB9B\uCB9D-\uCBB7\uCBB9-\uCBD3\uCBD5-\uCBEF\uCBF1-\uCC0B\uCC0D-\uCC27\uCC29-\uCC43\uCC45-\uCC5F\uCC61-\uCC7B\uCC7D-\uCC97\uCC99-\uCCB3\uCCB5-\uCCCF\uCCD1-\uCCEB\uCCED-\uCD07\uCD09-\uCD23\uCD25-\uCD3F\uCD41-\uCD5B\uCD5D-\uCD77\uCD79-\uCD93\uCD95-\uCDAF\uCDB1-\uCDCB\uCDCD-\uCDE7\uCDE9-\uCE03\uCE05-\uCE1F\uCE21-\uCE3B\uCE3D-\uCE57\uCE59-\uCE73\uCE75-\uCE8F\uCE91-\uCEAB\uCEAD-\uCEC7\uCEC9-\uCEE3\uCEE5-\uCEFF\uCF01-\uCF1B\uCF1D-\uCF37\uCF39-\uCF53\uCF55-\uCF6F\uCF71-\uCF8B\uCF8D-\uCFA7\uCFA9-\uCFC3\uCFC5-\uCFDF\uCFE1-\uCFFB\uCFFD-\uD017\uD019-\uD033\uD035-\uD04F\uD051-\uD06B\uD06D-\uD087\uD089-\uD0A3\uD0A5-\uD0BF\uD0C1-\uD0DB\uD0DD-\uD0F7\uD0F9-\uD113\uD115-\uD12F\uD131-\uD14B\uD14D-\uD167\uD169-\uD183\uD185-\uD19F\uD1A1-\uD1BB\uD1BD-\uD1D7\uD1D9-\uD1F3\uD1F5-\uD20F\uD211-\uD22B\uD22D-\uD247\uD249-\uD263\uD265-\uD27F\uD281-\uD29B\uD29D-\uD2B7\uD2B9-\uD2D3\uD2D5-\uD2EF\uD2F1-\uD30B\uD30D-\uD327\uD329-\uD343\uD345-\uD35F\uD361-\uD37B\uD37D-\uD397\uD399-\uD3B3\uD3B5-\uD3CF\uD3D1-\uD3EB\uD3ED-\uD407\uD409-\uD423\uD425-\uD43F\uD441-\uD45B\uD45D-\uD477\uD479-\uD493\uD495-\uD4AF\uD4B1-\uD4CB\uD4CD-\uD4E7\uD4E9-\uD503\uD505-\uD51F\uD521-\uD53B\uD53D-\uD557\uD559-\uD573\uD575-\uD58F\uD591-\uD5AB\uD5AD-\uD5C7\uD5C9-\uD5E3\uD5E5-\uD5FF\uD601-\uD61B\uD61D-\uD637\uD639-\uD653\uD655-\uD66F\uD671-\uD68B\uD68D-\uD6A7\uD6A9-\uD6C3\uD6C5-\uD6DF\uD6E1-\uD6FB\uD6FD-\uD717\uD719-\uD733\uD735-\uD74F\uD751-\uD76B\uD76D-\uD787\uD789-\uD7A3]$/u; +const reExtPict = /^\p{ExtPict}$/u; + +const getCodepointType = (char: string, code: number): CodepointType => { + let type = CodepointType.Any; + if (char.search(reExtend) !== -1) { + type |= CodepointType.Extend; + } + if (code === 0x200d) { + type |= CodepointType.ZWJ; + } + if (code >= 0x1f1e6 && code <= 0x1f1ff) { + type |= CodepointType.RI; + } + if (char.search(rePrepend) !== -1) { + type |= CodepointType.Prepend; + } + if (char.search(reSpacingMark) !== -1) { + type |= CodepointType.SpacingMark; + } + if (char.search(reL) !== -1) { + type |= CodepointType.L; + } + if (char.search(reV) !== -1) { + type |= CodepointType.V; + } + if (char.search(reT) !== -1) { + type |= CodepointType.T; + } + if (char.search(reLV) !== -1) { + type |= CodepointType.LV; + } + if (char.search(reLVT) !== -1) { + type |= CodepointType.LVT; + } + if (char.search(reExtPict) !== -1) { + type |= CodepointType.ExtPict; + } + + return type; +}; + +function intersects(x: CodepointType, y: CodepointType) { + return (x & y) !== 0; +} + +const NonBoundaryPairs: [CodepointType, CodepointType][] = [ + // GB6 + [ + CodepointType.L, + CodepointType.L | CodepointType.V | CodepointType.LV | CodepointType.LVT, + ], + // GB7 + [CodepointType.LV | CodepointType.V, CodepointType.V | CodepointType.T], + // GB8 + [CodepointType.LVT | CodepointType.T, CodepointType.T], + // GB9 + [CodepointType.Any, CodepointType.Extend | CodepointType.ZWJ], + // GB9a + [CodepointType.Any, CodepointType.SpacingMark], + // GB9b + [CodepointType.Prepend, CodepointType.Any], + // GB11 + [CodepointType.ZWJ, CodepointType.ExtPict], + // GB12 and GB13 + [CodepointType.RI, CodepointType.RI], +]; + +function isBoundaryPair(left: CodepointType, right: CodepointType) { + return ( + NonBoundaryPairs.findIndex( + (r) => intersects(left, r[0]) && intersects(right, r[1]) + ) === -1 + ); +} + +const endingEmojiZWJ = /\p{ExtPict}[\p{Gr_Ext}\p{EMod}]*\u200D$/u; +const endsWithEmojiZWJ = (str: string): boolean => { + return str.search(endingEmojiZWJ) !== -1; +}; + +const endingRIs = /\p{RI}+$/gu; +const endsWithOddNumberOfRIs = (str: string): boolean => { + const match = str.match(endingRIs); + if (match === null) { + return false; + } else { + // A RI is represented by a surrogate pair. + const numRIs = match[0].length / 2; + return numRIs % 2 === 1; + } +}; diff --git a/src/strings/direction.ts b/src/strings/direction.ts new file mode 100644 index 0000000..02f989e --- /dev/null +++ b/src/strings/direction.ts @@ -0,0 +1,32 @@ +import { EditorView } from "prosemirror-view"; + +import { browser } from "../browser.js"; + +export function findDirection(view: EditorView, pos: number): "rtl" | "ltr" { + const $pos = view.state.doc.resolve(pos); + if (!(browser.chrome || browser.windows) && $pos.parent.inlineContent) { + const coords = view.coordsAtPos(pos); + if (pos > $pos.start()) { + const before = view.coordsAtPos(pos - 1); + const mid = (before.top + before.bottom) / 2; + if ( + mid > coords.top && + mid < coords.bottom && + Math.abs(before.left - coords.left) > 1 + ) + return before.left < coords.left ? "ltr" : "rtl"; + } + if (pos < $pos.end()) { + const after = view.coordsAtPos(pos + 1); + const mid = (after.top + after.bottom) / 2; + if ( + mid > coords.top && + mid < coords.bottom && + Math.abs(after.left - coords.left) > 1 + ) + return after.left > coords.left ? "ltr" : "rtl"; + } + } + const computed = getComputedStyle(view.dom).direction; + return computed == "rtl" ? "rtl" : "ltr"; +} diff --git a/src/strings/words.ts b/src/strings/words.ts new file mode 100644 index 0000000..b213438 --- /dev/null +++ b/src/strings/words.ts @@ -0,0 +1,59 @@ +import { Node } from "prosemirror-model"; + +const SPACE = /\s/; +const PUNCTUATION = + /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/; +const CHAMELEON = /['\u2018\u2019]/; + +export function isWordCharacter( + doc: Node, + pos: number, + checkDir = -1 +): boolean { + const $pos = doc.resolve(pos); + + // The position is at the beginning of a node + if ($pos.parentOffset === 0) return false; + + const char = doc.textBetween(pos + checkDir, pos, null, " "); + + if (SPACE.test(char)) { + return false; + } + + // Chameleons count as word characters as long as they're in a word, so + // recurse to see if the next one is a word character or not. + if (CHAMELEON.test(char)) { + if (isWordCharacter(doc, pos - 1)) { + return true; + } + } + + if (PUNCTUATION.test(char)) { + return false; + } + + return true; +} + +export function findWordBoundaryBackward(doc: Node, start: number) { + let pos = start; + while (!isWordCharacter(doc, pos)) { + pos--; + } + while (isWordCharacter(doc, pos)) { + pos--; + } + return pos; +} + +export function findWordBoundaryForward(doc: Node, start: number) { + let pos = start; + while (!isWordCharacter(doc, pos, 1)) { + pos++; + } + while (isWordCharacter(doc, pos, 1)) { + pos++; + } + return pos; +}