From aea3fd1828ca718e393afca9176bee888f9af287 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 10:19:34 -0800 Subject: [PATCH 1/3] feat: provide word style list creation based on user input wehn editing a document --- blocks/edit/prose/index.js | 2 ++ blocks/edit/prose/plugins/keyHandlers.js | 35 ++++++++++++++++++++++++ deps/da-y-wrapper/dist/index.js | 22 +++++++-------- deps/da-y-wrapper/src/index.js | 3 +- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js index 739de4d5..0fcc07c2 100644 --- a/blocks/edit/prose/index.js +++ b/blocks/edit/prose/index.js @@ -39,6 +39,7 @@ import { handleTableTab, getEnterInputRulesPlugin, getURLInputRulesPlugin, + getListInputRulesPlugin, handleUndo, handleRedo, } from './plugins/keyHandlers.js'; @@ -272,6 +273,7 @@ export default function initProse({ path, permissions }) { columnResizing(), getEnterInputRulesPlugin(dispatchTransaction), getURLInputRulesPlugin(), + getListInputRulesPlugin(schema), keymap(buildKeymap(schema)), keymap({ Backspace: handleTableBackspace }), keymap(baseKeymap), diff --git a/blocks/edit/prose/plugins/keyHandlers.js b/blocks/edit/prose/plugins/keyHandlers.js index 2675d6b7..391b25b3 100644 --- a/blocks/edit/prose/plugins/keyHandlers.js +++ b/blocks/edit/prose/plugins/keyHandlers.js @@ -10,6 +10,7 @@ import { deleteTable, InputRule, inputRules, + wrappingInputRule, yUndo, yRedo, } from 'da-y-wrapper'; @@ -47,6 +48,34 @@ export function getURLInputRule() { ); } +/** + * Converts "* " or "- " at the start of a line into a bullet list. + * + * @param {Schema} schema - The ProseMirror schema + * @returns {InputRule|null} the bullet list input rule, or null if + * bullet_list node doesn't exist + */ +export function getBulletListInputRule(schema) { + const { bullet_list: bulletList } = schema.nodes; + if (!bulletList) return null; + + return wrappingInputRule(/^\s*([-*])\s$/, bulletList); +} + +/** + * converts "1. " or "1) " at the start of a line into an ordered list. + * + * @param {Schema} schema - The ProseMirror schema + * @returns {InputRule|null} the ordered list input rule, or null if + * the ordered_list node doesn't exist + */ +export function getOrderedListInputRule(schema) { + const { ordered_list: orderedList } = schema.nodes; + if (!orderedList) return null; + + return wrappingInputRule(/^\s*1[.)]\s$/, orderedList); +} + export function getDashesInputRule(dispatchTransaction) { return new InputRule( /^---[\n]$/, @@ -82,6 +111,12 @@ export function getURLInputRulesPlugin() { return inputRules({ rules: [getURLInputRule()] }); } +// Returns an inputRules plugin for list formatting (bullet and ordered lists) +export function getListInputRulesPlugin(schema) { + const rules = [getBulletListInputRule(schema), getOrderedListInputRule(schema)].filter(Boolean); + return inputRules({ rules }); +} + const isRowSelected = (rect) => rect.left === 0 && rect.right === rect.map.width; const isColumnSelected = (rect) => rect.top === 0 && rect.bottom === rect.map.height; diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 30ec4a16..7027ec16 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,13 @@ -var hp=Object.defineProperty;var dp=(n,e)=>{for(var t in e)hp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var yo=oe;function ia(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=ia(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):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&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Pi(r+1,o):Pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=la(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(oa(this.content,e+this.openStart,t+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,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function oa(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(oa(s.content,e-i-1,t-i-1)))}function la(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=la(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function fp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ca(n,e,t,0)}function ca(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&xo(n,e,i+1),o=r.depth>i&&xo(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(aa(s,o),Gt(Xt(s,ha(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Fi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xo(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function up(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.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,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(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&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Yc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.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()+")"),da(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t 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(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var ko=class n extends Ke{constructor(e,t,r,i){if(super(e,t,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):da(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function da(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Co(e,t);if(r.next==null)return n.empty;let i=fa(r);r.next&&r.err("Unexpected trailing text");let s=kp(Sp(i));return Cp(s,r),s}matchType(e){for(let t=0;ta.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 t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` -`)}};en.empty=new en(!0);var Co=class{constructor(e,t){this.string=e,this.nodeTypes=t,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 fa(n){let e=[];do e.push(gp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function gp(n){let e=[];do e.push(yp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function yp(n){let e=xp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=wp(n,e);else break;return e}function Gc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function wp(n,e){let t=Gc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Gc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function bp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function xp(n){if(n.eat("(")){let e=fa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=bp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Sp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ma(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.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 s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Mp(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Mo=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Mp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ya(e,i.attrs),this.excluded=null;let s=pa(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ma(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=yo.from(e.nodes),t.marks=yo.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.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 s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Qc(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Qc(this,o.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,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){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(t,r,i)}text(e,t){let r=this.nodes.text;return new ko(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Qc(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ap(n){return n.tag!=null}function Ep(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ap(i))this.tags.push(i);else if(Ep(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=ea(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ea(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},wa={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},Tp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ba={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function Zc(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);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&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=Zc(null,t.preserveWhitespace,0)|(r?Er:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;ba.hasOwnProperty(i)&&this.parser.normalizeLists&&Dp(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Tp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(wa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ta(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].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 t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Dp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ba.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Op(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ea(n){let e={};for(let t in n)e[t]=n[t];return e}function ta(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=na(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return na(e.marks)}};function na(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bo(n){return n.document||window.document}var ra=new WeakMap;function Np(n){let e=ra.get(n);return e===void 0&&ra.set(n,e=Ip(n)),e}function Ip(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var ka=65535,Ca=Math.pow(2,16);function vp(n,e){return n+e*Ca}function xa(n){return n&ka}function _p(n){return(n-(n&ka))/Ca}var Ma=1,Aa=2,ji=4,Ea=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Ma|ji))>0}get deletedAfter(){return(this.delInfo&(Aa|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=xa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:vp(l/3,e-c),m=e==c?Aa:e==d?Ma:ji;return(t<0?e!=c:e!=d)&&(m|=Ea),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=xa(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(No(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,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,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Do(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Up(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Vp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Tr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Io(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Bp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].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(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function qp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Hp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Da(n,o,l,s),Io(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Ta(n,o,l,s),!1}})}function Ta(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Da(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` -`))}})}function Hp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Jp(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function $p(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Oa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Wp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Oa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function jp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Da(n,h.node(),h.before(),l)}o.inlineContent&&Io(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Ta(n,h.node(),h.before(),n.steps.length)}return n}function Kp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ia(i,s,r)?new Ee(e,t,r):new Oo(i,s,r).fit()}function Ia(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Oo=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.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(),t=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 s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Eo(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ra(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=To(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Eo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ra(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function To(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Yp(t,s.content,o)?l:null}function Yp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Gp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function va(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Qp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Kp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function Zp(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=_a(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function _a(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Xp(this,e,t,r),this}replaceRangeWith(e,t,r){return Qp(this,e,t,r),this}deleteRange(e,t){return Zp(this,e,t),this}lift(e,t){return Pp(this,e,t),this}join(e,t=1){return jp(this,e,t),this}wrap(e,t){return Fp(this,e,t),this}setBlockType(e,t=e,r,i=null){return qp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Jp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return $p(this,e,t,r),this}addMark(e,t,r){return Up(this,e,t,r),this}removeMark(e,t,r){return Vp(this,e,t,r),this}clearIncompatible(e,t,r){return Io(this,e,t,r),this}};var vo=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vo[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vo)throw new RangeError("Duplicate use of selection JSON ID "+e);return vo[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Ua=!1;function Va(n){!Ua&&!n.parent.inlineContent&&(Ua=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Va(e),Va(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Ba(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Pa=1,Qi=2,La=4,Vo=class extends qn{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|=Qi,this}ensureMarks(e){return D.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&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=La,this}get scrolledIntoView(){return(this.updated&La)>0}};function za(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=za(t.init,r),this.apply=za(t.apply,r)}},tm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=tm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Bo=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Fa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Fa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Fa(e.props,this,this.props),this.key=e.key?e.key.key:qa("plugin")}getState(e){return e[this.key]}},_o=Object.create(null);function qa(n){return n in _o?n+"$"+ ++_o[n]:(_o[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=qa(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qo=null,pt=function(n,e,t){let r=qo||(qo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},nm=function(){qo=null},fn=function(n,e,t,r){return t&&(Ha(n,e,t,r,-1)||Ha(n,e,t,r,1))},rm=/^(img|br|input|textarea|hr)$/i;function Ha(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Jr(n)||rm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function im(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function sm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),am=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!Ja&&"webkitFontSmoothing"in Ja.documentElement.style,hm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function dm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function fm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function $a(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=zr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?dm(s):fm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function um(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Mh(n.dom)}}function Mh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function pm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ah(t,r==0?0:r-e)}function Ah(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?gm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Eh(t,i)}function gm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ym(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function bm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Th(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=bm(n,r,i,e))}l==null&&(l=wm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Wa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!0)}return Po(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Po(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Oh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function km(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Oh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Dh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Cm=/[\u0590-\u08ac]/;function Mm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Cm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Oh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var ja=null,Ka=null,Ya=!1;function Am(n,e,t){return ja==e&&Ka==t?Ya:(ja=e,Ka=t,Ya=t=="up"||t=="down"?km(n,e,t):Mm(n,e,t))}var Ue=0,Ga=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof ns){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof es&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:Ga,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:Ge}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Ga;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ue&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Wo=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ue){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Go(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=It.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=Rh(h,r,t),a?c=new jo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new ts(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Ue&&e.eq(this.node)&&rs(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Yo(this,o&&o.node,e);Om(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Nh(this.contentDOM,this.children,e),Kn&&Nm(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Im(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Wo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Go(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ue}updateOuterDeco(e){if(rs(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Ih(this.dom,this.nodeDOM,Ko(this.outerDeco,this.node,t),Ko(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.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 Xa(n,e,t,r,i){Rh(r,e,n);let s=new Pt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var ts=class n extends Pt{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Ge||this.dirty!=Ue&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ue||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=Ue,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ge)}get domAtom(){return!1}isText(e){return this.node.text==e}},ns=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ue&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},jo=class extends Pt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Nh(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,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 c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Dm(n,e){return n.type.side-e.type.side}function Om(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Nm(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Im(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Go(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function cl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(ds(t)){for(c=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&om(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!vh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function vm(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,te(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&ke&&Bt<=11&&(r.disabled=!0,r.disabled=!1)}function _h(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(nh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else nh(n)}function nh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function al(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function rh(n){return n.editable&&!n.hasFocus()?!1:Uh(n)}function Uh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function _m(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Xo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ih(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xo(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?C.isSelectable(s)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof C&&r.node.isInline)return Ut(n,new A(e>0?r.$to:r.$from));{let i=Xo(n.state,e);return i?Ut(n,i):!1}}}function is(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Lr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function $n(n,e){return e<0?Um(n):Vm(n)}function Um(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Vh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=is(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Qo(n,t,r):i&&Qo(n,i,s)}function Vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=is(t),s,o;for(;;)if(r{n.state==i&&mt(n)},50)}function sh(n,e){let t=n.state.doc.resolve(e);if(!(ae||am)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function oh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ve&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Xo(n.state,e);if(o&&o instanceof C)return Ut(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Te?S.near(o,e):S.findFrom(o,e);return l?Ut(n,l):!1}return!1}function lh(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ch(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Lm(n){if(!me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ch(n,r,"true"),setTimeout(()=>ch(n,r,"false"),20)}return!1}function zm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Fm(n,e){let t=e.keyCode,r=zm(e);if(t==8||ve&&t==72&&r=="c")return lh(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return lh(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?sh(n,n.state.selection.from)=="ltr"?-1:1:-1;return ih(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?sh(n,n.state.selection.from)=="ltr"?1:-1:1;return ih(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return oh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Lm(n)||oh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Bh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Hh(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=qh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var dp=Object.defineProperty;var fp=(n,e)=>{for(var t in e)dp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var yo=oe;function ia(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=ia(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):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&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Li(r+1,o):Li(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Zt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=la(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(oa(this.content,e+this.openStart,t+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,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function oa(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(oa(s.content,e-i-1,t-i-1)))}function la(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=la(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function up(n,e,t){if(t.openStart>n.depth)throw new Zt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Zt("Inconsistent open depths");return ca(n,e,t,0)}function ca(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Er(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Xt(n.nodeAfter,r),s++));for(let l=s;li&&xo(n,e,i+1),o=r.depth>i&&xo(t,r,i+1),l=[];return Er(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(aa(s,o),Xt(Qt(s,ha(n,e,t,r,i+1)),l)):(s&&Xt(Qt(s,qi(n,e,i+1)),l),Er(e,t,i,l),o&&Xt(Qt(o,qi(t,r,i+1)),l)),Er(r,null,i,l),new w(l)}function qi(n,e,t){let r=[];if(Er(null,n,t,r),n.depth>t){let i=xo(n,e,t+1);Xt(Qt(i,qi(n,e,t+1)),r)}return Er(e,null,t,r),new w(r)}function pp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Hi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.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,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new en(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&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Yc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.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()+")"),da(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t 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(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var ko=class n extends Ke{constructor(e,t,r,i){if(super(e,t,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):da(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function da(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var tn=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Co(e,t);if(r.next==null)return n.empty;let i=fa(r);r.next&&r.err("Unexpected trailing text");let s=Cp(kp(i));return Mp(s,r),s}matchType(e){for(let t=0;ta.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 t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` +`)}};tn.empty=new tn(!0);var Co=class{constructor(e,t){this.string=e,this.nodeTypes=t,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 fa(n){let e=[];do e.push(yp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function yp(n){let e=[];do e.push(wp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function wp(n){let e=Sp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=bp(n,e);else break;return e}function Gc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function bp(n,e){let t=Gc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Gc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function xp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Sp(n){if(n.eat("(")){let e=fa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=xp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function kp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new tn(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ma(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.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 s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Ap(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Mo=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Ap(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Dr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ya(e,i.attrs),this.excluded=null;let s=pa(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ma(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Or=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=yo.from(e.nodes),t.marks=yo.from(e.marks||{}),this.nodes=Ji.compile(this.spec.nodes,this),this.marks=Dr.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 s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=tn.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Qc(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Qc(this,o.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,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Ji){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(t,r,i)}text(e,t){let r=this.nodes.text;return new ko(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Qc(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ep(n){return n.tag!=null}function Tp(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ep(i))this.tags.push(i);else if(Tp(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new ji(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new ji(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=ea(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ea(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},wa={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},Dp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ba={ol:!0,ul:!0},$i=1,Wi=2,Tr=4;function Zc(n,e,t){return e!=null?(e?$i:0)|(e==="full"?Wi:0):n&&n.whitespace=="pre"?$i|Wi:t&~Tr}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Tr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);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&$i)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ji=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=Zc(null,t.preserveWhitespace,0)|(r?Tr:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&Wi||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&$i)i.options&Wi?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;ba.hasOwnProperty(i)&&this.parser.normalizeLists&&Op(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Dp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(wa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ta(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].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 t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Op(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ba.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Np(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ea(n){let e={};for(let t in n)e[t]=n[t];return e}function ta(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&zi(bo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return zi(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=na(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return na(e.marks)}};function na(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bo(n){return n.document||window.document}var ra=new WeakMap;function Ip(n){let e=ra.get(n);return e===void 0&&ra.set(n,e=Rp(n)),e}function Rp(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=zi(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var ka=65535,Ca=Math.pow(2,16);function _p(n,e){return n+e*Ca}function xa(n){return n&ka}function Up(n){return(n-(n&ka))/Ca}var Ma=1,Aa=2,Ki=4,Ea=8,Rr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Ma|Ki))>0}get deletedAfter(){return(this.delInfo&(Aa|Ki))>0}get deletedAcross(){return(this.delInfo&Ki)>0}},ut=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=xa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:_p(l/3,e-c),m=e==c?Aa:e==d?Ma:Ki;return(t<0?e!=c:e!=d)&&(m|=Ea),new Rr(u,m,p)}i+=h-a}return r?e+i:new Rr(e+i,0,null)}touches(e,t){let r=0,i=xa(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new nn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",_r);var nn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(No(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new _r(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",nn);var Ur=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,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,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Do(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Vp(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Bp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Dr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new nn(o.from,o.to,o.style)))}function Io(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Pp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function rn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].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(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function Hp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Da(n,o,l,s),Io(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Ta(n,o,l,s),!1}})}function Ta(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Da(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` +`))}})}function Jp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function $p(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function vt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wp(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function pt(n,e){let t=n.resolve(e),r=t.index();return Oa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function jp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Oa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Kp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Da(n,h.node(),h.before(),l)}o.inlineContent&&Io(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Ta(n,h.node(),h.before(),n.steps.length)}return n}function Yp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ia(i,s,r)?new Ee(e,t,r):new Oo(i,s,r).fit()}function Ia(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Oo=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.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(),t=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 s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Eo(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Nr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Nr(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ra(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Ir(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=To(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Ir(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ir(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Ir(this.placed,this.frontier.length,t))}};function Nr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Nr(n.firstChild.content,e-1,t)))}function Ir(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Ir(n.lastChild.content,e-1,t)))}function Eo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ra(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function To(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Gp(t,s.content,o)?l:null}function Gp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Xp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function va(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Zp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Yp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function em(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=_a(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function _a(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Yi=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ut.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Yi);var Gi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ut.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Gi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new vr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Qp(this,e,t,r),this}replaceRangeWith(e,t,r){return Zp(this,e,t,r),this}deleteRange(e,t){return em(this,e,t),this}lift(e,t){return Lp(this,e,t),this}join(e,t=1){return Kp(this,e,t),this}wrap(e,t){return qp(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return $p(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Yi(e,t,r)),this}setDocAttribute(e,t){return this.step(new Gi(e,t)),this}addNodeMark(e,t){return this.step(new Ur(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Vr(e,t)),this}split(e,t=1,r){return Wp(this,e,t,r),this}addMark(e,t,r){return Vp(this,e,t,r),this}removeMark(e,t,r){return Bp(this,e,t,r),this}clearIncompatible(e,t,r){return Io(this,e,t,r),this}};var vo=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new _t(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Jn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Jn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Jn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Jn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vo[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vo)throw new RangeError("Duplicate use of selection JSON ID "+e);return vo[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var _t=class{constructor(e,t){this.$from=e,this.$to=t}},Ua=!1;function Va(n){!Ua&&!n.parent.inlineContent&&(Ua=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Va(e),Va(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Jn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Ba(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Pa=1,Qi=2,La=4,Vo=class extends qn{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|=Qi,this}ensureMarks(e){return D.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&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=La,this}get scrolledIntoView(){return(this.updated&La)>0}};function za(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=za(t.init,r),this.apply=za(t.apply,r)}},nm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Br=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=nm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Bo=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Br(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Fa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Fa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Fa(e.props,this,this.props),this.key=e.key?e.key.key:qa("plugin")}getState(e){return e[this.key]}},_o=Object.create(null);function qa(n){return n in _o?n+"$"+ ++_o[n]:(_o[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=qa(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Fr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qo=null,gt=function(n,e,t){let r=qo||(qo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},rm=function(){qo=null},fn=function(n,e,t,r){return t&&(Ha(n,e,t,r,-1)||Ha(n,e,t,r,1))},im=/^(img|br|input|textarea|hr)$/i;function Ha(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||$r(n)||im.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function sm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!$r(n))e=te(n),n=n.parentNode;else return null}}function om(n,e){for(;;){if(n.nodeType==3&&e2),ve=Yn||(Ye?/Mac/.test(Ye.platform):!1),hm=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(zt),Wr=!!Ja&&"webkitFontSmoothing"in Ja.documentElement.style,dm=Wr?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function fm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function mt(n,e){return typeof n=="number"?n:n[e]}function um(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function $a(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Fr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?fm(s):um(l),h=0,d=0;if(e.topa.bottom-mt(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+mt(i,"top")-a.top:e.bottom-a.bottom+mt(i,"bottom")),e.lefta.right-mt(r,"right")&&(h=e.right-a.right+mt(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function pm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Mh(n.dom)}}function Mh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Fr(r));return e}function mm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ah(t,r==0?0:r-e)}function Ah(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?ym(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Eh(t,i)}function ym(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function wm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function xm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Th(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;Wr&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=xm(n,r,i,e))}l==null&&(l=bm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Wa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Pr(Ut(gt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!0)}return Po(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?gt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Pr(Ut(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?gt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Pr(Ut(a,-1),!0)}return Pr(Ut(r.nodeType==3?gt(r):r,-t),t>=0)}function Pr(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Po(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Oh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Cm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Oh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Dh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=gt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Mm=/[\u0590-\u08ac]/;function Am(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Mm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Oh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var ja=null,Ka=null,Ya=!1;function Em(n,e,t){return ja==e&&Ka==t?Ya:(ja=e,Ka=t,Ya=t=="up"||t=="down"?Cm(n,e,t):Am(n,e,t))}var Ue=0,Ga=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof ns){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof es&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:Ga,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:Ge}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Ga;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ue&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Wo=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Gn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Rt.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ue){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Go(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=Rt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=Rh(h,r,t),a?c=new jo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new ts(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Ue&&e.eq(this.node)&&rs(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Yo(this,o&&o.node,e);Nm(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Nh(this.contentDOM,this.children,e),Yn&&Im(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Rm(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Wo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Go(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ue}updateOuterDeco(e){if(rs(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Ih(this.dom,this.nodeDOM,Ko(this.outerDeco,this.node,t),Ko(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.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 Xa(n,e,t,r,i){Rh(r,e,n);let s=new Lt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var ts=class n extends Lt{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Ge||this.dirty!=Ue&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ue||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=Ue,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ge)}get domAtom(){return!1}isText(e){return this.node.text==e}},ns=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ue&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},jo=class extends Lt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Nh(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,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 c=Gn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Gn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Om(n,e){return n.type.side-e.type.side}function Nm(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Im(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Rm(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Go(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function cl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(ds(t)){for(c=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&lm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!vh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function _m(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,te(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&ke&&Pt<=11&&(r.disabled=!0,r.disabled=!1)}function _h(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(nh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else nh(n)}function nh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function al(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function rh(n){return n.editable&&!n.hasFocus()?!1:Uh(n)}function Uh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Um(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Xo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Vt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ih(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Vt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xo(n.state,e);return i&&i instanceof C?Vt(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?C.isSelectable(s)?Vt(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):Wr?Vt(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof C&&r.node.isInline)return Vt(n,new A(e>0?r.$to:r.$from));{let i=Xo(n.state,e);return i?Vt(n,i):!1}}}function is(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function zr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Wn(n,e){return e<0?Vm(n):Bm(n)}function Vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(zr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Vh(t))break;{let l=t.previousSibling;for(;l&&zr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=is(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Qo(n,t,r):i&&Qo(n,i,s)}function Bm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=is(t),s,o;for(;;)if(r{n.state==i&&yt(n)},50)}function sh(n,e){let t=n.state.doc.resolve(e);if(!(ae||hm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function oh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ve&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Xo(n.state,e);if(o&&o instanceof C)return Vt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Te?S.near(o,e):S.findFrom(o,e);return l?Vt(n,l):!1}return!1}function lh(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ch(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function zm(n){if(!me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ch(n,r,"true"),setTimeout(()=>ch(n,r,"false"),20)}return!1}function Fm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qm(n,e){let t=e.keyCode,r=Fm(e);if(t==8||ve&&t==72&&r=="c")return lh(n,-1)||Wn(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return lh(n,1)||Wn(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?sh(n,n.state.selection.from)=="ltr"?-1:1:-1;return ih(n,i,r)||Wn(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?sh(n,n.state.selection.from)=="ltr"?1:-1:1;return ih(n,i,r)||Wn(n,i)}else{if(t==38||ve&&t==80&&r=="c")return oh(n,-1,r)||Wn(n,-1);if(t==40||ve&&t==78&&r=="c")return zm(n)||oh(n,1,r)||Wn(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Bh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Rt.fromSchema(n.state.schema),l=Hh(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=qh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:c,text:f,slice:e}}function Ph(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=It.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=$m(t),$r&&Wm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!qm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=jm(ah(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Hm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var qm=/^(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 Hm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&zh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Fh(o[o.length-1],s.length));let h=Lh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function Lh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function zh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ah(n,e,t){return et}).createHTML(n):n}function $m(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Hh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=Jm(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Km={touchstart:!0,touchmove:!0},el=class{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.compositionNode=null,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 Ym(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Xm(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Km[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),tl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Gm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function tl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>hl(n,r))})}function hl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Xm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Qm(n,e){!hl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!$h(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Kn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Fm(n,t)?t.preventDefault():Vt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if($h(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function Zm(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function dl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function jn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function eg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(jn(n,new C(t),"pointer"),!0):!1}function tg(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(C.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function ng(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?tg(n,t):eg(n,t))}function rg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ig(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||sg(n,t,r)}function sg(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(jn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)jn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return ss(n)}var Jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Zm(t,n.input.lastClick)&&!t[Jh]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(fs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,o,t,!!r)):(s=="doubleClick"?rg:ig)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var nl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Jh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof C&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!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)),Vt(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(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):ng(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(jn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Vt(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)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),fl(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>fl(n);function $h(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var og=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ss(n,!0),n.markCursor=null;else if(ss(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Wh(n,og)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Wh(n,20))};function Wh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ss(n),e))}function jh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=cg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function lg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=im(e.focusNode,e.focusOffset),r=sm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function cg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ss(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),jh(n),e||n.docView&&n.docView.dirty){let t=cl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function ag(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Fr=ke&&Bt<15||Kn&&hm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Fr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Bh(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):ag(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function hg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function dg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?qr(n,r.value,null,i,e):qr(n,r.textContent,r.innerHTML,i,e)},50)}function qr(n,e,t,r,i){let s=Ph(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=hg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Kh(r),r.getData("text/html"),i,t)?t.preventDefault():dg(n,t)};var ls=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Yh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(fs(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)o=C.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=C.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Bh(n,l);(!t.dataTransfer.files.length||!ae||Ch>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Fr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Fr||t.dataTransfer.setData("text/plain",a),n.dragging=new ls(h,!t[Yh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(fs(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Ph(n,Kh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Yh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Na(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new C(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(al(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Hr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cs=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Hr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Xh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=ug(l,n,e,t,i,s,o),h=hs(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Xh(n,l,c+t);if(a){s=!0;let h=hs(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Gh(s?Qh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var pg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mg=ke&&Bt<=11,il=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}},sl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new il,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),mg&&(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,pg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(rh(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(ke&&Bt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=zr(s))t.add(s);for(let s=e.anchorNode;s;s=zr(s))if(t.has(s)){r=s;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}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&rh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||wg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),gg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||mt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:xg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function xg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var Sg=/^(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 kg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=cl(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100ap(n,on(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),s&&Bi.setMeta("composition",s),n.dispatch(Bi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=bg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!Sg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=mh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);s&&Nt.setMeta("composition",s),n.dispatch(Nt)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Bt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Mg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,dt,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20)),Y=n.state.tr.delete(Se,pe),dt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Cg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Ot.type=="add"?Y.addMark(Se,pe,Ot.mark):Y.removeMark(Se,pe,Ot.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=mh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Cg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ag(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ol=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new el,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Sh),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=bh(this),wh(this),this.nodeViews=xh(this),this.docView=Xa(this.state.doc,yh(this),zo(this),this.dom,this),this.domObserver=new sl(this,(r,i,s,o)=>kg(this,r,i,s,o)),this.domObserver.start(),Ym(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&tl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Sh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(jh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=xh(this);Tg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=bh(this),wh(this);let c=zo(this),a=yh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&um(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Eg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=lg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Xa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_m(this))?mt(this,u):(_h(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),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&pm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$a(this,t.getBoundingClientRect(),e)}else $a(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ls(e.slice,e.move,i<0?void 0:C.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return xm(this,e)}coordsAtPos(e,t=1){return Dh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Am(this,t||this.state,e)}pasteHTML(e,t){return qr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return qr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Gm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,nm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Qm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&lm(this.dom.ownerDocument)==this.dom&&yg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function yh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function wh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function bh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Eg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function xh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Tg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Sh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Dg=["p",0],Og=["blockquote",0],Ng=["hr"],Ig=["pre",["code",0]],Rg=["br"],vg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Dg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Og}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ng}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Ig}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Rg}}},_g=["em",0],Ug=["strong",0],Vg=["code",0],Bg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return _g}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Ug}},code:{parseDOM:[{tag:"code"}],toDOM(){return Vg}}},Pg=new Dr({nodes:vg,marks:Bg});var ed=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Lg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var zg=(n,e,t)=>{let r=Lg(n,t);if(!r)return!1;let i=td(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(id(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||C.isSelectable(s)))for(let o=r.depth;;o--){let l=Xi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Gn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var Fg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=td(r)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function td(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function qg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=qg(n,t);if(!r)return!1;let i=nd(r);if(!i)return!1;let s=i.nodeAfter;if(id(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||C.isSelectable(s))){let o=Xi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof C,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=Ro(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(C.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},rd=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=Ro(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},$g=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function ml(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ml(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Wg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ml(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Rt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Kg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!Rt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Rt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Yg=Kg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Gg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Xg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function id(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Xg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&nn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Gn(s,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Qg=sd(-1),Zg=sd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Gi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ty(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new vt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new Zt(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Rt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function bl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?dy(e,t,n,s):fy(e,t,s):!0:!1}}function dy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var yt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ms={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},uy=typeof navigator<"u"&&/Mac/.test(navigator.platform),py=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)yt[48+J]=yt[96+J]=String(J);var J;for(J=1;J<=24;J++)yt[J+111]="F"+J;var J;for(J=65;J<=90;J++)yt[J]=String.fromCharCode(J+32),ms[J]=String.fromCharCode(J);var J;for(ps in yt)ms.hasOwnProperty(ps)||(ms[ps]=yt[ps]);var ps;function cd(n){var e=uy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||py&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ms:yt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var my=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function gy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=yt[r.keyCode])&&s!=i){let l=e[Sl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var gs=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new ad(e):re.empty};var ad=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new ad([]);var by=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),kl=re;var xy=500,ys=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hky&&(l=Sy(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Rr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fxy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),s)}};ys.empty=new ys(kl.empty,0);function Sy(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Ml=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},ky=20;function Cy(n,e,t){let r=My(e),i=Al.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,hd=null;function My(n){let e=n.plugins;if(hd!=e){Cl=!1,hd=e;for(let t=0;t{let i=Al.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Cy(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Xr=ws(!1,!0),Qn=ws(!0,!0),yx=ws(!1,!1),wx=ws(!0,!1);var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new El(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ay(e)||!Ey(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!C.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var El=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ay(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-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 Ey(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;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 Ty(){return new H({props:{decorations:Iy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Oy,handleKeyDown:Dy,handleDOMEvents:{beforeinput:Ny}}})}var Dy=Gr({ArrowLeft:bs("horiz",-1),ArrowRight:bs("horiz",1),ArrowUp:bs("vert",-1),ArrowDown:bs("vert",1)});function bs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Oy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&C.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Ny(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Iy(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function wt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var vy=500;function ud({rules:n}){let e=new H({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return fd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&fd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function fd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-vy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},_y=new bt(/--$/,"\u2014"),Uy=new bt(/\.\.\.$/,"\u2026"),Tx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Dx=new bt(/"$/,"\u201D"),Ox=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Nx=new bt(/'$/,"\u2019");var md=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Vy(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",pd),md||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",rd),i("Mod-BracketLeft",jr),i("Escape",Kr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let s=r,o=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),md&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",wl(r)),i("Mod-[",bl(r)),i("Mod-]",xl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Dl,Ol;if(typeof WeakMap<"u"){let n=new WeakMap;Dl=e=>n.get(e),Ol=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Dl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Ly(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function yd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Fy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.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:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>gd(r,e)}],toDOM(r){return["td",yd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>gd(r,e)}],toDOM(r){return["th",yd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var zt=new le("selectingCells");function Zn(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function qy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function vl(n){let e=n.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;let t=Zn(e.$head)||Hy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Hy(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Nl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Jy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function _l(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ed(n,e,t){let r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Td(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new vt(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Nl(r)&&Nl(i)&&_l(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?xt.rowSelection(r,i):s&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof xt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),L.create(n.doc,e)}function Ky({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Yy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Gy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof C&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=z.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&Ky(r)?s=A.create(i,r.from):r instanceof A&&Yy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Xy=new le("fix-tables");function Od(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=Qy(n,i,s,t))};return e?e.doc!=n.doc&&Od(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qy(n,e,t,r){let i=z.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;$y(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;r0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function d0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=qy(i.$from),!s)return!1;o=(r=Zn(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var Qx=Ul("row",{useDeprecatedLogic:!0}),Zx=Ul("column",{useDeprecatedLogic:!0}),eS=Ul("cell",{useDeprecatedLogic:!0});function u0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function xs(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function g0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function b0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Cs(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=vd(i,n,e);if(o==null)return!1;if(n=="horiz")return Cs(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Ed(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Cs(t,r,a)}}}function ks(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=vd(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Ed(o.$headCell,n,e);return l?Cs(t,r,new V(o.$anchorCell,l)):!1}}function S0(n,e){let t=n.state.doc,r=Zn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function k0(n,e,t){if(!He(n.state))return!1;let r=g0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(Il(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=w0(r,l.right-l.left,l.bottom-l.top),kd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=vl(n.state),o=s.start(-1);return kd(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function C0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Cd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Tl(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Tl(n,a),d=zt.getState(n.state)==null;if(!h||!_l(c,h))if(d)h=c;else return;let f=new V(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(zt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),zt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(zt,-1))}function l(c){let a=c,h=zt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Cd(n,a.target)!=r&&(d=Tl(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function vd(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Cd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Tl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var M0=class{constructor(n,e){this.node=n,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")),Rl(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Rl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Rl(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new E0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{T0(s,o,n,e,r)},mouseleave:s=>{D0(s)},mousedown:(s,o)=>{O0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return U0(s,o.activeHandle)},nodeViews:{}}});return i}var E0=class Ms{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new Ms(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ms(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Nl(e.doc.resolve(i))||(i=-1),new Ms(i,t.dragging)}return t}};function T0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=I0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Md(n,e,"left",t):a-e.clientX<=t&&(l=Md(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=z.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}_d(n,l)}}}function D0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&_d(n,-1)}function O0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=N0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(R0(n,d.activeHandle,Ad(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ad(d.dragging,h,t);v0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function N0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;ajs,AbstractConnector:()=>ac,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>Et,ContentFormat:()=>P,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Mt,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>dc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Ys,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qs,YEvent:()=>Dn,YMapEvent:()=>Zs,YTextEvent:()=>eo,YXmlEvent:()=>to,applyUpdate:()=>kc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Ou,compareIDs:()=>kn,compareRelativePositions:()=>ro,convertUpdateFormatV1ToV2:()=>h1,convertUpdateFormatV2ToV1:()=>fu,createAbsolutePositionFromRelativePosition:()=>Tc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>bc,createDocFromSnapshot:()=>Yw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Jw,decodeSnapshot:()=>jw,decodeSnapshotV2:()=>Zf,decodeStateVector:()=>Mc,decodeUpdate:()=>r1,decodeUpdateV2:()=>ou,diffUpdate:()=>l1,diffUpdateV2:()=>Dc,emptySnapshot:()=>Kw,encodeRelativePosition:()=>qw,encodeSnapshot:()=>Ww,encodeSnapshotV2:()=>Qf,encodeStateAsUpdate:()=>Cc,encodeStateAsUpdateV2:()=>Yf,encodeStateVector:()=>Ec,encodeStateVectorFromUpdate:()=>i1,encodeStateVectorFromUpdateV2:()=>cu,equalDeleteSets:()=>jf,equalSnapshots:()=>$w,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>B,getTypeChildren:()=>p1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>Pw,logUpdate:()=>n1,logUpdateV2:()=>su,mergeDeleteSets:()=>Mn,mergeUpdates:()=>lu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>c1,obfuscateUpdateV2:()=>a1,parseUpdateMeta:()=>s1,parseUpdateMetaV2:()=>au,readUpdate:()=>_w,readUpdateV2:()=>Sc,relativePositionToJSON:()=>Lw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Xw,transact:()=>R,tryGc:()=>e1,typeListToArraySnapshot:()=>lo,typeMapGetAllSnapshot:()=>Mu,typeMapGetSnapshot:()=>y1});var _=()=>new Map,As=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Ud=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Vd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Es=n=>n[n.length-1];var Bd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},tr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,aS=Number.isNaN,zd=Math.pow;var Ds=n=>n!==0?n<0:1/n<0;var Vl=Number.MAX_SAFE_INTEGER,hS=Number.MIN_SAFE_INTEGER,dS=1<<31;var Fd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),fS=Number.isNaN,uS=Number.parseInt;var Bl=String.fromCharCode,pS=String.fromCodePoint,mS=Bl(65535),B0=n=>n.toLowerCase(),P0=/^\s*/g,L0=n=>n.replace(P0,""),z0=/([A-Z])/g,Pl=(n,e)=>L0(n.replace(z0,t=>`${e}${B0(t)}`));var F0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Hd=ir?q0:F0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Jd=(n,e)=>Ld(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var Ns=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Ns(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var cr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ni=(n,e)=>{let t=Ds(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Ll=new Uint8Array(3e4),J0=Ll.length/3,$0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iar(n,I(e)),ar=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),ar(n,e)},zl=(n,e)=>{H0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},j0=(n,e)=>zl(n,4).setFloat32(0,e,!1),K0=(n,e)=>zl(n,8).setFloat64(0,e,!1),Y0=(n,e)=>zl(n,8).setBigInt64(0,e,!1);var Wd=new DataView(new ArrayBuffer(4)),G0=n=>(Wd.setFloat32(0,n),Wd.getFloat32(0)===n),or=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Fd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):G0(e)?(Q(n,124),j0(n,e)):(Q(n,123),K0(n,e));break;case"bigint":Q(n,122),Y0(n,e);break;case"object":if(e===null)Q(n,126);else if(Zr(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var jd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(jd(this),this.count=1,this.s=e)}toUint8Array(){return jd(this),I(this.encoder)}};var Kd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ni(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},lr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Kd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}},Os=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var Gd=Ze("Unexpected end of array"),Xd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Fl=n=>n.pos!==n.arr.length;var X0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>X0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posVl)throw Xd}throw Gd},ii=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posVl)throw Xd}throw Gd};var Q0=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},Z0=n=>rr.decode(K(n)),Le=rr?Z0:Q0;var ql=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},ew=n=>ql(n,4).getFloat32(0,!1),tw=n=>ql(n,8).getFloat64(0,!1),nw=n=>ql(n,8).getBigInt64(0,!1);var rw=[n=>{},n=>null,ii,ew,tw,nw,n=>!1,n=>!0,Le,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rrw[127-xn(n)](n),ri=class extends hr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Fl(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends hr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Ds(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var fr=class extends hr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ii(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},vs=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var wS=crypto.subtle,Qd=crypto.getRandomValues.bind(crypto);var iw=Math.random,Hl=()=>Qd(new Uint32Array(1))[0];var Zd=n=>n[fe(iw()*n.length)],sw="10000000-1000-4000-8000"+-1e11,ef=()=>sw.replace(/[018]/g,n=>(n^Hl()&15>>n/4).toString(16));var Ne=Date.now;var Jl=n=>new Promise(n);var SS=Promise.all.bind(Promise);var $l=n=>n===void 0?null:n;var Wl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},nf=new Wl,jl=!0;try{typeof localStorage<"u"&&localStorage&&(nf=localStorage,jl=!1)}catch{}var Us=nf,rf=n=>jl||addEventListener("storage",n),sf=n=>jl||removeEventListener("storage",n);var cf=Object.assign,Vs=Object.keys,af=(n,e)=>{for(let t in n)e(n[t],t)},hf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Kl=n=>Vs(n).length,lf=n=>Vs(n).length;var df=n=>{for(let e in n)return!1;return!0},cw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Yl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Gl=(n,e)=>n===e||lf(n)===lf(e)&&cw(n,(t,r)=>(t!==void 0||Yl(e,r))&&e[r]===t),aw=Object.freeze,Xl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Xl(n[e])}return aw(n)};var oi=(n,e,t=0)=>{try{for(;tn,hw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return hw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",pr=typeof window<"u"&&typeof document<"u"&&!kt,kS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,dw=[],fw=()=>{if(et===void 0)if(kt){et=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${Pl(e,"-")}`,t),et.set(`-${Pl(e,"-")}`,t)}})):et=_();return et},ec=n=>fw().has(n);var li=n=>kt?$l(process.env[n.toUpperCase().replaceAll("-","_")]):$l(Us.getItem(n));var uf=n=>ec("--"+n)||li(n)!==null,CS=uf("production"),uw=kt&&ff(process.env.FORCE_COLOR,["true","1","2"]),pf=uw||!ec("--no-colors")&&!uf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||ec("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var mf=n=>new Uint8Array(n),pw=(n,e,t)=>new Uint8Array(n,e,t),gf=n=>new Uint8Array(n),mw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),yw=n=>{let e=atob(n),t=mf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return pw(e.buffer,e.byteOffset,e.byteLength)},yf=pr?mw:gw,wf=pr?yw:ww;var bf=n=>{let e=mf(n.byteLength);return e.set(n),e};var tc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new tc(n,e);var Ct=typeof document<"u"?document:{};var MS=typeof DOMParser<"u"?new DOMParser:null;var Sf=n=>Ud(n,(e,t)=>`${t}:${e};`).join("");var AS=Ct.ELEMENT_NODE,ES=Ct.TEXT_NODE,TS=Ct.CDATA_SECTION_NODE,DS=Ct.COMMENT_NODE,OS=Ct.DOCUMENT_NODE,NS=Ct.DOCUMENT_TYPE_NODE,IS=Ct.DOCUMENT_FRAGMENT_NODE;var Ps=n=>class{constructor(t){this._=t}destroy(){n(this._)}},xw=Ps(clearTimeout),ai=(n,e)=>new xw(setTimeout(e,n)),vS=Ps(clearInterval);var _S=Ps(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var US=Ps(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),nc=nt(),rc=nt(),ic=nt(),fi=nt(),sc=nt(),mr=nt(),oc=nt(),Mf=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Af(n)),Ef.forEach(e=>e.print(n))},lc=(...n)=>{console.warn(...Af(n)),n.unshift(mr),Ef.forEach(e=>e.print(n))};var Ef=Ce();var Tf=n=>({[Symbol.iterator](){return this},next:n}),Df=(n,e)=>Tf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zs=(n,e)=>Tf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ac=class extends er{constructor(e,t){super(),this.doc=e,this.awareness=t}},pi=class{constructor(e,t){this.clock=e,this.len=t}},$t=class{constructor(){this.clients=new Map}},rt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Ow(t,e.clock)!==null},wc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,bc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},it=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),it(s,r),s.toUint8Array()}return null},jf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Kf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ks,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Jl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Jl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,at)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Me=class extends An{readLeftID(){return M(k(this.restDecoder),k(this.restDecoder))}readRightID(){return M(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return dr(this.restDecoder)}readBuf(){return bf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Ws=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends Ws{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new fr(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new fr(K(e)),this.rightClockDecoder=new fr(K(e)),this.infoDecoder=new ri(K(e),xn),this.stringDecoder=new vs(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return dr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return dr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ei(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Nw(n,e.clients.get(i),i,s)})},Iw=(n,e)=>{let t=_(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ks,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return xc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},vw=(n,e)=>xc(n,e.doc.store,e.beforeState),Sc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Iw(r,o),a=Rw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=yi([h.update,a.update])}}else l.pendingStructs=a;let d=If(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=If(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),_w=(n,e,t)=>Sc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Sc(i,n,t,new r(i))},kc=(n,e,t)=>vn(n,e,t,Me),Uw=(n,e,t=new Map)=>{xc(n,e.store,t),it(n,bc(e.store))},Yf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Mc(e);Uw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Dc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===st)return lu(i.map((s,o)=>o===0?s:fu(s)));if(t.constructor===Ie)return yi(i)}return i[0]},Cc=(n,e)=>Yf(n,e,new st),Gf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rGf(new An(q(n))),Ac=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Vw=(n,e)=>Ac(n,Ei(e.store)),Bw=(n,e=new gr)=>(n instanceof Map?Ac(e,n):Vw(e,n),e.toUint8Array()),Ec=n=>Bw(n,new Wt),hc=class{constructor(){this.l=[]}},Rf=()=>new hc,vf=(n,e)=>n.l.push(e),_f=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Xf=(n,e,t)=>oi(n.l,[e,t]),Mt=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Mt(n,e),Uf=(n,e)=>{x(n,e.client),x(n,e.clock)},Vf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Pw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},dc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||br(),At(new An(q(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>At(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;it(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Tt(r,e))return t;return null}},ot=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Lw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new ot(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),js=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},zw=(n,e,t=0)=>new js(n,e,t),Fs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fs(n,r.lastId,t);r=r.right}return Fs(n,null,t)},Fw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Uf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Uf(n,t);else throw j();return ni(n,s),n},qw=n=>{let e=F();return Fw(e,n),I(e)},Hw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Vf(n);break;case 1:t=Le(n);break;case 2:e=Vf(n)}let i=Fl(n)?ii(n):0;return new ot(e,t,r,i)},Jw=n=>Hw(q(n)),Tc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?gc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?gc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return zw(c,a,n.assoc)},ro=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,jt=class{constructor(e,t){this.ds=e,this.sv=t}},$w=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Ac(e,n.sv),e.toUint8Array()),Ww=n=>Qf(n,new Wt),Zf=(n,e=new Ws(q(n)))=>new jt(At(e),Gf(e)),jw=n=>Zf(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Kw=Mi(br(),new Map),Ai=n=>Mi(bc(n.store),Ei(n.store)),qt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Tt(e.ds,n.id),fc=(n,e)=>{let t=$(n.meta,fc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Yw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Gw(n,e,Me),Ks=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ei=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},eu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=Qw,uc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[uc(n,t,e.clock)]},Bf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,no(n,s,t.clock-s.id.clock+1)),s},Zw=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},tu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=uc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Vd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(wc(e.deleteSet),vw(n,e),it(n,e.deleteSet),!0),Lf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},Js=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},nu=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+Js(i,c)}})},e1=(n,e,t)=>{nu(n,e,t),ru(n,e)},iu=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Xf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),oi(l,[]),t._needFormattingCleanup&&S1(t)}finally{r.gc&&nu(s,i,r.gcFilter),ru(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Js(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Js(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Ls(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Kf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;Pf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Pf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):iu(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ys(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&iu(i,0)}}return o},pc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},zf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&vc(r,!1)})},Ff=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;rt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=gc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Iu(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new $t;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&mi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new pc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),rt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&vc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=Zr(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&lc("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>zf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>zf(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Ff(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Ff(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*t1(n){let e=k(n.restDecoder);for(let t=0;tsu(n,Me),su=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Ls("Structs: ",t);let s=At(r);Ls("DeleteSet: ",s)},r1=n=>ou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},lu=n=>yi(n,Me,st),cu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,o),Yd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},i1=n=>cu(n,Wt,Me),au=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},s1=n=>au(n,Me),o1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},yi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new gi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=o1(f,p)),s.struct.mergeWith(f)||(Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Ht(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ht(l,s.struct,s.offset),s=null),Oc(l);let c=r.map(h=>At(h)),a=Mn(c);return it(o,a),o.toUint8Array()},Dc=(n,e,t=be,r=Ie)=>{let i=Mc(e),s=new r,o=new gi(s),l=new t(q(n)),c=new lt(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Ht(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Oc(o);let a=At(l);return it(s,a),s.toUint8Array()},l1=(n,e)=>Dc(n,e,Me,st),hu=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=F(),n.written=0)},Ht=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&hu(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Oc=n=>{hu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new lt(i,!1),o=new r,l=new gi(o);for(let a=s.curr;a!==null;a=s.next())Ht(l,e(a),0);Oc(l);let c=At(i);return it(o,c),o.toUint8Array()},du=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Et:{let d=h;d.embed={};break}case P:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case ki:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=Jd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},c1=(n,e)=>io(n,du(e),Me,st),a1=(n,e)=>io(n,du(e),be,Ie),h1=n=>io(n,Ql,Me,Ie),fu=n=>io(n,Ql,be,st),qf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=d1(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Es(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Es(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Es(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},d1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{lc("Invalid access: Add Yjs type to a document before reading data.")},uu=80,Nc=0,mc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Nc++}},f1=n=>{n.timestamp=Nc++},pu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Nc++},u1=(n,e,t)=>{if(n.length>=uu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>nr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&nr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},p1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},oo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Xf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Rf(),this._dEH=Rf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){vf(this._eH,e)}observeDeep(e){vf(this._dEH,e)}unobserve(e){_f(this._eH,e)}unobserveDeep(e){_f(this._dEH,e)}toJSON(){}},mu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},gu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&qt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},m1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},wu=(n,e)=>{n.doc??se();let t=so(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Kt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},bu=()=>Ze("Length exceeded!"),xu=(n,e,t,r)=>{if(t>e._length)throw bu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Gs(n,e,null,r);let i=t,s=so(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Gs(n,e,i,t)},Su=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=so(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw bu();e._searchMarker&&wi(e._searchMarker,i,-s+r)},Xs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ic=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Kt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Kt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Rc=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},ku=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Cu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},y1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&qt(r,t)?r.content.getContent()[r.length-1]:void 0},Mu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&qt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},qs=n=>(n.doc??se(),Df(n._map.entries(),e=>!e[1].deleted)),Qs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),oo(this,e,new Qs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{g1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return wu(this,e)}toArray(){return gu(this)}slice(e=0,t=this.length){return mu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return yu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return m1(this)}_write(e){e.writeTypeRef(P1)}},w1=n=>new On,Zs=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){oo(this,e,new Zs(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...qs(this)].length}keys(){return zs(qs(this),e=>e[0])}values(){return zs(qs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zs(qs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Rc(this,e)}has(e){return Cu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(L1)}},b1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Gl(n,e),xi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case P:this.right.deleted||xr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Hf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?so(e,t):null;if(s){let o=new xi(s.p.left,s.p,s.index,i);return Hf(n,o,t-s.index)}else{let o=new xi(null,e._start,0,i);return Hf(n,o,t)}},Au=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Jt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},xr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Eu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Jt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Tu=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},cc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Et(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Au(n,e,t,l)},Jf=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Jt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` -`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Au(n,e,t,l)},Du=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&xr(i,a);break}}}e=e.right}return l},x1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Ou=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=As(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:xr(o,i.content);break;default:e+=Du(t,r,i,s,o),s=As(o),r=i;break}i=i.right}}),e},S1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&tu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):x1(r,i)});for(let i of e)Ou(i)})},$f=(n,e,t)=>{let r=t,i=As(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Et:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},df(c)||(u.attributes=cf({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Et:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Jt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Jt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),xr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ct=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new eo(this,e,t);oo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new xi(null,this._start,0,new Map);for(let s=0;s0)&&cc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?Jf(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&$f(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(qt(c,e)||t!==void 0&&qt(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!qt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case P:qt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&fc(d,e),t&&fc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),cc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);cc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{$f(i,Hs(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!1);o.right!==null&&Jf(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Rc(this,e)}getAttributes(){return ku(this)}_write(e){e.writeTypeRef(z1)}},k1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===at)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},at=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){oo(this,e,new to(this,t,e))}toString(){return yu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),bi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Gs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw Ze("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return gu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return wu(this,e)}slice(e=0,t=this.length){return mu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(q1)}},C1=n=>new at,Z=class n extends at{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return af(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Rc(this,e)}hasAttribute(e){return Cu(this,e)}getAttributes(e){return e?Mu(this,e):ku(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return bi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(F1),e.writeKey(this.nodeName)}},M1=n=>new Z(n.readKey()),to=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},Si=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(H1),e.writeKey(this.hookName)}},A1=n=>new Si(n.readKey()),xe=class n extends ct{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(J1)}},E1=n=>new xe,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},T1=0,ue=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),eu(e.doc.store,this)}write(e,t){e.writeInfo(T1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},D1=n=>new In(n.readBuf()),wr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},O1=n=>new wr(n.readLen()),Nu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Nu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},N1=n=>new Rn(Nu(n.readString(),n.readAny())),Et=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},I1=n=>new Et(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},R1=n=>new P(n.readKey(),n.readJSON()),ki=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},V1=n=>new Re(n.readString()),B1=[w1,b1,k1,M1,C1,A1,E1],P1=0,L1=1,z1=2,F1=3,q1=4,H1=5,J1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},$1=n=>new Ae(B1[n.readTypeRef()](n)),gc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},vc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},no=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},Wf=(n,e)=>Pd(n,t=>Tt(t.deletions,e)),Iu=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Iu(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Tt(r,d.right.id)||Wf(s.undoStack,d.right.id)||Wf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,vc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Bf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mi(e.deleteSet,this.id.client,this.id.clock,this.length),Lf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?Zw(e,this,new ue(this.id,this.length)):this.content=new wr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Mt?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},Ru=(n,e)=>W1[e&31](n),W1=[()=>{j()},O1,v1,D1,V1,I1,R1,$1,U1,N1,()=>{j()}],j1=10,ie=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(j1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},vu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},_u="__ $YJS$ __";vu[_u]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");vu[_u]=!0;var Uu=new Map,_c=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:wf(t.newValue||"")}),rf(this._onChange)}postMessage(e){Us.setItem(this.room,yf(gf(e)))}close(){sf(this._onChange)}},K1=typeof BroadcastChannel>"u"?_c:BroadcastChannel,Uc=n=>$(Uu,n,()=>{let e=Ce(),t=new K1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Vu=(n,e)=>(Uc(n).subs.add(e),e),Bu=(n,e)=>{let t=Uc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Uu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Uc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Pu=0,co=1,Lu=2,ao=(n,e)=>{x(n,Pu);let t=Ec(e);U(n,t)},Vc=(n,e,t)=>{x(n,co),U(n,Cc(e,t))},G1=(n,e,t)=>Vc(e,t,K(n)),zu=(n,e,t)=>{try{kc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Fu=(n,e)=>{x(n,Lu),U(n,e)},X1=zu,qu=(n,e,t,r)=>{let i=k(n);switch(i){case Pu:G1(n,e,t);break;case co:zu(n,t,r);break;case Lu:X1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var Z1=0;var Hu=(n,e,t)=>{switch(k(n)){case Z1:t(e,Le(n))}};var Bc=3e4,ho=class extends tr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Bc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Bc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&fo(this,r,"timeout")},fe(Bc/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),ur(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},kr=(n,e,t=n.states)=>{let r=e.length,i=F();x(i,r);for(let s=0;s{let r=q(e),i=Ne(),s=[],o=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var $u=n=>hf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,ju=3,Cr=1,rb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=qu(e,n,t.doc,t);r&&s===co&&!t.synced&&(t.synced=!0)};Ti[ju]=(n,e,t,r,i)=>{x(n,Cr),U(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Ju(t.awareness,K(e),t)};Ti[rb]=(n,e,t,r,i)=>{Hu(e,t.doc,(s,o)=>ib(t,o))};var Wu=3e4,ib=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Ku=(n,e,t)=>{let r=q(e),i=F(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Yu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Ku(n,new Uint8Array(t.data),!0);Ns(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,fo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Yu,De(zd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=F();if(x(t,Bn),ao(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),U(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Pc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Lc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:s=new ho(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ti.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=F();x(f,Bn),ao(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Ku(this,new Uint8Array(f),!1);Ns(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Fu(p,f),Pc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=F();x(y,Cr),U(y,kr(s,g)),Pc(this,I(y))},this._exitHandler=()=>{fo(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Wu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var sb=/[\uD800-\uDBFF]/,ob=/[\uDC00-\uDFFF]/,lb=(n,e)=>{let t=0,r=0;for(;t0&&sb.test(n[t-1])&&t--;r+t0&&ob.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Xu=lb;var v=new le("y-sync"),Dt=new le("y-undo"),Di=new le("yjs-cursor");var Ni=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Tt(e.ds,n.id),cb=[{light:"#ecd44433",dark:"#ecd444"}],ab=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Zd(e))}return n.get(t)},ep=(n,{colors:e=cb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new uo(n,s),c=new H({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ai(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Dt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},hb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Yt(t.doc,t.type,e.anchor,t.mapping),i=Yt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ii=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),uo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Gu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(pr&&this._domSelectionInView===null&&(ai(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Mi(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Oi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Oi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ai(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ai(i),vn(i,e),e=Ai(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{rt(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:ab(r.colorMapping,r.colors,f)}},c=lo(this.type,new jt(t.ds,e.sv)).map(h=>!h._item.deleted||Ni(h._item,e)||Ni(h._item,t)?Oi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);rt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>tp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));hb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Mr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},tp=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,s);throw Oe()}return o},Oi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=tp(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof ct&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=db(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):lo(n,new jt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ni(n._item,r)?Ni(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},db=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},fb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:rp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},ub=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,mo(n).map(r=>zc(r,e))),e.set(t,n),t},zc=(n,e)=>n instanceof Array?fb(n,e):ub(n,e),Qu=n=>typeof n=="object"&&n!==null,qc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Vs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>qc(r.attributes[s.type.name]||{},s.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Fc(n,e)){let t=mo(e);return n._length===t.length&&qc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&np(n,e)},po=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Zu=(n,e,t)=>{let r=n.toArray(),i=mo(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},mb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=pb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,rp(a.marks))})),{insert:o,remove:l,index:c}=Xu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},rp=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Mr=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=mo(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)np(f,u)||mb(f,u,r),a+=1;else{let g=f instanceof Z&&Fc(f,u),y=p instanceof Z&&Fc(p,m);if(g&&y){let E=Zu(f,u,r),N=Zu(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var vi=null,gb=()=>{let n=vi;vi=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Hc=(n,e,t)=>{vi||(vi=new Map,ai(0,gb)),$(vi,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Ci(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Ci(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return yb(r._item.parent,r._item)}return Ci(e,e._length,-1)},yb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Tc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function sp(n,e="prosemirror"){return $c(n.getXmlFragment(e))}function $c(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var wb=(n,e,t)=>n!==e,bb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},xb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Sb=/^#[0-9a-fA-F]{6}$/,op=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?L.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Sb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Yt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(n.doc,l))},kb=(n,{awarenessStateFilter:e=wb,cursorBuilder:t=bb,selectionBuilder:r=xb,getSelection:i=o=>o.selection}={},s="cursor")=>new H({key:Di,state:{init(o,l){return op(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?op(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Di.getState(o)},view:o=>{let l=()=>{o.docView&&Hc(o,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!ro(Un(h.cursor.anchor),f)||!ro(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Cb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Mb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Ab=new Set(["paragraph"]),Eb=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof ct||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Tb=({protectedNodes:n=Ab,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Eb(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Dt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Dt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var _i="http://www.w3.org/2000/svg",Db="http://www.w3.org/1999/xlink",jc="ProseMirror-icon",Wc="pm-close-dropdowns";function Ob(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,lp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;lp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function go(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Rb(n){Ui.time=Date.now(),Ui.node=n.target}function vb(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Wc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Rb(d),o?a():(r.dispatchEvent(new CustomEvent(Wc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{vb(s)||a()}),r.addEventListener(Wc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function _b(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Vk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),Bk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Pk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Lk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Bb(n,e){let t={run(r,i){return Xn(n,e.attrs)(r,i)},select(r){return Xn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new ht(t)}function Pb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function lp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Kc as Dropdown,Bo as EditorState,ol as EditorView,w as Fragment,bt as InputRule,ht as MenuItem,H as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Lc as WebsocketProvider,Sr as Y,e0 as addColumnAfter,Zy as addColumnBefore,ay as addListNodes,s0 as addRowAfter,i0 as addRowBefore,ld as baseKeymap,Pg as baseSchema,Pb as blockTypeItem,Vy as buildKeymap,A0 as columnResizing,n0 as deleteColumn,l0 as deleteRow,m0 as deleteTable,Nd as fixTables,Ty as gapCursor,p0 as goToNextCell,ud as inputRules,He as isInTable,wy as keymap,bl as liftListItem,a0 as mergeCells,ip as prosemirrorToYDoc,Jc as prosemirrorToYXmlFragment,Ub as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,h0 as splitCell,wl as splitListItem,V0 as tableEditing,Fy as tableNodes,mn as toggleMark,Xn as wrapIn,us as wrapInList,Bb as wrapItem,kb as yCursorPlugin,sp as yDocToProsemirrorJSON,Mb as yRedo,ep as ySyncPlugin,Cb as yUndo,Tb as yUndoPlugin,Dt as yUndoPluginKey,$c as yXmlFragmentToProsemirrorJSON}; +`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=Rt.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=Wm(t),Wr&&jm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Hm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Km(ah(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Jm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var Hm=/^(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 Jm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&zh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Fh(o[o.length-1],s.length));let h=Lh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function Lh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function zh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ah(n,e,t){return et}).createHTML(n):n}function Wm(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Hh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=$m(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Ym={touchstart:!0,touchmove:!0},el=class{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.compositionNode=null,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 Gm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Qm(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Ym[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),tl(n)}function Bt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Xm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function tl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>hl(n,r))})}function hl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Qm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Zm(n,e){!hl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!$h(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Yn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||qm(n,t)?t.preventDefault():Bt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if($h(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function eg(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function dl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Kn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function tg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(Kn(n,new C(t),"pointer"),!0):!1}function ng(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(C.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(Kn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function rg(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?ng(n,t):tg(n,t))}function ig(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function sg(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||og(n,t,r)}function og(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Kn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)Kn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))Kn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return ss(n)}var Jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&eg(t,n.input.lastClick)&&!t[Jh]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(fs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,o,t,!!r)):(s=="doubleClick"?ig:sg)(n,o.pos,o.inside,t)?t.preventDefault():Bt(n,"pointer"))};var nl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Jh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof C&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!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)),Bt(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(()=>yt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Bt(this.view,"pointer"):rg(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Kn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Bt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Bt(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)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),fl(n),Bt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Bt(n,"pointer")};ge.contextmenu=n=>fl(n);function $h(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var lg=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ss(n,!0),n.markCursor=null;else if(ss(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Wh(n,lg)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Wh(n,20))};function Wh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ss(n),e))}function jh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ag());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function cg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=sm(e.focusNode,e.focusOffset),r=om(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function ag(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ss(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),jh(n),e||n.docView&&n.docView.dirty){let t=cl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function hg(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var qr=ke&&Pt<15||Yn&&dm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=qr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Bh(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):hg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function fg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Hr(n,r.value,null,i,e):Hr(n,r.textContent,r.innerHTML,i,e)},50)}function Hr(n,e,t,r,i){let s=Ph(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=dg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=qr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Hr(n,Kh(r),r.getData("text/html"),i,t)?t.preventDefault():fg(n,t)};var ls=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Yh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(fs(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)o=C.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=C.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Bh(n,l);(!t.dataTransfer.files.length||!ae||Ch>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(qr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",qr||t.dataTransfer.setData("text/plain",a),n.dragging=new ls(h,!t[Yh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(fs(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Ph(n,Kh(t.dataTransfer),qr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Yh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Na(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new C(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(al(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&yt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Jr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cs=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Jr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Xh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=pg(l,n,e,t,i,s,o),h=hs(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Xh(n,l,c+t);if(a){s=!0;let h=hs(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Gh(s?Qh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var mg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},gg=ke&&Pt<=11,il=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}},sl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new il,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),gg&&(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,mg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(rh(this.view)){if(this.suppressingSelectionUpdates)return yt(this.view);if(ke&&Pt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Fr(s))t.add(s);for(let s=e.anchorNode;s;s=Fr(s))if(t.has(s)){r=s;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}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&rh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||bg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),yg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||yt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Sg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Sg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var kg=/^(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 Cg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,It=cl(n,T);if(It&&!n.state.selection.eq(It)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100hp(n,on(13,"Enter"))))return;let Pi=n.state.tr.setSelection(It);T=="pointer"?Pi.setMeta("pointer",!0):T=="key"&&Pi.scrollIntoView(),s&&Pi.setMeta("composition",s),n.dispatch(Pi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=xg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!kg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=mh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let It=n.state.tr.setSelection(T);s&&It.setMeta("composition",s),n.dispatch(It)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Pt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Yn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ag(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,ft,Nt;if(E){if(m.pos==g.pos)ke&&Pt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>yt(n),20)),Y=n.state.tr.delete(Se,pe),ft=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Nt=Mg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Nt.type=="add"?Y.addMark(Se,pe,Nt.mark):Y.removeMark(Se,pe,Nt.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",It=>It(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=mh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Mg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Eg(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ol=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new el,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Sh),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=bh(this),wh(this),this.nodeViews=xh(this),this.docView=Xa(this.state.doc,yh(this),zo(this),this.dom,this),this.domObserver=new sl(this,(r,i,s,o)=>Cg(this,r,i,s,o)),this.domObserver.start(),Gm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&tl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Sh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(jh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=xh(this);Dg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=bh(this),wh(this);let c=zo(this),a=yh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&pm(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Tg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=cg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Xa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Um(this))?yt(this,u):(_h(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),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&mm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$a(this,t.getBoundingClientRect(),e)}else $a(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ls(e.slice,e.move,i<0?void 0:C.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Sm(this,e)}coordsAtPos(e,t=1){return Dh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Em(this,t||this.state,e)}pasteHTML(e,t){return Hr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Hr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Xm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,rm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Zm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&cm(this.dom.ownerDocument)==this.dom&&wg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function yh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function wh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function bh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Tg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function xh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Dg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Sh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Og=["p",0],Ng=["blockquote",0],Ig=["hr"],Rg=["pre",["code",0]],vg=["br"],_g={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Og}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Ng}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ig}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Rg}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return vg}}},Ug=["em",0],Vg=["strong",0],Bg=["code",0],Pg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Ug}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Vg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Bg}}},Lg=new Or({nodes:_g,marks:Pg});var ed=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function zg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Fg=(n,e,t)=>{let r=zg(n,t);if(!r)return!1;let i=td(r);if(!i){let o=r.blockRange(),l=o&&rn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(id(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Xn(s,"end")||C.isSelectable(s)))for(let o=r.depth;;o--){let l=Xi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Xn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var qg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=td(r)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function td(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Hg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Hg(n,t);if(!r)return!1;let i=nd(r);if(!i)return!1;let s=i.nodeAfter;if(id(n,i,e,1))return!0;if(r.parent.content.size==0&&(Xn(s,"start")||C.isSelectable(s))){let o=Xi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof C,i;if(r){if(t.node.isTextblock||!pt(n.doc,t.from))return!1;i=t.from}else if(i=Ro(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(C.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},rd=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!pt(n.doc,t.to))return!1;r=t.to}else if(r=Ro(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},Kr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&rn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Wg=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function ml(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ml(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},jg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ml(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(vt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&rn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Yg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!vt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=vt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&vt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Gg=Yg();var Yr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Xg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Qg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||pt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function id(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Qg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&pt(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&rn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Xn(s,"start",!0)&&Xn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Zg=sd(-1),ey=sd(1);function Qn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Hn(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ny(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new _t(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new en(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return vt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function bl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?fy(e,t,n,s):uy(e,t,s):!0:!1}}function fy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var bt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ms={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},py=typeof navigator<"u"&&/Mac/.test(navigator.platform),my=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)bt[48+J]=bt[96+J]=String(J);var J;for(J=1;J<=24;J++)bt[J+111]="F"+J;var J;for(J=65;J<=90;J++)bt[J]=String.fromCharCode(J+32),ms[J]=String.fromCharCode(J);var J;for(ps in bt)ms.hasOwnProperty(ps)||(ms[ps]=bt[ps]);var ps;function cd(n){var e=py&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||my&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ms:bt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var gy=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function yy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=bt[r.keyCode])&&s!=i){let l=e[Sl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var gs=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new ad(e):re.empty};var ad=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new ad([]);var xy=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),kl=re;var Sy=500,ys=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hCy&&(l=ky(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new vr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fSy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),s)}};ys.empty=new ys(kl.empty,0);function ky(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Ml=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},Cy=20;function My(n,e,t){let r=Ay(e),i=Al.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,hd=null;function Ay(n){let e=n.plugins;if(hd!=e){Cl=!1,hd=e;for(let t=0;t{let i=Al.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=My(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Qr=ws(!1,!0),Zn=ws(!0,!0),wx=ws(!1,!1),bx=ws(!0,!1);var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new El(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ey(e)||!Ty(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!C.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var El=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ey(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-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 Ty(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;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 Dy(){return new H({props:{decorations:Ry,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Ny,handleKeyDown:Oy,handleDOMEvents:{beforeinput:Iy}}})}var Oy=Xr({ArrowLeft:bs("horiz",-1),ArrowRight:bs("horiz",1),ArrowUp:bs("vert",-1),ArrowDown:bs("vert",1)});function bs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Ny(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&C.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Iy(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Ry(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function xt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var _y=500;function ud({rules:n}){let e=new H({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return fd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&fd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function fd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-_y),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},Uy=new Qe(/--$/,"\u2014"),Vy=new Qe(/\.\.\.$/,"\u2026"),Ox=new Qe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Nx=new Qe(/"$/,"\u201D"),Ix=new Qe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Rx=new Qe(/'$/,"\u2019");function md(n,e,t=null,r){return new Qe(n,(i,s,o,l)=>{let c=t instanceof Function?t(s):t,a=i.tr.delete(o,l),h=a.doc.resolve(o),d=h.blockRange(),f=d&&Hn(d,e,c);if(!f)return null;a.wrap(d,f);let u=a.doc.resolve(o-1).nodeBefore;return u&&u.type==e&&pt(a.doc,o-1)&&(!r||r(s,u))&&a.join(o-1),a})}var gd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function By(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Qr),i("Shift-Mod-z",Zn),i("Backspace",pd),gd||i("Mod-y",Zn),i("Alt-ArrowUp",jr),i("Alt-ArrowDown",rd),i("Mod-BracketLeft",Kr),i("Escape",Yr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Qn(r)),r=n.nodes.hard_break){let s=r,o=Gr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),gd&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",wl(r)),i("Mod-[",bl(r)),i("Mod-]",xl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Dl,Ol;if(typeof WeakMap<"u"){let n=new WeakMap;Dl=e=>n.get(e),Ol=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Dl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function zy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function wd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function qy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.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:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>yd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>yd(r,e)}],toDOM(r){return["th",wd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Ft=new le("selectingCells");function er(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Hy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function vl(n){let e=n.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;let t=er(e.$head)||Jy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Jy(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Nl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function $y(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function _l(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Td(n,e,t){let r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Dd(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new _t(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Nl(r)&&Nl(i)&&_l(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?St.rowSelection(r,i):s&&this.isColSelection()?St.colSelection(r,i):new St(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof St&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),L.create(n.doc,e)}function Yy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Gy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Xy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof C&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=z.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&Yy(r)?s=A.create(i,r.from):r instanceof A&&Gy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Qy=new le("fix-tables");function Nd(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=Zy(n,i,s,t))};return e?e.doc!=n.doc&&Nd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Zy(n,e,t,r){let i=z.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;Wy(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;i0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function f0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=Hy(i.$from),!s)return!1;o=(r=er(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var Zx=Ul("row",{useDeprecatedLogic:!0}),eS=Ul("column",{useDeprecatedLogic:!0}),tS=Ul("cell",{useDeprecatedLogic:!0});function p0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function xs(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function y0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function x0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Cs(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=_d(i,n,e);if(o==null)return!1;if(n=="horiz")return Cs(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Td(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Cs(t,r,a)}}}function ks(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=_d(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Td(o.$headCell,n,e);return l?Cs(t,r,new V(o.$anchorCell,l)):!1}}function k0(n,e){let t=n.state.doc,r=er(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function C0(n,e,t){if(!He(n.state))return!1;let r=y0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(Il(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=b0(r,l.right-l.left,l.bottom-l.top),Cd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=vl(n.state),o=s.start(-1);return Cd(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function M0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Md(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=er(n.state.selection.$anchor))!=null&&((t=Tl(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Tl(n,a),d=Ft.getState(n.state)==null;if(!h||!_l(c,h))if(d)h=c;else return;let f=new V(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(Ft,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ft.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ft,-1))}function l(c){let a=c,h=Ft.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Md(n,a.target)!=r&&(d=Tl(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function _d(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Md(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Tl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?er(n.state.doc.resolve(t.pos)):null}var A0=class{constructor(n,e){this.node=n,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")),Rl(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Rl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Rl(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new T0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{D0(s,o,n,e,r)},mouseleave:s=>{O0(s)},mousedown:(s,o)=>{N0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return V0(s,o.activeHandle)},nodeViews:{}}});return i}var T0=class Ms{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new Ms(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ms(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Nl(e.doc.resolve(i))||(i=-1),new Ms(i,t.dragging)}return t}};function D0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=R0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Ad(n,e,"left",t):a-e.clientX<=t&&(l=Ad(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=z.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ud(n,l)}}}function O0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ud(n,-1)}function N0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=I0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(v0(n,d.activeHandle,Ed(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ed(d.dragging,h,t);_0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function I0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;ajs,AbstractConnector:()=>ac,AbstractStruct:()=>wr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Yt,ContentBinary:()=>In,ContentDeleted:()=>br,ContentDoc:()=>Rn,ContentEmbed:()=>Tt,ContentFormat:()=>P,ContentJSON:()=>Ci,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>At,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>dc,RelativePosition:()=>lt,Skip:()=>ie,Snapshot:()=>Kt,Text:()=>at,Transaction:()=>Ys,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>ot,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>ht,XmlHook:()=>ki,XmlText:()=>xe,YArrayEvent:()=>Qs,YEvent:()=>Dn,YMapEvent:()=>Zs,YTextEvent:()=>eo,YXmlEvent:()=>to,applyUpdate:()=>kc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Nu,compareIDs:()=>kn,compareRelativePositions:()=>ro,convertUpdateFormatV1ToV2:()=>d1,convertUpdateFormatV2ToV1:()=>uu,createAbsolutePositionFromRelativePosition:()=>Tc,createDeleteSet:()=>xr,createDeleteSetFromStructStore:()=>bc,createDocFromSnapshot:()=>Gw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Mi,createSnapshot:()=>Ai,decodeRelativePosition:()=>$w,decodeSnapshot:()=>Kw,decodeSnapshotV2:()=>eu,decodeStateVector:()=>Mc,decodeUpdate:()=>i1,decodeUpdateV2:()=>lu,diffUpdate:()=>c1,diffUpdateV2:()=>Dc,emptySnapshot:()=>Yw,encodeRelativePosition:()=>Hw,encodeSnapshot:()=>jw,encodeSnapshotV2:()=>Zf,encodeStateAsUpdate:()=>Cc,encodeStateAsUpdateV2:()=>Gf,encodeStateVector:()=>Ec,encodeStateVectorFromUpdate:()=>s1,encodeStateVectorFromUpdateV2:()=>au,equalDeleteSets:()=>Kf,equalSnapshots:()=>Ww,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>B,getTypeChildren:()=>m1,isDeleted:()=>Dt,isParentOf:()=>En,iterateDeletedStructs:()=>it,logType:()=>Lw,logUpdate:()=>r1,logUpdateV2:()=>ou,mergeDeleteSets:()=>Mn,mergeUpdates:()=>cu,mergeUpdatesV2:()=>wi,obfuscateUpdate:()=>a1,obfuscateUpdateV2:()=>h1,parseUpdateMeta:()=>o1,parseUpdateMetaV2:()=>hu,readUpdate:()=>Uw,readUpdateV2:()=>Sc,relativePositionToJSON:()=>zw,snapshot:()=>Ei,snapshotContainsUpdate:()=>Qw,transact:()=>R,tryGc:()=>t1,typeListToArraySnapshot:()=>lo,typeMapGetAllSnapshot:()=>Au,typeMapGetSnapshot:()=>w1});var _=()=>new Map,As=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Vd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Bd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Es=n=>n[n.length-1];var Pd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},nr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var rr=Math.abs;var De=(n,e)=>nn>e?n:e,hS=Number.isNaN,Fd=Math.pow;var Ds=n=>n!==0?n<0:1/n<0;var Vl=Number.MAX_SAFE_INTEGER,dS=Number.MIN_SAFE_INTEGER,fS=1<<31;var qd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),uS=Number.isNaN,pS=Number.parseInt;var Bl=String.fromCharCode,mS=String.fromCodePoint,gS=Bl(65535),P0=n=>n.toLowerCase(),L0=/^\s*/g,z0=n=>n.replace(L0,""),F0=/([A-Z])/g,Pl=(n,e)=>z0(n.replace(F0,t=>`${e}${P0(t)}`));var q0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;isr.encode(n),Jd=sr?H0:q0;var ir=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ir&&ir.decode(new Uint8Array).length===1&&(ir=null);var $d=(n,e)=>zd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var Ns=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Ns(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var ar=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ri=(n,e)=>{let t=Ds(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Ll=new Uint8Array(3e4),$0=Ll.length/3,W0=(n,e)=>{if(e.length<$0){let t=sr.encodeInto(e,Ll).written||0;x(n,t);for(let r=0;r{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;ihr(n,I(e)),hr=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),hr(n,e)},zl=(n,e)=>{J0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},K0=(n,e)=>zl(n,4).setFloat32(0,e,!1),Y0=(n,e)=>zl(n,8).setFloat64(0,e,!1),G0=(n,e)=>zl(n,8).setBigInt64(0,e,!1);var jd=new DataView(new ArrayBuffer(4)),X0=n=>(jd.setFloat32(0,n),jd.getFloat32(0)===n),lr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Ze(n,e);break;case"number":qd(e)&&rr(e)<=2147483647?(Q(n,125),ri(n,e)):X0(e)?(Q(n,124),K0(n,e)):(Q(n,123),Y0(n,e));break;case"bigint":Q(n,122),G0(n,e);break;case"object":if(e===null)Q(n,126);else if(ei(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var Kd=n=>{n.count>0&&(ri(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Kd(this),this.count=1,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}};var Yd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ri(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},cr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Yd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Yd(this),I(this.encoder)}},Os=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Ze(e,this.sarr.join("")),hr(e,this.lensE.toUint8Array()),I(e)}};var et=n=>new Error(n),Oe=()=>{throw et("Method unimplemented")},j=()=>{throw et("Unexpected case")};var Xd=et("Unexpected end of array"),Qd=et("Integer out of Range"),dr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new dr(n),Fl=n=>n.pos!==n.arr.length;var Q0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>Q0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posVl)throw Qd}throw Xd},si=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posVl)throw Qd}throw Xd};var Z0=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},ew=n=>ir.decode(K(n)),Le=ir?ew:Z0;var ql=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},tw=n=>ql(n,4).getFloat32(0,!1),nw=n=>ql(n,8).getFloat64(0,!1),rw=n=>ql(n,8).getBigInt64(0,!1);var iw=[n=>{},n=>null,si,tw,nw,rw,n=>!1,n=>!0,Le,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;riw[127-xn(n)](n),ii=class extends dr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Fl(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends dr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=si(this);let e=Ds(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var ur=class extends dr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=si(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},vs=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var bS=crypto.subtle,Zd=crypto.getRandomValues.bind(crypto);var sw=Math.random,Hl=()=>Zd(new Uint32Array(1))[0];var ef=n=>n[fe(sw()*n.length)],ow="10000000-1000-4000-8000"+-1e11,tf=()=>ow.replace(/[018]/g,n=>(n^Hl()&15>>n/4).toString(16));var Ne=Date.now;var Jl=n=>new Promise(n);var kS=Promise.all.bind(Promise);var $l=n=>n===void 0?null:n;var Wl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},rf=new Wl,jl=!0;try{typeof localStorage<"u"&&localStorage&&(rf=localStorage,jl=!1)}catch{}var Us=rf,sf=n=>jl||addEventListener("storage",n),of=n=>jl||removeEventListener("storage",n);var af=Object.assign,Vs=Object.keys,hf=(n,e)=>{for(let t in n)e(n[t],t)},df=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Kl=n=>Vs(n).length,cf=n=>Vs(n).length;var ff=n=>{for(let e in n)return!1;return!0},aw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Yl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Gl=(n,e)=>n===e||cf(n)===cf(e)&&aw(n,(t,r)=>(t!==void 0||Yl(e,r))&&e[r]===t),hw=Object.freeze,Xl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Xl(n[e])}return hw(n)};var li=(n,e,t=0)=>{try{for(;tn,dw=(n,e)=>n===e;var pr=(n,e)=>{if(n==null||e==null)return dw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var Ct=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",mr=typeof window<"u"&&typeof document<"u"&&!Ct,CS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,tt,fw=[],uw=()=>{if(tt===void 0)if(Ct){tt=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");tt.set(`--${Pl(e,"-")}`,t),tt.set(`-${Pl(e,"-")}`,t)}})):tt=_();return tt},ec=n=>uw().has(n);var ci=n=>Ct?$l(process.env[n.toUpperCase().replaceAll("-","_")]):$l(Us.getItem(n));var pf=n=>ec("--"+n)||ci(n)!==null,MS=pf("production"),pw=Ct&&uf(process.env.FORCE_COLOR,["true","1","2"]),mf=pw||!ec("--no-colors")&&!pf("no-color")&&(!Ct||process.stdout.isTTY)&&(!Ct||ec("--color")||ci("COLORTERM")!==null||(ci("TERM")||"").includes("color"));var gf=n=>new Uint8Array(n),mw=(n,e,t)=>new Uint8Array(n,e,t),yf=n=>new Uint8Array(n),gw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),ww=n=>{let e=atob(n),t=gf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return mw(e.buffer,e.byteOffset,e.byteLength)},wf=mr?gw:yw,bf=mr?ww:bw;var xf=n=>{let e=gf(n.byteLength);return e.set(n),e};var tc=class{constructor(e,t){this.left=e,this.right=t}},nt=(n,e)=>new tc(n,e);var Mt=typeof document<"u"?document:{};var AS=typeof DOMParser<"u"?new DOMParser:null;var kf=n=>Vd(n,(e,t)=>`${t}:${e};`).join("");var ES=Mt.ELEMENT_NODE,TS=Mt.TEXT_NODE,DS=Mt.CDATA_SECTION_NODE,OS=Mt.COMMENT_NODE,NS=Mt.DOCUMENT_NODE,IS=Mt.DOCUMENT_TYPE_NODE,RS=Mt.DOCUMENT_FRAGMENT_NODE;var Ps=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Sw=Ps(clearTimeout),hi=(n,e)=>new Sw(setTimeout(e,n)),_S=Ps(clearInterval);var US=Ps(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var VS=Ps(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var rt=Symbol;var di=rt(),fi=rt(),nc=rt(),rc=rt(),ic=rt(),ui=rt(),sc=rt(),gr=rt(),oc=rt(),Af=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Ef(n)),Tf.forEach(e=>e.print(n))},lc=(...n)=>{console.warn(...Ef(n)),n.unshift(gr),Tf.forEach(e=>e.print(n))};var Tf=Ce();var Df=n=>({[Symbol.iterator](){return this},next:n}),Of=(n,e)=>Df(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zs=(n,e)=>Df(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ac=class extends tr{constructor(e,t){super(),this.doc=e,this.awareness=t}},mi=class{constructor(e,t){this.clock=e,this.len=t}},Wt=class{constructor(){this.clients=new Map}},it=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Nw(t,e.clock)!==null},wc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new Wt;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new mi(t,r))},xr=()=>new Wt,bc=n=>{let e=xr();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},st=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new Wt,t=k(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new Wt,i=k(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),st(s,r),s.toUint8Array()}return null},Kf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Yf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ks,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Jl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Jl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,at)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,ht)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Me=class extends An{readLeftID(){return M(k(this.restDecoder),k(this.restDecoder))}readRightID(){return M(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return fr(this.restDecoder)}readBuf(){return xf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Ws=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends Ws{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new ur(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new ur(K(e)),this.rightClockDecoder=new ur(K(e)),this.infoDecoder=new ii(K(e),xn),this.stringDecoder=new vs(K(e)),this.parentInfoDecoder=new ii(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new At(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new At(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return fr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return fr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ti(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Iw(n,e.clients.get(i),i,s)})},Rw=(n,e)=>{let t=_(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ks,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return xc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},_w=(n,e)=>xc(n,e.doc.store,e.beforeState),Sc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Rw(r,o),a=vw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=wi([h.update,a.update])}}else l.pendingStructs=a;let d=Rf(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=Rf(f,i,l);d&&u?l.pendingDs=wi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Uw=(n,e,t)=>Sc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Sc(i,n,t,new r(i))},kc=(n,e,t)=>vn(n,e,t,Me),Vw=(n,e,t=new Map)=>{xc(n,e.store,t),st(n,bc(e.store))},Gf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Mc(e);Vw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Dc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===ot)return cu(i.map((s,o)=>o===0?s:uu(s)));if(t.constructor===Ie)return wi(i)}return i[0]},Cc=(n,e)=>Gf(n,e,new ot),Xf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rXf(new An(q(n))),Ac=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Bw=(n,e)=>Ac(n,Ti(e.store)),Pw=(n,e=new yr)=>(n instanceof Map?Ac(e,n):Bw(e,n),e.toUint8Array()),Ec=n=>Pw(n,new jt),hc=class{constructor(){this.l=[]}},vf=()=>new hc,_f=(n,e)=>n.l.push(e),Uf=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Qf=(n,e,t)=>li(n.l,[e,t]),At=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new At(n,e),Vf=(n,e)=>{x(n,e.client),x(n,e.clock)},Bf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Lw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},dc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||xr(),Et(new An(q(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>Et(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new jt,h=this.dss.get(r);h&&(st(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new jt;st(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Dt(r,e))return t;return null}},lt=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},zw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new lt(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),js=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Fw=(n,e,t=0)=>new js(n,e,t),Fs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new lt(r,i,e,t)},Mi=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fs(n,r.lastId,t);r=r.right}return Fs(n,null,t)},qw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Vf(n,i);else if(r!==null)ar(n,1),Ze(n,r);else if(t!==null)ar(n,2),Vf(n,t);else throw j();return ri(n,s),n},Hw=n=>{let e=F();return qw(e,n),I(e)},Jw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Bf(n);break;case 1:t=Le(n);break;case 2:e=Bf(n)}let i=Fl(n)?si(n):0;return new lt(e,t,r,i)},$w=n=>Jw(q(n)),Tc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?gc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?gc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return Fw(c,a,n.assoc)},ro=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,Kt=class{constructor(e,t){this.ds=e,this.sv=t}},Ww=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(st(e,n.ds),Ac(e,n.sv),e.toUint8Array()),jw=n=>Zf(n,new jt),eu=(n,e=new Ws(q(n)))=>new Kt(Et(e),Xf(e)),Kw=n=>eu(n,new An(q(n))),Ai=(n,e)=>new Kt(n,e),Yw=Ai(xr(),new Map),Ei=n=>Ai(bc(n.store),Ti(n.store)),Ht=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Dt(e.ds,n.id),fc=(n,e)=>{let t=$(n.meta,fc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Gw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new ct(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Xw(n,e,Me),Ks=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ti=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},tu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=Zw,uc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[uc(n,t,e.clock)]},Pf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,no(n,s,t.clock-s.id.clock+1)),s},e1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},nu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=uc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Bd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(wc(e.deleteSet),_w(n,e),st(n,e.deleteSet),!0),zf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},Js=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},ru=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+Js(i,c)}})},t1=(n,e,t)=>{ru(n,e,t),iu(n,e)},su=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Qf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),li(l,[]),t._needFormattingCleanup&&k1(t)}finally{r.gc&&ru(s,i,r.gcFilter),iu(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Js(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Js(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Ls(gr,di,"[yjs] ",fi,ui,"Changed the client-id because another client seems to be using it."),r.clientID=Yf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new ot;Lf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Lf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):su(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ys(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&su(i,0)}}return o},pc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Ff=(n,e,t)=>{it(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&vc(r,!1)})},qf=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;it(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=gc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),it(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Dt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Ru(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends tr{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=ei(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new Wt;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&gi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new pc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),it(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&vc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=ei(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&lc("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>Ff(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Ff(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=qf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=qf(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*n1(n){let e=k(n.restDecoder);for(let t=0;tou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(q(n)),i=new ct(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Ls("Structs: ",t);let s=Et(r);Ls("DeleteSet: ",s)},i1=n=>lu(n,Me),lu=(n,e=be)=>{let t=[],r=new e(q(n)),i=new ct(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:Et(r)}},yi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},cu=n=>wi(n,Me,ot),au=(n,e=yr,t=be)=>{let r=new e,i=new ct(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,o),Gd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},s1=n=>au(n,jt,Me),hu=(n,e=be)=>{let t=new Map,r=new Map,i=new ct(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},o1=n=>hu(n,Me),l1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},wi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new ct(h,!0)),s=null,o=new t,l=new yi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Jt(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=l1(f,p)),s.struct.mergeWith(f)||(Jt(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Jt(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Jt(l,s.struct,s.offset),s=null),Oc(l);let c=r.map(h=>Et(h)),a=Mn(c);return st(o,a),o.toUint8Array()},Dc=(n,e,t=be,r=Ie)=>{let i=Mc(e),s=new r,o=new yi(s),l=new t(q(n)),c=new ct(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Jt(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Jt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Oc(o);let a=Et(l);return st(s,a),s.toUint8Array()},c1=(n,e)=>Dc(n,e,Me,ot),du=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=F(),n.written=0)},Jt=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&du(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Oc=n=>{du(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new ct(i,!1),o=new r,l=new yi(o);for(let a=s.curr;a!==null;a=s.next())Jt(l,e(a),0);Oc(l);let c=Et(i);return st(o,c),o.toUint8Array()},fu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case br:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof ki&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Yt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Tt:{let d=h;d.embed={};break}case P:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case Ci:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=$d(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},a1=(n,e)=>io(n,fu(e),Me,ot),h1=(n,e)=>io(n,fu(e),be,Ie),d1=n=>io(n,Ql,Me,Ie),uu=n=>io(n,Ql,be,ot),Hf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=f1(this.currentTarget,this.target))}deletes(e){return Dt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw et(Hf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Es(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Es(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Es(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw et(Hf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},f1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{lc("Invalid access: Add Yjs type to a document before reading data.")},pu=80,Nc=0,mc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Nc++}},u1=n=>{n.timestamp=Nc++},mu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Nc++},p1=(n,e,t)=>{if(n.length>=pu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>rr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&rr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},m1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},oo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Qf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=vf(),this._dEH=vf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){_f(this._eH,e)}observeDeep(e){_f(this._dEH,e)}unobserve(e){Uf(this._eH,e)}unobserveDeep(e){Uf(this._dEH,e)}toJSON(){}},gu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},yu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&Ht(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return xi(n,(r,i)=>{t.push(e(r,i,n))}),t},g1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},bu=(n,e)=>{n.doc??se();let t=so(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Yt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},xu=()=>et("Length exceeded!"),Su=(n,e,t,r)=>{if(t>e._length)throw xu();if(t===0)return e._searchMarker&&bi(e._searchMarker,t,r.length),Gs(n,e,null,r);let i=t,s=so(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Gs(n,e,i,t)},ku=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=so(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw xu();e._searchMarker&&bi(e._searchMarker,i,-s+r)},Xs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ic=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Yt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Yt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Rc=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Cu=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Mu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},w1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&Ht(r,t)?r.content.getContent()[r.length-1]:void 0},Au=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&Ht(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},qs=n=>(n.doc??se(),Of(n._map.entries(),e=>!e[1].deleted)),Qs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),oo(this,e,new Qs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{y1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return bu(this,e)}toArray(){return yu(this)}slice(e=0,t=this.length){return gu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return wu(this,e)}forEach(e){xi(this,e)}[Symbol.iterator](){return g1(this)}_write(e){e.writeTypeRef(L1)}},b1=n=>new On,Zs=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){oo(this,e,new Zs(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...qs(this)].length}keys(){return zs(qs(this),e=>e[0])}values(){return zs(qs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zs(qs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Rc(this,e)}has(e){return Mu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(z1)}},x1=n=>new Nn,$t=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Gl(n,e),Si=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case P:this.right.deleted||Sr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Jf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||Sr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?so(e,t):null;if(s){let o=new Si(s.p.left,s.p,s.index,i);return Jf(n,o,t-s.index)}else{let o=new Si(null,e._start,0,i);return Jf(n,o,t)}},Eu=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&$t(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},Sr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Tu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&$t(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Du=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!$t(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},cc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Tt(r),{left:a,right:h,index:d}=t;e._searchMarker&&bi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Eu(n,e,t,l)},$f=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if($t(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` +`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Eu(n,e,t,l)},Ou=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&Sr(i,a);break}}}e=e.right}return l},S1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Nu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=As(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:Sr(o,i.content);break;default:e+=Ou(t,r,i,s,o),s=As(o),r=i;break}i=i.right}}),e},k1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&nu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{it(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):S1(r,i)});for(let i of e)Nu(i)})},Wf=(n,e,t)=>{let r=t,i=As(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Tt:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},ff(c)||(u.attributes=af({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Tt:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;$t(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),$t(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;$t(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&($t(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),Sr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},at=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new eo(this,e,t);oo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new Si(null,this._start,0,new Map);for(let s=0;s0)&&cc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?$f(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wf(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(Ht(c,e)||t!==void 0&&Ht(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!Ht(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!Ht(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Tt:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case P:Ht(c,e)&&(a(),Sr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&fc(d,e),t&&fc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),cc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);cc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{Wf(i,Hs(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!1);o.right!==null&&$f(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Rc(this,e)}getAttributes(){return Cu(this)}_write(e){e.writeTypeRef(F1)}},C1=n=>new at,pi=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===ht)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ht=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new pi(this,e)}querySelector(e){e=e.toUpperCase();let r=new pi(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new pi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){oo(this,e,new to(this,t,e))}toString(){return wu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),xi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Gs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw et("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return yu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return bu(this,e)}slice(e=0,t=this.length){return gu(this,e,t)}forEach(e){xi(this,e)}_write(e){e.writeTypeRef(H1)}},M1=n=>new ht,Z=class n extends ht{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return hf(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Rc(this,e)}hasAttribute(e){return Mu(this,e)}getAttributes(e){return e?Au(this,e):Cu(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return xi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(q1),e.writeKey(this.nodeName)}},A1=n=>new Z(n.readKey()),to=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},ki=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(J1),e.writeKey(this.hookName)}},E1=n=>new ki(n.readKey()),xe=class n extends at{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef($1)}},T1=n=>new xe,wr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},D1=0,ue=class extends wr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),tu(e.doc.store,this)}write(e,t){e.writeInfo(D1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},O1=n=>new In(n.readBuf()),br=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){gi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},N1=n=>new br(n.readLen()),Iu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Iu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},I1=n=>new Rn(Iu(n.readString(),n.readAny())),Tt=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},R1=n=>new Tt(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},v1=n=>new P(n.readKey(),n.readJSON()),Ci=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},B1=n=>new Re(n.readString()),P1=[b1,x1,C1,A1,M1,E1,T1],L1=0,z1=1,F1=2,q1=3,H1=4,J1=5,$1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},W1=n=>new Ae(P1[n.readTypeRef()](n)),gc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},vc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},no=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},jf=(n,e)=>Ld(n,t=>Dt(t.deletions,e)),Ru=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Ru(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Dt(r,d.right.id)||jf(s.undoStack,d.right.id)||jf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,vc(g,!0),g.integrate(n,0),g},O=class n extends wr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===At&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Pf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===At){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Pf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),gi(e.deleteSet,this.id.client,this.id.clock,this.length),zf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?e1(e,this,new ue(this.id,this.length)):this.content=new br(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===At?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},vu=(n,e)=>j1[e&31](n),j1=[()=>{j()},N1,_1,O1,B1,R1,v1,W1,V1,I1,()=>{j()}],K1=10,ie=class extends wr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(K1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},_u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Uu="__ $YJS$ __";_u[Uu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");_u[Uu]=!0;var Vu=new Map,_c=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:bf(t.newValue||"")}),sf(this._onChange)}postMessage(e){Us.setItem(this.room,wf(yf(e)))}close(){of(this._onChange)}},Y1=typeof BroadcastChannel>"u"?_c:BroadcastChannel,Uc=n=>$(Vu,n,()=>{let e=Ce(),t=new Y1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Bu=(n,e)=>(Uc(n).subs.add(e),e),Pu=(n,e)=>{let t=Uc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Vu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Uc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Lu=0,co=1,zu=2,ao=(n,e)=>{x(n,Lu);let t=Ec(e);U(n,t)},Vc=(n,e,t)=>{x(n,co),U(n,Cc(e,t))},X1=(n,e,t)=>Vc(e,t,K(n)),Fu=(n,e,t)=>{try{kc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},qu=(n,e)=>{x(n,zu),U(n,e)},Q1=Fu,Hu=(n,e,t,r)=>{let i=k(n);switch(i){case Lu:X1(n,e,t);break;case co:Fu(n,t,r);break;case zu:Q1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var eb=0;var Ju=(n,e,t)=>{switch(k(n)){case eb:t(e,Le(n))}};var Bc=3e4,ho=class extends nr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Bc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Bc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&fo(this,r,"timeout")},fe(Bc/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),pr(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},Cr=(n,e,t=n.states)=>{let r=e.length,i=F();x(i,r);for(let s=0;s{let r=q(e),i=Ne(),s=[],o=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var Wu=n=>df(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Ku=3,Mr=1,ib=2,Di=[];Di[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=Hu(e,n,t.doc,t);r&&s===co&&!t.synced&&(t.synced=!0)};Di[Ku]=(n,e,t,r,i)=>{x(n,Mr),U(n,Cr(t.awareness,Array.from(t.awareness.getStates().keys())))};Di[Mr]=(n,e,t,r,i)=>{$u(t.awareness,K(e),t)};Di[ib]=(n,e,t,r,i)=>{Ju(e,t.doc,(s,o)=>sb(t,o))};var ju=3e4,sb=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Yu=(n,e,t)=>{let r=q(e),i=F(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Gu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Yu(n,new Uint8Array(t.data),!0);Ns(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,fo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Gu,De(Fd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=F();if(x(t,Bn),ao(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Mr),U(r,Cr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Pc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Lc=class extends nr{constructor(e,t,r,{connect:i=!0,awareness:s=new ho(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Di.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=F();x(f,Bn),ao(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Yu(this,new Uint8Array(f),!1);Ns(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),qu(p,f),Pc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=F();x(y,Mr),U(y,Cr(s,g)),Pc(this,I(y))},this._exitHandler=()=>{fo(this.awareness,[r.clientID],"app closed")},Ct&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&ju{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var ob=/[\uD800-\uDBFF]/,lb=/[\uDC00-\uDFFF]/,cb=(n,e)=>{let t=0,r=0;for(;t0&&ob.test(n[t-1])&&t--;r+t0&&lb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Qu=cb;var v=new le("y-sync"),Ot=new le("y-undo"),Oi=new le("yjs-cursor");var Ii=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Dt(e.ds,n.id),ab=[{light:"#ecd44433",dark:"#ecd444"}],hb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,ef(e))}return n.get(t)},tp=(n,{colors:e=ab,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new uo(n,s),c=new H({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&hi(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Ot.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},db=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Gt(t.doc,t.type,e.anchor,t.mapping),i=Gt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ri=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),uo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Xu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ri(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(mr&&this._domSelectionInView===null&&(hi(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Mt.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Ai(xr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Ni(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Ni(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ei(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ei(i),vn(i,e),e=Ei(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{it(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:hb(r.colorMapping,r.colors,f)}},c=lo(this.type,new Kt(t.ds,e.sv)).map(h=>!h._item.deleted||Ii(h._item,e)||Ii(h._item,t)?Ni(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);it(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>np(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));db(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Ar(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ri(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},np=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Ni(n,e,t,r,i,s);throw Oe()}return o},Ni=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=np(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof at&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=fb(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):lo(n,new Kt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ii(n._item,r)?Ii(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},fb=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},ub=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:ip(i.marks)}));return t.applyDelta(r),e.set(t,n),t},pb=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,mo(n).map(r=>zc(r,e))),e.set(t,n),t},zc=(n,e)=>n instanceof Array?ub(n,e):pb(n,e),Zu=n=>typeof n=="object"&&n!==null,qc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Vs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>qc(r.attributes[s.type.name]||{},s.attrs)))},vi=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Fc(n,e)){let t=mo(e);return n._length===t.length&&qc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>vi(r,t[i]))}return n instanceof xe&&e instanceof Array&&rp(n,e)},po=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),ep=(n,e,t)=>{let r=n.toArray(),i=mo(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},gb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=mb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,ip(a.marks))})),{insert:o,remove:l,index:c}=Qu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},ip=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Ar=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=mo(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)rp(f,u)||gb(f,u,r),a+=1;else{let g=f instanceof Z&&Fc(f,u),y=p instanceof Z&&Fc(p,m);if(g&&y){let E=ep(f,u,r),N=ep(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var _i=null,yb=()=>{let n=_i;_i=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Hc=(n,e,t)=>{_i||(_i=new Map,hi(0,yb)),$(_i,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Mi(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Mi(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new lt(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new lt(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return wb(r._item.parent,r._item)}return Mi(e,e._length,-1)},wb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new lt(t,r,e.id)},Gt=(n,e,t,r)=>{let i=Tc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Ar(r,t,n,new Map),t}function op(n,e="prosemirror"){return $c(n.getXmlFragment(e))}function $c(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var bb=(n,e,t)=>n!==e,xb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},Sb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),kb=/^#[0-9a-fA-F]{6}$/,lp=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?L.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":kb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Gt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Gt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(n.doc,l))},Cb=(n,{awarenessStateFilter:e=bb,cursorBuilder:t=xb,selectionBuilder:r=Sb,getSelection:i=o=>o.selection}={},s="cursor")=>new H({key:Oi,state:{init(o,l){return lp(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Oi);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?lp(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Oi.getState(o)},view:o=>{let l=()=>{o.docView&&Hc(o,Oi,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!ro(Un(h.cursor.anchor),f)||!ro(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Gt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Mb=n=>{let e=Ot.getState(n).undoManager;if(e!=null)return e.undo(),!0},Ab=n=>{let e=Ot.getState(n).undoManager;if(e!=null)return e.redo(),!0},Eb=new Set(["paragraph"]),Tb=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof at||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Db=({protectedNodes:n=Eb,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Ot,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Tb(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ri(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Ot.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Ot.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var Ui="http://www.w3.org/2000/svg",Ob="http://www.w3.org/1999/xlink",jc="ProseMirror-icon",Wc="pm-close-dropdowns";function Nb(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,cp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;cp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function go(n,e){return n._props.translate?n._props.translate(e):e}var Vi={time:0,node:null};function vb(n){Vi.time=Date.now(),Vi.node=n.target}function _b(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Wc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),vb(d),o?a():(r.dispatchEvent(new CustomEvent(Wc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{_b(s)||a()}),r.addEventListener(Wc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=xt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function Ub(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;ijr(n),icon:Bi.join}),Bk=new dt({title:"Lift out of enclosing block",run:Kr,select:n=>Kr(n),icon:Bi.lift}),Pk=new dt({title:"Select parent node",run:Yr,select:n=>Yr(n),icon:Bi.selectParentNode}),Lk=new dt({title:"Undo last change",run:Qr,enable:n=>Qr(n),icon:Bi.undo}),zk=new dt({title:"Redo last undone change",run:Zn,enable:n=>Zn(n),icon:Bi.redo});function Pb(n,e){let t={run(r,i){return Qn(n,e.attrs)(r,i)},select(r){return Qn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new dt(t)}function Lb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new dt(r)}function cp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,Rt as DOMSerializer,Kc as Dropdown,Bo as EditorState,ol as EditorView,w as Fragment,Qe as InputRule,dt as MenuItem,H as Plugin,le as PluginKey,Or as Schema,b as Slice,A as TextSelection,Lc as WebsocketProvider,kr as Y,t0 as addColumnAfter,e0 as addColumnBefore,hy as addListNodes,o0 as addRowAfter,s0 as addRowBefore,ld as baseKeymap,Lg as baseSchema,Lb as blockTypeItem,By as buildKeymap,E0 as columnResizing,r0 as deleteColumn,c0 as deleteRow,g0 as deleteTable,Id as fixTables,Dy as gapCursor,m0 as goToNextCell,ud as inputRules,He as isInTable,by as keymap,bl as liftListItem,h0 as mergeCells,sp as prosemirrorToYDoc,Jc as prosemirrorToYXmlFragment,Vb as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,d0 as splitCell,wl as splitListItem,B0 as tableEditing,qy as tableNodes,mn as toggleMark,Qn as wrapIn,us as wrapInList,Pb as wrapItem,md as wrappingInputRule,Cb as yCursorPlugin,op as yDocToProsemirrorJSON,Ab as yRedo,tp as ySyncPlugin,Mb as yUndo,Db as yUndoPlugin,Ot as yUndoPluginKey,$c as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index e50cf962..076ae9df 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -46,7 +46,7 @@ import { import { MenuItem, Dropdown, renderGrouped, blockTypeItem, wrapItem } from '../../prosemirror-menu/dist/index.js'; -import { InputRule, inputRules } from 'prosemirror-inputrules'; +import { InputRule, inputRules, wrappingInputRule } from 'prosemirror-inputrules'; // All exported export { @@ -96,6 +96,7 @@ export { sinkListItem, InputRule, inputRules, + wrappingInputRule, Y, WebsocketProvider, ySyncPlugin, From fdb8264da6d39fa71b5d06823d34a926719e73a2 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 10:36:40 -0800 Subject: [PATCH 2/3] fix: lint --- blocks/start/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/start/index.js b/blocks/start/index.js index 30573f81..cabd3ee2 100644 --- a/blocks/start/index.js +++ b/blocks/start/index.js @@ -1,6 +1,6 @@ import { getNx } from '../../scripts/utils.js'; import { DA_ORIGIN } from '../shared/constants.js'; -import { daFetch, aemAdmin } from '../shared/utils.js'; +import { daFetch } from '../shared/utils.js'; const { crawl } = await import(`${getNx()}/public/utils/tree.js`); From 0cc7c370ea7b6e76d5b4e90ad30f607143ff3cc2 Mon Sep 17 00:00:00 2001 From: Cursor AI Date: Thu, 13 Nov 2025 13:14:53 -0800 Subject: [PATCH 3/3] updated from PR feedback --- blocks/edit/prose/plugins/keyHandlers.js | 35 ++++-------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/blocks/edit/prose/plugins/keyHandlers.js b/blocks/edit/prose/plugins/keyHandlers.js index 391b25b3..d66f2962 100644 --- a/blocks/edit/prose/plugins/keyHandlers.js +++ b/blocks/edit/prose/plugins/keyHandlers.js @@ -48,34 +48,6 @@ export function getURLInputRule() { ); } -/** - * Converts "* " or "- " at the start of a line into a bullet list. - * - * @param {Schema} schema - The ProseMirror schema - * @returns {InputRule|null} the bullet list input rule, or null if - * bullet_list node doesn't exist - */ -export function getBulletListInputRule(schema) { - const { bullet_list: bulletList } = schema.nodes; - if (!bulletList) return null; - - return wrappingInputRule(/^\s*([-*])\s$/, bulletList); -} - -/** - * converts "1. " or "1) " at the start of a line into an ordered list. - * - * @param {Schema} schema - The ProseMirror schema - * @returns {InputRule|null} the ordered list input rule, or null if - * the ordered_list node doesn't exist - */ -export function getOrderedListInputRule(schema) { - const { ordered_list: orderedList } = schema.nodes; - if (!orderedList) return null; - - return wrappingInputRule(/^\s*1[.)]\s$/, orderedList); -} - export function getDashesInputRule(dispatchTransaction) { return new InputRule( /^---[\n]$/, @@ -111,9 +83,12 @@ export function getURLInputRulesPlugin() { return inputRules({ rules: [getURLInputRule()] }); } -// Returns an inputRules plugin for list formatting (bullet and ordered lists) +// Returns an inputRules plugin for auto-creating bullet and ordered lists export function getListInputRulesPlugin(schema) { - const rules = [getBulletListInputRule(schema), getOrderedListInputRule(schema)].filter(Boolean); + const rules = [ + wrappingInputRule(/^\s*1[.)]\s$/, schema.nodes.ordered_list), + wrappingInputRule(/^\s*([-*])\s$/, schema.nodes.bullet_list), + ]; return inputRules({ rules }); }