From eafb284a684db0c8f1dd2037320ed0ef1ce29de2 Mon Sep 17 00:00:00 2001 From: Usman Khalid Date: Tue, 27 Jan 2026 13:08:32 -0500 Subject: [PATCH 1/3] feat: allow block/table copy and drag --- blocks/edit/da-editor/da-editor.css | 31 ++ blocks/edit/img/drag-handle.svg | 8 + blocks/edit/prose/index.js | 6 +- blocks/edit/prose/plugins/imageDrop.js | 4 +- blocks/edit/prose/plugins/tableDragHandle.js | 174 ++++++++ blocks/edit/prose/schema.js | 373 ++++++++++++++++++ deps/da-y-wrapper/dist/index.js | 26 +- deps/da-y-wrapper/src/index.js | 2 + .../prose/plugins/tableDragHandle.test.js | 201 ++++++++++ 9 files changed, 808 insertions(+), 17 deletions(-) create mode 100644 blocks/edit/img/drag-handle.svg create mode 100644 blocks/edit/prose/plugins/tableDragHandle.js create mode 100644 blocks/edit/prose/schema.js create mode 100644 test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js diff --git a/blocks/edit/da-editor/da-editor.css b/blocks/edit/da-editor/da-editor.css index 1ad82d21..13c5187b 100644 --- a/blocks/edit/da-editor/da-editor.css +++ b/blocks/edit/da-editor/da-editor.css @@ -8,6 +8,7 @@ --editor-btn-bg-color: #EFEFEF; --editor-btn-bg-color-hover: var(--s2-blue-900); + position: relative; grid-area: editor; } @@ -981,3 +982,33 @@ da-diff-deleted, da-diff-added { .focal-point-icon:hover svg { color: #0265dc; } + +.table-drag-handle { + position: absolute; + width: 20px; + height: 20px; + background-color: #fff; + background-image: url('/blocks/edit/img/drag-handle.svg'); + background-repeat: no-repeat; + background-position: center; + border: 1px solid #ccc; + border-radius: 4px; + z-index: 100; + cursor: grab; + display: none; + align-items: center; + justify-content: center; +} + +.table-drag-handle.is-visible { + display: flex; +} + +.table-drag-handle:hover { + background-color: #f0f7ff; + border-color: var(--s2-blue-800); +} + +.table-drag-handle:active { + cursor: grabbing; +} diff --git a/blocks/edit/img/drag-handle.svg b/blocks/edit/img/drag-handle.svg new file mode 100644 index 00000000..fcb14001 --- /dev/null +++ b/blocks/edit/img/drag-handle.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js index 5996c1c5..f8780e46 100644 --- a/blocks/edit/prose/index.js +++ b/blocks/edit/prose/index.js @@ -11,6 +11,7 @@ import { liftListItem, sinkListItem, gapCursor, + dropCursor, TextSelection, NodeSelection, Plugin, @@ -29,6 +30,7 @@ import { linkItem } from './plugins/menu/linkItem.js'; import codemark from './plugins/codemark.js'; import imageDrop from './plugins/imageDrop.js'; import imageFocalPoint from './plugins/imageFocalPoint.js'; +import tableDragHandle from './plugins/tableDragHandle.js'; import linkConverter from './plugins/linkConverter.js'; import linkTextSync from './plugins/linkTextSync.js'; import sectionPasteHandler from './plugins/sectionPasteHandler.js'; @@ -347,6 +349,7 @@ export default function initProse({ path, permissions }) { trackCursorAndChanges(), slashMenu(), linkMenu(), + tableDragHandle(), imageDrop(schema), linkConverter(schema), linkTextSync(), @@ -380,7 +383,8 @@ export default function initProse({ path, permissions }) { 'Shift-Tab': liftListItem(schema.nodes.list_item), }), gapCursor(), - tableEditing(), + dropCursor({ color: 'var(--s2-blue-800)', width: 2 }), + tableEditing({ allowTableNodeSelection: true }), ]; if (canWrite) { diff --git a/blocks/edit/prose/plugins/imageDrop.js b/blocks/edit/prose/plugins/imageDrop.js index 5bb24b6e..fdbd51a6 100644 --- a/blocks/edit/prose/plugins/imageDrop.js +++ b/blocks/edit/prose/plugins/imageDrop.js @@ -11,11 +11,11 @@ export default function imageDrop(schema) { props: { handleDOMEvents: { drop: (view, event) => { - event.preventDefault(); - const { files } = event.dataTransfer; if (files.length === 0) return; + event.preventDefault(); + ([...files]).forEach(async (file) => { if (!SUPPORTED_FILES.some((type) => type === file.type)) return; diff --git a/blocks/edit/prose/plugins/tableDragHandle.js b/blocks/edit/prose/plugins/tableDragHandle.js new file mode 100644 index 00000000..3f31c5f0 --- /dev/null +++ b/blocks/edit/prose/plugins/tableDragHandle.js @@ -0,0 +1,174 @@ +import { Plugin, NodeSelection } from 'da-y-wrapper'; + +const HANDLE_OFFSET = 6; + +function getTablePos(view, tableEl) { + const pos = view.posAtDOM(tableEl, 0); + + if (pos === null) { + return null; + } + + const $pos = view.state.doc.resolve(pos); + for (let d = $pos.depth; d >= 0; d -= 1) { + if ($pos.node(d).type.name === 'table') { + return $pos.before(d); + } + } + + return null; +} + +/** + * Allows dragging and easier copy/pasting of entire blocks/tables. + */ +export default function tableDragHandle() { + let handle = null; + let currentTable = null; + let currentWrapper = null; + + function showHandle(wrapper, editorRect) { + if (!handle || !wrapper) { + return; + } + const rect = wrapper.getBoundingClientRect(); + handle.style.left = `${rect.left - editorRect.left + HANDLE_OFFSET}px`; + handle.style.top = `${rect.top - editorRect.top + HANDLE_OFFSET}px`; + handle.classList.add('is-visible'); + } + + function hideHandle() { + handle?.classList.remove('is-visible'); + currentTable = null; + currentWrapper = null; + } + + function createHandle(view) { + const el = document.createElement('div'); + el.className = 'table-drag-handle'; + el.draggable = true; + el.contentEditable = 'false'; + + el.addEventListener('mousedown', (e) => { + if (!currentTable) { + return; + } + + e.stopPropagation(); + + const tablePos = getTablePos(view, currentTable); + + if (tablePos !== null) { + const sel = NodeSelection.create(view.state.doc, tablePos); + view.dispatch(view.state.tr.setSelection(sel)); + } + }); + + el.addEventListener('dragstart', (e) => { + if (!currentTable) { + e.preventDefault(); + return; + } + + const tablePos = getTablePos(view, currentTable); + + if (tablePos === null) { + e.preventDefault(); + return; + } + + let { state } = view; + const sel = NodeSelection.create(state.doc, tablePos); + view.dispatch(state.tr.setSelection(sel)); + state = view.state; + + const slice = state.selection.content(); + view.dragging = { slice, move: true }; + e.dataTransfer.effectAllowed = 'move'; + }); + + el.addEventListener('mouseleave', (e) => { + if (e.relatedTarget && currentWrapper?.contains(e.relatedTarget)) { + return; + } + + hideHandle(); + }); + + el.addEventListener('dragend', () => { + hideHandle(); + }); + + return el; + } + + return new Plugin({ + props: { + handleDOMEvents: { + drop(view, event) { + const isFileDrop = event.dataTransfer.files.length > 0; + if (isFileDrop) { + // let imageDrop handle it. + return false; + } + + if (!view.dragging) { + return true; + } + + const isTableDrag = view.dragging.slice.content.firstChild?.type.name === 'table'; + return !isTableDrag; + }, + }, + }, + view(editorView) { + handle = createHandle(editorView); + const container = editorView.dom.parentElement; + + if (container) { + container.appendChild(handle); + } + + const onMouseOver = (e) => { + const wrapper = e.target.closest('.tableWrapper'); + + if (!wrapper || wrapper === currentWrapper) { + return; + } + + currentWrapper = wrapper; + currentTable = wrapper.querySelector('table'); + const editorRect = editorView.dom.getBoundingClientRect(); + showHandle(wrapper, editorRect); + }; + + const onMouseOut = (e) => { + const wrapper = e.target.closest('.tableWrapper'); + + if (!wrapper) { + return; + } + + const related = e.relatedTarget; + + if (related === handle || wrapper.contains(related)) { + return; + } + + hideHandle(); + }; + + editorView.dom.addEventListener('mouseover', onMouseOver); + editorView.dom.addEventListener('mouseout', onMouseOut); + + return { + destroy() { + editorView.dom.removeEventListener('mouseover', onMouseOver); + editorView.dom.removeEventListener('mouseout', onMouseOut); + handle?.remove(); + handle = null; + }, + }; + }, + }); +} diff --git a/blocks/edit/prose/schema.js b/blocks/edit/prose/schema.js new file mode 100644 index 00000000..675ab11a --- /dev/null +++ b/blocks/edit/prose/schema.js @@ -0,0 +1,373 @@ +/* + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +/* + * IMPORTANT: + * Until getSchema() is separated into its own module, + * these files need to be kept in-sync: + * + * da-live /blocks/edit/prose/schema.js + * da-collab /src/schema.js + * + * Note that the import locations are different between the two files + * but otherwise the files should be identical. + */ + +import { addListNodes, Schema, tableNodes } from 'da-y-wrapper'; + +function parseLocDOM(locTag) { + return [ + { + tag: locTag, + contentElement: (dom) => dom, + }, + ]; +} + +const topLevelAttrs = { + dataId: { default: null, validate: 'string|null' }, + daDiffAdded: { default: null, validate: 'string|null' }, +}; + +const getTopLevelToDomAttrs = (node) => { + const attrs = {}; + if (node.attrs.dataId != null) attrs['data-id'] = node.attrs.dataId; + if (node.attrs.daDiffAdded === '') attrs['da-diff-added'] = ''; + return attrs; +}; + +const getTopLevelParseAttrs = (dom) => ({ + dataId: dom.getAttribute('dataId') ?? null, + daDiffAdded: dom.getAttribute('da-diff-added') ?? null, +}); + +const getHeadingAttrs = (level) => (dom) => ({ + level, + ...getTopLevelParseAttrs(dom), +}); + +/* Base nodes taken from prosemirror-schema-basic */ +const baseNodes = { + doc: { content: 'block+' }, + paragraph: { + attrs: { ...topLevelAttrs }, + content: 'inline*', + group: 'block', + parseDOM: [{ tag: 'p', getAttrs: getTopLevelParseAttrs }], + toDOM(node) { + return ['p', { ...getTopLevelToDomAttrs(node) }, 0]; + }, + }, + blockquote: { + attrs: { ...topLevelAttrs }, + content: 'block+', + group: 'block', + defining: true, + parseDOM: [{ tag: 'blockquote', getAttrs: getTopLevelParseAttrs }], + toDOM(node) { + return ['blockquote', { ...getTopLevelToDomAttrs(node) }, 0]; + }, + }, + horizontal_rule: { + group: 'block', + parseDOM: [{ tag: 'hr' }], + toDOM() { + return ['hr']; + }, + }, + heading: { + attrs: { + level: { default: 1 }, + ...topLevelAttrs, + }, + content: 'inline*', + group: 'block', + defining: true, + parseDOM: [ + { tag: 'h1', getAttrs: getHeadingAttrs(1) }, + { tag: 'h2', getAttrs: getHeadingAttrs(2) }, + { tag: 'h3', getAttrs: getHeadingAttrs(3) }, + { tag: 'h4', getAttrs: getHeadingAttrs(4) }, + { tag: 'h5', getAttrs: getHeadingAttrs(5) }, + { tag: 'h6', getAttrs: getHeadingAttrs(6) }, + ], + toDOM(node) { + return [`h${node.attrs.level}`, { ...getTopLevelToDomAttrs(node) }, 0]; + }, + }, + code_block: { + attrs: { ...topLevelAttrs }, + content: 'text*', + marks: '', + group: 'block', + code: true, + defining: true, + parseDOM: [{ tag: 'pre', preserveWhitespace: 'full', getAttrs: getTopLevelParseAttrs }], + toDOM(node) { + return ['pre', { ...getTopLevelToDomAttrs(node) }, ['code', 0]]; + }, + }, + text: { group: 'inline' }, + // due to bug in y-prosemirror, add href to image node + // which will be converted to a wrapping tag + image: { + inline: true, + attrs: { + src: { validate: 'string' }, + alt: { default: null, validate: 'string|null' }, + title: { default: null, validate: 'string|null' }, + href: { default: null, validate: 'string|null' }, + dataFocalX: { default: null, validate: 'string|null' }, + dataFocalY: { default: null, validate: 'string|null' }, + ...topLevelAttrs, + }, + group: 'inline', + draggable: true, + parseDOM: [ + { + tag: 'img[src]', + getAttrs(dom) { + const attrs = { + src: dom.getAttribute('src'), + alt: dom.getAttribute('alt'), + href: dom.getAttribute('href'), + dataFocalX: dom.getAttribute('data-focal-x'), + dataFocalY: dom.getAttribute('data-focal-y'), + ...getTopLevelParseAttrs(dom), + }; + const title = dom.getAttribute('title'); + // TODO: Remove this once helix properly supports data-focal-x and data-focal-y + if (!title?.includes('data-focal:')) { + attrs.title = title; + } + return attrs; + }, + }, + ], + toDOM(node) { + const { + src, alt, title, href, dataFocalX, dataFocalY, + } = node.attrs; + const attrs = { + src, + alt, + title, + href, + ...getTopLevelToDomAttrs(node), + }; + if (dataFocalX != null) attrs['data-focal-x'] = dataFocalX; + if (dataFocalY != null) attrs['data-focal-y'] = dataFocalY; + // TODO: This is temp code to store the focal data in the title attribute + // Once helix properly supports data-focal-x and data-focal-y, we can remove this code + if (dataFocalX != null) attrs.title = `data-focal:${dataFocalX},${dataFocalY}`; + return ['img', attrs]; + }, + }, + hard_break: { + inline: true, + group: 'inline', + selectable: false, + parseDOM: [{ tag: 'br' }], + toDOM() { + return ['br']; + }, + }, + loc_added: { + group: 'block', + content: 'block+', + atom: true, + isolating: true, + parseDOM: parseLocDOM('da-loc-added'), + toDOM: () => ['da-loc-added', { contenteditable: false }, 0], + }, + diff_added: { + group: 'block', + content: 'block+', + atom: true, + isolating: true, + parseDOM: [ + { + tag: 'da-diff-added', + contentElement: (dom) => { + [...dom.children].forEach((child) => { + if (child.properties) { + // eslint-disable-next-line no-param-reassign + child.properties['da-diff-added'] = ''; + } + }); + return dom; + }, + }, + { + tag: 'da-loc-added', // Temp code to support old regional edits + contentElement: (dom) => { + [...dom.children].forEach((child) => { + if (child.properties) { + // eslint-disable-next-line no-param-reassign + child.properties['da-diff-added'] = ''; + } + }); + return dom; + }, + }, + ], + toDOM: () => ['da-diff-added', { contenteditable: false }, 0], + }, + loc_deleted: { + group: 'block', + content: 'block+', + atom: true, + isolating: true, + parseDOM: parseLocDOM('da-loc-deleted'), + toDOM: () => ['da-loc-deleted', { contenteditable: false }, 0], + }, + diff_deleted: { + group: 'block', + content: 'block+', + atom: true, + isolating: true, + parseDOM: [ + { + tag: 'da-diff-deleted', + contentElement: (dom) => dom, + }, + { + tag: 'da-loc-deleted', // Temp code to support old regional edits + contentElement: (dom) => dom, + }, + ], + toDOM: () => ['da-diff-deleted', { 'data-mdast': 'ignore', contenteditable: false }, 0], + }, +}; + +const baseMarks = { + s: { + parseDOM: [{ tag: 's' }], + toDOM() { + return ['s', 0]; + }, + }, + em: { + parseDOM: [{ tag: 'i' }, { tag: 'em' }, { style: 'font-style=italic' }, { style: 'font-style=normal', clearMark: (m) => m.type.name === 'em' }], + toDOM() { + return ['em', 0]; + }, + }, + strong: { + parseDOM: [ + { tag: 'strong' }, + // This works around a Google Docs misbehavior where + // pasted content will be inexplicably wrapped in `` + // tags with a font-weight normal. + { tag: 'b', getAttrs: (node) => node.style.fontWeight !== 'normal' && null }, + { style: 'font-weight=400', clearMark: (m) => m.type.name === 'strong' }, + { style: 'font-weight', getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null }, + ], + toDOM() { + return ['strong', 0]; + }, + }, + link: { + attrs: { + href: {}, + title: { default: null }, + ...topLevelAttrs, + }, + inclusive: false, + parseDOM: [ + { + tag: 'a[href]', + getAttrs(dom) { + return { href: dom.getAttribute('href'), title: dom.getAttribute('title'), ...getTopLevelParseAttrs(dom) }; + }, + }, + ], + toDOM(node) { + const { href, title } = node.attrs; + return ['a', { href, title, ...getTopLevelToDomAttrs(node) }, 0]; + }, + }, + code: { + parseDOM: [{ tag: 'code' }], + toDOM() { + return ['code', 0]; + }, + }, + u: { + parseDOM: [{ tag: 'u' }], + toDOM() { + return ['u', 0]; + }, + }, +}; + +const baseSchema = new Schema({ nodes: baseNodes, marks: baseMarks }); + +function addCustomMarks(marks) { + const sup = { + parseDOM: [{ tag: 'sup' }, { clearMark: (m) => m.type.name === 'sup' }], + toDOM() { + return ['sup', 0]; + }, + }; + + const sub = { + parseDOM: [{ tag: 'sub' }, { clearMark: (m) => m.type.name === 'sub' }], + toDOM() { + return ['sub', 0]; + }, + }; + + const contextHighlight = { toDOM: () => ['span', { class: 'highlighted-context' }, 0] }; + + return marks.addToEnd('sub', sub).addToEnd('sup', sup).addToEnd('contextHighlightingMark', contextHighlight); +} + +function getTableNodeSchema() { + const schema = tableNodes({ tableGroup: 'block', cellContent: 'block+' }); + schema.table.attrs = { ...topLevelAttrs }; + schema.table.parseDOM = [{ tag: 'table', getAttrs: getTopLevelParseAttrs }]; + schema.table.toDOM = (node) => ['table', node.attrs, ['tbody', 0]]; + schema.table.draggable = true; + return schema; +} + +function addAttrsToListNode(_nodes, listType, tag) { + const nodes = _nodes; + nodes.get(listType).attrs = { ...topLevelAttrs }; + nodes.get(listType).parseDOM = [{ tag, getAttrs: getTopLevelParseAttrs }]; + nodes.get(listType).toDOM = (node) => [tag, { ...getTopLevelToDomAttrs(node) }, 0]; +} + +function addListNodeSchema(nodes) { + const withListNodes = addListNodes(nodes, 'block+', 'block'); + addAttrsToListNode(withListNodes, 'bullet_list', 'ul'); + addAttrsToListNode(withListNodes, 'ordered_list', 'ol'); + return withListNodes; +} + +// eslint-disable-next-line import/prefer-default-export +export function getSchema() { + let { nodes } = baseSchema.spec; + const { marks } = baseSchema.spec; + nodes = addListNodeSchema(nodes); + + // Update diff nodes to allow list_item after list nodes are added + nodes = nodes.update('diff_deleted', { ...nodes.get('diff_deleted'), content: '(block | list_item)+' }); + nodes = nodes.update('diff_added', { ...nodes.get('diff_added'), content: '(block | list_item)+' }); + nodes = nodes.update('loc_deleted', { ...nodes.get('loc_deleted'), content: '(block | list_item)+' }); + nodes = nodes.update('loc_added', { ...nodes.get('loc_added'), content: '(block | list_item)+' }); + + nodes = nodes.append(getTableNodeSchema()); + const customMarks = addCustomMarks(marks); + return new Schema({ nodes, marks: customMarks }); +} diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 9d1b4d73..dfd129ad 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,15 +1,13 @@ -var dm=Object.defineProperty;var um=(n,e)=>{for(var t in e)dm(n,t,{get:e[t],enumerable:!0})};function he(n){this.content=n}he.prototype={constructor:he,find:function(n){for(var e=0;e>1}};he.from=function(n){if(n instanceof he)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new he(e)};var Zo=he;function Xa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Xa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Qa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?ls(r+1,o):ls(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var rn=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=eh(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Za(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function Za(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Za(s.content,e-i-1,t-i-1)))}function eh(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=eh(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function pm(n,e,t){if(t.openStart>n.depth)throw new rn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new rn("Inconsistent open depths");return th(n,e,t,0)}function th(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function zr(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(tn(n.nodeAfter,r),s++));for(let l=s;li&&nl(n,e,i+1),o=r.depth>i&&nl(t,r,i+1),l=[];return zr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(nh(s,o),tn(nn(s,rh(n,e,t,r,i+1)),l)):(s&&tn(nn(s,hs(n,e,i+1)),l),zr(e,t,i,l),o&&tn(nn(o,hs(t,r,i+1)),l)),zr(r,null,i,l),new w(l)}function hs(n,e,t){let r=[];if(zr(null,n,t,r),n.depth>t){let i=nl(n,e,t+1);tn(nn(i,hs(n,e,t+1)),r)}return zr(e,null,t,r),new w(r)}function mm(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var fs=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new sn(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=$a.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ih(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Be.prototype.text=void 0;var il=class n extends Be{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ih(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ih(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var on=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new sl(e,t);if(r.next==null)return n.empty;let i=sh(r);r.next&&r.err("Unexpected trailing text");let s=Mm(Cm(i));return Am(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` -`)}};on.empty=new on(!0);var sl=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function sh(n){let e=[];do e.push(wm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function wm(n){let e=[];do e.push(bm(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bm(n){let e=km(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=xm(n,e);else break;return e}function qa(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function xm(n,e){let t=qa(n),r=t;return n.eat(",")&&(n.next!="}"?r=qa(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Sm(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function km(n){if(n.eat("(")){let e=sh(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Sm(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Cm(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new on(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ch(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Be(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Be(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Be(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Em(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var ol=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Em(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},$r=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=hh(e,i.attrs),this.excluded=null;let s=lh(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ch(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},qr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Zo.from(e.nodes),t.marks=Zo.from(e.marks||{}),this.nodes=ds.compile(this.spec.nodes,this),this.marks=$r.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=on.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Ja(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Ja(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ds){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new il(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Be.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Ja(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Tm(n){return n.tag!=null}function Dm(n){return n.style!=null}var Wn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Tm(i))this.tags.push(i);else if(Dm(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new ms(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new ms(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=Wa(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=Wa(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},fh={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Om={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},dh={ol:!0,ul:!0},us=1,ps=2,Fr=4;function ja(n,e,t){return e!=null?(e?us:0)|(e==="full"?ps:0):n&&n.whitespace=="pre"?us|ps:t&~Fr}var jn=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Fr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&us)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!fh.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ms=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ja(null,t.preserveWhitespace,0)|(r?Fr:0);i?s=new jn(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new jn(null,null,D.none,!0,null,o):s=new jn(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&ps||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&us)i.options&ps?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;dh.hasOwnProperty(i)&&this.parser.normalizeLists&&Nm(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Om.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(fh.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):Ka(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new jn(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Nm(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&dh.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Im(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Wa(n){let e={};for(let t in n)e[t]=n[t];return e}function Ka(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&cs(tl(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return cs(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Ya(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Ya(e.marks)}};function Ya(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function tl(n){return n.document||window.document}var Ga=new WeakMap;function Rm(n){let e=Ga.get(n);return e===void 0&&Ga.set(n,e=vm(n)),e}function vm(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let f in a)if(a[f]!=null){let d=f.indexOf(" ");d>0?c.setAttributeNS(f.slice(0,d),f.slice(d+1),a[f]):c.setAttribute(f,a[f])}}for(let f=h;fh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=cs(n,d,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var mh=65535,gh=Math.pow(2,16);function Um(n,e){return n+e*gh}function uh(n){return n&mh}function Vm(n){return(n-(n&mh))/gh}var yh=1,wh=2,gs=4,bh=8,jr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&bh)>0}get deletedBefore(){return(this.delInfo&(yh|gs))>0}get deletedAfter(){return(this.delInfo&(wh|gs))>0}get deletedAcross(){return(this.delInfo&gs)>0}},gt=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=uh(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],f=c+a;if(e<=f){let d=a?e==c?-1:e==f?1:t:t,u=c+i+(d<0?0:h);if(r)return u;let p=e==(t<0?c:f)?null:Um(l/3,e-c),m=e==c?wh:e==f?yh:gs;return(t<0?e!=c:e!=f)&&(m|=bh),new jr(u,m,p)}i+=h-a}return r?e+i:new jr(e+i,0,null)}touches(e,t){let r=0,i=uh(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,s)}invert(){return new ln(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Z.jsonID("addMark",Kr);var ln=class n extends Z{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(dl(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,r)}invert(){return new Kr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Z.jsonID("removeMark",ln);var Yr=class n extends Z{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return re.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return re.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};Z.jsonID("replaceAround",ee);function hl(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Bm(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let f=c.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(f);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Pm(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof $r){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new ln(o.from,o.to,o.style)))}function ul(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Lm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function cn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,s=0;;--r){let o=n.$from.node(r),l=n.$from.index(r)+i,c=n.$to.indexAfter(r)-s;if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),f++):c--;let d=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new ee(i,s,i,s,new b(r,0,0),t.length,!0))}function Hm(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jm(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Sh(n,o,l,s),ul(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new ee(f,d,f+1,d-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&xh(n,o,l,s),!1}})}function xh(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Sh(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` -`))}})}function Jm(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function jm(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new ee(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Vt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let f=i.node(a),d=i.index(a);if(f.type.spec.isolating)return!1;let u=f.content.cutByIndex(d,f.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wm(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ne(e,e,new b(s.append(o),t,t),!0))}function an(n,e){let t=n.resolve(e),r=t.index();return kh(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Km(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&kh(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Ym(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Sh(n,h.node(),h.before(),l)}o.inlineContent&&ul(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ne(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);xh(n,h.node(),h.before(),n.steps.length)}return n}function Gm(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let f=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=f&&a.canReplaceWith(c,c,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function xs(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Mh(i,s,r)?new Ne(e,t,r):new fl(i,s,r).fit()}function Mh(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var fl=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new ee(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ne(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=cl(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,f=null;if(t==1&&(o?a.matchType(o.type)||(f=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Hr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Hr(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(f=g,h.push(Ah(m.mark(d.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Jr(this.placed,t,w.from(h)),this.frontier[t].match=f,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=al(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Jr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Jr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Jr(this.placed,this.frontier.length,t))}};function Hr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Hr(n.firstChild.content,e-1,t)))}function Jr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Jr(n.lastChild.content,e-1,t)))}function cl(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ah(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function al(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Xm(t,s.content,o)?l:null}function Xm(n,e,t){for(let r=t;r0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let c=o.indexOf(l),a=[],h=r.openStart;for(let d=r.content,u=0;;u++){let p=d.firstChild;if(a.push(p),u==r.openStart)break;d=p.content}for(let d=h-1;d>=0;d--){let u=a[d],p=Qm(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(p||!u.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let u=(d+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function Eh(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function eg(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Gm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function tg(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Th(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function Th(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var ys=class n extends Z{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return re.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return re.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return gt.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};Z.jsonID("attr",ys);var ws=class n extends Z{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return re.ok(r)}getMap(){return gt.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};Z.jsonID("docAttr",ws);var Yn=class extends Error{};Yn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yn.prototype=Object.create(Error.prototype);Yn.prototype.constructor=Yn;Yn.prototype.name="TransformError";var Gn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Wr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=xs(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Zm(this,e,t,r),this}replaceRangeWith(e,t,r){return eg(this,e,t,r),this}deleteRange(e,t){return tg(this,e,t),this}lift(e,t){return zm(this,e,t),this}join(e,t=1){return Ym(this,e,t),this}wrap(e,t){return qm(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hm(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return jm(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ys(e,t,r)),this}setDocAttribute(e,t){return this.step(new ws(e,t)),this}addNodeMark(e,t){return this.step(new Yr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof D)t.isInSet(r.marks)&&this.step(new Kn(e,t));else{let i=r.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Kn(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,r){return Wm(this,e,t,r),this}addMark(e,t,r){return Bm(this,e,t,r),this}removeMark(e,t,r){return Pm(this,e,t,r),this}clearIncompatible(e,t,r){return ul(this,e,t,r),this}};var ml=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Bt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Xn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Xn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Ie(e.node(0))}static atStart(e){return Xn(e,e,0,0,1)||new Ie(e)}static atEnd(e){return Xn(e,e,e.content.size,e.childCount,-1)||new Ie(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=ml[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in ml)throw new RangeError("Duplicate use of selection JSON ID "+e);return ml[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Bt=class{constructor(e,t){this.$from=e,this.$to=t}},Dh=!1;function Oh(n){!Dh&&!n.parent.inlineContent&&(Dh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Oh(e),Oh(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ks(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Xn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Nh(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Ih=1,Ss=2,Rh=4,wl=class extends Gn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ss,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Ss)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ss,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Rh,this}get scrolledIntoView(){return(this.updated&Rh)>0}};function vh(n,e){return!e||!n?n:n.bind(e)}var hn=class{constructor(e,t,r){this.name=e,this.init=vh(t.init,r),this.apply=vh(t.apply,r)}},rg=[new hn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new hn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new hn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new hn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Gr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=rg.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new hn(r.key,r.spec.state,r))})}},bl=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Gr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Be.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function _h(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=_h(i,e,{})),t[r]=i}return t}var J=class{constructor(e){this.spec=e,this.props={},e.props&&_h(e.props,this,this.props),this.key=e.key?e.key.key:Uh("plugin")}getState(e){return e[this.key]}},gl=Object.create(null);function Uh(n){return n in gl?n+"$"+ ++gl[n]:(gl[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=Uh(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ie=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ei=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ml=null,wt=function(n,e,t){let r=Ml||(Ml=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ig=function(){Ml=null},yn=function(n,e,t,r){return t&&(Vh(n,e,t,r,-1)||Vh(n,e,t,r,1))},sg=/^(img|br|input|textarea|hr)$/i;function Vh(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Le(n))){let s=n.parentNode;if(!s||s.nodeType!=1||ii(n)||sg.test(n.nodeName)||n.contentEditable=="false")return!1;e=ie(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function og(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Le(n)}else if(n.parentNode&&!ii(n))e=ie(n),n=n.parentNode;else return null}}function lg(n,e){for(;;){if(n.nodeType==3&&e2),Pe=nr||(Ze?/Mac/.test(Ze.platform):!1),fg=Ze?/Win/.test(Ze.platform):!1,We=/Android \d/.test(qt),si=!!Bh&&"webkitFontSmoothing"in Bh.documentElement.style,dg=si?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ug(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function yt(n,e){return typeof n=="number"?n:n[e]}function pg(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ph(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=ei(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?ug(s):pg(l),h=0,f=0;if(e.topa.bottom-yt(r,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+yt(i,"top")-a.top:e.bottom-a.bottom+yt(i,"bottom")),e.lefta.right-yt(r,"right")&&(h=e.right-a.right+yt(i,"right")),h||f)if(c)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,u=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let p=l.scrollLeft-d,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function mg(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:wf(n.dom)}}function wf(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ei(r));return e}function gg({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;bf(t,r==0?0:r-e)}function bf(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=f+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?wg(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:xf(t,i)}function wg(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ql(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function bg(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function Sg(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Sf(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;si&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Sg(n,r,i,e))}l==null&&(l=xg(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Lh(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Xr(Pt(wt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return xl(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1],a=c.nodeType==3?wt(c,Le(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Xr(Pt(a,1),!1)}if(s==null&&i=0)}function Xr(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function xl(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Cf(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Mg(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Cf(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=kf(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=wt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Ag=/[\u0590-\u08ac]/;function Eg(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Ag.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Cf(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,f),c&&(c!=h||a!=f)&&l.extend&&l.extend(c,a)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var zh=null,Fh=null,$h=!1;function Tg(n,e,t){return zh==e&&Fh==t?$h:(zh=e,Fh=t,$h=t=="up"||t=="down"?Mg(n,e,t):Eg(n,e,t))}var ze=0,qh=1,dn=2,et=3,wn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ze,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tie(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof As){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Cs&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?ie(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ie(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let d=document.createRange();d.setEnd(c.node,c.offset),d.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?dn:qh,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=et:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?dn:et}r=o}this.dirty=dn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?dn:qh;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ze&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Dl=class extends wn{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},rr=class n extends wn{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Ut.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=et&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ze){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Rl(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,f=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=Ut.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=Ef(h,r,t),a?c=new Ol(e,t,r,i,h,f||null,d,a,s,o+1):t.isText?new Ms(e,t,r,i,h,d,s):new n(e,t,r,i,h,f||null,d,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==ze&&e.eq(this.node)&&Es(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Il(this,o&&o.node,e);Ig(this.node,this.innerDeco,(a,h,f)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!f&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,f,d)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,f,u,e)||c.updateNextNode(a,h,f,e,d,i)||c.addNode(a,h,f,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==dn)&&(o&&this.protectLocalComposition(e,o),Mf(this.contentDOM,this.children,e),nr&&Rg(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=vg(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Dl(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rl(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==et||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ze}updateOuterDeco(e){if(Es(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Af(this.dom,this.nodeDOM,Nl(this.outerDeco,this.node,t),Nl(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Hh(n,e,t,r,i){Ef(r,e,n);let s=new $t(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Ms=class n extends $t{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==et||this.dirty!=ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ze||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ze,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=et)}get domAtom(){return!1}isText(e){return this.node.text==e}},As=class extends wn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ol=class extends $t{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==et)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Mf(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=rr.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof rr)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Ng(n,e){return n.type.side-e.type.side}function Ig(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o!g.inline):l.slice();r(d,m,e.forChild(s,d),u),s=p}}function Rg(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function vg(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Rl(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function Hl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(vs(t)){for(c=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&k.isSelectable(f)&&i.parent&&!(f.isInline&&cg(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new k(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Tf(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ug(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,ie(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Ee&&Ft<=11&&(r.disabled=!0,r.disabled=!1)}function Df(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Yh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Yh(n)}function Yh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Jl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Gh(n){return n.editable&&!n.hasFocus()?!1:Of(n)}function Of(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Vg(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return yn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function vl(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Lt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Lt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=vl(n.state,e);return i&&i instanceof k?Lt(n,i):!1}else if(!(Pe&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?k.isSelectable(s)?Lt(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):si?Lt(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return Lt(n,new A(e>0?r.$to:r.$from));{let i=vl(n.state,e);return i?Lt(n,i):!1}}}function Ts(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Zr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Zn(n,e){return e<0?Bg(n):Pg(n)}function Bg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(Ke&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Zr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Nf(t))break;{let l=t.previousSibling;for(;l&&Zr(l,-1);)i=t.parentNode,s=ie(l),l=l.previousSibling;if(l)t=l,r=Ts(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?_l(n,t,r):i&&_l(n,i,s)}function Pg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Ts(t),s,o;for(;;)if(r{n.state==i&&bt(n)},50)}function Qh(n,e){let t=n.state.doc.resolve(e);if(!(ue||fg)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Zh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Pe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=vl(n.state,e);if(o&&o instanceof k)return Lt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ie?S.near(o,e):S.findFrom(o,e);return l?Lt(n,l):!1}return!1}function ef(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function tf(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Fg(n){if(!be||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;tf(n,r,"true"),setTimeout(()=>tf(n,r,"false"),20)}return!1}function $g(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qg(n,e){let t=e.keyCode,r=$g(e);if(t==8||Pe&&t==72&&r=="c")return ef(n,-1)||Zn(n,-1);if(t==46&&!e.shiftKey||Pe&&t==68&&r=="c")return ef(n,1)||Zn(n,1);if(t==13||t==27)return!0;if(t==37||Pe&&t==66&&r=="c"){let i=t==37?Qh(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xh(n,i,r)||Zn(n,i)}else if(t==39||Pe&&t==70&&r=="c"){let i=t==39?Qh(n,n.state.selection.from)=="ltr"?1:-1:1;return Xh(n,i,r)||Zn(n,i)}else{if(t==38||Pe&&t==80&&r=="c")return Zh(n,-1,r)||Zn(n,-1);if(t==40||Pe&&t==78&&r=="c")return Fg(n)||Zh(n,1,r)||Zn(n,1);if(r==(Pe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function If(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Ut.fromSchema(n.state.schema),l=Bf(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,f=0;for(;a&&a.nodeType==1&&(h=Vf[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),f++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var dp=Object.defineProperty;var fp=(n,e)=>{for(var t in e)dp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var wo=oe;function oa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=oa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function la(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Pi(r+1,o):Pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=aa(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ca(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function ca(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(ca(s.content,e-i-1,t-i-1)))}function aa(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=aa(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function up(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ha(n,e,t,0)}function ha(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&So(n,e,i+1),o=r.depth>i&&So(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(da(s,o),Gt(Xt(s,fa(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Fi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=So(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function pp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Xc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ua(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var Co=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ua(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ua(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Mo(e,t);if(r.next==null)return n.empty;let i=pa(r);r.next&&r.err("Unexpected trailing text");let s=Cp(kp(i));return Mp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` +`)}};en.empty=new en(!0);var Mo=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function pa(n){let e=[];do e.push(yp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function yp(n){let e=[];do e.push(wp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function wp(n){let e=Sp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=bp(n,e);else break;return e}function Qc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function bp(n,e){let t=Qc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Qc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function xp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Sp(n){if(n.eat("(")){let e=pa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=xp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function kp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ya(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Ap(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Ao=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Ap(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ba(e,i.attrs),this.excluded=null;let s=ga(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ya(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=wo.from(e.nodes),t.marks=wo.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?ea(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:ea(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Co(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ea(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ep(n){return n.tag!=null}function Tp(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ep(i))this.tags.push(i);else if(Tp(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=na(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=na(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},xa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Dp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Sa={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function ta(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!xa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ta(null,t.preserveWhitespace,0)|(r?Er:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;Sa.hasOwnProperty(i)&&this.parser.normalizeLists&&Op(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Dp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(xa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ra(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Op(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Sa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Np(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function na(n){let e={};for(let t in n)e[t]=n[t];return e}function ra(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(xo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ia(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ia(e.marks)}};function ia(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function xo(n){return n.document||window.document}var sa=new WeakMap;function Ip(n){let e=sa.get(n);return e===void 0&&sa.set(n,e=Rp(n)),e}function Rp(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ma=65535,Aa=Math.pow(2,16);function _p(n,e){return n+e*Aa}function ka(n){return n&Ma}function Up(n){return(n-(n&Ma))/Aa}var Ea=1,Ta=2,ji=4,Da=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Da)>0}get deletedBefore(){return(this.delInfo&(Ea|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=ka(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:_p(l/3,e-c),m=e==c?Ta:e==d?Ea:ji;return(t<0?e!=c:e!=d)&&(m|=Da),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=ka(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Io(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Oo(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Vp(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Bp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Tr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Ro(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Pp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function Hp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Na(n,o,l,s),Ro(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Oa(n,o,l,s),!1}})}function Oa(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Na(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` +`))}})}function Jp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function $p(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wp(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ia(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function jp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Ia(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Kp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Na(n,h.node(),h.before(),l)}o.inlineContent&&Ro(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Oa(n,h.node(),h.before(),n.steps.length)}return n}function Yp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Qi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ra(i,s,r)?new Ee(e,t,r):new No(i,s,r).fit()}function Ra(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var No=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=To(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=To(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=To(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(va(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Do(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function To(n,e){for(let t=0;t1&&(r=r.replaceChild(0,va(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Do(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Gp(t,s.content,o)?l:null}function Gp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Xp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function _a(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Zp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Yp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function em(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ua(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function Ua(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Qi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Qp(this,e,t,r),this}replaceRangeWith(e,t,r){return Zp(this,e,t,r),this}deleteRange(e,t){return em(this,e,t),this}lift(e,t){return Lp(this,e,t),this}join(e,t=1){return Kp(this,e,t),this}wrap(e,t){return qp(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return $p(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Wp(this,e,t,r),this}addMark(e,t,r){return Vp(this,e,t,r),this}removeMark(e,t,r){return Bp(this,e,t,r),this}clearIncompatible(e,t,r){return Ro(this,e,t,r),this}};var _o=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=_o[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in _o)throw new RangeError("Duplicate use of selection JSON ID "+e);return _o[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Va=!1;function Ba(n){!Va&&!n.parent.inlineContent&&(Va=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Ba(e),Ba(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new es(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Pa(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var La=1,Zi=2,za=4,Bo=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Zi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Zi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Zi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=za,this}get scrolledIntoView(){return(this.updated&za)>0}};function Fa(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=Fa(t.init,r),this.apply=Fa(t.apply,r)}},nm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=nm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Po=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function qa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=qa(i,e,{})),t[r]=i}return t}var L=class{constructor(e){this.spec=e,this.props={},e.props&&qa(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}},Uo=Object.create(null);function Ha(n){return n in Uo?n+"$"+ ++Uo[n]:(Uo[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ho=null,pt=function(n,e,t){let r=Ho||(Ho=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},rm=function(){Ho=null},fn=function(n,e,t,r){return t&&(Ja(n,e,t,r,-1)||Ja(n,e,t,r,1))},im=/^(img|br|input|textarea|hr)$/i;function Ja(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Jr(n)||im.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function sm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function om(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),hm=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!$a&&"webkitFontSmoothing"in $a.documentElement.style,dm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function fm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function um(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Wa(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=zr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?fm(s):um(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function pm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Ah(n.dom)}}function Ah(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function mm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Eh(t,r==0?0:r-e)}function Eh(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?ym(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Th(t,i)}function ym(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function cl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function wm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function xm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=xm(n,r,i,e))}l==null&&(l=bm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function ja(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Lo(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Lo(c.getBoundingClientRect(),!0)}return Lo(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Lo(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Nh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Cm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Nh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Oh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Mm=/[\u0590-\u08ac]/;function Am(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Mm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Nh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ka=null,Ya=null,Ga=!1;function Em(n,e,t){return Ka==e&&Ya==t?Ga:(Ka=e,Ya=t,Ga=t=="up"||t=="down"?Cm(n,e,t):Am(n,e,t))}var Ue=0,Xa=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof rs){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof ts&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:Xa,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:Ge}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Xa;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ue&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},jo=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ue){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Xo(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=It.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=vh(h,r,t),a?c=new Ko(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new ns(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Ue&&e.eq(this.node)&&is(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Go(this,o&&o.node,e);Nm(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Ih(this.contentDOM,this.children,e),Kn&&Im(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Rm(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new jo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Xo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ue}updateOuterDeco(e){if(is(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Rh(this.dom,this.nodeDOM,Yo(this.outerDeco,this.node,t),Yo(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Qa(n,e,t,r,i){vh(r,e,n);let s=new Pt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var ns=class n extends Pt{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Ge||this.dirty!=Ue&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ue||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Ue,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ge)}get domAtom(){return!1}isText(e){return this.node.text==e}},rs=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ue&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ko=class extends Pt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Ih(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Om(n,e){return n.type.side-e.type.side}function Nm(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Im(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Rm(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Xo(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function al(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(fs(t)){for(c=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&k.isSelectable(d)&&i.parent&&!(d.isInline&&lm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new k(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!_h(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function _m(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,te(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&ke&&Bt<=11&&(r.disabled=!0,r.disabled=!1)}function Uh(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(rh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else rh(n)}function rh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function hl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function ih(n){return n.editable&&!n.hasFocus()?!1:Vh(n)}function Vh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Um(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Qo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function sh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Qo(n.state,e);return i&&i instanceof k?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?k.isSelectable(s)?Ut(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return Ut(n,new A(e>0?r.$to:r.$from));{let i=Qo(n.state,e);return i?Ut(n,i):!1}}}function ss(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Lr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function $n(n,e){return e<0?Vm(n):Bm(n)}function Vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Bh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=ss(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Zo(n,t,r):i&&Zo(n,i,s)}function Bm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=ss(t),s,o;for(;;)if(r{n.state==i&&mt(n)},50)}function oh(n,e){let t=n.state.doc.resolve(e);if(!(ae||hm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function lh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ve&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Qo(n.state,e);if(o&&o instanceof k)return Ut(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Te?S.near(o,e):S.findFrom(o,e);return l?Ut(n,l):!1}return!1}function ch(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ah(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function zm(n){if(!me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ah(n,r,"true"),setTimeout(()=>ah(n,r,"false"),20)}return!1}function Fm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qm(n,e){let t=e.keyCode,r=Fm(e);if(t==8||ve&&t==72&&r=="c")return ch(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ch(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?oh(n,n.state.selection.from)=="ltr"?-1:1:-1;return sh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?oh(n,n.state.selection.from)=="ltr"?1:-1:1;return sh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return lh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return zm(n)||lh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ph(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Jh(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Hh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` -`);return{dom:c,text:d,slice:e}}function Rf(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",d=>{e=d(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:u}=n.state,p=Ut.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=Wg(t),si&&Kg(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Wn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Hg.test(d.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Yg(nf(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Jg(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let u=l.content.firstChild;f{l=f(l,n)}),l}var Hg=/^(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 Jg(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&_f(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Uf(o[o.length-1],s.length));let h=vf(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function vf(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function _f(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function nf(n,e,t){return et}).createHTML(n):n}function Wg(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Bf().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Vf[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=jg(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var xe={},Se={},Gg={touchstart:!0,touchmove:!0},Vl=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Xg(n){for(let e in xe){let t=xe[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Zg(n,r)&&!jl(n,r)&&(n.editable||!(r.type in Se))&&t(n,r)},Gg[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Bl(n)}function zt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Qg(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Bl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>jl(n,r))})}function jl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Zg(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ey(n,e){!jl(n,e)&&xe[e.type]&&(n.editable||!(e.type in Se))&&xe[e.type](n,e)}Se.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Lf(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(We&&ue&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),nr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,fn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||qg(n,t)?t.preventDefault():zt(n,"key")};Se.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Se.keypress=(n,e)=>{let t=e;if(Lf(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Pe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function _s(n){return{left:n.clientX,top:n.clientY}}function ty(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Wl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function tr(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function ny(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(tr(n,new k(t),"pointer"),!0):!1}function ry(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof k&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(k.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(tr(n,k.create(n.state.doc,i),"pointer"),!0):!1}function iy(n,e,t,r,i){return Wl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?ry(n,t):ny(n,t))}function sy(n,e,t,r){return Wl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function oy(n,e,t,r){return Wl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||ly(n,t,r)}function ly(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(tr(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)tr(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(k.isSelectable(o))tr(n,k.create(r,l),"pointer");else continue;return!0}}function Kl(n){return Ds(n)}var Pf=Pe?"metaKey":"ctrlKey";xe.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Kl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&ty(t,n.input.lastClick)&&!t[Pf]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(_s(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Pl(n,o,t,!!r)):(s=="doubleClick"?sy:oy)(n,o.pos,o.inside,t)?t.preventDefault():zt(n,"pointer"))};var Pl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Pf],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof k&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ke&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),zt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>bt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(_s(e))),this.updateAllowDefault(e),this.allowDefault||!t?zt(this.view,"pointer"):iy(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!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)?(tr(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):zt(this.view,"pointer")}move(e){this.updateAllowDefault(e),zt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};xe.touchstart=n=>{n.input.lastTouch=Date.now(),Kl(n),zt(n,"pointer")};xe.touchmove=n=>{n.input.lastTouch=Date.now(),zt(n,"pointer")};xe.contextmenu=n=>Kl(n);function Lf(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var cy=We?5e3:-1;Se.compositionstart=Se.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),Ds(n,!0),n.markCursor=null;else if(Ds(n,!e.selection.empty),Ke&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}zf(n,cy)};Se.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,zf(n,20))};function zf(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ds(n),e))}function Ff(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=hy());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function ay(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=og(e.focusNode,e.focusOffset),r=lg(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function hy(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Ds(n,e=!1){if(!(We&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ff(n),e||n.docView&&n.docView.dirty){let t=Hl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function fy(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var ti=Ee&&Ft<15||nr&&dg<604;xe.copy=Se.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=ti?null:t.clipboardData,o=r.content(),{dom:l,text:c}=If(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):fy(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dy(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function uy(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?ni(n,r.value,null,i,e):ni(n,r.textContent,r.innerHTML,i,e)},50)}function ni(n,e,t,r,i){let s=Rf(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=dy(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function $f(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Se.paste=(n,e)=>{let t=e;if(n.composing&&!We)return;let r=ti?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&ni(n,$f(r),r.getData("text/html"),i,t)?t.preventDefault():uy(n,t)};var Os=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},qf=Pe?"altKey":"ctrlKey";xe.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(_s(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=k.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=If(n,l);(!t.dataTransfer.files.length||!ue||yf>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ti?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",ti||t.dataTransfer.setData("text/plain",a),n.dragging=new Os(h,!t[qf],o)};xe.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Se.dragover=Se.dragenter=(n,e)=>e.preventDefault();Se.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(_s(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Rf(n,$f(t.dataTransfer),ti?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[qf]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Ch(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,d=a.doc;if(f?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(d))return;let u=a.doc.resolve(h);if(f&&k.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new k(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(Jl(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};xe.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&bt(n)},20))};xe.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};xe.beforeinput=(n,e)=>{if(ue&&We&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,fn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Se)xe[n]=Se[n];function ri(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var Ns=class n{constructor(e,t){this.toDOM=e,this.spec=t||mn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new se(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ri(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pn=class n{constructor(e,t){this.attrs=e,this.spec=t||mn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new se(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==de||e.maps.length==0?this:this.mapInner(e,t,0,0,r||mn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Jf(t,l,a)){for(i||(i=this.children.slice());sl&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof pn){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,mn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-d);for(let y=0;yE+h-f)continue;let N=l[y]+h-f;u>=N?l[y+1]=d<=N?-2:-1:d>=h&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let d=t.map(n[a+1]+s,-1),u=d-i,{index:p,offset:m}=r.content.findIndex(f),g=r.maybeChild(p);if(g&&m==f&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=de?(l[a]=f,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=my(l,n,e,t,i,s,o),h=Rs(a,r,0,o);e=h.local;for(let f=0;ft&&o.to{let a=Jf(n,l,c+t);if(a){s=!0;let h=Rs(a,l,t+c+1,r);h!=de&&i.push(c,c+l.nodeSize,h)}});let o=Hf(s?jf(n):n,-t).sort(gn);for(let l=0;l0;)e++;n.splice(e,0,t)}function kl(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=de&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),Is.from(e)}var gy={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yy=Ee&&Ft<=11,zl=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}},Fl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new zl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),yy&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,gy)),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(Gh(this.view)){if(this.suppressingSelectionUpdates)return bt(this.view);if(Ee&&Ft<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&yn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=ei(s))t.add(s);for(let s=e.anchorNode;s;s=ei(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&Gh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hf.nodeName=="BR");if(h.length==2){let[f,d]=h;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of h){let u=d.parentNode;u&&u.nodeName=="LI"&&(!f||xy(e,f)!=u)&&d.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),wy(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||bt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let f=n.state.doc,d=n.someProp("domParser")||Wn.fromSchema(n.state.schema),u=f.resolve(o),p=null,m=d.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:ky,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function ky(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||be&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var Cy=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function My(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,_t=Hl(n,T);if(_t&&!n.state.selection.eq(_t)){if(ue&&We&&n.input.lastKeyCode===13&&Date.now()-100fm(n,fn(13,"Enter"))))return;let ss=n.state.tr.setSelection(_t);T=="pointer"?ss.setMeta("pointer",!0):T=="key"&&ss.scrollIntoView(),s&&ss.setMeta("composition",s),n.dispatch(ss)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Sy(n,e,t),h=n.state.doc,f=h.slice(a.from,a.to),d,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||We)&&i.some(T=>T.nodeType==1&&!Cy.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=af(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let _t=n.state.tr.setSelection(T);s&&_t.setMeta("composition",s),n.dispatch(_t)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Ee&&Ft<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((nr&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ey(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,fn(8,"Backspace")))){We&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&We&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),We&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,fn(13,"Enter"))})},20));let Ae=p.start,we=p.endA,Q,mt,vt;if(E){if(m.pos==g.pos)Ee&&Ft<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>bt(n),20)),Q=n.state.tr.delete(Ae,we),mt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(vt=Ay(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Q=n.state.tr,vt.type=="add"?Q.addMark(Ae,we,vt.mark):Q.removeMark(Ae,we,vt.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",_t=>_t(n,Ae,we,T)))return;Q=n.state.tr.insertText(T,Ae,we)}}if(Q||(Q=n.state.tr.replace(Ae,we,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=af(n,Q.doc,a.sel);T&&!(ue&&We&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:Jl(n,e.resolve(t.anchor),e.resolve(t.head))}function Ay(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Cl(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ty(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var $l=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 Vl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(mf),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=uf(this),df(this),this.nodeViews=pf(this),this.docView=Hh(this.state.doc,ff(this),kl(this),this.dom,this),this.domObserver=new Fl(this,(r,i,s,o)=>My(this,r,i,s,o)),this.domObserver.start(),Xg(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&&Bl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(mf),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Ff(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=pf(this);Oy(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Bl(this),this.editable=uf(this),df(this);let c=kl(this),a=ff(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,a,c);(f||!e.selection.eq(i.selection))&&(o=!0);let d=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&mg(this);if(o){this.domObserver.stop();let u=f&&(Ee||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Dy(i.selection,e.selection);if(f){let p=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=ay(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Hh(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Vg(this))?bt(this,u):(Df(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():d&&gg(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ph(this,t.getBoundingClientRect(),e)}else Ph(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new Os(e.slice,e.move,i<0?void 0:k.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return kg(this,e)}coordsAtPos(e,t=1){return kf(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Tg(this,t||this.state,e)}pasteHTML(e,t){return ni(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ni(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Qg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],kl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ig())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ey(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?be&&this.root.nodeType===11&&ag(this.dom.ownerDocument)==this.dom&&by(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function ff(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[se.node(0,n.state.doc.content.size,e)]}function df(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function uf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Dy(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function pf(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Oy(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function mf(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Ny=["p",0],Iy=["blockquote",0],Ry=["hr"],vy=["pre",["code",0]],_y=["br"],Uy={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Ny}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Iy}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ry}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return vy}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return _y}}},Vy=["em",0],By=["strong",0],Py=["code",0],Ly={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Vy}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return By}},code:{parseDOM:[{tag:"code"}],toDOM(){return Py}}},zy=new qr({nodes:Uy,marks:Ly});var Kf=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Fy(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var $y=(n,e,t)=>{let r=Fy(n,t);if(!r)return!1;let i=Yf(r);if(!i){let o=r.blockRange(),l=o&&cn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Qf(n,i,e,-1))return!0;if(r.parent.content.size==0&&(ir(s,"end")||k.isSelectable(s)))for(let o=r.depth;;o--){let l=xs(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function ir(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var qy=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Yf(r)}let o=s&&s.nodeBefore;return!o||!k.isSelectable(o)?!1:(e&&e(n.tr.setSelection(k.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Yf(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Hy(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Hy(n,t);if(!r)return!1;let i=Gf(r);if(!i)return!1;let s=i.nodeAfter;if(Qf(n,i,e,1))return!0;if(r.parent.content.size==0&&(ir(s,"start")||k.isSelectable(s))){let o=xs(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof k,i;if(r){if(t.node.isTextblock||!an(n.doc,t.from))return!1;i=t.from}else if(i=pl(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(k.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Xf=(n,e)=>{let t=n.selection,r;if(t instanceof k){if(t.node.isTextblock||!an(n.doc,t.to))return!1;r=t.to}else if(r=pl(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},li=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&cn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Wy=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function Xl(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Xl(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Ky=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ie||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Xl(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Vt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&cn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Gy(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof k&&e.selection.node.isBlock)return!r.parentOffset||!Vt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Ie)&&o.deleteSelection();let l=r.depth==0?null:Xl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Vt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Vt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let f=o.mapping.map(r.before()),d=o.doc.resolve(f);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Xy=Gy();var ci=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(k.create(n.doc,i))),!0)},Qy=(n,e)=>(e&&e(n.tr.setSelection(new Ie(n.doc))),!0);function Zy(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||an(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Qf(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Zy(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new ee(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&an(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),d=f&&cn(f);if(d!=null&&d>=e.depth)return t&&t(n.tr.lift(f,d).scrollIntoView()),!0;if(a&&ir(s,"start",!0)&&ir(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new ee(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function Zf(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var e0=Zf(-1),t0=Zf(1);function sr(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&bs(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function bn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),f=h.index();i=h.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function r0(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new Bt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):h=!a.every(d=>{let u=!1;return f.doc.nodesBetween(d.$from.pos,d.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,d.$from.pos-m),Math.min(p.nodeSize,d.$to.pos-m))))}),!u});for(let d=0;d=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new sn(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new ee(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)f=w.from(i.node(y).copy(f));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Vt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function tc(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?u0(e,t,n,s):p0(e,t,s):!0:!1}}function u0(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let f=s.pos,d=f+o.nodeSize;return r.step(new ee(f-(l?1:0),d+(c?1:0),f+1,d-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function nc(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),f=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),d=s.start,u=s.end;t(e.tr.step(new ee(d-(a?3:1),u,d,u,f,1,!0)).scrollIntoView())}return!0}}var St={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:"'"},Bs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},m0=typeof navigator<"u"&&/Mac/.test(navigator.platform),g0=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(j=0;j<10;j++)St[48+j]=St[96+j]=String(j);var j;for(j=1;j<=24;j++)St[j+111]="F"+j;var j;for(j=65;j<=90;j++)St[j]=String.fromCharCode(j+32),Bs[j]=String.fromCharCode(j);var j;for(Vs in St)Bs.hasOwnProperty(Vs)||(Bs[Vs]=St[Vs]);var Vs;function nd(n){var e=m0&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||g0&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Bs:St)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var y0=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function w0(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=St[r.keyCode])&&s!=i){let l=e[rc(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var Ps=200,oe=function(){};oe.prototype.append=function(e){return e.length?(e=oe.from(e),!this.length&&e||e.length=t?oe.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};oe.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};oe.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};oe.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};oe.from=function(e){return e instanceof oe?e:e&&e.length?new rd(e):oe.empty};var rd=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Ps)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Ps)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(oe);oe.empty=new rd([]);var S0=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(oe),ic=oe;var k0=500,Ls=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),s=i.maps.length),s--,h.push(f);return}if(i){h.push(new tt(f.map));let u=f.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new tt(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(s)):f.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hM0&&(l=C0(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Wr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new tt(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let c=t;this.items.forEach(d=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(d.step){let m=e.steps[u].invert(e.docs[u]),g=d.selection&&d.selection.map(s.slice(c+1,u));g&&l++,r.push(new tt(p,m,g))}else r.push(new tt(p))},i);let a=[];for(let d=t;dk0&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let f=new tt(a.invert(),c,h),d,u=i.length-1;(d=i.length&&i[u].merge(f))?i[u]=d:i.push(f)}}else o.map&&r--},this.items.length,0),new n(ic.from(i.reverse()),s)}};Ls.empty=new Ls(ic.empty,0);function C0(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var tt=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},oc=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},M0=20;function A0(n,e,t){let r=E0(e),i=lc.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new oc(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(lc,{redo:t,historyState:c})}var sc=!1,id=null;function E0(n){let e=n.plugins;if(id!=e){sc=!1,id=e;for(let t=0;t{let i=lc.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=A0(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var fi=zs(!1,!0),or=zs(!0,!0),WS=zs(!1,!1),KS=zs(!0,!1);var pe=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new cc(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!T0(e)||!D0(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!k.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};pe.prototype.visible=!1;pe.findFrom=pe.findGapCursorFrom;S.jsonID("gapcursor",pe);var cc=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return pe.valid(t)?new pe(t):S.near(t)}};function T0(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function D0(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function O0(){return new J({props:{decorations:v0,createSelectionBetween(n,e,t){return e.pos==t.pos&&pe.valid(t)?new pe(t):null},handleClick:I0,handleKeyDown:N0,handleDOMEvents:{beforeinput:R0}}})}var N0=hi({ArrowLeft:Fs("horiz",-1),ArrowRight:Fs("horiz",1),ArrowUp:Fs("vert",-1),ArrowDown:Fs("vert",1)});function Fs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=pe.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new pe(a))),!0):!1}}function I0(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!pe.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&k.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new pe(r))),!0)}function R0(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof pe))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function v0(n){if(!(n.selection instanceof pe))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(n.doc,[se.widget(n.selection.head,e,{key:"gapcursor"})])}function kt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var U0=500;function ld({rules:n}){let e=new J({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return od(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&od(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function od(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-U0),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},V0=new Ct(/--$/,"\u2014"),B0=new Ct(/\.\.\.$/,"\u2026"),rk=new Ct(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),ik=new Ct(/"$/,"\u201D"),sk=new Ct(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),ok=new Ct(/'$/,"\u2019");var ad=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function P0(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",fi),i("Shift-Mod-z",or),i("Backspace",cd),ad||i("Mod-y",or),i("Alt-ArrowUp",oi),i("Alt-ArrowDown",Xf),i("Mod-BracketLeft",li),i("Escape",ci),(r=n.marks.strong)&&(i("Mod-b",xn(r)),i("Mod-B",xn(r))),(r=n.marks.em)&&(i("Mod-i",xn(r)),i("Mod-I",xn(r))),(r=n.marks.code)&&i("Mod-`",xn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",Us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",Us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",sr(r)),r=n.nodes.hard_break){let s=r,o=ai(Ql,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),ad&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",ec(r)),i("Mod-[",tc(r)),i("Mod-]",nc(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",bn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",bn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,bn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var hc,fc;if(typeof WeakMap<"u"){let n=new WeakMap;hc=e=>n.get(e),fc=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;hc=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Ae=i+N*e;for(let we=0;wer&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function F0(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function fd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function q0(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>hd(r,e)}],toDOM(r){return["td",fd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>hd(r,e)}],toDOM(r){return["th",fd(r,e),0]}}}}function me(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Ht=new fe("selectingCells");function lr(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function H0(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Ye(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function mc(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=lr(e.$head)||J0(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function J0(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function dc(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function j0(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function gc(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function xd(n,e,t){let r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function Sn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Sd(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let f=r.nodeAt(h);if(!f)throw RangeError(`No cell with offset ${h} found`);let d=s+h+1;return new Bt(l.resolve(d),l.resolve(d+f.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(dc(r)&&dc(i)&&gc(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Mt.rowSelection(r,i):s&&this.isColSelection()?Mt.colSelection(r,i):new Mt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=Sn(y,0,m)),g>0&&(y=Sn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof Mt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(se.node(r,r+t.nodeSize,{class:"selectedCell"}))}),L.create(n.doc,e)}function G0({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function X0({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Q0(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=z.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&G0(r)?s=A.create(i,r.from):r instanceof A&&X0(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Z0=new fe("fix-tables");function Cd(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=ew(n,i,s,t))};return e?e.doc!=n.doc&&Cd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function ew(n,e,t,r){let i=z.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;W0(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;sw(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&f==e.map[h-e.width]){let d=t.nodeAt(f).attrs;n.setNodeMarkup(n.mapping.slice(l).map(f+r),null,{...d,rowspan:d.rowspan-1}),a+=d.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function uw(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=H0(i.$from),!s)return!1;o=(r=lr(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Ge(e),f=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,d,m.attrs)}),r(o)}return!0}}var Dk=yc("row",{useDeprecatedLogic:!0}),Ok=yc("column",{useDeprecatedLogic:!0}),Nk=yc("cell",{useDeprecatedLogic:!0});function mw(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function $s(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=me(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function ww(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(d=d.type.createChecked(Sn(d.attrs,d.attrs.colspan,h+d.attrs.colspan-r),d.content)),a.push(d),h+=d.attrs.colspan;for(let u=1;ui&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),c.push(f)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function Sw(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=me(l),a,h;if(i>e.width)for(let f=0,d=0;fe.height){let f=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;f.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let d=c.row.create(null,w.from(f)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Js(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Td(i,n,e);if(o==null)return!1;if(n=="horiz")return Js(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=xd(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Js(t,r,a)}}}function Hs(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=Td(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=xd(o.$headCell,n,e);return l?Js(t,r,new V(o.$anchorCell,l)):!1}}function Cw(n,e){let t=n.state.doc,r=lr(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function Mw(n,e,t){if(!Ye(n.state))return!1;let r=ww(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(uc(me(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=xw(r,l.right-l.left,l.bottom-l.top),gd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=mc(n.state),o=s.start(-1);return gd(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function Aw(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=yd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=lr(n.state.selection.$anchor))!=null&&((t=ac(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=ac(n,a),f=Ht.getState(n.state)==null;if(!h||!gc(c,h))if(f)h=c;else return;let d=new V(c,h);if(f||!n.state.selection.eq(d)){let u=n.state.tr.setSelection(d);f&&u.setMeta(Ht,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ht.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ht,-1))}function l(c){let a=c,h=Ht.getState(n.state),f;if(h!=null)f=n.state.doc.resolve(h);else if(yd(n,a.target)!=r&&(f=ac(n,e),!f))return o();f&&s(f,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function Td(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function yd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function ac(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?lr(n.state.doc.resolve(t.pos)):null}var Ew=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),pc(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,pc(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function pc(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let f=0,d=0;fnew t(f,e,d)),new Dw(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Fe.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{Ow(s,o,n,e,r)},mouseleave:s=>{Nw(s)},mousedown:(s,o)=>{Iw(s,o,e)}},decorations:s=>{let o=Fe.getState(s);if(o&&o.activeHandle>-1)return Bw(s,o.activeHandle)},nodeViews:{}}});return i}var Dw=class js{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Fe);if(r&&r.setHandle!=null)return new js(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new js(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return dc(e.doc.resolve(i))||(i=-1),new js(i,t.dragging)}return t}};function Ow(n,e,t,r,i){let s=Fe.getState(n.state);if(s&&!s.dragging){let o=vw(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=wd(n,e,"left",t):a-e.clientX<=t&&(l=wd(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=z.get(a),f=c.start(-1);if(h.colCount(c.pos-f)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Dd(n,l)}}}function Nw(n){let e=Fe.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Dd(n,-1)}function Iw(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Fe.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=Rw(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Fe,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let f=Fe.getState(n.state);f?.dragging&&(_w(n,f.activeHandle,bd(f.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Fe,{setDragging:null})))}function a(h){if(!h.which)return c(h);let f=Fe.getState(n.state);if(f&&f.dragging){let d=bd(f.dragging,h,t);Uw(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function Rw(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;aNo,AbstractConnector:()=>ea,AbstractStruct:()=>Rr,AbstractType:()=>H,Array:()=>Vn,ContentAny:()=>Zt,ContentBinary:()=>Pn,ContentDeleted:()=>vr,ContentDoc:()=>Ln,ContentEmbed:()=>Nt,ContentFormat:()=>P,ContentJSON:()=>Hi,ContentString:()=>Ve,ContentType:()=>Oe,Doc:()=>Je,GC:()=>ye,ID:()=>Dt,Item:()=>O,Map:()=>Bn,PermanentUserData:()=>na,RelativePosition:()=>ht,Skip:()=>ce,Snapshot:()=>Qt,Text:()=>dt,Transaction:()=>Ro,UndoManager:()=>_n,UpdateDecoderV1:()=>De,UpdateDecoderV2:()=>Ce,UpdateEncoderV1:()=>at,UpdateEncoderV2:()=>Ue,XmlElement:()=>ne,XmlFragment:()=>ut,XmlHook:()=>qi,XmlText:()=>Me,YArrayEvent:()=>Uo,YEvent:()=>Un,YMapEvent:()=>Vo,YTextEvent:()=>Bo,YXmlEvent:()=>Po,applyUpdate:()=>pa,applyUpdateV2:()=>zn,cleanupYTextFormatting:()=>Ip,compareIDs:()=>On,compareRelativePositions:()=>zo,convertUpdateFormatV1ToV2:()=>zb,convertUpdateFormatV2ToV1:()=>pp,createAbsolutePositionFromRelativePosition:()=>ba,createDeleteSet:()=>_r,createDeleteSetFromStructStore:()=>fa,createDocFromSnapshot:()=>Ab,createID:()=>M,createRelativePositionFromJSON:()=>$n,createRelativePositionFromTypeIndex:()=>Ji,createSnapshot:()=>ji,decodeRelativePosition:()=>bb,decodeSnapshot:()=>Cb,decodeSnapshotV2:()=>tp,decodeStateVector:()=>ga,decodeUpdate:()=>vb,decodeUpdateV2:()=>cp,diffUpdate:()=>Bb,diffUpdateV2:()=>xa,emptySnapshot:()=>Mb,encodeRelativePosition:()=>yb,encodeSnapshot:()=>kb,encodeSnapshotV2:()=>ep,encodeStateAsUpdate:()=>ma,encodeStateAsUpdateV2:()=>Xu,encodeStateVector:()=>wa,encodeStateVectorFromUpdate:()=>_b,encodeStateVectorFromUpdateV2:()=>hp,equalDeleteSets:()=>Yu,equalSnapshots:()=>Sb,findIndexSS:()=>je,findRootTypeKey:()=>Fn,getItem:()=>Nn,getItemCleanEnd:()=>sa,getItemCleanStart:()=>ge,getState:()=>B,getTypeChildren:()=>Hb,isDeleted:()=>It,isParentOf:()=>vn,iterateDeletedStructs:()=>lt,logType:()=>ub,logUpdate:()=>Rb,logUpdateV2:()=>lp,mergeDeleteSets:()=>In,mergeUpdates:()=>ap,mergeUpdatesV2:()=>Li,obfuscateUpdate:()=>Pb,obfuscateUpdateV2:()=>Lb,parseUpdateMeta:()=>Ub,parseUpdateMetaV2:()=>fp,readUpdate:()=>ab,readUpdateV2:()=>ua,relativePositionToJSON:()=>pb,snapshot:()=>Wi,snapshotContainsUpdate:()=>Tb,transact:()=>R,tryGc:()=>Nb,typeListToArraySnapshot:()=>Ho,typeMapGetAllSnapshot:()=>Ep,typeMapGetSnapshot:()=>Wb});var _=()=>new Map,Ws=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},W=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Od=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Nd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Te=()=>new Set;var Ks=n=>n[n.length-1];var Id=(n,e)=>{for(let t=0;t{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return Xe((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},ar=class{constructor(){this._observers=_()}on(e,t){W(this._observers,e,Te).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return Xe((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var Y=Math.floor;var Cn=Math.abs;var Re=(n,e)=>nn>e?n:e,Lk=Number.isNaN,vd=Math.pow;var Gs=n=>n!==0?n<0:1/n<0;var hr=Number.MAX_SAFE_INTEGER,wc=Number.MIN_SAFE_INTEGER,zk=1<<31;var _d=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&Y(n)===n),Fk=Number.isNaN,$k=Number.parseInt;var mi=String.fromCharCode,Lw=String.fromCodePoint,qk=mi(65535),zw=n=>n.toLowerCase(),Fw=/^\s*/g,$w=n=>n.replace(Fw,""),qw=/([A-Z])/g,xc=(n,e)=>$w(n.replace(qw,t=>`${e}${zw(t)}`));var Hw=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;idr.encode(n),Ud=dr?Jw:Hw;var fr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});fr&&fr.decode(new Uint8Array).length===1&&(fr=null);var Xs=(n,e)=>Rd(e,()=>n).join("");var Mn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},$=()=>new Mn;var Zs=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Zs(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var yr=te;var x=(n,e)=>{for(;e>127;)te(n,128|127&e),e=Y(e/128);te(n,127&e)},yi=(n,e)=>{let t=Gs(e);for(t&&(e=-e),te(n,(e>63?128:0)|(t?64:0)|63&e),e=Y(e/64);e>0;)te(n,(e>127?128:0)|127&e),e=Y(e/128)},Sc=new Uint8Array(3e4),Ww=Sc.length/3,Kw=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iwr(n,I(e)),wr=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=Re(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array($e(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),wr(n,e)},kc=(n,e)=>{jw(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Gw=(n,e)=>kc(n,4).setFloat32(0,e,!1),Xw=(n,e)=>kc(n,8).setFloat64(0,e,!1),Qw=(n,e)=>kc(n,8).setBigInt64(0,e,!1);var Bd=new DataView(new ArrayBuffer(4)),Zw=n=>(Bd.setFloat32(0,n),Bd.getFloat32(0)===n),mr=(n,e)=>{switch(typeof e){case"string":te(n,119),rt(n,e);break;case"number":_d(e)&&Cn(e)<=2147483647?(te(n,125),yi(n,e)):Zw(e)?(te(n,124),Gw(n,e)):(te(n,123),Xw(n,e));break;case"bigint":te(n,122),Qw(n,e);break;case"object":if(e===null)te(n,126);else if(At(e)){te(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var Pd=n=>{n.count>0&&(yi(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},An=class{constructor(){this.encoder=new Mn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Pd(this),this.count=1,this.s=e)}toUint8Array(){return Pd(this),I(this.encoder)}};var Ld=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);yi(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},gr=class{constructor(){this.encoder=new Mn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Ld(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ld(this),I(this.encoder)}},Qs=class{constructor(){this.sarr=[],this.s="",this.lensE=new An}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 Mn;return this.sarr.push(this.s),this.s="",rt(e,this.sarr.join("")),wr(e,this.lensE.toUint8Array()),I(e)}};var ve=n=>new Error(n),ke=()=>{throw ve("Method unimplemented")},F=()=>{throw ve("Unexpected case")};var Fd=ve("Unexpected end of array"),$d=ve("Integer out of Range"),br=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new br(n),Cc=n=>n.pos!==n.arr.length;var e1=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},G=n=>e1(n,C(n));var En=n=>n.arr[n.pos++];var C=n=>{let e=0,t=1,r=n.arr.length;for(;n.poshr)throw $d}throw Fd},xi=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.poshr)throw $d}throw Fd};var t1=n=>{let e=C(n);if(e===0)return"";{let t=String.fromCodePoint(En(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(En(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},n1=n=>fr.decode(G(n)),He=fr?n1:t1;var Mc=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},r1=n=>Mc(n,4).getFloat32(0,!1),i1=n=>Mc(n,8).getFloat64(0,!1),s1=n=>Mc(n,8).getBigInt64(0,!1);var o1=[n=>{},n=>null,xi,r1,i1,s1,n=>!1,n=>!0,He,n=>{let e=C(n),t={};for(let r=0;r{let e=C(n),t=[];for(let r=0;ro1[127-En(n)](n),bi=class extends br{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Cc(this)?this.count=C(this)+1:this.count=-1),this.count--,this.s}};var Tn=class extends br{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=xi(this);let e=Gs(this.s);this.count=1,e&&(this.s=-this.s,this.count=C(this)+2)}return this.count--,this.s}};var Sr=class extends br{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=xi(this),t=e&1;this.diff=Y(e/2),this.count=1,t&&(this.count=C(this)+2)}return this.s+=this.diff,this.count--,this.s}},to=class{constructor(e){this.decoder=new Tn(e),this.str=He(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var jk=crypto.subtle,qd=crypto.getRandomValues.bind(crypto);var l1=Math.random,Ac=()=>qd(new Uint32Array(1))[0];var Hd=n=>n[Y(l1()*n.length)],c1="10000000-1000-4000-8000"+-1e11,Jd=()=>c1.replace(/[018]/g,n=>(n^Ac()&15>>n/4).toString(16));var _e=Date.now;var Ec=n=>new Promise(n);var Yk=Promise.all.bind(Promise);var Tc=n=>n===void 0?null:n;var Dc=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Wd=new Dc,Oc=!0;try{typeof localStorage<"u"&&localStorage&&(Wd=localStorage,Oc=!1)}catch{}var ro=Wd,Kd=n=>Oc||addEventListener("storage",n),Yd=n=>Oc||removeEventListener("storage",n);var Dn=Symbol("Equality"),io=(n,e)=>n===e||!!n?.[Dn]?.(e)||!1;var Xd=n=>typeof n=="object",Qd=Object.assign,Ic=Object.keys;var Zd=(n,e)=>{for(let t in n)e(n[t],t)},eu=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t};var ki=n=>Ic(n).length;var tu=n=>{for(let e in n)return!1;return!0},kr=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Ci=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Rc=(n,e)=>n===e||ki(n)===ki(e)&&kr(n,(t,r)=>(t!==void 0||Ci(e,r))&&io(e[r],t)),f1=Object.freeze,vc=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&vc(n[e])}return f1(n)};var Ai=(n,e,t=0)=>{try{for(;tn;var jt=(n,e)=>{if(n===e)return!0;if(n==null||e==null||n.constructor!==e.constructor&&(n.constructor||Object)!==(e.constructor||Object))return!1;if(n[Dn]!=null)return n[Dn](e);switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var Et=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Cr=typeof window<"u"&&typeof document<"u"&&!Et,Gk=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,it,d1=[],u1=()=>{if(it===void 0)if(Et){it=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");it.set(`--${xc(e,"-")}`,t),it.set(`-${xc(e,"-")}`,t)}})):it=_();return it},Uc=n=>u1().has(n);var Ei=n=>Et?Tc(process.env[n.toUpperCase().replaceAll("-","_")]):Tc(ro.getItem(n));var ru=n=>Uc("--"+n)||Ei(n)!==null,iu=ru("production"),p1=Et&&nu(process.env.FORCE_COLOR,["true","1","2"]),su=p1||!Uc("--no-colors")&&!ru("no-color")&&(!Et||process.stdout.isTTY)&&(!Et||Uc("--color")||Ei("COLORTERM")!==null||(Ei("TERM")||"").includes("color"));var ou=n=>new Uint8Array(n),m1=(n,e,t)=>new Uint8Array(n,e,t),lu=n=>new Uint8Array(n),g1=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),w1=n=>{let e=atob(n),t=ou(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return m1(e.buffer,e.byteOffset,e.byteLength)},cu=Cr?g1:y1,au=Cr?w1:b1;var hu=n=>{let e=ou(n.byteLength);return e.set(n),e};var Vc=class{constructor(e,t){this.left=e,this.right=t}},st=(n,e)=>new Vc(n,e);var Bc=n=>n.next()>=.5,oo=(n,e,t)=>Y(n.next()*(t+1-e)+e);var Pc=(n,e,t)=>Y(n.next()*(t+1-e)+e);var Lc=(n,e,t)=>Pc(n,e,t);var S1=n=>mi(Lc(n,97,122)),du=(n,e=0,t=20)=>{let r=Lc(n,e,t),i="";for(let s=0;se[Lc(n,0,e.length-1)];var C1=Symbol("0schema"),zc=class{constructor(){this._rerrs=[]}extend(e,t,r,i=null){this._rerrs.push({path:e,expected:t,has:r,message:i})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let r=this._rerrs[t];e.push(Xs(" ",(this._rerrs.length-t)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(` -`)}},Fc=(n,e)=>n===e?!0:n==null||e==null||n.constructor!==e.constructor?!1:n[Dn]?io(n,e):At(n)?Ys(n,t=>ui(e,r=>Fc(t,r))):Xd(n)?kr(n,(t,r)=>Fc(t,e[r])):!1,le=class{static _dilutes=!1;extends(e){let[t,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,t]=[t,r]),Fc(t,r)}equals(e){return this.constructor===e.constructor&&jt(this.shape,e.shape)}[C1](){return!0}[Dn](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){ke()}get nullable(){return Or(this,xo)}get optional(){return new co(this)}cast(e){return uu(e,this),e}expect(e){return uu(e,this),e}},Ti=class extends le{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let r=e?.constructor===this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},K=(n,e=null)=>new Ti(n,e),Qk=K(Ti),Di=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=this.shape(e);return!r&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),r}},X=n=>new Di(n),Zk=K(Di),Tr=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=this.shape.some(i=>i===e);return!r&&t?.extend(null,this.shape.join(" | "),e.toString()),r}},wo=(...n)=>new Tr(n),pu=K(Tr),M1=RegExp.escape||(n=>n.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),mu=n=>{if(Dr.check(n))return[M1(n)];if(pu.check(n))return n.shape.map(e=>e+"");if(xu.check(n))return["[+-]?\\d+.?\\d*"];if(Su.check(n))return[".*"];if(go.check(n))return n.shape.map(mu).flat(1);F()},$c=class extends le{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(mu).map(t=>`(${t.join("|")})`).join("")+"$")}check(e,t){let r=this._r.exec(e)!=null;return!r&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),r}};var eC=K($c),A1=Symbol("optional"),co=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=e===void 0||this.shape.check(e);return!r&&t?.extend(null,"undefined (optional)","()"),r}get[A1](){return!0}},E1=K(co),ao=class extends le{check(e,t){return t?.extend(null,"never",typeof e),!1}},tC=new ao,nC=K(ao),ho=class n extends le{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new n(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,"object","null"),!1):kr(this.shape,(r,i)=>{let s=this._isPartial&&!Ci(e,i)||r.check(e[i],t);return!s&&t?.extend(i.toString(),r.toString(),typeof e[i],"Object property does not match"),s})}},T1=n=>new ho(n),D1=K(ho),O1=X(n=>n!=null&&(n.constructor===Object||n.constructor==null)),fo=class extends le{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&kr(e,(r,i)=>{let s=this.shape.keys.check(i,t);return!s&&t?.extend(i+"","Record",typeof e,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(r,t)})}},gu=(n,e)=>new fo(n,e),N1=K(fo),uo=class extends le{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&kr(this.shape,(r,i)=>{let s=r.check(e[i],t);return!s&&t?.extend(i.toString(),"Tuple",typeof r),s})}},I1=(...n)=>new uo(n),rC=K(uo),po=class extends le{constructor(e){super(),this.shape=e.length===1?e[0]:new Oi(e)}check(e,t){let r=At(e)&&Ys(e,i=>this.shape.check(i));return!r&&t?.extend(null,"Array",""),r}},yu=(...n)=>new po(n),R1=K(po),v1=X(n=>At(n)),mo=class extends le{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name),r}},_1=(n,e=null)=>new mo(n,e),iC=K(mo),U1=_1(le),qc=class extends le{constructor(e){super(),this.len=e.length-1,this.args=I1(...e.slice(-1)),this.res=e[this.len]}check(e,t){let r=e.constructor===Function&&e.length<=this.len;return!r&&t?.extend(null,"function",typeof e),r}};var V1=K(qc),B1=X(n=>typeof n=="function"),Hc=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=Ys(this.shape,i=>i.check(e,t));return!r&&t?.extend(null,"Intersectinon",typeof e),r}};var sC=K(Hc,n=>n.shape.length>0),Oi=class extends le{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let r=ui(this.shape,i=>i.check(e,t));return t?.extend(null,"Union",typeof e),r}},Or=(...n)=>n.findIndex(e=>go.check(e))>=0?Or(...n.map(e=>Ni(e)).map(e=>go.check(e)?e.shape:[e]).flat(1)):n.length===1?n[0]:new Oi(n),go=K(Oi),wu=()=>!0,yo=X(wu),P1=K(Di,n=>n.shape===wu),jc=X(n=>typeof n=="bigint"),L1=X(n=>n===jc),bu=X(n=>typeof n=="symbol"),oC=X(n=>n===bu),Er=X(n=>typeof n=="number"),xu=X(n=>n===Er),Dr=X(n=>typeof n=="string"),Su=X(n=>n===Dr),bo=X(n=>typeof n=="boolean"),z1=X(n=>n===bo),ku=wo(void 0),lC=K(Tr,n=>n.shape.length===1&&n.shape[0]===void 0),cC=wo(void 0);var xo=wo(null),F1=K(Tr,n=>n.shape.length===1&&n.shape[0]===null),aC=K(Uint8Array),hC=K(Ti,n=>n.shape===Uint8Array),$1=Or(Er,Dr,xo,ku,jc,bo,bu),fC=(()=>{let n=yu(yo),e=gu(Dr,yo),t=Or(Er,Dr,xo,bo,n,e);return n.shape=t,e.shape.values=t,t})(),Ni=n=>{if(U1.check(n))return n;if(O1.check(n)){let e={};for(let t in n)e[t]=Ni(n[t]);return T1(e)}else{if(v1.check(n))return Or(...n.map(Ni));if($1.check(n))return wo(n);if(B1.check(n))return K(n)}F()},uu=iu?()=>{}:(n,e)=>{let t=new zc;if(!e.check(n,t))throw ve(`Expected value to be of type ${e.constructor.name}. -${t.toString()}`)},Jc=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Ni(e),h:t}),this}else(e){return this.if(yo,e)}done(){return(e,t)=>{for(let r=0;rnew Jc(n),Cu=q1(yo).if(xu,(n,e)=>oo(e,wc,hr)).if(Su,(n,e)=>du(e)).if(z1,(n,e)=>Bc(e)).if(L1,(n,e)=>BigInt(oo(e,wc,hr))).if(go,(n,e)=>Ar(e,lo(e,n.shape))).if(D1,(n,e)=>{let t={};for(let r in n.shape){let i=n.shape[r];if(E1.check(i)){if(Bc(e))continue;i=i.shape}t[r]=Cu(i,e)}return t}).if(R1,(n,e)=>{let t=[],r=Pc(e,0,42);for(let i=0;ilo(e,n.shape)).if(F1,(n,e)=>null).if(V1,(n,e)=>{let t=Ar(e,n.res);return()=>t}).if(P1,(n,e)=>Ar(e,lo(e,[Er,Dr,xo,ku,jc,bo,yu(Er),gu(Or("a","b","c"),Er)]))).if(N1,(n,e)=>{let t={},r=oo(e,0,3);for(let i=0;iCu(Ni(e),n);var Tt=typeof document<"u"?document:{};var dC=X(n=>n.nodeType===K1);var uC=typeof DOMParser<"u"?new DOMParser:null;var pC=X(n=>n.nodeType===J1);var mC=X(n=>n.nodeType===j1);var Mu=n=>Od(n,(e,t)=>`${t}:${e};`).join("");var J1=Tt.ELEMENT_NODE,j1=Tt.TEXT_NODE,gC=Tt.CDATA_SECTION_NODE,yC=Tt.COMMENT_NODE,W1=Tt.DOCUMENT_NODE,wC=Tt.DOCUMENT_TYPE_NODE,K1=Tt.DOCUMENT_FRAGMENT_NODE,bC=X(n=>n.nodeType===W1);var So=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Y1=So(clearTimeout),Ii=(n,e)=>new Y1(setTimeout(e,n)),SC=So(clearInterval);var kC=So(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var CC=So(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var ot=Symbol;var Ri=ot(),vi=ot(),Wc=ot(),Kc=ot(),Yc=ot(),_i=ot(),Gc=ot(),Nr=ot(),Xc=ot(),Tu=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Du(n)),Ou.forEach(e=>e.print(n))},Qc=(...n)=>{console.warn(...Du(n)),n.unshift(Nr),Ou.forEach(e=>e.print(n))};var Ou=Te();var Nu=n=>({[Symbol.iterator](){return this},next:n}),Iu=(n,e)=>Nu(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Co=(n,e)=>Nu(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ea=class extends cr{constructor(e,t){super(),this.doc=e,this.awareness=t}},Vi=class{constructor(e,t){this.clock=e,this.len=t}},Gt=class{constructor(){this.clients=new Map}},lt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);if(s!=null){let o=s[s.length-1],l=o.id.clock+o.length;for(let c=0,a=r[c];c{let t=0,r=n.length-1;for(;t<=r;){let i=Y((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&ib(t,e.clock)!==null},ha=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=$e(i.len,s.clock+s.len-i.clock):(r{let e=new Gt;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{W(n.clients,e,()=>[]).push(new Vi(t,r))},_r=()=>new Gt,fa=n=>{let e=_r();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},ct=(n,e)=>{x(n.restEncoder,e.clients.size),Xe(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new Gt,t=C(n.restDecoder);for(let r=0;r0){let o=W(e.clients,i,()=>[]);for(let l=0;l{let r=new Gt,i=C(n.restDecoder);for(let s=0;s0){let s=new Ue;return x(s.restEncoder,0),ct(s,r),s.toUint8Array()}return null},Yu=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Gu(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Io,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ec(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Ec(a=>{let h=f=>{(f===void 0||f===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Xe(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=H){let r=W(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==H&&i!==t)if(i===H){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,Vn)}getText(e=""){return this.get(e,dt)}getMap(e=""){return this.get(e,Bn)}getXmlElement(e=""){return this.get(e,ne)}getXmlFragment(e=""){return this.get(e,ut)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Xe(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Rn=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return C(this.restDecoder)}readDsLen(){return C(this.restDecoder)}},De=class extends Rn{readLeftID(){return M(C(this.restDecoder),C(this.restDecoder))}readRightID(){return M(C(this.restDecoder),C(this.restDecoder))}readClient(){return C(this.restDecoder)}readInfo(){return En(this.restDecoder)}readString(){return He(this.restDecoder)}readParentInfo(){return C(this.restDecoder)===1}readTypeRef(){return C(this.restDecoder)}readLen(){return C(this.restDecoder)}readAny(){return xr(this.restDecoder)}readBuf(){return hu(G(this.restDecoder))}readJSON(){return JSON.parse(He(this.restDecoder))}readKey(){return He(this.restDecoder)}},Oo=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=C(this.restDecoder),this.dsCurrVal}readDsLen(){let e=C(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ce=class extends Oo{constructor(e){super(e),this.keys=[],C(e),this.keyClockDecoder=new Sr(G(e)),this.clientDecoder=new Tn(G(e)),this.leftClockDecoder=new Sr(G(e)),this.rightClockDecoder=new Sr(G(e)),this.infoDecoder=new bi(G(e),En),this.stringDecoder=new to(G(e)),this.parentInfoDecoder=new bi(G(e),En),this.typeRefDecoder=new Tn(G(e)),this.lenDecoder=new Tn(G(e))}readLeftID(){return new Dt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Dt(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 xr(this.restDecoder)}readBuf(){return G(this.restDecoder)}readJSON(){return xr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=$e(r,e[0].id.clock);let i=je(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ki(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),Xe(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{sb(n,e.clients.get(i),i,s)})},ob=(n,e)=>{let t=_(),r=C(n.restDecoder);for(let i=0;i{let r=[],i=Xe(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Io,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],f=new Map,d=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ce){let p=W(f,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),d();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),d();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ue;return da(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},cb=(n,e)=>da(n,e.doc.store,e.beforeState),ua=(n,e,t,r=new Ce(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=ob(r,o),a=lb(i,l,c),h=l.pendingStructs;if(h){for(let[d,u]of h.missing)if(uu)&&h.missing.set(d,u)}h.update=Li([h.update,a.update])}}else l.pendingStructs=a;let f=_u(r,i,l);if(l.pendingDs){let d=new Ce(q(l.pendingDs));C(d.restDecoder);let u=_u(d,i,l);f&&u?l.pendingDs=Li([f,u]):l.pendingDs=f||u}else l.pendingDs=f;if(s){let d=l.pendingStructs.update;l.pendingStructs=null,zn(i.doc,d)}},t,!1),ab=(n,e,t)=>ua(n,e,t,new De(n)),zn=(n,e,t,r=Ce)=>{let i=q(e);ua(i,n,t,new r(i))},pa=(n,e,t)=>zn(n,e,t,De),hb=(n,e,t=new Map)=>{da(n,e.store,t),ct(n,fa(e.store))},Xu=(n,e=new Uint8Array([0]),t=new Ue)=>{let r=ga(e);hb(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(xa(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===at)return ap(i.map((s,o)=>o===0?s:pp(s)));if(t.constructor===Ue)return Li(i)}return i[0]},ma=(n,e)=>Xu(n,e,new at),Qu=n=>{let e=new Map,t=C(n.restDecoder);for(let r=0;rQu(new Rn(q(n))),ya=(n,e)=>(x(n.restEncoder,e.size),Xe(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),fb=(n,e)=>ya(n,Ki(e.store)),db=(n,e=new Ir)=>(n instanceof Map?ya(e,n):fb(e,n),e.toUint8Array()),wa=n=>db(n,new Xt),ta=class{constructor(){this.l=[]}},Uu=()=>new ta,Vu=(n,e)=>n.l.push(e),Bu=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Zu=(n,e,t)=>Ai(n.l,[e,t]),Dt=class{constructor(e,t){this.client=e,this.clock=t}},On=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Dt(n,e),Pu=(n,e)=>{x(n,e.client),x(n,e.clock)},Lu=n=>M(C(n),C(n)),Fn=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw F()},vn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},ub=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},na=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(f=>{f.content.getContent().forEach(d=>{d instanceof Uint8Array&&this.dss.set(o,In([this.dss.get(o)||_r(),Ot(new Rn(q(d)))]))})})}),this.dss.set(o,In(l.map(h=>Ot(new Rn(q(h)))))),c.observe(h=>h.changes.added.forEach(f=>f.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Bn,o.set("ids",new Vn),o.set("ds",new Vn),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((f,d)=>{r===f&&o.get("ids").push([d])});let a=new Xt,h=this.dss.get(r);h&&(ct(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Xt;ct(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(It(r,e))return t;return null}},ht=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},pb=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},$n=n=>new ht(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),No=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},mb=(n,e,t=0)=>new No(n,e,t),Mo=(n,e,t)=>{let r=null,i=null;return n._item===null?i=Fn(n):r=M(n._item.id.client,n._item.id.clock),new ht(r,i,e,t)},Ji=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Mo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Mo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Mo(n,r.lastId,t);r=r.right}return Mo(n,null,t)},gb=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Pu(n,i);else if(r!==null)yr(n,1),rt(n,r);else if(t!==null)yr(n,2),Pu(n,t);else throw F();return yi(n,s),n},yb=n=>{let e=$();return gb(e,n),I(e)},wb=n=>{let e=null,t=null,r=null;switch(C(n)){case 0:r=Lu(n);break;case 1:t=He(n);break;case 2:e=Lu(n)}let i=Cc(n)?xi(n):0;return new ht(e,t,r,i)},bb=n=>wb(q(n)),xb=(n,e)=>{let t=Nn(n,e),r=e.clock-t.id.clock;return{item:t,diff:r}},ba=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?ca(r,i):xb(r,i),f=h.item;if(!(f instanceof O))return null;if(c=f.parent,c._item===null||!c._item.deleted){a=f.deleted||!f.countable?0:h.diff+(l>=0?0:1);let d=f.left;for(;d!==null;)!d.deleted&&d.countable&&(a+=d.length),d=d.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?ca(r,s):{item:Nn(r,s)};if(h instanceof O&&h.content instanceof Oe)c=h.content.type;else return null}else throw F();l>=0?a=c._length:a=0}return mb(c,a,n.assoc)},zo=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&On(n.item,e.item)&&On(n.type,e.type)&&n.assoc===e.assoc,Qt=class{constructor(e,t){this.ds=e,this.sv=t}},Sb=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(ct(e,n.ds),ya(e,n.sv),e.toUint8Array()),kb=n=>ep(n,new Xt),tp=(n,e=new Oo(q(n)))=>new Qt(Ot(e),Qu(e)),Cb=n=>tp(n,new Rn(q(n))),ji=(n,e)=>new Qt(n,e),Mb=ji(_r(),new Map),Wi=n=>ji(fa(n.store),Ki(n.store)),Wt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!It(e.ds,n.id),ra=(n,e)=>{let t=W(n.meta,ra,Te),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Ab=(n,e,t=new Je)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ue;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new ft(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Eb(n,e,De),Io=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ki=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},np=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw F()}t.push(e)},je=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=Y(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[je(t,e.clock)]},Nn=Db,ia=(n,e,t)=>{let r=je(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[ia(n,t,e.clock)]},sa=(n,e,t)=>{let r=e.clients.get(t.client),i=je(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ye&&r.splice(i+1,0,Lo(n,s,t.clock-s.id.clock+1)),s},Ob=(n,e,t)=>{let r=n.clients.get(e.id.client);r[je(r,e.id.clock)]=t},rp=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=ia(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Nd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(ha(e.deleteSet),cb(n,e),ct(n,e.deleteSet),!0),Fu=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&W(n.changed,e,Te).add(t)},To=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},ip=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=je(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=Re(i.length-1,1+je(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+To(i,c)}})},Nb=(n,e,t)=>{ip(n,e,t),sp(n,e)},op=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,f)=>h.path.length-f.path.length),l.push(()=>{Zu(a._dEH,c,t)}))}),l.push(()=>r.emit("afterTransaction",[t,r])),l.push(()=>{t._needFormattingCleanup&&Xb(t)})}),Ai(l,[])}finally{r.gc&&ip(s,i,r.gcFilter),sp(s,i),t.afterState.forEach((h,f)=>{let d=t.beforeState.get(f)||0;if(d!==h){let u=i.clients.get(f),p=$e(je(u,d),1);for(let m=u.length-1;m>=p;)m-=1+To(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:f,clock:d}=o[h].id,u=i.clients.get(f),p=je(u,d);p+11||p>0&&To(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(ko(Nr,Ri,"[yjs] ",vi,_i,"Changed the client-id because another client seems to be using it."),r.clientID=Gu()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new at;zu(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ue;zu(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):op(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ro(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&op(i,0)}}return o},oa=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},$u=(n,e,t)=>{lt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>i===n.doc||vn(i,r))&&Aa(r,!1)})},qu=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,f=[],d=!1;lt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=ca(c,u.id);m>0&&(p=ge(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>p===l.doc||vn(p,u))&&f.push(u)}}),lt(l,a.deletions,u=>{u instanceof O&&s.some(p=>p===l.doc||vn(p,u))&&!It(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{d=vp(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||d});for(let u=f.length-1;u>=0;u--){let p=f[u];n.deleteFilter(p)&&(p.delete(l),d=!0)}n.currStackItem=d?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},_n=class extends cr{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=At(e)?e[0].doc:e instanceof Je?e:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g)||g===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,f=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let d=new Gt;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&Bi(d,y,E,N)});let u=_e(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=f[f.length-1];g.deletions=In([g.deletions,c.deleteSet]),g.insertions=In([g.insertions,d])}else f.push(new oa(c.deleteSet,d)),p=!0;!a&&!h&&(this.lastChange=u),lt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>y===c.doc||vn(y,g))&&Aa(g,!0)});let m=[{stackItem:f[f.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=At(e)?e:[e],e.forEach(r=>{t.has(r)||(t.add(r),(r instanceof H?r.doc!==this.doc:r!==this.doc)&&Qc("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>$u(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>$u(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=qu(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=qu(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*Ib(n){let e=C(n.restDecoder);for(let t=0;tlp(n,De),lp=(n,e=Ce)=>{let t=[],r=new e(q(n)),i=new ft(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);ko("Structs: ",t);let s=Ot(r);ko("DeleteSet: ",s)},vb=n=>cp(n,De),cp=(n,e=Ce)=>{let t=[],r=new e(q(n)),i=new ft(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:Ot(r)}},Pi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ap=n=>Li(n,De,at),hp=(n,e=Ir,t=Ce)=>{let r=new e,i=new ft(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ce&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=$();return x(h,o),zd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},_b=n=>hp(n,Xt,De),fp=(n,e=Ce)=>{let t=new Map,r=new Map,i=new ft(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},Ub=n=>fp(n,De),Vb=(n,e)=>{if(n.constructor===ye){let{client:t,clock:r}=n.id;return new ye(M(t,r+e),n.length-e)}else if(n.constructor===ce){let{client:t,clock:r}=n.id;return new ce(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},Li=(n,e=Ce,t=Ue)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new ft(h,!0)),s=null,o=new t,l=new Pi(o);for(;i=i.filter(d=>d.curr!==null),i.sort((d,u)=>{if(d.curr.id.client===u.curr.id.client){let p=d.curr.id.clock-u.curr.id.clock;return p===0?d.curr.constructor===u.curr.constructor?0:d.curr.constructor===ce?1:-1:p}else return u.curr.id.client-d.curr.id.client}),i.length!==0;){let h=i[0],f=h.curr.id.client;if(s!==null){let d=h.curr,u=!1;for(;d!==null&&d.id.clock+d.length<=s.struct.id.clock+s.struct.length&&d.id.client>=s.struct.id.client;)d=h.next(),u=!0;if(d===null||d.id.client!==f||u&&d.id.clock>s.struct.id.clock+s.struct.length)continue;if(f!==s.struct.id.client)Kt(l,s.struct,s.offset),s={struct:d,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ce?s.struct.length-=p:d=Vb(d,p)),s.struct.mergeWith(d)||(Kt(l,s.struct,s.offset),s={struct:d,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===f&&d.id.clock===s.struct.id.clock+s.struct.length&&d.constructor!==ce;d=h.next())Kt(l,s.struct,s.offset),s={struct:d,offset:0}}s!==null&&(Kt(l,s.struct,s.offset),s=null),Sa(l);let c=r.map(h=>Ot(h)),a=In(c);return ct(o,a),o.toUint8Array()},xa=(n,e,t=Ce,r=Ue)=>{let i=ga(e),s=new r,o=new Pi(s),l=new t(q(n)),c=new ft(l,!1);for(;c.curr;){let h=c.curr,f=h.id.client,d=i.get(f)||0;if(c.curr.constructor===ce){c.next();continue}if(h.id.clock+h.length>d)for(Kt(o,h,$e(d-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===f;)Kt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===f&&c.curr.id.clock+c.curr.length<=d;)c.next()}Sa(o);let a=Ot(l);return ct(s,a),s.toUint8Array()},Bb=(n,e)=>xa(n,e,De,at),dp=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=$(),n.written=0)},Kt=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&dp(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Sa=n=>{dp(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new ft(i,!1),o=new r,l=new Pi(o);for(let a=s.curr;a!==null;a=s.next())Kt(l,e(a),0);Sa(l);let c=Ot(i);return ct(o,c),o.toUint8Array()},up=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ye:case ce:return c;case O:{let a=c,h=a.content;switch(h.constructor){case vr:break;case Oe:{if(t){let f=h.type;f instanceof ne&&(f.nodeName=W(s,f.nodeName,()=>"node-"+r)),f instanceof qi&&(f.hookName=W(s,f.hookName,()=>"hook-"+r))}break}case Zt:{let f=h;f.arr=f.arr.map(()=>r);break}case Pn:{let f=h;f.content=new Uint8Array([r]);break}case Ln:{let f=h;e&&(f.opts={},f.doc.guid=r+"");break}case Nt:{let f=h;f.embed={};break}case P:{let f=h;n&&(f.key=W(o,f.key,()=>r+""),f.value=W(l,f.value,()=>({i:r})));break}case Hi:{let f=h;f.arr=f.arr.map(()=>r);break}case Ve:{let f=h;f.str=Xs(r%10+"",f.str.length);break}default:F()}return a.parentSub&&(a.parentSub=W(i,a.parentSub,()=>r+"")),r++,c}default:F()}}},Pb=(n,e)=>Fo(n,up(e),De,at),Lb=(n,e)=>Fo(n,up(e),Ce,Ue),zb=n=>Fo(n,_c,De,Ue),pp=n=>Fo(n,_c,Ce,at),Hu="You must not compute changes after the event-handler fired.",Un=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Fb(this.currentTarget,this.target))}deletes(e){return It(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ve(Hu);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Ks(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ks(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Ks(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw ve(Hu);let t=this.target,r=Te(),i=Te(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},Fb=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},ae=()=>{Qc("Invalid access: Add Yjs type to a document before reading data.")},mp=80,ka=0,la=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ka++}},$b=n=>{n.timestamp=ka++},gp=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=ka++},qb=(n,e,t)=>{if(n.length>=mp){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>Cn(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&Cn(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=$e(e,i.index+t))}},Hb=n=>{n.doc??ae();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},qo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;W(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Zu(r._eH,t,e)},H=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Uu(),this._dEH=Uu(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw ke()}clone(){throw ke()}_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){Vu(this._eH,e)}observeDeep(e){Vu(this._dEH,e)}unobserve(e){Bu(this._eH,e)}unobserveDeep(e){Bu(this._dEH,e)}toJSON(){}},yp=(n,e,t)=>{n.doc??ae(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},wp=n=>{n.doc??ae();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&Wt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??ae();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return Fi(n,(r,i)=>{t.push(e(r,i,n))}),t},Jb=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},xp=(n,e)=>{n.doc??ae();let t=$o(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Zt(a)),i.integrate(n,0),a=[])};r.forEach(f=>{if(f===null)a.push(f);else switch(f.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(f);break;default:switch(h(),f.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Pn(new Uint8Array(f))),i.integrate(n,0);break;case Je:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ln(f)),i.integrate(n,0);break;default:if(f instanceof H)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Oe(f)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Sp=()=>ve("Length exceeded!"),kp=(n,e,t,r)=>{if(t>e._length)throw Sp();if(t===0)return e._searchMarker&&zi(e._searchMarker,t,r.length),vo(n,e,null,r);let i=t,s=$o(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return vo(n,e,i,t)},Cp=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=$o(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Sp();e._searchMarker&&zi(e._searchMarker,i,-s+r)},_o=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ca=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Zt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Zt([r]);break;case Uint8Array:l=new Pn(r);break;case Je:l=new Ln(r);break;default:if(r instanceof H)l=new Oe(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Ma=(n,e)=>{n.doc??ae();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Mp=n=>{let e={};return n.doc??ae(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Ap=(n,e)=>{n.doc??ae();let t=n._map.get(e);return t!==void 0&&!t.deleted},Wb=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&Wt(r,t)?r.content.getContent()[r.length-1]:void 0},Ep=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&Wt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Ao=n=>(n.doc??ae(),Iu(n._map.entries(),e=>!e[1].deleted)),Uo=class extends Un{},Vn=class n extends H{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof H?t.clone():t)),e}get length(){return this.doc??ae(),this._length}_callObserver(e,t){super._callObserver(e,t),qo(this,e,new Uo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{kp(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{jb(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cp(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return xp(this,e)}toArray(){return wp(this)}slice(e=0,t=this.length){return yp(this,e,t)}toJSON(){return this.map(e=>e instanceof H?e.toJSON():e)}map(e){return bp(this,e)}forEach(e){Fi(this,e)}[Symbol.iterator](){return Jb(this)}_write(e){e.writeTypeRef(px)}},Kb=n=>new Vn,Vo=class extends Un{constructor(e,t,r){super(e,t),this.keysChanged=r}},Bn=class n extends H{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof H?t.clone():t)}),e}_callObserver(e,t){qo(this,e,new Vo(this,e,t))}toJSON(){this.doc??ae();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof H?i.toJSON():i}}),e}get size(){return[...Ao(this)].length}keys(){return Co(Ao(this),e=>e[0])}values(){return Co(Ao(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Co(Ao(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ae(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ma(this,e)}has(e){return Ap(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){_o(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mx)}},Yb=n=>new Bn,Yt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Rc(n,e),$i=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&F(),this.right.content.constructor){case P:this.right.deleted||Ur(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Ju=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||Ur(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?$o(e,t):null;if(s){let o=new $i(s.p.left,s.p,s.index,i);return Ju(n,o,t-s.index)}else{let o=new $i(null,e._start,0,i);return Ju(n,o,t)}},Tp=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Yt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},Ur=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Dp=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Yt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Op=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Yt(a,c)){o.set(l,a);let{left:h,right:f}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,f,f&&f.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},Zc=(n,e,t,r,i)=>{t.currentAttributes.forEach((d,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Dp(t,i);let l=Op(n,e,t,i),c=r.constructor===String?new Ve(r):r instanceof H?new Oe(r):new Nt(r),{left:a,right:h,index:f}=t;e._searchMarker&&zi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=f,t.forward(),Tp(n,e,t,l)},ju=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Dp(t,i);let l=Op(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Yt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` -`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Ve(c)),t.right.integrate(n,0),t.forward()}Tp(n,e,t,l)},Np=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:f}=a,d=r.get(h)??null;(o.get(h)!==a||d===f)&&(e.delete(n),l++,!c&&(i.get(h)??null)===f&&d!==f&&(d===null?i.delete(h):i.set(h,d))),!c&&!e.deleted&&Ur(i,a);break}}}e=e.right}return l},Gb=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Ip=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=Ws(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:Ur(o,i.content);break;default:e+=Np(t,r,i,s,o),s=Ws(o),r=i;break}i=i.right}}),e},Xb=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&rp(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ye&&e.add(o.parent)})}R(t,r=>{lt(n,n.deleteSet,i=>{if(i instanceof ye||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):Gb(r,i)});for(let i of e)Ip(i)})},Wu=(n,e,t)=>{let r=t,i=Ws(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Oe:case Nt:case Ve:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,f=0,d=()=>{if(l!==null){let u=null;switch(l){case"delete":f>0&&(u={delete:f}),f=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},tu(c)||(u.attributes=Qd({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Oe:case Nt:this.adds(o)?this.deletes(o)||(d(),l="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),f+=1):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=1);break;case Ve:this.adds(o)?this.deletes(o)||(l!=="insert"&&(d(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),f+=o.length):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Yt(m,p)?p!==null&&o.delete(r):(l==="retain"&&d(),Yt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Yt(m,p)||(l==="retain"&&d(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Yt(m,p)?m!==null&&o.delete(r):(l==="retain"&&d(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&d(),Ur(i,o.content));break}}o=o.right}for(d();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},dt=class n extends H{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ae(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new Bo(this,e,t);qo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ae();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Ve&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new $i(null,this._start,0,new Map);for(let s=0;s0)&&Zc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?ju(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wu(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??ae();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let f={},d=!1;s.forEach((p,m)=>{d=!0,f[m]=p});let u={insert:l};d&&(u.attributes=f),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(Wt(c,e)||t!==void 0&&Wt(c,t))switch(c.content.constructor){case Ve:{let f=s.get("ychange");e!==void 0&&!Wt(c,e)?(f===void 0||f.user!==c.id.client||f.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!Wt(c,t)?(f===void 0||f.user!==c.id.client||f.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):f!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Oe:case Nt:{a();let f={insert:c.content.getContent()[0]};if(s.size>0){let d={};f.attributes=d,s.forEach((u,p)=>{d[p]=u})}i.push(f);break}case P:Wt(c,e)&&(a(),Ur(s,c.content));break}c=c.right}a()};return e||t?R(o,f=>{e&&ra(f,e),t&&ra(f,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),Zc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!r);Zc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{Wu(i,Eo(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!1);o.right!==null&&ju(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ma(this,e)}getAttributes(){return Mp(this)}_write(e){e.writeTypeRef(gx)}},Qb=n=>new dt,Ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ae()}[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===ne||t.constructor===ut)&&t._start!==null)e=t._start;else for(;e!==null;){let r=e.next;if(r!==null){e=r;break}else e.parent===this._root?e=null:e=e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ut=class n extends H{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof H?t.clone():t)),e}get length(){return this.doc??ae(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new Ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Xe(new Ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){qo(this,e,new Po(this,t,e))}toString(){return bp(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),Fi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{kp(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof H?e._item:e;vo(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw ve("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cp(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return wp(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return xp(this,e)}slice(e=0,t=this.length){return yp(this,e,t)}forEach(e){Fi(this,e)}_write(e){e.writeTypeRef(wx)}},Zb=n=>new ut,ne=class n extends ut{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return Zd(t,(r,i)=>{e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof H?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ma(this,e)}hasAttribute(e){return Ap(this,e)}getAttributes(e){return e?Ep(this,e):Mp(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return Fi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(yx),e.writeKey(this.nodeName)}},ex=n=>new ne(n.readKey()),Po=class extends Un{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},qi=class n extends Bn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(bx),e.writeKey(this.hookName)}},tx=n=>new qi(n.readKey()),Me=class n extends dt{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(xx)}},nx=n=>new Me,Rr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw ke()}mergeWith(e){return!1}write(e,t,r){throw ke()}integrate(e,t){throw ke()}},rx=0,ye=class extends Rr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),np(e.doc.store,this)}write(e,t){e.writeInfo(rx),e.writeLen(this.length-t)}getMissing(e,t){return null}},Pn=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ix=n=>new Pn(n.readBuf()),vr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Bi(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}},sx=n=>new vr(n.readLen()),Rp=(n,e)=>new Je({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Ln=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Rp(this.doc.guid,this.opts))}splice(e){throw ke()}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}},ox=n=>new Ln(Rp(n.readString(),n.readAny())),Nt=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},lx=n=>new Nt(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},cx=n=>new P(n.readKey(),n.readJSON()),Hi=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},dx=n=>new Ve(n.readString()),ux=[Kb,Yb,Qb,ex,Zb,tx,nx],px=0,mx=1,gx=2,yx=3,wx=4,bx=5,xx=6,Oe=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Sx=n=>new Oe(ux[n.readTypeRef()](n)),ca=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Nn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},Aa=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},Lo=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},Ku=(n,e)=>ui(n,t=>It(t.deletions,e)),vp=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return ge(n,a);let h=e.parent._item,f=null,d;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||vp(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=ge(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(f=e.left,d=e;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:ge(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.left}for(;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:ge(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.right}}else if(d=null,e.right&&!i){for(f=e;f!==null&&f.right!==null&&(f.right.redone||It(r,f.right.id)||Ku(s.undoStack,f.right.id)||Ku(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=ge(n,f.redone);if(f&&f.right!==null)return null}else f=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,f,f&&f.lastId,d,d&&d.id,u,e.parentSub,e.content.copy());return e.redone=m,Aa(g,!0),g.integrate(n,0),g},O=class n extends Rr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sa(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=ge(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ye||this.right&&this.right.constructor===ye)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){let r=Nn(t,this.parent);r.constructor===ye?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=sa(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),On(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Bi(e.deleteSet,this.id.client,this.id.clock,this.length),Fu(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw F();this.content.gc(e),t?Ob(e,this,new ye(this.id,this.length)):this.content=new vr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=Fn(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Dt?(e.writeParentInfo(!1),e.writeLeftID(l)):F();s!==null&&e.writeString(s)}this.content.write(e,t)}},_p=(n,e)=>kx[e&31](n),kx=[()=>{F()},sx,ax,ix,dx,lx,cx,Sx,fx,ox,()=>{F()}],Cx=10,ce=class extends Rr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){F()}write(e,t){e.writeInfo(Cx),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Up=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vp="__ $YJS$ __";Up[Vp]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Up[Vp]=!0;var Bp=new Map,Ea=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:au(t.newValue||"")}),Kd(this._onChange)}postMessage(e){ro.setItem(this.room,cu(lu(e)))}close(){Yd(this._onChange)}},Mx=typeof BroadcastChannel>"u"?Ea:BroadcastChannel,Ta=n=>W(Bp,n,()=>{let e=Te(),t=new Mx(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Pp=(n,e)=>(Ta(n).subs.add(e),e),Lp=(n,e)=>{let t=Ta(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Bp.delete(n)),r},qn=(n,e,t=null)=>{let r=Ta(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var zp=0,Jo=1,Fp=2,jo=(n,e)=>{x(n,zp);let t=wa(e);U(n,t)},Da=(n,e,t)=>{x(n,Jo),U(n,ma(e,t))},Ex=(n,e,t)=>Da(e,t,G(n)),$p=(n,e,t)=>{try{pa(e,G(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},qp=(n,e)=>{x(n,Fp),U(n,e)},Tx=$p,Hp=(n,e,t,r)=>{let i=C(n);switch(i){case zp:Ex(n,e,t);break;case Jo:$p(n,t,r);break;case Fp:Tx(n,t,r);break;default:throw new Error("Unknown message type")}return i};var Ox=0;var Jp=(n,e,t)=>{switch(C(n)){case Ox:t(e,He(n))}};var Oa=3e4,Wo=class extends ar{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=_e();this.getLocalState()!==null&&Oa/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Oa<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&Ko(this,r,"timeout")},Y(Oa/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:_e()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),jt(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},Ko=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},Br=(n,e,t=n.states)=>{let r=e.length,i=$();x(i,r);for(let s=0;s{let r=q(e),i=_e(),s=[],o=[],l=[],c=[],a=C(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var Wp=n=>eu(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Hn=0,Yp=3,Pr=1,vx=2,Yi=[];Yi[Hn]=(n,e,t,r,i)=>{x(n,Hn);let s=Hp(e,n,t.doc,t);r&&s===Jo&&!t.synced&&(t.synced=!0)};Yi[Yp]=(n,e,t,r,i)=>{x(n,Pr),U(n,Br(t.awareness,Array.from(t.awareness.getStates().keys())))};Yi[Pr]=(n,e,t,r,i)=>{jp(t.awareness,G(e),t)};Yi[vx]=(n,e,t,r,i)=>{Jp(e,t.doc,(s,o)=>_x(t,o))};var Kp=3e4,_x=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Gp=(n,e,t)=>{let r=q(e),i=$(),s=C(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Xp=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=_e();let r=Gp(n,new Uint8Array(t.data),!0);Zs(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,Ko(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Xp,Re(vd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=_e(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=$();if(x(t,Hn),jo(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=$();x(r,Pr),U(r,Br(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Na=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&qn(n.bcChannel,e,n)},Ia=class extends ar{constructor(e,t,r,{connect:i=!0,awareness:s=new Wo(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:f=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=f,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Yi.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let d=$();x(d,Hn),jo(d,r),this.ws.send(I(d))}},a)),this._bcSubscriber=(d,u)=>{if(u!==this){let p=Gp(this,new Uint8Array(d),!1);Zs(p)>1&&qn(this.bcChannel,I(p),this)}},this._updateHandler=(d,u)=>{if(u!==this){let p=$();x(p,Hn),qp(p,d),Na(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:u,removed:p},m)=>{let g=d.concat(u).concat(p),y=$();x(y,Pr),U(y,Br(s,g)),Na(this,I(y))},this._exitHandler=()=>{Ko(this.awareness,[r.clientID],"app closed")},Et&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Kp<_e()-this.wsLastMessageReceived&&this.ws.close()},Kp/10),i&&this.connect()}get url(){let e=Wp(this.params);return this.serverUrl+"/"+this.roomname+(e.length===0?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Et&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Pp(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);let e=$();x(e,Hn),jo(e,this.doc),qn(this.bcChannel,I(e),this);let t=$();x(t,Hn),Da(t,this.doc),qn(this.bcChannel,I(t),this);let r=$();x(r,Yp),qn(this.bcChannel,I(r),this);let i=$();x(i,Pr),U(i,Br(this.awareness,[this.doc.clientID])),qn(this.bcChannel,I(i),this)}disconnectBc(){let e=$();x(e,Pr),U(e,Br(this.awareness,[this.doc.clientID],new Map)),Na(this,I(e)),this.bcconnected&&(Lp(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Xp(this),this.connectBc())}};var Qp=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var Ux=/[\uD800-\uDBFF]/,Vx=/[\uDC00-\uDFFF]/,Bx=(n,e)=>{let t=0,r=0;for(;t0&&Ux.test(n[t-1])&&t--;r+t0&&Vx.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Zp=Bx;var v=new fe("y-sync"),Rt=new fe("y-undo"),Gi=new fe("yjs-cursor");var Qi=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!It(e.ds,n.id),Px=[{light:"#ecd44433",dark:"#ecd444"}],Lx=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Hd(e))}return n.get(t)},nm=(n,{colors:e=Px,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Yo(n,s),c=new J({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let f=a.getMeta(v);if(f!==void 0){h=Object.assign({},h);for(let d in f)h[d]=f[d]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=f!==void 0&&!!f.isChangeOrigin,h.isUndoRedoOperation=f!==void 0&&!!f.isChangeOrigin&&!!f.isUndoRedoOperation,l.prosemirrorView!==null&&f!==void 0&&(f.snapshot!=null||f.prevSnapshot!=null)&&Ii(0,()=>{l.prosemirrorView!=null&&(f.restore==null?l._renderSnapshot(f.snapshot,f.prevSnapshot,h):(l._renderSnapshot(f.snapshot,f.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let f=Rt.getState(a.state),d=f&&f.undoManager;d&&d.stopCapturing()}l.mux(()=>{h.doc.transact(f=>{f.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},zx=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=en(t.doc,t.type,e.anchor,t.mapping),i=en(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Zi=(n,e)=>({anchor:Jn(e.selection.anchor,n.type,n.mapping),head:Jn(e.selection.head,n.type,n.mapping)}),Yo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Qp(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Zi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(Cr&&this._domSelectionInView===null&&(Ii(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Tt.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=ji(_r(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Xi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Xi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Wi(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&F(),i=new Je({gc:!1}),zn(i,t),t=Wi(i),zn(i,e),e=Wi(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{lt(s,h,f=>{})});let l=(h,f)=>{let d=h==="added"?o.getUserByClientId(f.client):o.getUserByDeletedId(f);return{user:d,type:h,color:Lx(r.colorMapping,r.colors,d)}},c=Ho(this.type,new Qt(t.ds,e.sv)).map(h=>!h._item.deleted||Qi(h._item,e)||Qi(h._item,t)?Xi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);lt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>rm(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));zx(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof _n}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Lr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Zi(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},rm=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof ne)return Xi(n,e,t,r,i,s);throw ke()}return o},Xi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===ne){let a=rm(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof dt&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(f=>{a._item.delete(f)}));let h=Fx(c,e,t,r,i,s);h!==null&&h.forEach(f=>{f!==null&&o.push(f)})}};r===void 0||i===void 0?n.toArray().forEach(l):Ho(n,new Qt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Qi(n._item,r)?Qi(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},Fx=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},$x=(n,e)=>{let t=new Me,r=n.map(i=>({insert:i.text,attributes:sm(i.marks)}));return t.applyDelta(r),e.set(t,n),t},qx=(n,e)=>{let t=new ne(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,Xo(n).map(r=>Ra(r,e))),e.set(t,n),t},Ra=(n,e)=>n instanceof Array?$x(n,e):qx(n,e),em=n=>typeof n=="object"&&n!==null,_a=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Ic(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>_a(r.attributes[s.type.name]||{},s.attrs)))},es=(n,e)=>{if(n instanceof ne&&!(e instanceof Array)&&va(n,e)){let t=Xo(e);return n._length===t.length&&_a(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>es(r,t[i]))}return n instanceof Me&&e instanceof Array&&im(n,e)},Go=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),tm=(n,e,t)=>{let r=n.toArray(),i=Xo(e),s=i.length,o=r.length,l=Re(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Ve?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},Jx=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=Hx(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,sm(a.marks))})),{insert:o,remove:l,index:c}=Zp(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},sm=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Lr=(n,e,t,r)=>{if(e instanceof ne&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof ne){let f=e.getAttributes(),d=t.attrs;for(let u in d)d[u]!==null?f[u]!==d[u]&&u!=="ychange"&&e.setAttribute(u,d[u]):e.removeAttribute(u);for(let u in f)d[u]===void 0&&e.removeAttribute(u)}let i=Xo(t),s=i.length,o=e.toArray(),l=o.length,c=Re(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let d=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(d instanceof Me&&u instanceof Array)im(d,u)||Jx(d,u,r),a+=1;else{let g=d instanceof ne&&va(d,u),y=p instanceof ne&&va(p,m);if(g&&y){let E=tm(d,u,r),N=tm(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+f).forEach(d=>r.delete(d)),e.delete(a,f)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var ts=null,jx=()=>{let n=ts;ts=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Ua=(n,e,t)=>{ts||(ts=new Map,Ii(0,jx)),W(ts,n,_).set(e,t)},Jn=(n,e,t)=>{if(n===0)return Ji(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof Me){if(r._length>=n)return Ji(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ht(r._item===null?null:r._item.id,r._item===null?Fn(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ht(r._item===null?null:r._item.id,r._item===null?Fn(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw F();if(n===0&&r.constructor!==Me&&r!==e)return Wx(r._item.parent,r._item)}return Ji(e,e._length,-1)},Wx=(n,e)=>{let t=null,r=null;return n._item===null?r=Fn(n):t=M(n._item.id.client,n._item.id.clock),new ht(t,r,e.id)},en=(n,e,t,r)=>{let i=ba(t,n);if(i===null||i.type!==e&&!vn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===Me)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Lr(r,t,n,new Map),t}function lm(n,e){let t=Ba(e);return Be.fromJSON(n,t)}function Ba(n,e="prosemirror"){return Pa(n.getXmlFragment(e))}function Pa(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Kx=(n,e,t)=>n!==e,Yx=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},Gx=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Xx=/^#[0-9a-fA-F]{6}$/,cm=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?L.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Xx.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let f=en(o,s.type,$n(c.cursor.anchor),s.binding.mapping),d=en(o,s.type,$n(c.cursor.head),s.binding.mapping);if(f!==null&&d!==null){let u=$e(n.doc.content.size-1,0);f=Re(f,u),d=Re(d,u),l.push(se.widget(d,()=>r(h),{key:a+"",side:10}));let p=Re(f,d),m=$e(f,d);l.push(se.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(n.doc,l))},Qx=(n,{awarenessStateFilter:e=Kx,cursorBuilder:t=Yx,selectionBuilder:r=Gx,getSelection:i=o=>o.selection}={},s="cursor")=>new J({key:Gi,state:{init(o,l){return cm(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),f=o.getMeta(Gi);return h&&h.isChangeOrigin||f&&f.awarenessUpdated?cm(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Gi.getState(o)},view:o=>{let l=()=>{o.docView&&Ua(o,Gi,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let f=i(o.state),d=Jn(f.anchor,a.type,a.binding.mapping),u=Jn(f.head,a.type,a.binding.mapping);(h.cursor==null||!zo($n(h.cursor.anchor),d)||!zo($n(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:d,head:u})}else h.cursor!=null&&en(a.doc,a.type,$n(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Zx=n=>{let e=Rt.getState(n).undoManager;if(e!=null)return e.undo(),!0},eS=n=>{let e=Rt.getState(n).undoManager;if(e!=null)return e.redo(),!0},tS=new Set(["paragraph"]),nS=(n,e)=>!(n instanceof O)||!(n.content instanceof Oe)||!(n.content.type instanceof dt||n.content.type instanceof ne&&e.has(n.content.type.nodeName))||n.content.type._length===0,rS=({protectedNodes:n=tS,trackedOrigins:e=[],undoManager:t=null}={})=>new J({key:Rt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new _n(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>nS(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Zi(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Rt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Rt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var ns="http://www.w3.org/2000/svg",iS="http://www.w3.org/1999/xlink",za="ProseMirror-icon",La="pm-close-dropdowns";function sS(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(Qe+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,am(r,Qe+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;am(r,Qe+"-active",l)}return!0}return{dom:r,update:i}}};function Qo(n,e){return n._props.translate?n._props.translate(e):e}var rs={time:0,node:null};function cS(n){rs.time=Date.now(),rs.node=n.target}function aS(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(La,c))};i.addEventListener("mousedown",f=>{f.preventDefault(),cS(f),o?a():(r.dispatchEvent(new CustomEvent(La)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{aS(s)||a()}),r.addEventListener(La,c=()=>{a()}))});function h(f){let d=t.update(f);return s.style.display=d?"":"none",d}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${Qe}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${Qe}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=kt("div",{class:Qe+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function hS(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;ioi(n),icon:is.join}),AM=new pt({title:"Lift out of enclosing block",run:li,select:n=>li(n),icon:is.lift}),EM=new pt({title:"Select parent node",run:ci,select:n=>ci(n),icon:is.selectParentNode}),TM=new pt({title:"Undo last change",run:fi,enable:n=>fi(n),icon:is.undo}),DM=new pt({title:"Redo last undone change",run:or,enable:n=>or(n),icon:is.redo});function uS(n,e){let t={run(r,i){return sr(n,e.attrs)(r,i)},select(r){return sr(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new pt(t)}function pS(n,e){let t=bn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new pt(r)}function am(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{Wn as DOMParser,Ut as DOMSerializer,Fa as Dropdown,bl as EditorState,$l as EditorView,w as Fragment,Ct as InputRule,pt as MenuItem,k as NodeSelection,J as Plugin,fe as PluginKey,qr as Schema,b as Slice,A as TextSelection,Ia as WebsocketProvider,Vr as Y,nw as addColumnAfter,tw as addColumnBefore,f0 as addListNodes,lw as addRowAfter,ow as addRowBefore,td as baseKeymap,zy as baseSchema,pS as blockTypeItem,P0 as buildKeymap,Tw as columnResizing,iw as deleteColumn,aw as deleteRow,yw as deleteTable,Md as fixTables,O0 as gapCursor,gw as goToNextCell,ld as inputRules,Ye as isInTable,x0 as keymap,tc as liftListItem,fw as mergeCells,om as prosemirrorToYDoc,Va as prosemirrorToYXmlFragment,fS as renderGrouped,Ge as selectedRect,bn as setBlockType,nc as sinkListItem,dw as splitCell,ec as splitListItem,Pw as tableEditing,q0 as tableNodes,xn as toggleMark,sr as wrapIn,Us as wrapInList,uS as wrapItem,Qx as yCursorPlugin,lm as yDocToProsemirror,Ba as yDocToProsemirrorJSON,eS as yRedo,nm as ySyncPlugin,Zx as yUndo,rS as yUndoPlugin,Rt as yUndoPluginKey,Pa as yXmlFragmentToProsemirrorJSON}; +`);return{dom:c,text:f,slice:e}}function Lh(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=It.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=Wm(t),$r&&jm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Hm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Km(hh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Jm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var Hm=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Jm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&Fh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=qh(o[o.length-1],s.length));let h=zh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function zh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Fh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function hh(n,e,t){return et}).createHTML(n):n}function Wm(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Jh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Hh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=$m(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Ym={touchstart:!0,touchmove:!0},tl=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Gm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Qm(n,r)&&!dl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Ym[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),nl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Xm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function nl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>dl(n,r))})}function dl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Qm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Zm(n,e){!dl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Wh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Kn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||qm(n,t)?t.preventDefault():Vt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if(Wh(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function us(n){return{left:n.clientX,top:n.clientY}}function eg(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function fl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function jn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function tg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(jn(n,new k(t),"pointer"),!0):!1}function ng(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof k&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(k.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(jn(n,k.create(n.state.doc,i),"pointer"),!0):!1}function rg(n,e,t,r,i){return fl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?ng(n,t):tg(n,t))}function ig(n,e,t,r){return fl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function sg(n,e,t,r){return fl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||og(n,t,r)}function og(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(jn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)jn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(k.isSelectable(o))jn(n,k.create(r,l),"pointer");else continue;return!0}}function ul(n){return ls(n)}var $h=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ul(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&eg(t,n.input.lastClick)&&!t[$h]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(us(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new rl(n,o,t,!!r)):(s=="doubleClick"?ig:sg)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var rl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[$h],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof k&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Vt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(us(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):rg(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(jn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Vt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),ul(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>ul(n);function Wh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var lg=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ls(n,!0),n.markCursor=null;else if(ls(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}jh(n,lg)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,jh(n,20))};function jh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ls(n),e))}function Kh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ag());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function cg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=sm(e.focusNode,e.focusOffset),r=om(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function ag(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ls(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Kh(n),e||n.docView&&n.docView.dirty){let t=al(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function hg(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Fr=ke&&Bt<15||Kn&&dm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Fr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Ph(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):hg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function fg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?qr(n,r.value,null,i,e):qr(n,r.textContent,r.innerHTML,i,e)},50)}function qr(n,e,t,r,i){let s=Lh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=dg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Yh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Yh(r),r.getData("text/html"),i,t)?t.preventDefault():fg(n,t)};var cs=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Gh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(us(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=k.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Ph(n,l);(!t.dataTransfer.files.length||!ae||Mh>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Fr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Fr||t.dataTransfer.setData("text/plain",a),n.dragging=new cs(h,!t[Gh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(us(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Lh(n,Yh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Gh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Xi(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&k.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new k(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(hl(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Hr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var as=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Hr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Qh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return z.empty;let r=[];for(let i=0;it instanceof z)?e:e.reduce((t,r)=>t.concat(r instanceof z?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=pg(l,n,e,t,i,s,o),h=ds(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Qh(n,l,c+t);if(a){s=!0;let h=ds(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Xh(s?Zh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Fo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(z.create(n.state.doc,[n.cursorWrapper.deco])),hs.from(e)}var mg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},gg=ke&&Bt<=11,sl=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}},ol=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new sl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),gg&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,mg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(ih(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(ke&&Bt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=zr(s))t.add(s);for(let s=e.anchorNode;s;s=zr(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&ih(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||bg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),yg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||mt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Sg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Sg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var kg=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Cg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=al(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100hp(n,on(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),s&&Bi.setMeta("composition",s),n.dispatch(Bi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=xg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!kg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=gh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);s&&Nt.setMeta("composition",s),n.dispatch(Nt)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Bt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ag(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,dt,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20)),Y=n.state.tr.delete(Se,pe),dt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Mg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Ot.type=="add"?Y.addMark(Se,pe,Ot.mark):Y.removeMark(Se,pe,Ot.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=gh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:hl(n,e.resolve(t.anchor),e.resolve(t.head))}function Mg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||qo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Eg(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ll=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 tl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(kh),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=xh(this),bh(this),this.nodeViews=Sh(this),this.docView=Qa(this.state.doc,wh(this),Fo(this),this.dom,this),this.domObserver=new ol(this,(r,i,s,o)=>Cg(this,r,i,s,o)),this.domObserver.start(),Gm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&nl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(kh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Kh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=Sh(this);Dg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&nl(this),this.editable=xh(this),bh(this);let c=Fo(this),a=wh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&pm(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Tg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=cg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Um(this))?mt(this,u):(Uh(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&mm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Wa(this,t.getBoundingClientRect(),e)}else Wa(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new cs(e.slice,e.move,i<0?void 0:k.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Sm(this,e)}coordsAtPos(e,t=1){return Oh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Em(this,t||this.state,e)}pasteHTML(e,t){return qr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return qr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Xm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Fo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,rm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Zm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&cm(this.dom.ownerDocument)==this.dom&&wg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function wh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function bh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function xh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Tg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Sh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Dg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function kh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Og=["p",0],Ng=["blockquote",0],Ig=["hr"],Rg=["pre",["code",0]],vg=["br"],_g={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Og}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Ng}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ig}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Rg}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return vg}}},Ug=["em",0],Vg=["strong",0],Bg=["code",0],Pg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Ug}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Vg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Bg}}},Lg=new Dr({nodes:_g,marks:Pg});var td=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function zg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Fg=(n,e,t)=>{let r=zg(n,t);if(!r)return!1;let i=nd(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(sd(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||k.isSelectable(s)))for(let o=r.depth;;o--){let l=Qi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Gn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var qg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=nd(r)}let o=s&&s.nodeBefore;return!o||!k.isSelectable(o)?!1:(e&&e(n.tr.setSelection(k.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function nd(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Hg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Hg(n,t);if(!r)return!1;let i=rd(r);if(!i)return!1;let s=i.nodeAfter;if(sd(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||k.isSelectable(s))){let o=Qi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof k,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=vo(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(k.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},id=(n,e)=>{let t=n.selection,r;if(t instanceof k){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=vo(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Wg=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function gl(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=gl(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},jg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=gl(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Rt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Yg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof k&&e.selection.node.isBlock)return!r.parentOffset||!Rt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:gl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Rt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Gg=Yg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(k.create(n.doc,i))),!0)},Xg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Qg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function sd(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Qg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&nn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Gn(s,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function od(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Zg=od(-1),ey=od(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Gi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ny(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new vt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new Zt(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Rt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?fy(e,t,n,s):uy(e,t,s):!0:!1}}function fy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Sl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var yt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},gs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},py=typeof navigator<"u"&&/Mac/.test(navigator.platform),my=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)yt[48+J]=yt[96+J]=String(J);var J;for(J=1;J<=24;J++)yt[J+111]="F"+J;var J;for(J=65;J<=90;J++)yt[J]=String.fromCharCode(J+32),gs[J]=String.fromCharCode(J);var J;for(ms in yt)gs.hasOwnProperty(ms)||(gs[ms]=yt[ms]);var ms;function ad(n){var e=py&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||my&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?gs:yt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var gy=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function yy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=yt[r.keyCode])&&s!=i){let l=e[kl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var ys=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new hd(e):re.empty};var hd=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=ys)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=ys)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new hd([]);var xy=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),Cl=re;var Sy=500,ws=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hCy&&(l=ky(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Rr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fSy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(Cl.from(i.reverse()),s)}};ws.empty=new ws(Cl.empty,0);function ky(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Al=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},Cy=20;function My(n,e,t){let r=Ay(e),i=El.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Al(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(El,{redo:t,historyState:c})}var Ml=!1,dd=null;function Ay(n){let e=n.plugins;if(dd!=e){Ml=!1,dd=e;for(let t=0;t{let i=El.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=My(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Xr=bs(!1,!0),Qn=bs(!0,!0),bx=bs(!1,!1),xx=bs(!0,!1);function Ey(n={}){return new L({view(e){return new Tl(e,n)}})}var Tl=class{constructor(e,t){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=t.width)!==null&&r!==void 0?r:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,r;if(t){let l=e.nodeBefore,c=e.nodeAfter;if(l||c){let a=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(a){let h=a.getBoundingClientRect(),d=l?h.bottom:h.top;l&&c&&(d=(d+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:h.left,right:h.right,top:d-this.width/2,bottom:d+this.width/2}}}}if(!r){let l=this.editorView.coordsAtPos(this.cursorPos);r={left:l.left-this.width/2,right:l.left+this.width/2,top:l.top,bottom:l.bottom}}let i=this.editorView.dom.offsetParent;this.element||(this.element=i.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let s,o;if(!i||i==document.body&&getComputedStyle(i).position=="static")s=-pageXOffset,o=-pageYOffset;else{let l=i.getBoundingClientRect();s=l.left-i.scrollLeft,o=l.top-i.scrollTop}this.element.style.left=r.left-s+"px",this.element.style.top=r.top-o+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Xi(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}};var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new Dl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ty(e)||!Dy(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!k.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var Dl=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ty(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Dy(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Oy(){return new L({props:{decorations:vy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Iy,handleKeyDown:Ny,handleDOMEvents:{beforeinput:Ry}}})}var Ny=Gr({ArrowLeft:xs("horiz",-1),ArrowRight:xs("horiz",1),ArrowUp:xs("vert",-1),ArrowDown:xs("vert",1)});function xs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Iy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&k.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Ry(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function vy(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",z.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function wt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var Uy=500;function pd({rules:n}){let e=new L({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return ud(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ud(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ud(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-Uy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},Vy=new bt(/--$/,"\u2014"),By=new bt(/\.\.\.$/,"\u2026"),Rx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),vx=new bt(/"$/,"\u201D"),_x=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Ux=new bt(/'$/,"\u2019");var gd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Py(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",md),gd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",id),i("Mod-BracketLeft",jr),i("Escape",Kr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",ps(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",ps(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let s=r,o=Yr(yl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),gd&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",bl(r)),i("Mod-[",xl(r)),i("Mod-]",Sl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Nl,Il;if(typeof WeakMap<"u"){let n=new WeakMap;Nl=e=>n.get(e),Il=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Nl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var F=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Fy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function wd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Hy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>yd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>yd(r,e)}],toDOM(r){return["th",wd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var zt=new le("selectingCells");function Zn(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Jy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ul(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=Zn(e.$head)||$y(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function $y(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Rl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Wy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Vl(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Td(n,e,t){let r=n.node(-1),i=F.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Dd(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new vt(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Rl(r)&&Rl(i)&&Vl(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?xt.rowSelection(r,i):s&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=F.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=F.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof xt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=F.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Gy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Xy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Qy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=F.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&Gy(r)?s=A.create(i,r.from):r instanceof A&&Xy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Zy=new le("fix-tables");function Nd(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=e0(n,i,s,t))};return e?e.doc!=n.doc&&Nd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function e0(n,e,t,r){let i=F.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;jy(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;s0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function u0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=Jy(i.$from),!s)return!1;o=(r=Zn(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var rS=Bl("row",{useDeprecatedLogic:!0}),iS=Bl("column",{useDeprecatedLogic:!0}),sS=Bl("cell",{useDeprecatedLogic:!0});function m0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function Ss(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function w0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function S0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Ms(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=_d(i,n,e);if(o==null)return!1;if(n=="horiz")return Ms(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Td(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Ms(t,r,a)}}}function Cs(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=_d(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Td(o.$headCell,n,e);return l?Ms(t,r,new V(o.$anchorCell,l)):!1}}function C0(n,e){let t=n.state.doc,r=Zn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function M0(n,e,t){if(!He(n.state))return!1;let r=w0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(vl(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=F.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=x0(r,l.right-l.left,l.bottom-l.top),Cd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ul(n.state),o=s.start(-1);return Cd(n.state,n.dispatch,o,F.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function A0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Md(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Ol(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Ol(n,a),d=zt.getState(n.state)==null;if(!h||!Vl(c,h))if(d)h=c;else return;let f=new V(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(zt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),zt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(zt,-1))}function l(c){let a=c,h=zt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Md(n,a.target)!=r&&(d=Ol(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function _d(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Md(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ol(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var E0=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),_l(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,_l(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function _l(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new D0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{O0(s,o,n,e,r)},mouseleave:s=>{N0(s)},mousedown:(s,o)=>{I0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return B0(s,o.activeHandle)},nodeViews:{}}});return i}var D0=class As{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new As(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new As(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Rl(e.doc.resolve(i))||(i=-1),new As(i,t.dragging)}return t}};function O0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=v0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Ad(n,e,"left",t):a-e.clientX<=t&&(l=Ad(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=F.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ud(n,l)}}}function N0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ud(n,-1)}function I0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=R0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(_0(n,d.activeHandle,Ed(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ed(d.dragging,h,t);U0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function R0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;aKs,AbstractConnector:()=>dc,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>Et,ContentFormat:()=>P,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Mt,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>uc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Gs,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Zs,YEvent:()=>Dn,YMapEvent:()=>eo,YTextEvent:()=>to,YXmlEvent:()=>no,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Nu,compareIDs:()=>kn,compareRelativePositions:()=>io,convertUpdateFormatV1ToV2:()=>f1,convertUpdateFormatV2ToV1:()=>uu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Xw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Ww,decodeSnapshot:()=>Yw,decodeSnapshotV2:()=>eu,decodeStateVector:()=>Ec,decodeUpdate:()=>s1,decodeUpdateV2:()=>lu,diffUpdate:()=>a1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Gw,encodeRelativePosition:()=>Jw,encodeSnapshot:()=>Kw,encodeSnapshotV2:()=>Zf,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Gf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>o1,encodeStateVectorFromUpdateV2:()=>au,equalDeleteSets:()=>Kf,equalSnapshots:()=>jw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>B,getTypeChildren:()=>g1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>zw,logUpdate:()=>i1,logUpdateV2:()=>ou,mergeDeleteSets:()=>Mn,mergeUpdates:()=>cu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>h1,obfuscateUpdateV2:()=>d1,parseUpdateMeta:()=>l1,parseUpdateMetaV2:()=>hu,readUpdate:()=>Vw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>Fw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Zw,transact:()=>R,tryGc:()=>n1,typeListToArraySnapshot:()=>co,typeMapGetAllSnapshot:()=>Au,typeMapGetSnapshot:()=>b1});var _=()=>new Map,Es=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Vd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Bd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Ts=n=>n[n.length-1];var Pd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},tr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,pS=Number.isNaN,Fd=Math.pow;var Os=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,mS=Number.MIN_SAFE_INTEGER,gS=1<<31;var qd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),yS=Number.isNaN,wS=Number.parseInt;var Ll=String.fromCharCode,bS=String.fromCodePoint,xS=Ll(65535),L0=n=>n.toLowerCase(),z0=/^\s*/g,F0=n=>n.replace(z0,""),q0=/([A-Z])/g,zl=(n,e)=>F0(n.replace(q0,t=>`${e}${L0(t)}`));var H0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Jd=ir?J0:H0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var $d=(n,e)=>zd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},q=()=>new wn;var Is=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Is(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var cr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ni=(n,e)=>{let t=Os(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Fl=new Uint8Array(3e4),W0=Fl.length/3,j0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iar(n,I(e)),ar=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{$0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Y0=(n,e)=>ql(n,4).setFloat32(0,e,!1),G0=(n,e)=>ql(n,8).setFloat64(0,e,!1),X0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var jd=new DataView(new ArrayBuffer(4)),Q0=n=>(jd.setFloat32(0,n),jd.getFloat32(0)===n),or=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":qd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Q0(e)?(Q(n,124),Y0(n,e)):(Q(n,123),G0(n,e));break;case"bigint":Q(n,122),X0(n,e);break;case"object":if(e===null)Q(n,126);else if(Zr(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var Kd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Kd(this),this.count=1,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}};var Yd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ni(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},lr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Yd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Yd(this),I(this.encoder)}},Ns=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var Xd=Ze("Unexpected end of array"),Qd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},H=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var Z0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>Z0(n,C(n));var xn=n=>n.arr[n.pos++];var C=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw Qd}throw Xd},ii=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posPl)throw Qd}throw Xd};var ew=n=>{let e=C(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},tw=n=>rr.decode(K(n)),Le=rr?tw:ew;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},nw=n=>Jl(n,4).getFloat32(0,!1),rw=n=>Jl(n,8).getFloat64(0,!1),iw=n=>Jl(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,nw,rw,iw,n=>!1,n=>!0,Le,n=>{let e=C(n),t={};for(let r=0;r{let e=C(n),t=[];for(let r=0;rsw[127-xn(n)](n),ri=class extends hr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Hl(this)?this.count=C(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends hr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Os(this.s);this.count=1,e&&(this.s=-this.s,this.count=C(this)+2)}return this.count--,this.s}};var fr=class extends hr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ii(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=C(this)+2)}return this.s+=this.diff,this.count--,this.s}},_s=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var CS=crypto.subtle,Zd=crypto.getRandomValues.bind(crypto);var ow=Math.random,$l=()=>Zd(new Uint32Array(1))[0];var ef=n=>n[fe(ow()*n.length)],lw="10000000-1000-4000-8000"+-1e11,tf=()=>lw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var ES=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},rf=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(rf=localStorage,Yl=!1)}catch{}var Vs=rf,sf=n=>Yl||addEventListener("storage",n),of=n=>Yl||removeEventListener("storage",n);var af=Object.assign,Bs=Object.keys,hf=(n,e)=>{for(let t in n)e(n[t],t)},df=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Bs(n).length,cf=n=>Bs(n).length;var ff=n=>{for(let e in n)return!1;return!0},hw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||cf(n)===cf(e)&&hw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),dw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return dw(n)};var oi=(n,e,t=0)=>{try{for(;tn,fw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return fw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",pr=typeof window<"u"&&typeof document<"u"&&!kt,TS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,uw=[],pw=()=>{if(et===void 0)if(kt){et=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${zl(e,"-")}`,t),et.set(`-${zl(e,"-")}`,t)}})):et=_();return et},nc=n=>pw().has(n);var li=n=>kt?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Vs.getItem(n));var pf=n=>nc("--"+n)||li(n)!==null,DS=pf("production"),mw=kt&&uf(process.env.FORCE_COLOR,["true","1","2"]),mf=mw||!nc("--no-colors")&&!pf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var gf=n=>new Uint8Array(n),gw=(n,e,t)=>new Uint8Array(n,e,t),yf=n=>new Uint8Array(n),yw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),bw=n=>{let e=atob(n),t=gf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return gw(e.buffer,e.byteOffset,e.byteLength)},wf=pr?yw:ww,bf=pr?bw:xw;var xf=n=>{let e=gf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new rc(n,e);var Ct=typeof document<"u"?document:{};var OS=typeof DOMParser<"u"?new DOMParser:null;var kf=n=>Vd(n,(e,t)=>`${t}:${e};`).join("");var NS=Ct.ELEMENT_NODE,IS=Ct.TEXT_NODE,RS=Ct.CDATA_SECTION_NODE,vS=Ct.COMMENT_NODE,_S=Ct.DOCUMENT_NODE,US=Ct.DOCUMENT_TYPE_NODE,VS=Ct.DOCUMENT_FRAGMENT_NODE;var Ls=n=>class{constructor(t){this._=t}destroy(){n(this._)}},kw=Ls(clearTimeout),ai=(n,e)=>new kw(setTimeout(e,n)),PS=Ls(clearInterval);var LS=Ls(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var zS=Ls(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),ic=nt(),sc=nt(),oc=nt(),fi=nt(),lc=nt(),mr=nt(),cc=nt(),Af=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Ef(n)),Tf.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Ef(n)),n.unshift(mr),Tf.forEach(e=>e.print(n))};var Tf=Ce();var Df=n=>({[Symbol.iterator](){return this},next:n}),Of=(n,e)=>Df(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Fs=(n,e)=>Df(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=class extends er{constructor(e,t){super(),this.doc=e,this.awareness=t}},pi=class{constructor(e,t){this.clock=e,this.len=t}},$t=class{constructor(){this.clients=new Map}},rt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Iw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},it=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new $t,t=C(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=C(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),it(s,r),s.toUint8Array()}return null},Kf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Yf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ys,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,at)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return C(this.restDecoder)}readDsLen(){return C(this.restDecoder)}},Me=class extends An{readLeftID(){return M(C(this.restDecoder),C(this.restDecoder))}readRightID(){return M(C(this.restDecoder),C(this.restDecoder))}readClient(){return C(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return C(this.restDecoder)===1}readTypeRef(){return C(this.restDecoder)}readLen(){return C(this.restDecoder)}readAny(){return dr(this.restDecoder)}readBuf(){return xf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},js=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=C(this.restDecoder),this.dsCurrVal}readDsLen(){let e=C(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends js{constructor(e){super(e),this.keys=[],C(e),this.keyClockDecoder=new fr(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new fr(K(e)),this.rightClockDecoder=new fr(K(e)),this.infoDecoder=new ri(K(e),xn),this.stringDecoder=new _s(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return dr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return dr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ei(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Rw(n,e.clients.get(i),i,s)})},vw=(n,e)=>{let t=_(),r=C(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ys,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Uw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=vw(r,o),a=_w(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=yi([h.update,a.update])}}else l.pendingStructs=a;let d=Rf(r,i,l);if(l.pendingDs){let f=new be(H(l.pendingDs));C(f.restDecoder);let u=Rf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Vw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=H(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Bw=(n,e,t=new Map)=>{kc(n,e.store,t),it(n,Sc(e.store))},Gf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Ec(e);Bw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===st)return cu(i.map((s,o)=>o===0?s:uu(s)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Gf(n,e,new st),Xf=n=>{let e=new Map,t=C(n.restDecoder);for(let r=0;rXf(new An(H(n))),Tc=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Pw=(n,e)=>Tc(n,Ei(e.store)),Lw=(n,e=new gr)=>(n instanceof Map?Tc(e,n):Pw(e,n),e.toUint8Array()),Dc=n=>Lw(n,new Wt),fc=class{constructor(){this.l=[]}},vf=()=>new fc,_f=(n,e)=>n.l.push(e),Uf=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Qf=(n,e,t)=>oi(n.l,[e,t]),Mt=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Mt(n,e),Vf=(n,e)=>{x(n,e.client),x(n,e.clock)},Bf=n=>M(C(n),C(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},zw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},uc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||br(),At(new An(H(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>At(new An(H(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;it(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Tt(r,e))return t;return null}},ot=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Fw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new ot(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),Ks=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},qw=(n,e,t=0)=>new Ks(n,e,t),qs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return qs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return qs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return qs(n,r.lastId,t);r=r.right}return qs(n,null,t)},Hw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Vf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Vf(n,t);else throw j();return ni(n,s),n},Jw=n=>{let e=q();return Hw(e,n),I(e)},$w=n=>{let e=null,t=null,r=null;switch(C(n)){case 0:r=Bf(n);break;case 1:t=Le(n);break;case 2:e=Bf(n)}let i=Hl(n)?ii(n):0;return new ot(e,t,r,i)},Ww=n=>$w(H(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?wc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?wc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return qw(c,a,n.assoc)},io=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,jt=class{constructor(e,t){this.ds=e,this.sv=t}},jw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Tc(e,n.sv),e.toUint8Array()),Kw=n=>Zf(n,new Wt),eu=(n,e=new js(H(n)))=>new jt(At(e),Xf(e)),Yw=n=>eu(n,new An(H(n))),Mi=(n,e)=>new jt(n,e),Gw=Mi(br(),new Map),Ai=n=>Mi(Sc(n.store),Ei(n.store)),qt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Tt(e.ds,n.id),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Xw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(H(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Qw(n,e,Me),Ys=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ei=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},tu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=e1,mc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[mc(n,t,e.clock)]},Pf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,ro(n,s,t.clock-s.id.clock+1)),s},t1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},nu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=mc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Bd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Uw(n,e),it(n,e.deleteSet),!0),zf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},$s=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},ru=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+$s(i,c)}})},n1=(n,e,t)=>{ru(n,e,t),iu(n,e)},su=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Qf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),oi(l,[]),t._needFormattingCleanup&&C1(t)}finally{r.gc&&ru(s,i,r.gcFilter),iu(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+$s(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&$s(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(zs(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Yf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;Lf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Lf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):su(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Gs(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&su(i,0)}}return o},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Ff=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Uc(r,!1)})},qf=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;rt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Ru(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new $t;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&mi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new gc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),rt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&Uc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=Zr(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&ac("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>Ff(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Ff(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=qf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=qf(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*r1(n){let e=C(n.restDecoder);for(let t=0;tou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);zs("Structs: ",t);let s=At(r);zs("DeleteSet: ",s)},s1=n=>lu(n,Me),lu=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},cu=n=>yi(n,Me,st),au=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(H(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=q();return x(h,o),Gd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},o1=n=>au(n,Wt,Me),hu=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(H(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},l1=n=>hu(n,Me),c1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},yi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(H(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new gi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=c1(f,p)),s.struct.mergeWith(f)||(Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Ht(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ht(l,s.struct,s.offset),s=null),Ic(l);let c=r.map(h=>At(h)),a=Mn(c);return it(o,a),o.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Ec(e),s=new r,o=new gi(s),l=new t(H(n)),c=new lt(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Ht(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(o);let a=At(l);return it(s,a),s.toUint8Array()},a1=(n,e)=>Nc(n,e,Me,st),du=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=q(),n.written=0)},Ht=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&du(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Ic=n=>{du(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(H(n)),s=new lt(i,!1),o=new r,l=new gi(o);for(let a=s.curr;a!==null;a=s.next())Ht(l,e(a),0);Ic(l);let c=At(i);return it(o,c),o.toUint8Array()},fu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Et:{let d=h;d.embed={};break}case P:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case ki:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=$d(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},h1=(n,e)=>so(n,fu(e),Me,st),d1=(n,e)=>so(n,fu(e),be,Ie),f1=n=>so(n,ec,Me,Ie),uu=n=>so(n,ec,be,st),Hf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=u1(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(Hf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Ts(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ts(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Ts(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(Hf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},u1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},pu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},p1=n=>{n.timestamp=Rc++},mu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},m1=(n,e,t)=>{if(n.length>=pu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>nr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&nr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},g1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},lo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Qf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=vf(),this._dEH=vf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){_f(this._eH,e)}observeDeep(e){_f(this._dEH,e)}unobserve(e){Uf(this._eH,e)}unobserveDeep(e){Uf(this._dEH,e)}toJSON(){}},gu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},yu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&qt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},y1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},bu=(n,e)=>{n.doc??se();let t=oo(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Kt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},xu=()=>Ze("Length exceeded!"),Su=(n,e,t,r)=>{if(t>e._length)throw xu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Xs(n,e,null,r);let i=t,s=oo(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Xs(n,e,i,t)},ku=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=oo(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw xu();e._searchMarker&&wi(e._searchMarker,i,-s+r)},Qs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Kt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Kt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Cu=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Mu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},b1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&qt(r,t)?r.content.getContent()[r.length-1]:void 0},Au=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&qt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Hs=n=>(n.doc??se(),Of(n._map.entries(),e=>!e[1].deleted)),Zs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),lo(this,e,new Zs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{w1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return bu(this,e)}toArray(){return yu(this)}slice(e=0,t=this.length){return gu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return wu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return y1(this)}_write(e){e.writeTypeRef(z1)}},x1=n=>new On,eo=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){lo(this,e,new eo(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...Hs(this)].length}keys(){return Fs(Hs(this),e=>e[0])}values(){return Fs(Hs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Fs(Hs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Mu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Qs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(F1)}},S1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(n,e),xi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case P:this.right.deleted||xr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Jf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?oo(e,t):null;if(s){let o=new xi(s.p.left,s.p,s.index,i);return Jf(n,o,t-s.index)}else{let o=new xi(null,e._start,0,i);return Jf(n,o,t)}},Eu=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Jt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},xr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Tu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Jt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Du=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Et(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Eu(n,e,t,l)},$f=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Jt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` +`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Eu(n,e,t,l)},Ou=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&xr(i,a);break}}}e=e.right}return l},k1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Nu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=Es(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:xr(o,i.content);break;default:e+=Ou(t,r,i,s,o),s=Es(o),r=i;break}i=i.right}}),e},C1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&nu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):k1(r,i)});for(let i of e)Nu(i)})},Wf=(n,e,t)=>{let r=t,i=Es(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Et:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},ff(c)||(u.attributes=af({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Et:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Jt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Jt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),xr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ct=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new to(this,e,t);lo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new xi(null,this._start,0,new Map);for(let s=0;s0)&&hc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?$f(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wf(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(qt(c,e)||t!==void 0&&qt(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!qt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case P:qt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!r);hc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{Wf(i,Js(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!1);o.right!==null&&$f(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Cu(this)}_write(e){e.writeTypeRef(q1)}},M1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===at)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},at=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){lo(this,e,new no(this,t,e))}toString(){return wu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),bi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Xs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw Ze("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return yu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return bu(this,e)}slice(e=0,t=this.length){return gu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(J1)}},A1=n=>new at,Z=class n extends at{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return hf(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Mu(this,e)}getAttributes(e){return e?Au(this,e):Cu(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return bi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(H1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),no=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},Si=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef($1),e.writeKey(this.hookName)}},T1=n=>new Si(n.readKey()),xe=class n extends ct{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(W1)}},D1=n=>new xe,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},O1=0,ue=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),tu(e.doc.store,this)}write(e,t){e.writeInfo(O1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},N1=n=>new In(n.readBuf()),wr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},I1=n=>new wr(n.readLen()),Iu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Iu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},R1=n=>new Rn(Iu(n.readString(),n.readAny())),Et=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},v1=n=>new Et(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},_1=n=>new P(n.readKey(),n.readJSON()),ki=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},P1=n=>new Re(n.readString()),L1=[x1,S1,M1,E1,A1,T1,D1],z1=0,F1=1,q1=2,H1=3,J1=4,$1=5,W1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},j1=n=>new Ae(L1[n.readTypeRef()](n)),wc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ro=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},jf=(n,e)=>Ld(n,t=>Tt(t.deletions,e)),Ru=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Ru(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Tt(r,d.right.id)||jf(s.undoStack,d.right.id)||jf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Pf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Pf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mi(e.deleteSet,this.id.client,this.id.clock,this.length),zf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?t1(e,this,new ue(this.id,this.length)):this.content=new wr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Mt?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},vu=(n,e)=>K1[e&31](n),K1=[()=>{j()},I1,U1,N1,P1,v1,_1,j1,B1,R1,()=>{j()}],Y1=10,ie=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(Y1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},_u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Uu="__ $YJS$ __";_u[Uu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");_u[Uu]=!0;var Vu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:bf(t.newValue||"")}),sf(this._onChange)}postMessage(e){Vs.setItem(this.room,wf(yf(e)))}close(){of(this._onChange)}},G1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Vu,n,()=>{let e=Ce(),t=new G1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Bu=(n,e)=>(Bc(n).subs.add(e),e),Pu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Vu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Lu=0,ao=1,zu=2,ho=(n,e)=>{x(n,Lu);let t=Dc(e);U(n,t)},Pc=(n,e,t)=>{x(n,ao),U(n,Ac(e,t))},Q1=(n,e,t)=>Pc(e,t,K(n)),Fu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},qu=(n,e)=>{x(n,zu),U(n,e)},Z1=Fu,Hu=(n,e,t,r)=>{let i=C(n);switch(i){case Lu:Q1(n,e,t);break;case ao:Fu(n,t,r);break;case zu:Z1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var tb=0;var Ju=(n,e,t)=>{switch(C(n)){case tb:t(e,Le(n))}};var Lc=3e4,fo=class extends tr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&uo(this,r,"timeout")},fe(Lc/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),ur(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},uo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},kr=(n,e,t=n.states)=>{let r=e.length,i=q();x(i,r);for(let s=0;s{let r=H(e),i=Ne(),s=[],o=[],l=[],c=[],a=C(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var Wu=n=>df(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Ku=3,Cr=1,sb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=Hu(e,n,t.doc,t);r&&s===ao&&!t.synced&&(t.synced=!0)};Ti[Ku]=(n,e,t,r,i)=>{x(n,Cr),U(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{$u(t.awareness,K(e),t)};Ti[sb]=(n,e,t,r,i)=>{Ju(e,t.doc,(s,o)=>ob(t,o))};var ju=3e4,ob=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Yu=(n,e,t)=>{let r=H(e),i=q(),s=C(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Gu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Yu(n,new Uint8Array(t.data),!0);Is(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,uo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Gu,De(Fd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=q();if(x(t,Bn),ho(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=q();x(r,Cr),U(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:s=new fo(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ti.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=q();x(f,Bn),ho(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Yu(this,new Uint8Array(f),!1);Is(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=q();x(p,Bn),qu(p,f),zc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=q();x(y,Cr),U(y,kr(s,g)),zc(this,I(y))},this._exitHandler=()=>{uo(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&ju{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var lb=/[\uD800-\uDBFF]/,cb=/[\uDC00-\uDFFF]/,ab=(n,e)=>{let t=0,r=0;for(;t0&&lb.test(n[t-1])&&t--;r+t0&&cb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Qu=ab;var v=new le("y-sync"),Dt=new le("y-undo"),Di=new le("yjs-cursor");var Ni=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Tt(e.ds,n.id),hb=[{light:"#ecd44433",dark:"#ecd444"}],db=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,ef(e))}return n.get(t)},tp=(n,{colors:e=hb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new po(n,s),c=new L({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ai(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Dt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},fb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Yt(t.doc,t.type,e.anchor,t.mapping),i=Yt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ii=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),po=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Xu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(pr&&this._domSelectionInView===null&&(ai(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Mi(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Oi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Oi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ai(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ai(i),vn(i,e),e=Ai(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{rt(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:db(r.colorMapping,r.colors,f)}},c=co(this.type,new jt(t.ds,e.sv)).map(h=>!h._item.deleted||Ni(h._item,e)||Ni(h._item,t)?Oi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);rt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>np(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));fb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Mr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},np=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,s);throw Oe()}return o},Oi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=np(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof ct&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=ub(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):co(n,new jt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ni(n._item,r)?Ni(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},ub=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},pb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:ip(i.marks)}));return t.applyDelta(r),e.set(t,n),t},mb=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,go(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?pb(n,e):mb(n,e),Zu=n=>typeof n=="object"&&n!==null,Jc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Bs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>Jc(r.attributes[s.type.name]||{},s.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=go(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&rp(n,e)},mo=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),ep=(n,e,t)=>{let r=n.toArray(),i=go(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},yb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=gb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,ip(a.marks))})),{insert:o,remove:l,index:c}=Qu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},ip=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Mr=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=go(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)rp(f,u)||yb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let E=ep(f,u,r),N=ep(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var vi=null,wb=()=>{let n=vi;vi=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,wb)),$(vi,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Ci(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Ci(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return bb(r._item.parent,r._item)}return Ci(e,e._length,-1)},bb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Oc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function op(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var xb=(n,e,t)=>n!==e,Sb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},kb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Cb=/^#[0-9a-fA-F]{6}$/,lp=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Cb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Yt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),z.create(n.doc,l))},Mb=(n,{awarenessStateFilter:e=xb,cursorBuilder:t=Sb,selectionBuilder:r=kb,getSelection:i=o=>o.selection}={},s="cursor")=>new L({key:Di,state:{init(o,l){return lp(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?lp(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Di.getState(o)},view:o=>{let l=()=>{o.docView&&$c(o,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!io(Un(h.cursor.anchor),f)||!io(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Ab=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Tb=new Set(["paragraph"]),Db=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof ct||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Ob=({protectedNodes:n=Tb,trackedOrigins:e=[],undoManager:t=null}={})=>new L({key:Dt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Db(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Dt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Dt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var _i="http://www.w3.org/2000/svg",Nb="http://www.w3.org/1999/xlink",Yc="ProseMirror-icon",Kc="pm-close-dropdowns";function Ib(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,cp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;cp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function yo(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function _b(n){Ui.time=Date.now(),Ui.node=n.target}function Ub(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Kc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),_b(d),o?a():(r.dispatchEvent(new CustomEvent(Kc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Ub(s)||a()}),r.addEventListener(Kc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function Vb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Fk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),qk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Hk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Jk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Lb(n,e){let t={run(r,i){return Xn(n,e.attrs)(r,i)},select(r){return Xn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new ht(t)}function zb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function cp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Gc as Dropdown,Po as EditorState,ll as EditorView,w as Fragment,bt as InputRule,ht as MenuItem,k as NodeSelection,L as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Fc as WebsocketProvider,Sr as Y,n0 as addColumnAfter,t0 as addColumnBefore,hy as addListNodes,l0 as addRowAfter,o0 as addRowBefore,cd as baseKeymap,Lg as baseSchema,zb as blockTypeItem,Py as buildKeymap,T0 as columnResizing,i0 as deleteColumn,a0 as deleteRow,y0 as deleteTable,Ey as dropCursor,Id as fixTables,Oy as gapCursor,g0 as goToNextCell,pd as inputRules,He as isInTable,by as keymap,xl as liftListItem,d0 as mergeCells,sp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Bb as renderGrouped,Je as selectedRect,pn as setBlockType,Sl as sinkListItem,f0 as splitCell,bl as splitListItem,P0 as tableEditing,Hy as tableNodes,mn as toggleMark,Xn as wrapIn,ps as wrapInList,Lb as wrapItem,Mb as yCursorPlugin,op as yDocToProsemirrorJSON,Eb as yRedo,tp as ySyncPlugin,Ab as yUndo,Ob as yUndoPlugin,Dt as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index b5d88189..a3e71b97 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -8,6 +8,7 @@ import { addListNodes, wrapInList, splitListItem, liftListItem, sinkListItem } f import { keymap } from 'prosemirror-keymap'; import { buildKeymap } from 'prosemirror-example-setup'; import { gapCursor } from 'prosemirror-gapcursor'; +import { dropCursor } from 'prosemirror-dropcursor'; import { tableEditing, @@ -84,6 +85,7 @@ export { splitCell, deleteTable, gapCursor, + dropCursor, MenuItem, Dropdown, renderGrouped, diff --git a/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js b/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js new file mode 100644 index 00000000..077b7fbe --- /dev/null +++ b/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js @@ -0,0 +1,201 @@ +import { expect } from '@esm-bundle/chai'; +import sinon from 'sinon'; + +describe('tableDragHandle Plugin', () => { + let tableDragHandle; + let plugin; + + before(async () => { + const mod = await import('../../../../../../blocks/edit/prose/plugins/tableDragHandle.js'); + tableDragHandle = mod.default; + }); + + beforeEach(() => { + plugin = tableDragHandle(); + }); + + describe('Drop handler', () => { + it('allows file drops to pass through (returns false)', () => { + const mockView = {}; + const mockEvent = { dataTransfer: { files: [{ name: 'image.png' }] } }; + + const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); + expect(result).to.be.false; + }); + + it('allows table drops (returns false)', () => { + const mockView = { dragging: { slice: { content: { firstChild: { type: { name: 'table' } } } } } }; + const mockEvent = { dataTransfer: { files: [] } }; + + const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); + expect(result).to.be.false; + }); + + it('blocks non-table internal drops (returns true)', () => { + const mockView = { dragging: { slice: { content: { firstChild: { type: { name: 'paragraph' } } } } } }; + const mockEvent = { dataTransfer: { files: [] } }; + + const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); + expect(result).to.be.true; + }); + + it('blocks drops with no dragging context (returns true)', () => { + const mockView = { dragging: null }; + const mockEvent = { dataTransfer: { files: [] } }; + + const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); + expect(result).to.be.true; + }); + + it('handles empty slice content gracefully', () => { + const mockView = { dragging: { slice: { content: { firstChild: null } } } }; + const mockEvent = { dataTransfer: { files: [] } }; + + const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); + expect(result).to.be.true; + }); + }); + + describe('View initialization', () => { + let mockEditorView; + let container; + + beforeEach(() => { + container = document.createElement('div'); + const editorDom = document.createElement('div'); + editorDom.className = 'ProseMirror'; + container.appendChild(editorDom); + document.body.appendChild(container); + + mockEditorView = { + dom: editorDom, + state: { + doc: { + resolve: () => ({ + depth: 1, + node: () => ({ type: { name: 'table' } }), + before: () => 0, + }), + }, + tr: { setSelection: sinon.stub().returnsThis() }, + selection: { content: () => ({ content: {} }) }, + }, + dispatch: sinon.stub(), + posAtDOM: () => 0, + }; + }); + + afterEach(() => { + container.remove(); + }); + + it('creates and appends drag handle element', () => { + const viewReturn = plugin.spec.view(mockEditorView); + + const handle = container.querySelector('.table-drag-handle'); + expect(handle).to.exist; + expect(handle.draggable).to.be.true; + expect(handle.classList.contains('is-visible')).to.be.false; + + viewReturn.destroy(); + }); + + it('removes handle on destroy', () => { + const viewReturn = plugin.spec.view(mockEditorView); + + let handle = container.querySelector('.table-drag-handle'); + expect(handle).to.exist; + + viewReturn.destroy(); + + handle = container.querySelector('.table-drag-handle'); + expect(handle).to.be.null; + }); + }); + + describe('Mouse events', () => { + let mockEditorView; + let container; + let editorDom; + + beforeEach(() => { + container = document.createElement('div'); + editorDom = document.createElement('div'); + editorDom.className = 'ProseMirror'; + container.appendChild(editorDom); + document.body.appendChild(container); + + mockEditorView = { + dom: editorDom, + state: { + doc: { + resolve: () => ({ + depth: 1, + node: () => ({ type: { name: 'table' } }), + before: () => 0, + }), + }, + tr: { setSelection: sinon.stub().returnsThis() }, + selection: { content: () => ({ content: {} }) }, + }, + dispatch: sinon.stub(), + posAtDOM: () => 0, + }; + }); + + afterEach(() => { + container.remove(); + }); + + it('shows handle on mouseover of tableWrapper', () => { + const viewReturn = plugin.spec.view(mockEditorView); + + const tableWrapper = document.createElement('div'); + tableWrapper.className = 'tableWrapper'; + const table = document.createElement('table'); + tableWrapper.appendChild(table); + editorDom.appendChild(tableWrapper); + + const event = new MouseEvent('mouseover', { + bubbles: true, + target: tableWrapper, + }); + Object.defineProperty(event, 'target', { value: tableWrapper }); + editorDom.dispatchEvent(event); + + const handle = container.querySelector('.table-drag-handle'); + expect(handle.classList.contains('is-visible')).to.be.true; + + viewReturn.destroy(); + }); + + it('hides handle on dragend', () => { + const viewReturn = plugin.spec.view(mockEditorView); + + const tableWrapper = document.createElement('div'); + tableWrapper.className = 'tableWrapper'; + const table = document.createElement('table'); + tableWrapper.appendChild(table); + editorDom.appendChild(tableWrapper); + + // Show the handle first + const mouseoverEvent = new MouseEvent('mouseover', { + bubbles: true, + target: tableWrapper, + }); + Object.defineProperty(mouseoverEvent, 'target', { value: tableWrapper }); + editorDom.dispatchEvent(mouseoverEvent); + + const handle = container.querySelector('.table-drag-handle'); + expect(handle.classList.contains('is-visible')).to.be.true; + + // Trigger dragend + const dragendEvent = new Event('dragend', { bubbles: true }); + handle.dispatchEvent(dragendEvent); + + expect(handle.classList.contains('is-visible')).to.be.false; + + viewReturn.destroy(); + }); + }); +}); From 401424f4b697fc4038f6c42b5a3d0cc7ec35e73b Mon Sep 17 00:00:00 2001 From: Usman Khalid Date: Tue, 10 Feb 2026 22:08:21 -0500 Subject: [PATCH 2/3] chore: remove drag&drop functionality --- blocks/edit/da-editor/da-editor.css | 6 +- blocks/edit/prose/index.js | 2 - blocks/edit/prose/plugins/imageDrop.js | 4 +- blocks/edit/prose/plugins/tableDragHandle.js | 55 +-- blocks/edit/prose/schema.js | 373 ------------------ deps/da-y-wrapper/dist/index.js | 26 +- deps/da-y-wrapper/src/index.js | 2 - .../prose/plugins/tableDragHandle.test.js | 74 +--- 8 files changed, 26 insertions(+), 516 deletions(-) delete mode 100644 blocks/edit/prose/schema.js diff --git a/blocks/edit/da-editor/da-editor.css b/blocks/edit/da-editor/da-editor.css index 13c5187b..1c63b90a 100644 --- a/blocks/edit/da-editor/da-editor.css +++ b/blocks/edit/da-editor/da-editor.css @@ -994,7 +994,7 @@ da-diff-deleted, da-diff-added { border: 1px solid #ccc; border-radius: 4px; z-index: 100; - cursor: grab; + cursor: pointer; display: none; align-items: center; justify-content: center; @@ -1008,7 +1008,3 @@ da-diff-deleted, da-diff-added { background-color: #f0f7ff; border-color: var(--s2-blue-800); } - -.table-drag-handle:active { - cursor: grabbing; -} diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js index f8780e46..7c22cd7f 100644 --- a/blocks/edit/prose/index.js +++ b/blocks/edit/prose/index.js @@ -11,7 +11,6 @@ import { liftListItem, sinkListItem, gapCursor, - dropCursor, TextSelection, NodeSelection, Plugin, @@ -383,7 +382,6 @@ export default function initProse({ path, permissions }) { 'Shift-Tab': liftListItem(schema.nodes.list_item), }), gapCursor(), - dropCursor({ color: 'var(--s2-blue-800)', width: 2 }), tableEditing({ allowTableNodeSelection: true }), ]; diff --git a/blocks/edit/prose/plugins/imageDrop.js b/blocks/edit/prose/plugins/imageDrop.js index fdbd51a6..5bb24b6e 100644 --- a/blocks/edit/prose/plugins/imageDrop.js +++ b/blocks/edit/prose/plugins/imageDrop.js @@ -11,11 +11,11 @@ export default function imageDrop(schema) { props: { handleDOMEvents: { drop: (view, event) => { + event.preventDefault(); + const { files } = event.dataTransfer; if (files.length === 0) return; - event.preventDefault(); - ([...files]).forEach(async (file) => { if (!SUPPORTED_FILES.some((type) => type === file.type)) return; diff --git a/blocks/edit/prose/plugins/tableDragHandle.js b/blocks/edit/prose/plugins/tableDragHandle.js index 3f31c5f0..1dc3d2b9 100644 --- a/blocks/edit/prose/plugins/tableDragHandle.js +++ b/blocks/edit/prose/plugins/tableDragHandle.js @@ -20,7 +20,7 @@ function getTablePos(view, tableEl) { } /** - * Allows dragging and easier copy/pasting of entire blocks/tables. + * Allows selecting an entire table by clicking an icon in the top left corner. */ export default function tableDragHandle() { let handle = null; @@ -46,7 +46,6 @@ export default function tableDragHandle() { function createHandle(view) { const el = document.createElement('div'); el.className = 'table-drag-handle'; - el.draggable = true; el.contentEditable = 'false'; el.addEventListener('mousedown', (e) => { @@ -54,6 +53,7 @@ export default function tableDragHandle() { return; } + e.preventDefault(); e.stopPropagation(); const tablePos = getTablePos(view, currentTable); @@ -61,32 +61,10 @@ export default function tableDragHandle() { if (tablePos !== null) { const sel = NodeSelection.create(view.state.doc, tablePos); view.dispatch(view.state.tr.setSelection(sel)); + view.focus(); } }); - el.addEventListener('dragstart', (e) => { - if (!currentTable) { - e.preventDefault(); - return; - } - - const tablePos = getTablePos(view, currentTable); - - if (tablePos === null) { - e.preventDefault(); - return; - } - - let { state } = view; - const sel = NodeSelection.create(state.doc, tablePos); - view.dispatch(state.tr.setSelection(sel)); - state = view.state; - - const slice = state.selection.content(); - view.dragging = { slice, move: true }; - e.dataTransfer.effectAllowed = 'move'; - }); - el.addEventListener('mouseleave', (e) => { if (e.relatedTarget && currentWrapper?.contains(e.relatedTarget)) { return; @@ -95,32 +73,10 @@ export default function tableDragHandle() { hideHandle(); }); - el.addEventListener('dragend', () => { - hideHandle(); - }); - return el; } return new Plugin({ - props: { - handleDOMEvents: { - drop(view, event) { - const isFileDrop = event.dataTransfer.files.length > 0; - if (isFileDrop) { - // let imageDrop handle it. - return false; - } - - if (!view.dragging) { - return true; - } - - const isTableDrag = view.dragging.slice.content.firstChild?.type.name === 'table'; - return !isTableDrag; - }, - }, - }, view(editorView) { handle = createHandle(editorView); const container = editorView.dom.parentElement; @@ -162,6 +118,11 @@ export default function tableDragHandle() { editorView.dom.addEventListener('mouseout', onMouseOut); return { + update() { + if (currentWrapper && !currentWrapper.isConnected) { + hideHandle(); + } + }, destroy() { editorView.dom.removeEventListener('mouseover', onMouseOver); editorView.dom.removeEventListener('mouseout', onMouseOut); diff --git a/blocks/edit/prose/schema.js b/blocks/edit/prose/schema.js deleted file mode 100644 index 675ab11a..00000000 --- a/blocks/edit/prose/schema.js +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright 2024 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -/* - * IMPORTANT: - * Until getSchema() is separated into its own module, - * these files need to be kept in-sync: - * - * da-live /blocks/edit/prose/schema.js - * da-collab /src/schema.js - * - * Note that the import locations are different between the two files - * but otherwise the files should be identical. - */ - -import { addListNodes, Schema, tableNodes } from 'da-y-wrapper'; - -function parseLocDOM(locTag) { - return [ - { - tag: locTag, - contentElement: (dom) => dom, - }, - ]; -} - -const topLevelAttrs = { - dataId: { default: null, validate: 'string|null' }, - daDiffAdded: { default: null, validate: 'string|null' }, -}; - -const getTopLevelToDomAttrs = (node) => { - const attrs = {}; - if (node.attrs.dataId != null) attrs['data-id'] = node.attrs.dataId; - if (node.attrs.daDiffAdded === '') attrs['da-diff-added'] = ''; - return attrs; -}; - -const getTopLevelParseAttrs = (dom) => ({ - dataId: dom.getAttribute('dataId') ?? null, - daDiffAdded: dom.getAttribute('da-diff-added') ?? null, -}); - -const getHeadingAttrs = (level) => (dom) => ({ - level, - ...getTopLevelParseAttrs(dom), -}); - -/* Base nodes taken from prosemirror-schema-basic */ -const baseNodes = { - doc: { content: 'block+' }, - paragraph: { - attrs: { ...topLevelAttrs }, - content: 'inline*', - group: 'block', - parseDOM: [{ tag: 'p', getAttrs: getTopLevelParseAttrs }], - toDOM(node) { - return ['p', { ...getTopLevelToDomAttrs(node) }, 0]; - }, - }, - blockquote: { - attrs: { ...topLevelAttrs }, - content: 'block+', - group: 'block', - defining: true, - parseDOM: [{ tag: 'blockquote', getAttrs: getTopLevelParseAttrs }], - toDOM(node) { - return ['blockquote', { ...getTopLevelToDomAttrs(node) }, 0]; - }, - }, - horizontal_rule: { - group: 'block', - parseDOM: [{ tag: 'hr' }], - toDOM() { - return ['hr']; - }, - }, - heading: { - attrs: { - level: { default: 1 }, - ...topLevelAttrs, - }, - content: 'inline*', - group: 'block', - defining: true, - parseDOM: [ - { tag: 'h1', getAttrs: getHeadingAttrs(1) }, - { tag: 'h2', getAttrs: getHeadingAttrs(2) }, - { tag: 'h3', getAttrs: getHeadingAttrs(3) }, - { tag: 'h4', getAttrs: getHeadingAttrs(4) }, - { tag: 'h5', getAttrs: getHeadingAttrs(5) }, - { tag: 'h6', getAttrs: getHeadingAttrs(6) }, - ], - toDOM(node) { - return [`h${node.attrs.level}`, { ...getTopLevelToDomAttrs(node) }, 0]; - }, - }, - code_block: { - attrs: { ...topLevelAttrs }, - content: 'text*', - marks: '', - group: 'block', - code: true, - defining: true, - parseDOM: [{ tag: 'pre', preserveWhitespace: 'full', getAttrs: getTopLevelParseAttrs }], - toDOM(node) { - return ['pre', { ...getTopLevelToDomAttrs(node) }, ['code', 0]]; - }, - }, - text: { group: 'inline' }, - // due to bug in y-prosemirror, add href to image node - // which will be converted to a wrapping tag - image: { - inline: true, - attrs: { - src: { validate: 'string' }, - alt: { default: null, validate: 'string|null' }, - title: { default: null, validate: 'string|null' }, - href: { default: null, validate: 'string|null' }, - dataFocalX: { default: null, validate: 'string|null' }, - dataFocalY: { default: null, validate: 'string|null' }, - ...topLevelAttrs, - }, - group: 'inline', - draggable: true, - parseDOM: [ - { - tag: 'img[src]', - getAttrs(dom) { - const attrs = { - src: dom.getAttribute('src'), - alt: dom.getAttribute('alt'), - href: dom.getAttribute('href'), - dataFocalX: dom.getAttribute('data-focal-x'), - dataFocalY: dom.getAttribute('data-focal-y'), - ...getTopLevelParseAttrs(dom), - }; - const title = dom.getAttribute('title'); - // TODO: Remove this once helix properly supports data-focal-x and data-focal-y - if (!title?.includes('data-focal:')) { - attrs.title = title; - } - return attrs; - }, - }, - ], - toDOM(node) { - const { - src, alt, title, href, dataFocalX, dataFocalY, - } = node.attrs; - const attrs = { - src, - alt, - title, - href, - ...getTopLevelToDomAttrs(node), - }; - if (dataFocalX != null) attrs['data-focal-x'] = dataFocalX; - if (dataFocalY != null) attrs['data-focal-y'] = dataFocalY; - // TODO: This is temp code to store the focal data in the title attribute - // Once helix properly supports data-focal-x and data-focal-y, we can remove this code - if (dataFocalX != null) attrs.title = `data-focal:${dataFocalX},${dataFocalY}`; - return ['img', attrs]; - }, - }, - hard_break: { - inline: true, - group: 'inline', - selectable: false, - parseDOM: [{ tag: 'br' }], - toDOM() { - return ['br']; - }, - }, - loc_added: { - group: 'block', - content: 'block+', - atom: true, - isolating: true, - parseDOM: parseLocDOM('da-loc-added'), - toDOM: () => ['da-loc-added', { contenteditable: false }, 0], - }, - diff_added: { - group: 'block', - content: 'block+', - atom: true, - isolating: true, - parseDOM: [ - { - tag: 'da-diff-added', - contentElement: (dom) => { - [...dom.children].forEach((child) => { - if (child.properties) { - // eslint-disable-next-line no-param-reassign - child.properties['da-diff-added'] = ''; - } - }); - return dom; - }, - }, - { - tag: 'da-loc-added', // Temp code to support old regional edits - contentElement: (dom) => { - [...dom.children].forEach((child) => { - if (child.properties) { - // eslint-disable-next-line no-param-reassign - child.properties['da-diff-added'] = ''; - } - }); - return dom; - }, - }, - ], - toDOM: () => ['da-diff-added', { contenteditable: false }, 0], - }, - loc_deleted: { - group: 'block', - content: 'block+', - atom: true, - isolating: true, - parseDOM: parseLocDOM('da-loc-deleted'), - toDOM: () => ['da-loc-deleted', { contenteditable: false }, 0], - }, - diff_deleted: { - group: 'block', - content: 'block+', - atom: true, - isolating: true, - parseDOM: [ - { - tag: 'da-diff-deleted', - contentElement: (dom) => dom, - }, - { - tag: 'da-loc-deleted', // Temp code to support old regional edits - contentElement: (dom) => dom, - }, - ], - toDOM: () => ['da-diff-deleted', { 'data-mdast': 'ignore', contenteditable: false }, 0], - }, -}; - -const baseMarks = { - s: { - parseDOM: [{ tag: 's' }], - toDOM() { - return ['s', 0]; - }, - }, - em: { - parseDOM: [{ tag: 'i' }, { tag: 'em' }, { style: 'font-style=italic' }, { style: 'font-style=normal', clearMark: (m) => m.type.name === 'em' }], - toDOM() { - return ['em', 0]; - }, - }, - strong: { - parseDOM: [ - { tag: 'strong' }, - // This works around a Google Docs misbehavior where - // pasted content will be inexplicably wrapped in `` - // tags with a font-weight normal. - { tag: 'b', getAttrs: (node) => node.style.fontWeight !== 'normal' && null }, - { style: 'font-weight=400', clearMark: (m) => m.type.name === 'strong' }, - { style: 'font-weight', getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null }, - ], - toDOM() { - return ['strong', 0]; - }, - }, - link: { - attrs: { - href: {}, - title: { default: null }, - ...topLevelAttrs, - }, - inclusive: false, - parseDOM: [ - { - tag: 'a[href]', - getAttrs(dom) { - return { href: dom.getAttribute('href'), title: dom.getAttribute('title'), ...getTopLevelParseAttrs(dom) }; - }, - }, - ], - toDOM(node) { - const { href, title } = node.attrs; - return ['a', { href, title, ...getTopLevelToDomAttrs(node) }, 0]; - }, - }, - code: { - parseDOM: [{ tag: 'code' }], - toDOM() { - return ['code', 0]; - }, - }, - u: { - parseDOM: [{ tag: 'u' }], - toDOM() { - return ['u', 0]; - }, - }, -}; - -const baseSchema = new Schema({ nodes: baseNodes, marks: baseMarks }); - -function addCustomMarks(marks) { - const sup = { - parseDOM: [{ tag: 'sup' }, { clearMark: (m) => m.type.name === 'sup' }], - toDOM() { - return ['sup', 0]; - }, - }; - - const sub = { - parseDOM: [{ tag: 'sub' }, { clearMark: (m) => m.type.name === 'sub' }], - toDOM() { - return ['sub', 0]; - }, - }; - - const contextHighlight = { toDOM: () => ['span', { class: 'highlighted-context' }, 0] }; - - return marks.addToEnd('sub', sub).addToEnd('sup', sup).addToEnd('contextHighlightingMark', contextHighlight); -} - -function getTableNodeSchema() { - const schema = tableNodes({ tableGroup: 'block', cellContent: 'block+' }); - schema.table.attrs = { ...topLevelAttrs }; - schema.table.parseDOM = [{ tag: 'table', getAttrs: getTopLevelParseAttrs }]; - schema.table.toDOM = (node) => ['table', node.attrs, ['tbody', 0]]; - schema.table.draggable = true; - return schema; -} - -function addAttrsToListNode(_nodes, listType, tag) { - const nodes = _nodes; - nodes.get(listType).attrs = { ...topLevelAttrs }; - nodes.get(listType).parseDOM = [{ tag, getAttrs: getTopLevelParseAttrs }]; - nodes.get(listType).toDOM = (node) => [tag, { ...getTopLevelToDomAttrs(node) }, 0]; -} - -function addListNodeSchema(nodes) { - const withListNodes = addListNodes(nodes, 'block+', 'block'); - addAttrsToListNode(withListNodes, 'bullet_list', 'ul'); - addAttrsToListNode(withListNodes, 'ordered_list', 'ol'); - return withListNodes; -} - -// eslint-disable-next-line import/prefer-default-export -export function getSchema() { - let { nodes } = baseSchema.spec; - const { marks } = baseSchema.spec; - nodes = addListNodeSchema(nodes); - - // Update diff nodes to allow list_item after list nodes are added - nodes = nodes.update('diff_deleted', { ...nodes.get('diff_deleted'), content: '(block | list_item)+' }); - nodes = nodes.update('diff_added', { ...nodes.get('diff_added'), content: '(block | list_item)+' }); - nodes = nodes.update('loc_deleted', { ...nodes.get('loc_deleted'), content: '(block | list_item)+' }); - nodes = nodes.update('loc_added', { ...nodes.get('loc_added'), content: '(block | list_item)+' }); - - nodes = nodes.append(getTableNodeSchema()); - const customMarks = addCustomMarks(marks); - return new Schema({ nodes, marks: customMarks }); -} diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index dfd129ad..9d1b4d73 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,15 @@ -var dp=Object.defineProperty;var fp=(n,e)=>{for(var t in e)dp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var wo=oe;function oa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=oa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function la(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Pi(r+1,o):Pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=aa(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ca(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function ca(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(ca(s.content,e-i-1,t-i-1)))}function aa(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=aa(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function up(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ha(n,e,t,0)}function ha(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&So(n,e,i+1),o=r.depth>i&&So(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(da(s,o),Gt(Xt(s,fa(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Fi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=So(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function pp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Xc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ua(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var Co=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ua(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ua(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Mo(e,t);if(r.next==null)return n.empty;let i=pa(r);r.next&&r.err("Unexpected trailing text");let s=Cp(kp(i));return Mp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` -`)}};en.empty=new en(!0);var Mo=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function pa(n){let e=[];do e.push(yp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function yp(n){let e=[];do e.push(wp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function wp(n){let e=Sp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=bp(n,e);else break;return e}function Qc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function bp(n,e){let t=Qc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Qc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function xp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Sp(n){if(n.eat("(")){let e=pa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=xp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function kp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ya(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Ap(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Ao=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Ap(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ba(e,i.attrs),this.excluded=null;let s=ga(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ya(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=wo.from(e.nodes),t.marks=wo.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?ea(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:ea(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Co(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ea(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ep(n){return n.tag!=null}function Tp(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ep(i))this.tags.push(i);else if(Tp(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=na(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=na(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},xa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Dp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Sa={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function ta(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!xa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ta(null,t.preserveWhitespace,0)|(r?Er:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;Sa.hasOwnProperty(i)&&this.parser.normalizeLists&&Op(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Dp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(xa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ra(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Op(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Sa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Np(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function na(n){let e={};for(let t in n)e[t]=n[t];return e}function ra(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(xo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ia(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ia(e.marks)}};function ia(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function xo(n){return n.document||window.document}var sa=new WeakMap;function Ip(n){let e=sa.get(n);return e===void 0&&sa.set(n,e=Rp(n)),e}function Rp(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ma=65535,Aa=Math.pow(2,16);function _p(n,e){return n+e*Aa}function ka(n){return n&Ma}function Up(n){return(n-(n&Ma))/Aa}var Ea=1,Ta=2,ji=4,Da=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Da)>0}get deletedBefore(){return(this.delInfo&(Ea|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=ka(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:_p(l/3,e-c),m=e==c?Ta:e==d?Ea:ji;return(t<0?e!=c:e!=d)&&(m|=Da),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=ka(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Io(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Oo(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Vp(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Bp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Tr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Ro(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Pp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function Hp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Na(n,o,l,s),Ro(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Oa(n,o,l,s),!1}})}function Oa(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Na(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` -`))}})}function Jp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function $p(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wp(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ia(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function jp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Ia(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Kp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Na(n,h.node(),h.before(),l)}o.inlineContent&&Ro(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Oa(n,h.node(),h.before(),n.steps.length)}return n}function Yp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Qi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ra(i,s,r)?new Ee(e,t,r):new No(i,s,r).fit()}function Ra(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var No=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=To(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=To(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=To(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(va(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Do(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function To(n,e){for(let t=0;t1&&(r=r.replaceChild(0,va(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Do(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Gp(t,s.content,o)?l:null}function Gp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Xp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function _a(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Zp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Yp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function em(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ua(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function Ua(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Qi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Qp(this,e,t,r),this}replaceRangeWith(e,t,r){return Zp(this,e,t,r),this}deleteRange(e,t){return em(this,e,t),this}lift(e,t){return Lp(this,e,t),this}join(e,t=1){return Kp(this,e,t),this}wrap(e,t){return qp(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return $p(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Wp(this,e,t,r),this}addMark(e,t,r){return Vp(this,e,t,r),this}removeMark(e,t,r){return Bp(this,e,t,r),this}clearIncompatible(e,t,r){return Ro(this,e,t,r),this}};var _o=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=_o[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in _o)throw new RangeError("Duplicate use of selection JSON ID "+e);return _o[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Va=!1;function Ba(n){!Va&&!n.parent.inlineContent&&(Va=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Ba(e),Ba(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new es(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Pa(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var La=1,Zi=2,za=4,Bo=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Zi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Zi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Zi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=za,this}get scrolledIntoView(){return(this.updated&za)>0}};function Fa(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=Fa(t.init,r),this.apply=Fa(t.apply,r)}},nm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=nm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Po=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function qa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=qa(i,e,{})),t[r]=i}return t}var L=class{constructor(e){this.spec=e,this.props={},e.props&&qa(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}},Uo=Object.create(null);function Ha(n){return n in Uo?n+"$"+ ++Uo[n]:(Uo[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ho=null,pt=function(n,e,t){let r=Ho||(Ho=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},rm=function(){Ho=null},fn=function(n,e,t,r){return t&&(Ja(n,e,t,r,-1)||Ja(n,e,t,r,1))},im=/^(img|br|input|textarea|hr)$/i;function Ja(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Jr(n)||im.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function sm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function om(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),hm=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!$a&&"webkitFontSmoothing"in $a.documentElement.style,dm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function fm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function um(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Wa(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=zr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?fm(s):um(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function pm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Ah(n.dom)}}function Ah(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function mm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Eh(t,r==0?0:r-e)}function Eh(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?ym(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Th(t,i)}function ym(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function cl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function wm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function xm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=xm(n,r,i,e))}l==null&&(l=bm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function ja(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Lo(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Lo(c.getBoundingClientRect(),!0)}return Lo(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Lo(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Nh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Cm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Nh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Oh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Mm=/[\u0590-\u08ac]/;function Am(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Mm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Nh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ka=null,Ya=null,Ga=!1;function Em(n,e,t){return Ka==e&&Ya==t?Ga:(Ka=e,Ya=t,Ga=t=="up"||t=="down"?Cm(n,e,t):Am(n,e,t))}var Ue=0,Xa=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof rs){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof ts&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:Xa,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:Ge}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Xa;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ue&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},jo=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ue){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Xo(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=It.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=vh(h,r,t),a?c=new Ko(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new ns(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Ue&&e.eq(this.node)&&is(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Go(this,o&&o.node,e);Nm(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Ih(this.contentDOM,this.children,e),Kn&&Im(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Rm(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new jo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Xo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ue}updateOuterDeco(e){if(is(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Rh(this.dom,this.nodeDOM,Yo(this.outerDeco,this.node,t),Yo(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Qa(n,e,t,r,i){vh(r,e,n);let s=new Pt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var ns=class n extends Pt{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Ge||this.dirty!=Ue&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ue||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Ue,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ge)}get domAtom(){return!1}isText(e){return this.node.text==e}},rs=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ue&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ko=class extends Pt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Ih(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Om(n,e){return n.type.side-e.type.side}function Nm(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Im(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Rm(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Xo(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function al(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(fs(t)){for(c=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&k.isSelectable(d)&&i.parent&&!(d.isInline&&lm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new k(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!_h(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function _m(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,te(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&ke&&Bt<=11&&(r.disabled=!0,r.disabled=!1)}function Uh(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(rh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else rh(n)}function rh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function hl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function ih(n){return n.editable&&!n.hasFocus()?!1:Vh(n)}function Vh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Um(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Qo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function sh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Qo(n.state,e);return i&&i instanceof k?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?k.isSelectable(s)?Ut(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return Ut(n,new A(e>0?r.$to:r.$from));{let i=Qo(n.state,e);return i?Ut(n,i):!1}}}function ss(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Lr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function $n(n,e){return e<0?Vm(n):Bm(n)}function Vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Bh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=ss(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Zo(n,t,r):i&&Zo(n,i,s)}function Bm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=ss(t),s,o;for(;;)if(r{n.state==i&&mt(n)},50)}function oh(n,e){let t=n.state.doc.resolve(e);if(!(ae||hm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function lh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ve&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Qo(n.state,e);if(o&&o instanceof k)return Ut(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Te?S.near(o,e):S.findFrom(o,e);return l?Ut(n,l):!1}return!1}function ch(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ah(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function zm(n){if(!me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ah(n,r,"true"),setTimeout(()=>ah(n,r,"false"),20)}return!1}function Fm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qm(n,e){let t=e.keyCode,r=Fm(e);if(t==8||ve&&t==72&&r=="c")return ch(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ch(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?oh(n,n.state.selection.from)=="ltr"?-1:1:-1;return sh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?oh(n,n.state.selection.from)=="ltr"?1:-1:1;return sh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return lh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return zm(n)||lh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ph(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Jh(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Hh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var dm=Object.defineProperty;var um=(n,e)=>{for(var t in e)dm(n,t,{get:e[t],enumerable:!0})};function he(n){this.content=n}he.prototype={constructor:he,find:function(n){for(var e=0;e>1}};he.from=function(n){if(n instanceof he)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new he(e)};var Zo=he;function Xa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Xa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Qa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?ls(r+1,o):ls(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var rn=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=eh(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Za(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function Za(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Za(s.content,e-i-1,t-i-1)))}function eh(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=eh(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function pm(n,e,t){if(t.openStart>n.depth)throw new rn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new rn("Inconsistent open depths");return th(n,e,t,0)}function th(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function zr(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(tn(n.nodeAfter,r),s++));for(let l=s;li&&nl(n,e,i+1),o=r.depth>i&&nl(t,r,i+1),l=[];return zr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(nh(s,o),tn(nn(s,rh(n,e,t,r,i+1)),l)):(s&&tn(nn(s,hs(n,e,i+1)),l),zr(e,t,i,l),o&&tn(nn(o,hs(t,r,i+1)),l)),zr(r,null,i,l),new w(l)}function hs(n,e,t){let r=[];if(zr(null,n,t,r),n.depth>t){let i=nl(n,e,t+1);tn(nn(i,hs(n,e,t+1)),r)}return zr(e,null,t,r),new w(r)}function mm(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var fs=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new sn(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=$a.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ih(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Be.prototype.text=void 0;var il=class n extends Be{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ih(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ih(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var on=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new sl(e,t);if(r.next==null)return n.empty;let i=sh(r);r.next&&r.err("Unexpected trailing text");let s=Mm(Cm(i));return Am(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` +`)}};on.empty=new on(!0);var sl=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function sh(n){let e=[];do e.push(wm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function wm(n){let e=[];do e.push(bm(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function bm(n){let e=km(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=xm(n,e);else break;return e}function qa(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function xm(n,e){let t=qa(n),r=t;return n.eat(",")&&(n.next!="}"?r=qa(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Sm(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function km(n){if(n.eat("(")){let e=sh(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Sm(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Cm(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new on(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ch(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Be(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Be(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Be(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Em(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var ol=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Em(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},$r=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=hh(e,i.attrs),this.excluded=null;let s=lh(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ch(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},qr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Zo.from(e.nodes),t.marks=Zo.from(e.marks||{}),this.nodes=ds.compile(this.spec.nodes,this),this.marks=$r.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=on.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Ja(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Ja(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ds){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new il(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Be.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Ja(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Tm(n){return n.tag!=null}function Dm(n){return n.style!=null}var Wn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Tm(i))this.tags.push(i);else if(Dm(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new ms(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new ms(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=Wa(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=Wa(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},fh={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Om={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},dh={ol:!0,ul:!0},us=1,ps=2,Fr=4;function ja(n,e,t){return e!=null?(e?us:0)|(e==="full"?ps:0):n&&n.whitespace=="pre"?us|ps:t&~Fr}var jn=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Fr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&us)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!fh.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ms=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ja(null,t.preserveWhitespace,0)|(r?Fr:0);i?s=new jn(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new jn(null,null,D.none,!0,null,o):s=new jn(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&ps||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&us)i.options&ps?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;dh.hasOwnProperty(i)&&this.parser.normalizeLists&&Nm(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Om.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(fh.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):Ka(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new jn(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Nm(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&dh.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Im(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Wa(n){let e={};for(let t in n)e[t]=n[t];return e}function Ka(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&cs(tl(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return cs(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Ya(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Ya(e.marks)}};function Ya(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function tl(n){return n.document||window.document}var Ga=new WeakMap;function Rm(n){let e=Ga.get(n);return e===void 0&&Ga.set(n,e=vm(n)),e}function vm(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let f in a)if(a[f]!=null){let d=f.indexOf(" ");d>0?c.setAttributeNS(f.slice(0,d),f.slice(d+1),a[f]):c.setAttribute(f,a[f])}}for(let f=h;fh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=cs(n,d,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var mh=65535,gh=Math.pow(2,16);function Um(n,e){return n+e*gh}function uh(n){return n&mh}function Vm(n){return(n-(n&mh))/gh}var yh=1,wh=2,gs=4,bh=8,jr=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&bh)>0}get deletedBefore(){return(this.delInfo&(yh|gs))>0}get deletedAfter(){return(this.delInfo&(wh|gs))>0}get deletedAcross(){return(this.delInfo&gs)>0}},gt=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=uh(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],f=c+a;if(e<=f){let d=a?e==c?-1:e==f?1:t:t,u=c+i+(d<0?0:h);if(r)return u;let p=e==(t<0?c:f)?null:Um(l/3,e-c),m=e==c?wh:e==f?yh:gs;return(t<0?e!=c:e!=f)&&(m|=bh),new jr(u,m,p)}i+=h-a}return r?e+i:new jr(e+i,0,null)}touches(e,t){let r=0,i=uh(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,s)}invert(){return new ln(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Z.jsonID("addMark",Kr);var ln=class n extends Z{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(dl(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return re.fromReplace(e,this.from,this.to,r)}invert(){return new Kr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Z.jsonID("removeMark",ln);var Yr=class n extends Z{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return re.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return re.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};Z.jsonID("replaceAround",ee);function hl(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Bm(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let f=c.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(f);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Pm(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof $r){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new ln(o.from,o.to,o.style)))}function ul(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Lm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function cn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth,i=0,s=0;;--r){let o=n.$from.node(r),l=n.$from.index(r)+i,c=n.$to.indexAfter(r)-s;if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),f++):c--;let d=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new ee(i,s,i,s,new b(r,0,0),t.length,!0))}function Hm(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Jm(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Sh(n,o,l,s),ul(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new ee(f,d,f+1,d-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&xh(n,o,l,s),!1}})}function xh(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Sh(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` +`))}})}function Jm(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function jm(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new ee(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Vt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let f=i.node(a),d=i.index(a);if(f.type.spec.isolating)return!1;let u=f.content.cutByIndex(d,f.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Wm(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ne(e,e,new b(s.append(o),t,t),!0))}function an(n,e){let t=n.resolve(e),r=t.index();return kh(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Km(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&kh(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Ym(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Sh(n,h.node(),h.before(),l)}o.inlineContent&&ul(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ne(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);xh(n,h.node(),h.before(),n.steps.length)}return n}function Gm(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let f=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=f&&a.canReplaceWith(c,c,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function xs(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Mh(i,s,r)?new Ne(e,t,r):new fl(i,s,r).fit()}function Mh(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var fl=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new ee(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ne(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=cl(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,f=null;if(t==1&&(o?a.matchType(o.type)||(f=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=cl(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Hr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Hr(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(f=g,h.push(Ah(m.mark(d.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Jr(this.placed,t,w.from(h)),this.frontier[t].match=f,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=al(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Jr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Jr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Jr(this.placed,this.frontier.length,t))}};function Hr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Hr(n.firstChild.content,e-1,t)))}function Jr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Jr(n.lastChild.content,e-1,t)))}function cl(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ah(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function al(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Xm(t,s.content,o)?l:null}function Xm(n,e,t){for(let r=t;r0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let c=o.indexOf(l),a=[],h=r.openStart;for(let d=r.content,u=0;;u++){let p=d.firstChild;if(a.push(p),u==r.openStart)break;d=p.content}for(let d=h-1;d>=0;d--){let u=a[d],p=Qm(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(p||!u.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let u=(d+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function Eh(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function eg(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Gm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function tg(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Th(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function Th(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var ys=class n extends Z{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return re.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return re.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return gt.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};Z.jsonID("attr",ys);var ws=class n extends Z{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return re.ok(r)}getMap(){return gt.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};Z.jsonID("docAttr",ws);var Yn=class extends Error{};Yn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Yn.prototype=Object.create(Error.prototype);Yn.prototype.constructor=Yn;Yn.prototype.name="TransformError";var Gn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Wr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Yn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=xs(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Zm(this,e,t,r),this}replaceRangeWith(e,t,r){return eg(this,e,t,r),this}deleteRange(e,t){return tg(this,e,t),this}lift(e,t){return zm(this,e,t),this}join(e,t=1){return Ym(this,e,t),this}wrap(e,t){return qm(this,e,t),this}setBlockType(e,t=e,r,i=null){return Hm(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return jm(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ys(e,t,r)),this}setDocAttribute(e,t){return this.step(new ws(e,t)),this}addNodeMark(e,t){return this.step(new Yr(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof D)t.isInSet(r.marks)&&this.step(new Kn(e,t));else{let i=r.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Kn(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,r){return Wm(this,e,t,r),this}addMark(e,t,r){return Bm(this,e,t,r),this}removeMark(e,t,r){return Pm(this,e,t,r),this}clearIncompatible(e,t,r){return ul(this,e,t,r),this}};var ml=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Bt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Xn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Xn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Ie(e.node(0))}static atStart(e){return Xn(e,e,0,0,1)||new Ie(e)}static atEnd(e){return Xn(e,e,e.content.size,e.childCount,-1)||new Ie(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=ml[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in ml)throw new RangeError("Duplicate use of selection JSON ID "+e);return ml[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Bt=class{constructor(e,t){this.$from=e,this.$to=t}},Dh=!1;function Oh(n){!Dh&&!n.parent.inlineContent&&(Dh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Oh(e),Oh(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ks(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&k.isSelectable(l))return k.create(n,t-(i<0?l.nodeSize:0))}else{let c=Xn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Nh(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Ih=1,Ss=2,Rh=4,wl=class extends Gn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ss,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Ss)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ss,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Rh,this}get scrolledIntoView(){return(this.updated&Rh)>0}};function vh(n,e){return!e||!n?n:n.bind(e)}var hn=class{constructor(e,t,r){this.name=e,this.init=vh(t.init,r),this.apply=vh(t.apply,r)}},rg=[new hn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new hn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new hn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new hn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Gr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=rg.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new hn(r.key,r.spec.state,r))})}},bl=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Gr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Be.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function _h(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=_h(i,e,{})),t[r]=i}return t}var J=class{constructor(e){this.spec=e,this.props={},e.props&&_h(e.props,this,this.props),this.key=e.key?e.key.key:Uh("plugin")}getState(e){return e[this.key]}},gl=Object.create(null);function Uh(n){return n in gl?n+"$"+ ++gl[n]:(gl[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=Uh(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ie=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},ei=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ml=null,wt=function(n,e,t){let r=Ml||(Ml=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},ig=function(){Ml=null},yn=function(n,e,t,r){return t&&(Vh(n,e,t,r,-1)||Vh(n,e,t,r,1))},sg=/^(img|br|input|textarea|hr)$/i;function Vh(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Le(n))){let s=n.parentNode;if(!s||s.nodeType!=1||ii(n)||sg.test(n.nodeName)||n.contentEditable=="false")return!1;e=ie(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function og(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Le(n)}else if(n.parentNode&&!ii(n))e=ie(n),n=n.parentNode;else return null}}function lg(n,e){for(;;){if(n.nodeType==3&&e2),Pe=nr||(Ze?/Mac/.test(Ze.platform):!1),fg=Ze?/Win/.test(Ze.platform):!1,We=/Android \d/.test(qt),si=!!Bh&&"webkitFontSmoothing"in Bh.documentElement.style,dg=si?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ug(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function yt(n,e){return typeof n=="number"?n:n[e]}function pg(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ph(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=ei(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?ug(s):pg(l),h=0,f=0;if(e.topa.bottom-yt(r,"bottom")&&(f=e.bottom-e.top>a.bottom-a.top?e.top+yt(i,"top")-a.top:e.bottom-a.bottom+yt(i,"bottom")),e.lefta.right-yt(r,"right")&&(h=e.right-a.right+yt(i,"right")),h||f)if(c)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,u=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let p=l.scrollLeft-d,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function mg(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:wf(n.dom)}}function wf(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=ei(r));return e}function gg({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;bf(t,r==0?0:r-e)}function bf(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=f+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?wg(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:xf(t,i)}function wg(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ql(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function bg(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function Sg(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Sf(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;si&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Sg(n,r,i,e))}l==null&&(l=xg(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Lh(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Xr(Pt(wt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return xl(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==Le(r))){let c=r.childNodes[i-1],a=c.nodeType==3?wt(c,Le(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Xr(Pt(a,1),!1)}if(s==null&&i=0)}function Xr(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function xl(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Cf(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Mg(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Cf(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=kf(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=wt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Ag=/[\u0590-\u08ac]/;function Eg(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Ag.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Cf(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,f),c&&(c!=h||a!=f)&&l.extend&&l.extend(c,a)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}var zh=null,Fh=null,$h=!1;function Tg(n,e,t){return zh==e&&Fh==t?$h:(zh=e,Fh=t,$h=t=="up"||t=="down"?Mg(n,e,t):Eg(n,e,t))}var ze=0,qh=1,dn=2,et=3,wn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ze,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tie(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof As){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Cs&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?ie(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=ie(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let d=document.createRange();d.setEnd(c.node,c.offset),d.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?dn:qh,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=et:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?dn:et}r=o}this.dirty=dn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?dn:qh;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ze&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Dl=class extends wn{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},rr=class n extends wn{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Ut.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&et||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=et&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ze){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Rl(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,f=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=Ut.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=Ef(h,r,t),a?c=new Ol(e,t,r,i,h,f||null,d,a,s,o+1):t.isText?new Ms(e,t,r,i,h,d,s):new n(e,t,r,i,h,f||null,d,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==ze&&e.eq(this.node)&&Es(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Il(this,o&&o.node,e);Ig(this.node,this.innerDeco,(a,h,f)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!f&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,f,d)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,f,u,e)||c.updateNextNode(a,h,f,e,d,i)||c.addNode(a,h,f,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==dn)&&(o&&this.protectLocalComposition(e,o),Mf(this.contentDOM,this.children,e),nr&&Rg(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=vg(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Dl(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rl(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==et||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ze}updateOuterDeco(e){if(Es(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Af(this.dom,this.nodeDOM,Nl(this.outerDeco,this.node,t),Nl(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Hh(n,e,t,r,i){Ef(r,e,n);let s=new $t(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Ms=class n extends $t{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==et||this.dirty!=ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ze||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ze,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=et)}get domAtom(){return!1}isText(e){return this.node.text==e}},As=class extends wn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Ol=class extends $t{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==et)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Mf(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=rr.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof rr)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Ng(n,e){return n.type.side-e.type.side}function Ig(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o!g.inline):l.slice();r(d,m,e.forChild(s,d),u),s=p}}function Rg(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function vg(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Rl(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function Hl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(vs(t)){for(c=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&k.isSelectable(f)&&i.parent&&!(f.isInline&&cg(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new k(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Tf(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ug(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,ie(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&Ee&&Ft<=11&&(r.disabled=!0,r.disabled=!1)}function Df(n,e){if(e instanceof k){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Yh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Yh(n)}function Yh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Jl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Gh(n){return n.editable&&!n.hasFocus()?!1:Of(n)}function Of(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Vg(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return yn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function vl(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Lt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Xh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Lt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=vl(n.state,e);return i&&i instanceof k?Lt(n,i):!1}else if(!(Pe&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?k.isSelectable(s)?Lt(n,new k(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):si?Lt(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof k&&r.node.isInline)return Lt(n,new A(e>0?r.$to:r.$from));{let i=vl(n.state,e);return i?Lt(n,i):!1}}}function Ts(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Zr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Zn(n,e){return e<0?Bg(n):Pg(n)}function Bg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(Ke&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Zr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Nf(t))break;{let l=t.previousSibling;for(;l&&Zr(l,-1);)i=t.parentNode,s=ie(l),l=l.previousSibling;if(l)t=l,r=Ts(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?_l(n,t,r):i&&_l(n,i,s)}function Pg(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Ts(t),s,o;for(;;)if(r{n.state==i&&bt(n)},50)}function Qh(n,e){let t=n.state.doc.resolve(e);if(!(ue||fg)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Zh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Pe&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=vl(n.state,e);if(o&&o instanceof k)return Lt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ie?S.near(o,e):S.findFrom(o,e);return l?Lt(n,l):!1}return!1}function ef(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function tf(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Fg(n){if(!be||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;tf(n,r,"true"),setTimeout(()=>tf(n,r,"false"),20)}return!1}function $g(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function qg(n,e){let t=e.keyCode,r=$g(e);if(t==8||Pe&&t==72&&r=="c")return ef(n,-1)||Zn(n,-1);if(t==46&&!e.shiftKey||Pe&&t==68&&r=="c")return ef(n,1)||Zn(n,1);if(t==13||t==27)return!0;if(t==37||Pe&&t==66&&r=="c"){let i=t==37?Qh(n,n.state.selection.from)=="ltr"?-1:1:-1;return Xh(n,i,r)||Zn(n,i)}else if(t==39||Pe&&t==70&&r=="c"){let i=t==39?Qh(n,n.state.selection.from)=="ltr"?1:-1:1;return Xh(n,i,r)||Zn(n,i)}else{if(t==38||Pe&&t==80&&r=="c")return Zh(n,-1,r)||Zn(n,-1);if(t==40||Pe&&t==78&&r=="c")return Fg(n)||Zh(n,1,r)||Zn(n,1);if(r==(Pe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function If(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Ut.fromSchema(n.state.schema),l=Bf(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,f=0;for(;a&&a.nodeType==1&&(h=Vf[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),f++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` -`);return{dom:c,text:f,slice:e}}function Lh(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=It.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=Wm(t),$r&&jm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Hm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Km(hh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Jm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var Hm=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Jm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&Fh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=qh(o[o.length-1],s.length));let h=zh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function zh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Fh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function hh(n,e,t){return et}).createHTML(n):n}function Wm(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Jh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Hh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=$m(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Ym={touchstart:!0,touchmove:!0},tl=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Gm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Qm(n,r)&&!dl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Ym[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),nl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Xm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function nl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>dl(n,r))})}function dl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Qm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Zm(n,e){!dl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Wh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Kn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||qm(n,t)?t.preventDefault():Vt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if(Wh(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function us(n){return{left:n.clientX,top:n.clientY}}function eg(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function fl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function jn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function tg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(jn(n,new k(t),"pointer"),!0):!1}function ng(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof k&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(k.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(jn(n,k.create(n.state.doc,i),"pointer"),!0):!1}function rg(n,e,t,r,i){return fl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?ng(n,t):tg(n,t))}function ig(n,e,t,r){return fl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function sg(n,e,t,r){return fl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||og(n,t,r)}function og(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(jn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)jn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(k.isSelectable(o))jn(n,k.create(r,l),"pointer");else continue;return!0}}function ul(n){return ls(n)}var $h=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ul(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&eg(t,n.input.lastClick)&&!t[$h]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(us(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new rl(n,o,t,!!r)):(s=="doubleClick"?ig:sg)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var rl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[$h],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof k&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Vt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(us(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):rg(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(jn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Vt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),ul(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>ul(n);function Wh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var lg=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ls(n,!0),n.markCursor=null;else if(ls(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}jh(n,lg)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,jh(n,20))};function jh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ls(n),e))}function Kh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ag());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function cg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=sm(e.focusNode,e.focusOffset),r=om(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function ag(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ls(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Kh(n),e||n.docView&&n.docView.dirty){let t=al(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function hg(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Fr=ke&&Bt<15||Kn&&dm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Fr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Ph(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):hg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function fg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?qr(n,r.value,null,i,e):qr(n,r.textContent,r.innerHTML,i,e)},50)}function qr(n,e,t,r,i){let s=Lh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=dg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Yh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Yh(r),r.getData("text/html"),i,t)?t.preventDefault():fg(n,t)};var cs=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Gh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(us(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=k.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Ph(n,l);(!t.dataTransfer.files.length||!ae||Mh>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Fr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Fr||t.dataTransfer.setData("text/plain",a),n.dragging=new cs(h,!t[Gh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(us(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Lh(n,Yh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Gh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Xi(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&k.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new k(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(hl(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Hr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var as=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Hr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Qh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return z.empty;let r=[];for(let i=0;it instanceof z)?e:e.reduce((t,r)=>t.concat(r instanceof z?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=pg(l,n,e,t,i,s,o),h=ds(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Qh(n,l,c+t);if(a){s=!0;let h=ds(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Xh(s?Zh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Fo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(z.create(n.state.doc,[n.cursorWrapper.deco])),hs.from(e)}var mg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},gg=ke&&Bt<=11,sl=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}},ol=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new sl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),gg&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,mg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(ih(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(ke&&Bt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=zr(s))t.add(s);for(let s=e.anchorNode;s;s=zr(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&ih(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||bg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),yg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||mt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Sg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function Sg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var kg=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Cg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=al(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100hp(n,on(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),s&&Bi.setMeta("composition",s),n.dispatch(Bi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=xg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!kg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=gh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);s&&Nt.setMeta("composition",s),n.dispatch(Nt)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Bt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ag(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,dt,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20)),Y=n.state.tr.delete(Se,pe),dt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Mg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Ot.type=="add"?Y.addMark(Se,pe,Ot.mark):Y.removeMark(Se,pe,Ot.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=gh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:hl(n,e.resolve(t.anchor),e.resolve(t.head))}function Mg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||qo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Eg(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ll=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 tl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(kh),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=xh(this),bh(this),this.nodeViews=Sh(this),this.docView=Qa(this.state.doc,wh(this),Fo(this),this.dom,this),this.domObserver=new ol(this,(r,i,s,o)=>Cg(this,r,i,s,o)),this.domObserver.start(),Gm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&nl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(kh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Kh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=Sh(this);Dg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&nl(this),this.editable=xh(this),bh(this);let c=Fo(this),a=wh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&pm(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Tg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=cg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Um(this))?mt(this,u):(Uh(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&mm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Wa(this,t.getBoundingClientRect(),e)}else Wa(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new cs(e.slice,e.move,i<0?void 0:k.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Sm(this,e)}coordsAtPos(e,t=1){return Oh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Em(this,t||this.state,e)}pasteHTML(e,t){return qr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return qr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Xm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Fo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,rm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Zm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&cm(this.dom.ownerDocument)==this.dom&&wg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function wh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function bh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function xh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Tg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Sh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Dg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function kh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Og=["p",0],Ng=["blockquote",0],Ig=["hr"],Rg=["pre",["code",0]],vg=["br"],_g={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Og}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Ng}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ig}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Rg}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return vg}}},Ug=["em",0],Vg=["strong",0],Bg=["code",0],Pg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Ug}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Vg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Bg}}},Lg=new Dr({nodes:_g,marks:Pg});var td=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function zg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Fg=(n,e,t)=>{let r=zg(n,t);if(!r)return!1;let i=nd(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(sd(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||k.isSelectable(s)))for(let o=r.depth;;o--){let l=Qi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Gn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var qg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=nd(r)}let o=s&&s.nodeBefore;return!o||!k.isSelectable(o)?!1:(e&&e(n.tr.setSelection(k.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function nd(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Hg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Hg(n,t);if(!r)return!1;let i=rd(r);if(!i)return!1;let s=i.nodeAfter;if(sd(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||k.isSelectable(s))){let o=Qi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof k,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=vo(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(k.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},id=(n,e)=>{let t=n.selection,r;if(t instanceof k){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=vo(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Wg=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function gl(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=gl(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},jg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=gl(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Rt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Yg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof k&&e.selection.node.isBlock)return!r.parentOffset||!Rt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:gl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Rt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Gg=Yg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(k.create(n.doc,i))),!0)},Xg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Qg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function sd(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Qg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&nn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Gn(s,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function od(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Zg=od(-1),ey=od(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Gi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ny(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new vt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new Zt(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Rt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?fy(e,t,n,s):uy(e,t,s):!0:!1}}function fy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Sl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var yt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},gs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},py=typeof navigator<"u"&&/Mac/.test(navigator.platform),my=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)yt[48+J]=yt[96+J]=String(J);var J;for(J=1;J<=24;J++)yt[J+111]="F"+J;var J;for(J=65;J<=90;J++)yt[J]=String.fromCharCode(J+32),gs[J]=String.fromCharCode(J);var J;for(ms in yt)gs.hasOwnProperty(ms)||(gs[ms]=yt[ms]);var ms;function ad(n){var e=py&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||my&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?gs:yt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var gy=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function yy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=yt[r.keyCode])&&s!=i){let l=e[kl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var ys=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new hd(e):re.empty};var hd=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=ys)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=ys)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new hd([]);var xy=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),Cl=re;var Sy=500,ws=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hCy&&(l=ky(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Rr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fSy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(Cl.from(i.reverse()),s)}};ws.empty=new ws(Cl.empty,0);function ky(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Al=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},Cy=20;function My(n,e,t){let r=Ay(e),i=El.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Al(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(El,{redo:t,historyState:c})}var Ml=!1,dd=null;function Ay(n){let e=n.plugins;if(dd!=e){Ml=!1,dd=e;for(let t=0;t{let i=El.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=My(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Xr=bs(!1,!0),Qn=bs(!0,!0),bx=bs(!1,!1),xx=bs(!0,!1);function Ey(n={}){return new L({view(e){return new Tl(e,n)}})}var Tl=class{constructor(e,t){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=t.width)!==null&&r!==void 0?r:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,r;if(t){let l=e.nodeBefore,c=e.nodeAfter;if(l||c){let a=this.editorView.nodeDOM(this.cursorPos-(l?l.nodeSize:0));if(a){let h=a.getBoundingClientRect(),d=l?h.bottom:h.top;l&&c&&(d=(d+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:h.left,right:h.right,top:d-this.width/2,bottom:d+this.width/2}}}}if(!r){let l=this.editorView.coordsAtPos(this.cursorPos);r={left:l.left-this.width/2,right:l.left+this.width/2,top:l.top,bottom:l.bottom}}let i=this.editorView.dom.offsetParent;this.element||(this.element=i.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let s,o;if(!i||i==document.body&&getComputedStyle(i).position=="static")s=-pageXOffset,o=-pageYOffset;else{let l=i.getBoundingClientRect();s=l.left-i.scrollLeft,o=l.top-i.scrollTop}this.element.style.left=r.left-s+"px",this.element.style.top=r.top-o+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),i=r&&r.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,t,e):i;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Xi(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}};var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new Dl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ty(e)||!Dy(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!k.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var Dl=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ty(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Dy(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Oy(){return new L({props:{decorations:vy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Iy,handleKeyDown:Ny,handleDOMEvents:{beforeinput:Ry}}})}var Ny=Gr({ArrowLeft:xs("horiz",-1),ArrowRight:xs("horiz",1),ArrowUp:xs("vert",-1),ArrowDown:xs("vert",1)});function xs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Iy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&k.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Ry(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function vy(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",z.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function wt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var Uy=500;function pd({rules:n}){let e=new L({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return ud(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ud(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ud(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-Uy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},Vy=new bt(/--$/,"\u2014"),By=new bt(/\.\.\.$/,"\u2026"),Rx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),vx=new bt(/"$/,"\u201D"),_x=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Ux=new bt(/'$/,"\u2019");var gd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Py(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",md),gd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",id),i("Mod-BracketLeft",jr),i("Escape",Kr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",ps(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",ps(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let s=r,o=Yr(yl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),gd&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",bl(r)),i("Mod-[",xl(r)),i("Mod-]",Sl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Nl,Il;if(typeof WeakMap<"u"){let n=new WeakMap;Nl=e=>n.get(e),Il=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Nl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var F=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Fy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function wd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Hy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>yd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>yd(r,e)}],toDOM(r){return["th",wd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var zt=new le("selectingCells");function Zn(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Jy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ul(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=Zn(e.$head)||$y(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function $y(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Rl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Wy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Vl(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Td(n,e,t){let r=n.node(-1),i=F.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Dd(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new vt(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Rl(r)&&Rl(i)&&Vl(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?xt.rowSelection(r,i):s&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=F.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=F.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof xt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=F.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Gy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Xy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Qy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=F.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&Gy(r)?s=A.create(i,r.from):r instanceof A&&Xy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Zy=new le("fix-tables");function Nd(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=e0(n,i,s,t))};return e?e.doc!=n.doc&&Nd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function e0(n,e,t,r){let i=F.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;jy(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;s0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function u0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=Jy(i.$from),!s)return!1;o=(r=Zn(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var rS=Bl("row",{useDeprecatedLogic:!0}),iS=Bl("column",{useDeprecatedLogic:!0}),sS=Bl("cell",{useDeprecatedLogic:!0});function m0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function Ss(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function w0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function S0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Ms(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=_d(i,n,e);if(o==null)return!1;if(n=="horiz")return Ms(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Td(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Ms(t,r,a)}}}function Cs(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=_d(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Td(o.$headCell,n,e);return l?Ms(t,r,new V(o.$anchorCell,l)):!1}}function C0(n,e){let t=n.state.doc,r=Zn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function M0(n,e,t){if(!He(n.state))return!1;let r=w0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(vl(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=F.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=x0(r,l.right-l.left,l.bottom-l.top),Cd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ul(n.state),o=s.start(-1);return Cd(n.state,n.dispatch,o,F.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function A0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Md(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Ol(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Ol(n,a),d=zt.getState(n.state)==null;if(!h||!Vl(c,h))if(d)h=c;else return;let f=new V(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(zt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),zt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(zt,-1))}function l(c){let a=c,h=zt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Md(n,a.target)!=r&&(d=Ol(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function _d(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Md(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ol(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var E0=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),_l(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,_l(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function _l(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new D0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{O0(s,o,n,e,r)},mouseleave:s=>{N0(s)},mousedown:(s,o)=>{I0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return B0(s,o.activeHandle)},nodeViews:{}}});return i}var D0=class As{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new As(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new As(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Rl(e.doc.resolve(i))||(i=-1),new As(i,t.dragging)}return t}};function O0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=v0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Ad(n,e,"left",t):a-e.clientX<=t&&(l=Ad(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=F.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ud(n,l)}}}function N0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ud(n,-1)}function I0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=R0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(_0(n,d.activeHandle,Ed(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ed(d.dragging,h,t);U0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function R0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;aKs,AbstractConnector:()=>dc,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>Et,ContentFormat:()=>P,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Mt,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>uc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Gs,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Zs,YEvent:()=>Dn,YMapEvent:()=>eo,YTextEvent:()=>to,YXmlEvent:()=>no,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Nu,compareIDs:()=>kn,compareRelativePositions:()=>io,convertUpdateFormatV1ToV2:()=>f1,convertUpdateFormatV2ToV1:()=>uu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Xw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Ww,decodeSnapshot:()=>Yw,decodeSnapshotV2:()=>eu,decodeStateVector:()=>Ec,decodeUpdate:()=>s1,decodeUpdateV2:()=>lu,diffUpdate:()=>a1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Gw,encodeRelativePosition:()=>Jw,encodeSnapshot:()=>Kw,encodeSnapshotV2:()=>Zf,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Gf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>o1,encodeStateVectorFromUpdateV2:()=>au,equalDeleteSets:()=>Kf,equalSnapshots:()=>jw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>B,getTypeChildren:()=>g1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>zw,logUpdate:()=>i1,logUpdateV2:()=>ou,mergeDeleteSets:()=>Mn,mergeUpdates:()=>cu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>h1,obfuscateUpdateV2:()=>d1,parseUpdateMeta:()=>l1,parseUpdateMetaV2:()=>hu,readUpdate:()=>Vw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>Fw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Zw,transact:()=>R,tryGc:()=>n1,typeListToArraySnapshot:()=>co,typeMapGetAllSnapshot:()=>Au,typeMapGetSnapshot:()=>b1});var _=()=>new Map,Es=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Vd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Bd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Ts=n=>n[n.length-1];var Pd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},tr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,pS=Number.isNaN,Fd=Math.pow;var Os=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,mS=Number.MIN_SAFE_INTEGER,gS=1<<31;var qd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),yS=Number.isNaN,wS=Number.parseInt;var Ll=String.fromCharCode,bS=String.fromCodePoint,xS=Ll(65535),L0=n=>n.toLowerCase(),z0=/^\s*/g,F0=n=>n.replace(z0,""),q0=/([A-Z])/g,zl=(n,e)=>F0(n.replace(q0,t=>`${e}${L0(t)}`));var H0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Jd=ir?J0:H0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var $d=(n,e)=>zd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},q=()=>new wn;var Is=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Is(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var cr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ni=(n,e)=>{let t=Os(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Fl=new Uint8Array(3e4),W0=Fl.length/3,j0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iar(n,I(e)),ar=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{$0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Y0=(n,e)=>ql(n,4).setFloat32(0,e,!1),G0=(n,e)=>ql(n,8).setFloat64(0,e,!1),X0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var jd=new DataView(new ArrayBuffer(4)),Q0=n=>(jd.setFloat32(0,n),jd.getFloat32(0)===n),or=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":qd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Q0(e)?(Q(n,124),Y0(n,e)):(Q(n,123),G0(n,e));break;case"bigint":Q(n,122),X0(n,e);break;case"object":if(e===null)Q(n,126);else if(Zr(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var Kd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Kd(this),this.count=1,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}};var Yd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ni(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},lr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Yd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Yd(this),I(this.encoder)}},Ns=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var Xd=Ze("Unexpected end of array"),Qd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},H=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var Z0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>Z0(n,C(n));var xn=n=>n.arr[n.pos++];var C=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw Qd}throw Xd},ii=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posPl)throw Qd}throw Xd};var ew=n=>{let e=C(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},tw=n=>rr.decode(K(n)),Le=rr?tw:ew;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},nw=n=>Jl(n,4).getFloat32(0,!1),rw=n=>Jl(n,8).getFloat64(0,!1),iw=n=>Jl(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,nw,rw,iw,n=>!1,n=>!0,Le,n=>{let e=C(n),t={};for(let r=0;r{let e=C(n),t=[];for(let r=0;rsw[127-xn(n)](n),ri=class extends hr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Hl(this)?this.count=C(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends hr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Os(this.s);this.count=1,e&&(this.s=-this.s,this.count=C(this)+2)}return this.count--,this.s}};var fr=class extends hr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ii(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=C(this)+2)}return this.s+=this.diff,this.count--,this.s}},_s=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var CS=crypto.subtle,Zd=crypto.getRandomValues.bind(crypto);var ow=Math.random,$l=()=>Zd(new Uint32Array(1))[0];var ef=n=>n[fe(ow()*n.length)],lw="10000000-1000-4000-8000"+-1e11,tf=()=>lw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var ES=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},rf=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(rf=localStorage,Yl=!1)}catch{}var Vs=rf,sf=n=>Yl||addEventListener("storage",n),of=n=>Yl||removeEventListener("storage",n);var af=Object.assign,Bs=Object.keys,hf=(n,e)=>{for(let t in n)e(n[t],t)},df=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Bs(n).length,cf=n=>Bs(n).length;var ff=n=>{for(let e in n)return!1;return!0},hw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||cf(n)===cf(e)&&hw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),dw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return dw(n)};var oi=(n,e,t=0)=>{try{for(;tn,fw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return fw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",pr=typeof window<"u"&&typeof document<"u"&&!kt,TS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,uw=[],pw=()=>{if(et===void 0)if(kt){et=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${zl(e,"-")}`,t),et.set(`-${zl(e,"-")}`,t)}})):et=_();return et},nc=n=>pw().has(n);var li=n=>kt?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Vs.getItem(n));var pf=n=>nc("--"+n)||li(n)!==null,DS=pf("production"),mw=kt&&uf(process.env.FORCE_COLOR,["true","1","2"]),mf=mw||!nc("--no-colors")&&!pf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var gf=n=>new Uint8Array(n),gw=(n,e,t)=>new Uint8Array(n,e,t),yf=n=>new Uint8Array(n),yw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),bw=n=>{let e=atob(n),t=gf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return gw(e.buffer,e.byteOffset,e.byteLength)},wf=pr?yw:ww,bf=pr?bw:xw;var xf=n=>{let e=gf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new rc(n,e);var Ct=typeof document<"u"?document:{};var OS=typeof DOMParser<"u"?new DOMParser:null;var kf=n=>Vd(n,(e,t)=>`${t}:${e};`).join("");var NS=Ct.ELEMENT_NODE,IS=Ct.TEXT_NODE,RS=Ct.CDATA_SECTION_NODE,vS=Ct.COMMENT_NODE,_S=Ct.DOCUMENT_NODE,US=Ct.DOCUMENT_TYPE_NODE,VS=Ct.DOCUMENT_FRAGMENT_NODE;var Ls=n=>class{constructor(t){this._=t}destroy(){n(this._)}},kw=Ls(clearTimeout),ai=(n,e)=>new kw(setTimeout(e,n)),PS=Ls(clearInterval);var LS=Ls(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var zS=Ls(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),ic=nt(),sc=nt(),oc=nt(),fi=nt(),lc=nt(),mr=nt(),cc=nt(),Af=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Ef(n)),Tf.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Ef(n)),n.unshift(mr),Tf.forEach(e=>e.print(n))};var Tf=Ce();var Df=n=>({[Symbol.iterator](){return this},next:n}),Of=(n,e)=>Df(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Fs=(n,e)=>Df(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=class extends er{constructor(e,t){super(),this.doc=e,this.awareness=t}},pi=class{constructor(e,t){this.clock=e,this.len=t}},$t=class{constructor(){this.clients=new Map}},rt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Iw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},it=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new $t,t=C(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=C(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),it(s,r),s.toUint8Array()}return null},Kf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Yf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ys,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,at)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return C(this.restDecoder)}readDsLen(){return C(this.restDecoder)}},Me=class extends An{readLeftID(){return M(C(this.restDecoder),C(this.restDecoder))}readRightID(){return M(C(this.restDecoder),C(this.restDecoder))}readClient(){return C(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return C(this.restDecoder)===1}readTypeRef(){return C(this.restDecoder)}readLen(){return C(this.restDecoder)}readAny(){return dr(this.restDecoder)}readBuf(){return xf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},js=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=C(this.restDecoder),this.dsCurrVal}readDsLen(){let e=C(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends js{constructor(e){super(e),this.keys=[],C(e),this.keyClockDecoder=new fr(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new fr(K(e)),this.rightClockDecoder=new fr(K(e)),this.infoDecoder=new ri(K(e),xn),this.stringDecoder=new _s(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return dr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return dr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ei(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Rw(n,e.clients.get(i),i,s)})},vw=(n,e)=>{let t=_(),r=C(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ys,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Uw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=vw(r,o),a=_w(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=yi([h.update,a.update])}}else l.pendingStructs=a;let d=Rf(r,i,l);if(l.pendingDs){let f=new be(H(l.pendingDs));C(f.restDecoder);let u=Rf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Vw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=H(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Bw=(n,e,t=new Map)=>{kc(n,e.store,t),it(n,Sc(e.store))},Gf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Ec(e);Bw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===st)return cu(i.map((s,o)=>o===0?s:uu(s)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Gf(n,e,new st),Xf=n=>{let e=new Map,t=C(n.restDecoder);for(let r=0;rXf(new An(H(n))),Tc=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Pw=(n,e)=>Tc(n,Ei(e.store)),Lw=(n,e=new gr)=>(n instanceof Map?Tc(e,n):Pw(e,n),e.toUint8Array()),Dc=n=>Lw(n,new Wt),fc=class{constructor(){this.l=[]}},vf=()=>new fc,_f=(n,e)=>n.l.push(e),Uf=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Qf=(n,e,t)=>oi(n.l,[e,t]),Mt=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Mt(n,e),Vf=(n,e)=>{x(n,e.client),x(n,e.clock)},Bf=n=>M(C(n),C(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},zw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},uc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||br(),At(new An(H(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>At(new An(H(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;it(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Tt(r,e))return t;return null}},ot=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Fw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new ot(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),Ks=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},qw=(n,e,t=0)=>new Ks(n,e,t),qs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return qs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return qs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return qs(n,r.lastId,t);r=r.right}return qs(n,null,t)},Hw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Vf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Vf(n,t);else throw j();return ni(n,s),n},Jw=n=>{let e=q();return Hw(e,n),I(e)},$w=n=>{let e=null,t=null,r=null;switch(C(n)){case 0:r=Bf(n);break;case 1:t=Le(n);break;case 2:e=Bf(n)}let i=Hl(n)?ii(n):0;return new ot(e,t,r,i)},Ww=n=>$w(H(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?wc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?wc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return qw(c,a,n.assoc)},io=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,jt=class{constructor(e,t){this.ds=e,this.sv=t}},jw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Tc(e,n.sv),e.toUint8Array()),Kw=n=>Zf(n,new Wt),eu=(n,e=new js(H(n)))=>new jt(At(e),Xf(e)),Yw=n=>eu(n,new An(H(n))),Mi=(n,e)=>new jt(n,e),Gw=Mi(br(),new Map),Ai=n=>Mi(Sc(n.store),Ei(n.store)),qt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Tt(e.ds,n.id),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Xw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(H(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Qw(n,e,Me),Ys=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ei=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},tu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=e1,mc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[mc(n,t,e.clock)]},Pf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,ro(n,s,t.clock-s.id.clock+1)),s},t1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},nu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=mc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Bd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Uw(n,e),it(n,e.deleteSet),!0),zf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},$s=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},ru=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+$s(i,c)}})},n1=(n,e,t)=>{ru(n,e,t),iu(n,e)},su=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Qf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),oi(l,[]),t._needFormattingCleanup&&C1(t)}finally{r.gc&&ru(s,i,r.gcFilter),iu(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+$s(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&$s(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(zs(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Yf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;Lf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Lf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):su(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Gs(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&su(i,0)}}return o},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Ff=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Uc(r,!1)})},qf=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;rt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Ru(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new $t;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&mi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new gc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),rt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&Uc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=Zr(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&ac("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>Ff(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Ff(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=qf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=qf(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*r1(n){let e=C(n.restDecoder);for(let t=0;tou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);zs("Structs: ",t);let s=At(r);zs("DeleteSet: ",s)},s1=n=>lu(n,Me),lu=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},cu=n=>yi(n,Me,st),au=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(H(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=q();return x(h,o),Gd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},o1=n=>au(n,Wt,Me),hu=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(H(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},l1=n=>hu(n,Me),c1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},yi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(H(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new gi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=c1(f,p)),s.struct.mergeWith(f)||(Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Ht(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ht(l,s.struct,s.offset),s=null),Ic(l);let c=r.map(h=>At(h)),a=Mn(c);return it(o,a),o.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Ec(e),s=new r,o=new gi(s),l=new t(H(n)),c=new lt(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Ht(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(o);let a=At(l);return it(s,a),s.toUint8Array()},a1=(n,e)=>Nc(n,e,Me,st),du=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=q(),n.written=0)},Ht=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&du(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Ic=n=>{du(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(H(n)),s=new lt(i,!1),o=new r,l=new gi(o);for(let a=s.curr;a!==null;a=s.next())Ht(l,e(a),0);Ic(l);let c=At(i);return it(o,c),o.toUint8Array()},fu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Et:{let d=h;d.embed={};break}case P:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case ki:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=$d(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},h1=(n,e)=>so(n,fu(e),Me,st),d1=(n,e)=>so(n,fu(e),be,Ie),f1=n=>so(n,ec,Me,Ie),uu=n=>so(n,ec,be,st),Hf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=u1(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(Hf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Ts(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ts(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Ts(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(Hf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},u1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},pu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},p1=n=>{n.timestamp=Rc++},mu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},m1=(n,e,t)=>{if(n.length>=pu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>nr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&nr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},g1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},lo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Qf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=vf(),this._dEH=vf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){_f(this._eH,e)}observeDeep(e){_f(this._dEH,e)}unobserve(e){Uf(this._eH,e)}unobserveDeep(e){Uf(this._dEH,e)}toJSON(){}},gu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},yu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&qt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},y1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},bu=(n,e)=>{n.doc??se();let t=oo(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Kt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},xu=()=>Ze("Length exceeded!"),Su=(n,e,t,r)=>{if(t>e._length)throw xu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Xs(n,e,null,r);let i=t,s=oo(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Xs(n,e,i,t)},ku=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=oo(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw xu();e._searchMarker&&wi(e._searchMarker,i,-s+r)},Qs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Kt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Kt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Cu=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Mu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},b1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&qt(r,t)?r.content.getContent()[r.length-1]:void 0},Au=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&qt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Hs=n=>(n.doc??se(),Of(n._map.entries(),e=>!e[1].deleted)),Zs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),lo(this,e,new Zs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{w1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return bu(this,e)}toArray(){return yu(this)}slice(e=0,t=this.length){return gu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return wu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return y1(this)}_write(e){e.writeTypeRef(z1)}},x1=n=>new On,eo=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){lo(this,e,new eo(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...Hs(this)].length}keys(){return Fs(Hs(this),e=>e[0])}values(){return Fs(Hs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Fs(Hs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Mu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Qs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(F1)}},S1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(n,e),xi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case P:this.right.deleted||xr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Jf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?oo(e,t):null;if(s){let o=new xi(s.p.left,s.p,s.index,i);return Jf(n,o,t-s.index)}else{let o=new xi(null,e._start,0,i);return Jf(n,o,t)}},Eu=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Jt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},xr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Tu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Jt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Du=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Et(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Eu(n,e,t,l)},$f=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Tu(t,i);let l=Du(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Jt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` -`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Eu(n,e,t,l)},Ou=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&xr(i,a);break}}}e=e.right}return l},k1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Nu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=Es(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:xr(o,i.content);break;default:e+=Ou(t,r,i,s,o),s=Es(o),r=i;break}i=i.right}}),e},C1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&nu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):k1(r,i)});for(let i of e)Nu(i)})},Wf=(n,e,t)=>{let r=t,i=Es(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Et:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},ff(c)||(u.attributes=af({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Et:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Jt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Jt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),xr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ct=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new to(this,e,t);lo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new xi(null,this._start,0,new Map);for(let s=0;s0)&&hc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?$f(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wf(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(qt(c,e)||t!==void 0&&qt(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!qt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case P:qt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!r);hc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{Wf(i,Js(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Js(s,this,e,!1);o.right!==null&&$f(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Cu(this)}_write(e){e.writeTypeRef(q1)}},M1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===at)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},at=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){lo(this,e,new no(this,t,e))}toString(){return wu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),bi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Xs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw Ze("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return yu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return bu(this,e)}slice(e=0,t=this.length){return gu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(J1)}},A1=n=>new at,Z=class n extends at{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return hf(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Qs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Mu(this,e)}getAttributes(e){return e?Au(this,e):Cu(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return bi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(H1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),no=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},Si=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef($1),e.writeKey(this.hookName)}},T1=n=>new Si(n.readKey()),xe=class n extends ct{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(W1)}},D1=n=>new xe,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},O1=0,ue=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),tu(e.doc.store,this)}write(e,t){e.writeInfo(O1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},N1=n=>new In(n.readBuf()),wr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},I1=n=>new wr(n.readLen()),Iu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Iu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},R1=n=>new Rn(Iu(n.readString(),n.readAny())),Et=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},v1=n=>new Et(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},_1=n=>new P(n.readKey(),n.readJSON()),ki=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},P1=n=>new Re(n.readString()),L1=[x1,S1,M1,E1,A1,T1,D1],z1=0,F1=1,q1=2,H1=3,J1=4,$1=5,W1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},j1=n=>new Ae(L1[n.readTypeRef()](n)),wc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ro=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},jf=(n,e)=>Ld(n,t=>Tt(t.deletions,e)),Ru=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Ru(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Tt(r,d.right.id)||jf(s.undoStack,d.right.id)||jf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Pf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Pf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mi(e.deleteSet,this.id.client,this.id.clock,this.length),zf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?t1(e,this,new ue(this.id,this.length)):this.content=new wr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Mt?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},vu=(n,e)=>K1[e&31](n),K1=[()=>{j()},I1,U1,N1,P1,v1,_1,j1,B1,R1,()=>{j()}],Y1=10,ie=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(Y1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},_u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Uu="__ $YJS$ __";_u[Uu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");_u[Uu]=!0;var Vu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:bf(t.newValue||"")}),sf(this._onChange)}postMessage(e){Vs.setItem(this.room,wf(yf(e)))}close(){of(this._onChange)}},G1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Vu,n,()=>{let e=Ce(),t=new G1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Bu=(n,e)=>(Bc(n).subs.add(e),e),Pu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Vu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Lu=0,ao=1,zu=2,ho=(n,e)=>{x(n,Lu);let t=Dc(e);U(n,t)},Pc=(n,e,t)=>{x(n,ao),U(n,Ac(e,t))},Q1=(n,e,t)=>Pc(e,t,K(n)),Fu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},qu=(n,e)=>{x(n,zu),U(n,e)},Z1=Fu,Hu=(n,e,t,r)=>{let i=C(n);switch(i){case Lu:Q1(n,e,t);break;case ao:Fu(n,t,r);break;case zu:Z1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var tb=0;var Ju=(n,e,t)=>{switch(C(n)){case tb:t(e,Le(n))}};var Lc=3e4,fo=class extends tr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&uo(this,r,"timeout")},fe(Lc/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),ur(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},uo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},kr=(n,e,t=n.states)=>{let r=e.length,i=q();x(i,r);for(let s=0;s{let r=H(e),i=Ne(),s=[],o=[],l=[],c=[],a=C(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var Wu=n=>df(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Ku=3,Cr=1,sb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=Hu(e,n,t.doc,t);r&&s===ao&&!t.synced&&(t.synced=!0)};Ti[Ku]=(n,e,t,r,i)=>{x(n,Cr),U(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{$u(t.awareness,K(e),t)};Ti[sb]=(n,e,t,r,i)=>{Ju(e,t.doc,(s,o)=>ob(t,o))};var ju=3e4,ob=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Yu=(n,e,t)=>{let r=H(e),i=q(),s=C(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Gu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Yu(n,new Uint8Array(t.data),!0);Is(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,uo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Gu,De(Fd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=q();if(x(t,Bn),ho(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=q();x(r,Cr),U(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:s=new fo(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ti.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=q();x(f,Bn),ho(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Yu(this,new Uint8Array(f),!1);Is(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=q();x(p,Bn),qu(p,f),zc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=q();x(y,Cr),U(y,kr(s,g)),zc(this,I(y))},this._exitHandler=()=>{uo(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&ju{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var lb=/[\uD800-\uDBFF]/,cb=/[\uDC00-\uDFFF]/,ab=(n,e)=>{let t=0,r=0;for(;t0&&lb.test(n[t-1])&&t--;r+t0&&cb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Qu=ab;var v=new le("y-sync"),Dt=new le("y-undo"),Di=new le("yjs-cursor");var Ni=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Tt(e.ds,n.id),hb=[{light:"#ecd44433",dark:"#ecd444"}],db=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,ef(e))}return n.get(t)},tp=(n,{colors:e=hb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new po(n,s),c=new L({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ai(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Dt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},fb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Yt(t.doc,t.type,e.anchor,t.mapping),i=Yt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ii=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),po=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Xu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(pr&&this._domSelectionInView===null&&(ai(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Mi(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Oi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Oi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ai(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ai(i),vn(i,e),e=Ai(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{rt(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:db(r.colorMapping,r.colors,f)}},c=co(this.type,new jt(t.ds,e.sv)).map(h=>!h._item.deleted||Ni(h._item,e)||Ni(h._item,t)?Oi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);rt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>np(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));fb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Mr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},np=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,s);throw Oe()}return o},Oi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=np(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof ct&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=ub(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):co(n,new jt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ni(n._item,r)?Ni(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},ub=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},pb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:ip(i.marks)}));return t.applyDelta(r),e.set(t,n),t},mb=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,go(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?pb(n,e):mb(n,e),Zu=n=>typeof n=="object"&&n!==null,Jc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Bs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>Jc(r.attributes[s.type.name]||{},s.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=go(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&rp(n,e)},mo=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),ep=(n,e,t)=>{let r=n.toArray(),i=go(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},yb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=gb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,ip(a.marks))})),{insert:o,remove:l,index:c}=Qu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},ip=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Mr=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=go(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)rp(f,u)||yb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let E=ep(f,u,r),N=ep(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var vi=null,wb=()=>{let n=vi;vi=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,wb)),$(vi,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Ci(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Ci(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return bb(r._item.parent,r._item)}return Ci(e,e._length,-1)},bb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Oc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function op(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var xb=(n,e,t)=>n!==e,Sb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},kb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Cb=/^#[0-9a-fA-F]{6}$/,lp=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Cb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Yt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),z.create(n.doc,l))},Mb=(n,{awarenessStateFilter:e=xb,cursorBuilder:t=Sb,selectionBuilder:r=kb,getSelection:i=o=>o.selection}={},s="cursor")=>new L({key:Di,state:{init(o,l){return lp(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?lp(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Di.getState(o)},view:o=>{let l=()=>{o.docView&&$c(o,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!io(Un(h.cursor.anchor),f)||!io(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Ab=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Tb=new Set(["paragraph"]),Db=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof ct||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Ob=({protectedNodes:n=Tb,trackedOrigins:e=[],undoManager:t=null}={})=>new L({key:Dt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Db(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Dt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Dt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var _i="http://www.w3.org/2000/svg",Nb="http://www.w3.org/1999/xlink",Yc="ProseMirror-icon",Kc="pm-close-dropdowns";function Ib(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,cp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;cp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function yo(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function _b(n){Ui.time=Date.now(),Ui.node=n.target}function Ub(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Kc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),_b(d),o?a():(r.dispatchEvent(new CustomEvent(Kc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Ub(s)||a()}),r.addEventListener(Kc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function Vb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Fk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),qk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Hk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Jk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Lb(n,e){let t={run(r,i){return Xn(n,e.attrs)(r,i)},select(r){return Xn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new ht(t)}function zb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function cp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Gc as Dropdown,Po as EditorState,ll as EditorView,w as Fragment,bt as InputRule,ht as MenuItem,k as NodeSelection,L as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Fc as WebsocketProvider,Sr as Y,n0 as addColumnAfter,t0 as addColumnBefore,hy as addListNodes,l0 as addRowAfter,o0 as addRowBefore,cd as baseKeymap,Lg as baseSchema,zb as blockTypeItem,Py as buildKeymap,T0 as columnResizing,i0 as deleteColumn,a0 as deleteRow,y0 as deleteTable,Ey as dropCursor,Id as fixTables,Oy as gapCursor,g0 as goToNextCell,pd as inputRules,He as isInTable,by as keymap,xl as liftListItem,d0 as mergeCells,sp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Bb as renderGrouped,Je as selectedRect,pn as setBlockType,Sl as sinkListItem,f0 as splitCell,bl as splitListItem,P0 as tableEditing,Hy as tableNodes,mn as toggleMark,Xn as wrapIn,ps as wrapInList,Lb as wrapItem,Mb as yCursorPlugin,op as yDocToProsemirrorJSON,Eb as yRedo,tp as ySyncPlugin,Ab as yUndo,Ob as yUndoPlugin,Dt as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; +`);return{dom:c,text:d,slice:e}}function Rf(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",d=>{e=d(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0):b.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:u}=n.state,p=Ut.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=Wg(t),si&&Kg(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Wn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Hg.test(d.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Yg(nf(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Jg(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let u=l.content.firstChild;f{l=f(l,n)}),l}var Hg=/^(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 Jg(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&_f(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Uf(o[o.length-1],s.length));let h=vf(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function vf(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function _f(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function nf(n,e,t){return et}).createHTML(n):n}function Wg(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Bf().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Vf[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=jg(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var xe={},Se={},Gg={touchstart:!0,touchmove:!0},Vl=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Xg(n){for(let e in xe){let t=xe[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Zg(n,r)&&!jl(n,r)&&(n.editable||!(r.type in Se))&&t(n,r)},Gg[e]?{passive:!0}:void 0)}be&&n.dom.addEventListener("input",()=>null),Bl(n)}function zt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Qg(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Bl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>jl(n,r))})}function jl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Zg(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ey(n,e){!jl(n,e)&&xe[e.type]&&(n.editable||!(e.type in Se))&&xe[e.type](n,e)}Se.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Lf(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(We&&ue&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),nr&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,fn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||qg(n,t)?t.preventDefault():zt(n,"key")};Se.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Se.keypress=(n,e)=>{let t=e;if(Lf(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Pe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function _s(n){return{left:n.clientX,top:n.clientY}}function ty(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Wl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function tr(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function ny(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&k.isSelectable(r)?(tr(n,new k(t),"pointer"),!0):!1}function ry(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof k&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(k.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(tr(n,k.create(n.state.doc,i),"pointer"),!0):!1}function iy(n,e,t,r,i){return Wl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?ry(n,t):ny(n,t))}function sy(n,e,t,r){return Wl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function oy(n,e,t,r){return Wl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||ly(n,t,r)}function ly(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(tr(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)tr(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(k.isSelectable(o))tr(n,k.create(r,l),"pointer");else continue;return!0}}function Kl(n){return Ds(n)}var Pf=Pe?"metaKey":"ctrlKey";xe.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Kl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&ty(t,n.input.lastClick)&&!t[Pf]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(_s(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Pl(n,o,t,!!r)):(s=="doubleClick"?sy:oy)(n,o.pos,o.inside,t)?t.preventDefault():zt(n,"pointer"))};var Pl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Pf],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof k&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ke&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),zt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>bt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(_s(e))),this.updateAllowDefault(e),this.allowDefault||!t?zt(this.view,"pointer"):iy(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||be&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!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)?(tr(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):zt(this.view,"pointer")}move(e){this.updateAllowDefault(e),zt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};xe.touchstart=n=>{n.input.lastTouch=Date.now(),Kl(n),zt(n,"pointer")};xe.touchmove=n=>{n.input.lastTouch=Date.now(),zt(n,"pointer")};xe.contextmenu=n=>Kl(n);function Lf(n,e){return n.composing?!0:be&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var cy=We?5e3:-1;Se.compositionstart=Se.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),Ds(n,!0),n.markCursor=null;else if(Ds(n,!e.selection.empty),Ke&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}zf(n,cy)};Se.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,zf(n,20))};function zf(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ds(n),e))}function Ff(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=hy());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function ay(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=og(e.focusNode,e.focusOffset),r=lg(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function hy(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Ds(n,e=!1){if(!(We&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ff(n),e||n.docView&&n.docView.dirty){let t=Hl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function fy(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var ti=Ee&&Ft<15||nr&&dg<604;xe.copy=Se.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=ti?null:t.clipboardData,o=r.content(),{dom:l,text:c}=If(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):fy(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function dy(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function uy(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?ni(n,r.value,null,i,e):ni(n,r.textContent,r.innerHTML,i,e)},50)}function ni(n,e,t,r,i){let s=Rf(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=dy(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function $f(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Se.paste=(n,e)=>{let t=e;if(n.composing&&!We)return;let r=ti?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&ni(n,$f(r),r.getData("text/html"),i,t)?t.preventDefault():uy(n,t)};var Os=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},qf=Pe?"altKey":"ctrlKey";xe.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(_s(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof k?i.to-1:i.to))){if(r&&r.mightDrag)o=k.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=k.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=If(n,l);(!t.dataTransfer.files.length||!ue||yf>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ti?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",ti||t.dataTransfer.setData("text/plain",a),n.dragging=new Os(h,!t[qf],o)};xe.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Se.dragover=Se.dragenter=(n,e)=>e.preventDefault();Se.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(_s(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Rf(n,$f(t.dataTransfer),ti?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[qf]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Ch(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,d=a.doc;if(f?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(d))return;let u=a.doc.resolve(h);if(f&&k.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new k(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(Jl(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};xe.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&bt(n)},20))};xe.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};xe.beforeinput=(n,e)=>{if(ue&&We&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,fn(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in Se)xe[n]=Se[n];function ri(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var Ns=class n{constructor(e,t){this.toDOM=e,this.spec=t||mn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new se(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ri(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},pn=class n{constructor(e,t){this.attrs=e,this.spec=t||mn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new se(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==de||e.maps.length==0?this:this.mapInner(e,t,0,0,r||mn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Jf(t,l,a)){for(i||(i=this.children.slice());sl&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof pn){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,mn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-d);for(let y=0;yE+h-f)continue;let N=l[y]+h-f;u>=N?l[y+1]=d<=N?-2:-1:d>=h&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let d=t.map(n[a+1]+s,-1),u=d-i,{index:p,offset:m}=r.content.findIndex(f),g=r.maybeChild(p);if(g&&m==f&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=de?(l[a]=f,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=my(l,n,e,t,i,s,o),h=Rs(a,r,0,o);e=h.local;for(let f=0;ft&&o.to{let a=Jf(n,l,c+t);if(a){s=!0;let h=Rs(a,l,t+c+1,r);h!=de&&i.push(c,c+l.nodeSize,h)}});let o=Hf(s?jf(n):n,-t).sort(gn);for(let l=0;l0;)e++;n.splice(e,0,t)}function kl(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=de&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),Is.from(e)}var gy={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yy=Ee&&Ft<=11,zl=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}},Fl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new zl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),yy&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,gy)),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(Gh(this.view)){if(this.suppressingSelectionUpdates)return bt(this.view);if(Ee&&Ft<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&yn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=ei(s))t.add(s);for(let s=e.anchorNode;s;s=ei(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&Gh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hf.nodeName=="BR");if(h.length==2){let[f,d]=h;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of h){let u=d.parentNode;u&&u.nodeName=="LI"&&(!f||xy(e,f)!=u)&&d.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),wy(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||bt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let f=n.state.doc,d=n.someProp("domParser")||Wn.fromSchema(n.state.schema),u=f.resolve(o),p=null,m=d.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:ky,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function ky(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(be&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||be&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var Cy=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function My(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,_t=Hl(n,T);if(_t&&!n.state.selection.eq(_t)){if(ue&&We&&n.input.lastKeyCode===13&&Date.now()-100fm(n,fn(13,"Enter"))))return;let ss=n.state.tr.setSelection(_t);T=="pointer"?ss.setMeta("pointer",!0):T=="key"&&ss.scrollIntoView(),s&&ss.setMeta("composition",s),n.dispatch(ss)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Sy(n,e,t),h=n.state.doc,f=h.slice(a.from,a.to),d,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||We)&&i.some(T=>T.nodeType==1&&!Cy.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=af(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let _t=n.state.tr.setSelection(T);s&&_t.setMeta("composition",s),n.dispatch(_t)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),Ee&&Ft<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((nr&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,fn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ey(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,fn(8,"Backspace")))){We&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&We&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),We&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,fn(13,"Enter"))})},20));let Ae=p.start,we=p.endA,Q,mt,vt;if(E){if(m.pos==g.pos)Ee&&Ft<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>bt(n),20)),Q=n.state.tr.delete(Ae,we),mt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(vt=Ay(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Q=n.state.tr,vt.type=="add"?Q.addMark(Ae,we,vt.mark):Q.removeMark(Ae,we,vt.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",_t=>_t(n,Ae,we,T)))return;Q=n.state.tr.insertText(T,Ae,we)}}if(Q||(Q=n.state.tr.replace(Ae,we,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=af(n,Q.doc,a.sel);T&&!(ue&&We&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:Jl(n,e.resolve(t.anchor),e.resolve(t.head))}function Ay(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Cl(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ty(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var $l=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 Vl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(mf),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=uf(this),df(this),this.nodeViews=pf(this),this.docView=Hh(this.state.doc,ff(this),kl(this),this.dom,this),this.domObserver=new Fl(this,(r,i,s,o)=>My(this,r,i,s,o)),this.domObserver.start(),Xg(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&&Bl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(mf),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Ff(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=pf(this);Oy(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Bl(this),this.editable=uf(this),df(this);let c=kl(this),a=ff(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,a,c);(f||!e.selection.eq(i.selection))&&(o=!0);let d=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&mg(this);if(o){this.domObserver.stop();let u=f&&(Ee||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Dy(i.selection,e.selection);if(f){let p=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=ay(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Hh(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Vg(this))?bt(this,u):(Df(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():d&&gg(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof k){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ph(this,t.getBoundingClientRect(),e)}else Ph(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new Os(e.slice,e.move,i<0?void 0:k.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return kg(this,e)}coordsAtPos(e,t=1){return kf(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Tg(this,t||this.state,e)}pasteHTML(e,t){return ni(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ni(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Qg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],kl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ig())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ey(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?be&&this.root.nodeType===11&&ag(this.dom.ownerDocument)==this.dom&&by(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function ff(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[se.node(0,n.state.doc.content.size,e)]}function df(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:se.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function uf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Dy(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function pf(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Oy(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function mf(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Ny=["p",0],Iy=["blockquote",0],Ry=["hr"],vy=["pre",["code",0]],_y=["br"],Uy={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Ny}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Iy}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ry}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return vy}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return _y}}},Vy=["em",0],By=["strong",0],Py=["code",0],Ly={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Vy}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return By}},code:{parseDOM:[{tag:"code"}],toDOM(){return Py}}},zy=new qr({nodes:Uy,marks:Ly});var Kf=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Fy(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var $y=(n,e,t)=>{let r=Fy(n,t);if(!r)return!1;let i=Yf(r);if(!i){let o=r.blockRange(),l=o&&cn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Qf(n,i,e,-1))return!0;if(r.parent.content.size==0&&(ir(s,"end")||k.isSelectable(s)))for(let o=r.depth;;o--){let l=xs(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function ir(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var qy=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Yf(r)}let o=s&&s.nodeBefore;return!o||!k.isSelectable(o)?!1:(e&&e(n.tr.setSelection(k.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Yf(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Hy(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Hy(n,t);if(!r)return!1;let i=Gf(r);if(!i)return!1;let s=i.nodeAfter;if(Qf(n,i,e,1))return!0;if(r.parent.content.size==0&&(ir(s,"start")||k.isSelectable(s))){let o=xs(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof k,i;if(r){if(t.node.isTextblock||!an(n.doc,t.from))return!1;i=t.from}else if(i=pl(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(k.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Xf=(n,e)=>{let t=n.selection,r;if(t instanceof k){if(t.node.isTextblock||!an(n.doc,t.to))return!1;r=t.to}else if(r=pl(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},li=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&cn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Wy=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function Xl(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Xl(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Ky=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ie||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Xl(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Vt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&cn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Gy(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof k&&e.selection.node.isBlock)return!r.parentOffset||!Vt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Ie)&&o.deleteSelection();let l=r.depth==0?null:Xl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Vt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Vt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let f=o.mapping.map(r.before()),d=o.doc.resolve(f);l&&r.node(-1).canReplaceWith(d.index(),d.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Xy=Gy();var ci=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(k.create(n.doc,i))),!0)},Qy=(n,e)=>(e&&e(n.tr.setSelection(new Ie(n.doc))),!0);function Zy(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||an(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Qf(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Zy(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new ee(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&an(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),d=f&&cn(f);if(d!=null&&d>=e.depth)return t&&t(n.tr.lift(f,d).scrollIntoView()),!0;if(a&&ir(s,"start",!0)&&ir(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new ee(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function Zf(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var e0=Zf(-1),t0=Zf(1);function sr(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&bs(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function bn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),f=h.index();i=h.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function r0(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new Bt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):h=!a.every(d=>{let u=!1;return f.doc.nodesBetween(d.$from.pos,d.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,d.$from.pos-m),Math.min(p.nodeSize,d.$to.pos-m))))}),!u});for(let d=0;d=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new sn(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new ee(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)f=w.from(i.node(y).copy(f));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Vt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function tc(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?u0(e,t,n,s):p0(e,t,s):!0:!1}}function u0(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let f=s.pos,d=f+o.nodeSize;return r.step(new ee(f-(l?1:0),d+(c?1:0),f+1,d-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function nc(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),f=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),d=s.start,u=s.end;t(e.tr.step(new ee(d-(a?3:1),u,d,u,f,1,!0)).scrollIntoView())}return!0}}var St={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:"'"},Bs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},m0=typeof navigator<"u"&&/Mac/.test(navigator.platform),g0=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(j=0;j<10;j++)St[48+j]=St[96+j]=String(j);var j;for(j=1;j<=24;j++)St[j+111]="F"+j;var j;for(j=65;j<=90;j++)St[j]=String.fromCharCode(j+32),Bs[j]=String.fromCharCode(j);var j;for(Vs in St)Bs.hasOwnProperty(Vs)||(Bs[Vs]=St[Vs]);var Vs;function nd(n){var e=m0&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||g0&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Bs:St)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var y0=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function w0(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=St[r.keyCode])&&s!=i){let l=e[rc(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var Ps=200,oe=function(){};oe.prototype.append=function(e){return e.length?(e=oe.from(e),!this.length&&e||e.length=t?oe.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};oe.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};oe.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};oe.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};oe.from=function(e){return e instanceof oe?e:e&&e.length?new rd(e):oe.empty};var rd=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=Ps)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=Ps)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(oe);oe.empty=new rd([]);var S0=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(oe),ic=oe;var k0=500,Ls=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),s=i.maps.length),s--,h.push(f);return}if(i){h.push(new tt(f.map));let u=f.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new tt(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(s)):f.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hM0&&(l=C0(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Wr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new tt(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let c=t;this.items.forEach(d=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(d.step){let m=e.steps[u].invert(e.docs[u]),g=d.selection&&d.selection.map(s.slice(c+1,u));g&&l++,r.push(new tt(p,m,g))}else r.push(new tt(p))},i);let a=[];for(let d=t;dk0&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let f=new tt(a.invert(),c,h),d,u=i.length-1;(d=i.length&&i[u].merge(f))?i[u]=d:i.push(f)}}else o.map&&r--},this.items.length,0),new n(ic.from(i.reverse()),s)}};Ls.empty=new Ls(ic.empty,0);function C0(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var tt=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},oc=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},M0=20;function A0(n,e,t){let r=E0(e),i=lc.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new oc(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(lc,{redo:t,historyState:c})}var sc=!1,id=null;function E0(n){let e=n.plugins;if(id!=e){sc=!1,id=e;for(let t=0;t{let i=lc.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=A0(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var fi=zs(!1,!0),or=zs(!0,!0),WS=zs(!1,!1),KS=zs(!0,!1);var pe=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new cc(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!T0(e)||!D0(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!k.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};pe.prototype.visible=!1;pe.findFrom=pe.findGapCursorFrom;S.jsonID("gapcursor",pe);var cc=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return pe.valid(t)?new pe(t):S.near(t)}};function T0(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function D0(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function O0(){return new J({props:{decorations:v0,createSelectionBetween(n,e,t){return e.pos==t.pos&&pe.valid(t)?new pe(t):null},handleClick:I0,handleKeyDown:N0,handleDOMEvents:{beforeinput:R0}}})}var N0=hi({ArrowLeft:Fs("horiz",-1),ArrowRight:Fs("horiz",1),ArrowUp:Fs("vert",-1),ArrowDown:Fs("vert",1)});function Fs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=pe.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new pe(a))),!0):!1}}function I0(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!pe.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&k.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new pe(r))),!0)}function R0(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof pe))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function v0(n){if(!(n.selection instanceof pe))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(n.doc,[se.widget(n.selection.head,e,{key:"gapcursor"})])}function kt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var U0=500;function ld({rules:n}){let e=new J({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return od(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&od(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function od(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-U0),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},V0=new Ct(/--$/,"\u2014"),B0=new Ct(/\.\.\.$/,"\u2026"),rk=new Ct(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),ik=new Ct(/"$/,"\u201D"),sk=new Ct(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),ok=new Ct(/'$/,"\u2019");var ad=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function P0(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",fi),i("Shift-Mod-z",or),i("Backspace",cd),ad||i("Mod-y",or),i("Alt-ArrowUp",oi),i("Alt-ArrowDown",Xf),i("Mod-BracketLeft",li),i("Escape",ci),(r=n.marks.strong)&&(i("Mod-b",xn(r)),i("Mod-B",xn(r))),(r=n.marks.em)&&(i("Mod-i",xn(r)),i("Mod-I",xn(r))),(r=n.marks.code)&&i("Mod-`",xn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",Us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",Us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",sr(r)),r=n.nodes.hard_break){let s=r,o=ai(Ql,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),ad&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",ec(r)),i("Mod-[",tc(r)),i("Mod-]",nc(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",bn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",bn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,bn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var hc,fc;if(typeof WeakMap<"u"){let n=new WeakMap;hc=e=>n.get(e),fc=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;hc=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Ae=i+N*e;for(let we=0;wer&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function F0(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function fd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function q0(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>hd(r,e)}],toDOM(r){return["td",fd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>hd(r,e)}],toDOM(r){return["th",fd(r,e),0]}}}}function me(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Ht=new fe("selectingCells");function lr(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function H0(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Ye(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function mc(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=lr(e.$head)||J0(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function J0(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function dc(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function j0(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function gc(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function xd(n,e,t){let r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function Sn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Sd(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let f=r.nodeAt(h);if(!f)throw RangeError(`No cell with offset ${h} found`);let d=s+h+1;return new Bt(l.resolve(d),l.resolve(d+f.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(dc(r)&&dc(i)&&gc(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Mt.rowSelection(r,i):s&&this.isColSelection()?Mt.colSelection(r,i):new Mt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=Sn(y,0,m)),g>0&&(y=Sn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof Mt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(se.node(r,r+t.nodeSize,{class:"selectedCell"}))}),L.create(n.doc,e)}function G0({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function X0({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Q0(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof k&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=z.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&G0(r)?s=A.create(i,r.from):r instanceof A&&X0(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Z0=new fe("fix-tables");function Cd(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=ew(n,i,s,t))};return e?e.doc!=n.doc&&Cd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function ew(n,e,t,r){let i=z.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;W0(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;sw(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&f==e.map[h-e.width]){let d=t.nodeAt(f).attrs;n.setNodeMarkup(n.mapping.slice(l).map(f+r),null,{...d,rowspan:d.rowspan-1}),a+=d.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function uw(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=H0(i.$from),!s)return!1;o=(r=lr(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Ge(e),f=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,d,m.attrs)}),r(o)}return!0}}var Dk=yc("row",{useDeprecatedLogic:!0}),Ok=yc("column",{useDeprecatedLogic:!0}),Nk=yc("cell",{useDeprecatedLogic:!0});function mw(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function $s(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=me(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function ww(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(d=d.type.createChecked(Sn(d.attrs,d.attrs.colspan,h+d.attrs.colspan-r),d.content)),a.push(d),h+=d.attrs.colspan;for(let u=1;ui&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),c.push(f)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function Sw(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=me(l),a,h;if(i>e.width)for(let f=0,d=0;fe.height){let f=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;f.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let d=c.row.create(null,w.from(f)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Js(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Td(i,n,e);if(o==null)return!1;if(n=="horiz")return Js(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=xd(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Js(t,r,a)}}}function Hs(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=Td(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=xd(o.$headCell,n,e);return l?Js(t,r,new V(o.$anchorCell,l)):!1}}function Cw(n,e){let t=n.state.doc,r=lr(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function Mw(n,e,t){if(!Ye(n.state))return!1;let r=ww(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(uc(me(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=xw(r,l.right-l.left,l.bottom-l.top),gd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=mc(n.state),o=s.start(-1);return gd(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function Aw(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=yd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=lr(n.state.selection.$anchor))!=null&&((t=ac(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=ac(n,a),f=Ht.getState(n.state)==null;if(!h||!gc(c,h))if(f)h=c;else return;let d=new V(c,h);if(f||!n.state.selection.eq(d)){let u=n.state.tr.setSelection(d);f&&u.setMeta(Ht,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ht.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ht,-1))}function l(c){let a=c,h=Ht.getState(n.state),f;if(h!=null)f=n.state.doc.resolve(h);else if(yd(n,a.target)!=r&&(f=ac(n,e),!f))return o();f&&s(f,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function Td(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function yd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function ac(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?lr(n.state.doc.resolve(t.pos)):null}var Ew=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),pc(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,pc(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function pc(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let f=0,d=0;fnew t(f,e,d)),new Dw(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Fe.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{Ow(s,o,n,e,r)},mouseleave:s=>{Nw(s)},mousedown:(s,o)=>{Iw(s,o,e)}},decorations:s=>{let o=Fe.getState(s);if(o&&o.activeHandle>-1)return Bw(s,o.activeHandle)},nodeViews:{}}});return i}var Dw=class js{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Fe);if(r&&r.setHandle!=null)return new js(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new js(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return dc(e.doc.resolve(i))||(i=-1),new js(i,t.dragging)}return t}};function Ow(n,e,t,r,i){let s=Fe.getState(n.state);if(s&&!s.dragging){let o=vw(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=wd(n,e,"left",t):a-e.clientX<=t&&(l=wd(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=z.get(a),f=c.start(-1);if(h.colCount(c.pos-f)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Dd(n,l)}}}function Nw(n){let e=Fe.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Dd(n,-1)}function Iw(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Fe.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=Rw(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Fe,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let f=Fe.getState(n.state);f?.dragging&&(_w(n,f.activeHandle,bd(f.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Fe,{setDragging:null})))}function a(h){if(!h.which)return c(h);let f=Fe.getState(n.state);if(f&&f.dragging){let d=bd(f.dragging,h,t);Uw(n,f.activeHandle,d,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function Rw(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;aNo,AbstractConnector:()=>ea,AbstractStruct:()=>Rr,AbstractType:()=>H,Array:()=>Vn,ContentAny:()=>Zt,ContentBinary:()=>Pn,ContentDeleted:()=>vr,ContentDoc:()=>Ln,ContentEmbed:()=>Nt,ContentFormat:()=>P,ContentJSON:()=>Hi,ContentString:()=>Ve,ContentType:()=>Oe,Doc:()=>Je,GC:()=>ye,ID:()=>Dt,Item:()=>O,Map:()=>Bn,PermanentUserData:()=>na,RelativePosition:()=>ht,Skip:()=>ce,Snapshot:()=>Qt,Text:()=>dt,Transaction:()=>Ro,UndoManager:()=>_n,UpdateDecoderV1:()=>De,UpdateDecoderV2:()=>Ce,UpdateEncoderV1:()=>at,UpdateEncoderV2:()=>Ue,XmlElement:()=>ne,XmlFragment:()=>ut,XmlHook:()=>qi,XmlText:()=>Me,YArrayEvent:()=>Uo,YEvent:()=>Un,YMapEvent:()=>Vo,YTextEvent:()=>Bo,YXmlEvent:()=>Po,applyUpdate:()=>pa,applyUpdateV2:()=>zn,cleanupYTextFormatting:()=>Ip,compareIDs:()=>On,compareRelativePositions:()=>zo,convertUpdateFormatV1ToV2:()=>zb,convertUpdateFormatV2ToV1:()=>pp,createAbsolutePositionFromRelativePosition:()=>ba,createDeleteSet:()=>_r,createDeleteSetFromStructStore:()=>fa,createDocFromSnapshot:()=>Ab,createID:()=>M,createRelativePositionFromJSON:()=>$n,createRelativePositionFromTypeIndex:()=>Ji,createSnapshot:()=>ji,decodeRelativePosition:()=>bb,decodeSnapshot:()=>Cb,decodeSnapshotV2:()=>tp,decodeStateVector:()=>ga,decodeUpdate:()=>vb,decodeUpdateV2:()=>cp,diffUpdate:()=>Bb,diffUpdateV2:()=>xa,emptySnapshot:()=>Mb,encodeRelativePosition:()=>yb,encodeSnapshot:()=>kb,encodeSnapshotV2:()=>ep,encodeStateAsUpdate:()=>ma,encodeStateAsUpdateV2:()=>Xu,encodeStateVector:()=>wa,encodeStateVectorFromUpdate:()=>_b,encodeStateVectorFromUpdateV2:()=>hp,equalDeleteSets:()=>Yu,equalSnapshots:()=>Sb,findIndexSS:()=>je,findRootTypeKey:()=>Fn,getItem:()=>Nn,getItemCleanEnd:()=>sa,getItemCleanStart:()=>ge,getState:()=>B,getTypeChildren:()=>Hb,isDeleted:()=>It,isParentOf:()=>vn,iterateDeletedStructs:()=>lt,logType:()=>ub,logUpdate:()=>Rb,logUpdateV2:()=>lp,mergeDeleteSets:()=>In,mergeUpdates:()=>ap,mergeUpdatesV2:()=>Li,obfuscateUpdate:()=>Pb,obfuscateUpdateV2:()=>Lb,parseUpdateMeta:()=>Ub,parseUpdateMetaV2:()=>fp,readUpdate:()=>ab,readUpdateV2:()=>ua,relativePositionToJSON:()=>pb,snapshot:()=>Wi,snapshotContainsUpdate:()=>Tb,transact:()=>R,tryGc:()=>Nb,typeListToArraySnapshot:()=>Ho,typeMapGetAllSnapshot:()=>Ep,typeMapGetSnapshot:()=>Wb});var _=()=>new Map,Ws=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},W=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Od=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Nd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Te=()=>new Set;var Ks=n=>n[n.length-1];var Id=(n,e)=>{for(let t=0;t{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return Xe((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},ar=class{constructor(){this._observers=_()}on(e,t){W(this._observers,e,Te).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return Xe((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var Y=Math.floor;var Cn=Math.abs;var Re=(n,e)=>nn>e?n:e,Lk=Number.isNaN,vd=Math.pow;var Gs=n=>n!==0?n<0:1/n<0;var hr=Number.MAX_SAFE_INTEGER,wc=Number.MIN_SAFE_INTEGER,zk=1<<31;var _d=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&Y(n)===n),Fk=Number.isNaN,$k=Number.parseInt;var mi=String.fromCharCode,Lw=String.fromCodePoint,qk=mi(65535),zw=n=>n.toLowerCase(),Fw=/^\s*/g,$w=n=>n.replace(Fw,""),qw=/([A-Z])/g,xc=(n,e)=>$w(n.replace(qw,t=>`${e}${zw(t)}`));var Hw=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;idr.encode(n),Ud=dr?Jw:Hw;var fr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});fr&&fr.decode(new Uint8Array).length===1&&(fr=null);var Xs=(n,e)=>Rd(e,()=>n).join("");var Mn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},$=()=>new Mn;var Zs=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Zs(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var yr=te;var x=(n,e)=>{for(;e>127;)te(n,128|127&e),e=Y(e/128);te(n,127&e)},yi=(n,e)=>{let t=Gs(e);for(t&&(e=-e),te(n,(e>63?128:0)|(t?64:0)|63&e),e=Y(e/64);e>0;)te(n,(e>127?128:0)|127&e),e=Y(e/128)},Sc=new Uint8Array(3e4),Ww=Sc.length/3,Kw=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iwr(n,I(e)),wr=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=Re(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array($e(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),wr(n,e)},kc=(n,e)=>{jw(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Gw=(n,e)=>kc(n,4).setFloat32(0,e,!1),Xw=(n,e)=>kc(n,8).setFloat64(0,e,!1),Qw=(n,e)=>kc(n,8).setBigInt64(0,e,!1);var Bd=new DataView(new ArrayBuffer(4)),Zw=n=>(Bd.setFloat32(0,n),Bd.getFloat32(0)===n),mr=(n,e)=>{switch(typeof e){case"string":te(n,119),rt(n,e);break;case"number":_d(e)&&Cn(e)<=2147483647?(te(n,125),yi(n,e)):Zw(e)?(te(n,124),Gw(n,e)):(te(n,123),Xw(n,e));break;case"bigint":te(n,122),Qw(n,e);break;case"object":if(e===null)te(n,126);else if(At(e)){te(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var Pd=n=>{n.count>0&&(yi(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},An=class{constructor(){this.encoder=new Mn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Pd(this),this.count=1,this.s=e)}toUint8Array(){return Pd(this),I(this.encoder)}};var Ld=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);yi(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},gr=class{constructor(){this.encoder=new Mn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Ld(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ld(this),I(this.encoder)}},Qs=class{constructor(){this.sarr=[],this.s="",this.lensE=new An}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 Mn;return this.sarr.push(this.s),this.s="",rt(e,this.sarr.join("")),wr(e,this.lensE.toUint8Array()),I(e)}};var ve=n=>new Error(n),ke=()=>{throw ve("Method unimplemented")},F=()=>{throw ve("Unexpected case")};var Fd=ve("Unexpected end of array"),$d=ve("Integer out of Range"),br=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new br(n),Cc=n=>n.pos!==n.arr.length;var e1=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},G=n=>e1(n,C(n));var En=n=>n.arr[n.pos++];var C=n=>{let e=0,t=1,r=n.arr.length;for(;n.poshr)throw $d}throw Fd},xi=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.poshr)throw $d}throw Fd};var t1=n=>{let e=C(n);if(e===0)return"";{let t=String.fromCodePoint(En(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(En(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},n1=n=>fr.decode(G(n)),He=fr?n1:t1;var Mc=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},r1=n=>Mc(n,4).getFloat32(0,!1),i1=n=>Mc(n,8).getFloat64(0,!1),s1=n=>Mc(n,8).getBigInt64(0,!1);var o1=[n=>{},n=>null,xi,r1,i1,s1,n=>!1,n=>!0,He,n=>{let e=C(n),t={};for(let r=0;r{let e=C(n),t=[];for(let r=0;ro1[127-En(n)](n),bi=class extends br{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Cc(this)?this.count=C(this)+1:this.count=-1),this.count--,this.s}};var Tn=class extends br{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=xi(this);let e=Gs(this.s);this.count=1,e&&(this.s=-this.s,this.count=C(this)+2)}return this.count--,this.s}};var Sr=class extends br{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=xi(this),t=e&1;this.diff=Y(e/2),this.count=1,t&&(this.count=C(this)+2)}return this.s+=this.diff,this.count--,this.s}},to=class{constructor(e){this.decoder=new Tn(e),this.str=He(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var jk=crypto.subtle,qd=crypto.getRandomValues.bind(crypto);var l1=Math.random,Ac=()=>qd(new Uint32Array(1))[0];var Hd=n=>n[Y(l1()*n.length)],c1="10000000-1000-4000-8000"+-1e11,Jd=()=>c1.replace(/[018]/g,n=>(n^Ac()&15>>n/4).toString(16));var _e=Date.now;var Ec=n=>new Promise(n);var Yk=Promise.all.bind(Promise);var Tc=n=>n===void 0?null:n;var Dc=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Wd=new Dc,Oc=!0;try{typeof localStorage<"u"&&localStorage&&(Wd=localStorage,Oc=!1)}catch{}var ro=Wd,Kd=n=>Oc||addEventListener("storage",n),Yd=n=>Oc||removeEventListener("storage",n);var Dn=Symbol("Equality"),io=(n,e)=>n===e||!!n?.[Dn]?.(e)||!1;var Xd=n=>typeof n=="object",Qd=Object.assign,Ic=Object.keys;var Zd=(n,e)=>{for(let t in n)e(n[t],t)},eu=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t};var ki=n=>Ic(n).length;var tu=n=>{for(let e in n)return!1;return!0},kr=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Ci=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Rc=(n,e)=>n===e||ki(n)===ki(e)&&kr(n,(t,r)=>(t!==void 0||Ci(e,r))&&io(e[r],t)),f1=Object.freeze,vc=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&vc(n[e])}return f1(n)};var Ai=(n,e,t=0)=>{try{for(;tn;var jt=(n,e)=>{if(n===e)return!0;if(n==null||e==null||n.constructor!==e.constructor&&(n.constructor||Object)!==(e.constructor||Object))return!1;if(n[Dn]!=null)return n[Dn](e);switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var Et=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Cr=typeof window<"u"&&typeof document<"u"&&!Et,Gk=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,it,d1=[],u1=()=>{if(it===void 0)if(Et){it=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");it.set(`--${xc(e,"-")}`,t),it.set(`-${xc(e,"-")}`,t)}})):it=_();return it},Uc=n=>u1().has(n);var Ei=n=>Et?Tc(process.env[n.toUpperCase().replaceAll("-","_")]):Tc(ro.getItem(n));var ru=n=>Uc("--"+n)||Ei(n)!==null,iu=ru("production"),p1=Et&&nu(process.env.FORCE_COLOR,["true","1","2"]),su=p1||!Uc("--no-colors")&&!ru("no-color")&&(!Et||process.stdout.isTTY)&&(!Et||Uc("--color")||Ei("COLORTERM")!==null||(Ei("TERM")||"").includes("color"));var ou=n=>new Uint8Array(n),m1=(n,e,t)=>new Uint8Array(n,e,t),lu=n=>new Uint8Array(n),g1=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),w1=n=>{let e=atob(n),t=ou(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return m1(e.buffer,e.byteOffset,e.byteLength)},cu=Cr?g1:y1,au=Cr?w1:b1;var hu=n=>{let e=ou(n.byteLength);return e.set(n),e};var Vc=class{constructor(e,t){this.left=e,this.right=t}},st=(n,e)=>new Vc(n,e);var Bc=n=>n.next()>=.5,oo=(n,e,t)=>Y(n.next()*(t+1-e)+e);var Pc=(n,e,t)=>Y(n.next()*(t+1-e)+e);var Lc=(n,e,t)=>Pc(n,e,t);var S1=n=>mi(Lc(n,97,122)),du=(n,e=0,t=20)=>{let r=Lc(n,e,t),i="";for(let s=0;se[Lc(n,0,e.length-1)];var C1=Symbol("0schema"),zc=class{constructor(){this._rerrs=[]}extend(e,t,r,i=null){this._rerrs.push({path:e,expected:t,has:r,message:i})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let r=this._rerrs[t];e.push(Xs(" ",(this._rerrs.length-t)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(` +`)}},Fc=(n,e)=>n===e?!0:n==null||e==null||n.constructor!==e.constructor?!1:n[Dn]?io(n,e):At(n)?Ys(n,t=>ui(e,r=>Fc(t,r))):Xd(n)?kr(n,(t,r)=>Fc(t,e[r])):!1,le=class{static _dilutes=!1;extends(e){let[t,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,t]=[t,r]),Fc(t,r)}equals(e){return this.constructor===e.constructor&&jt(this.shape,e.shape)}[C1](){return!0}[Dn](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){ke()}get nullable(){return Or(this,xo)}get optional(){return new co(this)}cast(e){return uu(e,this),e}expect(e){return uu(e,this),e}},Ti=class extends le{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let r=e?.constructor===this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},K=(n,e=null)=>new Ti(n,e),Qk=K(Ti),Di=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=this.shape(e);return!r&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),r}},X=n=>new Di(n),Zk=K(Di),Tr=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=this.shape.some(i=>i===e);return!r&&t?.extend(null,this.shape.join(" | "),e.toString()),r}},wo=(...n)=>new Tr(n),pu=K(Tr),M1=RegExp.escape||(n=>n.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),mu=n=>{if(Dr.check(n))return[M1(n)];if(pu.check(n))return n.shape.map(e=>e+"");if(xu.check(n))return["[+-]?\\d+.?\\d*"];if(Su.check(n))return[".*"];if(go.check(n))return n.shape.map(mu).flat(1);F()},$c=class extends le{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(mu).map(t=>`(${t.join("|")})`).join("")+"$")}check(e,t){let r=this._r.exec(e)!=null;return!r&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),r}};var eC=K($c),A1=Symbol("optional"),co=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=e===void 0||this.shape.check(e);return!r&&t?.extend(null,"undefined (optional)","()"),r}get[A1](){return!0}},E1=K(co),ao=class extends le{check(e,t){return t?.extend(null,"never",typeof e),!1}},tC=new ao,nC=K(ao),ho=class n extends le{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new n(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,"object","null"),!1):kr(this.shape,(r,i)=>{let s=this._isPartial&&!Ci(e,i)||r.check(e[i],t);return!s&&t?.extend(i.toString(),r.toString(),typeof e[i],"Object property does not match"),s})}},T1=n=>new ho(n),D1=K(ho),O1=X(n=>n!=null&&(n.constructor===Object||n.constructor==null)),fo=class extends le{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&kr(e,(r,i)=>{let s=this.shape.keys.check(i,t);return!s&&t?.extend(i+"","Record",typeof e,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(r,t)})}},gu=(n,e)=>new fo(n,e),N1=K(fo),uo=class extends le{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&kr(this.shape,(r,i)=>{let s=r.check(e[i],t);return!s&&t?.extend(i.toString(),"Tuple",typeof r),s})}},I1=(...n)=>new uo(n),rC=K(uo),po=class extends le{constructor(e){super(),this.shape=e.length===1?e[0]:new Oi(e)}check(e,t){let r=At(e)&&Ys(e,i=>this.shape.check(i));return!r&&t?.extend(null,"Array",""),r}},yu=(...n)=>new po(n),R1=K(po),v1=X(n=>At(n)),mo=class extends le{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name),r}},_1=(n,e=null)=>new mo(n,e),iC=K(mo),U1=_1(le),qc=class extends le{constructor(e){super(),this.len=e.length-1,this.args=I1(...e.slice(-1)),this.res=e[this.len]}check(e,t){let r=e.constructor===Function&&e.length<=this.len;return!r&&t?.extend(null,"function",typeof e),r}};var V1=K(qc),B1=X(n=>typeof n=="function"),Hc=class extends le{constructor(e){super(),this.shape=e}check(e,t){let r=Ys(this.shape,i=>i.check(e,t));return!r&&t?.extend(null,"Intersectinon",typeof e),r}};var sC=K(Hc,n=>n.shape.length>0),Oi=class extends le{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let r=ui(this.shape,i=>i.check(e,t));return t?.extend(null,"Union",typeof e),r}},Or=(...n)=>n.findIndex(e=>go.check(e))>=0?Or(...n.map(e=>Ni(e)).map(e=>go.check(e)?e.shape:[e]).flat(1)):n.length===1?n[0]:new Oi(n),go=K(Oi),wu=()=>!0,yo=X(wu),P1=K(Di,n=>n.shape===wu),jc=X(n=>typeof n=="bigint"),L1=X(n=>n===jc),bu=X(n=>typeof n=="symbol"),oC=X(n=>n===bu),Er=X(n=>typeof n=="number"),xu=X(n=>n===Er),Dr=X(n=>typeof n=="string"),Su=X(n=>n===Dr),bo=X(n=>typeof n=="boolean"),z1=X(n=>n===bo),ku=wo(void 0),lC=K(Tr,n=>n.shape.length===1&&n.shape[0]===void 0),cC=wo(void 0);var xo=wo(null),F1=K(Tr,n=>n.shape.length===1&&n.shape[0]===null),aC=K(Uint8Array),hC=K(Ti,n=>n.shape===Uint8Array),$1=Or(Er,Dr,xo,ku,jc,bo,bu),fC=(()=>{let n=yu(yo),e=gu(Dr,yo),t=Or(Er,Dr,xo,bo,n,e);return n.shape=t,e.shape.values=t,t})(),Ni=n=>{if(U1.check(n))return n;if(O1.check(n)){let e={};for(let t in n)e[t]=Ni(n[t]);return T1(e)}else{if(v1.check(n))return Or(...n.map(Ni));if($1.check(n))return wo(n);if(B1.check(n))return K(n)}F()},uu=iu?()=>{}:(n,e)=>{let t=new zc;if(!e.check(n,t))throw ve(`Expected value to be of type ${e.constructor.name}. +${t.toString()}`)},Jc=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Ni(e),h:t}),this}else(e){return this.if(yo,e)}done(){return(e,t)=>{for(let r=0;rnew Jc(n),Cu=q1(yo).if(xu,(n,e)=>oo(e,wc,hr)).if(Su,(n,e)=>du(e)).if(z1,(n,e)=>Bc(e)).if(L1,(n,e)=>BigInt(oo(e,wc,hr))).if(go,(n,e)=>Ar(e,lo(e,n.shape))).if(D1,(n,e)=>{let t={};for(let r in n.shape){let i=n.shape[r];if(E1.check(i)){if(Bc(e))continue;i=i.shape}t[r]=Cu(i,e)}return t}).if(R1,(n,e)=>{let t=[],r=Pc(e,0,42);for(let i=0;ilo(e,n.shape)).if(F1,(n,e)=>null).if(V1,(n,e)=>{let t=Ar(e,n.res);return()=>t}).if(P1,(n,e)=>Ar(e,lo(e,[Er,Dr,xo,ku,jc,bo,yu(Er),gu(Or("a","b","c"),Er)]))).if(N1,(n,e)=>{let t={},r=oo(e,0,3);for(let i=0;iCu(Ni(e),n);var Tt=typeof document<"u"?document:{};var dC=X(n=>n.nodeType===K1);var uC=typeof DOMParser<"u"?new DOMParser:null;var pC=X(n=>n.nodeType===J1);var mC=X(n=>n.nodeType===j1);var Mu=n=>Od(n,(e,t)=>`${t}:${e};`).join("");var J1=Tt.ELEMENT_NODE,j1=Tt.TEXT_NODE,gC=Tt.CDATA_SECTION_NODE,yC=Tt.COMMENT_NODE,W1=Tt.DOCUMENT_NODE,wC=Tt.DOCUMENT_TYPE_NODE,K1=Tt.DOCUMENT_FRAGMENT_NODE,bC=X(n=>n.nodeType===W1);var So=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Y1=So(clearTimeout),Ii=(n,e)=>new Y1(setTimeout(e,n)),SC=So(clearInterval);var kC=So(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var CC=So(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var ot=Symbol;var Ri=ot(),vi=ot(),Wc=ot(),Kc=ot(),Yc=ot(),_i=ot(),Gc=ot(),Nr=ot(),Xc=ot(),Tu=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Du(n)),Ou.forEach(e=>e.print(n))},Qc=(...n)=>{console.warn(...Du(n)),n.unshift(Nr),Ou.forEach(e=>e.print(n))};var Ou=Te();var Nu=n=>({[Symbol.iterator](){return this},next:n}),Iu=(n,e)=>Nu(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Co=(n,e)=>Nu(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ea=class extends cr{constructor(e,t){super(),this.doc=e,this.awareness=t}},Vi=class{constructor(e,t){this.clock=e,this.len=t}},Gt=class{constructor(){this.clients=new Map}},lt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);if(s!=null){let o=s[s.length-1],l=o.id.clock+o.length;for(let c=0,a=r[c];c{let t=0,r=n.length-1;for(;t<=r;){let i=Y((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&ib(t,e.clock)!==null},ha=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=$e(i.len,s.clock+s.len-i.clock):(r{let e=new Gt;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{W(n.clients,e,()=>[]).push(new Vi(t,r))},_r=()=>new Gt,fa=n=>{let e=_r();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},ct=(n,e)=>{x(n.restEncoder,e.clients.size),Xe(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new Gt,t=C(n.restDecoder);for(let r=0;r0){let o=W(e.clients,i,()=>[]);for(let l=0;l{let r=new Gt,i=C(n.restDecoder);for(let s=0;s0){let s=new Ue;return x(s.restEncoder,0),ct(s,r),s.toUint8Array()}return null},Yu=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Gu(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Io,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ec(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Ec(a=>{let h=f=>{(f===void 0||f===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Xe(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=H){let r=W(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==H&&i!==t)if(i===H){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,Vn)}getText(e=""){return this.get(e,dt)}getMap(e=""){return this.get(e,Bn)}getXmlElement(e=""){return this.get(e,ne)}getXmlFragment(e=""){return this.get(e,ut)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Xe(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Rn=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return C(this.restDecoder)}readDsLen(){return C(this.restDecoder)}},De=class extends Rn{readLeftID(){return M(C(this.restDecoder),C(this.restDecoder))}readRightID(){return M(C(this.restDecoder),C(this.restDecoder))}readClient(){return C(this.restDecoder)}readInfo(){return En(this.restDecoder)}readString(){return He(this.restDecoder)}readParentInfo(){return C(this.restDecoder)===1}readTypeRef(){return C(this.restDecoder)}readLen(){return C(this.restDecoder)}readAny(){return xr(this.restDecoder)}readBuf(){return hu(G(this.restDecoder))}readJSON(){return JSON.parse(He(this.restDecoder))}readKey(){return He(this.restDecoder)}},Oo=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=C(this.restDecoder),this.dsCurrVal}readDsLen(){let e=C(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ce=class extends Oo{constructor(e){super(e),this.keys=[],C(e),this.keyClockDecoder=new Sr(G(e)),this.clientDecoder=new Tn(G(e)),this.leftClockDecoder=new Sr(G(e)),this.rightClockDecoder=new Sr(G(e)),this.infoDecoder=new bi(G(e),En),this.stringDecoder=new to(G(e)),this.parentInfoDecoder=new bi(G(e),En),this.typeRefDecoder=new Tn(G(e)),this.lenDecoder=new Tn(G(e))}readLeftID(){return new Dt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Dt(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 xr(this.restDecoder)}readBuf(){return G(this.restDecoder)}readJSON(){return xr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=$e(r,e[0].id.clock);let i=je(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ki(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),Xe(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{sb(n,e.clients.get(i),i,s)})},ob=(n,e)=>{let t=_(),r=C(n.restDecoder);for(let i=0;i{let r=[],i=Xe(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Io,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],f=new Map,d=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ce){let p=W(f,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),d();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),d();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ue;return da(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},cb=(n,e)=>da(n,e.doc.store,e.beforeState),ua=(n,e,t,r=new Ce(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=ob(r,o),a=lb(i,l,c),h=l.pendingStructs;if(h){for(let[d,u]of h.missing)if(uu)&&h.missing.set(d,u)}h.update=Li([h.update,a.update])}}else l.pendingStructs=a;let f=_u(r,i,l);if(l.pendingDs){let d=new Ce(q(l.pendingDs));C(d.restDecoder);let u=_u(d,i,l);f&&u?l.pendingDs=Li([f,u]):l.pendingDs=f||u}else l.pendingDs=f;if(s){let d=l.pendingStructs.update;l.pendingStructs=null,zn(i.doc,d)}},t,!1),ab=(n,e,t)=>ua(n,e,t,new De(n)),zn=(n,e,t,r=Ce)=>{let i=q(e);ua(i,n,t,new r(i))},pa=(n,e,t)=>zn(n,e,t,De),hb=(n,e,t=new Map)=>{da(n,e.store,t),ct(n,fa(e.store))},Xu=(n,e=new Uint8Array([0]),t=new Ue)=>{let r=ga(e);hb(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(xa(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===at)return ap(i.map((s,o)=>o===0?s:pp(s)));if(t.constructor===Ue)return Li(i)}return i[0]},ma=(n,e)=>Xu(n,e,new at),Qu=n=>{let e=new Map,t=C(n.restDecoder);for(let r=0;rQu(new Rn(q(n))),ya=(n,e)=>(x(n.restEncoder,e.size),Xe(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),fb=(n,e)=>ya(n,Ki(e.store)),db=(n,e=new Ir)=>(n instanceof Map?ya(e,n):fb(e,n),e.toUint8Array()),wa=n=>db(n,new Xt),ta=class{constructor(){this.l=[]}},Uu=()=>new ta,Vu=(n,e)=>n.l.push(e),Bu=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Zu=(n,e,t)=>Ai(n.l,[e,t]),Dt=class{constructor(e,t){this.client=e,this.clock=t}},On=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Dt(n,e),Pu=(n,e)=>{x(n,e.client),x(n,e.clock)},Lu=n=>M(C(n),C(n)),Fn=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw F()},vn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},ub=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},na=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(f=>{f.content.getContent().forEach(d=>{d instanceof Uint8Array&&this.dss.set(o,In([this.dss.get(o)||_r(),Ot(new Rn(q(d)))]))})})}),this.dss.set(o,In(l.map(h=>Ot(new Rn(q(h)))))),c.observe(h=>h.changes.added.forEach(f=>f.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Bn,o.set("ids",new Vn),o.set("ds",new Vn),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((f,d)=>{r===f&&o.get("ids").push([d])});let a=new Xt,h=this.dss.get(r);h&&(ct(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Xt;ct(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(It(r,e))return t;return null}},ht=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},pb=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},$n=n=>new ht(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),No=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},mb=(n,e,t=0)=>new No(n,e,t),Mo=(n,e,t)=>{let r=null,i=null;return n._item===null?i=Fn(n):r=M(n._item.id.client,n._item.id.clock),new ht(r,i,e,t)},Ji=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Mo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Mo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Mo(n,r.lastId,t);r=r.right}return Mo(n,null,t)},gb=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Pu(n,i);else if(r!==null)yr(n,1),rt(n,r);else if(t!==null)yr(n,2),Pu(n,t);else throw F();return yi(n,s),n},yb=n=>{let e=$();return gb(e,n),I(e)},wb=n=>{let e=null,t=null,r=null;switch(C(n)){case 0:r=Lu(n);break;case 1:t=He(n);break;case 2:e=Lu(n)}let i=Cc(n)?xi(n):0;return new ht(e,t,r,i)},bb=n=>wb(q(n)),xb=(n,e)=>{let t=Nn(n,e),r=e.clock-t.id.clock;return{item:t,diff:r}},ba=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?ca(r,i):xb(r,i),f=h.item;if(!(f instanceof O))return null;if(c=f.parent,c._item===null||!c._item.deleted){a=f.deleted||!f.countable?0:h.diff+(l>=0?0:1);let d=f.left;for(;d!==null;)!d.deleted&&d.countable&&(a+=d.length),d=d.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?ca(r,s):{item:Nn(r,s)};if(h instanceof O&&h.content instanceof Oe)c=h.content.type;else return null}else throw F();l>=0?a=c._length:a=0}return mb(c,a,n.assoc)},zo=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&On(n.item,e.item)&&On(n.type,e.type)&&n.assoc===e.assoc,Qt=class{constructor(e,t){this.ds=e,this.sv=t}},Sb=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(ct(e,n.ds),ya(e,n.sv),e.toUint8Array()),kb=n=>ep(n,new Xt),tp=(n,e=new Oo(q(n)))=>new Qt(Ot(e),Qu(e)),Cb=n=>tp(n,new Rn(q(n))),ji=(n,e)=>new Qt(n,e),Mb=ji(_r(),new Map),Wi=n=>ji(fa(n.store),Ki(n.store)),Wt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!It(e.ds,n.id),ra=(n,e)=>{let t=W(n.meta,ra,Te),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Ab=(n,e,t=new Je)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ue;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new ft(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Eb(n,e,De),Io=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ki=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},np=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw F()}t.push(e)},je=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=Y(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[je(t,e.clock)]},Nn=Db,ia=(n,e,t)=>{let r=je(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[ia(n,t,e.clock)]},sa=(n,e,t)=>{let r=e.clients.get(t.client),i=je(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ye&&r.splice(i+1,0,Lo(n,s,t.clock-s.id.clock+1)),s},Ob=(n,e,t)=>{let r=n.clients.get(e.id.client);r[je(r,e.id.clock)]=t},rp=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=ia(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Nd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(ha(e.deleteSet),cb(n,e),ct(n,e.deleteSet),!0),Fu=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&W(n.changed,e,Te).add(t)},To=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},ip=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=je(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=Re(i.length-1,1+je(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+To(i,c)}})},Nb=(n,e,t)=>{ip(n,e,t),sp(n,e)},op=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,f)=>h.path.length-f.path.length),l.push(()=>{Zu(a._dEH,c,t)}))}),l.push(()=>r.emit("afterTransaction",[t,r])),l.push(()=>{t._needFormattingCleanup&&Xb(t)})}),Ai(l,[])}finally{r.gc&&ip(s,i,r.gcFilter),sp(s,i),t.afterState.forEach((h,f)=>{let d=t.beforeState.get(f)||0;if(d!==h){let u=i.clients.get(f),p=$e(je(u,d),1);for(let m=u.length-1;m>=p;)m-=1+To(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:f,clock:d}=o[h].id,u=i.clients.get(f),p=je(u,d);p+11||p>0&&To(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(ko(Nr,Ri,"[yjs] ",vi,_i,"Changed the client-id because another client seems to be using it."),r.clientID=Gu()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new at;zu(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ue;zu(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):op(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ro(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&op(i,0)}}return o},oa=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},$u=(n,e,t)=>{lt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>i===n.doc||vn(i,r))&&Aa(r,!1)})},qu=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,f=[],d=!1;lt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=ca(c,u.id);m>0&&(p=ge(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>p===l.doc||vn(p,u))&&f.push(u)}}),lt(l,a.deletions,u=>{u instanceof O&&s.some(p=>p===l.doc||vn(p,u))&&!It(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{d=vp(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||d});for(let u=f.length-1;u>=0;u--){let p=f[u];n.deleteFilter(p)&&(p.delete(l),d=!0)}n.currStackItem=d?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},_n=class extends cr{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=At(e)?e[0].doc:e instanceof Je?e:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g)||g===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,f=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let d=new Gt;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&Bi(d,y,E,N)});let u=_e(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=f[f.length-1];g.deletions=In([g.deletions,c.deleteSet]),g.insertions=In([g.insertions,d])}else f.push(new oa(c.deleteSet,d)),p=!0;!a&&!h&&(this.lastChange=u),lt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>y===c.doc||vn(y,g))&&Aa(g,!0)});let m=[{stackItem:f[f.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=At(e)?e:[e],e.forEach(r=>{t.has(r)||(t.add(r),(r instanceof H?r.doc!==this.doc:r!==this.doc)&&Qc("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>$u(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>$u(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=qu(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=qu(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*Ib(n){let e=C(n.restDecoder);for(let t=0;tlp(n,De),lp=(n,e=Ce)=>{let t=[],r=new e(q(n)),i=new ft(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);ko("Structs: ",t);let s=Ot(r);ko("DeleteSet: ",s)},vb=n=>cp(n,De),cp=(n,e=Ce)=>{let t=[],r=new e(q(n)),i=new ft(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:Ot(r)}},Pi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ap=n=>Li(n,De,at),hp=(n,e=Ir,t=Ce)=>{let r=new e,i=new ft(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ce&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=$();return x(h,o),zd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},_b=n=>hp(n,Xt,De),fp=(n,e=Ce)=>{let t=new Map,r=new Map,i=new ft(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},Ub=n=>fp(n,De),Vb=(n,e)=>{if(n.constructor===ye){let{client:t,clock:r}=n.id;return new ye(M(t,r+e),n.length-e)}else if(n.constructor===ce){let{client:t,clock:r}=n.id;return new ce(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},Li=(n,e=Ce,t=Ue)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new ft(h,!0)),s=null,o=new t,l=new Pi(o);for(;i=i.filter(d=>d.curr!==null),i.sort((d,u)=>{if(d.curr.id.client===u.curr.id.client){let p=d.curr.id.clock-u.curr.id.clock;return p===0?d.curr.constructor===u.curr.constructor?0:d.curr.constructor===ce?1:-1:p}else return u.curr.id.client-d.curr.id.client}),i.length!==0;){let h=i[0],f=h.curr.id.client;if(s!==null){let d=h.curr,u=!1;for(;d!==null&&d.id.clock+d.length<=s.struct.id.clock+s.struct.length&&d.id.client>=s.struct.id.client;)d=h.next(),u=!0;if(d===null||d.id.client!==f||u&&d.id.clock>s.struct.id.clock+s.struct.length)continue;if(f!==s.struct.id.client)Kt(l,s.struct,s.offset),s={struct:d,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ce?s.struct.length-=p:d=Vb(d,p)),s.struct.mergeWith(d)||(Kt(l,s.struct,s.offset),s={struct:d,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===f&&d.id.clock===s.struct.id.clock+s.struct.length&&d.constructor!==ce;d=h.next())Kt(l,s.struct,s.offset),s={struct:d,offset:0}}s!==null&&(Kt(l,s.struct,s.offset),s=null),Sa(l);let c=r.map(h=>Ot(h)),a=In(c);return ct(o,a),o.toUint8Array()},xa=(n,e,t=Ce,r=Ue)=>{let i=ga(e),s=new r,o=new Pi(s),l=new t(q(n)),c=new ft(l,!1);for(;c.curr;){let h=c.curr,f=h.id.client,d=i.get(f)||0;if(c.curr.constructor===ce){c.next();continue}if(h.id.clock+h.length>d)for(Kt(o,h,$e(d-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===f;)Kt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===f&&c.curr.id.clock+c.curr.length<=d;)c.next()}Sa(o);let a=Ot(l);return ct(s,a),s.toUint8Array()},Bb=(n,e)=>xa(n,e,De,at),dp=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=$(),n.written=0)},Kt=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&dp(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Sa=n=>{dp(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new ft(i,!1),o=new r,l=new Pi(o);for(let a=s.curr;a!==null;a=s.next())Kt(l,e(a),0);Sa(l);let c=Ot(i);return ct(o,c),o.toUint8Array()},up=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ye:case ce:return c;case O:{let a=c,h=a.content;switch(h.constructor){case vr:break;case Oe:{if(t){let f=h.type;f instanceof ne&&(f.nodeName=W(s,f.nodeName,()=>"node-"+r)),f instanceof qi&&(f.hookName=W(s,f.hookName,()=>"hook-"+r))}break}case Zt:{let f=h;f.arr=f.arr.map(()=>r);break}case Pn:{let f=h;f.content=new Uint8Array([r]);break}case Ln:{let f=h;e&&(f.opts={},f.doc.guid=r+"");break}case Nt:{let f=h;f.embed={};break}case P:{let f=h;n&&(f.key=W(o,f.key,()=>r+""),f.value=W(l,f.value,()=>({i:r})));break}case Hi:{let f=h;f.arr=f.arr.map(()=>r);break}case Ve:{let f=h;f.str=Xs(r%10+"",f.str.length);break}default:F()}return a.parentSub&&(a.parentSub=W(i,a.parentSub,()=>r+"")),r++,c}default:F()}}},Pb=(n,e)=>Fo(n,up(e),De,at),Lb=(n,e)=>Fo(n,up(e),Ce,Ue),zb=n=>Fo(n,_c,De,Ue),pp=n=>Fo(n,_c,Ce,at),Hu="You must not compute changes after the event-handler fired.",Un=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Fb(this.currentTarget,this.target))}deletes(e){return It(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ve(Hu);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Ks(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ks(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Ks(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw ve(Hu);let t=this.target,r=Te(),i=Te(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},Fb=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},ae=()=>{Qc("Invalid access: Add Yjs type to a document before reading data.")},mp=80,ka=0,la=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ka++}},$b=n=>{n.timestamp=ka++},gp=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=ka++},qb=(n,e,t)=>{if(n.length>=mp){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>Cn(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&Cn(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=$e(e,i.index+t))}},Hb=n=>{n.doc??ae();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},qo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;W(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Zu(r._eH,t,e)},H=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Uu(),this._dEH=Uu(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw ke()}clone(){throw ke()}_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){Vu(this._eH,e)}observeDeep(e){Vu(this._dEH,e)}unobserve(e){Bu(this._eH,e)}unobserveDeep(e){Bu(this._dEH,e)}toJSON(){}},yp=(n,e,t)=>{n.doc??ae(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},wp=n=>{n.doc??ae();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&Wt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??ae();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return Fi(n,(r,i)=>{t.push(e(r,i,n))}),t},Jb=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},xp=(n,e)=>{n.doc??ae();let t=$o(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Zt(a)),i.integrate(n,0),a=[])};r.forEach(f=>{if(f===null)a.push(f);else switch(f.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(f);break;default:switch(h(),f.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Pn(new Uint8Array(f))),i.integrate(n,0);break;case Je:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ln(f)),i.integrate(n,0);break;default:if(f instanceof H)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Oe(f)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Sp=()=>ve("Length exceeded!"),kp=(n,e,t,r)=>{if(t>e._length)throw Sp();if(t===0)return e._searchMarker&&zi(e._searchMarker,t,r.length),vo(n,e,null,r);let i=t,s=$o(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return vo(n,e,i,t)},Cp=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=$o(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Sp();e._searchMarker&&zi(e._searchMarker,i,-s+r)},_o=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ca=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Zt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new Zt([r]);break;case Uint8Array:l=new Pn(r);break;case Je:l=new Ln(r);break;default:if(r instanceof H)l=new Oe(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Ma=(n,e)=>{n.doc??ae();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Mp=n=>{let e={};return n.doc??ae(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Ap=(n,e)=>{n.doc??ae();let t=n._map.get(e);return t!==void 0&&!t.deleted},Wb=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&Wt(r,t)?r.content.getContent()[r.length-1]:void 0},Ep=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&Wt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Ao=n=>(n.doc??ae(),Iu(n._map.entries(),e=>!e[1].deleted)),Uo=class extends Un{},Vn=class n extends H{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof H?t.clone():t)),e}get length(){return this.doc??ae(),this._length}_callObserver(e,t){super._callObserver(e,t),qo(this,e,new Uo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{kp(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{jb(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cp(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return xp(this,e)}toArray(){return wp(this)}slice(e=0,t=this.length){return yp(this,e,t)}toJSON(){return this.map(e=>e instanceof H?e.toJSON():e)}map(e){return bp(this,e)}forEach(e){Fi(this,e)}[Symbol.iterator](){return Jb(this)}_write(e){e.writeTypeRef(px)}},Kb=n=>new Vn,Vo=class extends Un{constructor(e,t,r){super(e,t),this.keysChanged=r}},Bn=class n extends H{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof H?t.clone():t)}),e}_callObserver(e,t){qo(this,e,new Vo(this,e,t))}toJSON(){this.doc??ae();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof H?i.toJSON():i}}),e}get size(){return[...Ao(this)].length}keys(){return Co(Ao(this),e=>e[0])}values(){return Co(Ao(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Co(Ao(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ae(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ma(this,e)}has(e){return Ap(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){_o(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mx)}},Yb=n=>new Bn,Yt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Rc(n,e),$i=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&F(),this.right.content.constructor){case P:this.right.deleted||Ur(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Ju=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||Ur(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?$o(e,t):null;if(s){let o=new $i(s.p.left,s.p,s.index,i);return Ju(n,o,t-s.index)}else{let o=new $i(null,e._start,0,i);return Ju(n,o,t)}},Tp=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Yt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},Ur=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Dp=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Yt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Op=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Yt(a,c)){o.set(l,a);let{left:h,right:f}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,f,f&&f.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},Zc=(n,e,t,r,i)=>{t.currentAttributes.forEach((d,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Dp(t,i);let l=Op(n,e,t,i),c=r.constructor===String?new Ve(r):r instanceof H?new Oe(r):new Nt(r),{left:a,right:h,index:f}=t;e._searchMarker&&zi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=f,t.forward(),Tp(n,e,t,l)},ju=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Dp(t,i);let l=Op(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Yt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` +`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Ve(c)),t.right.integrate(n,0),t.forward()}Tp(n,e,t,l)},Np=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:f}=a,d=r.get(h)??null;(o.get(h)!==a||d===f)&&(e.delete(n),l++,!c&&(i.get(h)??null)===f&&d!==f&&(d===null?i.delete(h):i.set(h,d))),!c&&!e.deleted&&Ur(i,a);break}}}e=e.right}return l},Gb=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Ip=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=Ws(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:Ur(o,i.content);break;default:e+=Np(t,r,i,s,o),s=Ws(o),r=i;break}i=i.right}}),e},Xb=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&rp(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ye&&e.add(o.parent)})}R(t,r=>{lt(n,n.deleteSet,i=>{if(i instanceof ye||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):Gb(r,i)});for(let i of e)Ip(i)})},Wu=(n,e,t)=>{let r=t,i=Ws(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Oe:case Nt:case Ve:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,f=0,d=()=>{if(l!==null){let u=null;switch(l){case"delete":f>0&&(u={delete:f}),f=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},tu(c)||(u.attributes=Qd({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Oe:case Nt:this.adds(o)?this.deletes(o)||(d(),l="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),f+=1):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=1);break;case Ve:this.adds(o)?this.deletes(o)||(l!=="insert"&&(d(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),f+=o.length):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Yt(m,p)?p!==null&&o.delete(r):(l==="retain"&&d(),Yt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Yt(m,p)||(l==="retain"&&d(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Yt(m,p)?m!==null&&o.delete(r):(l==="retain"&&d(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&d(),Ur(i,o.content));break}}o=o.right}for(d();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},dt=class n extends H{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ae(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new Bo(this,e,t);qo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ae();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Ve&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new $i(null,this._start,0,new Map);for(let s=0;s0)&&Zc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?ju(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Wu(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??ae();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let f={},d=!1;s.forEach((p,m)=>{d=!0,f[m]=p});let u={insert:l};d&&(u.attributes=f),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(Wt(c,e)||t!==void 0&&Wt(c,t))switch(c.content.constructor){case Ve:{let f=s.get("ychange");e!==void 0&&!Wt(c,e)?(f===void 0||f.user!==c.id.client||f.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!Wt(c,t)?(f===void 0||f.user!==c.id.client||f.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):f!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Oe:case Nt:{a();let f={insert:c.content.getContent()[0]};if(s.size>0){let d={};f.attributes=d,s.forEach((u,p)=>{d[p]=u})}i.push(f);break}case P:Wt(c,e)&&(a(),Ur(s,c.content));break}c=c.right}a()};return e||t?R(o,f=>{e&&ra(f,e),t&&ra(f,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),Zc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!r);Zc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{Wu(i,Eo(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Eo(s,this,e,!1);o.right!==null&&ju(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ma(this,e)}getAttributes(){return Mp(this)}_write(e){e.writeTypeRef(gx)}},Qb=n=>new dt,Ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ae()}[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===ne||t.constructor===ut)&&t._start!==null)e=t._start;else for(;e!==null;){let r=e.next;if(r!==null){e=r;break}else e.parent===this._root?e=null:e=e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ut=class n extends H{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof H?t.clone():t)),e}get length(){return this.doc??ae(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new Ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Xe(new Ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){qo(this,e,new Po(this,t,e))}toString(){return bp(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),Fi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{kp(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof H?e._item:e;vo(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw ve("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cp(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return wp(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return xp(this,e)}slice(e=0,t=this.length){return yp(this,e,t)}forEach(e){Fi(this,e)}_write(e){e.writeTypeRef(wx)}},Zb=n=>new ut,ne=class n extends ut{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return Zd(t,(r,i)=>{e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof H?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{_o(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ca(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ma(this,e)}hasAttribute(e){return Ap(this,e)}getAttributes(e){return e?Ep(this,e):Mp(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return Fi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(yx),e.writeKey(this.nodeName)}},ex=n=>new ne(n.readKey()),Po=class extends Un{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},qi=class n extends Bn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(bx),e.writeKey(this.hookName)}},tx=n=>new qi(n.readKey()),Me=class n extends dt{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(xx)}},nx=n=>new Me,Rr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw ke()}mergeWith(e){return!1}write(e,t,r){throw ke()}integrate(e,t){throw ke()}},rx=0,ye=class extends Rr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),np(e.doc.store,this)}write(e,t){e.writeInfo(rx),e.writeLen(this.length-t)}getMissing(e,t){return null}},Pn=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ix=n=>new Pn(n.readBuf()),vr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Bi(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}},sx=n=>new vr(n.readLen()),Rp=(n,e)=>new Je({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Ln=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Rp(this.doc.guid,this.opts))}splice(e){throw ke()}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}},ox=n=>new Ln(Rp(n.readString(),n.readAny())),Nt=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},lx=n=>new Nt(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},cx=n=>new P(n.readKey(),n.readJSON()),Hi=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},dx=n=>new Ve(n.readString()),ux=[Kb,Yb,Qb,ex,Zb,tx,nx],px=0,mx=1,gx=2,yx=3,wx=4,bx=5,xx=6,Oe=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw ke()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Sx=n=>new Oe(ux[n.readTypeRef()](n)),ca=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Nn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},Aa=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},Lo=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},Ku=(n,e)=>ui(n,t=>It(t.deletions,e)),vp=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return ge(n,a);let h=e.parent._item,f=null,d;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||vp(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=ge(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(f=e.left,d=e;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:ge(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.left}for(;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:ge(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.right}}else if(d=null,e.right&&!i){for(f=e;f!==null&&f.right!==null&&(f.right.redone||It(r,f.right.id)||Ku(s.undoStack,f.right.id)||Ku(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=ge(n,f.redone);if(f&&f.right!==null)return null}else f=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,f,f&&f.lastId,d,d&&d.id,u,e.parentSub,e.content.copy());return e.redone=m,Aa(g,!0),g.integrate(n,0),g},O=class n extends Rr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sa(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=ge(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ye||this.right&&this.right.constructor===ye)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){let r=Nn(t,this.parent);r.constructor===ye?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=sa(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),On(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Bi(e.deleteSet,this.id.client,this.id.clock,this.length),Fu(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw F();this.content.gc(e),t?Ob(e,this,new ye(this.id,this.length)):this.content=new vr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=Fn(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Dt?(e.writeParentInfo(!1),e.writeLeftID(l)):F();s!==null&&e.writeString(s)}this.content.write(e,t)}},_p=(n,e)=>kx[e&31](n),kx=[()=>{F()},sx,ax,ix,dx,lx,cx,Sx,fx,ox,()=>{F()}],Cx=10,ce=class extends Rr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){F()}write(e,t){e.writeInfo(Cx),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Up=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vp="__ $YJS$ __";Up[Vp]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Up[Vp]=!0;var Bp=new Map,Ea=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:au(t.newValue||"")}),Kd(this._onChange)}postMessage(e){ro.setItem(this.room,cu(lu(e)))}close(){Yd(this._onChange)}},Mx=typeof BroadcastChannel>"u"?Ea:BroadcastChannel,Ta=n=>W(Bp,n,()=>{let e=Te(),t=new Mx(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Pp=(n,e)=>(Ta(n).subs.add(e),e),Lp=(n,e)=>{let t=Ta(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Bp.delete(n)),r},qn=(n,e,t=null)=>{let r=Ta(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var zp=0,Jo=1,Fp=2,jo=(n,e)=>{x(n,zp);let t=wa(e);U(n,t)},Da=(n,e,t)=>{x(n,Jo),U(n,ma(e,t))},Ex=(n,e,t)=>Da(e,t,G(n)),$p=(n,e,t)=>{try{pa(e,G(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},qp=(n,e)=>{x(n,Fp),U(n,e)},Tx=$p,Hp=(n,e,t,r)=>{let i=C(n);switch(i){case zp:Ex(n,e,t);break;case Jo:$p(n,t,r);break;case Fp:Tx(n,t,r);break;default:throw new Error("Unknown message type")}return i};var Ox=0;var Jp=(n,e,t)=>{switch(C(n)){case Ox:t(e,He(n))}};var Oa=3e4,Wo=class extends ar{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=_e();this.getLocalState()!==null&&Oa/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Oa<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&Ko(this,r,"timeout")},Y(Oa/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:_e()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),jt(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},Ko=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},Br=(n,e,t=n.states)=>{let r=e.length,i=$();x(i,r);for(let s=0;s{let r=q(e),i=_e(),s=[],o=[],l=[],c=[],a=C(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var Wp=n=>eu(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Hn=0,Yp=3,Pr=1,vx=2,Yi=[];Yi[Hn]=(n,e,t,r,i)=>{x(n,Hn);let s=Hp(e,n,t.doc,t);r&&s===Jo&&!t.synced&&(t.synced=!0)};Yi[Yp]=(n,e,t,r,i)=>{x(n,Pr),U(n,Br(t.awareness,Array.from(t.awareness.getStates().keys())))};Yi[Pr]=(n,e,t,r,i)=>{jp(t.awareness,G(e),t)};Yi[vx]=(n,e,t,r,i)=>{Jp(e,t.doc,(s,o)=>_x(t,o))};var Kp=3e4,_x=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Gp=(n,e,t)=>{let r=q(e),i=$(),s=C(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Xp=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=_e();let r=Gp(n,new Uint8Array(t.data),!0);Zs(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,Ko(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Xp,Re(vd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=_e(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=$();if(x(t,Hn),jo(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=$();x(r,Pr),U(r,Br(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Na=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&qn(n.bcChannel,e,n)},Ia=class extends ar{constructor(e,t,r,{connect:i=!0,awareness:s=new Wo(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:f=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=f,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Yi.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let d=$();x(d,Hn),jo(d,r),this.ws.send(I(d))}},a)),this._bcSubscriber=(d,u)=>{if(u!==this){let p=Gp(this,new Uint8Array(d),!1);Zs(p)>1&&qn(this.bcChannel,I(p),this)}},this._updateHandler=(d,u)=>{if(u!==this){let p=$();x(p,Hn),qp(p,d),Na(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:u,removed:p},m)=>{let g=d.concat(u).concat(p),y=$();x(y,Pr),U(y,Br(s,g)),Na(this,I(y))},this._exitHandler=()=>{Ko(this.awareness,[r.clientID],"app closed")},Et&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Kp<_e()-this.wsLastMessageReceived&&this.ws.close()},Kp/10),i&&this.connect()}get url(){let e=Wp(this.params);return this.serverUrl+"/"+this.roomname+(e.length===0?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Et&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Pp(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);let e=$();x(e,Hn),jo(e,this.doc),qn(this.bcChannel,I(e),this);let t=$();x(t,Hn),Da(t,this.doc),qn(this.bcChannel,I(t),this);let r=$();x(r,Yp),qn(this.bcChannel,I(r),this);let i=$();x(i,Pr),U(i,Br(this.awareness,[this.doc.clientID])),qn(this.bcChannel,I(i),this)}disconnectBc(){let e=$();x(e,Pr),U(e,Br(this.awareness,[this.doc.clientID],new Map)),Na(this,I(e)),this.bcconnected&&(Lp(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Xp(this),this.connectBc())}};var Qp=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var Ux=/[\uD800-\uDBFF]/,Vx=/[\uDC00-\uDFFF]/,Bx=(n,e)=>{let t=0,r=0;for(;t0&&Ux.test(n[t-1])&&t--;r+t0&&Vx.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Zp=Bx;var v=new fe("y-sync"),Rt=new fe("y-undo"),Gi=new fe("yjs-cursor");var Qi=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!It(e.ds,n.id),Px=[{light:"#ecd44433",dark:"#ecd444"}],Lx=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Hd(e))}return n.get(t)},nm=(n,{colors:e=Px,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Yo(n,s),c=new J({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let f=a.getMeta(v);if(f!==void 0){h=Object.assign({},h);for(let d in f)h[d]=f[d]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=f!==void 0&&!!f.isChangeOrigin,h.isUndoRedoOperation=f!==void 0&&!!f.isChangeOrigin&&!!f.isUndoRedoOperation,l.prosemirrorView!==null&&f!==void 0&&(f.snapshot!=null||f.prevSnapshot!=null)&&Ii(0,()=>{l.prosemirrorView!=null&&(f.restore==null?l._renderSnapshot(f.snapshot,f.prevSnapshot,h):(l._renderSnapshot(f.snapshot,f.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let f=Rt.getState(a.state),d=f&&f.undoManager;d&&d.stopCapturing()}l.mux(()=>{h.doc.transact(f=>{f.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},zx=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=en(t.doc,t.type,e.anchor,t.mapping),i=en(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Zi=(n,e)=>({anchor:Jn(e.selection.anchor,n.type,n.mapping),head:Jn(e.selection.head,n.type,n.mapping)}),Yo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Qp(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Zi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(Cr&&this._domSelectionInView===null&&(Ii(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Tt.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=ji(_r(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Xi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Xi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Wi(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&F(),i=new Je({gc:!1}),zn(i,t),t=Wi(i),zn(i,e),e=Wi(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{lt(s,h,f=>{})});let l=(h,f)=>{let d=h==="added"?o.getUserByClientId(f.client):o.getUserByDeletedId(f);return{user:d,type:h,color:Lx(r.colorMapping,r.colors,d)}},c=Ho(this.type,new Qt(t.ds,e.sv)).map(h=>!h._item.deleted||Qi(h._item,e)||Qi(h._item,t)?Xi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);lt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>rm(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));zx(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof _n}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Lr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Zi(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},rm=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof ne)return Xi(n,e,t,r,i,s);throw ke()}return o},Xi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===ne){let a=rm(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof dt&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(f=>{a._item.delete(f)}));let h=Fx(c,e,t,r,i,s);h!==null&&h.forEach(f=>{f!==null&&o.push(f)})}};r===void 0||i===void 0?n.toArray().forEach(l):Ho(n,new Qt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Qi(n._item,r)?Qi(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},Fx=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},$x=(n,e)=>{let t=new Me,r=n.map(i=>({insert:i.text,attributes:sm(i.marks)}));return t.applyDelta(r),e.set(t,n),t},qx=(n,e)=>{let t=new ne(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,Xo(n).map(r=>Ra(r,e))),e.set(t,n),t},Ra=(n,e)=>n instanceof Array?$x(n,e):qx(n,e),em=n=>typeof n=="object"&&n!==null,_a=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Ic(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>_a(r.attributes[s.type.name]||{},s.attrs)))},es=(n,e)=>{if(n instanceof ne&&!(e instanceof Array)&&va(n,e)){let t=Xo(e);return n._length===t.length&&_a(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>es(r,t[i]))}return n instanceof Me&&e instanceof Array&&im(n,e)},Go=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),tm=(n,e,t)=>{let r=n.toArray(),i=Xo(e),s=i.length,o=r.length,l=Re(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Ve?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},Jx=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=Hx(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,sm(a.marks))})),{insert:o,remove:l,index:c}=Zp(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},sm=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Lr=(n,e,t,r)=>{if(e instanceof ne&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof ne){let f=e.getAttributes(),d=t.attrs;for(let u in d)d[u]!==null?f[u]!==d[u]&&u!=="ychange"&&e.setAttribute(u,d[u]):e.removeAttribute(u);for(let u in f)d[u]===void 0&&e.removeAttribute(u)}let i=Xo(t),s=i.length,o=e.toArray(),l=o.length,c=Re(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let d=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(d instanceof Me&&u instanceof Array)im(d,u)||Jx(d,u,r),a+=1;else{let g=d instanceof ne&&va(d,u),y=p instanceof ne&&va(p,m);if(g&&y){let E=tm(d,u,r),N=tm(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+f).forEach(d=>r.delete(d)),e.delete(a,f)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var ts=null,jx=()=>{let n=ts;ts=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Ua=(n,e,t)=>{ts||(ts=new Map,Ii(0,jx)),W(ts,n,_).set(e,t)},Jn=(n,e,t)=>{if(n===0)return Ji(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof Me){if(r._length>=n)return Ji(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ht(r._item===null?null:r._item.id,r._item===null?Fn(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ht(r._item===null?null:r._item.id,r._item===null?Fn(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw F();if(n===0&&r.constructor!==Me&&r!==e)return Wx(r._item.parent,r._item)}return Ji(e,e._length,-1)},Wx=(n,e)=>{let t=null,r=null;return n._item===null?r=Fn(n):t=M(n._item.id.client,n._item.id.clock),new ht(t,r,e.id)},en=(n,e,t,r)=>{let i=ba(t,n);if(i===null||i.type!==e&&!vn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===Me)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Lr(r,t,n,new Map),t}function lm(n,e){let t=Ba(e);return Be.fromJSON(n,t)}function Ba(n,e="prosemirror"){return Pa(n.getXmlFragment(e))}function Pa(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Kx=(n,e,t)=>n!==e,Yx=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},Gx=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Xx=/^#[0-9a-fA-F]{6}$/,cm=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?L.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Xx.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let f=en(o,s.type,$n(c.cursor.anchor),s.binding.mapping),d=en(o,s.type,$n(c.cursor.head),s.binding.mapping);if(f!==null&&d!==null){let u=$e(n.doc.content.size-1,0);f=Re(f,u),d=Re(d,u),l.push(se.widget(d,()=>r(h),{key:a+"",side:10}));let p=Re(f,d),m=$e(f,d);l.push(se.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(n.doc,l))},Qx=(n,{awarenessStateFilter:e=Kx,cursorBuilder:t=Yx,selectionBuilder:r=Gx,getSelection:i=o=>o.selection}={},s="cursor")=>new J({key:Gi,state:{init(o,l){return cm(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),f=o.getMeta(Gi);return h&&h.isChangeOrigin||f&&f.awarenessUpdated?cm(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Gi.getState(o)},view:o=>{let l=()=>{o.docView&&Ua(o,Gi,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let f=i(o.state),d=Jn(f.anchor,a.type,a.binding.mapping),u=Jn(f.head,a.type,a.binding.mapping);(h.cursor==null||!zo($n(h.cursor.anchor),d)||!zo($n(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:d,head:u})}else h.cursor!=null&&en(a.doc,a.type,$n(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Zx=n=>{let e=Rt.getState(n).undoManager;if(e!=null)return e.undo(),!0},eS=n=>{let e=Rt.getState(n).undoManager;if(e!=null)return e.redo(),!0},tS=new Set(["paragraph"]),nS=(n,e)=>!(n instanceof O)||!(n.content instanceof Oe)||!(n.content.type instanceof dt||n.content.type instanceof ne&&e.has(n.content.type.nodeName))||n.content.type._length===0,rS=({protectedNodes:n=tS,trackedOrigins:e=[],undoManager:t=null}={})=>new J({key:Rt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new _n(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>nS(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Zi(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Rt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Rt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var ns="http://www.w3.org/2000/svg",iS="http://www.w3.org/1999/xlink",za="ProseMirror-icon",La="pm-close-dropdowns";function sS(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(Qe+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,am(r,Qe+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;am(r,Qe+"-active",l)}return!0}return{dom:r,update:i}}};function Qo(n,e){return n._props.translate?n._props.translate(e):e}var rs={time:0,node:null};function cS(n){rs.time=Date.now(),rs.node=n.target}function aS(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(La,c))};i.addEventListener("mousedown",f=>{f.preventDefault(),cS(f),o?a():(r.dispatchEvent(new CustomEvent(La)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{aS(s)||a()}),r.addEventListener(La,c=()=>{a()}))});function h(f){let d=t.update(f);return s.style.display=d?"":"none",d}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${Qe}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${Qe}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=kt("div",{class:Qe+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function hS(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;ioi(n),icon:is.join}),AM=new pt({title:"Lift out of enclosing block",run:li,select:n=>li(n),icon:is.lift}),EM=new pt({title:"Select parent node",run:ci,select:n=>ci(n),icon:is.selectParentNode}),TM=new pt({title:"Undo last change",run:fi,enable:n=>fi(n),icon:is.undo}),DM=new pt({title:"Redo last undone change",run:or,enable:n=>or(n),icon:is.redo});function uS(n,e){let t={run(r,i){return sr(n,e.attrs)(r,i)},select(r){return sr(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new pt(t)}function pS(n,e){let t=bn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new pt(r)}function am(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{Wn as DOMParser,Ut as DOMSerializer,Fa as Dropdown,bl as EditorState,$l as EditorView,w as Fragment,Ct as InputRule,pt as MenuItem,k as NodeSelection,J as Plugin,fe as PluginKey,qr as Schema,b as Slice,A as TextSelection,Ia as WebsocketProvider,Vr as Y,nw as addColumnAfter,tw as addColumnBefore,f0 as addListNodes,lw as addRowAfter,ow as addRowBefore,td as baseKeymap,zy as baseSchema,pS as blockTypeItem,P0 as buildKeymap,Tw as columnResizing,iw as deleteColumn,aw as deleteRow,yw as deleteTable,Md as fixTables,O0 as gapCursor,gw as goToNextCell,ld as inputRules,Ye as isInTable,x0 as keymap,tc as liftListItem,fw as mergeCells,om as prosemirrorToYDoc,Va as prosemirrorToYXmlFragment,fS as renderGrouped,Ge as selectedRect,bn as setBlockType,nc as sinkListItem,dw as splitCell,ec as splitListItem,Pw as tableEditing,q0 as tableNodes,xn as toggleMark,sr as wrapIn,Us as wrapInList,uS as wrapItem,Qx as yCursorPlugin,lm as yDocToProsemirror,Ba as yDocToProsemirrorJSON,eS as yRedo,nm as ySyncPlugin,Zx as yUndo,rS as yUndoPlugin,Rt as yUndoPluginKey,Pa as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index a3e71b97..b5d88189 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -8,7 +8,6 @@ import { addListNodes, wrapInList, splitListItem, liftListItem, sinkListItem } f import { keymap } from 'prosemirror-keymap'; import { buildKeymap } from 'prosemirror-example-setup'; import { gapCursor } from 'prosemirror-gapcursor'; -import { dropCursor } from 'prosemirror-dropcursor'; import { tableEditing, @@ -85,7 +84,6 @@ export { splitCell, deleteTable, gapCursor, - dropCursor, MenuItem, Dropdown, renderGrouped, diff --git a/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js b/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js index 077b7fbe..f5995612 100644 --- a/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js +++ b/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js @@ -14,48 +14,6 @@ describe('tableDragHandle Plugin', () => { plugin = tableDragHandle(); }); - describe('Drop handler', () => { - it('allows file drops to pass through (returns false)', () => { - const mockView = {}; - const mockEvent = { dataTransfer: { files: [{ name: 'image.png' }] } }; - - const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); - expect(result).to.be.false; - }); - - it('allows table drops (returns false)', () => { - const mockView = { dragging: { slice: { content: { firstChild: { type: { name: 'table' } } } } } }; - const mockEvent = { dataTransfer: { files: [] } }; - - const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); - expect(result).to.be.false; - }); - - it('blocks non-table internal drops (returns true)', () => { - const mockView = { dragging: { slice: { content: { firstChild: { type: { name: 'paragraph' } } } } } }; - const mockEvent = { dataTransfer: { files: [] } }; - - const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); - expect(result).to.be.true; - }); - - it('blocks drops with no dragging context (returns true)', () => { - const mockView = { dragging: null }; - const mockEvent = { dataTransfer: { files: [] } }; - - const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); - expect(result).to.be.true; - }); - - it('handles empty slice content gracefully', () => { - const mockView = { dragging: { slice: { content: { firstChild: null } } } }; - const mockEvent = { dataTransfer: { files: [] } }; - - const result = plugin.props.handleDOMEvents.drop(mockView, mockEvent); - expect(result).to.be.true; - }); - }); - describe('View initialization', () => { let mockEditorView; let container; @@ -89,12 +47,11 @@ describe('tableDragHandle Plugin', () => { container.remove(); }); - it('creates and appends drag handle element', () => { + it('creates and appends handle element', () => { const viewReturn = plugin.spec.view(mockEditorView); const handle = container.querySelector('.table-drag-handle'); expect(handle).to.exist; - expect(handle.draggable).to.be.true; expect(handle.classList.contains('is-visible')).to.be.false; viewReturn.destroy(); @@ -168,34 +125,5 @@ describe('tableDragHandle Plugin', () => { viewReturn.destroy(); }); - - it('hides handle on dragend', () => { - const viewReturn = plugin.spec.view(mockEditorView); - - const tableWrapper = document.createElement('div'); - tableWrapper.className = 'tableWrapper'; - const table = document.createElement('table'); - tableWrapper.appendChild(table); - editorDom.appendChild(tableWrapper); - - // Show the handle first - const mouseoverEvent = new MouseEvent('mouseover', { - bubbles: true, - target: tableWrapper, - }); - Object.defineProperty(mouseoverEvent, 'target', { value: tableWrapper }); - editorDom.dispatchEvent(mouseoverEvent); - - const handle = container.querySelector('.table-drag-handle'); - expect(handle.classList.contains('is-visible')).to.be.true; - - // Trigger dragend - const dragendEvent = new Event('dragend', { bubbles: true }); - handle.dispatchEvent(dragendEvent); - - expect(handle.classList.contains('is-visible')).to.be.false; - - viewReturn.destroy(); - }); }); }); From 89ca65b0ae2c78f501987012cfce69ff0417e388 Mon Sep 17 00:00:00 2001 From: Usman Khalid Date: Wed, 25 Feb 2026 11:46:01 -0500 Subject: [PATCH 3/3] chore: rename drag references to select --- blocks/edit/da-editor/da-editor.css | 8 ++++---- .../img/{drag-handle.svg => select-handle.svg} | 0 blocks/edit/prose/index.js | 4 ++-- ...tableDragHandle.js => tableSelectHandle.js} | 4 ++-- ...andle.test.js => tableSelectHandle.test.js} | 18 +++++++++--------- 5 files changed, 17 insertions(+), 17 deletions(-) rename blocks/edit/img/{drag-handle.svg => select-handle.svg} (100%) rename blocks/edit/prose/plugins/{tableDragHandle.js => tableSelectHandle.js} (97%) rename test/unit/blocks/edit/prose/plugins/{tableDragHandle.test.js => tableSelectHandle.test.js} (87%) diff --git a/blocks/edit/da-editor/da-editor.css b/blocks/edit/da-editor/da-editor.css index 1c63b90a..c191bc0d 100644 --- a/blocks/edit/da-editor/da-editor.css +++ b/blocks/edit/da-editor/da-editor.css @@ -983,12 +983,12 @@ da-diff-deleted, da-diff-added { color: #0265dc; } -.table-drag-handle { +.table-select-handle { position: absolute; width: 20px; height: 20px; background-color: #fff; - background-image: url('/blocks/edit/img/drag-handle.svg'); + background-image: url('/blocks/edit/img/select-handle.svg'); background-repeat: no-repeat; background-position: center; border: 1px solid #ccc; @@ -1000,11 +1000,11 @@ da-diff-deleted, da-diff-added { justify-content: center; } -.table-drag-handle.is-visible { +.table-select-handle.is-visible { display: flex; } -.table-drag-handle:hover { +.table-select-handle:hover { background-color: #f0f7ff; border-color: var(--s2-blue-800); } diff --git a/blocks/edit/img/drag-handle.svg b/blocks/edit/img/select-handle.svg similarity index 100% rename from blocks/edit/img/drag-handle.svg rename to blocks/edit/img/select-handle.svg diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js index 7c22cd7f..2e298d85 100644 --- a/blocks/edit/prose/index.js +++ b/blocks/edit/prose/index.js @@ -29,7 +29,7 @@ import { linkItem } from './plugins/menu/linkItem.js'; import codemark from './plugins/codemark.js'; import imageDrop from './plugins/imageDrop.js'; import imageFocalPoint from './plugins/imageFocalPoint.js'; -import tableDragHandle from './plugins/tableDragHandle.js'; +import tableSelectHandle from './plugins/tableSelectHandle.js'; import linkConverter from './plugins/linkConverter.js'; import linkTextSync from './plugins/linkTextSync.js'; import sectionPasteHandler from './plugins/sectionPasteHandler.js'; @@ -348,7 +348,7 @@ export default function initProse({ path, permissions }) { trackCursorAndChanges(), slashMenu(), linkMenu(), - tableDragHandle(), + tableSelectHandle(), imageDrop(schema), linkConverter(schema), linkTextSync(), diff --git a/blocks/edit/prose/plugins/tableDragHandle.js b/blocks/edit/prose/plugins/tableSelectHandle.js similarity index 97% rename from blocks/edit/prose/plugins/tableDragHandle.js rename to blocks/edit/prose/plugins/tableSelectHandle.js index 1dc3d2b9..304a87bf 100644 --- a/blocks/edit/prose/plugins/tableDragHandle.js +++ b/blocks/edit/prose/plugins/tableSelectHandle.js @@ -22,7 +22,7 @@ function getTablePos(view, tableEl) { /** * Allows selecting an entire table by clicking an icon in the top left corner. */ -export default function tableDragHandle() { +export default function tableSelectHandle() { let handle = null; let currentTable = null; let currentWrapper = null; @@ -45,7 +45,7 @@ export default function tableDragHandle() { function createHandle(view) { const el = document.createElement('div'); - el.className = 'table-drag-handle'; + el.className = 'table-select-handle'; el.contentEditable = 'false'; el.addEventListener('mousedown', (e) => { diff --git a/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js b/test/unit/blocks/edit/prose/plugins/tableSelectHandle.test.js similarity index 87% rename from test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js rename to test/unit/blocks/edit/prose/plugins/tableSelectHandle.test.js index f5995612..771ec123 100644 --- a/test/unit/blocks/edit/prose/plugins/tableDragHandle.test.js +++ b/test/unit/blocks/edit/prose/plugins/tableSelectHandle.test.js @@ -1,17 +1,17 @@ import { expect } from '@esm-bundle/chai'; import sinon from 'sinon'; -describe('tableDragHandle Plugin', () => { - let tableDragHandle; +describe('tableSelectHandle Plugin', () => { + let tableSelectHandle; let plugin; before(async () => { - const mod = await import('../../../../../../blocks/edit/prose/plugins/tableDragHandle.js'); - tableDragHandle = mod.default; + const mod = await import('../../../../../../blocks/edit/prose/plugins/tableSelectHandle.js'); + tableSelectHandle = mod.default; }); beforeEach(() => { - plugin = tableDragHandle(); + plugin = tableSelectHandle(); }); describe('View initialization', () => { @@ -50,7 +50,7 @@ describe('tableDragHandle Plugin', () => { it('creates and appends handle element', () => { const viewReturn = plugin.spec.view(mockEditorView); - const handle = container.querySelector('.table-drag-handle'); + const handle = container.querySelector('.table-select-handle'); expect(handle).to.exist; expect(handle.classList.contains('is-visible')).to.be.false; @@ -60,12 +60,12 @@ describe('tableDragHandle Plugin', () => { it('removes handle on destroy', () => { const viewReturn = plugin.spec.view(mockEditorView); - let handle = container.querySelector('.table-drag-handle'); + let handle = container.querySelector('.table-select-handle'); expect(handle).to.exist; viewReturn.destroy(); - handle = container.querySelector('.table-drag-handle'); + handle = container.querySelector('.table-select-handle'); expect(handle).to.be.null; }); }); @@ -120,7 +120,7 @@ describe('tableDragHandle Plugin', () => { Object.defineProperty(event, 'target', { value: tableWrapper }); editorDom.dispatchEvent(event); - const handle = container.querySelector('.table-drag-handle'); + const handle = container.querySelector('.table-select-handle'); expect(handle.classList.contains('is-visible')).to.be.true; viewReturn.destroy();