diff --git a/Database/pb_migrations/1763300000_push_devices.js b/Database/pb_migrations/1763300000_push_devices.js
new file mode 100644
index 0000000..4eff4d9
--- /dev/null
+++ b/Database/pb_migrations/1763300000_push_devices.js
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+///
+
+// push_devices: phones that get push notifications. endpoint is the
+// UnifiedPush address the phone's distributor (ntfy, …) gave the app;
+// docwell-server POSTs each notification there, encrypted to the app's
+// Web Push keys (RFC 8291). A device whose endpoint
+// answers 404 or 410 is deleted.
+
+migrate(
+ (app) => {
+ const users = app.findCollectionByNameOrId("users");
+ app.save(
+ new Collection({
+ type: "base",
+ name: "push_devices",
+ fields: [
+ { name: "user", type: "relation", collectionId: users.id, maxSelect: 1, required: true, cascadeDelete: true },
+ { name: "endpoint", type: "text", required: true, max: 1000 },
+ // The app's Web Push keys (base64url): messages are encrypted to them.
+ { name: "p256dh", type: "text", required: true, max: 200 },
+ { name: "auth", type: "text", required: true, max: 100 },
+ { name: "name", type: "text", max: 100 },
+ { name: "created", type: "autodate", onCreate: true, onUpdate: false },
+ { name: "updated", type: "autodate", onCreate: true, onUpdate: true },
+ ],
+ indexes: [
+ "CREATE UNIQUE INDEX idx_push_devices_endpoint ON push_devices (endpoint)",
+ "CREATE INDEX idx_push_devices_user ON push_devices (user)",
+ ],
+ }),
+ );
+ },
+ (app) => {
+ app.delete(app.findCollectionByNameOrId("push_devices"));
+ },
+);
diff --git a/Packages/api-client/src/schema.d.ts b/Packages/api-client/src/schema.d.ts
index 09904c6..1be208f 100644
--- a/Packages/api-client/src/schema.d.ts
+++ b/Packages/api-client/src/schema.d.ts
@@ -331,6 +331,46 @@ export interface paths {
patch?: never;
trace?: never;
};
+ "/api/v1/me/devices": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ /** The caller's phones registered for push notifications, newest first */
+ get: operations["listDevices"];
+ put?: never;
+ /**
+ * Register a phone for push notifications (UnifiedPush)
+ * @description endpoint is the address the phone's UnifiedPush distributor (ntfy, NextPush, …) gave the app. For each notification docwell-server POSTs a PushMessage there, encrypted to the app's Web Push keys (RFC 8291, aes128gcm). Registering the same endpoint again updates it. Endpoints that answer 404 or 410 are forgotten. A person keeps up to 10 phones; registering an 11th drops the oldest.
+ */
+ post: operations["registerDevice"];
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
+ "/api/v1/me/devices/{id}": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ id: string;
+ };
+ cookie?: never;
+ };
+ get?: never;
+ put?: never;
+ post?: never;
+ /** Stop push notifications to one of the caller's phones */
+ delete: operations["removeDevice"];
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
"/api/v1/auth/me": {
parameters: {
query?: never;
@@ -2380,6 +2420,20 @@ export interface components {
icon: string;
deletedAt: string;
};
+ PushDevice: {
+ id: string;
+ name: string;
+ created: string;
+ };
+ /** @description The JSON body docwell-server POSTs to a phone's push endpoint */
+ PushMessage: {
+ /** @description The page's icon and title */
+ title: string;
+ /** @description For example "Ann mentioned you: …" */
+ body: string;
+ /** @description The app route to open, for example /p/?comment= */
+ route: string;
+ };
ArchivedPage: {
id: string;
title: string;
@@ -3322,6 +3376,82 @@ export interface operations {
403: components["responses"]["Error"];
};
};
+ listDevices: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description OK */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["PushDevice"][];
+ };
+ };
+ 404: components["responses"]["Error"];
+ };
+ };
+ registerDevice: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": {
+ endpoint: string;
+ /** @description The app's P-256 public key */
+ p256dh: string;
+ /** @description The app's 16-byte auth secret */
+ auth: string;
+ /** @description e.g. the phone's model */
+ name?: string;
+ };
+ };
+ };
+ responses: {
+ /** @description Registered */
+ 201: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["PushDevice"];
+ };
+ };
+ 400: components["responses"]["Error"];
+ 404: components["responses"]["Error"];
+ };
+ };
+ removeDevice: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path: {
+ id: string;
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Removed */
+ 204: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content?: never;
+ };
+ 404: components["responses"]["Error"];
+ };
+ };
getMe: {
parameters: {
query?: never;
diff --git a/Packages/editor-bridge/dist/index.html b/Packages/editor-bridge/dist/index.html
index e6628cc..f2653a5 100644
--- a/Packages/editor-bridge/dist/index.html
+++ b/Packages/editor-bridge/dist/index.html
@@ -14,21 +14,23 @@
`),u&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){n.nodeName==`BR`&&(o=s={node:n.parentNode,offset:Fr(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];u=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}if(ci&&l.focusNode&&l.focusNode!=s.node&&O(l.focusNode)){let e=l.focusNode.childNodes[l.focusOffset];e&&e.contentEditable==`false`&&(r=!0)}if(!(r||u&&fi)&&Br(o.node,o.offset,l.anchorNode,l.anchorOffset)&&Br(s.node,s.offset,l.focusNode,l.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(u&&ci)){c.collapse(o.node,o.offset);try{e!=t&&c.extend(s.node,s.offset),d=!0}catch{}}if(!d){if(e>t){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}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 n=0,r=0;r=n:en){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?$i:Qi,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=ea:i.markDirty(e-r,t-r);return}i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?$i:ea}n=a}this.dirty=$i}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?$i:Qi;t.dirty{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){let e=O(a)?a:document.createElement(`span`);e!=a&&(e.appendChild(a),a=e),e.hasAttribute(`contenteditable`)||(e.contentEditable=`false`),e.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==Zi&&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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},ra=class extends ta{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},ia=class e extends ta{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return o&&o.dom||(o=Qe.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ea||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ea&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Zi){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(a=Ta(a,0,t,r));for(let e=0;e{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(!Wr(u))throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=Qe.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=ga(u,r,n),l?c=new la(t,n,r,i,u,d||null,f,l):n.isText?new sa(t,n,r,i,u,f):new e(t,n,r,i,u,d||null,f)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(t.preserveWhitespace=`full`),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(t=>O(t)&&e.indexOf(t.parentNode)<0&&this.dom.contains(t));n?t.contentElement=n:t.getContent=()=>s.empty}}return t}matchesNode(e,t,n){return this.dirty==Zi&&e.eq(this.node)&&_a(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new ya(this,a&&a.node,e),c=this.node.inlineContent,l=c&&this.node.isBlock;Sa(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?d.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,u,d)=>{s.syncToMarks(t.marks,n,e,d),l&&t.isAtom&&!t.isText&&s.addHackNode(`IMG`,s.top);let f;s.findNodeMatch(t,a,u,d)||o&&e.state.selection.from>r&&e.state.selection.to-1&&s.updateNodeAt(t,a,u,f,e)||s.updateNextNode(t,a,u,e,d,r)||s.addNode(t,a,u,e,r),r+=t.nodeSize,c&&(l=t.isAtom&&!t.isText)}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==$i)&&(a&&this.protectLocalComposition(e,a),ua(this.contentDOM,this.children,e),pi&&Ca(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof w)||nt+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=wa(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let a=new ra(this,i,t,r);e.input.compositionNodes.push(a),this.children=Ta(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==ea||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Zi}updateOuterDeco(e){if(_a(e,this.outerDeco))return;let t=!O(this.nodeDOM),n=this.dom;this.dom=ma(this.dom,this.nodeDOM,pa(this.outerDeco,this.node,t),pa(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){O(this.nodeDOM)&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){O(this.nodeDOM)&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function oa(e,t,n,r,i){ga(r,t,e);let a=new aa(void 0,e,t,n,r,r,r);return a.contentDOM&&a.updateChildren(i,0),a}var sa=class e extends aa{constructor(e,t,n,r,i,a){super(e,t,n,r,i,null,a)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==ea||this.dirty!=Zi&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Zi||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Zi,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ea)}get domAtom(){return!1}isText(e){return this.node.text==e}},ca=class extends ta{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Zi&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},la=class extends aa{constructor(e,t,n,r,i,a,o,s){super(e,t,n,r,i,a,o),this.spec=s}update(e,t,n,r){if(this.dirty==ea)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}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 ua(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a>1,o=Math.min(a,e.length);for(;i-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=ia.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof ia)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function xa(e,t){return e.type.side-t.type.side}function Sa(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;na;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function Ca(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function wa(e,t,n,r){for(let i=0,a=0;i=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function Ta(e,t,n,r,i){let a=[];for(let o=0,s=0;o=n||u<=t?a.push(c):(ln&&a.push(c.slice(n-l,c.size,r)))}return a}function Ea(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(Xr(n)){for(c=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&T.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&Jr(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new T(o==e?s:r.resolve(e))}else if(ci&&t==`key`&&o>e.state.selection.to&&O(n.focusNode)&&n.focusOffset==n.focusNode.childNodes.length&&i&&i.posAtStart>e.state.selection.to)for(let e=n.focusNode;;e=e.parentNode){if(getComputedStyle(e).overflow!=`visible`){l=C.findFrom(r.resolve(i.posAtStart),1);break}if(e==i.dom||e.nextSibling||!e.parentNode||!O(e.parentNode))break}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!Da(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Pa(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Fr(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oi&&si<=11&&(n.disabled=!0,n.disabled=!1)}function Fa(e,t){if(t instanceof T){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Ia(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Ia(e)}function Ia(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function La(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||w.between(t,n,r)}function Ra(e){return e.editable&&!e.hasFocus()?!1:za(e)}function za(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return Gr(e.dom,t.anchorNode)&&(e.editable||Gr(e.dom,t.focusNode))}catch{return!1}}function Ba(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return Br(t.node,t.offset,n.anchorNode,n.anchorOffset)}function Va(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&C.findFrom(a,t)}function Ha(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ua(e,t,n){let r=e.state.selection;if(r instanceof w){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return Ha(e,new w(r.$anchor,a))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=Va(e.state,t);return n&&n instanceof T?Ha(e,n):!1}if(!mi||n.indexOf(`m`)<0){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?T.isSelectable(i)?Ha(e,new T(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):Ha(e,new w(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1}}else if(r instanceof T&&r.node.isInline)return Ha(e,new w(t>0?r.$to:r.$from));else{let n=Va(e.state,t);return n?Ha(e,n):!1}}function Wa(e,t){let n=e.pmViewDesc;return n?n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`):O(e)&&e.contentEditable==`false`}function Ga(e,t){return t<0?Ka(e):qa(e)}function Ka(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(ci&&O(n)&&r0){if(!O(n))break;let e=n.childNodes[r-1];if(Wa(e,-1))i=n,a=--r;else if(Wr(e))n=e,r=n.nodeValue.length;else break}else if(Ja(n))break;else{let t=n.previousSibling;for(;t&&Wa(t,-1);)i=n.parentNode,a=Fr(t),t=t.previousSibling;if(t)n=t,r=Ur(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?Za(e,n,r):i&&Za(e,i,a)}function qa(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=Ur(n),a,o;for(;;)if(r{e.state==a&&Oa(e)},50)}function Qa(e,t){let n=e.state.doc.resolve(t);if(!(ui||hi)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i1)return n.leftr.top&&i1)return n.left>r.left?`ltr`:`rtl`}}let r=e.dom;for(let t=n.depth;t>0;t--)if(n.node(t).isBlock){r=e.nodeDOM(n.before(t))||r;break}return getComputedStyle(r).direction==`rtl`?`rtl`:`ltr`}function $a(e,t,n){let r=e.state.selection;if(r instanceof w&&!r.empty||n.indexOf(`s`)>-1||mi&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=Va(e.state,t);if(n&&n instanceof T)return Ha(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof On?C.near(n,t):C.findFrom(n,t);return o?Ha(e,o):!1}return!1}function eo(e,t){if(!(e.state.selection instanceof w))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function to(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function no(e){if(!fi||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&O(t)&&n==0&&t.firstChild&&O(t.firstChild)&&t.firstChild.contentEditable==`false`){let n=t.firstChild;to(e,n,`true`),setTimeout(()=>to(e,n,`false`),20)}return!1}function ro(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function io(e,t){let n=t.keyCode,r=ro(t);if(n==8||mi&&n==72&&r==`c`)return eo(e,-1)||Ga(e,-1);if(n==46&&!t.shiftKey||mi&&n==68&&r==`c`)return eo(e,1)||Ga(e,1);if(n==13||n==27)return!0;if(n==37||mi&&n==66&&r==`c`){let t=n==37?Qa(e,e.state.selection.from)==`ltr`?-1:1:-1;return Ua(e,t,r)||Ga(e,t)}if(n==39||mi&&n==70&&r==`c`){let t=n==39?Qa(e,e.state.selection.from)==`ltr`?1:-1:1;return Ua(e,t,r)||Ga(e,t)}return n==38||mi&&n==80&&r==`c`?$a(e,-1,r)||Ga(e,-1):n==40||mi&&n==78&&r==`c`?no(e)||$a(e,1,r)||Ga(e,1):!(r!=(mi?`m`:`c`)||n!=66&&n!=73&&n!=89&&n!=90)}function ao(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||Qe.fromSchema(e.state.schema),s=go(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&O(l)&&(u=ho[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&O(l)&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
`),slice:t}}function oo(e,t,n,r,i){let a=i.parent.type.spec.code,o,c;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return c=new p(s.from(e.state.schema.text(t.replace(/\r\n?/g,`
-`))),0,0),e.someProp(`transformPasted`,t=>{c=t(c,e,!0)}),c;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)c=n;else{let n=i.marks(),{schema:r}=e.state,a=Qe.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=yo(n),_i&&bo(o);let u=o&&o.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=o.firstChild;for(;e&&!O(e);)e=e.nextSibling;if(!e)break;o=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Re.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!so.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=xo(mo(c,+d[1],+d[2]),d[4]);else if(c=p.maxOpen(co(c.content,i),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e{c=t(c,e,l)}),c}var so=/^(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 co(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&uo(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=fo(a[a.length-1],i.length));let n=lo(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return s.from(a)}return e}function lo(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,s.from(e));return e}function uo(e,t,n,r,i){if(i1&&(a=0),i=n&&(c=t<0?o.contentMatchAt(0).fillBefore(c,a<=i).append(c):c.append(o.contentMatchAt(o.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(c))}function mo(e,t,n){return te})}return _o.createHTML(e)}function yo(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=go(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&ho[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>``+e+`>`).reverse().join(``)),r.innerHTML=vo(e),a)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;try{i=s.from(t.create(r[e+1],i))}catch{break}a++,o++}return new p(i,a,o)}var So={},Co={},wo={touchstart:!0,touchmove:!0},To=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Eo(e){for(let t in So){let n=So[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{jo(e,t)&&!Ao(e,t)&&(e.editable||!(t.type in Co))&&n(e,t)},wo[t]?{passive:!0}:void 0)}fi&&e.dom.addEventListener(`input`,()=>null),ko(e)}function Do(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function Oo(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function ko(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Ao(e,t))})}function Ao(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function jo(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Mo(e,t){!Ao(e,t)&&So[t.type]&&(e.editable||!(t.type in Co))&&So[t.type](e,t)}Co.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Yo(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(gi&&ui&&n.keyCode==13))){if(n.keyCode!=229&&e.domObserver.forceFlush(),pi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||io(e,n)?n.preventDefault():Do(e,`key`)}},Co.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},Co.keypress=(e,t)=>{let n=t;if(Yo(e)||!n.charCode||n.ctrlKey&&!n.altKey||mi&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof w)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function No(e){return{left:e.clientX,top:e.clientY}}function Po(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Fo(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Io(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function Lo(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&T.isSelectable(r)?(Io(e,new T(n)),!0):!1}function Ro(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof T&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(T.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i!=null&&(Io(e,T.create(e.state.doc,i)),!0)}function zo(e,t,n,r,i){return Fo(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?Ro(e,n):Lo(e,n))}function Bo(e,t,n,r){return Fo(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Vo(e,t,n,r){return Fo(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Ho(e,n,r)}function Ho(e,t,n){if(n.button!=0)return!1;let r=Uo(e,t,!0),i=e.state.doc;return r?(Io(e,r),r instanceof w&&i.eq(e.state.doc)&&(e.input.mouseDown=new Jo(e,r)),!0):!1}function Uo(e,t,n){let r=e.state.doc;if(t==-1)return r.inlineContent?w.create(r,0,r.content.size):null;let i=r.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e),a=i.before(e);if(t.inlineContent)return w.create(r,a+1,a+1+t.content.size);if(n&&T.isSelectable(t))return T.create(r,a)}return null}function Wo(e){return ts(e)}var Go=mi?`metaKey`:`ctrlKey`;So.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Wo(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&Po(n,e.input.lastClick)&&!n[Go]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(No(n));o&&(a==`singleClick`?e.input.mouseDown=new qo(e,o,n,!!r):(a==`doubleClick`?Bo:Vo)(e,o.pos,o.inside,n)?n.preventDefault():Do(e,`pointer`))};var Ko=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},qo=class extends Ko{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Go],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&O(s.nodeDOM)?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof T&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!(!this.target||this.target.draggable),setUneditable:!!(this.target&&ci&&!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()),Do(e,`pointer`)}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||Oa(this.view)})}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(No(e))),this.updateAllowDefault(e),this.allowDefault||!t?Do(this.view,`pointer`):zo(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||fi&&this.mightDrag&&!this.mightDrag.node.isAtom||ui&&!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)?(Io(this.view,C.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Do(this.view,`pointer`)}move(e){this.updateAllowDefault(e),Do(this.view,`pointer`),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Jo=class extends Ko{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Do(this.view,`pointer`);let t=this.view.posAtCoords(No(e)),n=t&&Uo(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,i=this.startSelection,[a,o]=n.from{e.input.lastTouch=Date.now(),Wo(e),Do(e,`pointer`)},So.touchmove=e=>{e.input.lastTouch=Date.now(),Do(e,`pointer`)},So.contextmenu=e=>Wo(e);function Yo(e,t){return e.composing?!0:fi&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Xo=gi?5e3:-1;Co.compositionstart=Co.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof w&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||ui&&hi&&Zo(e)))e.markCursor=e.state.storedMarks||n.marks(),ts(e,!0),e.markCursor=null;else if(ts(e,!t.selection.empty),ci&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&O(n)&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(Wr(t)){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Qo(e,Xo)};function Zo(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||!O(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return O(r)&&r.contentEditable==`false`}Co.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Qo(e,20))};function Qo(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ts(e),t))}function $o(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function es(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Kr(t.focusNode,t.focusOffset),r=qr(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return r}}return n||r}function ts(e,t=!1){if(!(gi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),$o(e),t||e.docView&&e.docView.dirty){let n=Ea(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function ns(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var rs=oi&&si<15||pi&&vi<604;So.copy=Co.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=rs?null:n.clipboardData,{dom:o,text:s}=ao(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):ns(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function is(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function as(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ss(e,r.value,null,i,t):ss(e,r.textContent,r.innerHTML,i,t)},50)}function ss(e,t,n,r,i){let a=oo(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||p.empty)))return!0;if(!a)return!1;let o=is(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function cs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}Co.paste=(e,t)=>{let n=t;if(e.composing&&!gi)return;let r=rs?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&ss(e,cs(r),r.getData(`text/html`),i,n)?n.preventDefault():as(e,n)};var ls=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},us=mi?`altKey`:`ctrlKey`;function ds(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[us]:!n}So.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(No(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof T?i.to-1:i.to))){if(r&&r.mightDrag)o=T.create(e.state.doc,r.mightDrag.pos);else if(n.target&&O(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=T.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=ao(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!ui||di>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(rs?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,rs||n.dataTransfer.setData(`text/plain`,c),e.dragging=new ls(l,ds(e,n),o)},So.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},Co.dragover=Co.dragenter=(e,t)=>t.preventDefault(),Co.drop=(e,t)=>{try{fs(e,t,e.dragging)}finally{e.dragging=null}};function fs(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(No(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=oo(e,cs(t.dataTransfer),rs?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ds(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||p.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?en(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&T.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new T(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(La(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}So.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Oa(e)},20))},So.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},So.beforeinput=(e,t)=>{if(gi&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in Co)So[e]=Co[e];function ps(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var ms=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index=a?null:new vs(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==xs||e.maps.length==0?this:this.mapInner(e,t,0,0,n||bs)}mapInner(t,n,r,i,a){let o;if(this.local.length){let e=new ms(n.content);for(let s=0;s{let o=t+r,s;if(s=Es(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof gs){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,bs));return e.from(r)}forChild(t,n){if(n.isLeaf)return k.empty;let r=[];for(let i=0;ie instanceof k)?t:t.reduce((e,t)=>e.concat(t instanceof k?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==xs?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=Os(Ts(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=Es(e,t,o+n);if(s){a=!0;let e=Os(s,t,n+o+1,r);e!=xs&&i.push(o,o+t.nodeSize,e)}});let o=ws(a?Ds(e):e,-n).sort(ks);if(o.length){let e=new ms(t.content);for(let n=0;n0;)t++;e.splice(t,0,n)}function Ms(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=xs&&t.push(r)}),e.cursorWrapper&&t.push(k.create(e.state.doc,[e.cursorWrapper.deco])),Ss.from(t)}var Ns={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Ps=oi&&si<=11,Fs=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}},Is=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Fs,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():fi&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Ps&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ns)),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(Ra(this.view)){if(this.suppressingSelectionUpdates)return Oa(this.view);if(oi&&si<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Br(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,n;for(let n=e.focusNode;n;n=Ir(n))t.add(n);for(let r=e.anchorNode;r;r=Ir(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:Wr(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&Ra(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||ui&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&O(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(ci&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||Hs(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),zs(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Us(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&Oa(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;na;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||Re.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace!=`pre`||`full`,findPositions:u,ruleFromNode:Gs(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Gs=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(fi&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}if(t.parentNode.lastChild==t||fi&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},Ks=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function qs(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Ea(e,t);if(n&&!e.state.selection.eq(n)){if(ui&&gi&&e.input.lastKeyCode===13&&Date.now()-100t(e,Zr(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Ws(e,t,n,i),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||gi)&&i.some(e=>O(e)&&!Ks.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m){if(r&&c instanceof w&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Js(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oi&&si<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((pi&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Zs(l.doc,h.pos,g.pos))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&(v?m.endA>m.start&&m.endB==m.start:Xs(u,m.start,m.endA,h,g))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))){gi&&ui&&e.domObserver.suppressSelectionUpdates();return}ui&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),gi&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Zr(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Js(e,n.doc,l.sel);t&&!(ui&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteOa(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Ys(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x())}else e.dispatch(x())}function Js(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:La(e,t.resolve(n.anchor),t.resolve(n.head))}function Ys(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,c,l;for(let e=0;ee.mark(c.addToSet(e.marks));else if(i.length==0&&a.length==1)c=a[0],o=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;en||Qs(o,!0,!1){e.isTextblock&&a>=t&&a0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function $s(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var ec=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 To,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(sc),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=rc(this),nc(this),this.nodeViews=ac(this),this.docView=oa(this.state.doc,tc(this),Ms(this),this.dom,this),this.domObserver=new Is(this,(e,t,n,r)=>qs(this,e,t,n,r)),this.domObserver.start(),Eo(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ko(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(sc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&($o(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=ac(this);oc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&ko(this),this.editable=rc(this),nc(this);let o=Ms(this),s=tc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&Ci(this);if(i){this.domObserver.stop();let t=l&&(oi||ui)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&ic(n.selection,e.selection);if(l){let n=ui?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=es(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=oa(e.doc,s,o,this.dom,this)),!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}let i=this.input.mouseDown;t||!(i&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ba(this)&&i.delaySelUpdate())?Oa(this,t):(Fa(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&Ti(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&Gr(this.dom,e)&&!this.someProp(`handleScrollToSelection`,e=>e(this))){if(this.state.selection instanceof T){let t=this.docView.domAfterPos(this.state.selection.from);O(t)&&Si(this,t.getBoundingClientRect(),e)}else Si(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 e=0;e0&&ee.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ii(this,e)}coordsAtPos(e,t=1){return Bi(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Xi(this,t||this.state,e)}pasteHTML(e,t){return ss(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return ss(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return ao(this,e)}destroy(){this.docView&&(Oo(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ms(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,zr())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Mo(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?fi&&this.root.nodeType===11&&Qr(this.dom.ownerDocument)==this.dom&&Vs(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};ec.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function tc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[vs.node(0,e.state.doc.content.size,t)]}function nc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:vs.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function rc(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function ic(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function ac(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function oc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function sc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var cc={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:`'`},lc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},uc=typeof navigator<`u`&&/Mac/.test(navigator.platform),dc=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),fc=0;fc<10;fc++)cc[48+fc]=cc[96+fc]=String(fc);for(var fc=1;fc<=24;fc++)cc[fc+111]=`F`+fc;for(var fc=65;fc<=90;fc++)cc[fc]=String.fromCharCode(fc+32),lc[fc]=String.fromCharCode(fc);for(var pc in cc)lc.hasOwnProperty(pc)||(lc[pc]=cc[pc]);function mc(e){var t=!(uc&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||dc&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?lc:cc)[e.keyCode]||e.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 hc=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),gc=typeof navigator<`u`&&/Win/.test(navigator.platform);function _c(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e=t?Cc.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Cc.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Cc.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},Cc.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},Cc.from=function(e){return e instanceof Cc?e:e&&e.length?new wc(e):Cc.empty};var wc=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=Sc)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=Sc)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(Cc);Cc.empty=new wc([]);var Tc=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(Cc),Ec=500,Dc=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step)i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);else{if(i){u.push(new kc(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new kc(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1}},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;ejc&&(s=Oc(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new gt;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new kc(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new kc(i,o,l))}else r.push(new kc(i))},i);let l=[];for(let e=n;eEc&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new kc(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(Cc.from(i.reverse()),a)}};Dc.empty=new Dc(Cc.empty,0);function Oc(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var kc=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},Ac=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},jc=20;function Mc(e,t,n,r){let i=n.getMeta(Vc),a;if(i)return i.historyState;n.getMeta(Hc)&&(e=new Ac(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Vc))return o.getMeta(Vc).redo?new Ac(e.done.addTransform(n,void 0,r,zc(t)),e.undone,Pc(n.mapping.maps),e.prevTime,e.prevComposition):new Ac(e.done,e.undone.addTransform(n,void 0,r,zc(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Nc(n,e.prevRanges)),s=o?Fc(e.prevRanges,n.mapping):Pc(n.mapping.maps);return new Ac(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,zc(t)),Dc.empty,s,n.time,i??e.prevComposition)}return(a=n.getMeta(`rebased`))?new Ac(e.done.rebased(n,a),e.undone.rebased(n,a),Fc(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new Ac(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Fc(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Nc(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function Pc(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Fc(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=Vc.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=Ic(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Gc=Wc(!1,!0),Kc=Wc(!0,!0);function qc(e){return e.getMeta(Vc)!=null}function Jc(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var Yc=class e{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}static createFakeChain(){let e=new Proxy({},{get:(t,n)=>{if(n!==`then`)return n===`run`?()=>!1:()=>e}});return e}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}static createFallbackCan(){let t=e.createFakeChain();return new Proxy({chain:()=>t},{get:(e,t)=>{if(t!==`then`)return t===`chain`?e.chain:()=>!1}})}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:Jc({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},Xc=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{if(!e.isDestroyed){var n;t.dom.blur(),(n=window)==null||(n=n.getSelection())==null||n.removeAllRanges()}}),!0),Zc=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),Qc=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=Pt(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},$c=e=>t=>e(t),el=()=>({state:e,dispatch:t})=>lr(e,t),tl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new w(r.doc.resolve(Math.max(o-1,0)))),!0},nl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function rl(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var il=e=>({tr:t,state:n,dispatch:r})=>{let i=rl(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},al=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},ol=e=>e.content?/^text(\*|\+)/.test(e.content):!1,sl=(e,t,n)=>{if(!e.parent.isInline||n===`left`&&e.pos>e.start()||n===`right`&&e.pos({from:sl(e,n,`left`),to:sl(t,n,`right`)}),ll=()=>({state:e,dispatch:t})=>{if(e.selection.empty)return!1;if(t){let n=e.tr,{ranges:r}=e.selection,i=e.selection instanceof w?e.selection.$from.marksAcross(e.selection.$to):null,a=n.steps.length;r.forEach(t=>{let r=n.mapping.slice(a),{from:i,to:o}=cl(n.doc.resolve(r.map(t.$from.pos)),n.doc.resolve(r.map(t.$to.pos)),e.schema);n.deleteRange(i,o)}),n.selection.empty||n.setSelection(w.near(n.doc.resolve(n.selection.from))),i&&n.ensureMarks(i),n.scrollIntoView(),t(n)}return!0},ul=()=>({commands:e})=>e.keyboardShortcut(`Enter`),dl=()=>({state:e,dispatch:t})=>cr(e,t);function fl(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function pl(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:fl(t[r])?t[r].test(e[r]):t[r]===e[r])}function ml(e,t,n={}){return e.find(e=>e.type===t&&pl(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function hl(e,t,n={}){return!!ml(e,t,n)}function gl(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!ml([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&hl([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=_l(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=gl(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=w.create(o,e.from,e.to);n.setSelection(t)}}return!0},yl=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(wl()||Cl())&&r.dom.focus(),Tl()&&!wl()&&!Cl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!bl(n.state.selection))return o(),!0;let s=Sl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Dl=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),Ol=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),kl=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&kl(r)}return e};function Al(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return kl(n)}function jl(e){return typeof e?.nodesBetween==`function`}function Ml(e,t,n){if(jl(e))return e;let r=typeof e==`object`&&!!e;n={slice:!0,parseOptions:{},...n};let i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return s.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),Ml(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Pe({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?Re.fromSchema(a).parseSlice(Al(e),n.parseOptions):Re.fromSchema(a).parse(Al(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=Re.fromSchema(t);return n.slice?r.parseSlice(Al(e),n.parseOptions).content:r.parse(Al(e),n.parseOptions)}return Ml(``,t,n)}function Nl(e){return!(`type`in e)}function Pl(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(C.near(e.doc.resolve(o),n))}var Fl=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{Ml(t,a.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=Ml(t,a.schema,{parseOptions:c,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:l,to:u}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},d=!0,f=!0,p=Nl(i)?i.content:[i];if(p.forEach(e=>{e.check(),d=d?e.isText&&e.marks.length===0:!1,f=f?e.isBlock:!1}),l===u&&f){let{parent:e}=r.doc.resolve(l);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--l,u+=1)}let m;if(d)m=Array.isArray(t)?t.map(e=>e.text||``).join(``):jl(t)?p.map(e=>e.text??``).join(``):typeof t==`object`&&t&&t.text?t.text:t,r.insertText(m,l,u);else{m=s.from(p);let e=r.doc.resolve(l),t=e.node(),n=e.parentOffset===0,i=t.isText||t.isTextblock,a=t.content.size>0;n&&i&&a&&f&&(l=Math.max(0,l-1)),r.replaceWith(l,u,p)}n.updateSelection&&Pl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:l,text:m}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:l,text:m})}return!0};function Il(e){for(let t=0;t({tr:t,dispatch:n,editor:r})=>{let{pos:i,attrs:a,content:o,updateSelection:s=!0}=e,c;c=typeof i==`number`?t.doc.resolve(i):i||t.selection.$from;let l=Il(c.parent.contentMatchAt(c.index()));if(!l)return!1;let u=Object.keys(l.spec.attrs||{}),d=a?Object.fromEntries(Object.entries(a).filter(([e])=>u.includes(e))):{},f;if(o){let e=Ml(o,r.schema);f=l.createAndFill(d,e)}else f=l.createAndFill(d);return f?(n&&(t.insert(c.pos,f),s&&Pl(t,t.steps.length-1,-1)),!0):!1},Rl=()=>({state:e,dispatch:t})=>rr(e,t),zl=()=>({state:e,dispatch:t})=>ir(e,t),Bl=()=>({state:e,dispatch:t})=>Kn(e,t),Vl=()=>({state:e,dispatch:t})=>er(e,t),Hl=(e,t)=>{let n=e.resolve(t),r=n.nodeBefore,i=n.nodeAfter;return!r||!i?!1:!r.type.spec.isolating&&!i.type.spec.isolating},Ul=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Zt(e.doc,e.selection.$from.pos,-1);return r==null||!Hl(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Wl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Zt(e.doc,e.selection.$from.pos,1);return r==null||!Hl(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Gl=()=>({state:e,dispatch:t})=>qn(e,t),Kl=()=>({state:e,dispatch:t})=>Jn(e,t);function ql(){return typeof navigator<`u`&&/Mac/.test(navigator.platform)}function Jl(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Jl(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function Xl(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?rl(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>!o||o.name===e.node.type.name).filter(e=>pl(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Zl=(e,t={})=>({state:n,dispatch:r})=>Xl(n,rl(e,n.schema),t)?ar(n,r):!1,Ql=()=>({state:e,dispatch:t})=>ur(e,t),$l=e=>({state:t,dispatch:n})=>jr(rl(e,t.schema))(t,n),eu=()=>({state:e,dispatch:t})=>or(e,t);function tu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function nu(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var ru=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=tu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=rl(e,r.schema)),s===`mark`&&(o=_l(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,nu(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(nu(a.attrs,t))))})})}),c},iu=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),au=()=>({tr:e,dispatch:t})=>{if(t){let t=new On(e.doc);e.setSelection(t)}return!0},ou=()=>({state:e,dispatch:t})=>Zn(e,t),su=()=>({state:e,dispatch:t})=>tr(e,t),cu=()=>({state:e,dispatch:t})=>pr(e,t),lu=()=>({state:e,dispatch:t})=>yr(e,t),uu=()=>({state:e,dispatch:t})=>vr(e,t);function du(e,t,n={},r={}){return Ml(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var fu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=du(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});if(o){let e=Nl(s)?s.content:[s];a.replaceWith(0,c.content.size,e).setMeta(`preventUpdate`,!n)}return!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function pu(e,t){let n=_l(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function mu(e,t){let n=new xn(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function hu(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function gu(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function _u(e){return t=>gu(t.$from,e)}function A(e,t,n){return e.config[t]===void 0&&e.parent?A(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?A(e.parent,t,n):null}):e.config[t]}function vu(e){return e.map(e=>{let t=A(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...vu(t())]:e}).flat(10)}function yu(e,t){let n=Qe.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function bu(e,t){let n=new Map;for(let t of e){let e=n.get(t.type)??new Map;e.set(t.name,t),n.set(t.type,e)}return[...Object.values(t.nodes),...Object.values(t.marks)].flatMap(e=>Object.entries(e.spec.attrs??{}).map(([t,r])=>{let i=n.get(e.name)?.get(t),a=Object.hasOwn(r,`default`);return{type:e.name,name:t,attribute:{rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,...i?.attribute,default:r.default,isRequired:!a,validate:r.validate}}}))}var xu={content:`string`,marks:`string`,group:`string`,inline:`boolean`,atom:`boolean`,selectable:`boolean`,draggable:`boolean`,code:`boolean`,whitespace:[`pre`,`normal`],definingAsContext:`boolean`,definingForContent:`boolean`,defining:`boolean`,isolating:`boolean`,linebreakReplacement:`boolean`},Su={inclusive:`boolean`,excludes:`string`,group:`string`,spanning:`boolean`,code:`boolean`};function Cu(e,t,n){return Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e[t];if(i===void 0)return[];if(!(typeof r==`string`?typeof i===r:typeof i==`string`&&r.includes(i)))throw RangeError(`Invalid schemaSpec field '${n}.${t}'`);return[[t,i]]}))}function wu(e,t,n,r){return{...Object.fromEntries(Object.entries(t).filter(([e])=>e!==`attrs`&&!Object.hasOwn(r,e))),...Cu(n,r,e),attrs:n.attrs}}function Tu(e,t,n){for(let r of Object.keys(t))if(!Object.hasOwn(e,r))throw RangeError(`schemaSpec requires a local ${n} extension named '${r}'`);for(let r of Object.keys(e))if(!Object.hasOwn(t,r))throw RangeError(`Local ${n} extension '${r}' is not in schemaSpec`)}function Eu(e,t){Tu(e.nodes,t.nodes,`node`),Tu(e.marks,t.marks,`mark`);let n=t.spec.nodes,r=t.spec.marks;return t.spec.nodes.forEach((t,r)=>{n=n.update(t,wu(t,e.nodes[t],r,xu))}),t.spec.marks.forEach((t,n)=>{r=r.update(t,wu(t,e.marks[t],n,Su))}),{topNode:t.topNodeType.name,nodes:n,marks:r}}function Du(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function Ou(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function ku(e){let t=[],{nodeExtensions:n,markExtensions:r}=Ou(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=A(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=A(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Au(e){return typeof e==`function`}function ju(e,t=void 0,...n){return Au(e)?t?e.bind(t)(...n):e(...n):e}function Mu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Nu(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}}return n&&t.push(n),t}function Pu(e){let t=[],n=Nu(e||``),r=n.length;for(let e=0;e!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(e===`__proto__`)Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0});else if(!n[e])n[e]=t;else if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...Pu(n[e]),...Pu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Iu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>Fu(e,t),{})}function Lu(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`||e!==`false`&&e:e}function Ru(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Lu(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function zu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Mu(t)?!1:t!=null))}function Bu(e){var t,n;let r={};return!(e!=null&&(t=e.attribute)!=null&&t.isRequired)&&`default`in(e?.attribute||{})&&(r.default=e.attribute.default),(e==null||(n=e.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function Vu(e,t,n=ku(e)){let{nodeExtensions:r,markExtensions:i}=Ou(e);return{topNode:r.find(e=>A(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=zu({...e.reduce((e,t)=>{let n=A(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:ju(A(r,`content`,a)),marks:ju(A(r,`marks`,a)),group:ju(A(r,`group`,a)),inline:ju(A(r,`inline`,a)),atom:ju(A(r,`atom`,a)),selectable:ju(A(r,`selectable`,a)),draggable:ju(A(r,`draggable`,a)),code:ju(A(r,`code`,a)),whitespace:ju(A(r,`whitespace`,a)),linebreakReplacement:ju(A(r,`linebreakReplacement`,a)),defining:ju(A(r,`defining`,a)),isolating:ju(A(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Bu))}),s=ju(A(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Ru(e,i)));let c=A(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Iu(e,i)}));let l=A(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=zu({...e.reduce((e,t)=>{let n=A(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:ju(A(r,`inclusive`,a)),excludes:ju(A(r,`excludes`,a)),group:ju(A(r,`group`,a)),spanning:ju(A(r,`spanning`,a)),code:ju(A(r,`code`,a)),attrs:Object.fromEntries(i.map(Bu))}),s=ju(A(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Ru(e,i)));let c=A(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Iu(e,i)})),[r.name,o]}))}}function Hu(e,t,n){if(n===void 0)return new Pe(Vu(e,t));let r=Du(e.filter(e=>e.type!==`extension`).map(e=>e.name));if(r.length)throw RangeError(`Duplicate local schema types: ${r.join(`, `)}`);let i=new Pe(n);return new Pe(Eu(Vu(e,t,bu(ku(e),i)),i))}function Uu(e){return e.sort((e,t)=>{let n=A(e,`priority`)||100,r=A(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Gu(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=`
+`))),0,0),e.someProp(`transformPasted`,t=>{c=t(c,e,!0)}),c;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)c=n;else{let n=i.marks(),{schema:r}=e.state,a=Qe.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=yo(n),_i&&bo(o);let u=o&&o.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=o.firstChild;for(;e&&!O(e);)e=e.nextSibling;if(!e)break;o=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Re.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!so.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=xo(mo(c,+d[1],+d[2]),d[4]);else if(c=p.maxOpen(co(c.content,i),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e{c=t(c,e,l)}),c}var so=/^(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 co(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&uo(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=fo(a[a.length-1],i.length));let n=lo(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return s.from(a)}return e}function lo(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,s.from(e));return e}function uo(e,t,n,r,i){if(i1&&(a=0),i=n&&(c=t<0?o.contentMatchAt(0).fillBefore(c,a<=i).append(c):c.append(o.contentMatchAt(o.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(c))}function mo(e,t,n){return te})}return _o.createHTML(e)}function yo(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=go(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&ho[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>``+e+`>`).reverse().join(``)),r.innerHTML=vo(e),a)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;try{i=s.from(t.create(r[e+1],i))}catch{break}a++,o++}return new p(i,a,o)}var So={},Co={},wo={touchstart:!0,touchmove:!0},To=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Eo(e){for(let t in So){let n=So[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{jo(e,t)&&!Ao(e,t)&&(e.editable||!(t.type in Co))&&n(e,t)},wo[t]?{passive:!0}:void 0)}fi&&e.dom.addEventListener(`input`,()=>null),ko(e)}function Do(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function Oo(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function ko(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Ao(e,t))})}function Ao(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function jo(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Mo(e,t){!Ao(e,t)&&So[t.type]&&(e.editable||!(t.type in Co))&&So[t.type](e,t)}Co.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Yo(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(gi&&ui&&n.keyCode==13))){if(n.keyCode!=229&&e.domObserver.forceFlush(),pi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||io(e,n)?n.preventDefault():Do(e,`key`)}},Co.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},Co.keypress=(e,t)=>{let n=t;if(Yo(e)||!n.charCode||n.ctrlKey&&!n.altKey||mi&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof w)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function No(e){return{left:e.clientX,top:e.clientY}}function Po(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Fo(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Io(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function Lo(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&T.isSelectable(r)?(Io(e,new T(n)),!0):!1}function Ro(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof T&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(T.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i!=null&&(Io(e,T.create(e.state.doc,i)),!0)}function zo(e,t,n,r,i){return Fo(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?Ro(e,n):Lo(e,n))}function Bo(e,t,n,r){return Fo(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Vo(e,t,n,r){return Fo(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Ho(e,n,r)}function Ho(e,t,n){if(n.button!=0)return!1;let r=Uo(e,t,!0),i=e.state.doc;return r?(Io(e,r),r instanceof w&&i.eq(e.state.doc)&&(e.input.mouseDown=new Jo(e,r)),!0):!1}function Uo(e,t,n){let r=e.state.doc;if(t==-1)return r.inlineContent?w.create(r,0,r.content.size):null;let i=r.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e),a=i.before(e);if(t.inlineContent)return w.create(r,a+1,a+1+t.content.size);if(n&&T.isSelectable(t))return T.create(r,a)}return null}function Wo(e){return ts(e)}var Go=mi?`metaKey`:`ctrlKey`;So.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Wo(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&Po(n,e.input.lastClick)&&!n[Go]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(No(n));o&&(a==`singleClick`?e.input.mouseDown=new qo(e,o,n,!!r):(a==`doubleClick`?Bo:Vo)(e,o.pos,o.inside,n)?n.preventDefault():Do(e,`pointer`))};var Ko=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},qo=class extends Ko{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Go],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&O(s.nodeDOM)?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof T&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!(!this.target||this.target.draggable),setUneditable:!!(this.target&&ci&&!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()),Do(e,`pointer`)}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||Oa(this.view)})}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(No(e))),this.updateAllowDefault(e),this.allowDefault||!t?Do(this.view,`pointer`):zo(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||fi&&this.mightDrag&&!this.mightDrag.node.isAtom||ui&&!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)?(Io(this.view,C.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Do(this.view,`pointer`)}move(e){this.updateAllowDefault(e),Do(this.view,`pointer`),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Jo=class extends Ko{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Do(this.view,`pointer`);let t=this.view.posAtCoords(No(e)),n=t&&Uo(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,i=this.startSelection,[a,o]=n.from{e.input.lastTouch=Date.now(),Wo(e),Do(e,`pointer`)},So.touchmove=e=>{e.input.lastTouch=Date.now(),Do(e,`pointer`)},So.contextmenu=e=>Wo(e);function Yo(e,t){return e.composing?!0:fi&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Xo=gi?5e3:-1;Co.compositionstart=Co.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof w&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||ui&&hi&&Zo(e)))e.markCursor=e.state.storedMarks||n.marks(),ts(e,!0),e.markCursor=null;else if(ts(e,!t.selection.empty),ci&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&O(n)&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(Wr(t)){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Qo(e,Xo)};function Zo(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||!O(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return O(r)&&r.contentEditable==`false`}Co.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Qo(e,20))};function Qo(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ts(e),t))}function $o(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function es(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Kr(t.focusNode,t.focusOffset),r=qr(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return r}}return n||r}function ts(e,t=!1){if(!(gi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),$o(e),t||e.docView&&e.docView.dirty){let n=Ea(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function ns(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var rs=oi&&si<15||pi&&vi<604;So.copy=Co.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=rs?null:n.clipboardData,{dom:o,text:s}=ao(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):ns(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function is(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function as(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ss(e,r.value,null,i,t):ss(e,r.textContent,r.innerHTML,i,t)},50)}function ss(e,t,n,r,i){let a=oo(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||p.empty)))return!0;if(!a)return!1;let o=is(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function cs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}Co.paste=(e,t)=>{let n=t;if(e.composing&&!gi)return;let r=rs?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&ss(e,cs(r),r.getData(`text/html`),i,n)?n.preventDefault():as(e,n)};var ls=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},us=mi?`altKey`:`ctrlKey`;function ds(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[us]:!n}So.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(No(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof T?i.to-1:i.to))){if(r&&r.mightDrag)o=T.create(e.state.doc,r.mightDrag.pos);else if(n.target&&O(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=T.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=ao(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!ui||di>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(rs?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,rs||n.dataTransfer.setData(`text/plain`,c),e.dragging=new ls(l,ds(e,n),o)},So.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},Co.dragover=Co.dragenter=(e,t)=>t.preventDefault(),Co.drop=(e,t)=>{try{fs(e,t,e.dragging)}finally{e.dragging=null}};function fs(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(No(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=oo(e,cs(t.dataTransfer),rs?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ds(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||p.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?en(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&T.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new T(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(La(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}So.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Oa(e)},20))},So.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},So.beforeinput=(e,t)=>{if(gi&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in Co)So[e]=Co[e];function ps(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var ms=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index=a?null:new vs(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==Ss||e.maps.length==0?this:this.mapInner(e,t,0,0,n||bs)}mapInner(t,n,r,i,a){let o;if(this.local.length){let e=new ms(n.content);for(let s=0;s{let o=t+r,s;if(s=Ds(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof gs){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,bs));return e.from(r)}forChild(t,n){if(n.isLeaf)return xs.empty;let r=[];for(let i=0;ie instanceof xs)?t:t.reduce((e,t)=>e.concat(t instanceof xs?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==Ss?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=ks(Es(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=Ds(e,t,o+n);if(s){a=!0;let e=ks(s,t,n+o+1,r);e!=Ss&&i.push(o,o+t.nodeSize,e)}});let o=Ts(a?Os(e):e,-n).sort(As);if(o.length){let e=new ms(t.content);for(let n=0;n0;)t++;e.splice(t,0,n)}function Ns(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=Ss&&t.push(r)}),e.cursorWrapper&&t.push(xs.create(e.state.doc,[e.cursorWrapper.deco])),Cs.from(t)}var Ps={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Fs=oi&&si<=11,Is=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}},Ls=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Is,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():fi&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Fs&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ps)),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(Ra(this.view)){if(this.suppressingSelectionUpdates)return Oa(this.view);if(oi&&si<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Br(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,n;for(let n=e.focusNode;n;n=Ir(n))t.add(n);for(let r=e.anchorNode;r;r=Ir(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:Wr(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&Ra(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||ui&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&O(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(ci&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||Us(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),Bs(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Ws(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&Oa(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;na;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||Re.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace!=`pre`||`full`,findPositions:u,ruleFromNode:Ks(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Ks=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(fi&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}if(t.parentNode.lastChild==t||fi&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},qs=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Js(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Ea(e,t);if(n&&!e.state.selection.eq(n)){if(ui&&gi&&e.input.lastKeyCode===13&&Date.now()-100t(e,Zr(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Gs(e,t,n,i),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||gi)&&i.some(e=>O(e)&&!qs.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m){if(r&&c instanceof w&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Ys(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oi&&si<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((pi&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Qs(l.doc,h.pos,g.pos))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&(v?m.endA>m.start&&m.endB==m.start:Zs(u,m.start,m.endA,h,g))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))){gi&&ui&&e.domObserver.suppressSelectionUpdates();return}ui&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),gi&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Zr(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Ys(e,n.doc,l.sel);t&&!(ui&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteOa(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Xs(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x())}else e.dispatch(x())}function Ys(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:La(e,t.resolve(n.anchor),t.resolve(n.head))}function Xs(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,c,l;for(let e=0;ee.mark(c.addToSet(e.marks));else if(i.length==0&&a.length==1)c=a[0],o=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;en||$s(o,!0,!1){e.isTextblock&&a>=t&&a0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function ec(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var tc=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 To,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(cc),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=ic(this),rc(this),this.nodeViews=oc(this),this.docView=oa(this.state.doc,nc(this),Ns(this),this.dom,this),this.domObserver=new Ls(this,(e,t,n,r)=>Js(this,e,t,n,r)),this.domObserver.start(),Eo(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ko(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(cc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&($o(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=oc(this);sc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&ko(this),this.editable=ic(this),rc(this);let o=Ns(this),s=nc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&Ci(this);if(i){this.domObserver.stop();let t=l&&(oi||ui)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&ac(n.selection,e.selection);if(l){let n=ui?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=es(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=oa(e.doc,s,o,this.dom,this)),!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}let i=this.input.mouseDown;t||!(i&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ba(this)&&i.delaySelUpdate())?Oa(this,t):(Fa(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&Ti(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&Gr(this.dom,e)&&!this.someProp(`handleScrollToSelection`,e=>e(this))){if(this.state.selection instanceof T){let t=this.docView.domAfterPos(this.state.selection.from);O(t)&&Si(this,t.getBoundingClientRect(),e)}else Si(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 e=0;e0&&ee.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ii(this,e)}coordsAtPos(e,t=1){return Bi(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Xi(this,t||this.state,e)}pasteHTML(e,t){return ss(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return ss(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return ao(this,e)}destroy(){this.docView&&(Oo(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ns(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,zr())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Mo(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?fi&&this.root.nodeType===11&&Qr(this.dom.ownerDocument)==this.dom&&Hs(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};tc.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function nc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[vs.node(0,e.state.doc.content.size,t)]}function rc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:vs.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ic(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function ac(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function oc(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function sc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function cc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var lc={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:`'`},uc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},dc=typeof navigator<`u`&&/Mac/.test(navigator.platform),fc=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),pc=0;pc<10;pc++)lc[48+pc]=lc[96+pc]=String(pc);for(var pc=1;pc<=24;pc++)lc[pc+111]=`F`+pc;for(var pc=65;pc<=90;pc++)lc[pc]=String.fromCharCode(pc+32),uc[pc]=String.fromCharCode(pc);for(var mc in lc)uc.hasOwnProperty(mc)||(uc[mc]=lc[mc]);function hc(e){var t=!(dc&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||fc&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?uc:lc)[e.keyCode]||e.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 gc=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),_c=typeof navigator<`u`&&/Win/.test(navigator.platform);function vc(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e=t?wc.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},wc.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},wc.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},wc.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},wc.from=function(e){return e instanceof wc?e:e&&e.length?new Tc(e):wc.empty};var Tc=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=Cc)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=Cc)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(wc);wc.empty=new Tc([]);var Ec=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(wc),Dc=500,Oc=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step)i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);else{if(i){u.push(new Ac(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new Ac(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1}},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;eMc&&(s=kc(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new gt;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new Ac(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new Ac(i,o,l))}else r.push(new Ac(i))},i);let l=[];for(let e=n;eDc&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new Ac(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(wc.from(i.reverse()),a)}};Oc.empty=new Oc(wc.empty,0);function kc(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var Ac=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},jc=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},Mc=20;function Nc(e,t,n,r){let i=n.getMeta(Hc),a;if(i)return i.historyState;n.getMeta(Uc)&&(e=new jc(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Hc))return o.getMeta(Hc).redo?new jc(e.done.addTransform(n,void 0,r,Bc(t)),e.undone,Fc(n.mapping.maps),e.prevTime,e.prevComposition):new jc(e.done,e.undone.addTransform(n,void 0,r,Bc(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Pc(n,e.prevRanges)),s=o?Ic(e.prevRanges,n.mapping):Fc(n.mapping.maps);return new jc(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,Bc(t)),Oc.empty,s,n.time,i??e.prevComposition)}return(a=n.getMeta(`rebased`))?new jc(e.done.rebased(n,a),e.undone.rebased(n,a),Ic(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new jc(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Ic(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Pc(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function Fc(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Ic(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=Hc.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=Lc(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Kc=Gc(!1,!0),qc=Gc(!0,!0);function Jc(e){return e.getMeta(Hc)!=null}function Yc(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var Xc=class e{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}static createFakeChain(){let e=new Proxy({},{get:(t,n)=>{if(n!==`then`)return n===`run`?()=>!1:()=>e}});return e}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}static createFallbackCan(){let t=e.createFakeChain();return new Proxy({chain:()=>t},{get:(e,t)=>{if(t!==`then`)return t===`chain`?e.chain:()=>!1}})}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:Yc({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},Zc=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{if(!e.isDestroyed){var n;t.dom.blur(),(n=window)==null||(n=n.getSelection())==null||n.removeAllRanges()}}),!0),Qc=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),$c=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=Pt(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},el=e=>t=>e(t),tl=()=>({state:e,dispatch:t})=>lr(e,t),nl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new w(r.doc.resolve(Math.max(o-1,0)))),!0},rl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function il(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var al=e=>({tr:t,state:n,dispatch:r})=>{let i=il(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},ol=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},sl=e=>e.content?/^text(\*|\+)/.test(e.content):!1,cl=(e,t,n)=>{if(!e.parent.isInline||n===`left`&&e.pos>e.start()||n===`right`&&e.pos({from:cl(e,n,`left`),to:cl(t,n,`right`)}),ul=()=>({state:e,dispatch:t})=>{if(e.selection.empty)return!1;if(t){let n=e.tr,{ranges:r}=e.selection,i=e.selection instanceof w?e.selection.$from.marksAcross(e.selection.$to):null,a=n.steps.length;r.forEach(t=>{let r=n.mapping.slice(a),{from:i,to:o}=ll(n.doc.resolve(r.map(t.$from.pos)),n.doc.resolve(r.map(t.$to.pos)),e.schema);n.deleteRange(i,o)}),n.selection.empty||n.setSelection(w.near(n.doc.resolve(n.selection.from))),i&&n.ensureMarks(i),n.scrollIntoView(),t(n)}return!0},dl=()=>({commands:e})=>e.keyboardShortcut(`Enter`),fl=()=>({state:e,dispatch:t})=>cr(e,t);function pl(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function ml(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:pl(t[r])?t[r].test(e[r]):t[r]===e[r])}function hl(e,t,n={}){return e.find(e=>e.type===t&&ml(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function gl(e,t,n={}){return!!hl(e,t,n)}function _l(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!hl([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&gl([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=vl(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=_l(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=w.create(o,e.from,e.to);n.setSelection(t)}}return!0},bl=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(Tl()||wl())&&r.dom.focus(),El()&&!Tl()&&!wl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!xl(n.state.selection))return o(),!0;let s=Cl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Ol=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),kl=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),Al=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&Al(r)}return e};function jl(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return Al(n)}function Ml(e){return typeof e?.nodesBetween==`function`}function Nl(e,t,n){if(Ml(e))return e;let r=typeof e==`object`&&!!e;n={slice:!0,parseOptions:{},...n};let i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return s.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),Nl(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Pe({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?Re.fromSchema(a).parseSlice(jl(e),n.parseOptions):Re.fromSchema(a).parse(jl(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=Re.fromSchema(t);return n.slice?r.parseSlice(jl(e),n.parseOptions).content:r.parse(jl(e),n.parseOptions)}return Nl(``,t,n)}function Pl(e){return!(`type`in e)}function Fl(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(C.near(e.doc.resolve(o),n))}var Il=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{Nl(t,a.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=Nl(t,a.schema,{parseOptions:c,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:l,to:u}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},d=!0,f=!0,p=Pl(i)?i.content:[i];if(p.forEach(e=>{e.check(),d=d?e.isText&&e.marks.length===0:!1,f=f?e.isBlock:!1}),l===u&&f){let{parent:e}=r.doc.resolve(l);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--l,u+=1)}let m;if(d)m=Array.isArray(t)?t.map(e=>e.text||``).join(``):Ml(t)?p.map(e=>e.text??``).join(``):typeof t==`object`&&t&&t.text?t.text:t,r.insertText(m,l,u);else{m=s.from(p);let e=r.doc.resolve(l),t=e.node(),n=e.parentOffset===0,i=t.isText||t.isTextblock,a=t.content.size>0;n&&i&&a&&f&&(l=Math.max(0,l-1)),r.replaceWith(l,u,p)}n.updateSelection&&Fl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:l,text:m}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:l,text:m})}return!0};function Ll(e){for(let t=0;t({tr:t,dispatch:n,editor:r})=>{let{pos:i,attrs:a,content:o,updateSelection:s=!0}=e,c;c=typeof i==`number`?t.doc.resolve(i):i||t.selection.$from;let l=Ll(c.parent.contentMatchAt(c.index()));if(!l)return!1;let u=Object.keys(l.spec.attrs||{}),d=a?Object.fromEntries(Object.entries(a).filter(([e])=>u.includes(e))):{},f;if(o){let e=Nl(o,r.schema);f=l.createAndFill(d,e)}else f=l.createAndFill(d);return f?(n&&(t.insert(c.pos,f),s&&Fl(t,t.steps.length-1,-1)),!0):!1},zl=()=>({state:e,dispatch:t})=>rr(e,t),Bl=()=>({state:e,dispatch:t})=>ir(e,t),Vl=()=>({state:e,dispatch:t})=>Kn(e,t),Hl=()=>({state:e,dispatch:t})=>er(e,t),Ul=(e,t)=>{let n=e.resolve(t),r=n.nodeBefore,i=n.nodeAfter;return!r||!i?!1:!r.type.spec.isolating&&!i.type.spec.isolating},Wl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Zt(e.doc,e.selection.$from.pos,-1);return r==null||!Ul(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Gl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Zt(e.doc,e.selection.$from.pos,1);return r==null||!Ul(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Kl=()=>({state:e,dispatch:t})=>qn(e,t),ql=()=>({state:e,dispatch:t})=>Jn(e,t);function Jl(){return typeof navigator<`u`&&/Mac/.test(navigator.platform)}function Yl(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Yl(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function Zl(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?il(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>!o||o.name===e.node.type.name).filter(e=>ml(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Ql=(e,t={})=>({state:n,dispatch:r})=>Zl(n,il(e,n.schema),t)?ar(n,r):!1,$l=()=>({state:e,dispatch:t})=>ur(e,t),eu=e=>({state:t,dispatch:n})=>jr(il(e,t.schema))(t,n),tu=()=>({state:e,dispatch:t})=>or(e,t);function nu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function ru(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var iu=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=nu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=il(e,r.schema)),s===`mark`&&(o=vl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,ru(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(ru(a.attrs,t))))})})}),c},au=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),ou=()=>({tr:e,dispatch:t})=>{if(t){let t=new On(e.doc);e.setSelection(t)}return!0},su=()=>({state:e,dispatch:t})=>Zn(e,t),cu=()=>({state:e,dispatch:t})=>tr(e,t),lu=()=>({state:e,dispatch:t})=>pr(e,t),uu=()=>({state:e,dispatch:t})=>yr(e,t),du=()=>({state:e,dispatch:t})=>vr(e,t);function fu(e,t,n={},r={}){return Nl(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var pu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=fu(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});if(o){let e=Pl(s)?s.content:[s];a.replaceWith(0,c.content.size,e).setMeta(`preventUpdate`,!n)}return!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function mu(e,t){let n=vl(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function hu(e,t){let n=new xn(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function gu(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function _u(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function vu(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function yu(e){return t=>vu(t.$from,e)}function k(e,t,n){return e.config[t]===void 0&&e.parent?k(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?k(e.parent,t,n):null}):e.config[t]}function bu(e){return e.map(e=>{let t=k(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...bu(t())]:e}).flat(10)}function xu(e,t){let n=Qe.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function Su(e,t){let n=new Map;for(let t of e){let e=n.get(t.type)??new Map;e.set(t.name,t),n.set(t.type,e)}return[...Object.values(t.nodes),...Object.values(t.marks)].flatMap(e=>Object.entries(e.spec.attrs??{}).map(([t,r])=>{let i=n.get(e.name)?.get(t),a=Object.hasOwn(r,`default`);return{type:e.name,name:t,attribute:{rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,...i?.attribute,default:r.default,isRequired:!a,validate:r.validate}}}))}var Cu={content:`string`,marks:`string`,group:`string`,inline:`boolean`,atom:`boolean`,selectable:`boolean`,draggable:`boolean`,code:`boolean`,whitespace:[`pre`,`normal`],definingAsContext:`boolean`,definingForContent:`boolean`,defining:`boolean`,isolating:`boolean`,linebreakReplacement:`boolean`},wu={inclusive:`boolean`,excludes:`string`,group:`string`,spanning:`boolean`,code:`boolean`};function Tu(e,t,n){return Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e[t];if(i===void 0)return[];if(!(typeof r==`string`?typeof i===r:typeof i==`string`&&r.includes(i)))throw RangeError(`Invalid schemaSpec field '${n}.${t}'`);return[[t,i]]}))}function Eu(e,t,n,r){return{...Object.fromEntries(Object.entries(t).filter(([e])=>e!==`attrs`&&!Object.hasOwn(r,e))),...Tu(n,r,e),attrs:n.attrs}}function Du(e,t,n){for(let r of Object.keys(t))if(!Object.hasOwn(e,r))throw RangeError(`schemaSpec requires a local ${n} extension named '${r}'`);for(let r of Object.keys(e))if(!Object.hasOwn(t,r))throw RangeError(`Local ${n} extension '${r}' is not in schemaSpec`)}function Ou(e,t){Du(e.nodes,t.nodes,`node`),Du(e.marks,t.marks,`mark`);let n=t.spec.nodes,r=t.spec.marks;return t.spec.nodes.forEach((t,r)=>{n=n.update(t,Eu(t,e.nodes[t],r,Cu))}),t.spec.marks.forEach((t,n)=>{r=r.update(t,Eu(t,e.marks[t],n,wu))}),{topNode:t.topNodeType.name,nodes:n,marks:r}}function ku(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function Au(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function ju(e){let t=[],{nodeExtensions:n,markExtensions:r}=Au(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=k(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=k(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Mu(e){return typeof e==`function`}function Nu(e,t=void 0,...n){return Mu(e)?t?e.bind(t)(...n):e(...n):e}function Pu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Fu(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}}return n&&t.push(n),t}function Iu(e){let t=[],n=Fu(e||``),r=n.length;for(let e=0;e!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(e===`__proto__`)Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0});else if(!n[e])n[e]=t;else if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...Iu(n[e]),...Iu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Lu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>A(e,t),{})}function Ru(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`||e!==`false`&&e:e}function zu(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Ru(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Bu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Pu(t)?!1:t!=null))}function Vu(e){var t,n;let r={};return!(e!=null&&(t=e.attribute)!=null&&t.isRequired)&&`default`in(e?.attribute||{})&&(r.default=e.attribute.default),(e==null||(n=e.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function Hu(e,t,n=ju(e)){let{nodeExtensions:r,markExtensions:i}=Au(e);return{topNode:r.find(e=>k(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Bu({...e.reduce((e,t)=>{let n=k(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:Nu(k(r,`content`,a)),marks:Nu(k(r,`marks`,a)),group:Nu(k(r,`group`,a)),inline:Nu(k(r,`inline`,a)),atom:Nu(k(r,`atom`,a)),selectable:Nu(k(r,`selectable`,a)),draggable:Nu(k(r,`draggable`,a)),code:Nu(k(r,`code`,a)),whitespace:Nu(k(r,`whitespace`,a)),linebreakReplacement:Nu(k(r,`linebreakReplacement`,a)),defining:Nu(k(r,`defining`,a)),isolating:Nu(k(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Vu))}),s=Nu(k(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>zu(e,i)));let c=k(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Lu(e,i)}));let l=k(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Bu({...e.reduce((e,t)=>{let n=k(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:Nu(k(r,`inclusive`,a)),excludes:Nu(k(r,`excludes`,a)),group:Nu(k(r,`group`,a)),spanning:Nu(k(r,`spanning`,a)),code:Nu(k(r,`code`,a)),attrs:Object.fromEntries(i.map(Vu))}),s=Nu(k(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>zu(e,i)));let c=k(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Lu(e,i)})),[r.name,o]}))}}function Uu(e,t,n){if(n===void 0)return new Pe(Hu(e,t));let r=ku(e.filter(e=>e.type!==`extension`).map(e=>e.name));if(r.length)throw RangeError(`Duplicate local schema types: ${r.join(`, `)}`);let i=new Pe(n);return new Pe(Ou(Hu(e,t,Su(ju(e),i)),i))}function Wu(e){return e.sort((e,t)=>{let n=k(e,`priority`)||100,r=k(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Ku(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=`
-`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;if(e.isText){var d;s+=e==null||(d=e.text)==null?void 0:d.slice(Math.max(r,n)-n,i-n)}}),s}function Ku(e,t){return Gu(e,{from:0,to:e.content.size},t)}function qu(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Ju(e,t){let n=rl(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function Yu(e,t){let n=tu(typeof t==`string`?t:t.name,e.schema);return n===`node`?Ju(e,t):n===`mark`?pu(e,t):{}}function Xu(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Zu(e){let t=Xu(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function Qu(e){let{mapping:t,steps:n}=e,r=[],i=t.invert();return t.maps.forEach((e,a)=>{let o=[];if(e.ranges.length)e.forEach((e,t)=>{o.push({from:e,to:t})});else{let{from:e,to:t}=n[a];if(e===void 0||t===void 0)return;o.push({from:e,to:t})}let s=t.slice(a);o.forEach(({from:e,to:t})=>{let n=s.map(e,-1),a=s.map(t),o=i.map(n,-1),c=i.map(a);r.push({oldRange:{from:o,to:c},newRange:{from:n,to:a}})})}),Zu(r)}function $u(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=gl(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&e?.nodeSize!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var ed=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]},td=e=>{let t=e.depth-1;if(t<0)return null;let n=e.index(t);return n===0?null:e.node(t).child(n-1)};function nd(e,t){return t.nodes[e]||t.marks[e]||null}function rd(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var id=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function ad(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?_l(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!a||a.name===e.type.name).find(e=>pl(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>!a||a.name===e.mark.type.name).filter(e=>pl(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>!a||e.mark.type!==a&&e.mark.type.excludes(a)).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function od(e,t,n={}){if(!t)return Xl(e,null,n)||ad(e,null,n);let r=tu(t,e.schema);return r===`node`?Xl(e,t,n):r===`mark`&&ad(e,t,n)}var sd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=_u(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function ld(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function ud(e,t){let{nodeExtensions:n}=Ou(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=ju(A(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`&&i.split(` `).includes(`list`)}function dd(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(dd(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function fd(e){return e instanceof T}function pd(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.apply==`function`&&typeof t.getMap==`function`&&typeof t.invert==`function`&&typeof t.map==`function`&&typeof t.merge==`function`&&typeof t.toJSON==`function`}function md(e){if(typeof e!=`object`||!e)return!1;let t=e;if(!pd(t))return!1;let n=t.toJSON();return!(typeof n!=`object`||!n||n.stepType!==`replace`)}var hd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function gd(e,t){let n=t.mapping.mapResult(e.position);return{position:new hd(n.pos),mapResult:n}}function _d(e){return new hd(e)}function vd(e,t,n){let{selection:r}=t,i=null;if(bl(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var yd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=_l(e,r.schema);if(i){if(o){let e=pu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})})}return vd(r,n,c)},bd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),xd=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=rl(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>xr(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>xr(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Sd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=xl(e,0,n.content.size),i=T.create(n,r);t.setSelection(i)}return!0},Cd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},wd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=w.atStart(n).from,o=w.atEnd(n).to,s=xl(r,a,o),c=xl(i,a,o),l=w.create(n,s,c);t.setSelection(l)}return!0},Td=e=>({state:t,dispatch:n})=>Pr(rl(e,t.schema))(t,n);function Ed(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var Dd=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=rd(l,s.node().type.name,s.node().attrs);if(a instanceof T&&a.node.isBlock)return!s.parentOffset||!Kt(o,s.pos)?!1:(r&&(e&&Ed(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Il(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=a instanceof w&&!a.empty?Bn.create({doc:t.doc,selection:a}).tr.deleteSelection():null,h=m?m.doc:t.doc,g=m?m.mapping.map(s.pos):s.pos,_=Kt(h,g,1,p);if(!p&&!_&&Kt(h,g,1,f?[{type:f}]:void 0)&&(_=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(_){let e=t.steps.length;if(a instanceof w&&t.deleteSelection(),t.split(t.mapping.slice(e).map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f){let n=t.mapping.slice(e).map(s.before()),r=t.doc.resolve(n);s.node(-1).canReplaceWith(r.index(),r.index()+1,f)&&t.setNodeMarkup(t.mapping.slice(e).map(s.before()),f)}}e&&Ed(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return _},Od=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=rl(e,r.schema),{$from:c,$to:l}=r.selection,u=r.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(l))return!1;let d=c.node(-1);if(d.type!==o)return!1;let f=a.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==o||c.index(-2)!==c.node(-2).childCount-1)return!1;if(i){let e=s.empty,r=c.index(-1)?1:c.index(-2)?2:3;for(let t=c.depth-r;t>=c.depth-3;--t)e=s.from(c.node(t).copy(e));let i=c.indexAfter(-1){if(d>-1)return!1;e.isTextblock&&e.content.size===0&&(d=t+1)}),d>-1&&n.setSelection(w.near(n.doc.resolve(d))),n.scrollIntoView()}return!0}let m=l.pos===c.end()?d.contentMatchAt(0).defaultType:null,h={...rd(f,d.type.name,d.attrs),...t},g={...rd(f,c.node().type.name,c.node().attrs),...t},_=c.parentOffset===0&&c.index(-1)===0,v=c.before(-1);n.delete(c.pos,l.pos);let y=_?d.attrs:h,b=m?[{type:o,attrs:y},{type:m,attrs:g}]:[{type:o,attrs:y}];if(!Kt(n.doc,c.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,s=t||e.$to.parentOffset&&e.$from.marks();if(n.split(c.pos,2,b).scrollIntoView(),_&&n.setNodeMarkup(v,void 0,h),!s||!i)return!0;let l=s.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0};function kd(e,t,n){if(!e.validContent(t))return null;try{return e.create(n,t)}catch{return null}}function Ad(e,t){if(e.pendingContent.length===0)return!0;let n=kd(t,s.from(e.pendingContent));return n?(e.items.push(n),e.pendingContent=[],!0):!1}function jd(e,t,n){return n.validContent(s.from([...t.pendingContent,e]))?(t.pendingContent.push(e),!0):!Ad(t,n)||!n.validContent(s.from(e))?!1:(t.pendingContent.push(e),!0)}function Md(e,t,n,r){let i=r(e,n);if(!i)return!1;let a=kd(n.listType,s.from(i),e.attrs);return a?n.itemType.validContent(s.from([...t.pendingContent,a]))?(t.pendingContent.push(a),!0):Ad(t,n.itemType)?(t.items.push(...i),!0):!1:!1}function Nd(e,t,n){let r={items:[],pendingContent:[]};for(let i=0;ie!==t||(n=r,!1)),n}function Id(e){return!e||e===`1`?null:e}function Ld(e,t){return Id(e)===Id(t)}var Rd=(e,t)=>{let n=_u(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Jt(e.doc,n.pos))||!Ld(n.node.attrs.type,i?.attrs.type)||e.join(n.pos),!0},zd=(e,t)=>{let n=_u(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Jt(e.doc,r))||!Ld(n.node.attrs.type,i?.attrs.type)||e.join(r),!0};function Bd(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return w.between(r,i)}var Vd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:c,chain:l,commands:u,can:d})=>{let{extensions:f,splittableMarks:p}=i.extensionManager,m=rl(e,o.schema),h=rl(t,o.schema),{selection:g,storedMarks:_}=o,{$from:v,$to:y}=g,b=v.blockRange(y),x=_||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;let S=_u(e=>ud(e.type.name,f))(g),ee=g.from===0&&g.to===o.doc.content.size,te=o.doc.content.content,ne=te.length===1?te[0]:null,re=ee&&ne&&ud(ne.type.name,f)?{node:ne,pos:0,depth:0}:null,ie=S??re,ae=!!S&&b.depth>=1&&b.depth-S.depth<=1,oe=!!re;if((ae||oe)&&ie){if(ie.node.type===m)return ee&&oe?l().command(({tr:e,dispatch:t})=>{let n=Bd(e);return n?(e.setSelection(n),t&&t(e),!0):!1}).liftListItem(h).run():u.liftListItem(h);if(ud(ie.node.type.name,f)&&m.validContent(ie.node.content))return l().command(()=>(a.setNodeMarkup(ie.pos,m),!0)).command(()=>Rd(a,m)).command(()=>zd(a,m)).run();if(ud(ie.node.type.name,f)){let e=ie.node.firstChild?.type;if(e&&e!==h){let e=Pd(ie.node,{listType:m,itemType:h,isListNode:e=>ud(e.type.name,f)}),t=e?s.from(e):null;return!t||!m.validContent(t)?!1:l().command(()=>{let{$anchor:e,$head:n}=a.selection,i=e.parent,o=n.parent,s=e.parentOffset,c=n.parentOffset,l;try{l=m.create(r,t)}catch{return!1}if(a.replaceWith(ie.pos,ie.pos+ie.node.nodeSize,l),i.inlineContent&&o.inlineContent){let e=Fd(l,i),t=Fd(l,o);if(e!==null&&t!==null){let n=ie.pos+e+2+s,r=ie.pos+t+2+c;a.setSelection(w.create(a.doc,n,r))}}return!0}).command(()=>Rd(a,m)).command(()=>zd(a,m)).run()}}}return!n||!x||!c?l().command(()=>d().wrapInList(m,r)?!0:u.clearNodes()).wrapInList(m,r).command(()=>Rd(a,m)).command(()=>zd(a,m)).run():l().command(()=>{let e=d().wrapInList(m,r),t=x.filter(e=>p.includes(e.type.name));return a.ensureMarks(t),e?!0:u.clearNodes()}).wrapInList(m,r).command(()=>Rd(a,m)).command(()=>zd(a,m)).run()},Hd=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=_l(e,r.schema);return ad(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Ud=(e,t,n={})=>({state:r,commands:i})=>{let a=rl(e,r.schema),o=rl(t,r.schema),s=Xl(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Wd=(e,t={})=>({state:n,commands:r})=>{let i=rl(e,n.schema);return Xl(n,i,t)?r.lift(i):r.wrapIn(i,t)},Gd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},Kd=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{ignoreClearable:i=!1}=e,{selection:a}=t,{empty:o,ranges:s}=a;if(o)return!0;let{nonClearableMarks:c}=r.extensionManager;if(n){let e=Object.values(r.schema.marks).filter(e=>i||!c.includes(e.name));s.forEach(n=>{for(let r of e)t.removeMark(n.$from.pos,n.$to.pos,r)})}return!0},qd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=_l(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=gl(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Jd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Yd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=tu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=rl(e,r.schema)),s===`mark`&&(o=_l(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Xd=new D(`__tiptap_decorations__`),Zd=e=>({tr:t,dispatch:n})=>(n&&t.setMeta(Xd,{type:`force`,name:e}),!0),Qd=(e,t={})=>({state:n,dispatch:r})=>br(rl(e,n.schema),t)(n,r),$d=(e,t={})=>({state:n,dispatch:r})=>Dr(rl(e,n.schema),t)(n,r),ef=t({blur:()=>Xc,clearContent:()=>Zc,clearNodes:()=>Qc,command:()=>$c,createParagraphNear:()=>el,cut:()=>tl,deleteCurrentNode:()=>nl,deleteNode:()=>il,deleteRange:()=>al,deleteSelection:()=>ll,enter:()=>ul,exitCode:()=>dl,extendMarkRange:()=>vl,first:()=>yl,focus:()=>El,forEach:()=>Dl,insertContent:()=>Ol,insertContentAt:()=>Fl,insertDefaultBlock:()=>Ll,joinBackward:()=>Bl,joinDown:()=>zl,joinForward:()=>Vl,joinItemBackward:()=>Ul,joinItemForward:()=>Wl,joinTextblockBackward:()=>Gl,joinTextblockForward:()=>Kl,joinUp:()=>Rl,keyboardShortcut:()=>Yl,lift:()=>Zl,liftEmptyBlock:()=>Ql,liftListItem:()=>$l,newlineInCode:()=>eu,resetAttributes:()=>ru,scrollIntoView:()=>iu,selectAll:()=>au,selectNodeBackward:()=>ou,selectNodeForward:()=>su,selectParentNode:()=>cu,selectTextblockEnd:()=>lu,selectTextblockStart:()=>uu,setContent:()=>fu,setMark:()=>yd,setMeta:()=>bd,setNode:()=>xd,setNodeSelection:()=>Sd,setTextDirection:()=>Cd,setTextSelection:()=>wd,sinkListItem:()=>Td,splitBlock:()=>Dd,splitListItem:()=>Od,toggleList:()=>Vd,toggleMark:()=>Hd,toggleNode:()=>Ud,toggleWrap:()=>Wd,undoInputRule:()=>Gd,unsetAllMarks:()=>Kd,unsetMark:()=>qd,unsetTextDirection:()=>Jd,updateAttributes:()=>Yd,updateDecorations:()=>Zd,wrapIn:()=>Qd,wrapInList:()=>$d}),tf=new WeakMap;function nf(e,t){tf.set(e,(tf.get(e)??0)+1);try{return t()}finally{let t=(tf.get(e)??1)-1;t>0?tf.set(e,t):tf.delete(e)}}function rf(e){return tf.has(e)}var af=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},of=typeof process<`u`&&!1;function sf(e){return e.kind===`widget`}function cf(e,t){let n=[],r=new Set;for(let i of e)i.kind===`widget`&&sf(i)&&r.add(i.key),n.push(i.toPMDecoration(t));return{decorations:n,widgetKeys:r}}function lf(e,t,n){let{decorations:r,widgetKeys:i}=cf(t,n);return{set:k.create(e,r),widgetKeys:i}}function uf({position:e,from:t,to:n,docSize:r}){return euf({position:e.anchor,from:t,to:n,docSize:r})?!0:(e.anchor===n||a.has(i)||(a.add(i),console.warn(`[tiptap warn]: Extension "${i}" returned a decoration outside the requested range [${t}, ${n}). It was ignored.`)),!1))}function ff(e){let t=e.spec?.key;return typeof t==`string`?t:void 0}function pf(e){let t=new Map,n=new Map;for(let r of e.find()){let e=ff(r);if(!e)continue;let i=r.spec.extensionName??`unknown`,a=t.get(e)??new Set;a.add(i),t.set(e,a),n.set(e,(n.get(e)??0)+1)}return Array.from(t,([e,t])=>({key:e,extensions:t})).filter(({key:e})=>(n.get(e)??0)>1)}function mf(e){return e.jsonID===`attr`}function hf(e){let t=!1;if(e.getMap().forEach(()=>{t=!0}),t||mf(e))return!0;let n=e;return typeof n.from==`number`&&typeof n.to==`number`}function gf(e,t){let n=null,r=0,i=0;for(let a=0;at.to);a+=1){let o=i+e.child(a).nodeSize;o>=t.from&&(n===null&&(n=i),r=o),i=o}return n===null?null:{from:n,to:r}}function _f(e,t){if(e.steps.some(e=>!hf(e)))return{type:`full`};let n=Qu(e).map(({newRange:e})=>e);e.steps.forEach((t,r)=>{if(!mf(t))return;let i=e.mapping.slice(r);n.push({from:i.map(t.pos,-1),to:i.map(t.pos+1)})});let r=[];for(let e of n){let n=gf(t,e);n&&r.push(n)}r.sort((e,t)=>e.from-t.from);let i=[];for(let e of r){let t=i[i.length-1];t&&e.from<=t.to?t.to=Math.max(t.to,e.to):i.push({...e})}return{type:`ranges`,ranges:i}}function vf(e,t,n,r){return e.map(t,n,{onRemove:e=>{let t=e?.key;typeof t==`string`&&r.delete(t)}})}function yf(e,t,n){let r=t.decorationSetsByExtension[e]??k.empty,i=new Set(t.widgetKeysByExtension[e]??[]);return{set:vf(r,n.mapping,n.doc,i),widgetKeys:i}}function bf(e,t){let n=Object.values(t).flatMap(e=>e.find());return k.create(e,n)}function xf(e){let t=new Set;for(let n of Object.values(e))for(let e of n)t.add(e);return t}function Sf(e,t){switch(t.update??`document`){case`document`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" provides createInRange() but does not use the "changedRanges" decoration update strategy.`);return;case`changedRanges`:if(!t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "changedRanges" decoration update strategy but does not provide createInRange().`);return;case`manual`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "manual" decoration update strategy, which is not compatible with createInRange(). createInRange() requires the "changedRanges" strategy.`);if(t.shouldUpdate)throw Error(`[tiptap error]: Extension "${e}" cannot combine the "manual" decoration update strategy with shouldUpdate().`);return;default:throw Error(`[tiptap error]: Extension "${e}" uses an unknown decoration update strategy. Expected "document", "changedRanges", or "manual".`)}}function Cf(e,t,n){return n?!0:e.update===`manual`?!1:e.shouldUpdate?e.shouldUpdate(t):t.tr.docChanged}var wf=new Set,Tf=class{constructor(e){this.warnedWidgetKeys=new Set,this.warnedOutOfRangeExtensions=new Set,this.handleBeforeTransaction=({nextState:e})=>{let t=Xd.getState(e);t&&this.warnDuplicateWidgetKeys(t)},this.editor=e.editor,this.entries=this.resolveEntries(e.entries),this.entries.forEach(({name:e,spec:t})=>Sf(e,t)),this.plugin=this.entries.length>0?this.createPlugin():null,this.editor.on(`beforeTransaction`,this.handleBeforeTransaction)}destroy(){this.editor.off(`beforeTransaction`,this.handleBeforeTransaction)}liveWidgetKeys(){return Xd.getState(this.editor.state)?.widgetKeys??wf}get mountedView(){return this.editor.isDestroyed?null:this.editor.view}resolveEntries(e){let t=[];for(let{name:n,addDecorations:r}of e){let e=r();e&&t.push({name:n,spec:e})}return t}createPlugin(){let{editor:e,entries:t}=this;return new E({key:Xd,state:{init:(e,n)=>{let r={},i={};for(let{name:e,spec:a}of t){let{set:t,widgetKeys:o}=this.buildFullSet(e,a,n);r[e]=t,i[e]=o}let a={decorationSetsByExtension:r,widgetKeysByExtension:i,mergedDecorationSet:this.buildMergedSet(n.doc,r),widgetKeys:xf(i)};return this.warnDuplicateWidgetKeys(a),a},apply:(n,r,i,a)=>{let o=n.getMeta(Xd),s=o?.type===`force`&&!o.name,c=o?.type===`force`?o.name:void 0,l={},u={},d=new Set;return nf(e,()=>{for(let{name:o,spec:f}of t){let t=s||c===o;if(!Cf(f,{editor:e,tr:n,oldState:i,newState:a},t)){let e=yf(o,r,n);l[o]=e.set,u[o]=e.widgetKeys}else if(f.update===`changedRanges`&&n.docChanged&&!t){let e=this.applyChangedRangesRecompute(o,f,r,n,a);l[o]=e.set,u[o]=e.widgetKeys,d.add(o)}else{let{set:e,widgetKeys:t}=this.buildFullSet(o,f,a);l[o]=e,u[o]=t,d.add(o)}}}),d.size===0&&!n.docChanged?r:{decorationSetsByExtension:l,widgetKeysByExtension:u,mergedDecorationSet:this.mergeAfterApply({entries:t,previous:r,tr:n,decorationSetsByExtension:l,recomputedNames:d}),widgetKeys:xf(u)}}},props:{decorations(e){return Xd.getState(e)?.mergedDecorationSet??k.empty}}})}applyChangedRangesRecompute(e,t,n,r,i){let a=_f(r,i.doc);return a.type===`full`?this.buildFullSet(e,t,i):this.rebuildRanges(e,t,n,r,i,a.ranges)}rebuildRanges(e,t,n,r,i,a){let o=n.decorationSetsByExtension[e]??k.empty,s=new Set(n.widgetKeysByExtension[e]??[]),c=vf(o,r.mapping,r.doc,s),l=i.doc.content.size;for(let{from:n,to:r}of a){let a=c.find(n,r).filter(e=>uf({position:e.from,from:n,to:r,docSize:l}));for(let e of a){let t=ff(e);t&&s.delete(t)}c=c.remove(a);let{decorations:o,widgetKeys:u}=cf(df({decorations:this.runCreate(e,`createInRange`,()=>t.createInRange({editor:this.editor,state:i,view:this.mountedView,from:n,to:r})),from:n,to:r,docSize:l,extensionName:e,warnedExtensions:this.warnedOutOfRangeExtensions}),e);c=c.add(i.doc,o);for(let e of u)s.add(e)}return{set:c,widgetKeys:s}}buildFullSet(e,t,n){let r=this.runCreate(e,`create`,()=>t.create({editor:this.editor,state:n,view:this.mountedView}));return lf(n.doc,r,e)}runCreate(e,t,n){try{return n()}catch(n){return console.error(`[tiptap error]: Extension "${e}" threw in \`addDecorations().${t}()\`. Its decorations were dropped for this update.`,n),[]}}warnDuplicateWidgetKeys(e){if(!of)return;if(e.widgetKeys.size===0){this.warnedWidgetKeys.clear();return}let t=pf(e.mergedDecorationSet),n=new Set(t.map(({key:e})=>e));for(let{key:e,extensions:n}of t){if(this.warnedWidgetKeys.has(e))continue;let t=Array.from(n).map(e=>`"${e}"`).join(`, `);console.warn(`[tiptap warn]: Duplicate widget decoration key "${e}" in extension${n.size===1?``:`s`} ${t}. Widget decoration keys must be globally unique, otherwise ProseMirror misplaces the widget DOM. Use a stable, unique key (e.g. \`comment-\${id}\`).`)}this.warnedWidgetKeys=n}buildMergedSet(e,t){let n=Object.keys(t);return n.length===1?t[n[0]]:bf(e,t)}mergeAfterApply({entries:e,previous:t,tr:n,decorationSetsByExtension:r,recomputedNames:i}){return e.length===1?r[e[0].name]:i.size===0?t.mergedDecorationSet.map(n.mapping,n.doc):bf(n.doc,r)}};function Ef(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof T){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function Df(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}function Of(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function kf(e){return typeof e==`number`}function Af(e){return Object.prototype.toString.call(e).slice(8,-1)}function jf(e){return Af(e)===`Object`&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Mf(e){return typeof e==`string`&&e.trim().length>0&&!/[;{}]/.test(e)}function Nf(e){return/\s/.test(e)}function Pf(e){return/^[a-zA-Z]$/.test(e)}function Ff(e){return/^\w$/.test(e)}function If(e,t){for(;t=e.length));){let i=Uf(e,r,t);i.token&&n.push(i.token),r=i.nextIndex}return n}function Gf(e){let t={};return Wf(e,`shortcode`).forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),t}function Kf(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function qf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Gf,serializeAttributes:a=Kf,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=u(e.attrs||{}),i=a(n),o=i?` ${i}`:``;return s?`[${l}${o}]`:`[${l}${o}]${t}[/${l}]`}}}function Jf(e,t){return e.replace(/^[ \t]*/,e=>{let n=0;for(let t of e)n+=t===` `?4-n%4:1;return` `.repeat(Math.max(0,n-t))})}function Yf(e,t){let n=`text\n${e}\n`,r=t(n)[0];return(r?.type===`paragraph`||r?.type===`text`)&&r.raw===n}function Xf(e,t,n){let r=t.split(`
-`),i=n.isParagraphContinuation??(e=>Yf(e,n.blockTokens)),a=0;for(let e of r){if(!e.trim()||!i(e))break;a+=1}return{mainContent:[e,...r.slice(0,a).map(e=>e.trimStart())].join(`
+`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;if(e.isText){var d;s+=e==null||(d=e.text)==null?void 0:d.slice(Math.max(r,n)-n,i-n)}}),s}function qu(e,t){return Ku(e,{from:0,to:e.content.size},t)}function Ju(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Yu(e,t){let n=il(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function Xu(e,t){let n=nu(typeof t==`string`?t:t.name,e.schema);return n===`node`?Yu(e,t):n===`mark`?mu(e,t):{}}function Zu(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Qu(e){let t=Zu(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function $u(e){let{mapping:t,steps:n}=e,r=[],i=t.invert();return t.maps.forEach((e,a)=>{let o=[];if(e.ranges.length)e.forEach((e,t)=>{o.push({from:e,to:t})});else{let{from:e,to:t}=n[a];if(e===void 0||t===void 0)return;o.push({from:e,to:t})}let s=t.slice(a);o.forEach(({from:e,to:t})=>{let n=s.map(e,-1),a=s.map(t),o=i.map(n,-1),c=i.map(a);r.push({oldRange:{from:o,to:c},newRange:{from:n,to:a}})})}),Qu(r)}function ed(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=_l(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&e?.nodeSize!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var td=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]},nd=e=>{let t=e.depth-1;if(t<0)return null;let n=e.index(t);return n===0?null:e.node(t).child(n-1)};function rd(e,t){return t.nodes[e]||t.marks[e]||null}function id(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var ad=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function od(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?vl(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!a||a.name===e.type.name).find(e=>ml(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>!a||a.name===e.mark.type.name).filter(e=>ml(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>!a||e.mark.type!==a&&e.mark.type.excludes(a)).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function sd(e,t,n={}){if(!t)return Zl(e,null,n)||od(e,null,n);let r=nu(t,e.schema);return r===`node`?Zl(e,t,n):r===`mark`&&od(e,t,n)}var cd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=yu(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function ud(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function dd(e,t){let{nodeExtensions:n}=Au(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=Nu(k(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`&&i.split(` `).includes(`list`)}function fd(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(fd(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function pd(e){return e instanceof T}function md(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.apply==`function`&&typeof t.getMap==`function`&&typeof t.invert==`function`&&typeof t.map==`function`&&typeof t.merge==`function`&&typeof t.toJSON==`function`}function hd(e){if(typeof e!=`object`||!e)return!1;let t=e;if(!md(t))return!1;let n=t.toJSON();return!(typeof n!=`object`||!n||n.stepType!==`replace`)}var gd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function _d(e,t){let n=t.mapping.mapResult(e.position);return{position:new gd(n.pos),mapResult:n}}function vd(e){return new gd(e)}function yd(e,t,n){let{selection:r}=t,i=null;if(xl(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var bd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=vl(e,r.schema);if(i){if(o){let e=mu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})})}return yd(r,n,c)},xd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Sd=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=il(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>xr(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>xr(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Cd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=Sl(e,0,n.content.size),i=T.create(n,r);t.setSelection(i)}return!0},wd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},Td=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=w.atStart(n).from,o=w.atEnd(n).to,s=Sl(r,a,o),c=Sl(i,a,o),l=w.create(n,s,c);t.setSelection(l)}return!0},Ed=e=>({state:t,dispatch:n})=>Pr(il(e,t.schema))(t,n);function Dd(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var Od=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=id(l,s.node().type.name,s.node().attrs);if(a instanceof T&&a.node.isBlock)return!s.parentOffset||!Kt(o,s.pos)?!1:(r&&(e&&Dd(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Ll(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=a instanceof w&&!a.empty?Bn.create({doc:t.doc,selection:a}).tr.deleteSelection():null,h=m?m.doc:t.doc,g=m?m.mapping.map(s.pos):s.pos,_=Kt(h,g,1,p);if(!p&&!_&&Kt(h,g,1,f?[{type:f}]:void 0)&&(_=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(_){let e=t.steps.length;if(a instanceof w&&t.deleteSelection(),t.split(t.mapping.slice(e).map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f){let n=t.mapping.slice(e).map(s.before()),r=t.doc.resolve(n);s.node(-1).canReplaceWith(r.index(),r.index()+1,f)&&t.setNodeMarkup(t.mapping.slice(e).map(s.before()),f)}}e&&Dd(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return _},kd=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=il(e,r.schema),{$from:c,$to:l}=r.selection,u=r.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(l))return!1;let d=c.node(-1);if(d.type!==o)return!1;let f=a.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==o||c.index(-2)!==c.node(-2).childCount-1)return!1;if(i){let e=s.empty,r=c.index(-1)?1:c.index(-2)?2:3;for(let t=c.depth-r;t>=c.depth-3;--t)e=s.from(c.node(t).copy(e));let i=c.indexAfter(-1){if(d>-1)return!1;e.isTextblock&&e.content.size===0&&(d=t+1)}),d>-1&&n.setSelection(w.near(n.doc.resolve(d))),n.scrollIntoView()}return!0}let m=l.pos===c.end()?d.contentMatchAt(0).defaultType:null,h={...id(f,d.type.name,d.attrs),...t},g={...id(f,c.node().type.name,c.node().attrs),...t},_=c.parentOffset===0&&c.index(-1)===0,v=c.before(-1);n.delete(c.pos,l.pos);let y=_?d.attrs:h,b=m?[{type:o,attrs:y},{type:m,attrs:g}]:[{type:o,attrs:y}];if(!Kt(n.doc,c.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,s=t||e.$to.parentOffset&&e.$from.marks();if(n.split(c.pos,2,b).scrollIntoView(),_&&n.setNodeMarkup(v,void 0,h),!s||!i)return!0;let l=s.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0};function Ad(e,t,n){if(!e.validContent(t))return null;try{return e.create(n,t)}catch{return null}}function jd(e,t){if(e.pendingContent.length===0)return!0;let n=Ad(t,s.from(e.pendingContent));return n?(e.items.push(n),e.pendingContent=[],!0):!1}function Md(e,t,n){return n.validContent(s.from([...t.pendingContent,e]))?(t.pendingContent.push(e),!0):!jd(t,n)||!n.validContent(s.from(e))?!1:(t.pendingContent.push(e),!0)}function Nd(e,t,n,r){let i=r(e,n);if(!i)return!1;let a=Ad(n.listType,s.from(i),e.attrs);return a?n.itemType.validContent(s.from([...t.pendingContent,a]))?(t.pendingContent.push(a),!0):jd(t,n.itemType)?(t.items.push(...i),!0):!1:!1}function Pd(e,t,n){let r={items:[],pendingContent:[]};for(let i=0;ie!==t||(n=r,!1)),n}function Ld(e){return!e||e===`1`?null:e}function Rd(e,t){return Ld(e)===Ld(t)}var zd=(e,t)=>{let n=yu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Jt(e.doc,n.pos))||!Rd(n.node.attrs.type,i?.attrs.type)||e.join(n.pos),!0},Bd=(e,t)=>{let n=yu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&Jt(e.doc,r))||!Rd(n.node.attrs.type,i?.attrs.type)||e.join(r),!0};function Vd(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return w.between(r,i)}var Hd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:c,chain:l,commands:u,can:d})=>{let{extensions:f,splittableMarks:p}=i.extensionManager,m=il(e,o.schema),h=il(t,o.schema),{selection:g,storedMarks:_}=o,{$from:v,$to:y}=g,b=v.blockRange(y),x=_||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;let S=yu(e=>dd(e.type.name,f))(g),ee=g.from===0&&g.to===o.doc.content.size,te=o.doc.content.content,ne=te.length===1?te[0]:null,re=ee&&ne&&dd(ne.type.name,f)?{node:ne,pos:0,depth:0}:null,ie=S??re,ae=!!S&&b.depth>=1&&b.depth-S.depth<=1,oe=!!re;if((ae||oe)&&ie){if(ie.node.type===m)return ee&&oe?l().command(({tr:e,dispatch:t})=>{let n=Vd(e);return n?(e.setSelection(n),t&&t(e),!0):!1}).liftListItem(h).run():u.liftListItem(h);if(dd(ie.node.type.name,f)&&m.validContent(ie.node.content))return l().command(()=>(a.setNodeMarkup(ie.pos,m),!0)).command(()=>zd(a,m)).command(()=>Bd(a,m)).run();if(dd(ie.node.type.name,f)){let e=ie.node.firstChild?.type;if(e&&e!==h){let e=Fd(ie.node,{listType:m,itemType:h,isListNode:e=>dd(e.type.name,f)}),t=e?s.from(e):null;return!t||!m.validContent(t)?!1:l().command(()=>{let{$anchor:e,$head:n}=a.selection,i=e.parent,o=n.parent,s=e.parentOffset,c=n.parentOffset,l;try{l=m.create(r,t)}catch{return!1}if(a.replaceWith(ie.pos,ie.pos+ie.node.nodeSize,l),i.inlineContent&&o.inlineContent){let e=Id(l,i),t=Id(l,o);if(e!==null&&t!==null){let n=ie.pos+e+2+s,r=ie.pos+t+2+c;a.setSelection(w.create(a.doc,n,r))}}return!0}).command(()=>zd(a,m)).command(()=>Bd(a,m)).run()}}}return!n||!x||!c?l().command(()=>d().wrapInList(m,r)?!0:u.clearNodes()).wrapInList(m,r).command(()=>zd(a,m)).command(()=>Bd(a,m)).run():l().command(()=>{let e=d().wrapInList(m,r),t=x.filter(e=>p.includes(e.type.name));return a.ensureMarks(t),e?!0:u.clearNodes()}).wrapInList(m,r).command(()=>zd(a,m)).command(()=>Bd(a,m)).run()},Ud=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=vl(e,r.schema);return od(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Wd=(e,t,n={})=>({state:r,commands:i})=>{let a=il(e,r.schema),o=il(t,r.schema),s=Zl(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Gd=(e,t={})=>({state:n,commands:r})=>{let i=il(e,n.schema);return Zl(n,i,t)?r.lift(i):r.wrapIn(i,t)},Kd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},qd=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{ignoreClearable:i=!1}=e,{selection:a}=t,{empty:o,ranges:s}=a;if(o)return!0;let{nonClearableMarks:c}=r.extensionManager;if(n){let e=Object.values(r.schema.marks).filter(e=>i||!c.includes(e.name));s.forEach(n=>{for(let r of e)t.removeMark(n.$from.pos,n.$to.pos,r)})}return!0},Jd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=vl(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=_l(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Yd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Xd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=nu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=il(e,r.schema)),s===`mark`&&(o=vl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Zd=new D(`__tiptap_decorations__`),Qd=e=>({tr:t,dispatch:n})=>(n&&t.setMeta(Zd,{type:`force`,name:e}),!0),$d=(e,t={})=>({state:n,dispatch:r})=>br(il(e,n.schema),t)(n,r),ef=(e,t={})=>({state:n,dispatch:r})=>Dr(il(e,n.schema),t)(n,r),tf=t({blur:()=>Zc,clearContent:()=>Qc,clearNodes:()=>$c,command:()=>el,createParagraphNear:()=>tl,cut:()=>nl,deleteCurrentNode:()=>rl,deleteNode:()=>al,deleteRange:()=>ol,deleteSelection:()=>ul,enter:()=>dl,exitCode:()=>fl,extendMarkRange:()=>yl,first:()=>bl,focus:()=>Dl,forEach:()=>Ol,insertContent:()=>kl,insertContentAt:()=>Il,insertDefaultBlock:()=>Rl,joinBackward:()=>Vl,joinDown:()=>Bl,joinForward:()=>Hl,joinItemBackward:()=>Wl,joinItemForward:()=>Gl,joinTextblockBackward:()=>Kl,joinTextblockForward:()=>ql,joinUp:()=>zl,keyboardShortcut:()=>Xl,lift:()=>Ql,liftEmptyBlock:()=>$l,liftListItem:()=>eu,newlineInCode:()=>tu,resetAttributes:()=>iu,scrollIntoView:()=>au,selectAll:()=>ou,selectNodeBackward:()=>su,selectNodeForward:()=>cu,selectParentNode:()=>lu,selectTextblockEnd:()=>uu,selectTextblockStart:()=>du,setContent:()=>pu,setMark:()=>bd,setMeta:()=>xd,setNode:()=>Sd,setNodeSelection:()=>Cd,setTextDirection:()=>wd,setTextSelection:()=>Td,sinkListItem:()=>Ed,splitBlock:()=>Od,splitListItem:()=>kd,toggleList:()=>Hd,toggleMark:()=>Ud,toggleNode:()=>Wd,toggleWrap:()=>Gd,undoInputRule:()=>Kd,unsetAllMarks:()=>qd,unsetMark:()=>Jd,unsetTextDirection:()=>Yd,updateAttributes:()=>Xd,updateDecorations:()=>Qd,wrapIn:()=>$d,wrapInList:()=>ef}),nf=new WeakMap;function rf(e,t){nf.set(e,(nf.get(e)??0)+1);try{return t()}finally{let t=(nf.get(e)??1)-1;t>0?nf.set(e,t):nf.delete(e)}}function af(e){return nf.has(e)}var of=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},sf=typeof process<`u`&&!1;function cf(e){return e.kind===`widget`}function lf(e,t){let n=[],r=new Set;for(let i of e)i.kind===`widget`&&cf(i)&&r.add(i.key),n.push(i.toPMDecoration(t));return{decorations:n,widgetKeys:r}}function uf(e,t,n){let{decorations:r,widgetKeys:i}=lf(t,n);return{set:xs.create(e,r),widgetKeys:i}}function df({position:e,from:t,to:n,docSize:r}){return edf({position:e.anchor,from:t,to:n,docSize:r})?!0:(e.anchor===n||a.has(i)||(a.add(i),console.warn(`[tiptap warn]: Extension "${i}" returned a decoration outside the requested range [${t}, ${n}). It was ignored.`)),!1))}function pf(e){let t=e.spec?.key;return typeof t==`string`?t:void 0}function mf(e){let t=new Map,n=new Map;for(let r of e.find()){let e=pf(r);if(!e)continue;let i=r.spec.extensionName??`unknown`,a=t.get(e)??new Set;a.add(i),t.set(e,a),n.set(e,(n.get(e)??0)+1)}return Array.from(t,([e,t])=>({key:e,extensions:t})).filter(({key:e})=>(n.get(e)??0)>1)}function hf(e){return e.jsonID===`attr`}function gf(e){let t=!1;if(e.getMap().forEach(()=>{t=!0}),t||hf(e))return!0;let n=e;return typeof n.from==`number`&&typeof n.to==`number`}function _f(e,t){let n=null,r=0,i=0;for(let a=0;at.to);a+=1){let o=i+e.child(a).nodeSize;o>=t.from&&(n===null&&(n=i),r=o),i=o}return n===null?null:{from:n,to:r}}function vf(e,t){if(e.steps.some(e=>!gf(e)))return{type:`full`};let n=$u(e).map(({newRange:e})=>e);e.steps.forEach((t,r)=>{if(!hf(t))return;let i=e.mapping.slice(r);n.push({from:i.map(t.pos,-1),to:i.map(t.pos+1)})});let r=[];for(let e of n){let n=_f(t,e);n&&r.push(n)}r.sort((e,t)=>e.from-t.from);let i=[];for(let e of r){let t=i[i.length-1];t&&e.from<=t.to?t.to=Math.max(t.to,e.to):i.push({...e})}return{type:`ranges`,ranges:i}}function yf(e,t,n,r){return e.map(t,n,{onRemove:e=>{let t=e?.key;typeof t==`string`&&r.delete(t)}})}function bf(e,t,n){let r=t.decorationSetsByExtension[e]??xs.empty,i=new Set(t.widgetKeysByExtension[e]??[]);return{set:yf(r,n.mapping,n.doc,i),widgetKeys:i}}function xf(e,t){let n=Object.values(t).flatMap(e=>e.find());return xs.create(e,n)}function Sf(e){let t=new Set;for(let n of Object.values(e))for(let e of n)t.add(e);return t}function Cf(e,t){switch(t.update??`document`){case`document`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" provides createInRange() but does not use the "changedRanges" decoration update strategy.`);return;case`changedRanges`:if(!t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "changedRanges" decoration update strategy but does not provide createInRange().`);return;case`manual`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "manual" decoration update strategy, which is not compatible with createInRange(). createInRange() requires the "changedRanges" strategy.`);if(t.shouldUpdate)throw Error(`[tiptap error]: Extension "${e}" cannot combine the "manual" decoration update strategy with shouldUpdate().`);return;default:throw Error(`[tiptap error]: Extension "${e}" uses an unknown decoration update strategy. Expected "document", "changedRanges", or "manual".`)}}function wf(e,t,n){return n?!0:e.update===`manual`?!1:e.shouldUpdate?e.shouldUpdate(t):t.tr.docChanged}var Tf=new Set,Ef=class{constructor(e){this.warnedWidgetKeys=new Set,this.warnedOutOfRangeExtensions=new Set,this.handleBeforeTransaction=({nextState:e})=>{let t=Zd.getState(e);t&&this.warnDuplicateWidgetKeys(t)},this.editor=e.editor,this.entries=this.resolveEntries(e.entries),this.entries.forEach(({name:e,spec:t})=>Cf(e,t)),this.plugin=this.entries.length>0?this.createPlugin():null,this.editor.on(`beforeTransaction`,this.handleBeforeTransaction)}destroy(){this.editor.off(`beforeTransaction`,this.handleBeforeTransaction)}liveWidgetKeys(){return Zd.getState(this.editor.state)?.widgetKeys??Tf}get mountedView(){return this.editor.isDestroyed?null:this.editor.view}resolveEntries(e){let t=[];for(let{name:n,addDecorations:r}of e){let e=r();e&&t.push({name:n,spec:e})}return t}createPlugin(){let{editor:e,entries:t}=this;return new E({key:Zd,state:{init:(e,n)=>{let r={},i={};for(let{name:e,spec:a}of t){let{set:t,widgetKeys:o}=this.buildFullSet(e,a,n);r[e]=t,i[e]=o}let a={decorationSetsByExtension:r,widgetKeysByExtension:i,mergedDecorationSet:this.buildMergedSet(n.doc,r),widgetKeys:Sf(i)};return this.warnDuplicateWidgetKeys(a),a},apply:(n,r,i,a)=>{let o=n.getMeta(Zd),s=o?.type===`force`&&!o.name,c=o?.type===`force`?o.name:void 0,l={},u={},d=new Set;return rf(e,()=>{for(let{name:o,spec:f}of t){let t=s||c===o;if(!wf(f,{editor:e,tr:n,oldState:i,newState:a},t)){let e=bf(o,r,n);l[o]=e.set,u[o]=e.widgetKeys}else if(f.update===`changedRanges`&&n.docChanged&&!t){let e=this.applyChangedRangesRecompute(o,f,r,n,a);l[o]=e.set,u[o]=e.widgetKeys,d.add(o)}else{let{set:e,widgetKeys:t}=this.buildFullSet(o,f,a);l[o]=e,u[o]=t,d.add(o)}}}),d.size===0&&!n.docChanged?r:{decorationSetsByExtension:l,widgetKeysByExtension:u,mergedDecorationSet:this.mergeAfterApply({entries:t,previous:r,tr:n,decorationSetsByExtension:l,recomputedNames:d}),widgetKeys:Sf(u)}}},props:{decorations(e){return Zd.getState(e)?.mergedDecorationSet??xs.empty}}})}applyChangedRangesRecompute(e,t,n,r,i){let a=vf(r,i.doc);return a.type===`full`?this.buildFullSet(e,t,i):this.rebuildRanges(e,t,n,r,i,a.ranges)}rebuildRanges(e,t,n,r,i,a){let o=n.decorationSetsByExtension[e]??xs.empty,s=new Set(n.widgetKeysByExtension[e]??[]),c=yf(o,r.mapping,r.doc,s),l=i.doc.content.size;for(let{from:n,to:r}of a){let a=c.find(n,r).filter(e=>df({position:e.from,from:n,to:r,docSize:l}));for(let e of a){let t=pf(e);t&&s.delete(t)}c=c.remove(a);let{decorations:o,widgetKeys:u}=lf(ff({decorations:this.runCreate(e,`createInRange`,()=>t.createInRange({editor:this.editor,state:i,view:this.mountedView,from:n,to:r})),from:n,to:r,docSize:l,extensionName:e,warnedExtensions:this.warnedOutOfRangeExtensions}),e);c=c.add(i.doc,o);for(let e of u)s.add(e)}return{set:c,widgetKeys:s}}buildFullSet(e,t,n){let r=this.runCreate(e,`create`,()=>t.create({editor:this.editor,state:n,view:this.mountedView}));return uf(n.doc,r,e)}runCreate(e,t,n){try{return n()}catch(n){return console.error(`[tiptap error]: Extension "${e}" threw in \`addDecorations().${t}()\`. Its decorations were dropped for this update.`,n),[]}}warnDuplicateWidgetKeys(e){if(!sf)return;if(e.widgetKeys.size===0){this.warnedWidgetKeys.clear();return}let t=mf(e.mergedDecorationSet),n=new Set(t.map(({key:e})=>e));for(let{key:e,extensions:n}of t){if(this.warnedWidgetKeys.has(e))continue;let t=Array.from(n).map(e=>`"${e}"`).join(`, `);console.warn(`[tiptap warn]: Duplicate widget decoration key "${e}" in extension${n.size===1?``:`s`} ${t}. Widget decoration keys must be globally unique, otherwise ProseMirror misplaces the widget DOM. Use a stable, unique key (e.g. \`comment-\${id}\`).`)}this.warnedWidgetKeys=n}buildMergedSet(e,t){let n=Object.keys(t);return n.length===1?t[n[0]]:xf(e,t)}mergeAfterApply({entries:e,previous:t,tr:n,decorationSetsByExtension:r,recomputedNames:i}){return e.length===1?r[e[0].name]:i.size===0?t.mergedDecorationSet.map(n.mapping,n.doc):xf(n.doc,r)}};function Df(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof T){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function Of(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}function kf(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function Af(e){return typeof e==`number`}function jf(e){return Object.prototype.toString.call(e).slice(8,-1)}function Mf(e){return jf(e)===`Object`&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Nf(e){return typeof e==`string`&&e.trim().length>0&&!/[;{}]/.test(e)}function Pf(e){return/\s/.test(e)}function Ff(e){return/^[a-zA-Z]$/.test(e)}function If(e){return/^\w$/.test(e)}function Lf(e,t){for(;t=e.length));){let i=Wf(e,r,t);i.token&&n.push(i.token),r=i.nextIndex}return n}function Kf(e){let t={},n=e.filter(e=>e.type===`class`).map(e=>e.name),r=e.find(e=>e.type===`id`);return n.length>0&&(t.class=n.join(` `)),r&&(t.id=r.name),e.forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),e.forEach(e=>{e.type===`boolean`&&(t[e.name]=!0)}),t}function qf(e){return e?.trim()?Kf(Gf(e,`pandoc`)):{}}function Jf(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e!==`class`&&e!==`id`&&(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function Yf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=qf,serializeAttributes:a=Jf,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m){if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m)}return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=u(e.attrs||{}),r=a(n),i=r?` {${r}}`:``,o=t.renderChildren(e.content||[],`
+
+`);return`:::${l}${i}\n\n${o}\n\n:::`}}}function Xf(e){let t={};return Gf(e,`shortcode`).forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),t}function Zf(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function Qf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Xf,serializeAttributes:a=Zf,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=u(e.attrs||{}),i=a(n),o=i?` ${i}`:``;return s?`[${l}${o}]`:`[${l}${o}]${t}[/${l}]`}}}function $f(e,t){return e.replace(/^[ \t]*/,e=>{let n=0;for(let t of e)n+=t===` `?4-n%4:1;return` `.repeat(Math.max(0,n-t))})}function ep(e,t){let n=`text\n${e}\n`,r=t(n)[0];return(r?.type===`paragraph`||r?.type===`text`)&&r.raw===n}function tp(e,t,n){let r=t.split(`
+`),i=n.isParagraphContinuation??(e=>ep(e,n.blockTokens)),a=0;for(let e of r){if(!e.trim()||!i(e))break;a+=1}return{mainContent:[e,...r.slice(0,a).map(e=>e.trimStart())].join(`
`),nestedContent:r.slice(a).join(`
-`)}}function Zf(e,t,n){let r=e.split(`
-`),i=[],a=``,o=0,s=t.baseIndentSize||2;for(;o0)break;if(e.trim()===``){o+=1,a=`${a}${e}\n`;continue}return}let d=t.extractItemData(u),{indentLevel:f,mainContent:p}=d;a=`${a}${e}\n`;let m=[p];for(o+=1;oe.trim()!==``);if(t===-1)break;if((((l=r[o+1+t].match(/^(\s*)/))==null||(l=l[1])==null?void 0:l.length)||0)>f){m.push(e),a=`${a}${e}\n`,o+=1;continue}break}if((((c=e.match(/^(\s*)/))==null||(c=c[1])==null?void 0:c.length)||0)>f)m.push(e),a=`${a}${e}\n`,o+=1;else break}let h,g=m.slice(1);if(g.length>0){let e=Xf(p,g.map(e=>Jf(e,f+s)).join(`
-`),n);d.mainContent=e.mainContent;let r=e.nestedContent;r.trim()&&(h=t.customNestedParser?t.customNestedParser(r):n.blockTokens(r))}let _=t.createToken(d,h);i.push(_)}if(i.length!==0)return{items:i,raw:a.slice(0,e.length)}}var Qf=4;function $f(e){let t=0;for(let n of e)t=n===` `?t+Qf-t%Qf:t+1;return t}function ep(e,t,n,r,i){if(!e||!Array.isArray(e.content))return``;let a=typeof n==`function`?n(r):n,[o,...s]=e.content,c=t.renderChildren([o]),l=`${a}${i?.indentMainContent?c.split(`
+`)}}function np(e,t,n){let r=e.split(`
+`),i=[],a=``,o=0,s=t.baseIndentSize||2;for(;o0)break;if(e.trim()===``){o+=1,a=`${a}${e}\n`;continue}return}let d=t.extractItemData(u),{indentLevel:f,mainContent:p}=d;a=`${a}${e}\n`;let m=[p];for(o+=1;oe.trim()!==``);if(t===-1)break;if((((l=r[o+1+t].match(/^(\s*)/))==null||(l=l[1])==null?void 0:l.length)||0)>f){m.push(e),a=`${a}${e}\n`,o+=1;continue}break}if((((c=e.match(/^(\s*)/))==null||(c=c[1])==null?void 0:c.length)||0)>f)m.push(e),a=`${a}${e}\n`,o+=1;else break}let h,g=m.slice(1);if(g.length>0){let e=tp(p,g.map(e=>$f(e,f+s)).join(`
+`),n);d.mainContent=e.mainContent;let r=e.nestedContent;r.trim()&&(h=t.customNestedParser?t.customNestedParser(r):n.blockTokens(r))}let _=t.createToken(d,h);i.push(_)}if(i.length!==0)return{items:i,raw:a.slice(0,e.length)}}var rp=4;function ip(e){let t=0;for(let n of e)t=n===` `?t+rp-t%rp:t+1;return t}function ap(e,t,n,r,i){if(!e||!Array.isArray(e.content))return``;let a=typeof n==`function`?n(r):n,[o,...s]=e.content,c=t.renderChildren([o]),l=`${a}${i?.indentMainContent?c.split(`
`).map((e,n)=>n===0?e:t.indent(e)).join(`
-`):c}`;return s&&s.length>0&&s.forEach((e,n)=>{let r=t.renderChild?.call(t,e,n+1)??t.renderChildren([e]);if(r!=null){let n=e=>{if(!i?.alignNestedToPrefix)return t.indent(e);let n=t.indent(``),r=$f(a);return($f(n)>=r?n:` `.repeat(r))+e},o=r.split(`
+`):c}`;return s&&s.length>0&&s.forEach((e,n)=>{let r=t.renderChild?.call(t,e,n+1)??t.renderChildren([e]);if(r!=null){let n=e=>{if(!i?.alignNestedToPrefix)return t.indent(e);let n=t.indent(``),r=ip(a);return(ip(n)>=r?n:` `.repeat(r))+e},o=r.split(`
`).map(e=>n(e||``)).join(`
-`);l+=e.type===`paragraph`?`\n\n${o}`:`\n${o}`}}),l}function tp(e,t){let n={...e};return jf(e)&&jf(t)&&Object.keys(t).forEach(r=>{jf(t[r])&&jf(e[r])?n[r]=tp(e[r],t[r]):n[r]=t[r]}),n}function np(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var rp=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},ip=(e,t)=>{if(fl(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function ap(e){let{editor:t,from:n,to:r,text:i,insertText:a}=e;if(!a)return{inputTransaction:null,tr:t.view.state.tr};let o=t.view.state.tr.insertText(i,n,r);return{inputTransaction:o,tr:Bn.create({doc:o.doc,selection:o.selection,storedMarks:o.storedMarks}).tr}}function op(e){let{editor:t,from:n,to:r,text:i,rule:a,match:o,plugin:s,insertText:c}=e,{view:l}=t,{inputTransaction:u,tr:d}=ap({editor:t,from:n,to:r,text:i,insertText:c}),f=u?n+i.length:r,p=Jc({state:l.state,transaction:d}),m={from:n-(o[0].length-i.length),to:f},{commands:h,chain:g,can:_}=new Yc({editor:t,state:p});return a.handler({state:p,range:m,match:o,commands:h,chain:g,can:_})===null||!d.steps.length?!1:(u&&(l.dispatch(u),!l.state.doc.eq(u.doc))||(Bc(d),d.setMeta(`inputRule`,!0),a.undoable&&d.setMeta(s,{transform:d,from:n,to:f,text:i}),l.dispatch(d)),!0)}function sp(e,t,n){let r=t[0].length-n.length;if(r<=0)return!0;let i=e.parentOffset-r;return i>=0&&e.parent.textBetween(i,e.parentOffset)===t[0].slice(0,r)}function cp(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o,insertText:s}=e,{view:c}=t;if(c.composing)return!1;let l=c.state.doc.resolve(n);if(l.parent.type.spec.code||(l.nodeBefore||l.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let u=id(l)+i;for(let e of a){let a=ip(u,e.find);if(a&&sp(l,a,i)&&op({editor:t,from:n,to:r,text:i,rule:e,match:a,plugin:o,insertText:s}))return!0}return!1}function lp(e){let{editor:t,rules:n}=e,r=new E({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let c=e.getMeta(`applyInputRules`);return c&&setTimeout(()=>{let{text:e}=c;e=typeof e==`string`?e:yu(s.from(e),a.schema);let{from:i}=c,o=i+e.length;cp({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return cp({editor:t,from:i,to:a,text:o,rules:n,plugin:r,insertText:!0})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&cp({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?cp({editor:t,from:a.pos,to:a.pos,text:`
-`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}var up=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...ju(A(this,`addOptions`,{name:this.name}))}}get storage(){return{...ju(A(this,`addStorage`,{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>tp(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},dp=class e extends up{constructor(...e){super(...e),this.type=`mark`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},fp=class{constructor(e){this.find=e.find,this.handler=e.handler}},pp=(e,t,n)=>{if(fl(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function mp(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new Yc({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{var f;if((f=e.type)!=null&&(f=f.spec)!=null&&f.code||!(e.isText||e.isTextblock||e.isInline))return;let p=e.content?.size??e.nodeSize??0,m=Math.max(r,t),h=Math.min(i,t+p);m>=h||pp(e.isText?e.text||``:e.textBetween(m-t,h-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=m+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var hp=null,gp=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function _p(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c;try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}let l=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let s=e.tr,l=Jc({state:e,transaction:s});if(mp({editor:t,state:l,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:c})&&s.steps.length){try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s}};return t.on(`destroy`,()=>{hp===t&&(hp=null)}),n.map(e=>new E({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(hp=t)},i=()=>{hp&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,c=t,!a){let e=hp;e?.isEditable&&setTimeout(()=>{if(e.isDestroyed)return;let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let c=t[0],u=c.getMeta(`uiEvent`)===`paste`&&!i,d=c.getMeta(`uiEvent`)===`drop`&&!a,f=c.getMeta(`applyPasteRules`),p=!!f;if(!u&&!d&&!p)return;if(p){let{text:t}=f;t=typeof t==`string`?t:yu(s.from(t),r.schema);let{from:n}=f,i=n+t.length,a=gp(t);return l({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let m=n.doc.content.findDiffStart(r.doc.content),h=n.doc.content.findDiffEnd(r.doc.content);if(kf(m)&&h&&m!==h.b)return l({rule:e,state:r,from:m,to:h,pasteEvt:o})}}))}var vp=class{constructor(e,t){this.splittableMarks=[],this.nonClearableMarks=[],this.decorationManager=null,this.editor=t,this.baseExtensions=e,this.extensions=Wu(e),this.hasSchemaSpec=t.options.schemaSpec!==void 0,this.schema=Hu(this.extensions,t,t.options.schemaSpec),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=A(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:nd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this,t=Uu([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:nd(t.name,this.schema)},r=[],i=A(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&A(t,`exitable`,n)&&(a.ArrowRight=()=>dp.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=bc(a);r.push(o);let s=A(t,`addInputRules`,n);if(ld(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=lp({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=A(t,`addPasteRules`,n);if(ld(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=_p({editor:e,rules:t});r.push(...n)}}let l=A(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r}),n=this.createDecorationPlugin();return n&&t.push(n),t}createDecorationPlugin(){var e;let{editor:t}=this;(e=this.decorationManager)==null||e.destroy();let n=[];return this.extensions.forEach(e=>{let r=A(e,`addDecorations`,{name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:t,type:nd(e.name,this.schema)});r&&n.push({name:e.name,addDecorations:r})}),this.decorationManager=new Tf({editor:t,entries:n}),this.decorationManager.plugin}get attributes(){let e=ku(this.extensions);return this.hasSchemaSpec?bu(e,this.schema):e}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=Ou(this.extensions);return Object.fromEntries(t.filter(e=>!!A(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=A(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:rl(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>{let l=Iu(r,n);return i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:l})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Uu([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:nd(n.name,this.schema)},i=A(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Uu([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:nd(n.name,this.schema)},i=A(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=Ou(this.extensions);return Object.fromEntries(t.filter(e=>!!A(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=A(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:_l(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Iu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{np(i,e,t)}})}]:[]}))}destroy(){var e;(e=this.decorationManager)==null||e.destroy(),this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.decorationManager=null,this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:nd(e.name,this.schema)};e.type===`mark`&&((ju(A(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name),(ju(A(e,`clearable`,t))??!0)||this.nonClearableMarks.push(e.name));let n=A(e,`onBeforeCreate`,t),r=A(e,`onCreate`,t),i=A(e,`onUpdate`,t),a=A(e,`onSelectionUpdate`,t),o=A(e,`onTransaction`,t),s=A(e,`onFocus`,t),c=A(e,`onBlur`,t),l=A(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};vp.resolve=Wu,vp.sort=Uu,vp.flatten=vu;var yp=class e extends up{constructor(...e){super(...e),this.type=`extension`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},bp=yp.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new E({key:new D(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,a=qu(n),{blockSeparator:o}=this.options,s={...o===void 0?{}:{blockSeparator:o},textSerializers:a};return[...i.ranges].sort((e,t)=>e.$from.pos-t.$from.pos).map(({$from:e,$to:t})=>Gu(r,{from:e.pos,to:t.pos},s)).join(o??`
+`);l+=e.type===`paragraph`?`\n\n${o}`:`\n${o}`}}),l}function op(e,t){let n={...e};return Mf(e)&&Mf(t)&&Object.keys(t).forEach(r=>{Mf(t[r])&&Mf(e[r])?n[r]=op(e[r],t[r]):n[r]=t[r]}),n}function sp(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var cp=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},lp=(e,t)=>{if(pl(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function up(e){let{editor:t,from:n,to:r,text:i,insertText:a}=e;if(!a)return{inputTransaction:null,tr:t.view.state.tr};let o=t.view.state.tr.insertText(i,n,r);return{inputTransaction:o,tr:Bn.create({doc:o.doc,selection:o.selection,storedMarks:o.storedMarks}).tr}}function dp(e){let{editor:t,from:n,to:r,text:i,rule:a,match:o,plugin:s,insertText:c}=e,{view:l}=t,{inputTransaction:u,tr:d}=up({editor:t,from:n,to:r,text:i,insertText:c}),f=u?n+i.length:r,p=Yc({state:l.state,transaction:d}),m={from:n-(o[0].length-i.length),to:f},{commands:h,chain:g,can:_}=new Xc({editor:t,state:p});return a.handler({state:p,range:m,match:o,commands:h,chain:g,can:_})===null||!d.steps.length?!1:(u&&(l.dispatch(u),!l.state.doc.eq(u.doc))||(Vc(d),d.setMeta(`inputRule`,!0),a.undoable&&d.setMeta(s,{transform:d,from:n,to:f,text:i}),l.dispatch(d)),!0)}function fp(e,t,n){let r=t[0].length-n.length;if(r<=0)return!0;let i=e.parentOffset-r;return i>=0&&e.parent.textBetween(i,e.parentOffset)===t[0].slice(0,r)}function pp(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o,insertText:s}=e,{view:c}=t;if(c.composing)return!1;let l=c.state.doc.resolve(n);if(l.parent.type.spec.code||(l.nodeBefore||l.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let u=ad(l)+i;for(let e of a){let a=lp(u,e.find);if(a&&fp(l,a,i)&&dp({editor:t,from:n,to:r,text:i,rule:e,match:a,plugin:o,insertText:s}))return!0}return!1}function mp(e){let{editor:t,rules:n}=e,r=new E({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let c=e.getMeta(`applyInputRules`);return c&&setTimeout(()=>{let{text:e}=c;e=typeof e==`string`?e:xu(s.from(e),a.schema);let{from:i}=c,o=i+e.length;pp({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return pp({editor:t,from:i,to:a,text:o,rules:n,plugin:r,insertText:!0})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&pp({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?pp({editor:t,from:a.pos,to:a.pos,text:`
+`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}var hp=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...Nu(k(this,`addOptions`,{name:this.name}))}}get storage(){return{...Nu(k(this,`addStorage`,{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>op(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},gp=class e extends hp{constructor(...e){super(...e),this.type=`mark`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},_p=class{constructor(e){this.find=e.find,this.handler=e.handler}},vp=(e,t,n)=>{if(pl(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function yp(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new Xc({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{var f;if((f=e.type)!=null&&(f=f.spec)!=null&&f.code||!(e.isText||e.isTextblock||e.isInline))return;let p=e.content?.size??e.nodeSize??0,m=Math.max(r,t),h=Math.min(i,t+p);m>=h||vp(e.isText?e.text||``:e.textBetween(m-t,h-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=m+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var bp=null,xp=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function Sp(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c;try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}let l=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let s=e.tr,l=Yc({state:e,transaction:s});if(yp({editor:t,state:l,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:c})&&s.steps.length){try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s}};return t.on(`destroy`,()=>{bp===t&&(bp=null)}),n.map(e=>new E({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(bp=t)},i=()=>{bp&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,c=t,!a){let e=bp;e?.isEditable&&setTimeout(()=>{if(e.isDestroyed)return;let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let c=t[0],u=c.getMeta(`uiEvent`)===`paste`&&!i,d=c.getMeta(`uiEvent`)===`drop`&&!a,f=c.getMeta(`applyPasteRules`),p=!!f;if(!u&&!d&&!p)return;if(p){let{text:t}=f;t=typeof t==`string`?t:xu(s.from(t),r.schema);let{from:n}=f,i=n+t.length,a=xp(t);return l({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let m=n.doc.content.findDiffStart(r.doc.content),h=n.doc.content.findDiffEnd(r.doc.content);if(Af(m)&&h&&m!==h.b)return l({rule:e,state:r,from:m,to:h,pasteEvt:o})}}))}var Cp=class{constructor(e,t){this.splittableMarks=[],this.nonClearableMarks=[],this.decorationManager=null,this.editor=t,this.baseExtensions=e,this.extensions=Gu(e),this.hasSchemaSpec=t.options.schemaSpec!==void 0,this.schema=Uu(this.extensions,t,t.options.schemaSpec),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=k(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:rd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this,t=Wu([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:rd(t.name,this.schema)},r=[],i=k(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&k(t,`exitable`,n)&&(a.ArrowRight=()=>gp.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=xc(a);r.push(o);let s=k(t,`addInputRules`,n);if(ud(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=mp({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=k(t,`addPasteRules`,n);if(ud(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=Sp({editor:e,rules:t});r.push(...n)}}let l=k(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r}),n=this.createDecorationPlugin();return n&&t.push(n),t}createDecorationPlugin(){var e;let{editor:t}=this;(e=this.decorationManager)==null||e.destroy();let n=[];return this.extensions.forEach(e=>{let r=k(e,`addDecorations`,{name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:t,type:rd(e.name,this.schema)});r&&n.push({name:e.name,addDecorations:r})}),this.decorationManager=new Ef({editor:t,entries:n}),this.decorationManager.plugin}get attributes(){let e=ju(this.extensions);return this.hasSchemaSpec?Su(e,this.schema):e}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=Au(this.extensions);return Object.fromEntries(t.filter(e=>!!k(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=k(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:il(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>{let l=Lu(r,n);return i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:l})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Wu([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:rd(n.name,this.schema)},i=k(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Wu([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:rd(n.name,this.schema)},i=k(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=Au(this.extensions);return Object.fromEntries(t.filter(e=>!!k(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=k(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:vl(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Lu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{sp(i,e,t)}})}]:[]}))}destroy(){var e;(e=this.decorationManager)==null||e.destroy(),this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.decorationManager=null,this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:rd(e.name,this.schema)};e.type===`mark`&&((Nu(k(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name),(Nu(k(e,`clearable`,t))??!0)||this.nonClearableMarks.push(e.name));let n=k(e,`onBeforeCreate`,t),r=k(e,`onCreate`,t),i=k(e,`onUpdate`,t),a=k(e,`onSelectionUpdate`,t),o=k(e,`onTransaction`,t),s=k(e,`onFocus`,t),c=k(e,`onBlur`,t),l=k(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};Cp.resolve=Gu,Cp.sort=Wu,Cp.flatten=bu;var wp=class e extends hp{constructor(...e){super(...e),this.type=`extension`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},Tp=wp.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new E({key:new D(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,a=Ju(n),{blockSeparator:o}=this.options,s={...o===void 0?{}:{blockSeparator:o},textSerializers:a};return[...i.ranges].sort((e,t)=>e.$from.pos-t.$from.pos).map(({$from:e,$to:t})=>Ku(r,{from:e.pos,to:t.pos},s)).join(o??`
-`)}}})]}}),xp=yp.create({name:`commands`,addCommands(){return{...ef}}}),Sp=yp.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){var n;let r=()=>{var n,r;if(((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null||(r=n.filterTransaction)==null?void 0:r.call(n,e))??e.getMeta(`y-sync$`))return;let i=mu(e.before,[e,...t]);Qu(i).forEach(t=>{i.mapping.mapResult(t.oldRange.from).deletedAfter&&i.mapping.mapResult(t.oldRange.to).deletedBefore&&i.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let a=r+n.nodeSize-2,o=t.oldRange.from<=r&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:r,to:a,newFrom:i.mapping.map(r),newTo:i.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:i})})});let a=i.mapping;i.steps.forEach((t,n)=>{if(t instanceof St){let r=a.slice(n).map(t.from,-1),o=a.slice(n).map(t.to),s=a.invert().map(r,-1),c=a.invert().map(o),l=r>0&&i.doc.nodeAt(r-1)?.marks.some(e=>e.eq(t.mark)),u=i.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:r,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:i})}})};((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null?void 0:n.async)??!0?setTimeout(r,0):r()}}),Cp=yp.create({name:`drop`,addProseMirrorPlugins(){return[new E({key:new D(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),wp=yp.create({name:`editable`,addProseMirrorPlugins(){return[new E({key:new D(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),Tp=new D(`focusEvents`),Ep=yp.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new E({key:Tp,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),Dp=yp.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:C.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return wl()||ql()?i:r},addProseMirrorPlugins(){return[new E({key:new D(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=C.atStart(t.doc).from,l=C.atEnd(t.doc).to;if(a||o!==c||s!==l||!dd(n.doc))return;let u=n.tr,d=Jc({state:n,transaction:u}),{commands:f}=new Yc({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),Op=yp.create({name:`paste`,addProseMirrorPlugins(){return[new E({key:new D(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),kp=yp.create({name:`tabindex`,addOptions(){return{value:void 0}},addProseMirrorPlugins(){return[new E({key:new D(`tabindex`),props:{attributes:()=>!this.editor.isEditable&&this.options.value===void 0?{}:{tabindex:this.options.value??`0`}}})]}}),Ap=yp.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=Ou(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new E({key:new D(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),jp=!1;function Mp(e){if(jp)return;jp=!0;let t;try{let n=Dt.fromJSON(e,{from:0,to:0});if(!md(n))return;t=n.slice.content}catch{return}t instanceof s||console.warn(`[tiptap warn]: prosemirror-model is loaded more than once. Wrapping and splitting nodes will fail. Deduplicate it in your lock file, or alias it to a single copy in your bundler.`)}var Np=class e{get name(){return this.node.type.name}constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(t);return new e(n,this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e){if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),n&&r.length>0||(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Pp=`.ProseMirror {
+`)}}})]}}),Ep=wp.create({name:`commands`,addCommands(){return{...tf}}}),Dp=wp.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){var n;let r=()=>{var n,r;if(((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null||(r=n.filterTransaction)==null?void 0:r.call(n,e))??e.getMeta(`y-sync$`))return;let i=hu(e.before,[e,...t]);$u(i).forEach(t=>{i.mapping.mapResult(t.oldRange.from).deletedAfter&&i.mapping.mapResult(t.oldRange.to).deletedBefore&&i.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let a=r+n.nodeSize-2,o=t.oldRange.from<=r&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:r,to:a,newFrom:i.mapping.map(r),newTo:i.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:i})})});let a=i.mapping;i.steps.forEach((t,n)=>{if(t instanceof St){let r=a.slice(n).map(t.from,-1),o=a.slice(n).map(t.to),s=a.invert().map(r,-1),c=a.invert().map(o),l=r>0&&i.doc.nodeAt(r-1)?.marks.some(e=>e.eq(t.mark)),u=i.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:r,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:i})}})};((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null?void 0:n.async)??!0?setTimeout(r,0):r()}}),Op=wp.create({name:`drop`,addProseMirrorPlugins(){return[new E({key:new D(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),kp=wp.create({name:`editable`,addProseMirrorPlugins(){return[new E({key:new D(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),Ap=new D(`focusEvents`),jp=wp.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new E({key:Ap,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),Mp=wp.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:C.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Tl()||Jl()?i:r},addProseMirrorPlugins(){return[new E({key:new D(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=C.atStart(t.doc).from,l=C.atEnd(t.doc).to;if(a||o!==c||s!==l||!fd(n.doc))return;let u=n.tr,d=Yc({state:n,transaction:u}),{commands:f}=new Xc({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),Np=wp.create({name:`paste`,addProseMirrorPlugins(){return[new E({key:new D(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),Pp=wp.create({name:`tabindex`,addOptions(){return{value:void 0}},addProseMirrorPlugins(){return[new E({key:new D(`tabindex`),props:{attributes:()=>!this.editor.isEditable&&this.options.value===void 0?{}:{tabindex:this.options.value??`0`}}})]}}),Fp=wp.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=Au(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new E({key:new D(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Ip=!1;function Lp(e){if(Ip)return;Ip=!0;let t;try{let n=Dt.fromJSON(e,{from:0,to:0});if(!hd(n))return;t=n.slice.content}catch{return}t instanceof s||console.warn(`[tiptap warn]: prosemirror-model is loaded more than once. Wrapping and splitting nodes will fail. Deduplicate it in your lock file, or alias it to a single copy in your bundler.`)}var Rp=class e{get name(){return this.node.type.name}constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(t);return new e(n,this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e){if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),n&&r.length>0||(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},zp=`.ProseMirror {
position: relative;
}
@@ -98,21 +100,21 @@ img.ProseMirror-separator {
.ProseMirror-focused .ProseMirror-gapcursor {
display: block;
-}`,Fp=class extends af{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:gd,createMappablePosition:_d},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=Sl(t,this.options.autofocus);this.editorState=Bn.create({doc:t,schema:this.schema,selection:e||void 0})}Mp(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():Yc.createFakeChain()}can(){return this.commandManager?this.commandManager.can():Yc.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=Df(Pp,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.editorView&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return of&&!this.hasWarnedStaleDecorationRead&&rf(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Au(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[wp,bp.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),xp,Ep,Dp,kp.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),Cp,Op,Sp,Ap.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions!=`object`||this.options.enableCoreExtensions[e.name]!==!1):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new vp(n,this)}createCommandManager(){this.commandManager=new Yc({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=du(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=du(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=Bn.create({doc:t,schema:this.schema,selection:Sl(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return Au(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new ec(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc)||this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return Yu(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return od(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return yu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=`
+}`,Bp=class extends of{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:_d,createMappablePosition:vd},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=Cl(t,this.options.autofocus);this.editorState=Bn.create({doc:t,schema:this.schema,selection:e||void 0})}Lp(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():Xc.createFakeChain()}can(){return this.commandManager?this.commandManager.can():Xc.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=Of(zp,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.editorView&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return sf&&!this.hasWarnedStaleDecorationRead&&af(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Mu(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[kp,Tp.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Ep,jp,Mp,Pp.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),Op,Np,Dp,Fp.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions!=`object`||this.options.enableCoreExtensions[e.name]!==!1):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new Cp(n,this)}createCommandManager(){this.commandManager=new Xc({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=Bn.create({doc:t,schema:this.schema,selection:Cl(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return Mu(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new tc(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc)||this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return Xu(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return sd(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return xu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=`
-`,textSerializers:n={}}=e||{};return Ku(this.state.doc,{blockSeparator:t,textSerializers:{...qu(this.schema),...n}})}get isEmpty(){return dd(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new Np(t,this,!1,n)}get $doc(){return this.$pos(0)}};function Ip(e){return new rp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=ju(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if($u(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Lp(e){return new rp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=ju(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Rp(e){return new rp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=ju(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function zp(e){return new rp({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=ju(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&It(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&Jt(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var Bp=e=>`touches`in e,Vp=class{constructor(e){var t;this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.element.draggable=!1,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e!=null&&(t=e.options)!=null&&t.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type&&(this.node=e,!this.onUpdate||this.onUpdate(e,t,n))}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=this.node.type.isInline?`inline-flex`:`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,Bp(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}},Hp=class e extends up{constructor(...e){super(...e),this.type=`node`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Up(e){return new fp({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=ju(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if($u(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;dn.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Wp=()=>new Map,Gp=e=>{let t=Wp();return e.forEach((e,n)=>{t.set(n,e)}),t},Kp=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},qp=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Jp=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Yp=()=>new Set,Xp=e=>e[e.length-1],Zp=(e,t)=>{for(let n=0;n{for(let n=0;n{for(let n=0;n{let n=Array(e);for(let r=0;r{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Qp((this._observers.get(e)||Wp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Wp()}},im=class{constructor(){this._observers=Wp()}on(e,t){Kp(this._observers,e,Yp).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Qp((this._observers.get(e)||Wp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Wp()}},am=Math.floor,om=Math.abs,sm=(e,t)=>ee>t?e:t;Number.isNaN;var lm=e=>e===0?1/e<0:e<0,um=1<<29,dm=2**53-1,fm=-(2**53-1),pm=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&am(e)===e);Number.isNaN,Number.parseInt;var mm=String.fromCharCode;String.fromCodePoint,mm(65535);var hm=e=>e.toLowerCase(),gm=/^\s*/g,_m=e=>e.replace(gm,``),vm=/([A-Z])/g,ym=(e,t)=>_m(e.replace(vm,e=>`${t}${hm(e)}`)),bm=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;exm.encode(e):bm,Cm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Cm&&Cm.decode(new Uint8Array).length===1&&(Cm=null);var wm=(e,t)=>tm(t,()=>e).join(``),Tm=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Em=()=>new Tm,Dm=e=>{let t=Em();return e(t),km(t)},Om=e=>{let t=e.cpos;for(let n=0;n{let t=new Uint8Array(Om(e)),n=0;for(let r=0;r{let n=e.cbuf.length;n-e.cpos{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Mm=jm,j=(e,t)=>{for(;t>127;)jm(e,128|127&t),t=am(t/128);jm(e,127&t)},Nm=(e,t)=>{let n=lm(t);for(n&&(t=-t),jm(e,(t>63?128:0)|(n?64:0)|63&t),t=am(t/64);t>0;)jm(e,(t>127?128:0)|127&t),t=am(t/128)},Pm=new Uint8Array(3e4),Fm=Pm.length/3,Im=xm&&xm.encodeInto?(e,t)=>{if(t.length{let n=unescape(encodeURIComponent(t)),r=n.length;j(e,r);for(let t=0;t{let n=e.cbuf.length,r=e.cpos,i=sm(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(cm(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Rm=(e,t)=>{j(e,t.byteLength),Lm(e,t)},zm=(e,t)=>{Am(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Bm=(e,t)=>zm(e,4).setFloat32(0,t,!1),Vm=(e,t)=>zm(e,8).setFloat64(0,t,!1),Hm=(e,t)=>zm(e,8).setBigInt64(0,t,!1),Um=new DataView(new ArrayBuffer(4)),Wm=e=>(Um.setFloat32(0,e),Um.getFloat32(0)===e),Gm=(e,t)=>{switch(typeof t){case`string`:jm(e,119),Im(e,t);break;case`number`:pm(t)&&om(t)<=2147483647?(jm(e,125),Nm(e,t)):Wm(t)?(jm(e,124),Bm(e,t)):(jm(e,123),Vm(e,t));break;case`bigint`:jm(e,122),Hm(e,t);break;case`object`:if(t===null)jm(e,126);else if(nm(t)){jm(e,117),j(e,t.length);for(let n=0;n0&&j(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},qm=e=>{e.count>0&&(Nm(e.encoder,e.count===1?e.s:-e.s),e.count>1&&j(e.encoder,e.count-2))},Jm=class{constructor(){this.encoder=new Tm,this.s=0,this.count=0}write(e){this.s===e?this.count++:(qm(this),this.count=1,this.s=e)}toUint8Array(){return qm(this),km(this.encoder)}},Ym=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Nm(e.encoder,t),e.count>1&&j(e.encoder,e.count-2)}},Xm=class{constructor(){this.encoder=new Tm,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Ym(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ym(this),km(this.encoder)}},Zm=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Jm}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 Tm;return this.sarr.push(this.s),this.s=``,Im(e,this.sarr.join(``)),Lm(e,this.lensE.toUint8Array()),km(e)}},Qm=e=>Error(e),$m=()=>{throw Qm(`Method unimplemented`)},eh=()=>{throw Qm(`Unexpected case`)},th=Qm(`Unexpected end of array`),nh=Qm(`Integer out of Range`),rh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw th;return new Uint8Array(e.buffer,e.byteOffset+t,n)},ih=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw th;return new DataView(e.buffer,e.byteOffset+t,n)},ah=class{constructor(e){this.arr=e,this.pos=0}},oh=e=>new ah(e),sh=e=>e.pos!==e.arr.length,ch=(e,t)=>{let n=rh(e.arr,e.pos,t);return e.pos+=t,n},lh=e=>ch(e,M(e)),uh=e=>e.arr[e.pos++],M=e=>{let t=0,n=1,r=e.arr.length;for(;e.posdm)throw nh}throw th},dh=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.posdm)throw nh}throw th},fh=Cm?e=>Cm.decode(lh(e)):e=>{let t=M(e);if(t===0)return``;{let n=String.fromCodePoint(uh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(uh(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},ph=(e,t)=>{let n=ih(e.arr,e.pos,t);return e.pos+=t,n},mh=[e=>void 0,e=>null,dh,e=>ph(e,4).getFloat32(0,!1),e=>ph(e,8).getFloat64(0,!1),e=>ph(e,8).getBigInt64(0,!1),e=>!1,e=>!0,fh,e=>{let t=M(e),n={};for(let r=0;r{let t=M(e),n=[];for(let r=0;rmh[127-uh(e)](e),gh=class extends ah{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=sh(this)?M(this)+1:-1),this.count--,this.s}},_h=class extends ah{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=dh(this);let e=lm(this.s);this.count=1,e&&(this.s=-this.s,this.count=M(this)+2)}return this.count--,this.s}},vh=class extends ah{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=dh(this),t=e&1;this.diff=am(e/2),this.count=1,t&&(this.count=M(this)+2)}return this.s+=this.diff,this.count--,this.s}},yh=class{constructor(e){this.decoder=new _h(e),this.str=fh(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}};crypto.subtle;var bh=crypto.getRandomValues.bind(crypto),xh=Math.random,Sh=()=>bh(new Uint32Array(1))[0],Ch=e=>e[am(xh()*e.length)],wh=`10000000-1000-4000-8000-100000000000`,Th=()=>wh.replace(/[018]/g,e=>(e^Sh()&15>>e/4).toString(16)),Eh=Date.now,Dh=e=>new Promise(e);Promise.all.bind(Promise);var Oh=e=>e===void 0?null:e,kh=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(kh=localStorage)}catch{}var Ah=kh,jh=Symbol(`Equality`),Mh=(e,t)=>e===t||!!e?.[jh]?.(t)||!1,Nh=e=>typeof e==`object`,Ph=Object.assign,Fh=Object.keys,Ih=(e,t)=>{for(let n in e)t(e[n],n)},Lh=e=>Fh(e).length,Rh=e=>{for(let t in e)return!1;return!0},zh=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Bh=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Vh=(e,t)=>e===t||Lh(e)===Lh(t)&&zh(e,(e,n)=>(e!==void 0||Bh(t,n))&&Mh(t[n],e)),Hh=Object.freeze,Uh=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Uh(e[t])}return Hh(e)},Wh=(e,t,n=0)=>{try{for(;ne,Kh=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[jh]!=null)return e[jh](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;nt.includes(e),Jh=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Yh=typeof window<`u`&&typeof document<`u`&&!Jh;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Xh,Zh=[],Qh=()=>{if(Xh===void 0){if(Jh){Xh=Wp();let e=process.argv,t=null;for(let n=0;n{if(e.length!==0){let[t,n]=e.split(`=`);Xh.set(`--${ym(t,`-`)}`,n),Xh.set(`-${ym(t,`-`)}`,n)}})):Xh=Wp()}return Xh},$h=e=>Qh().has(e),eg=e=>Oh(Jh?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Ah.getItem(e)),tg=e=>$h(`--`+e)||eg(e)!==null,ng=tg(`production`),rg=Jh&&qh({}.FORCE_COLOR,[`true`,`1`,`2`])||!$h(`--no-colors`)&&!tg(`no-color`)&&(!Jh||process.stdout.isTTY)&&(!Jh||$h(`--color`)||eg(`COLORTERM`)!==null||(eg(`TERM`)||``).includes(`color`)),ig=e=>new Uint8Array(e),ag=e=>{let t=``;for(let n=0;nBuffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),sg=e=>{let t=atob(e),n=ig(t.length);for(let e=0;enew Uint8Array(Buffer.from(e,`base64`)),lg=Yh?ag:og,ug=Yh?sg:cg,dg=e=>{let t=ig(e.byteLength);return t.set(e),t},fg=e=>Dm(t=>Gm(t,e)),pg=class{constructor(e,t){this.left=e,this.right=t}},mg=(e,t)=>new pg(e,t),hg=e=>e.next()>=.5,gg=(e,t,n)=>am(e.next()*(n+1-t)+t),_g=(e,t,n)=>am(e.next()*(n+1-t)+t),vg=(e,t,n)=>_g(e,t,n),yg=e=>mm(vg(e,97,122)),bg=(e,t=0,n=20)=>{let r=vg(e,t,n),i=``;for(let t=0;tt[vg(e,0,t.length-1)],Sg=Symbol(`0schema`),Cg=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(wm(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
-`)}},wg=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[jh]?Mh(e,t):nm(e)?$p(e,e=>em(t,t=>wg(e,t))):Nh(e)?zh(e,(e,n)=>wg(e,t[n])):!1,Tg=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),wg(t,n)}equals(e){return this.constructor===e.constructor&&Kh(this.shape,e.shape)}[Sg](){return!0}[jh](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){$m()}get nullable(){return i_(this,y_)}get optional(){return new Ig(this)}cast(e){return C_(e,this),e}expect(e){return C_(e,this),e}},Eg=class extends Tg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Dg=(e,t=null)=>new Eg(e,t);Dg(Eg);var Og=class extends Tg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},kg=e=>new Og(e);Dg(Og);var Ag=class extends Tg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},jg=(...e)=>new Ag(e),Mg=Dg(Ag),Ng=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Pg=e=>{if(m_.check(e))return[Ng(e)];if(Mg.check(e))return e.shape.map(e=>e+``);if(p_.check(e))return[`[+-]?\\d+.?\\d*`];if(h_.check(e))return[`.*`];if(a_.check(e))return e.shape.map(Pg).flat(1);eh()};Dg(class extends Tg{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Pg).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Fg=Symbol(`optional`),Ig=class extends Tg{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Fg](){return!0}},Lg=Dg(Ig),Rg=class extends Tg{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Rg,Dg(Rg);var zg=class e extends Tg{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):zh(this.shape,(n,r)=>{let i=this._isPartial&&!Bh(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Bg=e=>new zg(e),Vg=Dg(zg),Hg=kg(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Ug=class extends Tg{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&zh(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},Wg=(e,t)=>new Ug(e,t),Gg=Dg(Ug),Kg=class extends Tg{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&zh(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},qg=(...e)=>new Kg(e);Dg(Kg);var Jg=class extends Tg{constructor(e){super(),this.shape=e.length===1?e[0]:new r_(e)}check(e,t){let n=nm(e)&&$p(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},Yg=(...e)=>new Jg(e),Xg=Dg(Jg),Zg=kg(e=>nm(e)),Qg=class extends Tg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},$g=(e,t=null)=>new Qg(e,t);Dg(Qg);var e_=$g(Tg),t_=Dg(class extends Tg{constructor(e){super(),this.len=e.length-1,this.args=qg(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),n_=kg(e=>typeof e==`function`);Dg(class extends Tg{constructor(e){super(),this.shape=e}check(e,t){let n=$p(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var r_=class extends Tg{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=em(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},i_=(...e)=>e.findIndex(e=>a_.check(e))>=0?i_(...e.map(e=>S_(e)).map(e=>a_.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new r_(e),a_=Dg(r_),o_=()=>!0,s_=kg(o_),c_=Dg(Og,e=>e.shape===o_),l_=kg(e=>typeof e==`bigint`),u_=kg(e=>e===l_),d_=kg(e=>typeof e==`symbol`);kg(e=>e===d_);var f_=kg(e=>typeof e==`number`),p_=kg(e=>e===f_),m_=kg(e=>typeof e==`string`),h_=kg(e=>e===m_),g_=kg(e=>typeof e==`boolean`),__=kg(e=>e===g_),v_=jg(void 0);Dg(Ag,e=>e.shape.length===1&&e.shape[0]===void 0),jg(void 0);var y_=jg(null),b_=Dg(Ag,e=>e.shape.length===1&&e.shape[0]===null);Dg(Uint8Array),Dg(Eg,e=>e.shape===Uint8Array);var x_=i_(f_,m_,y_,v_,l_,g_,d_);(()=>{let e=Yg(s_),t=Wg(m_,s_),n=i_(f_,m_,y_,g_,e,t);return e.shape=n,t.shape.values=n,n})();var S_=e=>{if(e_.check(e))return e;if(Hg.check(e)){let t={};for(let n in e)t[n]=S_(e[n]);return Bg(t)}if(Zg.check(e))return i_(...e.map(S_));if(x_.check(e))return jg(e);if(n_.check(e))return Dg(e);eh()},C_=ng?()=>{}:(e,t)=>{let n=new Cg;if(!t.check(e,n))throw Qm(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},w_=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:S_(e),h:t}),this}else(e){return this.if(s_,e)}done(){return(e,t)=>{for(let n=0;nnew w_(e))(s_).if(p_,(e,t)=>gg(t,fm,dm)).if(h_,(e,t)=>bg(t)).if(__,(e,t)=>hg(t)).if(u_,(e,t)=>BigInt(gg(t,fm,dm))).if(a_,(e,t)=>E_(t,xg(t,e.shape))).if(Vg,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Lg.check(i)){if(hg(t))continue;i=i.shape}n[r]=T_(i,t)}return n}).if(Xg,(e,t)=>{let n=[],r=_g(t,0,42);for(let i=0;ixg(t,e.shape)).if(b_,(e,t)=>null).if(t_,(e,t)=>{let n=E_(t,e.res);return()=>n}).if(c_,(e,t)=>E_(t,xg(t,[f_,m_,y_,v_,l_,g_,Yg(f_),Wg(i_(`a`,`b`,`c`),f_)]))).if(Gg,(e,t)=>{let n={},r=gg(t,0,3);for(let i=0;iT_(S_(t),e),D_=typeof document<`u`?document:{};kg(e=>e.nodeType===M_),typeof DOMParser<`u`&&new DOMParser,kg(e=>e.nodeType===k_),kg(e=>e.nodeType===A_);var O_=e=>qp(e,(e,t)=>`${t}:${e};`).join(``),k_=D_.ELEMENT_NODE,A_=D_.TEXT_NODE;D_.CDATA_SECTION_NODE,D_.COMMENT_NODE;var j_=D_.DOCUMENT_NODE;D_.DOCUMENT_TYPE_NODE;var M_=D_.DOCUMENT_FRAGMENT_NODE;kg(e=>e.nodeType===j_);var N_=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),P_=(e,t)=>new N_(setTimeout(t,e)),F_=Symbol,I_=F_(),L_=F_(),R_=F_(),z_=F_(),B_=F_(),V_=F_(),H_=F_(),U_=F_(),W_=F_(),G_=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r0&&n.push(t.join(``));r{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Wp(),i=[],a=0;for(;a0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a{console.log(...q_(e)),X_.forEach(t=>t.print(e))},Y_=(...e)=>{console.warn(...q_(e)),e.unshift(U_),X_.forEach(t=>t.print(e))},X_=Yp(),Z_=e=>({[Symbol.iterator](){return this},next:e}),Q_=(e,t)=>Z_(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),$_=(e,t)=>Z_(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),ev=class{constructor(e,t){this.clock=e,this.len=t}},tv=class{constructor(){this.clients=new Map}},nv=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r{let n=0,r=e.length-1;for(;n<=r;){let i=am((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t{let n=e.clients.get(t.client);return n!==void 0&&rv(n,t.clock)!==null},av=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t=i.clock?e[n-1]=new ev(r.clock,cm(r.len,i.clock+i.len-r.clock)):(n{let t=new tv;for(let n=0;n{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t{Kp(e.clients,t,()=>[]).push(new ev(n,r))},cv=()=>new tv,lv=e=>{let t=cv();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t0&&t.clients.set(n,r)}),t},uv=(e,t)=>{j(e.restEncoder,t.clients.size),Qp(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),j(e.restEncoder,t);let r=n.length;j(e.restEncoder,r);for(let t=0;t{let t=new tv,n=M(e.restDecoder);for(let r=0;r0){let i=Kp(t.clients,n,()=>[]);for(let t=0;t{let r=new tv,i=M(e.restDecoder);for(let a=0;a0){let e=new Sv;return j(e.restEncoder,0),uv(e,r),e.toUint8Array()}return null},pv=Sh,mv=class e extends rm{constructor({guid:e=Th(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=pv(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new py,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Dh(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Dh(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&jy(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Qp(this.subdocs).map(e=>e.guid))}transact(e,t=null){return jy(this,e,t)}get(e,t=sb){let n=Kp(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==sb&&r!==t){if(r===sb){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Ob)}getText(e=``){return this.get(e,Yb)}getMap(e=``){return this.get(e,jb)}getXmlElement(e=``){return this.get(e,ex)}getXmlFragment(e=``){return this.get(e,Qb)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Qp(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,jy(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},hv=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return M(this.restDecoder)}readDsLen(){return M(this.restDecoder)}},gv=class extends hv{readLeftID(){return N(M(this.restDecoder),M(this.restDecoder))}readRightID(){return N(M(this.restDecoder),M(this.restDecoder))}readClient(){return M(this.restDecoder)}readInfo(){return uh(this.restDecoder)}readString(){return fh(this.restDecoder)}readParentInfo(){return M(this.restDecoder)===1}readTypeRef(){return M(this.restDecoder)}readLen(){return M(this.restDecoder)}readAny(){return hh(this.restDecoder)}readBuf(){return dg(lh(this.restDecoder))}readJSON(){return JSON.parse(fh(this.restDecoder))}readKey(){return fh(this.restDecoder)}},_v=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=M(this.restDecoder),this.dsCurrVal}readDsLen(){let e=M(this.restDecoder)+1;return this.dsCurrVal+=e,e}},vv=class extends _v{constructor(e){super(e),this.keys=[],M(e),this.keyClockDecoder=new vh(lh(e)),this.clientDecoder=new _h(lh(e)),this.leftClockDecoder=new vh(lh(e)),this.rightClockDecoder=new vh(lh(e)),this.infoDecoder=new gh(lh(e),uh),this.stringDecoder=new yh(lh(e)),this.parentInfoDecoder=new gh(lh(e),uh),this.typeRefDecoder=new _h(lh(e)),this.lenDecoder=new _h(lh(e))}readLeftID(){return new Gv(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Gv(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 hh(this.restDecoder)}readBuf(){return lh(this.restDecoder)}readJSON(){return hh(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=cm(r,t[0].id.clock);let i=_y(t,r);j(e.restEncoder,t.length-i),e.writeClient(n),j(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n{let r=new Map;n.forEach((e,n)=>{hy(t,n)>e&&r.set(n,e)}),my(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),j(e.restEncoder,r.size),Qp(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Cv(e,t.clients.get(n),n,r)})},Tv=(e,t)=>{let n=Wp(),r=M(e.restDecoder);for(let i=0;i{let r=[],i=Qp(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new py,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==qx){let i=Kp(d,u.id.client,()=>hy(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,hy(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i0)u=r.pop();else if(o!==null&&o.i0){let e=new Sv;return wv(e,s,new Map),j(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Dv=(e,t)=>wv(e,t.doc.store,t.beforeState),Ov=(e,t,n,r=new vv(e))=>jy(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Ev(e,i,Tv(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(nt)&&o.missing.set(e,t)}o.update=Vy([o.update,a.update])}}else i.pendingStructs=a;let s=fv(r,e,i);if(i.pendingDs){let t=new vv(oh(i.pendingDs));M(t.restDecoder);let n=fv(t,e,i);i.pendingDs=s&&n?Vy([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,kv(e.doc,t)}},n,!1),kv=(e,t,n,r=vv)=>{let i=oh(t);Ov(i,e,n,new r(i))},Av=(e,t,n)=>kv(e,t,n,gv),jv=(e,t,n=new Map)=>{wv(e,t.store,n),uv(e,lv(t.store))},Mv=(e,t=new Uint8Array([0]),n=new Sv)=>{jv(n,e,Fv(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Hy(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===bv)return zy(r.map((e,t)=>t===0?e:qy(e)));if(n.constructor===Sv)return Vy(r)}return r[0]},Nv=(e,t)=>Mv(e,t,new bv),Pv=e=>{let t=new Map,n=M(e.restDecoder);for(let r=0;rPv(new hv(oh(e))),Iv=(e,t)=>(j(e.restEncoder,t.size),Qp(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{j(e.restEncoder,t),j(e.restEncoder,n)}),e),Lv=(e,t)=>Iv(e,my(t.store)),Rv=(e,t=new xv)=>(e instanceof Map?Iv(t,e):Lv(t,e),t.toUint8Array()),zv=e=>Rv(e,new yv),Bv=class{constructor(){this.l=[]}},Vv=()=>new Bv,Hv=(e,t)=>e.l.push(t),Uv=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},Wv=(e,t,n)=>Wh(e.l,[t,n]),Gv=class{constructor(e,t){this.client=e,this.clock=t}},Kv=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,N=(e,t)=>new Gv(e,t),qv=e=>N(M(e),M(e)),Jv=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw eh()},Yv=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Xv=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},Zv=e=>new Xv(e.type==null?null:N(e.type.client,e.type.clock),e.tname??null,e.item==null?null:N(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Qv=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},$v=(e,t,n=0)=>new Qv(e,t,n),ey=(e,t,n)=>{let r=null,i=null;return e._item===null?i=Jv(e):r=N(e._item.id.client,e._item.id.clock),new Xv(r,i,t,n)},ty=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ey(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ey(e,N(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ey(e,r.lastId,n);r=r.right}return ey(e,null,n)},ny=e=>{let t=null,n=null,r=null;switch(M(e)){case 0:r=qv(e);break;case 1:n=fh(e);break;case 2:t=qv(e)}let i=sh(e)?dh(e):0;return new Xv(t,n,r,i)},ry=e=>ny(oh(e)),iy=(e,t)=>{let n=vy(e,t);return{item:n,diff:t.clock-n.id.clock}},ay=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(hy(r,i.client)<=i.clock)return null;let e=n?Rx(r,i):iy(r,i),t=e.item;if(!(t instanceof Ux))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(hy(r,a.client)<=a.clock)return null;let{item:e}=n?Rx(r,a):{item:vy(r,a)};if(e instanceof Ux&&e.content instanceof Ix)c=e.content.type;else return null}else throw eh();l=s>=0?c._length:0}return $v(c,l,e.assoc)},oy=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Kv(e.item,t.item)&&Kv(e.type,t.type)&&e.assoc===t.assoc,sy=class{constructor(e,t){this.ds=e,this.sv=t}},cy=(e,t)=>new sy(e,t),ly=cy(cv(),new Map),uy=e=>cy(lv(e.store),my(e.store)),dy=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!iv(t.ds,e.id),fy=(e,t)=>{let n=Kp(e.meta,fy,Yp),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t{}),n.add(t))},py=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},my=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},hy=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},gy=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw eh()}n.push(t)},_y=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=am(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t{let n=e.clients.get(t.client);return n[_y(n,t.clock)]},yy=(e,t,n)=>{let r=_y(t,n),i=t[r];return i.id.clock{let n=e.doc.store.clients.get(t.client);return n[yy(e,n,t.clock)]},xy=(e,t,n)=>{let r=t.clients.get(n.client),i=_y(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==lx&&r.splice(i+1,0,Bx(e,a,n.clock-a.id.clock+1)),a},Sy=(e,t,n)=>{let r=e.clients.get(t.id.client);r[_y(r,t.id.clock)]=n},Cy=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=yy(e,t,n),s;do s=t[o++],at.deleteSet.clients.size===0&&!Jp(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(av(t.deleteSet),Dv(e,t),uv(e,t.deleteSet),!0),Ey=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Kp(e.changed,t,Yp).add(n)},Dy=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Ux&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Oy=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=_y(e,a.clock),i=e[r];r{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=sm(r.length-1,1+_y(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Dy(r,e)}})},Ay=(e,t)=>{if(te.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),Wv(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Kb(n)})}),Wh(e,[])}finally{r.gc&&Oy(a,i,r.gcFilter),ky(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=cm(_y(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Dy(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=_y(r,n);a+11||a>0&&Dy(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(J_(U_,I_,`[yjs] `,L_,V_,`Changed the client-id because another client seems to be using it.`),r.clientID=pv()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new bv;Ty(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Sv;Ty(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Ay(e,t+1)}}},jy=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new wy(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Ay(i,0)}}return o},My=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Ny=(e,t,n)=>{nv(e,n.deletions,n=>{n instanceof Ux&&t.scope.some(t=>t===e.doc||Yv(t,n))&&zx(n,!1)})},Py=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;jy(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;nv(n,o.insertions,e=>{if(e instanceof Ux){if(e.redone!==null){let{item:t,diff:i}=Rx(r,e.id);i>0&&(t=by(n,N(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||Yv(t,e))&&c.push(e)}}),nv(n,o.deletions,e=>{e instanceof Ux&&a.some(t=>t===n.doc||Yv(t,e))&&!iv(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Hx(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Fy=class extends rm{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=nm(e)?e[0].doc:e instanceof mv?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new tv;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&sv(i,n,r,a)});let a=Eh(),o=!1;if(this.lastChange>0&&a-this.lastChange0&&!t&&!n){let t=r[r.length-1];t.deletions=ov([t.deletions,e.deleteSet]),t.insertions=ov([t.insertions,i])}else r.push(new My(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),nv(e,e.deleteSet,t=>{t instanceof Ux&&this.scope.some(n=>n===e.doc||Yv(n,t))&&zx(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=nm(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof sb?e.doc!==this.doc:e!==this.doc)&&Y_(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}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(n=>{e&&(this.undoStack.forEach(e=>Ny(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Ny(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Py(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Py(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),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Iy(e){let t=M(e.restDecoder);for(let n=0;nVy(e,gv,bv),By=(e,t)=>{if(e.constructor===lx){let{client:n,clock:r}=e.id;return new lx(N(n,r+t),e.length-t)}if(e.constructor===qx){let{client:n,clock:r}=e.id;return new qx(N(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Ux(N(r,i+t),null,N(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Vy=(e,t=vv,n=Sv)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(oh(e))),i=r.map(e=>new Ly(e,!0)),a=null,o=new n,s=new Ry(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===qx?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Wy(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length0&&(a.struct.constructor===qx?a.struct.length-=t:n=By(n,t)),a.struct.mergeWith(n)||(Wy(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==qx;n=e.next())Wy(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Wy(s,a.struct,a.offset),a=null),Gy(s),uv(o,ov(r.map(e=>dv(e)))),o.toUint8Array()},Hy=(e,t,n=vv,r=Sv)=>{let i=Fv(t),a=new r,o=new Ry(a),s=new n(oh(e)),c=new Ly(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===qx)c.next();else if(e.id.clock+e.length>n)for(Wy(o,e,cm(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Wy(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Gy(o),uv(a,dv(s)),a.toUint8Array()},Uy=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:km(e.encoder.restEncoder)}),e.encoder.restEncoder=Em(),e.written=0)},Wy=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Uy(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),j(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Gy=e=>{Uy(e);let t=e.encoder.restEncoder;j(t,e.clientStructs.length);for(let n=0;n{let i=new n(oh(e)),a=new Ly(i,!1),o=new r,s=new Ry(o);for(let e=a.curr;e!==null;e=a.next())Wy(s,t(e),0);return Gy(s),uv(o,dv(i)),o.toUint8Array()},qy=e=>Ky(e,Gh,vv,bv),Jy=`You must not compute changes after the event-handler fired.`,Yy=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||=Xy(this.currentTarget,this.target)}deletes(e){return iv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Qm(Jy);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=Xp(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=Xp(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Xp(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),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 Qm(Jy);let t=this.target,n=Yp(),r=Yp(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Xy=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},Zy=()=>{Y_(`Invalid access: Add Yjs type to a document before reading data.`)},Qy=80,$y=0,eb=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=$y++}},tb=e=>{e.timestamp=$y++},nb=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=$y++},rb=(e,t,n)=>{if(e.length>=Qy){let r=e.reduce((e,t)=>e.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>om(t-e.index)t;)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 n!==null&&om(n.index-i){for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t0&&t===i.index)&&(i.index=cm(t,i.index+n))}},ob=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Kp(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Wv(r._eH,n,t)},sb=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Vv(),this._dEH=Vv(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw $m()}clone(){throw $m()}_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){Hv(this._eH,e)}observeDeep(e){Hv(this._dEH,e)}unobserve(e){Uv(this._eH,e)}unobserveDeep(e){Uv(this._dEH,e)}toJSON(){}},cb=(e,t,n)=>{e.doc??Zy(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},lb=e=>{e.doc??Zy();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n{let n=[],r=e._start;for(;r!==null;){if(r.countable&&dy(r,t)){let e=r.content.getContent();for(let t=0;t{let n=0,r=e._start;for(e.doc??Zy();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r{let n=[];return db(e,(r,i)=>{n.push(t(r,i,e))}),n},pb=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},mb=(e,t)=>{e.doc??Zy();let n=ib(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Ux(N(o,hy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wx(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Ux(N(o,hy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ux(new Uint8Array(n))),i.integrate(e,0);break;case mv:i=new Ux(N(o,hy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new hx(n)),i.integrate(e,0);break;default:if(n instanceof sb)i=new Ux(N(o,hy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Ix(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},gb=()=>Qm(`Length exceeded!`),_b=(e,t,n,r)=>{if(n>t._length)throw gb();if(n===0)return t._searchMarker&&ab(t._searchMarker,n,r.length),hb(e,t,null,r);let i=n,a=ib(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return hb(e,t,r,n)},yb=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=ib(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n0&&s!==null;)s.deleted||(r0)throw gb();t._searchMarker&&ab(t._searchMarker,i,-a+r)},bb=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},xb=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new wx([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new wx([r]);break;case Uint8Array:s=new ux(r);break;case mv:s=new hx(r);break;default:if(r instanceof sb)s=new Ix(r);else throw Error(`Unexpected content type`)}new Ux(N(o,hy(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Sb=(e,t)=>{e.doc??Zy();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Cb=e=>{let t={};return e.doc??Zy(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},wb=(e,t)=>{e.doc??Zy();let n=e._map.get(t);return n!==void 0&&!n.deleted},Tb=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&dy(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Eb=e=>(e.doc??Zy(),Q_(e._map.entries(),e=>!e[1].deleted)),Db=class extends Yy{},Ob=class e extends sb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof sb?e.clone():e)),t}get length(){return this.doc??Zy(),this._length}_callObserver(e,t){super._callObserver(e,t),ob(this,e,new Db(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):jy(this.doc,n=>{_b(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):jy(this.doc,t=>{vb(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):jy(this.doc,n=>{yb(n,this,e,t)})}get(e){return mb(this,e)}toArray(){return lb(this)}slice(e=0,t=this.length){return cb(this,e,t)}toJSON(){return this.map(e=>e instanceof sb?e.toJSON():e)}map(e){return fb(this,e)}forEach(e){db(this,e)}[Symbol.iterator](){return pb(this)}_write(e){e.writeTypeRef(kx)}},kb=e=>new Ob,Ab=class extends Yy{constructor(e,t,n){super(e,t),this.keysChanged=n}},jb=class e extends sb{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof sb?e.clone():e)}),t}_callObserver(e,t){ob(this,e,new Ab(this,e,t))}toJSON(){this.doc??Zy();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof sb?r.toJSON():r}}),e}get size(){return[...Eb(this)].length}keys(){return $_(Eb(this),e=>e[0])}values(){return $_(Eb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return $_(Eb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Zy(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):jy(this.doc,t=>{bb(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):jy(this.doc,n=>{xb(n,this,e,t)}),t}get(e){return Sb(this,e)}has(e){return wb(this,e)}clear(){this.doc===null?this._prelimContent.clear():jy(this.doc,e=>{this.forEach(function(t,n,r){bb(e,r,n)})})}_write(e){e.writeTypeRef(Ax)}},Mb=e=>new jb,Nb=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Vh(e,t),Pb=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&eh(),this.right.content.constructor){case yx:this.right.deleted||Rb(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Fb=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case yx:t.right.deleted||Rb(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{let i=new Map,a=r?ib(t,n):null;return a?Fb(e,new Pb(a.p.left,a.p,a.index,i),n-a.index):Fb(e,new Pb(null,t._start,0,i),n)},Lb=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===yx&&Nb(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Ux(N(a,hy(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new yx(o,r));l.integrate(e,0),n.right=l,n.forward()})},Rb=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},zb=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===yx&&Nb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Bb=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Nb(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Ux(N(a,hy(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new yx(s,c)),n.right.integrate(e,0),n.forward()}}return o},Vb=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;zb(n,i);let s=Bb(e,t,n,i),c=r.constructor===String?new Ex(r):r instanceof sb?new Ix(r):new _x(r),{left:l,right:u,index:d}=n;t._searchMarker&&ab(t._searchMarker,n.index,c.getLength()),u=new Ux(N(o,hy(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Lb(e,t,n,s)},Hb=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;zb(n,i);let s=Bb(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===yx));){if(!n.right.deleted)switch(n.right.content.constructor){case yx:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Nb(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r0){let i=``;for(;r>0;r--)i+=`
-`;n.right=new Ux(N(o,hy(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Ex(i)),n.right.integrate(e,0),n.forward()}Lb(e,t,n,s)},Ub=(e,t,n,r,i)=>{let a=t,o=Wp();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===yx){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case yx:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Rb(i,n);break}}}t=t.right}return s},Wb=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===yx){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Gb=e=>{let t=0;return jy(e.doc,n=>{let r=e._start,i=e._start,a=Wp(),o=Gp(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case yx:Rb(o,i.content);break;default:t+=Ub(n,r,i,a,o),a=Gp(o),r=i}i=i.right}}),t},Kb=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&Cy(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===yx&&e.constructor!==lx&&t.add(e.parent)})}jy(n,n=>{nv(e,e.deleteSet,e=>{if(e instanceof lx||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===yx?t.add(r):Wb(n,e)});for(let e of t)Gb(e)})},qb=(e,t,n)=>{let r=n,i=Gp(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Ix:case _x:case Ex:n{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}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=[];jy(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Rh(o)||(e.attributes=Ph({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Ix:case _x:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Ex:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case yx:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Nb(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Nb(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Nb(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Nb(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Rb(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Yb=class e extends sb{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Zy(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Jb(this,e,t);ob(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Zy();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Ex&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):jy(this.doc,n=>{let r=new Pb(null,this._start,0,new Map);for(let i=0;i0)&&Vb(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&qb(n,r,a.delete):Hb(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??Zy();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(dy(s,e)||t!==void 0&&dy(s,t))switch(s.content.constructor){case Ex:{let r=i.get(`ychange`);e!==void 0&&!dy(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!dy(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Ix:case _x:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case yx:dy(s,e)&&(c(),Rb(i,s.content))}s=s.right}c()};return e||t?jy(a,n=>{e&&fy(n,e),t&&fy(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):jy(r,r=>{let i=Ib(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Vb(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):jy(r,r=>{let i=Ib(r,this,e,!n);Vb(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):jy(n,n=>{qb(n,Ib(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):jy(r,r=>{let i=Ib(r,this,e,!1);i.right!==null&&Hb(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):jy(this.doc,t=>{bb(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):jy(this.doc,n=>{xb(n,this,e,t)})}getAttribute(e){return Sb(this,e)}getAttributes(){return Cb(this)}_write(e){e.writeTypeRef(jx)}},Xb=e=>new Yb,Zb=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Zy()}[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===ex||t.constructor===Qb)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null: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})}},Qb=class e extends sb{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 e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof sb?e.clone():e)),t}get length(){return this.doc??Zy(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Zb(this,e)}querySelector(e){e=e.toUpperCase();let t=new Zb(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Qp(new Zb(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ob(this,e,new nx(this,t,e))}toString(){return fb(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),db(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):jy(this.doc,n=>{_b(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)jy(this.doc,n=>{let r=e&&e instanceof sb?e._item:e;hb(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw Qm(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):jy(this.doc,n=>{yb(n,this,e,t)})}toArray(){return lb(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return mb(this,e)}slice(e=0,t=this.length){return cb(this,e,t)}forEach(e){db(this,e)}_write(e){e.writeTypeRef(Nx)}},$b=e=>new Qb,ex=class e extends Qb{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((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Ih(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof sb?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i0?` `+t.join(` `):``}>${super.toString()}${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):jy(this.doc,t=>{bb(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):jy(this.doc,n=>{xb(n,this,e,t)})}getAttribute(e){return Sb(this,e)}hasAttribute(e){return wb(this,e)}getAttributes(e){return e?Tb(this,e):Cb(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return db(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Mx),e.writeKey(this.nodeName)}},tx=e=>new ex(e.readKey()),nx=class extends Yy{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},rx=class e extends jb{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Px),e.writeKey(this.hookName)}},ix=e=>new rx(e.readKey()),ax=class e extends Yb{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 e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.keye.nodeName`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Fx)}},ox=e=>new ax,sx=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw $m()}mergeWith(e){return!1}write(e,t,n){throw $m()}integrate(e,t){throw $m()}},cx=0,lx=class extends sx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),gy(e.doc.store,this)}write(e,t){e.writeInfo(cx),e.writeLen(this.length-t)}getMissing(e,t){return null}},ux=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw $m()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},dx=e=>new ux(e.readBuf()),fx=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){sv(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}},px=e=>new fx(e.readLen()),mx=(e,t)=>new mv({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),hx=class e{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 e(mx(this.doc.guid,this.opts))}splice(e){throw $m()}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}},gx=e=>new hx(mx(e.readString(),e.readAny())),_x=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw $m()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},vx=e=>new _x(e.readJSON()),yx=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw $m()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},bx=e=>new yx(e.readKey(),e.readJSON()),xx=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r{let t=e.readLen(),n=[];for(let r=0;r{let t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}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}},Dx=e=>new Ex(e.readString()),Ox=[kb,Mb,Xb,tx,$b,ix,ox],kx=0,Ax=1,jx=2,Mx=3,Nx=4,Px=5,Fx=6,Ix=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw $m()}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(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.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(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Lx=e=>new Ix(Ox[e.readTypeRef()](e)),Rx=(e,t)=>{let n=t,r=0,i;do r>0&&(n=N(n.client,n.clock+r)),i=vy(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Ux);return{item:i,diff:r}},zx=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Bx=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Ux(N(r,i+n),t,N(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=N(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Vx=(e,t)=>em(e,e=>iv(e.deletions,t)),Hx=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return by(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Hx(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=by(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:by(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:by(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||iv(r,d.right.id)||Vx(a.undoStack,d.right.id)||Vx(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=by(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=N(c,hy(s,c)),h=new Ux(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,zx(h,!0),h.integrate(e,0),h},Ux=class e extends sx{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,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(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=hy(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=hy(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Gv&&this.id.client!==this.parent.client&&this.parent.clock>=hy(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=xy(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=by(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===lx||this.right&&this.right.constructor===lx)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Gv){let e=vy(n,this.parent);this.parent=e.constructor===lx?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=xy(e,e.doc.store,N(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 t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),Kv(this.origin,n.origin)){if(n.id.client{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.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(),sv(e.deleteSet,this.id.client,this.id.clock,this.length),Ey(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw eh();this.content.gc(e),t?Sy(e,this,new lx(this.id,this.length)):this.content=new fx(this.length)}write(e,t){let n=t>0?N(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=Jv(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Gv?(e.writeParentInfo(!1),e.writeLeftID(t)):eh();i!==null&&e.writeString(i)}this.content.write(e,t)}},Wx=(e,t)=>Gx[t&31](e),Gx=[()=>{eh()},px,Sx,dx,Dx,vx,bx,Lx,Tx,gx,()=>{eh()}],Kx=10,qx=class extends sx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){eh()}write(e,t){e.writeInfo(Kx),j(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Jx=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Yx=`__ $YJS$ __`;Jx[Yx]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Jx[Yx]=!0;var Xx=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},Zx=(e,t)=>e>>>t|e<<32-t,Qx=e=>Zx(e,2)^Zx(e,13)^Zx(e,22),$x=e=>Zx(e,6)^Zx(e,11)^Zx(e,25),eS=e=>Zx(e,7)^Zx(e,18)^e>>>3,tS=e=>Zx(e,17)^Zx(e,19)^e>>>10,nS=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),rS=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),iS=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(rS),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=tS(t[e-2])+t[e-7]+eS(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+$x(o)+(o&s^~o&c)+nS[e]+t[e]>>>0,d=Qx(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3=0&&t>>(3-t)*8;return i}},aS=e=>new iS().digest(e),oS=/[\uD800-\uDBFF]/,sS=/[\uDC00-\uDFFF]/,cS=(e,t)=>{let n=0,r=0;for(;n0&&oS.test(e[n-1])&&n--;r+n0&&sS.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}};function lS(e){if(!e||!(e.content instanceof Ix))return null;let t=e.content.type;if(!(t instanceof Qb||t instanceof Yb||t instanceof rx))throw Error(`Expected a Yjs XML type`);return t}function uS(e){if(e===null)return null;if(!(e.parent instanceof sb))throw Error(`Expected an integrated Yjs parent`);let t=e.parent;if(!(t instanceof Qb||t instanceof Yb||t instanceof rx))throw Error(`Expected a Yjs XML type`);return t}var dS=(e,t)=>{let n=null,r=null;return e._item===null?r=Jv(e):n=N(e._item.id.client,e._item.id.clock),new Xv(n,r,t.id)},fS=(e,t,n)=>{if(e===0)return ty(t,0,-1);let r=lS(t._first);for(;r!==null&&t!==r;){if(r instanceof ax){if(r._length>=e)return ty(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=lS(r._item.next);else{do r=uS(r._item),e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:lS(r._item.next))}}else{let i=n.get(r),a=i instanceof le?i.nodeSize:0;if(r._first!==null&&e1)return new Xv(r._item===null?null:r._item.id,r._item===null?Jv(r):null,null);if(e-=a,r._item!==null&&r._item.next!==null)r=lS(r._item.next);else{if(e===0){if(r=r._item===null?r:uS(r._item),r===null)throw eh();return new Xv(r._item===null?null:r._item.id,r._item===null?Jv(r):null,null)}do{if(r=uS(r._item),r===null)throw eh();e--}while(r!==t&&r._item?.next===null);r!==t&&(r=lS(r._item?.next))}}}if(r===null)throw eh();if(e===0&&r.constructor!==ax&&r!==t){let e=r._item,t=uS(e);if(e===null||t===null)throw eh();return dS(t,e)}}return ty(t,t._length,-1)},pS=(e,t)=>{if(!e.docChanged)return!1;if(e.doc.childCount!==t.childCount)return!0;for(let n of e.steps)if(n instanceof Dt){if(n.from===0&&n.to===t.content.size)return!0;if(n.slice.content.size>0){let e=!1;if(n.slice.content.forEach(t=>{t.isBlock&&(e=!0)}),e)return!0}else if(n.to>n.from){let e=t.resolve(n.from),r=t.resolve(n.to);if(e.depth===0&&r.depth===0&&e.index()!==r.index())return!0}}return!1};function mS(e,t){if(e instanceof ax)return e._length;let n=t.get(e);return n instanceof le?n.nodeSize:null}function hS(e,t,n){let r=0,i=e._first;for(;i!==null;){let e=lS(i);if(e===t)break;let a=i.deleted;if(i=i.right,a)continue;if(e===null)return null;let o=mS(e,n);if(o===null)return null;r+=o}return r}function gS(e,t,n){let r=0,i=0,a=e._first;for(;i{if(n===null)return!1;let r=ay(t,e);return r!==null&&r.type instanceof ax&&t.item!==null&&r.type._item?.deleted===!0},vS=e=>{if(!e.doc)throw Error(`The Yjs fragment must belong to a document`);let t=e._item?`item:${e._item.id.client}:${e._item.id.clock}`:`root:${Jv(e)}`;return e.doc.getMap(`__tiptap_position_migrations:${t}`)},yS=new WeakMap,bS=(e,t)=>{let n=t.item??t.type;if(!n)return[];let r;t.item||(r=t.assoc<0?`start`:`end`);let i=yS.get(e);if(!i||i.size!==e.size){let t=new Map;e.forEach(e=>e.transfers.forEach(n=>{let r=t.get(n.source.client)??[];r.push({migration:e,transfer:n}),t.set(n.source.client,r)})),i={size:e.size,clients:t},yS.set(e,i)}let a=(i.clients.get(n.client)??[]).filter(({transfer:e})=>e.source.boundary===r&&e.source.clock<=n.clock&&n.clock!a.some(t=>t.migration!==e.migration&&t.migration.seen.some(([t,n])=>t===e.migration.client&&n>e.migration.clock)))},xS=(e,t,n)=>{let{source:r,target:i}=e.transfer;return i?new Xv(i.boundary?N(i.client,i.clock):i.type,i.tname??null,i.boundary?null:N(i.client,i.clock+t.clock-r.clock),i.assoc??n):null},SS=(e,t,n)=>{let r=xS(e[0],t,n);return!r||e.some(e=>{let i=xS(e,t,n);return!i||!oy(r,i)})?null:r},CS=e=>{let t=e.item??e.type;if(!t)return null;let n=e.assoc<0?`start`:`end`;return e.item&&(n=`item`),`${t.client}:${t.clock}:${n}`},wS=(e,t)=>{let n=vS(e),r=new Set,i=t,a=i.item??i.type;for(;a;){let e=CS(i);if(r.has(e))return null;r.add(e);let t=bS(n,i);if(t.length===0)return i;let o=SS(t,a,i.assoc);if(!o)return null;if(CS(o)===e)return o;i=o,a=o.item??o.type}return i},TS=(e,t,n,r)=>{let i=wS(t,n);if(!i)return null;n=i;let a=ay(n,e);if(a===null||a.type!==t&&!Yv(t,a.type._item))return null;let o=a.type,s=0;if(o.constructor===ax)s=a.index;else if(!o._item?.deleted){let e=gS(o,a.index,r);if(e===null)return null;s=e+1}for(;o!==t&&o._item!==null;){let e=uS(o._item);if(e===null)return null;if(e._item?.deleted){o=e;continue}let t=hS(e,o,r);if(t===null)return null;s+=t+1,o=e}let c=s-1;return _S(e,n,c)?null:c},ES=new D(`y-sync`),DS=new D(`y-undo`),OS=new D(`yjs-cursor`),kS=null;function AS(){let e=kS;kS=null;let t=[];return e?.forEach((e,n)=>{e.forEach((e,r)=>t.push({view:n,key:r,value:e}))}),t}function jS(e=AS(),t=!1){let n=!0;for(;e.length>0;){let{view:r,key:i,value:a}=e[0];try{let e=ES.getState(r.state);e&&e.binding.prosemirrorView!==null&&r.dispatch(r.state.tr.setMeta(i,a))}catch(r){if(!(r instanceof RangeError))throw r;t&&n&&e.shift(),e.length>0&&P_(0,()=>jS(e,!0));return}n=!1,e.shift()}}function MS(e,t,n){kS===null&&(kS=new Map,P_(0,jS));let r=kS.get(e);r||(r=new Map,kS.set(e,r)),r.set(t,n)}var NS=(e,t,n)=>e!==t,PS=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(``),i=document.createTextNode(``);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},FS=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),IS=/^#[0-9a-fA-F]{6}$/,LS=e=>typeof e.name==`string`&&typeof e.color==`string`,RS=(e,t,n,r,i)=>{let a=ES.getState(e);if(a==null||a.doc==null||a.binding==null)return k.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?k.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t&&t.cursor!=null){let n={...t.user};if(n.color==null?n.color=`#ffa500`:IS.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`,!LS(n))return;let l=TS(o,a.type,Zv(t.cursor.anchor),a.binding.mapping),u=TS(o,a.type,Zv(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=cm(e.doc.content.size-1,0);l=sm(l,t),u=sm(u,t),s.push(vs.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=sm(l,u),o=cm(l,u);s.push(vs.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),k.create(e.doc,s))},zS=(e,{awarenessStateFilter:t=NS,cursorBuilder:n=PS,selectionBuilder:r=FS,getSelection:i=e=>e.selection}={},a=`cursor`)=>new E({key:OS,state:{init(i,a){return RS(a,e,t,n,r)},apply(i,a,o,s){let c=ES.getState(s),l=i.getMeta(OS),u=c&&c.isChangeOrigin;return i.docChanged&&!u&&pS(i,o.doc)?k.empty:u||l&&l.awarenessUpdated?RS(s,e,t,n,r):i.docChanged?a.map(i.mapping,i.doc):a}},props:{decorations:e=>OS.getState(e)??k.empty},view:t=>{let n=()=>{t.isDestroyed||MS(t,OS,{awarenessUpdated:!0})},r=t=>{let n=ES.getState(t.state);if(!n||!n.binding)return;let r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=fS(o.anchor,n.type,n.binding.mapping),c=fS(o.head,n.type,n.binding.mapping);r.cursor!=null&&oy(Zv(r.cursor.anchor),s)&&oy(Zv(r.cursor.head),c)||e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&TS(n.doc,n.type,Zv(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)},o=()=>r(t);return e.on(`change`,n),t.dom.addEventListener(`focusin`,o),t.dom.addEventListener(`focusout`,o),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,o),t.dom.removeEventListener(`focusout`,o),e.off(`change`,n),e.setLocalStateField(a,null)}}}});function BS(e){let t=ES.getState(e);if(!t)throw Error(`The editor requires ySyncPlugin`);return t}var VS=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)??0)>e.id.clock&&!iv(t.ds,e.id),HS=(e,t,n)=>{if(!e.has(n)){if(e.sizen.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,Ch(t))}let r=e.get(n);if(!r)throw Error(`At least one snapshot color is required`);return r},US=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},WS=e=>{let t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{let r=t[n];return r==null||!Object.prototype.hasOwnProperty.call(r,`default`)||r.default!==e.attrs[n]})},GS=(e,t,n)=>{let r=0,i=0;for(;in)break;r+=t.nodeSize}if(i>=e.childCount)return null;let a=e.child(i),o=e.resolve(n),s=(e,t)=>{if(o.depth===0){let i=e+(n-r),a=e+1,o=e+t.nodeSize-1;return Math.max(a,Math.min(i,o))}if(o.depth>1){let n=GS(o.node(1),t,o.pos-o.start(1));return n===null?null:e+1+n}return t.isTextblock?e+1+Math.min(o.parentOffset,t.content.size):null},c=(n,r=!1)=>{let a=0;for(let t=0;t<=i;t++)n(e.child(t))&&a++;let o=0,c=-1,l=null,u=0;for(let e=0;ee.type===a.type&&US(e.attrs,a.attrs),u=a.textContent,d=c(e=>l(e)&&e.textContent===u);if(d!==null)return d;let f=c(e=>e.type===a.type&&e.textContent===u);if(f!==null)return f;if(!a.isTextblock||WS(a)){let e=c(l,!0);if(e!==null)return e}return c(e=>l(e)&&u!==``&&e.textContent!==``&&(u.startsWith(e.textContent)||e.textContent.startsWith(u)),!0)},KS=(e,t,n,r)=>{if(r===null)return!1;let i=e.resolve(n),a=t.resolve(r);if(!i.parent.isTextblock)return!1;if(!a.parent.isTextblock||i.parent.textContent!==a.parent.textContent||i.parentOffset!==0&&a.parentOffset===0)return!0;let o=i.parentOffset===0&&a.parentOffset===0,s=i.parentOffset!==a.parentOffset||i.parent.type!==a.parent.type||!US(i.parent.attrs,a.parent.attrs);if(o||s){let i=GS(e,t,n);return i!==null&&i!==r}return!1},qS=(e,t,n,r)=>{if(n==null||n<0||n>t.content.size||!(r===null||n>1&&r<=1||KS(t,e,n,r)))return r;let i=GS(t,e,n);return i===null?r:i},JS=(e,t,n,r)=>{if(t!==null&&t.anchor!==null&&t.head!==null){if(t.type===`all`)e.setSelection(new On(e.doc));else if(t.type===`node`){let r=TS(n.doc,n.type,t.anchor,n.mapping);r!==null&&e.setSelection(YS(e,r))}else if(t.type===`nodeRange`){let r=XS(e,TS(n.doc,n.type,t.anchor,n.mapping),TS(n.doc,n.type,t.head,n.mapping),t.depth);r!==null&&e.setSelection(r)}else{let i=TS(n.doc,n.type,t.anchor,n.mapping),a=TS(n.doc,n.type,t.head,n.mapping);r!=null&&(wS(n.type,t.anchor)===t.anchor&&(i=qS(e.doc,r,t.absAnchor,i)),wS(n.type,t.head)===t.head&&(a=qS(e.doc,r,t.absHead,a))),i===null&&(i=a),a===null&&(a=i),i!==null&&a!==null&&e.setSelection(w.between(e.doc.resolve(i),e.doc.resolve(a)))}}},YS=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?T.create(e.doc,t):w.near(n)},XS=(e,t,n,r)=>{if(t===null||n===null)return null;let i=Math.min(Math.max(t,0),e.doc.content.size),a=Math.min(Math.max(n,0),e.doc.content.size);try{let t=C.fromJSON(e.doc,{type:`nodeRange`,anchor:i,head:a,depth:r});return t.ranges.length?t:w.near(e.doc.resolve(i))}catch{return w.near(e.doc.resolve(i))}},ZS=(e,t)=>{let n=t.selection,r=n.toJSON(),i=typeof r.type==`string`?r.type:`text`;return{type:i,depth:i===`nodeRange`&&`depth`in n&&typeof n.depth==`number`?n.depth:void 0,anchor:fS(t.selection.anchor,e.type,e.mapping),head:fS(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},QS=new WeakMap,$S=(e,t)=>{var n;(t instanceof Qb||t instanceof Yb||t instanceof rx)&&(e.delete(t),(n=QS.get(e))==null||n.delete(t))},eC=/(.*)(--[a-zA-Z0-9+/=]{8})$/,tC=e=>eC.exec(e)?.[1]??e,nC=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(tC(r),e[r]));return n},rC=e=>{let t=e.doc,n=e._item;if(!t||!n)throw eh();t.transact(e=>{n.delete(e)},ES)},iC=(e,t,n,r,i,a)=>{let o=e.toDelta(r,i,a);try{return o.map(e=>t.text(e.insert,nC(e.attributes,t)))}catch{return rC(e),null}},aC=e=>{var t;let n=(t=e._item)==null||(t=t.right)==null?void 0:t.content,r=n instanceof Ix?n.type:null;if(!(r instanceof Yb))return;let i=r._item,a=r.doc;i&&a&&!i.deleted&&i.id.client===a.clientID&&(e.applyDelta([{retain:e.length},...r.toDelta()]),a.transact(e=>{i.delete(e)}))},oC=(e,t,n,r)=>{if(e._item){if(!VS(e._item,t))return r?r(`removed`,e._item.id):{type:`removed`};if(!VS(e._item,n))return r?r(`added`,e._item.id):{type:`added`}}},sC=(e,t,n)=>{e.mapping.set(t,n);let r=QS.get(e.mapping);r===void 0&&(r=new WeakMap,QS.set(e.mapping,r)),r.set(t,n)},cC=(e,t,n,r,i,a)=>{let o=n.mapping.get(e),s=Array.isArray(o)?void 0:o;if(s!==void 0&&QS.get(n.mapping)?.get(e)===s)return s;let c=[],l=e=>{if(e instanceof ex){let o=cC(e,t,n,r,i,a);o!==null&&c.push(o)}else e instanceof ax&&(aC(e),iC(e,t,n,r,i,a)?.forEach(e=>c.push(e)))};r===void 0||i===void 0?e.toArray().forEach(l):ub(e,new sy(i.ds,r.sv)).forEach(l);try{let o=e.getAttributes(r),l=r?oC(e,r,i,a):void 0;l!==void 0&&(o.ychange=l);let u=t.node(e.nodeName,o,c);return s?.eq(u)&&(u=s),sC(n,e,u),u}catch{return rC(e),$S(n.mapping,e),null}},lC=e=>{for(let t=6;tlg(lC(aS(fg(e)))),dC=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=Kp(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${uC(e.toJSON())}`:e.type.name]=e.attrs}}),n},fC=(e,t)=>{let n=new ax,r=e.map(e=>({insert:e.text??``,attributes:dC(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},pC=e=>{let t=e.content.content,n=[];for(let e=0;ee instanceof Array?fC(e,t):hC(e,t),hC=(e,t)=>{let n=new ex(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,pC(e).map(e=>mC(e,t))),t.mapping.set(n,e),n},gC=e=>typeof e==`object`&&!!e,_C=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Fh(e.attributes||{}).length===t[n].marks.length&&Object.entries(e.attributes??{}).every(([e,r])=>{let i=tC(e),a=t[n].marks.find(e=>e.type.name===i);return a?_C(r,a.attrs):!1}))},yC=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,bC=(e,t)=>{if(e instanceof ex&&!(t instanceof Array)&&yC(e,t)){let n=pC(t);return e._length===n.length&&_C(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>bC(e,n[t]))}return e instanceof ax&&t instanceof Array&&vC(e,t)},xC=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),SC=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});let i=[];if(e.forEach((e,a)=>{let o=n.mapping.get(e),s=o===void 0?void 0:r.get(o);s!==void 0&&xC(o,t[s])&&i.push({yIndex:a,pIndex:s,yChild:e})}),i.length===0)return[];let a=[],o=[];for(let e=0;e>1;i[o[r]].pIndex