diff --git a/Docker-AIO/Dockerfile b/Docker-AIO/Dockerfile index b1acd2f..af5d0e6 100644 --- a/Docker-AIO/Dockerfile +++ b/Docker-AIO/Dockerfile @@ -39,7 +39,8 @@ RUN cd Web-App && go build -trimpath -ldflags "-s -w -X main.Version=${VERSION}" FROM alpine:3.22 ARG PB_VERSION=0.40.6 ARG TARGETARCH -RUN apk add --no-cache ca-certificates unzip wget \ +# ffmpeg cuts long recordings into pieces for transcription (ADR-15). +RUN apk add --no-cache ca-certificates unzip wget ffmpeg \ && wget -q "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${TARGETARCH:-amd64}.zip" -O /tmp/pb.zip \ && unzip /tmp/pb.zip pocketbase -d /usr/local/bin && rm /tmp/pb.zip && apk del unzip COPY --from=build /out/ /usr/local/bin/ diff --git a/Docs-Site/guide/administration.md b/Docs-Site/guide/administration.md index 99767ce..dee7caa 100644 --- a/Docs-Site/guide/administration.md +++ b/Docs-Site/guide/administration.md @@ -50,12 +50,15 @@ Docwell brings no AI of its own: you choose a provider, and nothing is sent anyw *Workspace settings → AI* and use them before (or instead of) the server's. A provider is an OpenAI-compatible API (OpenAI, Azure, OpenRouter, LiteLLM, vLLM, LocalAI…), Anthropic, or Ollama, with a chat model and, except for Anthropic, optionally an embedding model; OpenAI-compatible providers can also have a speech-to-text model - (for example `whisper-1`) for transcribing recordings. Providers are tried from the top: when one fails, the next one + (for example `whisper-1`, or a self-hosted faster-whisper or LocalAI server) for transcribing recordings; + Anthropic and Ollama have no speech-to-text API. Recordings over 25 MB are cut into pieces with ffmpeg (in the + Docker images; without it only MP3 and WAV can be cut). Providers are tried from the top: when one fails, the next one answers. **Test** checks a provider; requests and tokens are counted per provider. - **Search by meaning.** *Index pages for AI* in a workspace's settings sends every page's text to the first provider with an embedding model and keeps the vectors in `DOCWELL_DATA_DIR`. Without it, the chat finds sources with keyword search. Pages can be left out (with their subpages), and extra text, Markdown, HTML, Word or PDF files - can be added as sources. Changing the embedding model indexes the workspace again. + can be added as sources; a scanned PDF without a text layer is read by an Anthropic or OpenAI chat model that + handles documents. Changing the embedding model indexes the workspace again. - **Limits.** Usage is counted per workspace and month (UTC). A workspace admin can set a monthly token limit for the workspace; a superadmin can cap what each workspace may use through the server's providers (*Admin panel → AI*, which also lists every workspace's usage). When the server's cap is reached, a workspace's own providers diff --git a/Docs-Site/guide/using-docwell.md b/Docs-Site/guide/using-docwell.md index f0e110d..8b1b849 100644 --- a/Docs-Site/guide/using-docwell.md +++ b/Docs-Site/guide/using-docwell.md @@ -143,8 +143,11 @@ puts it in the page, where undo and page history work as for any edit. Audio and video files in a page get a **Transcribe** button when the workspace has a speech-to-text model: it adds a summary with key points and action items below the file, and the full transcript in a toggle. -The phone app has the same chat: the ✦ button on the home screen asks about the workspace, on a page about that -page. +Long recordings are cut into pieces and transcribed one after another, so they take a while. + +On the phone the ✦ button on the home screen asks about the workspace, and on a page about that page. While +editing, the ✦ button in the toolbar offers the same writing actions for the selected text, and audio files have +the Transcribe button too. AI only ever reads what you can open yourself. diff --git a/Packages/editor-bridge/dist/index.html b/Packages/editor-bridge/dist/index.html index 2f35af0..6b39796 100644 --- a/Packages/editor-bridge/dist/index.html +++ b/Packages/editor-bridge/dist/index.html @@ -102,19 +102,19 @@ img.ProseMirror-separator { display: block; }`,Vp=class extends of{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:_d,createMappablePosition:vd},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=Cl(t,this.options.autofocus);this.editorState=zn.create({doc:t,schema:this.schema,selection:e||void 0})}Rp(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():Xc.createFakeChain()}can(){return this.commandManager?this.commandManager.can():Xc.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=Of(Bp,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.editorView&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return sf&&!this.hasWarnedStaleDecorationRead&&af(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Mu(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[Ap,Ep.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Dp,Mp,Np,Fp.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),kp,Pp,Op,Ip.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions!=`object`||this.options.enableCoreExtensions[e.name]!==!1):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new wp(n,this)}createCommandManager(){this.commandManager=new Xc({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=zn.create({doc:t,schema:this.schema,selection:Cl(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return Mu(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new tc(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc)||this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return Xu(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return sd(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return xu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=` -`,textSerializers:n={}}=e||{};return qu(this.state.doc,{blockSeparator:t,textSerializers:{...Ju(this.schema),...n}})}get isEmpty(){return fd(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new zp(t,this,!1,n)}get $doc(){return this.$pos(0)}};function Hp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Up(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Wp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=Nu(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function Gp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=Nu(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&Ft(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&qt(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var Kp=e=>`touches`in e,qp=class{constructor(e){var t;this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.element.draggable=!1,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e!=null&&(t=e.options)!=null&&t.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type&&(this.node=e,!this.onUpdate||this.onUpdate(e,t,n))}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=this.node.type.isInline?`inline-flex`:`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,Kp(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}},Jp=class e extends gp{constructor(...e){super(...e),this.type=`node`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Yp(e){return new vp({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=Nu(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;dn.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Xp=()=>new Map,Zp=e=>{let t=Xp();return e.forEach((e,n)=>{t.set(n,e)}),t},Qp=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},$p=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},em=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},tm=()=>new Set,nm=e=>e[e.length-1],rm=(e,t)=>{for(let n=0;n{for(let n=0;n{for(let n=0;n{let n=Array(e);for(let r=0;r{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return im((this._observers.get(e)||Xp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Xp()}},um=class{constructor(){this._observers=Xp()}on(e,t){Qp(this._observers,e,tm).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return im((this._observers.get(e)||Xp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Xp()}},dm=Math.floor,fm=Math.abs,pm=(e,t)=>ee>t?e:t;Number.isNaN;var hm=e=>e===0?1/e<0:e<0,gm=1<<29,_m=2**53-1,vm=-(2**53-1),ym=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&dm(e)===e);Number.isNaN,Number.parseInt;var bm=String.fromCharCode;String.fromCodePoint,bm(65535);var xm=e=>e.toLowerCase(),Sm=/^\s*/g,Cm=e=>e.replace(Sm,``),wm=/([A-Z])/g,Tm=(e,t)=>Cm(e.replace(wm,e=>`${t}${xm(e)}`)),Em=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;eDm.encode(e):Em,km=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});km&&km.decode(new Uint8Array).length===1&&(km=null);var Am=(e,t)=>sm(t,()=>e).join(``),jm=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Mm=()=>new jm,Nm=e=>{let t=Mm();return e(t),Fm(t)},Pm=e=>{let t=e.cpos;for(let n=0;n{let t=new Uint8Array(Pm(e)),n=0;for(let r=0;r{let n=e.cbuf.length;n-e.cpos{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Rm=Lm,j=(e,t)=>{for(;t>127;)Lm(e,128|127&t),t=dm(t/128);Lm(e,127&t)},zm=(e,t)=>{let n=hm(t);for(n&&(t=-t),Lm(e,(t>63?128:0)|(n?64:0)|63&t),t=dm(t/64);t>0;)Lm(e,(t>127?128:0)|127&t),t=dm(t/128)},Bm=new Uint8Array(3e4),Vm=Bm.length/3,Hm=Dm&&Dm.encodeInto?(e,t)=>{if(t.length{let n=unescape(encodeURIComponent(t)),r=n.length;j(e,r);for(let t=0;t{let n=e.cbuf.length,r=e.cpos,i=pm(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(mm(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Wm=(e,t)=>{j(e,t.byteLength),Um(e,t)},Gm=(e,t)=>{Im(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Km=(e,t)=>Gm(e,4).setFloat32(0,t,!1),qm=(e,t)=>Gm(e,8).setFloat64(0,t,!1),Jm=(e,t)=>Gm(e,8).setBigInt64(0,t,!1),Ym=new DataView(new ArrayBuffer(4)),Xm=e=>(Ym.setFloat32(0,e),Ym.getFloat32(0)===e),Zm=(e,t)=>{switch(typeof t){case`string`:Lm(e,119),Hm(e,t);break;case`number`:ym(t)&&fm(t)<=2147483647?(Lm(e,125),zm(e,t)):Xm(t)?(Lm(e,124),Km(e,t)):(Lm(e,123),qm(e,t));break;case`bigint`:Lm(e,122),Jm(e,t);break;case`object`:if(t===null)Lm(e,126);else if(cm(t)){Lm(e,117),j(e,t.length);for(let n=0;n0&&j(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},$m=e=>{e.count>0&&(zm(e.encoder,e.count===1?e.s:-e.s),e.count>1&&j(e.encoder,e.count-2))},eh=class{constructor(){this.encoder=new jm,this.s=0,this.count=0}write(e){this.s===e?this.count++:($m(this),this.count=1,this.s=e)}toUint8Array(){return $m(this),Fm(this.encoder)}},th=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);zm(e.encoder,t),e.count>1&&j(e.encoder,e.count-2)}},nh=class{constructor(){this.encoder=new jm,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(th(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return th(this),Fm(this.encoder)}},rh=class{constructor(){this.sarr=[],this.s=``,this.lensE=new eh}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 jm;return this.sarr.push(this.s),this.s=``,Hm(e,this.sarr.join(``)),Um(e,this.lensE.toUint8Array()),Fm(e)}},ih=e=>Error(e),ah=()=>{throw ih(`Method unimplemented`)},oh=()=>{throw ih(`Unexpected case`)},sh=ih(`Unexpected end of array`),ch=ih(`Integer out of Range`),lh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sh;return new Uint8Array(e.buffer,e.byteOffset+t,n)},uh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sh;return new DataView(e.buffer,e.byteOffset+t,n)},dh=class{constructor(e){this.arr=e,this.pos=0}},fh=e=>new dh(e),ph=e=>e.pos!==e.arr.length,mh=(e,t)=>{let n=lh(e.arr,e.pos,t);return e.pos+=t,n},hh=e=>mh(e,M(e)),gh=e=>e.arr[e.pos++],M=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos_m)throw ch}throw sh},_h=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos_m)throw ch}throw sh},vh=km?e=>km.decode(hh(e)):e=>{let t=M(e);if(t===0)return``;{let n=String.fromCodePoint(gh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(gh(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},yh=(e,t)=>{let n=uh(e.arr,e.pos,t);return e.pos+=t,n},bh=[e=>void 0,e=>null,_h,e=>yh(e,4).getFloat32(0,!1),e=>yh(e,8).getFloat64(0,!1),e=>yh(e,8).getBigInt64(0,!1),e=>!1,e=>!0,vh,e=>{let t=M(e),n={};for(let r=0;r{let t=M(e),n=[];for(let r=0;rbh[127-gh(e)](e),Sh=class extends dh{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=ph(this)?M(this)+1:-1),this.count--,this.s}},Ch=class extends dh{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=_h(this);let e=hm(this.s);this.count=1,e&&(this.s=-this.s,this.count=M(this)+2)}return this.count--,this.s}},wh=class extends dh{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=_h(this),t=e&1;this.diff=dm(e/2),this.count=1,t&&(this.count=M(this)+2)}return this.s+=this.diff,this.count--,this.s}},Th=class{constructor(e){this.decoder=new Ch(e),this.str=vh(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var Eh=crypto.getRandomValues.bind(crypto),Dh=Math.random,Oh=()=>Eh(new Uint32Array(1))[0],kh=e=>e[dm(Dh()*e.length)],Ah=`10000000-1000-4000-8000-100000000000`,jh=()=>Ah.replace(/[018]/g,e=>(e^Oh()&15>>e/4).toString(16)),Mh=Date.now,Nh=e=>new Promise(e);Promise.all.bind(Promise);var Ph=e=>e===void 0?null:e,Fh=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Fh=localStorage)}catch{}var Ih=Fh,Lh=Symbol(`Equality`),Rh=(e,t)=>e===t||!!e?.[Lh]?.(t)||!1,zh=e=>typeof e==`object`,Bh=Object.assign,Vh=Object.keys,Hh=(e,t)=>{for(let n in e)t(e[n],n)},Uh=e=>Vh(e).length,Wh=e=>{for(let t in e)return!1;return!0},Gh=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Kh=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),qh=(e,t)=>e===t||Uh(e)===Uh(t)&&Gh(e,(e,n)=>(e!==void 0||Kh(t,n))&&Rh(t[n],e)),Jh=Object.freeze,Yh=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Yh(e[t])}return Jh(e)},Xh=(e,t,n=0)=>{try{for(;ne,Qh=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Lh]!=null)return e[Lh](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;nt.includes(e),eg=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,tg=typeof window<`u`&&typeof document<`u`&&!eg;typeof navigator<`u`&&/Mac/.test(navigator.platform);var ng,rg=[],ig=()=>{if(ng===void 0){if(eg){ng=Xp();let e=process.argv,t=null;for(let n=0;n{if(e.length!==0){let[t,n]=e.split(`=`);ng.set(`--${Tm(t,`-`)}`,n),ng.set(`-${Tm(t,`-`)}`,n)}})):ng=Xp()}return ng},ag=e=>ig().has(e),og=e=>Ph(eg?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Ih.getItem(e)),sg=e=>ag(`--`+e)||og(e)!==null,cg=sg(`production`),lg=eg&&$h({}.FORCE_COLOR,[`true`,`1`,`2`])||!ag(`--no-colors`)&&!sg(`no-color`)&&(!eg||process.stdout.isTTY)&&(!eg||ag(`--color`)||og(`COLORTERM`)!==null||(og(`TERM`)||``).includes(`color`)),ug=e=>new Uint8Array(e),dg=e=>{let t=``;for(let n=0;nBuffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),pg=e=>{let t=atob(e),n=ug(t.length);for(let e=0;enew Uint8Array(Buffer.from(e,`base64`)),hg=tg?dg:fg,gg=tg?pg:mg,_g=e=>{let t=ug(e.byteLength);return t.set(e),t},vg=e=>Nm(t=>Zm(t,e)),yg=class{constructor(e,t){this.left=e,this.right=t}},bg=(e,t)=>new yg(e,t),xg=e=>e.next()>=.5,Sg=(e,t,n)=>dm(e.next()*(n+1-t)+t),Cg=(e,t,n)=>dm(e.next()*(n+1-t)+t),wg=(e,t,n)=>Cg(e,t,n),Tg=e=>bm(wg(e,97,122)),Eg=(e,t=0,n=20)=>{let r=wg(e,t,n),i=``;for(let t=0;tt[wg(e,0,t.length-1)],Og=Symbol(`0schema`),kg=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Am(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(` -`)}},Ag=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Lh]?Rh(e,t):cm(e)?am(e,e=>om(t,t=>Ag(e,t))):zh(e)?Gh(e,(e,n)=>Ag(e,t[n])):!1,jg=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ag(t,n)}equals(e){return this.constructor===e.constructor&&Qh(this.shape,e.shape)}[Og](){return!0}[Lh](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){ah()}get nullable(){return u_(this,T_)}get optional(){return new Hg(this)}cast(e){return k_(e,this),e}expect(e){return k_(e,this),e}},Mg=class extends jg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Ng=(e,t=null)=>new Mg(e,t);Ng(Mg);var Pg=class extends jg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Fg=e=>new Pg(e);Ng(Pg);var Ig=class extends jg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},Lg=(...e)=>new Ig(e),Rg=Ng(Ig),zg=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Bg=e=>{if(b_.check(e))return[zg(e)];if(Rg.check(e))return e.shape.map(e=>e+``);if(y_.check(e))return[`[+-]?\\d+.?\\d*`];if(x_.check(e))return[`.*`];if(d_.check(e))return e.shape.map(Bg).flat(1);oh()};Ng(class extends jg{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Bg).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Vg=Symbol(`optional`),Hg=class extends jg{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Vg](){return!0}},Ug=Ng(Hg),Wg=class extends jg{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Wg,Ng(Wg);var Gg=class e extends jg{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Gh(this.shape,(n,r)=>{let i=this._isPartial&&!Kh(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Kg=e=>new Gg(e),qg=Ng(Gg),Jg=Fg(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Yg=class extends jg{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Gh(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},Xg=(e,t)=>new Yg(e,t),Zg=Ng(Yg),Qg=class extends jg{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Gh(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},$g=(...e)=>new Qg(e);Ng(Qg);var e_=class extends jg{constructor(e){super(),this.shape=e.length===1?e[0]:new l_(e)}check(e,t){let n=cm(e)&&am(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},t_=(...e)=>new e_(e),n_=Ng(e_),r_=Fg(e=>cm(e)),i_=class extends jg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},a_=(e,t=null)=>new i_(e,t);Ng(i_);var o_=a_(jg),s_=Ng(class extends jg{constructor(e){super(),this.len=e.length-1,this.args=$g(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),c_=Fg(e=>typeof e==`function`);Ng(class extends jg{constructor(e){super(),this.shape=e}check(e,t){let n=am(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var l_=class extends jg{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=om(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},u_=(...e)=>e.findIndex(e=>d_.check(e))>=0?u_(...e.map(e=>O_(e)).map(e=>d_.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new l_(e),d_=Ng(l_),f_=()=>!0,p_=Fg(f_),m_=Ng(Pg,e=>e.shape===f_),h_=Fg(e=>typeof e==`bigint`),g_=Fg(e=>e===h_),__=Fg(e=>typeof e==`symbol`);Fg(e=>e===__);var v_=Fg(e=>typeof e==`number`),y_=Fg(e=>e===v_),b_=Fg(e=>typeof e==`string`),x_=Fg(e=>e===b_),S_=Fg(e=>typeof e==`boolean`),C_=Fg(e=>e===S_),w_=Lg(void 0);Ng(Ig,e=>e.shape.length===1&&e.shape[0]===void 0),Lg(void 0);var T_=Lg(null),E_=Ng(Ig,e=>e.shape.length===1&&e.shape[0]===null);Ng(Uint8Array),Ng(Mg,e=>e.shape===Uint8Array);var D_=u_(v_,b_,T_,w_,h_,S_,__);(()=>{let e=t_(p_),t=Xg(b_,p_),n=u_(v_,b_,T_,S_,e,t);return e.shape=n,t.shape.values=n,n})();var O_=e=>{if(o_.check(e))return e;if(Jg.check(e)){let t={};for(let n in e)t[n]=O_(e[n]);return Kg(t)}if(r_.check(e))return u_(...e.map(O_));if(D_.check(e))return Lg(e);if(c_.check(e))return Ng(e);oh()},k_=cg?()=>{}:(e,t)=>{let n=new kg;if(!t.check(e,n))throw ih(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},A_=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:O_(e),h:t}),this}else(e){return this.if(p_,e)}done(){return(e,t)=>{for(let n=0;nnew A_(e))(p_).if(y_,(e,t)=>Sg(t,vm,_m)).if(x_,(e,t)=>Eg(t)).if(C_,(e,t)=>xg(t)).if(g_,(e,t)=>BigInt(Sg(t,vm,_m))).if(d_,(e,t)=>M_(t,Dg(t,e.shape))).if(qg,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Ug.check(i)){if(xg(t))continue;i=i.shape}n[r]=j_(i,t)}return n}).if(n_,(e,t)=>{let n=[],r=Cg(t,0,42);for(let i=0;iDg(t,e.shape)).if(E_,(e,t)=>null).if(s_,(e,t)=>{let n=M_(t,e.res);return()=>n}).if(m_,(e,t)=>M_(t,Dg(t,[v_,b_,T_,w_,h_,S_,t_(v_),Xg(u_(`a`,`b`,`c`),v_)]))).if(Zg,(e,t)=>{let n={},r=Sg(t,0,3);for(let i=0;ij_(O_(t),e),N_=typeof document<`u`?document:{};Fg(e=>e.nodeType===R_),typeof DOMParser<`u`&&new DOMParser,Fg(e=>e.nodeType===F_),Fg(e=>e.nodeType===I_);var P_=e=>$p(e,(e,t)=>`${t}:${e};`).join(``),F_=N_.ELEMENT_NODE,I_=N_.TEXT_NODE;N_.CDATA_SECTION_NODE,N_.COMMENT_NODE;var L_=N_.DOCUMENT_NODE;N_.DOCUMENT_TYPE_NODE;var R_=N_.DOCUMENT_FRAGMENT_NODE;Fg(e=>e.nodeType===L_);var z_=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),B_=(e,t)=>new z_(setTimeout(t,e)),V_=Symbol,H_=V_(),U_=V_(),W_=V_(),G_=V_(),K_=V_(),q_=V_(),J_=V_(),Y_=V_(),X_=V_(),Z_=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r0&&n.push(t.join(``));r{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Xp(),i=[],a=0;for(;a0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a{console.log(...$_(e)),nv.forEach(t=>t.print(e))},tv=(...e)=>{console.warn(...$_(e)),e.unshift(Y_),nv.forEach(t=>t.print(e))},nv=tm(),rv=e=>({[Symbol.iterator](){return this},next:e}),iv=(e,t)=>rv(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),av=(e,t)=>rv(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),ov=class{constructor(e,t){this.clock=e,this.len=t}},sv=class{constructor(){this.clients=new Map}},cv=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r{let n=0,r=e.length-1;for(;n<=r;){let i=dm((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t{let n=e.clients.get(t.client);return n!==void 0&&lv(n,t.clock)!==null},dv=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t=i.clock?e[n-1]=new ov(r.clock,mm(r.len,i.clock+i.len-r.clock)):(n{let t=new sv;for(let n=0;n{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t{Qp(e.clients,t,()=>[]).push(new ov(n,r))},mv=()=>new sv,hv=e=>{let t=mv();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t0&&t.clients.set(n,r)}),t},gv=(e,t)=>{j(e.restEncoder,t.clients.size),im(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),j(e.restEncoder,t);let r=n.length;j(e.restEncoder,r);for(let t=0;t{let t=new sv,n=M(e.restDecoder);for(let r=0;r0){let i=Qp(t.clients,n,()=>[]);for(let t=0;t{let r=new sv,i=M(e.restDecoder);for(let a=0;a0){let e=new Ov;return j(e.restEncoder,0),gv(e,r),e.toUint8Array()}return null},yv=Oh,bv=class e extends lm{constructor({guid:e=jh(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=yv(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new yy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Nh(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Nh(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&Ly(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(im(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Ly(this,e,t)}get(e,t=pb){let n=Qp(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==pb&&r!==t){if(r===pb){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Pb)}getText(e=``){return this.get(e,tx)}getMap(e=``){return this.get(e,Lb)}getXmlElement(e=``){return this.get(e,ox)}getXmlFragment(e=``){return this.get(e,ix)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,im(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ly(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},xv=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return M(this.restDecoder)}readDsLen(){return M(this.restDecoder)}},Sv=class extends xv{readLeftID(){return N(M(this.restDecoder),M(this.restDecoder))}readRightID(){return N(M(this.restDecoder),M(this.restDecoder))}readClient(){return M(this.restDecoder)}readInfo(){return gh(this.restDecoder)}readString(){return vh(this.restDecoder)}readParentInfo(){return M(this.restDecoder)===1}readTypeRef(){return M(this.restDecoder)}readLen(){return M(this.restDecoder)}readAny(){return xh(this.restDecoder)}readBuf(){return _g(hh(this.restDecoder))}readJSON(){return JSON.parse(vh(this.restDecoder))}readKey(){return vh(this.restDecoder)}},Cv=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=M(this.restDecoder),this.dsCurrVal}readDsLen(){let e=M(this.restDecoder)+1;return this.dsCurrVal+=e,e}},wv=class extends Cv{constructor(e){super(e),this.keys=[],M(e),this.keyClockDecoder=new wh(hh(e)),this.clientDecoder=new Ch(hh(e)),this.leftClockDecoder=new wh(hh(e)),this.rightClockDecoder=new wh(hh(e)),this.infoDecoder=new Sh(hh(e),gh),this.stringDecoder=new Th(hh(e)),this.parentInfoDecoder=new Sh(hh(e),gh),this.typeRefDecoder=new Ch(hh(e)),this.lenDecoder=new Ch(hh(e))}readLeftID(){return new Zv(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Zv(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 xh(this.restDecoder)}readBuf(){return hh(this.restDecoder)}readJSON(){return xh(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=mm(r,t[0].id.clock);let i=Cy(t,r);j(e.restEncoder,t.length-i),e.writeClient(n),j(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n{let r=new Map;n.forEach((e,n)=>{xy(t,n)>e&&r.set(n,e)}),by(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),j(e.restEncoder,r.size),im(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{kv(e,t.clients.get(n),n,r)})},jv=(e,t)=>{let n=Xp(),r=M(e.restDecoder);for(let i=0;i{let r=[],i=im(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new yy,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==$x){let i=Qp(d,u.id.client,()=>xy(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,xy(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i0)u=r.pop();else if(o!==null&&o.i0){let e=new Ov;return Av(e,s,new Map),j(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Nv=(e,t)=>Av(e,t.doc.store,t.beforeState),Pv=(e,t,n,r=new wv(e))=>Ly(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Mv(e,i,jv(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(nt)&&o.missing.set(e,t)}o.update=qy([o.update,a.update])}}else i.pendingStructs=a;let s=vv(r,e,i);if(i.pendingDs){let t=new wv(fh(i.pendingDs));M(t.restDecoder);let n=vv(t,e,i);i.pendingDs=s&&n?qy([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Fv(e.doc,t)}},n,!1),Fv=(e,t,n,r=wv)=>{let i=fh(t);Pv(i,e,n,new r(i))},Iv=(e,t,n)=>Fv(e,t,n,Sv),Lv=(e,t,n=new Map)=>{Av(e,t.store,n),gv(e,hv(t.store))},Rv=(e,t=new Uint8Array([0]),n=new Ov)=>{Lv(n,e,Vv(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Jy(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Ev)return Gy(r.map((e,t)=>t===0?e:$y(e)));if(n.constructor===Ov)return qy(r)}return r[0]},zv=(e,t)=>Rv(e,t,new Ev),Bv=e=>{let t=new Map,n=M(e.restDecoder);for(let r=0;rBv(new xv(fh(e))),Hv=(e,t)=>(j(e.restEncoder,t.size),im(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{j(e.restEncoder,t),j(e.restEncoder,n)}),e),Uv=(e,t)=>Hv(e,by(t.store)),Wv=(e,t=new Dv)=>(e instanceof Map?Hv(t,e):Uv(t,e),t.toUint8Array()),Gv=e=>Wv(e,new Tv),Kv=class{constructor(){this.l=[]}},qv=()=>new Kv,Jv=(e,t)=>e.l.push(t),Yv=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},Xv=(e,t,n)=>Xh(e.l,[t,n]),Zv=class{constructor(e,t){this.client=e,this.clock=t}},Qv=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,N=(e,t)=>new Zv(e,t),$v=e=>N(M(e),M(e)),ey=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw oh()},ty=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},ny=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ry=e=>new ny(e.type==null?null:N(e.type.client,e.type.clock),e.tname??null,e.item==null?null:N(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),iy=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},ay=(e,t,n=0)=>new iy(e,t,n),oy=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ey(e):r=N(e._item.id.client,e._item.id.clock),new ny(r,i,t,n)},sy=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return oy(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return oy(e,N(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return oy(e,r.lastId,n);r=r.right}return oy(e,null,n)},cy=e=>{let t=null,n=null,r=null;switch(M(e)){case 0:r=$v(e);break;case 1:n=vh(e);break;case 2:t=$v(e)}let i=ph(e)?_h(e):0;return new ny(t,n,r,i)},ly=e=>cy(fh(e)),uy=(e,t)=>{let n=wy(e,t);return{item:n,diff:t.clock-n.id.clock}},dy=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(xy(r,i.client)<=i.clock)return null;let e=n?Wx(r,i):uy(r,i),t=e.item;if(!(t instanceof Yx))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(xy(r,a.client)<=a.clock)return null;let{item:e}=n?Wx(r,a):{item:wy(r,a)};if(e instanceof Yx&&e.content instanceof Hx)c=e.content.type;else return null}else throw oh();l=s>=0?c._length:0}return ay(c,l,e.assoc)},fy=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qv(e.item,t.item)&&Qv(e.type,t.type)&&e.assoc===t.assoc,py=class{constructor(e,t){this.ds=e,this.sv=t}},my=(e,t)=>new py(e,t),hy=my(mv(),new Map),gy=e=>my(hv(e.store),by(e.store)),_y=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!uv(t.ds,e.id),vy=(e,t)=>{let n=Qp(e.meta,vy,tm),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t{}),n.add(t))},yy=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},by=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},xy=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Sy=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw oh()}n.push(t)},Cy=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=dm(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t{let n=e.clients.get(t.client);return n[Cy(n,t.clock)]},Ty=(e,t,n)=>{let r=Cy(t,n),i=t[r];return i.id.clock{let n=e.doc.store.clients.get(t.client);return n[Ty(e,n,t.clock)]},Dy=(e,t,n)=>{let r=t.clients.get(n.client),i=Cy(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==hx&&r.splice(i+1,0,Kx(e,a,n.clock-a.id.clock+1)),a},Oy=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Cy(r,t.id.clock)]=n},ky=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Ty(e,t,n),s;do s=t[o++],at.deleteSet.clients.size===0&&!em(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(dv(t.deleteSet),Nv(e,t),gv(e,t.deleteSet),!0),My=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Qp(e.changed,t,tm).add(n)},Ny=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Yx&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Py=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Cy(e,a.clock),i=e[r];r{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=pm(r.length-1,1+Cy(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Ny(r,e)}})},Iy=(e,t)=>{if(te.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),Xv(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Qb(n)})}),Xh(e,[])}finally{r.gc&&Py(a,i,r.gcFilter),Fy(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=mm(Cy(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Ny(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Cy(r,n);a+11||a>0&&Ny(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(ev(Y_,H_,`[yjs] `,U_,q_,`Changed the client-id because another client seems to be using it.`),r.clientID=yv()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Ev;jy(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Ov;jy(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Iy(e,t+1)}}},Ly=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Ay(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Iy(i,0)}}return o},Ry=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},zy=(e,t,n)=>{cv(e,n.deletions,n=>{n instanceof Yx&&t.scope.some(t=>t===e.doc||ty(t,n))&&Gx(n,!1)})},By=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;Ly(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;cv(n,o.insertions,e=>{if(e instanceof Yx){if(e.redone!==null){let{item:t,diff:i}=Wx(r,e.id);i>0&&(t=Ey(n,N(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||ty(t,e))&&c.push(e)}}),cv(n,o.deletions,e=>{e instanceof Yx&&a.some(t=>t===n.doc||ty(t,e))&&!uv(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Jx(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Vy=class extends lm{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=cm(e)?e[0].doc:e instanceof bv?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new sv;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&pv(i,n,r,a)});let a=Mh(),o=!1;if(this.lastChange>0&&a-this.lastChange0&&!t&&!n){let t=r[r.length-1];t.deletions=fv([t.deletions,e.deleteSet]),t.insertions=fv([t.insertions,i])}else r.push(new Ry(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),cv(e,e.deleteSet,t=>{t instanceof Yx&&this.scope.some(n=>n===e.doc||ty(n,t))&&Gx(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=cm(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof pb?e.doc!==this.doc:e!==this.doc)&&tv(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>zy(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>zy(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=By(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=By(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Hy(e){let t=M(e.restDecoder);for(let n=0;nqy(e,Sv,Ev),Ky=(e,t)=>{if(e.constructor===hx){let{client:n,clock:r}=e.id;return new hx(N(n,r+t),e.length-t)}if(e.constructor===$x){let{client:n,clock:r}=e.id;return new $x(N(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Yx(N(r,i+t),null,N(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},qy=(e,t=wv,n=Ov)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(fh(e))),i=r.map(e=>new Uy(e,!0)),a=null,o=new n,s=new Wy(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===$x?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Xy(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length0&&(a.struct.constructor===$x?a.struct.length-=t:n=Ky(n,t)),a.struct.mergeWith(n)||(Xy(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==$x;n=e.next())Xy(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Xy(s,a.struct,a.offset),a=null),Zy(s),gv(o,fv(r.map(e=>_v(e)))),o.toUint8Array()},Jy=(e,t,n=wv,r=Ov)=>{let i=Vv(t),a=new r,o=new Wy(a),s=new n(fh(e)),c=new Uy(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===$x)c.next();else if(e.id.clock+e.length>n)for(Xy(o,e,mm(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Xy(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Zy(o),gv(a,_v(s)),a.toUint8Array()},Yy=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Fm(e.encoder.restEncoder)}),e.encoder.restEncoder=Mm(),e.written=0)},Xy=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Yy(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),j(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Zy=e=>{Yy(e);let t=e.encoder.restEncoder;j(t,e.clientStructs.length);for(let n=0;n{let i=new n(fh(e)),a=new Uy(i,!1),o=new r,s=new Wy(o);for(let e=a.curr;e!==null;e=a.next())Xy(s,t(e),0);return Zy(s),gv(o,_v(i)),o.toUint8Array()},$y=e=>Qy(e,Zh,wv,Ev),eb=`You must not compute changes after the event-handler fired.`,tb=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||=nb(this.currentTarget,this.target)}deletes(e){return uv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ih(eb);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=nm(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=nm(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=nm(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw ih(eb);let t=this.target,n=tm(),r=tm(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},nb=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},rb=()=>{tv(`Invalid access: Add Yjs type to a document before reading data.`)},ib=80,ab=0,ob=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ab++}},sb=e=>{e.timestamp=ab++},cb=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ab++},lb=(e,t,n)=>{if(e.length>=ib){let r=e.reduce((e,t)=>e.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>fm(t-e.index)t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&fm(n.index-i){for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t0&&t===i.index)&&(i.index=mm(t,i.index+n))}},fb=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Qp(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Xv(r._eH,n,t)},pb=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=qv(),this._dEH=qv(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw ah()}clone(){throw ah()}_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){Jv(this._eH,e)}observeDeep(e){Jv(this._dEH,e)}unobserve(e){Yv(this._eH,e)}unobserveDeep(e){Yv(this._dEH,e)}toJSON(){}},mb=(e,t,n)=>{e.doc??rb(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},hb=e=>{e.doc??rb();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n{let n=[],r=e._start;for(;r!==null;){if(r.countable&&_y(r,t)){let e=r.content.getContent();for(let t=0;t{let n=0,r=e._start;for(e.doc??rb();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r{let n=[];return _b(e,(r,i)=>{n.push(t(r,i,e))}),n},yb=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},bb=(e,t)=>{e.doc??rb();let n=ub(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Yx(N(o,xy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Ax(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Yx(N(o,xy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new gx(new Uint8Array(n))),i.integrate(e,0);break;case bv:i=new Yx(N(o,xy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new xx(n)),i.integrate(e,0);break;default:if(n instanceof pb)i=new Yx(N(o,xy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Hx(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},Sb=()=>ih(`Length exceeded!`),Cb=(e,t,n,r)=>{if(n>t._length)throw Sb();if(n===0)return t._searchMarker&&db(t._searchMarker,n,r.length),xb(e,t,null,r);let i=n,a=ub(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return xb(e,t,r,n)},Tb=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=ub(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n0&&s!==null;)s.deleted||(r0)throw Sb();t._searchMarker&&db(t._searchMarker,i,-a+r)},Eb=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Db=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Ax([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Ax([r]);break;case Uint8Array:s=new gx(r);break;case bv:s=new xx(r);break;default:if(r instanceof pb)s=new Hx(r);else throw Error(`Unexpected content type`)}new Yx(N(o,xy(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Ob=(e,t)=>{e.doc??rb();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},kb=e=>{let t={};return e.doc??rb(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Ab=(e,t)=>{e.doc??rb();let n=e._map.get(t);return n!==void 0&&!n.deleted},jb=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&_y(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Mb=e=>(e.doc??rb(),iv(e._map.entries(),e=>!e[1].deleted)),Nb=class extends tb{},Pb=class e extends pb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof pb?e.clone():e)),t}get length(){return this.doc??rb(),this._length}_callObserver(e,t){super._callObserver(e,t),fb(this,e,new Nb(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ly(this.doc,n=>{Cb(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):Ly(this.doc,t=>{wb(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ly(this.doc,n=>{Tb(n,this,e,t)})}get(e){return bb(this,e)}toArray(){return hb(this)}slice(e=0,t=this.length){return mb(this,e,t)}toJSON(){return this.map(e=>e instanceof pb?e.toJSON():e)}map(e){return vb(this,e)}forEach(e){_b(this,e)}[Symbol.iterator](){return yb(this)}_write(e){e.writeTypeRef(Fx)}},Fb=e=>new Pb,Ib=class extends tb{constructor(e,t,n){super(e,t),this.keysChanged=n}},Lb=class e extends pb{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof pb?e.clone():e)}),t}_callObserver(e,t){fb(this,e,new Ib(this,e,t))}toJSON(){this.doc??rb();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof pb?r.toJSON():r}}),e}get size(){return[...Mb(this)].length}keys(){return av(Mb(this),e=>e[0])}values(){return av(Mb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return av(Mb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??rb(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):Ly(this.doc,t=>{Eb(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):Ly(this.doc,n=>{Db(n,this,e,t)}),t}get(e){return Ob(this,e)}has(e){return Ab(this,e)}clear(){this.doc===null?this._prelimContent.clear():Ly(this.doc,e=>{this.forEach(function(t,n,r){Eb(e,r,n)})})}_write(e){e.writeTypeRef(Ix)}},Rb=e=>new Lb,zb=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&qh(e,t),Bb=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&oh(),this.right.content.constructor){case Tx:this.right.deleted||Wb(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Vb=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Tx:t.right.deleted||Wb(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{let i=new Map,a=r?ub(t,n):null;return a?Vb(e,new Bb(a.p.left,a.p,a.index,i),n-a.index):Vb(e,new Bb(null,t._start,0,i),n)},Ub=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Tx&&zb(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Yx(N(a,xy(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Tx(o,r));l.integrate(e,0),n.right=l,n.forward()})},Wb=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Gb=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Tx&&zb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Kb=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!zb(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Yx(N(a,xy(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Tx(s,c)),n.right.integrate(e,0),n.forward()}}return o},qb=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Gb(n,i);let s=Kb(e,t,n,i),c=r.constructor===String?new Mx(r):r instanceof pb?new Hx(r):new Cx(r),{left:l,right:u,index:d}=n;t._searchMarker&&db(t._searchMarker,n.index,c.getLength()),u=new Yx(N(o,xy(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Ub(e,t,n,s)},Jb=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Gb(n,i);let s=Kb(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Tx));){if(!n.right.deleted)switch(n.right.content.constructor){case Tx:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(zb(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r0){let i=``;for(;r>0;r--)i+=` -`;n.right=new Yx(N(o,xy(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Mx(i)),n.right.integrate(e,0),n.forward()}Ub(e,t,n,s)},Yb=(e,t,n,r,i)=>{let a=t,o=Xp();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Tx){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Tx:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Wb(i,n);break}}}t=t.right}return s},Xb=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Tx){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Zb=e=>{let t=0;return Ly(e.doc,n=>{let r=e._start,i=e._start,a=Xp(),o=Zp(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Tx:Wb(o,i.content);break;default:t+=Yb(n,r,i,a,o),a=Zp(o),r=i}i=i.right}}),t},Qb=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&ky(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Tx&&e.constructor!==hx&&t.add(e.parent)})}Ly(n,n=>{cv(e,e.deleteSet,e=>{if(e instanceof hx||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Tx?t.add(r):Xb(n,e)});for(let e of t)Zb(e)})},$b=(e,t,n)=>{let r=n,i=Zp(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Hx:case Cx:case Mx:n{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];Ly(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Wh(o)||(e.attributes=Bh({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Hx:case Cx:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Mx:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Tx:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(zb(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),zb(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;zb(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(zb(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Wb(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},tx=class e extends pb{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??rb(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new ex(this,e,t);fb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??rb();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Mx&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):Ly(this.doc,n=>{let r=new Bb(null,this._start,0,new Map);for(let i=0;i0)&&qb(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&$b(n,r,a.delete):Jb(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??rb();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(_y(s,e)||t!==void 0&&_y(s,t))switch(s.content.constructor){case Mx:{let r=i.get(`ychange`);e!==void 0&&!_y(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!_y(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Hx:case Cx:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Tx:_y(s,e)&&(c(),Wb(i,s.content))}s=s.right}c()};return e||t?Ly(a,n=>{e&&vy(n,e),t&&vy(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):Ly(r,r=>{let i=Hb(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),qb(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Ly(r,r=>{let i=Hb(r,this,e,!n);qb(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):Ly(n,n=>{$b(n,Hb(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):Ly(r,r=>{let i=Hb(r,this,e,!1);i.right!==null&&Jb(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Ly(this.doc,t=>{Eb(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Ly(this.doc,n=>{Db(n,this,e,t)})}getAttribute(e){return Ob(this,e)}getAttributes(){return kb(this)}_write(e){e.writeTypeRef(Lx)}},nx=e=>new tx,rx=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??rb()}[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===ox||t.constructor===ix)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ix=class e extends pb{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof pb?e.clone():e)),t}get length(){return this.doc??rb(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new rx(this,e)}querySelector(e){e=e.toUpperCase();let t=new rx(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),im(new rx(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){fb(this,e,new cx(this,t,e))}toString(){return vb(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),_b(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ly(this.doc,n=>{Cb(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Ly(this.doc,n=>{let r=e&&e instanceof pb?e._item:e;xb(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw ih(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ly(this.doc,n=>{Tb(n,this,e,t)})}toArray(){return hb(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return bb(this,e)}slice(e=0,t=this.length){return mb(this,e,t)}forEach(e){_b(this,e)}_write(e){e.writeTypeRef(zx)}},ax=e=>new ix,ox=class e extends ix{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Hh(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof pb?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i0?` `+t.join(` `):``}>${super.toString()}`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):Ly(this.doc,t=>{Eb(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Ly(this.doc,n=>{Db(n,this,e,t)})}getAttribute(e){return Ob(this,e)}hasAttribute(e){return Ab(this,e)}getAttributes(e){return e?jb(this,e):kb(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return _b(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Rx),e.writeKey(this.nodeName)}},sx=e=>new ox(e.readKey()),cx=class extends tb{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},lx=class e extends Lb{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Bx),e.writeKey(this.hookName)}},ux=e=>new lx(e.readKey()),dx=class e extends tx{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.keye.nodeName`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=``;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Vx)}},fx=e=>new dx,px=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw ah()}mergeWith(e){return!1}write(e,t,n){throw ah()}integrate(e,t){throw ah()}},mx=0,hx=class extends px{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Sy(e.doc.store,this)}write(e,t){e.writeInfo(mx),e.writeLen(this.length-t)}getMissing(e,t){return null}},gx=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw ah()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},_x=e=>new gx(e.readBuf()),vx=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){pv(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}},yx=e=>new vx(e.readLen()),bx=(e,t)=>new bv({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),xx=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(bx(this.doc.guid,this.opts))}splice(e){throw ah()}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}},Sx=e=>new xx(bx(e.readString(),e.readAny())),Cx=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw ah()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},wx=e=>new Cx(e.readJSON()),Tx=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw ah()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},Ex=e=>new Tx(e.readKey(),e.readJSON()),Dx=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r{let t=e.readLen(),n=[];for(let r=0;r{let t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Nx=e=>new Mx(e.readString()),Px=[Fb,Rb,nx,sx,ax,ux,fx],Fx=0,Ix=1,Lx=2,Rx=3,zx=4,Bx=5,Vx=6,Hx=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw ah()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Ux=e=>new Hx(Px[e.readTypeRef()](e)),Wx=(e,t)=>{let n=t,r=0,i;do r>0&&(n=N(n.client,n.clock+r)),i=wy(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Yx);return{item:i,diff:r}},Gx=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Kx=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Yx(N(r,i+n),t,N(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=N(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},qx=(e,t)=>om(e,e=>uv(e.deletions,t)),Jx=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return Ey(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Jx(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=Ey(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Ey(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Ey(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||uv(r,d.right.id)||qx(a.undoStack,d.right.id)||qx(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Ey(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=N(c,xy(s,c)),h=new Yx(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Gx(h,!0),h.integrate(e,0),h},Yx=class e extends px{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=xy(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=xy(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zv&&this.id.client!==this.parent.client&&this.parent.clock>=xy(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Dy(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Ey(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===hx||this.right&&this.right.constructor===hx)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Zv){let e=wy(n,this.parent);this.parent=e.constructor===hx?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Dy(e,e.doc.store,N(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),Qv(this.origin,n.origin)){if(n.id.client{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),pv(e.deleteSet,this.id.client,this.id.clock,this.length),My(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw oh();this.content.gc(e),t?Oy(e,this,new hx(this.id,this.length)):this.content=new vx(this.length)}write(e,t){let n=t>0?N(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ey(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Zv?(e.writeParentInfo(!1),e.writeLeftID(t)):oh();i!==null&&e.writeString(i)}this.content.write(e,t)}},Xx=(e,t)=>Zx[t&31](e),Zx=[()=>{oh()},yx,Ox,_x,Nx,wx,Ex,Ux,jx,Sx,()=>{oh()}],Qx=10,$x=class extends px{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){oh()}write(e,t){e.writeInfo(Qx),j(e.restEncoder,this.length-t)}getMissing(e,t){return null}},eS=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},tS=`__ $YJS$ __`;eS[tS]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),eS[tS]=!0;var nS=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},rS=(e,t)=>e>>>t|e<<32-t,iS=e=>rS(e,2)^rS(e,13)^rS(e,22),aS=e=>rS(e,6)^rS(e,11)^rS(e,25),oS=e=>rS(e,7)^rS(e,18)^e>>>3,sS=e=>rS(e,17)^rS(e,19)^e>>>10,cS=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),lS=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),uS=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(lS),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=sS(t[e-2])+t[e-7]+oS(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+aS(o)+(o&s^~o&c)+cS[e]+t[e]>>>0,d=iS(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3=0&&t>>(3-t)*8;return i}},dS=e=>new uS().digest(e),fS=/[\uD800-\uDBFF]/,pS=/[\uDC00-\uDFFF]/,mS=(e,t)=>{let n=0,r=0;for(;n0&&fS.test(e[n-1])&&n--;r+n0&&pS.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}};function hS(e){if(!e||!(e.content instanceof Hx))return null;let t=e.content.type;if(!(t instanceof ix||t instanceof tx||t instanceof lx))throw Error(`Expected a Yjs XML type`);return t}function gS(e){if(e===null)return null;if(!(e.parent instanceof pb))throw Error(`Expected an integrated Yjs parent`);let t=e.parent;if(!(t instanceof ix||t instanceof tx||t instanceof lx))throw Error(`Expected a Yjs XML type`);return t}var _S=(e,t)=>{let n=null,r=null;return e._item===null?r=ey(e):n=N(e._item.id.client,e._item.id.clock),new ny(n,r,t.id)},vS=(e,t,n)=>{if(e===0)return sy(t,0,-1);let r=hS(t._first);for(;r!==null&&t!==r;){if(r instanceof dx){if(r._length>=e)return sy(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=hS(r._item.next);else{do r=gS(r._item),e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:hS(r._item.next))}}else{let i=n.get(r),a=i instanceof ce?i.nodeSize:0;if(r._first!==null&&e1)return new ny(r._item===null?null:r._item.id,r._item===null?ey(r):null,null);if(e-=a,r._item!==null&&r._item.next!==null)r=hS(r._item.next);else{if(e===0){if(r=r._item===null?r:gS(r._item),r===null)throw oh();return new ny(r._item===null?null:r._item.id,r._item===null?ey(r):null,null)}do{if(r=gS(r._item),r===null)throw oh();e--}while(r!==t&&r._item?.next===null);r!==t&&(r=hS(r._item?.next))}}}if(r===null)throw oh();if(e===0&&r.constructor!==dx&&r!==t){let e=r._item,t=gS(e);if(e===null||t===null)throw oh();return _S(t,e)}}return sy(t,t._length,-1)},yS=(e,t)=>{if(!e.docChanged)return!1;if(e.doc.childCount!==t.childCount)return!0;for(let n of e.steps)if(n instanceof Et){if(n.from===0&&n.to===t.content.size)return!0;if(n.slice.content.size>0){let e=!1;if(n.slice.content.forEach(t=>{t.isBlock&&(e=!0)}),e)return!0}else if(n.to>n.from){let e=t.resolve(n.from),r=t.resolve(n.to);if(e.depth===0&&r.depth===0&&e.index()!==r.index())return!0}}return!1};function bS(e,t){if(e instanceof dx)return e._length;let n=t.get(e);return n instanceof ce?n.nodeSize:null}function xS(e,t,n){let r=0,i=e._first;for(;i!==null;){let e=hS(i);if(e===t)break;let a=i.deleted;if(i=i.right,a)continue;if(e===null)return null;let o=bS(e,n);if(o===null)return null;r+=o}return r}function SS(e,t,n){let r=0,i=0,a=e._first;for(;i{if(n===null)return!1;let r=dy(t,e);return r!==null&&r.type instanceof dx&&t.item!==null&&r.type._item?.deleted===!0},wS=e=>{if(!e.doc)throw Error(`The Yjs fragment must belong to a document`);let t=e._item?`item:${e._item.id.client}:${e._item.id.clock}`:`root:${ey(e)}`;return e.doc.getMap(`__tiptap_position_migrations:${t}`)},TS=new WeakMap,ES=(e,t)=>{let n=t.item??t.type;if(!n)return[];let r;t.item||(r=t.assoc<0?`start`:`end`);let i=TS.get(e);if(!i||i.size!==e.size){let t=new Map;e.forEach(e=>e.transfers.forEach(n=>{let r=t.get(n.source.client)??[];r.push({migration:e,transfer:n}),t.set(n.source.client,r)})),i={size:e.size,clients:t},TS.set(e,i)}let a=(i.clients.get(n.client)??[]).filter(({transfer:e})=>e.source.boundary===r&&e.source.clock<=n.clock&&n.clock!a.some(t=>t.migration!==e.migration&&t.migration.seen.some(([t,n])=>t===e.migration.client&&n>e.migration.clock)))},DS=(e,t,n)=>{let{source:r,target:i}=e.transfer;return i?new ny(i.boundary?N(i.client,i.clock):i.type,i.tname??null,i.boundary?null:N(i.client,i.clock+t.clock-r.clock),i.assoc??n):null},OS=(e,t,n)=>{let r=DS(e[0],t,n);return!r||e.some(e=>{let i=DS(e,t,n);return!i||!fy(r,i)})?null:r},kS=e=>{let t=e.item??e.type;if(!t)return null;let n=e.assoc<0?`start`:`end`;return e.item&&(n=`item`),`${t.client}:${t.clock}:${n}`},AS=(e,t)=>{let n=wS(e),r=new Set,i=t,a=i.item??i.type;for(;a;){let e=kS(i);if(r.has(e))return null;r.add(e);let t=ES(n,i);if(t.length===0)return i;let o=OS(t,a,i.assoc);if(!o)return null;if(kS(o)===e)return o;i=o,a=o.item??o.type}return i},jS=(e,t,n,r)=>{let i=AS(t,n);if(!i)return null;n=i;let a=dy(n,e);if(a===null||a.type!==t&&!ty(t,a.type._item))return null;let o=a.type,s=0;if(o.constructor===dx)s=a.index;else if(!o._item?.deleted){let e=SS(o,a.index,r);if(e===null)return null;s=e+1}for(;o!==t&&o._item!==null;){let e=gS(o._item);if(e===null)return null;if(e._item?.deleted){o=e;continue}let t=xS(e,o,r);if(t===null)return null;s+=t+1,o=e}let c=s-1;return CS(e,n,c)?null:c},MS=new Un(`y-sync`),NS=new Un(`y-undo`),PS=new Un(`yjs-cursor`),FS=null;function IS(){let e=FS;FS=null;let t=[];return e?.forEach((e,n)=>{e.forEach((e,r)=>t.push({view:n,key:r,value:e}))}),t}function LS(e=IS(),t=!1){let n=!0;for(;e.length>0;){let{view:r,key:i,value:a}=e[0];try{let e=MS.getState(r.state);e&&e.binding.prosemirrorView!==null&&r.dispatch(r.state.tr.setMeta(i,a))}catch(r){if(!(r instanceof RangeError))throw r;t&&n&&e.shift(),e.length>0&&B_(0,()=>LS(e,!0));return}n=!1,e.shift()}}function RS(e,t,n){FS===null&&(FS=new Map,B_(0,LS));let r=FS.get(e);r||(r=new Map,FS.set(e,r)),r.set(t,n)}var zS=(e,t,n)=>e!==t,BS=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(`⁠`),i=document.createTextNode(`⁠`);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},VS=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),HS=/^#[0-9a-fA-F]{6}$/,US=e=>typeof e.name==`string`&&typeof e.color==`string`,WS=(e,t,n,r,i)=>{let a=MS.getState(e);if(a==null||a.doc==null||a.binding==null)return xs.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?xs.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t&&t.cursor!=null){let n={...t.user};if(n.color==null?n.color=`#ffa500`:HS.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`,!US(n))return;let l=jS(o,a.type,ry(t.cursor.anchor),a.binding.mapping),u=jS(o,a.type,ry(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=mm(e.doc.content.size-1,0);l=pm(l,t),u=pm(u,t),s.push(vs.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=pm(l,u),o=mm(l,u);s.push(vs.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),xs.create(e.doc,s))},GS=(e,{awarenessStateFilter:t=zS,cursorBuilder:n=BS,selectionBuilder:r=VS,getSelection:i=e=>e.selection}={},a=`cursor`)=>new D({key:PS,state:{init(i,a){return WS(a,e,t,n,r)},apply(i,a,o,s){let c=MS.getState(s),l=i.getMeta(PS),u=c&&c.isChangeOrigin;return i.docChanged&&!u&&yS(i,o.doc)?xs.empty:u||l&&l.awarenessUpdated?WS(s,e,t,n,r):i.docChanged?a.map(i.mapping,i.doc):a}},props:{decorations:e=>PS.getState(e)??xs.empty},view:t=>{let n=()=>{t.isDestroyed||RS(t,PS,{awarenessUpdated:!0})},r=t=>{let n=MS.getState(t.state);if(!n||!n.binding)return;let r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=vS(o.anchor,n.type,n.binding.mapping),c=vS(o.head,n.type,n.binding.mapping);r.cursor!=null&&fy(ry(r.cursor.anchor),s)&&fy(ry(r.cursor.head),c)||e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&jS(n.doc,n.type,ry(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)},o=()=>r(t);return e.on(`change`,n),t.dom.addEventListener(`focusin`,o),t.dom.addEventListener(`focusout`,o),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,o),t.dom.removeEventListener(`focusout`,o),e.off(`change`,n),e.setLocalStateField(a,null)}}}});function KS(e){let t=MS.getState(e);if(!t)throw Error(`The editor requires ySyncPlugin`);return t}var qS=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)??0)>e.id.clock&&!uv(t.ds,e.id),JS=(e,t,n)=>{if(!e.has(n)){if(e.sizen.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,kh(t))}let r=e.get(n);if(!r)throw Error(`At least one snapshot color is required`);return r},YS=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},XS=e=>{let t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{let r=t[n];return r==null||!Object.prototype.hasOwnProperty.call(r,`default`)||r.default!==e.attrs[n]})},ZS=(e,t,n)=>{let r=0,i=0;for(;in)break;r+=t.nodeSize}if(i>=e.childCount)return null;let a=e.child(i),o=e.resolve(n),s=(e,t)=>{if(o.depth===0){let i=e+(n-r),a=e+1,o=e+t.nodeSize-1;return Math.max(a,Math.min(i,o))}if(o.depth>1){let n=ZS(o.node(1),t,o.pos-o.start(1));return n===null?null:e+1+n}return t.isTextblock?e+1+Math.min(o.parentOffset,t.content.size):null},c=(n,r=!1)=>{let a=0;for(let t=0;t<=i;t++)n(e.child(t))&&a++;let o=0,c=-1,l=null,u=0;for(let e=0;ee.type===a.type&&YS(e.attrs,a.attrs),u=a.textContent,d=c(e=>l(e)&&e.textContent===u);if(d!==null)return d;let f=c(e=>e.type===a.type&&e.textContent===u);if(f!==null)return f;if(!a.isTextblock||XS(a)){let e=c(l,!0);if(e!==null)return e}return c(e=>l(e)&&u!==``&&e.textContent!==``&&(u.startsWith(e.textContent)||e.textContent.startsWith(u)),!0)},QS=(e,t,n,r)=>{if(r===null)return!1;let i=e.resolve(n),a=t.resolve(r);if(!i.parent.isTextblock)return!1;if(!a.parent.isTextblock||i.parent.textContent!==a.parent.textContent||i.parentOffset!==0&&a.parentOffset===0)return!0;let o=i.parentOffset===0&&a.parentOffset===0,s=i.parentOffset!==a.parentOffset||i.parent.type!==a.parent.type||!YS(i.parent.attrs,a.parent.attrs);if(o||s){let i=ZS(e,t,n);return i!==null&&i!==r}return!1},$S=(e,t,n,r)=>{if(n==null||n<0||n>t.content.size||!(r===null||n>1&&r<=1||QS(t,e,n,r)))return r;let i=ZS(t,e,n);return i===null?r:i},eC=(e,t,n,r)=>{if(t!==null&&t.anchor!==null&&t.head!==null){if(t.type===`all`)e.setSelection(new Dn(e.doc));else if(t.type===`node`){let r=jS(n.doc,n.type,t.anchor,n.mapping);r!==null&&e.setSelection(tC(e,r))}else if(t.type===`nodeRange`){let r=nC(e,jS(n.doc,n.type,t.anchor,n.mapping),jS(n.doc,n.type,t.head,n.mapping),t.depth);r!==null&&e.setSelection(r)}else{let i=jS(n.doc,n.type,t.anchor,n.mapping),a=jS(n.doc,n.type,t.head,n.mapping);r!=null&&(AS(n.type,t.anchor)===t.anchor&&(i=$S(e.doc,r,t.absAnchor,i)),AS(n.type,t.head)===t.head&&(a=$S(e.doc,r,t.absHead,a))),i===null&&(i=a),a===null&&(a=i),i!==null&&a!==null&&e.setSelection(T.between(e.doc.resolve(i),e.doc.resolve(a)))}}},tC=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?E.create(e.doc,t):T.near(n)},nC=(e,t,n,r)=>{if(t===null||n===null)return null;let i=Math.min(Math.max(t,0),e.doc.content.size),a=Math.min(Math.max(n,0),e.doc.content.size);try{let t=w.fromJSON(e.doc,{type:`nodeRange`,anchor:i,head:a,depth:r});return t.ranges.length?t:T.near(e.doc.resolve(i))}catch{return T.near(e.doc.resolve(i))}},rC=(e,t)=>{let n=t.selection,r=n.toJSON(),i=typeof r.type==`string`?r.type:`text`;return{type:i,depth:i===`nodeRange`&&`depth`in n&&typeof n.depth==`number`?n.depth:void 0,anchor:vS(t.selection.anchor,e.type,e.mapping),head:vS(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},iC=new WeakMap,aC=(e,t)=>{var n;(t instanceof ix||t instanceof tx||t instanceof lx)&&(e.delete(t),(n=iC.get(e))==null||n.delete(t))},oC=/(.*)(--[a-zA-Z0-9+/=]{8})$/,sC=e=>oC.exec(e)?.[1]??e,cC=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(sC(r),e[r]));return n},lC=e=>{let t=e.doc,n=e._item;if(!t||!n)throw oh();t.transact(e=>{n.delete(e)},MS)},uC=(e,t,n,r,i,a)=>{let o=e.toDelta(r,i,a);try{return o.map(e=>t.text(e.insert,cC(e.attributes,t)))}catch{return lC(e),null}},dC=e=>{var t;let n=(t=e._item)==null||(t=t.right)==null?void 0:t.content,r=n instanceof Hx?n.type:null;if(!(r instanceof tx))return;let i=r._item,a=r.doc;i&&a&&!i.deleted&&i.id.client===a.clientID&&(e.applyDelta([{retain:e.length},...r.toDelta()]),a.transact(e=>{i.delete(e)}))},fC=(e,t,n,r)=>{if(e._item){if(!qS(e._item,t))return r?r(`removed`,e._item.id):{type:`removed`};if(!qS(e._item,n))return r?r(`added`,e._item.id):{type:`added`}}},pC=(e,t,n)=>{e.mapping.set(t,n);let r=iC.get(e.mapping);r===void 0&&(r=new WeakMap,iC.set(e.mapping,r)),r.set(t,n)},mC=(e,t,n,r,i,a)=>{let o=n.mapping.get(e),s=Array.isArray(o)?void 0:o;if(s!==void 0&&iC.get(n.mapping)?.get(e)===s)return s;let c=[],l=e=>{if(e instanceof ox){let o=mC(e,t,n,r,i,a);o!==null&&c.push(o)}else e instanceof dx&&(dC(e),uC(e,t,n,r,i,a)?.forEach(e=>c.push(e)))};r===void 0||i===void 0?e.toArray().forEach(l):gb(e,new py(i.ds,r.sv)).forEach(l);try{let o=e.getAttributes(r),l=r?fC(e,r,i,a):void 0;l!==void 0&&(o.ychange=l);let u=t.node(e.nodeName,o,c);return s?.eq(u)&&(u=s),pC(n,e,u),u}catch{return lC(e),aC(n.mapping,e),null}},hC=e=>{for(let t=6;thg(hC(dS(vg(e)))),_C=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=Qp(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${gC(e.toJSON())}`:e.type.name]=e.attrs}}),n},vC=(e,t)=>{let n=new dx,r=e.map(e=>({insert:e.text??``,attributes:_C(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},yC=e=>{let t=e.content.content,n=[];for(let e=0;ee instanceof Array?vC(e,t):xC(e,t),xC=(e,t)=>{let n=new ox(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,yC(e).map(e=>bC(e,t))),t.mapping.set(n,e),n},SC=e=>typeof e==`object`&&!!e,CC=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Vh(e.attributes||{}).length===t[n].marks.length&&Object.entries(e.attributes??{}).every(([e,r])=>{let i=sC(e),a=t[n].marks.find(e=>e.type.name===i);return a?CC(r,a.attrs):!1}))},TC=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,EC=(e,t)=>{if(e instanceof ox&&!(t instanceof Array)&&TC(e,t)){let n=yC(t);return e._length===n.length&&CC(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>EC(e,n[t]))}return e instanceof dx&&t instanceof Array&&wC(e,t)},DC=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),OC=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});let i=[];if(e.forEach((e,a)=>{let o=n.mapping.get(e),s=o===void 0?void 0:r.get(o);s!==void 0&&DC(o,t[s])&&i.push({yIndex:a,pIndex:s,yChild:e})}),i.length===0)return[];let a=[],o=[];for(let e=0;e>1;i[o[r]].pIndex0?o[t-1]:-1,o[t]=e}let s=[];for(let e=o[o.length-1];e!==-1;e=a[e])s.push(i[e]);return s.reverse()},kC=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Mx?t+=n.content.str:n.content instanceof Tx&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},AC=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=kC(e),a=t.map(e=>({insert:e.text??``,attributes:Object.assign({},r,_C(e.marks,n))})),{insert:o,remove:s,index:c}=mS(i,a.map(e=>e.insert).join(``));e.delete(c,s),e.insert(c,o),e.applyDelta(a.map(e=>({retain:e.insert.length,attributes:e.attributes})))},jC=(e,t,n,r,i)=>t instanceof dx&&n instanceof Array?(wC(t,n)?r.mapping.set(t,n):AC(t,n,r),!0):t instanceof ox&&!(n instanceof Array)&&TC(t,n)?(EC(t,n)?r.mapping.set(t,n):i(e,t,n,r),!0):!1,MC=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>aC(r.mapping,e)),e.delete(t,n))},NC=(e,t,n,r,i,a)=>{if(r{let u=pm(a-i,s-o);for(let a=0;a{let o=OC(r,n,i);if(o.length<2||!o.some(e=>e.yIndex!==e.pIndex)||o.some(e=>{let t=n[e.pIndex];return!(e.yChild instanceof dx&&t instanceof Array||e.yChild instanceof ox&&!(t instanceof Array))}))return!1;let s=0,c=0;for(let l of o){PC(e,t,n,r,s,l.yIndex,c,l.pIndex,i,a);let o=n[l.pIndex];jC(e,l.yChild,o,i,a),s=l.yIndex+1,c=l.pIndex+1}return PC(e,t,n,r,s,r.length,c,n.length,i,a),!0},IC=(e,t,n)=>{let r=e.toArray(),i=yC(t),a=i.length,o=r.length,s=pm(o,a),c=0,l=0,u=!1;for(;c{if(t instanceof ox&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof ox){let e=t.getAttributes(),r=n.attrs;for(let n in r)r[n]===null?t.removeAttribute(n):e[n]!==r[n]&&n!==`ychange`&&t.setAttribute(n,r[n]);for(let n in e)r[n]===void 0&&t.removeAttribute(n)}let i=yC(n),a=i.length,o=t.toArray(),s=o.length,c=pm(a,s),l=!1;if(e.transact(()=>{l=FC(e,t,i,o,r,LC)},MS),l)return;let u=0,d=0;for(;u{for(;s-u-d>0&&a-u-d>0;){let n=o[u],c=i[u],l=o[s-d-1],f=i[a-d-1];if(n instanceof dx&&c instanceof Array){wC(n,c)||AC(n,c,r),u+=1;continue}let p=n instanceof ox&&TC(n,c),m=l instanceof ox&&TC(l,f);if(p&&m&&n instanceof ox&&l instanceof ox&&!Array.isArray(c)&&!Array.isArray(f)){let e=IC(n,c,r),t=IC(l,f,r);e.foundMappedChild&&!t.foundMappedChild?m=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor0&&(t.slice(u,u+n).forEach(e=>aC(r.mapping,e)),t.delete(u,n)),u+d>=a)return;let c=[];for(let e=u;e{let n=[];if(!e._item)throw Error(`Position tracking requires integrated text`);for(let r=e._start;r;r=r.right)if(!r.deleted&&r.countable){if(!(r.content instanceof Mx))throw Error(`Position tracking requires string text content`);for(let i=0;i{let r=[{current:-1,target:-1}];return e.forEach((e,n)=>{let i=t.get(`${e.client}:${e.clock}`);i!==void 0&&i>r[r.length-1].target&&r.push({current:n,target:i})}),r.push({current:e.length,target:n}),r},BC=(e,t,n,r,i)=>{let a=RC(e),o=new Map;for(let e=0;e0;--n){let r=s[n-1],o=s[n],c=a.slice(r.current+1,o.current),l=t.slice(r.target+1,o.target);(c.some(e=>i.has(`${e.client}:${e.clock}`))||c.map(e=>e.text).join(``)!==l)&&(e.delete(r.current+1,c.length),e.insert(r.current+1,l))}return RC(e,n)},VC=(e,t)=>!e.target||!t.target?e.target===t.target:e.target.client===t.target.client&&e.target.assoc===t.target.assoc&&e.target.boundary===t.target.boundary&&e.target.tname===t.target.tname&&e.target.clock+e.source.length===t.target.clock&&Qv(e.target.type,t.target.type),HC=e=>{let t=[];return e.forEach(e=>{let n=t[t.length-1];n&&n.source.client===e.source.client&&n.source.boundary===e.source.boundary&&n.source.clock+n.source.length===e.source.clock&&VC(n,e)?n.source.length+=e.source.length:t.push({...e,source:{...e.source}})}),t},UC=(e,t)=>{let n=e.doc;if(!n||t.length===0)return;let r=xy(n.store,n.clientID);e.set(`${n.clientID}:${r}`,{version:1,client:n.clientID,clock:r,seen:[...Vv(Gv(n))],transfers:HC(t)})},WC=(e,t)=>{let n=new Map;e.forEach(e=>{let t=`${e.type.client}:${e.type.clock}`,r=n.get(t)??[];r.push(e),n.set(t,r)});let r=[];return n.forEach(e=>{let n=e[0],i=e[e.length-1],a=n.position===null?void 0:t.get(n.position),o=i.position===null?void 0:t.get(i.position);a&&Qv(n.type,a.type)||r.push({source:{...n.type,length:1,boundary:`start`},target:a?{...a,assoc:0}:null}),o&&Qv(i.type,o.type)||r.push({source:{...n.type,length:1,boundary:`end`},target:o?{...o,assoc:-1}:null})}),r},GC=(e,t,n,r)=>{let i=[];e.forEach(e=>{let n=e.position===null?null:t.get(e.position)??null;n&&Qv(e.id,n)||i.push({source:{...e.id,length:1},target:n})});let a=[...e,...r];for(let e of[`start`,`end`]){let r=e===`start`?t:n;a.forEach(t=>{let n=e===`start`?t.position:t.end,a=n===null?null:r.get(n)??null;a&&Qv(t.id,a)||i.push({source:{...t.id,length:1,boundary:e},target:a?{client:a.client,clock:a.clock,type:null,boundary:e}:null})})}return i},KC=(e,t,n,r,i,a)=>{let o=e.get(t);if(!(o instanceof ox)||!o._item)throw Error(`Position migration requires synchronized elements`);let s=i.get(`${o._item.id.client}:${o._item.id.clock}`);if(s&&s.position!==r&&(aC(a.mapping,o),e.delete(t,1),o=bC(n,a),e.insert(t,[o])),!(o instanceof ox)||!o._item)throw Error(`Position migration requires integrated elements`);return o},qC=(e,t,n,r)=>{let i=new Map(t.characters.map(e=>[e.position,e])),a=new Set(t.characters.map(e=>`${e.client}:${e.clock}`)),o=new Map,s=new Map(t.nodes.map(e=>[`${e.id.client}:${e.id.clock}`,e])),c=new Map,l=new Map,u=(e,t,r)=>{let d=e.toArray(),f=r;yC(t).forEach((t,r)=>{let p=d[r];if(Array.isArray(t)){if(!(p instanceof dx)||!p._item)throw Error(`Position migration requires integrated text`);let e=t.map(e=>e.text??``).join(``),r=BC(p,e,f,i,a),s=p._item.id;r.forEach(e=>o.set(e.position,{client:e.client,clock:e.clock,type:s})),AC(p,t,n),f+=e.length;return}let m=KC(e,r,t,f,s,n),h=m._item.id,g={client:h.client,clock:h.clock,type:e._item?.id??null,...e._item?{}:{tname:ey(e)}};c.set(f,g),l.set(f+t.nodeSize-1,g),t.isLeaf||u(m,t,f+1),f+=t.nodeSize})};u(e,t.doc,0);let d=[];t.characters.forEach(e=>{let t=e.position===null?null:o.get(e.position)??null;t&&Qv(e,t)&&Qv(e.type,t.type)||d.push({source:{client:e.client,clock:e.clock,length:1},target:t})}),d.push(...WC(t.characters,o)),d.push(...GC(t.nodes,c,l,t.emptyTexts)),UC(r,d)},JC=(e,t)=>{let n=e.doc.content,r=0,i=0;for(;rr&&o>r&&n.child(a-1)===t.child(o-1);)s+=n.child(a-1).nodeSize,a--,o--;if(r===a&&r===o)return e;let c=new p(t.cut(i,t.size-s),0,0),l=en(e.doc,i,n.size-s,c);return l!==null&&l.apply(e.doc).doc?.content.eq(t)?e.step(l):e.replace(0,n.size,new p(t,0,0))},YC=class{constructor(e,t=new Map){if(this.prosemirrorView=null,this.mux=nS(),this.isOMark=new Map,this.beforeTransactionSelection=null,this._domSelectionInView=null,this.syncedDoc=null,this.type=e,this.mapping=t,this._observeFunction=this._typeChanged.bind(this),e.doc===null)throw Error(`The Yjs fragment must belong to a document`);this.doc=e.doc,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=rC(this,this.view.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null}}get view(){if(!this.prosemirrorView)throw Error(`The binding has no editor view`);return this.prosemirrorView}get _tr(){return this.view.state.tr.setMeta(`addToHistory`,!1)}_isLocalCursorInView(){return this.view.hasFocus()?(tg&&this._domSelectionInView===null&&(B_(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.view.root,t=`getSelection`in e&&typeof e.getSelection==`function`?e.getSelection():this.view.dom.ownerDocument.getSelection();if(t==null||t.anchorNode==null||t.focusNode==null)return!1;let n=this.view.dom.ownerDocument.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);let r=n.getBoundingClientRect(),i=N_.documentElement;return r.bottom>=0&&r.right>=0&&r.left<=(window.innerWidth||i.clientWidth||0)&&r.top<=(window.innerHeight||i.clientHeight||0)}renderSnapshot(e,t){t||=my(mv(),new Map),this.view.dispatch(this._tr.setMeta(MS,{snapshot:e,prevSnapshot:t}))}createDocumentTransaction(){let e=this.type.toArray().map(e=>{if(!(e instanceof ox))throw ah();return mC(e,this.view.state.schema,this)}).filter(e=>e!==null);return this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(e),0,0))}unrenderSnapshot(){this.mapping.clear(),iC.delete(this.mapping),this.mux(()=>{let e=this.createDocumentTransaction();e.setMeta(MS,{snapshot:null,prevSnapshot:null}),this.view.dispatch(e)})}_forceRerender(){this.mapping.clear(),iC.delete(this.mapping),this.mux(()=>{let e=this.beforeTransactionSelection===null?this.view.state.selection:null,t=this.createDocumentTransaction();if(e){let n=pm(mm(e.anchor,0),t.doc.content.size),r=pm(mm(e.head,0),t.doc.content.size);t.setSelection(T.create(t.doc,n,r))}this.view.dispatch(t.setMeta(MS,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=gy(this.doc),e instanceof Uint8Array||t instanceof Uint8Array){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw oh();if(r=new bv({gc:!1}),Fv(r,t),t=gy(r),Fv(r,e),e=gy(r),i._item===null){let e=Array.from(this.doc.share.keys()).find(e=>Object.is(this.doc.share.get(e),i));i=r.getXmlFragment(e)}else{let e=r.store.clients.get(i._item.id.client)??[],t=e[Cy(e,i._item.id.clock)];if(!(t instanceof Yx&&t.content instanceof Hx&&t.content.type instanceof ix))throw oh();i=t.content.type}}let a=e,o=t??hy;this.mapping.clear(),iC.delete(this.mapping),this.mux(()=>{r.transact(e=>{let t=n.permanentUserData;t&&t.dss.forEach(t=>{cv(e,t,e=>{})});let r=(e,r)=>{let i=t?e===`added`?t.getUserByClientId(r.client):t.getUserByDeletedId(r):null;return{user:i,type:e,color:JS(n.colorMapping,n.colors,i)}},c=gb(i,new py(o.ds,a.sv)).map(e=>!(e instanceof ox)||!e._item?null:!e._item.deleted||qS(e._item,a)||qS(e._item,o)?mC(e,this.view.state.schema,{mapping:new Map,isOMark:new Map},a,o,r):null).filter(e=>e!==null),l=this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(c),0,0));this.view.dispatch(l.setMeta(MS,{isChangeOrigin:!0}))},MS)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=KS(this.view.state);if(e.length===0||n.snapshot!=null||n.prevSnapshot!=null){this.renderSnapshot(n.snapshot,n.prevSnapshot);return}let r=t.origin instanceof Vy,i=r?t.origin.currStackItem?.meta.get(this):void 0,a=i||this.beforeTransactionSelection,o=i?void 0:this.view.state.doc;this.mux(()=>{let e=(e,t)=>aC(this.mapping,t);cv(t,t.deleteSet,e=>{e instanceof Yx&&e.content instanceof Hx&&aC(this.mapping,e.content.type)}),t.changed.forEach(e),t.changedParentTypes.forEach(e);let n=this.type.toArray().map(e=>{if(!(e instanceof ox))throw ah();return mC(e,this.view.state.schema,this)}).filter(e=>e!==null),i=JC(this._tr,s.from(n));eC(i,a,this,o),i=i.setMeta(MS,{isChangeOrigin:!0,isUndoRedoOperation:r}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.view.dispatch(i)})}_prosemirrorChanged(e,t=null){let n=KS(this.view.state);n.snapshot==null&&n.prevSnapshot==null&&this.doc.transact(()=>{LC(this.doc,this.type,e,this),t?.doc===e&&qC(this.type,t,this,wS(this.type)),this.syncedDoc=e,this.beforeTransactionSelection=rC(this,this.view.state)},MS)}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))}},XC=(e,t)=>{let n=[],r=[],i=[];if(e.length===0)return{characters:n,nodes:r,emptyTexts:i};let a=(e,t,o)=>{let s=e.toArray(),c=yC(t),l=o;t.content.size===0&&s.forEach(e=>{e instanceof dx&&e._item&&i.push({id:e._item.id,position:o-1,end:o})}),c.forEach((e,t)=>{let i=s[t];if(!Array.isArray(e)){if(!(i instanceof ox)||!i._item)throw Error(`Position tracking requires synchronized editor content`);r.push({id:i._item.id,position:l,end:l+e.nodeSize-1}),e.isLeaf||a(i,e,l+1),l+=e.nodeSize;return}if(!(i instanceof dx))throw Error(`Position tracking requires synchronized editor text`);let o=RC(i,l);n.push(...o),l+=o.length})};return a(e,t,0),{characters:n,nodes:r,emptyTexts:i}},ZC=(e,t,n,r)=>{let i=e.toJSON();if(i.stepType!==`replace`&&i.stepType!==`replaceAround`||r!==i.from&&r!==i.to-1)return!1;let a=t.nodeAt(i.from),o=n.nodeAt(i.from);return!a||!o||a.nodeSize!==i.to-i.from?!1:QC(a,o)},QC=(e,t)=>e.type===t.type&&e.content.eq(t.content)&&!e.sameMarkup(t),$C=(e,t)=>{let n=e.toJSON(),r=n.slice??{content:[]};if(n.stepType!==`replace`||r.openStart>0||r.openEnd>0)return!1;let i=t.resolve(n.from),a=t.resolve(n.to);return r.content.every(e=>e.type===`text`)&&i.parent.isTextblock&&i.sameParent(a)},ew=e=>{let t=new Map;return e.descendants((e,n)=>{let r=t.get(e)??[];r.push(n),t.set(e,r)}),t},tw=(e,t,n,r)=>{if(r[n].get(e)?.length!==1)return null;for(let i=n+1;i{let i=n[t].resolve(e),a=[],o=n[t].nodeAt(e);o&&!o.isText&&a.push({node:o,offset:0});for(let t=i.depth;t>0;--t)a.push({node:i.node(t),offset:e-i.before(t)});for(let e of a){let n=tw(e.node,e.offset,t,r);if(n)return n}return null},rw=(e,t,n,r)=>{for(let i=0;i{let r=n?.doc===e.before&&n.doc!==t.syncedDoc?n:null;if(!e.docChanged||!t.prosemirrorView||!r&&e.steps.every((t,n)=>$C(t,e.docs[n])))return r;let i=r??XC(t.type,e.before),a=[...e.docs,e.doc],o=a.map(ew),s=i.characters.map(t=>({...t,position:t.position===null?null:rw(t.position,e,a,o)})),c=t=>({...t,position:t.position===null?null:rw(t.position,e,a,o),end:t.end===null?null:rw(t.end,e,a,o)});return{doc:e.doc,characters:s,nodes:i.nodes.map(c),emptyTexts:i.emptyTexts.map(c)}},aw=[{light:`#ecd44433`,dark:`#ecd444`}],ow=(e,{colors:t=aw,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new YC(e,a);return new D({props:{editable:e=>{let t=KS(e);return t.snapshot==null&&t.prevSnapshot==null}},key:MS,state:{init:(i,a)=>({type:e,doc:s.doc,binding:s,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r,positionMigration:null}),apply:(e,t)=>{let n=e.getMeta(MS);return n!==void 0&&(t=Object.assign({},t,n)),e.docChanged&&(t.addToHistory=e.getMeta(`addToHistory`)!==!1),t.isChangeOrigin=n!==void 0&&!!n.isChangeOrigin,t.isUndoRedoOperation=n!==void 0&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,t={...t,positionMigration:t.isChangeOrigin||t.snapshot||t.prevSnapshot||n?.snapshot!==void 0||n?.prevSnapshot!==void 0?null:iw(e,s,t.positionMigration??null)},s.prosemirrorView===null||n===void 0||n.snapshot==null&&n.prevSnapshot==null||B_(0,()=>{s.prosemirrorView!=null&&(n.restore==null?s._renderSnapshot(n.snapshot,n.prevSnapshot,t):(s._renderSnapshot(n.snapshot,n.snapshot,t),s.mux(()=>{let e=s.prosemirrorView;e&&(e.dispatch(s._tr.setMeta(MS,{restore:!1,snapshot:null,prevSnapshot:null,isChangeOrigin:!0})),s._prosemirrorChanged(e.state.doc))})))}),t}},view:e=>(s.initView(e),a??s._forceRerender(),i(),{update:()=>{let t=KS(e.state);if(t.snapshot==null&&t.prevSnapshot==null){let n=e.state.doc.type.createAndFill();if(!n)throw Error(`The schema cannot create an empty document`);if(o||e.state.doc.content.findDiffStart(n.content)!==null){if(o=!0,t.addToHistory===!1&&!t.isChangeOrigin){let t=NS.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}s.mux(()=>{t.doc.transact(n=>{n.meta.set(`addToHistory`,t.addToHistory),s._prosemirrorChanged(e.state.doc,t.positionMigration??null)},MS)})}}},destroy:()=>{s.destroy()}})})};function sw(e){let t=NS.getState(e);if(!t)throw Error(`The editor requires yUndoPlugin`);return t}var cw=e=>{let t=new Map,n=e=>{e.toArray().forEach(r=>{if(r instanceof ox){let i=r._item.id;t.set(`${i.client}:${i.clock}`,{client:i.client,clock:i.clock,type:e._item?.id??null,...e._item?{}:{tname:ey(e)}}),n(r);return}if(!(r instanceof dx)||!r._item)return;let i=r._item.id;RC(r).forEach(e=>{t.set(`${e.client}:${e.clock}`,{client:e.client,clock:e.clock,type:i})})})};return n(e),t},lw=(e,t)=>{let n=e.doc;if(!n)return;let r=cw(e),i=new Map,a=new Map,o=(e,t)=>{let n=`${e.client}:${e.clock}`,r=`${t.client}:${t.clock}`;i.set(n,e),i.set(r,t);let o=a.get(n)??new Set,s=a.get(r)??new Set;o.add(r),s.add(n),a.set(n,o),a.set(r,s)};t.forEach(e=>e.transfers.forEach(({source:e,target:t})=>{if(t&&!e.boundary)for(let n=0;ne.forEach(e=>{if(e instanceof Yx&&e.redone&&(e.content instanceof Mx||e.content instanceof Hx))for(let t=0;t{if(c.has(t))return;let o=[t],l=[],u=[];for(;o.length>0;){let e=o.pop();if(c.has(e))continue;c.add(e),l.push(e);let t=r.get(e);t&&u.push(t),o.push(...a.get(e)??[])}u.length===1&&l.forEach(e=>{if(r.has(e))return;let t=i.get(e);s.push({source:{client:t.client,clock:t.clock,length:1},target:u[0]});let a=wy(n.store,t);if(a.content instanceof Hx&&a.content.type instanceof ox)for(let e of[`start`,`end`])s.push({source:{client:t.client,clock:t.clock,length:1,boundary:e},target:{client:u[0].client,clock:u[0].clock,type:null,boundary:e}})})}),UC(t,s)},uw=(e,t,n)=>{let r=wS(e);if(r.size===0)return t[n]();let i=n===`undo`?`undoing`:`redoing`,a=null,o=({stackItem:e})=>{a=e};t.on(`stack-item-popped`,o);try{t.doc.transact(()=>{t[n](),t[i]=!0,t.currStackItem=a,a&&lw(e,r)},t)}finally{t.off(`stack-item-popped`,o),t[i]=!1,t.currStackItem=null}return a},dw=(e,t)=>{let n=KS(e);if(n.snapshot!=null||n.prevSnapshot!=null)return!1;let r=sw(e).undoManager;if(r!=null)return uw(n.type,r,t),!0},fw=e=>dw(e,`undo`),pw=e=>dw(e,`redo`),mw=new Set([`paragraph`]),hw=(e,t)=>!(e instanceof Yx)||!(e.content instanceof Hx)||!(e.content.type instanceof tx||e.content.type instanceof ox&&t.has(e.content.type.nodeName))||e.content.type._length===0,gw=({protectedNodes:e=mw,trackedOrigins:t=[],undoManager:n=null}={})=>new D({key:NS,state:{init:(r,i)=>{let a=KS(i),o=new Set,s=n;if(!s){let n=new Set(a.doc._observers.get(`destroy`));s=new Vy(a.type,{trackedOrigins:new Set([MS,...t]),deleteFilter:t=>hw(t,e),captureTransaction:e=>e.meta.get(`addToHistory`)!==!1}),(a.doc._observers.get(`destroy`)??new Set).forEach(e=>{n.has(e)||o.add(e)})}return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0,destroyListeners:o}},apply:(e,t,n,r)=>{let i=KS(r).binding;return{...t,prevSel:i?rC(i,n):t.prevSel,hasUndoOps:t.undoManager.undoStack.length>0,hasRedoOps:t.undoManager.redoStack.length>0}}},view:e=>{let t=KS(e.state),{undoManager:n,destroyListeners:r}=sw(e.state);return n.on(`stack-item-added`,({stackItem:r})=>{let i=t.binding;if(i){let t=n.undoing||n.redoing?i.beforeTransactionSelection:sw(e.state).prevSel;r.meta.set(i,t)}}),{destroy:()=>{n.destroy(),r.forEach(e=>n.doc.off(`destroy`,e)),r.clear()}}}});function _w(e,t){let n=t||new ix;return LC(n.doc??{transact:e=>e()},n,e,{mapping:new Map,isOMark:new Map}),n}function vw(e){let t=e.toArray(),n=e=>{let t;if(e instanceof dx)t=e.toDelta().map(e=>{let t={type:`text`,text:e.insert},n=e.attributes;return n&&(t.marks=Object.keys(n).map(e=>{let t=n[e],r={type:sC(e)};return Object.keys(t).length&&(r.attrs=t),r})),t});else if(e instanceof ox){t={type:e.nodeName};let r=e.getAttributes();Object.keys(r).length&&(t.attrs=r);let i=e.toArray();i.length&&(t.content=i.map(n).flat())}else oh();return t};return{type:`doc`,content:t.map(n)}}function yw(e,t,n){return _w(ce.fromJSON(e,t),n)}function bw(e){return!!e.getMeta(MS)}function xw(e,t){if(t===null)return 0;let n=Cw(e);return jS(n.doc,n.type,t,n.binding.mapping)||0}function Sw(e,t){let n=Cw(e);return vS(t,n.type,n.binding.mapping)}function Cw(e){let t=MS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs sync plugin`);return t}var ww=class e extends gd{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Tw(e,t){return new ww(e,Sw(t,e))}function Ew(e,t,n){let r=e instanceof ww?e.yRelativePosition:null;if(bw(t)&&r)return{position:new ww(xw(n,r),r),mapResult:null};let i=_d(e,t),a=i.position.position;return{position:new ww(a,r??Sw(n,a)),mapResult:i.mapResult}}function Dw(e){let t=NS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs undo plugin`);return t.undoManager}var Ow=Tp.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>Ew(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Tw(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Dw(t).undoStack.length===0?!1:n?fw(t)??!1:!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Dw(t).redoStack.length===0?!1:n?pw(t)??!1:!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=gw(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let t=Dw(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[ow(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,new D({filterTransaction:(e,t)=>(e.getMeta(`inputRule`)&&Dw(t).stopCapturing(),!0)}),this.editor.options.enableContentCheck&&new D({key:new Un(`filterInvalidContent`),filterTransaction:t=>{if(!bw(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!0}}})].filter(e=>e!==!1)}}),kw=e=>Array.from(e.entries()).map(([e,t])=>t&&t.user?{clientId:e,...t.user}:{clientId:e}),Aw=()=>null,jw=e=>Pf(e)&&/^#[0-9a-fA-F]{6}$/.test(e),Mw=e=>({...e,color:jw(e.color)?e.color:`transparent`}),Nw=Tp.create({name:`collaborationCaret`,priority:999,addOptions(){return{provider:null,user:{name:null,color:null},render:e=>{let t=document.createElement(`span`),{color:n}=Mw(e);t.classList.add(`collaboration-carets__caret`),t.style.borderColor=n;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.style.backgroundColor=n,r.insertBefore(document.createTextNode(e.name),null),t.insertBefore(r,null),t},selectionRender:e=>jw(e.color)?VS({name:e.name,color:e.color}):{},onUpdate:Aw}},onCreate(){if(this.options.onUpdate!==Aw&&console.warn('[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'),!this.options.provider)throw Error(`The "provider" option is required for the CollaborationCaret extension`)},addStorage(){return{users:[]}},addCommands(){return{updateUser:e=>()=>(this.options.provider.awareness.setLocalStateField(`user`,e),!0),user:e=>({editor:t})=>(console.warn(`[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret`),t.commands.updateUser(e))}},addProseMirrorPlugins(){let{provider:e}=this.options,t=this.storage,n=this.options.user;return[new D({key:new Un(`collaborationCaretAwarenessListener`),view:()=>{let r=()=>{t.users=kw(e.awareness.states)};return e.awareness.setLocalStateField(`user`,n),t.users=kw(e.awareness.states),e.awareness.on(`update`,r),{destroy:()=>{e.awareness.off(`update`,r),t.users=[]}}}}),GS(e.awareness,{cursorBuilder:e=>this.options.render(Mw(e)),selectionBuilder:e=>this.options.selectionRender(Mw(e))})]}});function Pw(e={}){return new D({view(t){return new Fw(t,e)}})}var Fw=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc){if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else 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,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.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 c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(!t||i)return null;let a=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=$t(this.editorView.state.doc,a,this.editorView.dragging.slice);e!=null&&(a=e)}return a}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},Iw=class e extends w{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):w.near(r)}content(){return p.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new Lw(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!zw(e)||!Bw(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!E.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};Iw.prototype.visible=!1,Iw.findFrom=Iw.findGapCursorFrom,w.jsonID(`gapcursor`,Iw);var Lw=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return Iw.valid(t)?new Iw(t):w.near(t)}};function Rw(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function zw(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0}else for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||Rw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Bw(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0}else for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||Rw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Vw(){return new D({props:{decorations:Kw,createSelectionBetween(e,t,n){return t.pos==n.pos&&Iw.valid(n)?new Iw(n):null},handleClick:Ww,handleKeyDown:Hw,handleDOMEvents:{beforeinput:Gw}}})}var Hw=Sc({ArrowLeft:Uw(`horiz`,-1),ArrowRight:Uw(`horiz`,1),ArrowUp:Uw(`vert`,-1),ArrowDown:Uw(`vert`,1)});function Uw(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof T){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=Iw.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new Iw(c))),!0):!1}}function Ww(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!Iw.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&E.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new Iw(r))),!0)}function Gw(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof Iw))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new p(i,0,0));return a.setSelection(T.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function Kw(e){if(!(e.selection instanceof Iw))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,xs.create(e.doc,[vs.widget(e.selection.head,t,{key:`gapcursor`})])}Tp.create({name:`characterCount`,addOptions(){return{limit:null,autoTrim:!0,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new D({key:new Un(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit,a=this.options.autoTrim;if(i==null||i===0||a===!1){e=!0;return}let o=this.storage.characters({node:r.doc});if(o>i){let t=o-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var qw=Tp.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[Pw(this.options)]}});Tp.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new D({key:new Un(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return xs.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(vs.node(t,t+e.nodeSize,{class:this.options.className}))}),xs.create(e,a)}}})]}});var Jw=Tp.create({name:`gapCursor`,addProseMirrorPlugins(){return[Vw()]},extendNodeSchema(e){return{allowGapCursor:Nu(k(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Yw=`placeholder`,Xw=new Un(`tiptap__placeholder`);function Zw(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:a,isEmptyDoc:o,hasAnchor:s,classes:{emptyNode:c,emptyEditor:l}}=e,u=[c];return o&&u.push(l),vs.node(i,i+a.nodeSize,{class:u.join(` `),[r]:typeof n==`function`?n({editor:t,node:a,pos:i,hasAnchor:s}):n})}function Qw(e,t){return typeof e==`function`?e(t):e}function $w({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:a,to:o}){let{anchor:s}=i,c=[],l=e.isEmpty;return r.nodesBetween(a,o,(r,i)=>{let a=s>=i&&s<=i+r.nodeSize,o=!r.isLeaf&&fd(r);return r.type.isTextblock&&(a||!t.showOnlyCurrent)&&o&&c.push(Zw({editor:e,isEmptyDoc:l,dataAttribute:n,hasAnchor:a,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:Qw(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:a})},node:r,pos:i})),t.includeChildren}),c}function eT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!e.isEditable&&t.showOnlyWhenEditable)return null;let{anchor:a}=i,o=[],s=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(a),c=i.depth>0?i.node(1):i.nodeAfter,l=i.depth>0?i.before(1):a;if(c&&c.type.isTextblock&&fd(c)){let r=a>=l&&a<=l+c.nodeSize;o.push(Zw({editor:e,isEmptyDoc:s,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:Qw(t.emptyNodeClass,{editor:e,node:c,pos:l,hasAnchor:r})},node:c,pos:l}))}}else o.push(...$w({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return xs.create(r,o)}function tT(e,t){let n=e.resolve(t);if(n.depth===0){let e=n.nodeAfter??n.nodeBefore;if(!e)return{from:t,to:t};let r=n.nodeAfter?t:t-e.nodeSize;return{from:r,to:r+e.nodeSize}}let r=n.before(1);return{from:r,to:r+n.node(1).nodeSize}}function nT(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function rT(e,t,n){let r=[];return e.forEach((e,i)=>{let a=i,o=a+e.nodeSize,s=a+1,c=o+1;st&&r.push({from:a,to:o})}),r}function iT(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;et.from?n.push(nT(e,tT(e,Math.min(t.to,e.content.size+1)-1))):t.frome.from>=t&&e.to<=c);l.length&&(s=s.remove(l));let u=$w({editor:n,options:r,dataAttribute:i,doc:a,selection:o,from:t,to:c});u.length&&(s=s.add(a,u))}return s}function lT({editor:e,options:t,dataAttribute:n}){return{init(r,i){return eT({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection})??xs.empty},apply(r,i,a,o){return!r.docChanged&&!r.selectionSet?i:cT({decorations:i.map(r.mapping,r.doc),ranges:oT(r,a,o),editor:e,options:t,dataAttribute:n,doc:o.doc,selection:o.selection})}}}function uT(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}function dT({editor:e,options:t}){let n=t.dataAttribute?`data-${uT(t.dataAttribute)}`:`data-${Yw}`,r=t.showOnlyCurrent&&!t.includeChildren;return new D({key:Xw,...r?{}:{state:lT({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>eT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>t.showOnlyWhenEditable&&!e.isEditable?xs.empty:Xw.getState(n)??xs.empty}})}var fT=Tp.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Yw,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[dT({editor:this.editor,options:this.options})]}});function pT(e,t){return!e.selection.empty&&!pd(e.selection)&&t.isEditable}function mT(e,t){return pT(e,t)&&!t.isFocused&&!t.view.dragging}function hT(){var e;(e=window.getSelection())==null||e.removeAllRanges()}function gT(e){e.focus()}Tp.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new D({key:new Un(`selection`),props:{decorations(n){return mT(n,e)?xs.create(n.doc,[vs.inline(n.selection.from,n.selection.to,{class:t.className})]):null},handleDOMEvents:{blur(t){return pT(t.state,e)&&hT(),!1},focus(t){return pT(t.state,e)&&requestAnimationFrame(()=>{!e.isDestroyed&&t.hasFocus()&&gT(t)}),!1}}}})]}});function _T({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var vT=Tp.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new Un(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new D({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!_T({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!_T({node:r,types:n})}}})]}}),yT=Tp.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Kc(e,t),redo:()=>({state:e,dispatch:t})=>qc(e,t)}},addProseMirrorPlugins(){return[Wc(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),bT=new WeakSet,xT=new WeakSet;function ST(e){let t=e;return bT.add(t),t}function CT(e){return Array.isArray(e)&&bT.has(e)}function wT(e){return e.flatMap(e=>e==null?[]:Array.isArray(e)&&xT.has(e)&&!CT(e)?wT(e):[e])}function TT(e,t){if(e===`slot`)return 0;if(e instanceof Function){let n=e(t);return Array.isArray(n)&&!CT(n)&&!xT.has(n)?ST(n):n}let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);if(Array.isArray(n)){if(CT(n))return ST([e,r,n]);if(n.length===0)return ST([e,r]);let t=wT(n);return t.length===0?ST([e,r]):ST([e,r,...t])}return ST(n==null?[e,r]:[e,r,n])}var ET=(e,t)=>TT(e,t),DT=(e,t)=>{let{state:n}=e,{selection:r}=n;if(!r.empty)return!1;let{$from:i}=r;if(i.parentOffset!==0)return!1;let a=i.depth-1;if(a<0)return!1;let o=i.node(a),s=i.index(a);if(s===0)return!1;if(o.type===t)return e.commands.lift(t.name);let c=o.child(s-1);if(c.type!==t||!c.lastChild?.isTextblock)return!1;let l=i.before()-1-1;return e.commands.command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=i.parent.content,r=new p(n,0,0);return e.replace(l,i.after(),r),e.setSelection(T.create(e.doc,l+n.size)),e.scrollIntoView(),t(e),!0})},OT=/^\s*>\s$/,kT=Jp.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return ET(`blockquote`,{...A(this.options.HTMLAttributes,e),children:ET(`slot`,{})})},parseMarkdown:(e,t)=>{let n=t.parseBlockChildren??t.parseChildren;return t.createNode(`blockquote`,void 0,n(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach((e,r)=>{let i=(t.renderChild?.call(t,e,r)??t.renderChildren([e])).split(` +`,textSerializers:n={}}=e||{};return qu(this.state.doc,{blockSeparator:t,textSerializers:{...Ju(this.schema),...n}})}get isEmpty(){return fd(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new zp(t,this,!1,n)}get $doc(){return this.$pos(0)}};function Hp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Up(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Wp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=Nu(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function Gp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=Nu(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&Ft(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&qt(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var Kp=e=>`touches`in e,qp=class{constructor(e){var t;this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.element.draggable=!1,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e!=null&&(t=e.options)!=null&&t.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type&&(this.node=e,!this.onUpdate||this.onUpdate(e,t,n))}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=this.node.type.isInline?`inline-flex`:`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,Kp(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}},Jp=class e extends gp{constructor(...e){super(...e),this.type=`node`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Yp(e){return new vp({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=Nu(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;dn.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Xp=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]);function Zp(e,t=600){let n=[],r=``;for(let i of e.replace(/\s+/g,` `).trim().split(/(?<=[.!?…])\s+/))r&&r.length+i.length>t&&(n.push(r),r=``),r=r?`${r} ${i}`:i;return r&&n.push(r),n}function Qp(e,t,n){let r=`

${Xp(t.summaryTitle.replace(`{name}`,e.name))}

`;e.summary?r+=n(e.summary):e.summaryError&&(r+=`

${Xp(e.summaryError)}

`);let i=Zp(e.text).map(e=>`

${Xp(e)}

`).join(``);return`${r}
${Xp(t.transcript)}
${i}
`}var $p=()=>new Map,em=e=>{let t=$p();return e.forEach((e,n)=>{t.set(n,e)}),t},tm=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},nm=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},rm=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},im=()=>new Set,am=e=>e[e.length-1],om=(e,t)=>{for(let n=0;n{for(let n=0;n{for(let n=0;n{let n=Array(e);for(let r=0;r{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return sm((this._observers.get(e)||$p()).values()).forEach(e=>e(...t))}destroy(){this._observers=$p()}},pm=class{constructor(){this._observers=$p()}on(e,t){tm(this._observers,e,im).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return sm((this._observers.get(e)||$p()).values()).forEach(e=>e(...t))}destroy(){this._observers=$p()}},mm=Math.floor,hm=Math.abs,gm=(e,t)=>ee>t?e:t;Number.isNaN;var vm=e=>e===0?1/e<0:e<0,ym=1<<29,bm=2**53-1,xm=-(2**53-1),Sm=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&mm(e)===e);Number.isNaN,Number.parseInt;var Cm=String.fromCharCode;String.fromCodePoint,Cm(65535);var wm=e=>e.toLowerCase(),Tm=/^\s*/g,Em=e=>e.replace(Tm,``),Dm=/([A-Z])/g,Om=(e,t)=>Em(e.replace(Dm,e=>`${t}${wm(e)}`)),km=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;eAm.encode(e):km,Mm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Mm&&Mm.decode(new Uint8Array).length===1&&(Mm=null);var Nm=(e,t)=>um(t,()=>e).join(``),Pm=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Fm=()=>new Pm,Im=e=>{let t=Fm();return e(t),Rm(t)},Lm=e=>{let t=e.cpos;for(let n=0;n{let t=new Uint8Array(Lm(e)),n=0;for(let r=0;r{let n=e.cbuf.length;n-e.cpos{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Vm=Bm,j=(e,t)=>{for(;t>127;)Bm(e,128|127&t),t=mm(t/128);Bm(e,127&t)},Hm=(e,t)=>{let n=vm(t);for(n&&(t=-t),Bm(e,(t>63?128:0)|(n?64:0)|63&t),t=mm(t/64);t>0;)Bm(e,(t>127?128:0)|127&t),t=mm(t/128)},Um=new Uint8Array(3e4),Wm=Um.length/3,Gm=Am&&Am.encodeInto?(e,t)=>{if(t.length{let n=unescape(encodeURIComponent(t)),r=n.length;j(e,r);for(let t=0;t{let n=e.cbuf.length,r=e.cpos,i=gm(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(_m(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},qm=(e,t)=>{j(e,t.byteLength),Km(e,t)},Jm=(e,t)=>{zm(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ym=(e,t)=>Jm(e,4).setFloat32(0,t,!1),Xm=(e,t)=>Jm(e,8).setFloat64(0,t,!1),Zm=(e,t)=>Jm(e,8).setBigInt64(0,t,!1),Qm=new DataView(new ArrayBuffer(4)),$m=e=>(Qm.setFloat32(0,e),Qm.getFloat32(0)===e),eh=(e,t)=>{switch(typeof t){case`string`:Bm(e,119),Gm(e,t);break;case`number`:Sm(t)&&hm(t)<=2147483647?(Bm(e,125),Hm(e,t)):$m(t)?(Bm(e,124),Ym(e,t)):(Bm(e,123),Xm(e,t));break;case`bigint`:Bm(e,122),Zm(e,t);break;case`object`:if(t===null)Bm(e,126);else if(dm(t)){Bm(e,117),j(e,t.length);for(let n=0;n0&&j(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},nh=e=>{e.count>0&&(Hm(e.encoder,e.count===1?e.s:-e.s),e.count>1&&j(e.encoder,e.count-2))},rh=class{constructor(){this.encoder=new Pm,this.s=0,this.count=0}write(e){this.s===e?this.count++:(nh(this),this.count=1,this.s=e)}toUint8Array(){return nh(this),Rm(this.encoder)}},ih=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Hm(e.encoder,t),e.count>1&&j(e.encoder,e.count-2)}},ah=class{constructor(){this.encoder=new Pm,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(ih(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return ih(this),Rm(this.encoder)}},oh=class{constructor(){this.sarr=[],this.s=``,this.lensE=new rh}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 Pm;return this.sarr.push(this.s),this.s=``,Gm(e,this.sarr.join(``)),Km(e,this.lensE.toUint8Array()),Rm(e)}},sh=e=>Error(e),ch=()=>{throw sh(`Method unimplemented`)},lh=()=>{throw sh(`Unexpected case`)},uh=sh(`Unexpected end of array`),dh=sh(`Integer out of Range`),fh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw uh;return new Uint8Array(e.buffer,e.byteOffset+t,n)},ph=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw uh;return new DataView(e.buffer,e.byteOffset+t,n)},mh=class{constructor(e){this.arr=e,this.pos=0}},hh=e=>new mh(e),gh=e=>e.pos!==e.arr.length,_h=(e,t)=>{let n=fh(e.arr,e.pos,t);return e.pos+=t,n},vh=e=>_h(e,M(e)),yh=e=>e.arr[e.pos++],M=e=>{let t=0,n=1,r=e.arr.length;for(;e.posbm)throw dh}throw uh},bh=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.posbm)throw dh}throw uh},xh=Mm?e=>Mm.decode(vh(e)):e=>{let t=M(e);if(t===0)return``;{let n=String.fromCodePoint(yh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(yh(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Sh=(e,t)=>{let n=ph(e.arr,e.pos,t);return e.pos+=t,n},Ch=[e=>void 0,e=>null,bh,e=>Sh(e,4).getFloat32(0,!1),e=>Sh(e,8).getFloat64(0,!1),e=>Sh(e,8).getBigInt64(0,!1),e=>!1,e=>!0,xh,e=>{let t=M(e),n={};for(let r=0;r{let t=M(e),n=[];for(let r=0;rCh[127-yh(e)](e),Th=class extends mh{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=gh(this)?M(this)+1:-1),this.count--,this.s}},Eh=class extends mh{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=bh(this);let e=vm(this.s);this.count=1,e&&(this.s=-this.s,this.count=M(this)+2)}return this.count--,this.s}},Dh=class extends mh{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=bh(this),t=e&1;this.diff=mm(e/2),this.count=1,t&&(this.count=M(this)+2)}return this.s+=this.diff,this.count--,this.s}},Oh=class{constructor(e){this.decoder=new Eh(e),this.str=xh(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var kh=crypto.getRandomValues.bind(crypto),Ah=Math.random,jh=()=>kh(new Uint32Array(1))[0],Mh=e=>e[mm(Ah()*e.length)],Nh=`10000000-1000-4000-8000-100000000000`,Ph=()=>Nh.replace(/[018]/g,e=>(e^jh()&15>>e/4).toString(16)),Fh=Date.now,Ih=e=>new Promise(e);Promise.all.bind(Promise);var Lh=e=>e===void 0?null:e,Rh=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Rh=localStorage)}catch{}var zh=Rh,Bh=Symbol(`Equality`),Vh=(e,t)=>e===t||!!e?.[Bh]?.(t)||!1,Hh=e=>typeof e==`object`,Uh=Object.assign,Wh=Object.keys,Gh=(e,t)=>{for(let n in e)t(e[n],n)},Kh=e=>Wh(e).length,qh=e=>{for(let t in e)return!1;return!0},Jh=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Yh=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Xh=(e,t)=>e===t||Kh(e)===Kh(t)&&Jh(e,(e,n)=>(e!==void 0||Yh(t,n))&&Vh(t[n],e)),Zh=Object.freeze,Qh=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Qh(e[t])}return Zh(e)},$h=(e,t,n=0)=>{try{for(;ne,tg=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Bh]!=null)return e[Bh](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;nt.includes(e),rg=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,ig=typeof window<`u`&&typeof document<`u`&&!rg;typeof navigator<`u`&&/Mac/.test(navigator.platform);var ag,og=[],sg=()=>{if(ag===void 0){if(rg){ag=$p();let e=process.argv,t=null;for(let n=0;n{if(e.length!==0){let[t,n]=e.split(`=`);ag.set(`--${Om(t,`-`)}`,n),ag.set(`-${Om(t,`-`)}`,n)}})):ag=$p()}return ag},cg=e=>sg().has(e),lg=e=>Lh(rg?{}[e.toUpperCase().replaceAll(`-`,`_`)]:zh.getItem(e)),ug=e=>cg(`--`+e)||lg(e)!==null,dg=ug(`production`),fg=rg&&ng({}.FORCE_COLOR,[`true`,`1`,`2`])||!cg(`--no-colors`)&&!ug(`no-color`)&&(!rg||process.stdout.isTTY)&&(!rg||cg(`--color`)||lg(`COLORTERM`)!==null||(lg(`TERM`)||``).includes(`color`)),pg=e=>new Uint8Array(e),mg=e=>{let t=``;for(let n=0;nBuffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),gg=e=>{let t=atob(e),n=pg(t.length);for(let e=0;enew Uint8Array(Buffer.from(e,`base64`)),vg=ig?mg:hg,yg=ig?gg:_g,bg=e=>{let t=pg(e.byteLength);return t.set(e),t},xg=e=>Im(t=>eh(t,e)),Sg=class{constructor(e,t){this.left=e,this.right=t}},Cg=(e,t)=>new Sg(e,t),wg=e=>e.next()>=.5,Tg=(e,t,n)=>mm(e.next()*(n+1-t)+t),Eg=(e,t,n)=>mm(e.next()*(n+1-t)+t),Dg=(e,t,n)=>Eg(e,t,n),Og=e=>Cm(Dg(e,97,122)),kg=(e,t=0,n=20)=>{let r=Dg(e,t,n),i=``;for(let t=0;tt[Dg(e,0,t.length-1)],jg=Symbol(`0schema`),Mg=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Nm(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(` +`)}},Ng=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Bh]?Vh(e,t):dm(e)?cm(e,e=>lm(t,t=>Ng(e,t))):Hh(e)?Jh(e,(e,n)=>Ng(e,t[n])):!1,Pg=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ng(t,n)}equals(e){return this.constructor===e.constructor&&tg(this.shape,e.shape)}[jg](){return!0}[Bh](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){ch()}get nullable(){return p_(this,O_)}get optional(){return new Gg(this)}cast(e){return M_(e,this),e}expect(e){return M_(e,this),e}},Fg=class extends Pg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Ig=(e,t=null)=>new Fg(e,t);Ig(Fg);var Lg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Rg=e=>new Lg(e);Ig(Lg);var zg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},Bg=(...e)=>new zg(e),Vg=Ig(zg),Hg=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Ug=e=>{if(C_.check(e))return[Hg(e)];if(Vg.check(e))return e.shape.map(e=>e+``);if(S_.check(e))return[`[+-]?\\d+.?\\d*`];if(w_.check(e))return[`.*`];if(m_.check(e))return e.shape.map(Ug).flat(1);lh()};Ig(class extends Pg{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ug).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Wg=Symbol(`optional`),Gg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Wg](){return!0}},Kg=Ig(Gg),qg=class extends Pg{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new qg,Ig(qg);var Jg=class e extends Pg{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Jh(this.shape,(n,r)=>{let i=this._isPartial&&!Yh(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Yg=e=>new Jg(e),Xg=Ig(Jg),Zg=Rg(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Qg=class extends Pg{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Jh(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},$g=(e,t)=>new Qg(e,t),e_=Ig(Qg),t_=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Jh(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},n_=(...e)=>new t_(e);Ig(t_);var r_=class extends Pg{constructor(e){super(),this.shape=e.length===1?e[0]:new f_(e)}check(e,t){let n=dm(e)&&cm(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},i_=(...e)=>new r_(e),a_=Ig(r_),o_=Rg(e=>dm(e)),s_=class extends Pg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},c_=(e,t=null)=>new s_(e,t);Ig(s_);var l_=c_(Pg),u_=Ig(class extends Pg{constructor(e){super(),this.len=e.length-1,this.args=n_(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),d_=Rg(e=>typeof e==`function`);Ig(class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=cm(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var f_=class extends Pg{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=lm(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},p_=(...e)=>e.findIndex(e=>m_.check(e))>=0?p_(...e.map(e=>j_(e)).map(e=>m_.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new f_(e),m_=Ig(f_),h_=()=>!0,g_=Rg(h_),__=Ig(Lg,e=>e.shape===h_),v_=Rg(e=>typeof e==`bigint`),y_=Rg(e=>e===v_),b_=Rg(e=>typeof e==`symbol`);Rg(e=>e===b_);var x_=Rg(e=>typeof e==`number`),S_=Rg(e=>e===x_),C_=Rg(e=>typeof e==`string`),w_=Rg(e=>e===C_),T_=Rg(e=>typeof e==`boolean`),E_=Rg(e=>e===T_),D_=Bg(void 0);Ig(zg,e=>e.shape.length===1&&e.shape[0]===void 0),Bg(void 0);var O_=Bg(null),k_=Ig(zg,e=>e.shape.length===1&&e.shape[0]===null);Ig(Uint8Array),Ig(Fg,e=>e.shape===Uint8Array);var A_=p_(x_,C_,O_,D_,v_,T_,b_);(()=>{let e=i_(g_),t=$g(C_,g_),n=p_(x_,C_,O_,T_,e,t);return e.shape=n,t.shape.values=n,n})();var j_=e=>{if(l_.check(e))return e;if(Zg.check(e)){let t={};for(let n in e)t[n]=j_(e[n]);return Yg(t)}if(o_.check(e))return p_(...e.map(j_));if(A_.check(e))return Bg(e);if(d_.check(e))return Ig(e);lh()},M_=dg?()=>{}:(e,t)=>{let n=new Mg;if(!t.check(e,n))throw sh(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},N_=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:j_(e),h:t}),this}else(e){return this.if(g_,e)}done(){return(e,t)=>{for(let n=0;nnew N_(e))(g_).if(S_,(e,t)=>Tg(t,xm,bm)).if(w_,(e,t)=>kg(t)).if(E_,(e,t)=>wg(t)).if(y_,(e,t)=>BigInt(Tg(t,xm,bm))).if(m_,(e,t)=>F_(t,Ag(t,e.shape))).if(Xg,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Kg.check(i)){if(wg(t))continue;i=i.shape}n[r]=P_(i,t)}return n}).if(a_,(e,t)=>{let n=[],r=Eg(t,0,42);for(let i=0;iAg(t,e.shape)).if(k_,(e,t)=>null).if(u_,(e,t)=>{let n=F_(t,e.res);return()=>n}).if(__,(e,t)=>F_(t,Ag(t,[x_,C_,O_,D_,v_,T_,i_(x_),$g(p_(`a`,`b`,`c`),x_)]))).if(e_,(e,t)=>{let n={},r=Tg(t,0,3);for(let i=0;iP_(j_(t),e),I_=typeof document<`u`?document:{};Rg(e=>e.nodeType===V_),typeof DOMParser<`u`&&new DOMParser,Rg(e=>e.nodeType===R_),Rg(e=>e.nodeType===z_);var L_=e=>nm(e,(e,t)=>`${t}:${e};`).join(``),R_=I_.ELEMENT_NODE,z_=I_.TEXT_NODE;I_.CDATA_SECTION_NODE,I_.COMMENT_NODE;var B_=I_.DOCUMENT_NODE;I_.DOCUMENT_TYPE_NODE;var V_=I_.DOCUMENT_FRAGMENT_NODE;Rg(e=>e.nodeType===B_);var H_=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),U_=(e,t)=>new H_(setTimeout(t,e)),W_=Symbol,G_=W_(),K_=W_(),q_=W_(),J_=W_(),Y_=W_(),X_=W_(),Z_=W_(),Q_=W_(),$_=W_(),ev=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r0&&n.push(t.join(``));r{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=$p(),i=[],a=0;for(;a0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a{console.log(...nv(e)),av.forEach(t=>t.print(e))},iv=(...e)=>{console.warn(...nv(e)),e.unshift(Q_),av.forEach(t=>t.print(e))},av=im(),ov=e=>({[Symbol.iterator](){return this},next:e}),sv=(e,t)=>ov(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),cv=(e,t)=>ov(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),lv=class{constructor(e,t){this.clock=e,this.len=t}},uv=class{constructor(){this.clients=new Map}},dv=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r{let n=0,r=e.length-1;for(;n<=r;){let i=mm((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t{let n=e.clients.get(t.client);return n!==void 0&&fv(n,t.clock)!==null},mv=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t=i.clock?e[n-1]=new lv(r.clock,_m(r.len,i.clock+i.len-r.clock)):(n{let t=new uv;for(let n=0;n{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t{tm(e.clients,t,()=>[]).push(new lv(n,r))},_v=()=>new uv,vv=e=>{let t=_v();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t0&&t.clients.set(n,r)}),t},yv=(e,t)=>{j(e.restEncoder,t.clients.size),sm(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),j(e.restEncoder,t);let r=n.length;j(e.restEncoder,r);for(let t=0;t{let t=new uv,n=M(e.restDecoder);for(let r=0;r0){let i=tm(t.clients,n,()=>[]);for(let t=0;t{let r=new uv,i=M(e.restDecoder);for(let a=0;a0){let e=new jv;return j(e.restEncoder,0),yv(e,r),e.toUint8Array()}return null},Sv=jh,Cv=class e extends fm{constructor({guid:e=Ph(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Sv(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Sy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ih(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Ih(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&By(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(sm(this.subdocs).map(e=>e.guid))}transact(e,t=null){return By(this,e,t)}get(e,t=gb){let n=tm(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==gb&&r!==t){if(r===gb){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Lb)}getText(e=``){return this.get(e,ix)}getMap(e=``){return this.get(e,Bb)}getXmlElement(e=``){return this.get(e,lx)}getXmlFragment(e=``){return this.get(e,sx)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,sm(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,By(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},wv=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return M(this.restDecoder)}readDsLen(){return M(this.restDecoder)}},Tv=class extends wv{readLeftID(){return N(M(this.restDecoder),M(this.restDecoder))}readRightID(){return N(M(this.restDecoder),M(this.restDecoder))}readClient(){return M(this.restDecoder)}readInfo(){return yh(this.restDecoder)}readString(){return xh(this.restDecoder)}readParentInfo(){return M(this.restDecoder)===1}readTypeRef(){return M(this.restDecoder)}readLen(){return M(this.restDecoder)}readAny(){return wh(this.restDecoder)}readBuf(){return bg(vh(this.restDecoder))}readJSON(){return JSON.parse(xh(this.restDecoder))}readKey(){return xh(this.restDecoder)}},Ev=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=M(this.restDecoder),this.dsCurrVal}readDsLen(){let e=M(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Dv=class extends Ev{constructor(e){super(e),this.keys=[],M(e),this.keyClockDecoder=new Dh(vh(e)),this.clientDecoder=new Eh(vh(e)),this.leftClockDecoder=new Dh(vh(e)),this.rightClockDecoder=new Dh(vh(e)),this.infoDecoder=new Th(vh(e),yh),this.stringDecoder=new Oh(vh(e)),this.parentInfoDecoder=new Th(vh(e),yh),this.typeRefDecoder=new Eh(vh(e)),this.lenDecoder=new Eh(vh(e))}readLeftID(){return new ey(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ey(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 wh(this.restDecoder)}readBuf(){return vh(this.restDecoder)}readJSON(){return wh(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=_m(r,t[0].id.clock);let i=Ey(t,r);j(e.restEncoder,t.length-i),e.writeClient(n),j(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n{let r=new Map;n.forEach((e,n)=>{wy(t,n)>e&&r.set(n,e)}),Cy(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),j(e.restEncoder,r.size),sm(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Mv(e,t.clients.get(n),n,r)})},Pv=(e,t)=>{let n=$p(),r=M(e.restDecoder);for(let i=0;i{let r=[],i=sm(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new Sy,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==nS){let i=tm(d,u.id.client,()=>wy(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,wy(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i0)u=r.pop();else if(o!==null&&o.i0){let e=new jv;return Nv(e,s,new Map),j(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Iv=(e,t)=>Nv(e,t.doc.store,t.beforeState),Lv=(e,t,n,r=new Dv(e))=>By(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Fv(e,i,Pv(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(nt)&&o.missing.set(e,t)}o.update=Xy([o.update,a.update])}}else i.pendingStructs=a;let s=xv(r,e,i);if(i.pendingDs){let t=new Dv(hh(i.pendingDs));M(t.restDecoder);let n=xv(t,e,i);i.pendingDs=s&&n?Xy([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Rv(e.doc,t)}},n,!1),Rv=(e,t,n,r=Dv)=>{let i=hh(t);Lv(i,e,n,new r(i))},zv=(e,t,n)=>Rv(e,t,n,Tv),Bv=(e,t,n=new Map)=>{Nv(e,t.store,n),yv(e,vv(t.store))},Vv=(e,t=new Uint8Array([0]),n=new jv)=>{Bv(n,e,Wv(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Zy(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===kv)return Jy(r.map((e,t)=>t===0?e:nb(e)));if(n.constructor===jv)return Xy(r)}return r[0]},Hv=(e,t)=>Vv(e,t,new kv),Uv=e=>{let t=new Map,n=M(e.restDecoder);for(let r=0;rUv(new wv(hh(e))),Gv=(e,t)=>(j(e.restEncoder,t.size),sm(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{j(e.restEncoder,t),j(e.restEncoder,n)}),e),Kv=(e,t)=>Gv(e,Cy(t.store)),qv=(e,t=new Av)=>(e instanceof Map?Gv(t,e):Kv(t,e),t.toUint8Array()),Jv=e=>qv(e,new Ov),Yv=class{constructor(){this.l=[]}},Xv=()=>new Yv,Zv=(e,t)=>e.l.push(t),Qv=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},$v=(e,t,n)=>$h(e.l,[t,n]),ey=class{constructor(e,t){this.client=e,this.clock=t}},ty=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,N=(e,t)=>new ey(e,t),ny=e=>N(M(e),M(e)),ry=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw lh()},iy=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},ay=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},oy=e=>new ay(e.type==null?null:N(e.type.client,e.type.clock),e.tname??null,e.item==null?null:N(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),sy=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},cy=(e,t,n=0)=>new sy(e,t,n),ly=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ry(e):r=N(e._item.id.client,e._item.id.clock),new ay(r,i,t,n)},uy=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ly(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ly(e,N(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ly(e,r.lastId,n);r=r.right}return ly(e,null,n)},dy=e=>{let t=null,n=null,r=null;switch(M(e)){case 0:r=ny(e);break;case 1:n=xh(e);break;case 2:t=ny(e)}let i=gh(e)?bh(e):0;return new ay(t,n,r,i)},fy=e=>dy(hh(e)),py=(e,t)=>{let n=Dy(e,t);return{item:n,diff:t.clock-n.id.clock}},my=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(wy(r,i.client)<=i.clock)return null;let e=n?qx(r,i):py(r,i),t=e.item;if(!(t instanceof Qx))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(wy(r,a.client)<=a.clock)return null;let{item:e}=n?qx(r,a):{item:Dy(r,a)};if(e instanceof Qx&&e.content instanceof Gx)c=e.content.type;else return null}else throw lh();l=s>=0?c._length:0}return cy(c,l,e.assoc)},hy=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&ty(e.item,t.item)&&ty(e.type,t.type)&&e.assoc===t.assoc,gy=class{constructor(e,t){this.ds=e,this.sv=t}},_y=(e,t)=>new gy(e,t),vy=_y(_v(),new Map),yy=e=>_y(vv(e.store),Cy(e.store)),by=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!pv(t.ds,e.id),xy=(e,t)=>{let n=tm(e.meta,xy,im),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t{}),n.add(t))},Sy=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Cy=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},wy=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Ty=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw lh()}n.push(t)},Ey=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=mm(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t{let n=e.clients.get(t.client);return n[Ey(n,t.clock)]},Oy=(e,t,n)=>{let r=Ey(t,n),i=t[r];return i.id.clock{let n=e.doc.store.clients.get(t.client);return n[Oy(e,n,t.clock)]},Ay=(e,t,n)=>{let r=t.clients.get(n.client),i=Ey(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==vx&&r.splice(i+1,0,Yx(e,a,n.clock-a.id.clock+1)),a},jy=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Ey(r,t.id.clock)]=n},My=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Oy(e,t,n),s;do s=t[o++],at.deleteSet.clients.size===0&&!rm(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(mv(t.deleteSet),Iv(e,t),yv(e,t.deleteSet),!0),Fy=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&tm(e.changed,t,im).add(n)},Iy=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Qx&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Ly=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Ey(e,a.clock),i=e[r];r{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=gm(r.length-1,1+Ey(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Iy(r,e)}})},zy=(e,t)=>{if(te.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),$v(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&tx(n)})}),$h(e,[])}finally{r.gc&&Ly(a,i,r.gcFilter),Ry(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=_m(Ey(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Iy(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Ey(r,n);a+11||a>0&&Iy(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(rv(Q_,G_,`[yjs] `,K_,X_,`Changed the client-id because another client seems to be using it.`),r.clientID=Sv()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new kv;Py(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new jv;Py(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):zy(e,t+1)}}},By=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Ny(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&zy(i,0)}}return o},Vy=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Hy=(e,t,n)=>{dv(e,n.deletions,n=>{n instanceof Qx&&t.scope.some(t=>t===e.doc||iy(t,n))&&Jx(n,!1)})},Uy=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;By(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;dv(n,o.insertions,e=>{if(e instanceof Qx){if(e.redone!==null){let{item:t,diff:i}=qx(r,e.id);i>0&&(t=ky(n,N(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||iy(t,e))&&c.push(e)}}),dv(n,o.deletions,e=>{e instanceof Qx&&a.some(t=>t===n.doc||iy(t,e))&&!pv(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Zx(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Wy=class extends fm{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=dm(e)?e[0].doc:e instanceof Cv?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new uv;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&gv(i,n,r,a)});let a=Fh(),o=!1;if(this.lastChange>0&&a-this.lastChange0&&!t&&!n){let t=r[r.length-1];t.deletions=hv([t.deletions,e.deleteSet]),t.insertions=hv([t.insertions,i])}else r.push(new Vy(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),dv(e,e.deleteSet,t=>{t instanceof Qx&&this.scope.some(n=>n===e.doc||iy(n,t))&&Jx(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=dm(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof gb?e.doc!==this.doc:e!==this.doc)&&iv(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Hy(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Hy(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Uy(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Uy(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Gy(e){let t=M(e.restDecoder);for(let n=0;nXy(e,Tv,kv),Yy=(e,t)=>{if(e.constructor===vx){let{client:n,clock:r}=e.id;return new vx(N(n,r+t),e.length-t)}if(e.constructor===nS){let{client:n,clock:r}=e.id;return new nS(N(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Qx(N(r,i+t),null,N(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Xy=(e,t=Dv,n=jv)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(hh(e))),i=r.map(e=>new Ky(e,!0)),a=null,o=new n,s=new qy(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===nS?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)$y(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length0&&(a.struct.constructor===nS?a.struct.length-=t:n=Yy(n,t)),a.struct.mergeWith(n)||($y(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==nS;n=e.next())$y(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&($y(s,a.struct,a.offset),a=null),eb(s),yv(o,hv(r.map(e=>bv(e)))),o.toUint8Array()},Zy=(e,t,n=Dv,r=jv)=>{let i=Wv(t),a=new r,o=new qy(a),s=new n(hh(e)),c=new Ky(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===nS)c.next();else if(e.id.clock+e.length>n)for($y(o,e,_m(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)$y(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return eb(o),yv(a,bv(s)),a.toUint8Array()},Qy=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Rm(e.encoder.restEncoder)}),e.encoder.restEncoder=Fm(),e.written=0)},$y=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Qy(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),j(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},eb=e=>{Qy(e);let t=e.encoder.restEncoder;j(t,e.clientStructs.length);for(let n=0;n{let i=new n(hh(e)),a=new Ky(i,!1),o=new r,s=new qy(o);for(let e=a.curr;e!==null;e=a.next())$y(s,t(e),0);return eb(s),yv(o,bv(i)),o.toUint8Array()},nb=e=>tb(e,eg,Dv,kv),rb=`You must not compute changes after the event-handler fired.`,ib=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||=ab(this.currentTarget,this.target)}deletes(e){return pv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw sh(rb);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=am(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=am(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=am(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw sh(rb);let t=this.target,n=im(),r=im(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},ab=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},ob=()=>{iv(`Invalid access: Add Yjs type to a document before reading data.`)},sb=80,cb=0,lb=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=cb++}},ub=e=>{e.timestamp=cb++},db=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=cb++},fb=(e,t,n)=>{if(e.length>=sb){let r=e.reduce((e,t)=>e.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>hm(t-e.index)t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&hm(n.index-i){for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t0&&t===i.index)&&(i.index=_m(t,i.index+n))}},hb=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;tm(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;$v(r._eH,n,t)},gb=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Xv(),this._dEH=Xv(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw ch()}clone(){throw ch()}_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){Zv(this._eH,e)}observeDeep(e){Zv(this._dEH,e)}unobserve(e){Qv(this._eH,e)}unobserveDeep(e){Qv(this._dEH,e)}toJSON(){}},_b=(e,t,n)=>{e.doc??ob(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},vb=e=>{e.doc??ob();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n{let n=[],r=e._start;for(;r!==null;){if(r.countable&&by(r,t)){let e=r.content.getContent();for(let t=0;t{let n=0,r=e._start;for(e.doc??ob();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r{let n=[];return bb(e,(r,i)=>{n.push(t(r,i,e))}),n},Sb=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},Cb=(e,t)=>{e.doc??ob();let n=pb(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Nx(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new yx(new Uint8Array(n))),i.integrate(e,0);break;case Cv:i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wx(n)),i.integrate(e,0);break;default:if(n instanceof gb)i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Gx(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},Tb=()=>sh(`Length exceeded!`),Eb=(e,t,n,r)=>{if(n>t._length)throw Tb();if(n===0)return t._searchMarker&&mb(t._searchMarker,n,r.length),wb(e,t,null,r);let i=n,a=pb(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return wb(e,t,r,n)},Ob=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=pb(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n0&&s!==null;)s.deleted||(r0)throw Tb();t._searchMarker&&mb(t._searchMarker,i,-a+r)},kb=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Ab=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Nx([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Nx([r]);break;case Uint8Array:s=new yx(r);break;case Cv:s=new wx(r);break;default:if(r instanceof gb)s=new Gx(r);else throw Error(`Unexpected content type`)}new Qx(N(o,wy(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},jb=(e,t)=>{e.doc??ob();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Mb=e=>{let t={};return e.doc??ob(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Nb=(e,t)=>{e.doc??ob();let n=e._map.get(t);return n!==void 0&&!n.deleted},Pb=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&by(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Fb=e=>(e.doc??ob(),sv(e._map.entries(),e=>!e[1].deleted)),Ib=class extends ib{},Lb=class e extends gb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}get length(){return this.doc??ob(),this._length}_callObserver(e,t){super._callObserver(e,t),hb(this,e,new Ib(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):By(this.doc,n=>{Eb(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):By(this.doc,t=>{Db(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):By(this.doc,n=>{Ob(n,this,e,t)})}get(e){return Cb(this,e)}toArray(){return vb(this)}slice(e=0,t=this.length){return _b(this,e,t)}toJSON(){return this.map(e=>e instanceof gb?e.toJSON():e)}map(e){return xb(this,e)}forEach(e){bb(this,e)}[Symbol.iterator](){return Sb(this)}_write(e){e.writeTypeRef(Rx)}},Rb=e=>new Lb,zb=class extends ib{constructor(e,t,n){super(e,t),this.keysChanged=n}},Bb=class e extends gb{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof gb?e.clone():e)}),t}_callObserver(e,t){hb(this,e,new zb(this,e,t))}toJSON(){this.doc??ob();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof gb?r.toJSON():r}}),e}get size(){return[...Fb(this)].length}keys(){return cv(Fb(this),e=>e[0])}values(){return cv(Fb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return cv(Fb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ob(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):By(this.doc,t=>{kb(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):By(this.doc,n=>{Ab(n,this,e,t)}),t}get(e){return jb(this,e)}has(e){return Nb(this,e)}clear(){this.doc===null?this._prelimContent.clear():By(this.doc,e=>{this.forEach(function(t,n,r){kb(e,r,n)})})}_write(e){e.writeTypeRef(zx)}},Vb=e=>new Bb,Hb=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Xh(e,t),Ub=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&lh(),this.right.content.constructor){case Ox:this.right.deleted||qb(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Wb=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Ox:t.right.deleted||qb(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{let i=new Map,a=r?pb(t,n):null;return a?Wb(e,new Ub(a.p.left,a.p,a.index,i),n-a.index):Wb(e,new Ub(null,t._start,0,i),n)},Kb=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Ox&&Hb(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Qx(N(a,wy(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Ox(o,r));l.integrate(e,0),n.right=l,n.forward()})},qb=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Jb=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Ox&&Hb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Yb=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Hb(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Qx(N(a,wy(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Ox(s,c)),n.right.integrate(e,0),n.forward()}}return o},Xb=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Jb(n,i);let s=Yb(e,t,n,i),c=r.constructor===String?new Fx(r):r instanceof gb?new Gx(r):new Ex(r),{left:l,right:u,index:d}=n;t._searchMarker&&mb(t._searchMarker,n.index,c.getLength()),u=new Qx(N(o,wy(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Kb(e,t,n,s)},Zb=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Jb(n,i);let s=Yb(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Ox));){if(!n.right.deleted)switch(n.right.content.constructor){case Ox:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Hb(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r0){let i=``;for(;r>0;r--)i+=` +`;n.right=new Qx(N(o,wy(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Fx(i)),n.right.integrate(e,0),n.forward()}Kb(e,t,n,s)},Qb=(e,t,n,r,i)=>{let a=t,o=$p();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Ox){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Ox:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&qb(i,n);break}}}t=t.right}return s},$b=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Ox){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},ex=e=>{let t=0;return By(e.doc,n=>{let r=e._start,i=e._start,a=$p(),o=em(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Ox:qb(o,i.content);break;default:t+=Qb(n,r,i,a,o),a=em(o),r=i}i=i.right}}),t},tx=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&My(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Ox&&e.constructor!==vx&&t.add(e.parent)})}By(n,n=>{dv(e,e.deleteSet,e=>{if(e instanceof vx||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Ox?t.add(r):$b(n,e)});for(let e of t)ex(e)})},nx=(e,t,n)=>{let r=n,i=em(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Gx:case Ex:case Fx:n{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];By(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},qh(o)||(e.attributes=Uh({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Gx:case Ex:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Fx:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Ox:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Hb(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Hb(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Hb(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Hb(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),qb(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ix=class e extends gb{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ob(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new rx(this,e,t);hb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ob();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Fx&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):By(this.doc,n=>{let r=new Ub(null,this._start,0,new Map);for(let i=0;i0)&&Xb(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&nx(n,r,a.delete):Zb(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??ob();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(by(s,e)||t!==void 0&&by(s,t))switch(s.content.constructor){case Fx:{let r=i.get(`ychange`);e!==void 0&&!by(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!by(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Gx:case Ex:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Ox:by(s,e)&&(c(),qb(i,s.content))}s=s.right}c()};return e||t?By(a,n=>{e&&xy(n,e),t&&xy(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):By(r,r=>{let i=Gb(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Xb(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):By(r,r=>{let i=Gb(r,this,e,!n);Xb(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):By(n,n=>{nx(n,Gb(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):By(r,r=>{let i=Gb(r,this,e,!1);i.right!==null&&Zb(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):By(this.doc,t=>{kb(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):By(this.doc,n=>{Ab(n,this,e,t)})}getAttribute(e){return jb(this,e)}getAttributes(){return Mb(this)}_write(e){e.writeTypeRef(Bx)}},ax=e=>new ix,ox=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ob()}[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===lx||t.constructor===sx)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},sx=class e extends gb{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}get length(){return this.doc??ob(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ox(this,e)}querySelector(e){e=e.toUpperCase();let t=new ox(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),sm(new ox(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){hb(this,e,new dx(this,t,e))}toString(){return xb(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),bb(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):By(this.doc,n=>{Eb(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)By(this.doc,n=>{let r=e&&e instanceof gb?e._item:e;wb(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw sh(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):By(this.doc,n=>{Ob(n,this,e,t)})}toArray(){return vb(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Cb(this,e)}slice(e=0,t=this.length){return _b(this,e,t)}forEach(e){bb(this,e)}_write(e){e.writeTypeRef(Hx)}},cx=e=>new sx,lx=class e extends sx{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Gh(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i0?` `+t.join(` `):``}>${super.toString()}`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):By(this.doc,t=>{kb(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):By(this.doc,n=>{Ab(n,this,e,t)})}getAttribute(e){return jb(this,e)}hasAttribute(e){return Nb(this,e)}getAttributes(e){return e?Pb(this,e):Mb(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return bb(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Vx),e.writeKey(this.nodeName)}},ux=e=>new lx(e.readKey()),dx=class extends ib{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},fx=class e extends Bb{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Ux),e.writeKey(this.hookName)}},px=e=>new fx(e.readKey()),mx=class e extends ix{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.keye.nodeName`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=``;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Wx)}},hx=e=>new mx,gx=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw ch()}mergeWith(e){return!1}write(e,t,n){throw ch()}integrate(e,t){throw ch()}},_x=0,vx=class extends gx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Ty(e.doc.store,this)}write(e,t){e.writeInfo(_x),e.writeLen(this.length-t)}getMissing(e,t){return null}},yx=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},bx=e=>new yx(e.readBuf()),xx=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){gv(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=e=>new xx(e.readLen()),Cx=(e,t)=>new Cv({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),wx=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Cx(this.doc.guid,this.opts))}splice(e){throw ch()}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}},Tx=e=>new wx(Cx(e.readString(),e.readAny())),Ex=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Dx=e=>new Ex(e.readJSON()),Ox=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},kx=e=>new Ox(e.readKey(),e.readJSON()),Ax=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r{let t=e.readLen(),n=[];for(let r=0;r{let t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Ix=e=>new Fx(e.readString()),Lx=[Rb,Vb,ax,ux,cx,px,hx],Rx=0,zx=1,Bx=2,Vx=3,Hx=4,Ux=5,Wx=6,Gx=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Kx=e=>new Gx(Lx[e.readTypeRef()](e)),qx=(e,t)=>{let n=t,r=0,i;do r>0&&(n=N(n.client,n.clock+r)),i=Dy(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Qx);return{item:i,diff:r}},Jx=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Yx=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Qx(N(r,i+n),t,N(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=N(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Xx=(e,t)=>lm(e,e=>pv(e.deletions,t)),Zx=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return ky(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Zx(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=ky(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:ky(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:ky(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||pv(r,d.right.id)||Xx(a.undoStack,d.right.id)||Xx(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=ky(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=N(c,wy(s,c)),h=new Qx(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Jx(h,!0),h.integrate(e,0),h},Qx=class e extends gx{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=wy(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=wy(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ey&&this.id.client!==this.parent.client&&this.parent.clock>=wy(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Ay(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=ky(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===vx||this.right&&this.right.constructor===vx)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ey){let e=Dy(n,this.parent);this.parent=e.constructor===vx?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Ay(e,e.doc.store,N(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ty(this.origin,n.origin)){if(n.id.client{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),gv(e.deleteSet,this.id.client,this.id.clock,this.length),Fy(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw lh();this.content.gc(e),t?jy(e,this,new vx(this.id,this.length)):this.content=new xx(this.length)}write(e,t){let n=t>0?N(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ry(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ey?(e.writeParentInfo(!1),e.writeLeftID(t)):lh();i!==null&&e.writeString(i)}this.content.write(e,t)}},$x=(e,t)=>eS[t&31](e),eS=[()=>{lh()},Sx,jx,bx,Ix,Dx,kx,Kx,Px,Tx,()=>{lh()}],tS=10,nS=class extends gx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){lh()}write(e,t){e.writeInfo(tS),j(e.restEncoder,this.length-t)}getMissing(e,t){return null}},rS=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},iS=`__ $YJS$ __`;rS[iS]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),rS[iS]=!0;var aS=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},oS=(e,t)=>e>>>t|e<<32-t,sS=e=>oS(e,2)^oS(e,13)^oS(e,22),cS=e=>oS(e,6)^oS(e,11)^oS(e,25),lS=e=>oS(e,7)^oS(e,18)^e>>>3,uS=e=>oS(e,17)^oS(e,19)^e>>>10,dS=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),fS=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),pS=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(fS),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=uS(t[e-2])+t[e-7]+lS(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+cS(o)+(o&s^~o&c)+dS[e]+t[e]>>>0,d=sS(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3=0&&t>>(3-t)*8;return i}},mS=e=>new pS().digest(e),hS=/[\uD800-\uDBFF]/,gS=/[\uDC00-\uDFFF]/,_S=(e,t)=>{let n=0,r=0;for(;n0&&hS.test(e[n-1])&&n--;r+n0&&gS.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}};function vS(e){if(!e||!(e.content instanceof Gx))return null;let t=e.content.type;if(!(t instanceof sx||t instanceof ix||t instanceof fx))throw Error(`Expected a Yjs XML type`);return t}function yS(e){if(e===null)return null;if(!(e.parent instanceof gb))throw Error(`Expected an integrated Yjs parent`);let t=e.parent;if(!(t instanceof sx||t instanceof ix||t instanceof fx))throw Error(`Expected a Yjs XML type`);return t}var bS=(e,t)=>{let n=null,r=null;return e._item===null?r=ry(e):n=N(e._item.id.client,e._item.id.clock),new ay(n,r,t.id)},xS=(e,t,n)=>{if(e===0)return uy(t,0,-1);let r=vS(t._first);for(;r!==null&&t!==r;){if(r instanceof mx){if(r._length>=e)return uy(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=vS(r._item.next);else{do r=yS(r._item),e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:vS(r._item.next))}}else{let i=n.get(r),a=i instanceof ce?i.nodeSize:0;if(r._first!==null&&e1)return new ay(r._item===null?null:r._item.id,r._item===null?ry(r):null,null);if(e-=a,r._item!==null&&r._item.next!==null)r=vS(r._item.next);else{if(e===0){if(r=r._item===null?r:yS(r._item),r===null)throw lh();return new ay(r._item===null?null:r._item.id,r._item===null?ry(r):null,null)}do{if(r=yS(r._item),r===null)throw lh();e--}while(r!==t&&r._item?.next===null);r!==t&&(r=vS(r._item?.next))}}}if(r===null)throw lh();if(e===0&&r.constructor!==mx&&r!==t){let e=r._item,t=yS(e);if(e===null||t===null)throw lh();return bS(t,e)}}return uy(t,t._length,-1)},SS=(e,t)=>{if(!e.docChanged)return!1;if(e.doc.childCount!==t.childCount)return!0;for(let n of e.steps)if(n instanceof Et){if(n.from===0&&n.to===t.content.size)return!0;if(n.slice.content.size>0){let e=!1;if(n.slice.content.forEach(t=>{t.isBlock&&(e=!0)}),e)return!0}else if(n.to>n.from){let e=t.resolve(n.from),r=t.resolve(n.to);if(e.depth===0&&r.depth===0&&e.index()!==r.index())return!0}}return!1};function CS(e,t){if(e instanceof mx)return e._length;let n=t.get(e);return n instanceof ce?n.nodeSize:null}function wS(e,t,n){let r=0,i=e._first;for(;i!==null;){let e=vS(i);if(e===t)break;let a=i.deleted;if(i=i.right,a)continue;if(e===null)return null;let o=CS(e,n);if(o===null)return null;r+=o}return r}function TS(e,t,n){let r=0,i=0,a=e._first;for(;i{if(n===null)return!1;let r=my(t,e);return r!==null&&r.type instanceof mx&&t.item!==null&&r.type._item?.deleted===!0},DS=e=>{if(!e.doc)throw Error(`The Yjs fragment must belong to a document`);let t=e._item?`item:${e._item.id.client}:${e._item.id.clock}`:`root:${ry(e)}`;return e.doc.getMap(`__tiptap_position_migrations:${t}`)},OS=new WeakMap,kS=(e,t)=>{let n=t.item??t.type;if(!n)return[];let r;t.item||(r=t.assoc<0?`start`:`end`);let i=OS.get(e);if(!i||i.size!==e.size){let t=new Map;e.forEach(e=>e.transfers.forEach(n=>{let r=t.get(n.source.client)??[];r.push({migration:e,transfer:n}),t.set(n.source.client,r)})),i={size:e.size,clients:t},OS.set(e,i)}let a=(i.clients.get(n.client)??[]).filter(({transfer:e})=>e.source.boundary===r&&e.source.clock<=n.clock&&n.clock!a.some(t=>t.migration!==e.migration&&t.migration.seen.some(([t,n])=>t===e.migration.client&&n>e.migration.clock)))},AS=(e,t,n)=>{let{source:r,target:i}=e.transfer;return i?new ay(i.boundary?N(i.client,i.clock):i.type,i.tname??null,i.boundary?null:N(i.client,i.clock+t.clock-r.clock),i.assoc??n):null},jS=(e,t,n)=>{let r=AS(e[0],t,n);return!r||e.some(e=>{let i=AS(e,t,n);return!i||!hy(r,i)})?null:r},MS=e=>{let t=e.item??e.type;if(!t)return null;let n=e.assoc<0?`start`:`end`;return e.item&&(n=`item`),`${t.client}:${t.clock}:${n}`},NS=(e,t)=>{let n=DS(e),r=new Set,i=t,a=i.item??i.type;for(;a;){let e=MS(i);if(r.has(e))return null;r.add(e);let t=kS(n,i);if(t.length===0)return i;let o=jS(t,a,i.assoc);if(!o)return null;if(MS(o)===e)return o;i=o,a=o.item??o.type}return i},PS=(e,t,n,r)=>{let i=NS(t,n);if(!i)return null;n=i;let a=my(n,e);if(a===null||a.type!==t&&!iy(t,a.type._item))return null;let o=a.type,s=0;if(o.constructor===mx)s=a.index;else if(!o._item?.deleted){let e=TS(o,a.index,r);if(e===null)return null;s=e+1}for(;o!==t&&o._item!==null;){let e=yS(o._item);if(e===null)return null;if(e._item?.deleted){o=e;continue}let t=wS(e,o,r);if(t===null)return null;s+=t+1,o=e}let c=s-1;return ES(e,n,c)?null:c},FS=new Un(`y-sync`),IS=new Un(`y-undo`),LS=new Un(`yjs-cursor`),RS=null;function zS(){let e=RS;RS=null;let t=[];return e?.forEach((e,n)=>{e.forEach((e,r)=>t.push({view:n,key:r,value:e}))}),t}function BS(e=zS(),t=!1){let n=!0;for(;e.length>0;){let{view:r,key:i,value:a}=e[0];try{let e=FS.getState(r.state);e&&e.binding.prosemirrorView!==null&&r.dispatch(r.state.tr.setMeta(i,a))}catch(r){if(!(r instanceof RangeError))throw r;t&&n&&e.shift(),e.length>0&&U_(0,()=>BS(e,!0));return}n=!1,e.shift()}}function VS(e,t,n){RS===null&&(RS=new Map,U_(0,BS));let r=RS.get(e);r||(r=new Map,RS.set(e,r)),r.set(t,n)}var HS=(e,t,n)=>e!==t,US=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(`⁠`),i=document.createTextNode(`⁠`);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},WS=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),GS=/^#[0-9a-fA-F]{6}$/,KS=e=>typeof e.name==`string`&&typeof e.color==`string`,qS=(e,t,n,r,i)=>{let a=FS.getState(e);if(a==null||a.doc==null||a.binding==null)return xs.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?xs.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t&&t.cursor!=null){let n={...t.user};if(n.color==null?n.color=`#ffa500`:GS.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`,!KS(n))return;let l=PS(o,a.type,oy(t.cursor.anchor),a.binding.mapping),u=PS(o,a.type,oy(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=_m(e.doc.content.size-1,0);l=gm(l,t),u=gm(u,t),s.push(vs.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=gm(l,u),o=_m(l,u);s.push(vs.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),xs.create(e.doc,s))},JS=(e,{awarenessStateFilter:t=HS,cursorBuilder:n=US,selectionBuilder:r=WS,getSelection:i=e=>e.selection}={},a=`cursor`)=>new D({key:LS,state:{init(i,a){return qS(a,e,t,n,r)},apply(i,a,o,s){let c=FS.getState(s),l=i.getMeta(LS),u=c&&c.isChangeOrigin;return i.docChanged&&!u&&SS(i,o.doc)?xs.empty:u||l&&l.awarenessUpdated?qS(s,e,t,n,r):i.docChanged?a.map(i.mapping,i.doc):a}},props:{decorations:e=>LS.getState(e)??xs.empty},view:t=>{let n=()=>{t.isDestroyed||VS(t,LS,{awarenessUpdated:!0})},r=t=>{let n=FS.getState(t.state);if(!n||!n.binding)return;let r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=xS(o.anchor,n.type,n.binding.mapping),c=xS(o.head,n.type,n.binding.mapping);r.cursor!=null&&hy(oy(r.cursor.anchor),s)&&hy(oy(r.cursor.head),c)||e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&PS(n.doc,n.type,oy(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)},o=()=>r(t);return e.on(`change`,n),t.dom.addEventListener(`focusin`,o),t.dom.addEventListener(`focusout`,o),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,o),t.dom.removeEventListener(`focusout`,o),e.off(`change`,n),e.setLocalStateField(a,null)}}}});function YS(e){let t=FS.getState(e);if(!t)throw Error(`The editor requires ySyncPlugin`);return t}var XS=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)??0)>e.id.clock&&!pv(t.ds,e.id),ZS=(e,t,n)=>{if(!e.has(n)){if(e.sizen.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,Mh(t))}let r=e.get(n);if(!r)throw Error(`At least one snapshot color is required`);return r},QS=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},$S=e=>{let t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{let r=t[n];return r==null||!Object.prototype.hasOwnProperty.call(r,`default`)||r.default!==e.attrs[n]})},eC=(e,t,n)=>{let r=0,i=0;for(;in)break;r+=t.nodeSize}if(i>=e.childCount)return null;let a=e.child(i),o=e.resolve(n),s=(e,t)=>{if(o.depth===0){let i=e+(n-r),a=e+1,o=e+t.nodeSize-1;return Math.max(a,Math.min(i,o))}if(o.depth>1){let n=eC(o.node(1),t,o.pos-o.start(1));return n===null?null:e+1+n}return t.isTextblock?e+1+Math.min(o.parentOffset,t.content.size):null},c=(n,r=!1)=>{let a=0;for(let t=0;t<=i;t++)n(e.child(t))&&a++;let o=0,c=-1,l=null,u=0;for(let e=0;ee.type===a.type&&QS(e.attrs,a.attrs),u=a.textContent,d=c(e=>l(e)&&e.textContent===u);if(d!==null)return d;let f=c(e=>e.type===a.type&&e.textContent===u);if(f!==null)return f;if(!a.isTextblock||$S(a)){let e=c(l,!0);if(e!==null)return e}return c(e=>l(e)&&u!==``&&e.textContent!==``&&(u.startsWith(e.textContent)||e.textContent.startsWith(u)),!0)},tC=(e,t,n,r)=>{if(r===null)return!1;let i=e.resolve(n),a=t.resolve(r);if(!i.parent.isTextblock)return!1;if(!a.parent.isTextblock||i.parent.textContent!==a.parent.textContent||i.parentOffset!==0&&a.parentOffset===0)return!0;let o=i.parentOffset===0&&a.parentOffset===0,s=i.parentOffset!==a.parentOffset||i.parent.type!==a.parent.type||!QS(i.parent.attrs,a.parent.attrs);if(o||s){let i=eC(e,t,n);return i!==null&&i!==r}return!1},nC=(e,t,n,r)=>{if(n==null||n<0||n>t.content.size||!(r===null||n>1&&r<=1||tC(t,e,n,r)))return r;let i=eC(t,e,n);return i===null?r:i},rC=(e,t,n,r)=>{if(t!==null&&t.anchor!==null&&t.head!==null){if(t.type===`all`)e.setSelection(new Dn(e.doc));else if(t.type===`node`){let r=PS(n.doc,n.type,t.anchor,n.mapping);r!==null&&e.setSelection(iC(e,r))}else if(t.type===`nodeRange`){let r=aC(e,PS(n.doc,n.type,t.anchor,n.mapping),PS(n.doc,n.type,t.head,n.mapping),t.depth);r!==null&&e.setSelection(r)}else{let i=PS(n.doc,n.type,t.anchor,n.mapping),a=PS(n.doc,n.type,t.head,n.mapping);r!=null&&(NS(n.type,t.anchor)===t.anchor&&(i=nC(e.doc,r,t.absAnchor,i)),NS(n.type,t.head)===t.head&&(a=nC(e.doc,r,t.absHead,a))),i===null&&(i=a),a===null&&(a=i),i!==null&&a!==null&&e.setSelection(T.between(e.doc.resolve(i),e.doc.resolve(a)))}}},iC=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?E.create(e.doc,t):T.near(n)},aC=(e,t,n,r)=>{if(t===null||n===null)return null;let i=Math.min(Math.max(t,0),e.doc.content.size),a=Math.min(Math.max(n,0),e.doc.content.size);try{let t=w.fromJSON(e.doc,{type:`nodeRange`,anchor:i,head:a,depth:r});return t.ranges.length?t:T.near(e.doc.resolve(i))}catch{return T.near(e.doc.resolve(i))}},oC=(e,t)=>{let n=t.selection,r=n.toJSON(),i=typeof r.type==`string`?r.type:`text`;return{type:i,depth:i===`nodeRange`&&`depth`in n&&typeof n.depth==`number`?n.depth:void 0,anchor:xS(t.selection.anchor,e.type,e.mapping),head:xS(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},sC=new WeakMap,cC=(e,t)=>{var n;(t instanceof sx||t instanceof ix||t instanceof fx)&&(e.delete(t),(n=sC.get(e))==null||n.delete(t))},lC=/(.*)(--[a-zA-Z0-9+/=]{8})$/,uC=e=>lC.exec(e)?.[1]??e,dC=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(uC(r),e[r]));return n},fC=e=>{let t=e.doc,n=e._item;if(!t||!n)throw lh();t.transact(e=>{n.delete(e)},FS)},pC=(e,t,n,r,i,a)=>{let o=e.toDelta(r,i,a);try{return o.map(e=>t.text(e.insert,dC(e.attributes,t)))}catch{return fC(e),null}},mC=e=>{var t;let n=(t=e._item)==null||(t=t.right)==null?void 0:t.content,r=n instanceof Gx?n.type:null;if(!(r instanceof ix))return;let i=r._item,a=r.doc;i&&a&&!i.deleted&&i.id.client===a.clientID&&(e.applyDelta([{retain:e.length},...r.toDelta()]),a.transact(e=>{i.delete(e)}))},hC=(e,t,n,r)=>{if(e._item){if(!XS(e._item,t))return r?r(`removed`,e._item.id):{type:`removed`};if(!XS(e._item,n))return r?r(`added`,e._item.id):{type:`added`}}},gC=(e,t,n)=>{e.mapping.set(t,n);let r=sC.get(e.mapping);r===void 0&&(r=new WeakMap,sC.set(e.mapping,r)),r.set(t,n)},_C=(e,t,n,r,i,a)=>{let o=n.mapping.get(e),s=Array.isArray(o)?void 0:o;if(s!==void 0&&sC.get(n.mapping)?.get(e)===s)return s;let c=[],l=e=>{if(e instanceof lx){let o=_C(e,t,n,r,i,a);o!==null&&c.push(o)}else e instanceof mx&&(mC(e),pC(e,t,n,r,i,a)?.forEach(e=>c.push(e)))};r===void 0||i===void 0?e.toArray().forEach(l):yb(e,new gy(i.ds,r.sv)).forEach(l);try{let o=e.getAttributes(r),l=r?hC(e,r,i,a):void 0;l!==void 0&&(o.ychange=l);let u=t.node(e.nodeName,o,c);return s?.eq(u)&&(u=s),gC(n,e,u),u}catch{return fC(e),cC(n.mapping,e),null}},vC=e=>{for(let t=6;tvg(vC(mS(xg(e)))),bC=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=tm(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${yC(e.toJSON())}`:e.type.name]=e.attrs}}),n},xC=(e,t)=>{let n=new mx,r=e.map(e=>({insert:e.text??``,attributes:bC(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},SC=e=>{let t=e.content.content,n=[];for(let e=0;ee instanceof Array?xC(e,t):wC(e,t),wC=(e,t)=>{let n=new lx(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,SC(e).map(e=>CC(e,t))),t.mapping.set(n,e),n},TC=e=>typeof e==`object`&&!!e,EC=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Wh(e.attributes||{}).length===t[n].marks.length&&Object.entries(e.attributes??{}).every(([e,r])=>{let i=uC(e),a=t[n].marks.find(e=>e.type.name===i);return a?EC(r,a.attrs):!1}))},OC=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,kC=(e,t)=>{if(e instanceof lx&&!(t instanceof Array)&&OC(e,t)){let n=SC(t);return e._length===n.length&&EC(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>kC(e,n[t]))}return e instanceof mx&&t instanceof Array&&DC(e,t)},AC=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),jC=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});let i=[];if(e.forEach((e,a)=>{let o=n.mapping.get(e),s=o===void 0?void 0:r.get(o);s!==void 0&&AC(o,t[s])&&i.push({yIndex:a,pIndex:s,yChild:e})}),i.length===0)return[];let a=[],o=[];for(let e=0;e>1;i[o[r]].pIndex0?o[t-1]:-1,o[t]=e}let s=[];for(let e=o[o.length-1];e!==-1;e=a[e])s.push(i[e]);return s.reverse()},MC=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Fx?t+=n.content.str:n.content instanceof Ox&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},NC=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=MC(e),a=t.map(e=>({insert:e.text??``,attributes:Object.assign({},r,bC(e.marks,n))})),{insert:o,remove:s,index:c}=_S(i,a.map(e=>e.insert).join(``));e.delete(c,s),e.insert(c,o),e.applyDelta(a.map(e=>({retain:e.insert.length,attributes:e.attributes})))},PC=(e,t,n,r,i)=>t instanceof mx&&n instanceof Array?(DC(t,n)?r.mapping.set(t,n):NC(t,n,r),!0):t instanceof lx&&!(n instanceof Array)&&OC(t,n)?(kC(t,n)?r.mapping.set(t,n):i(e,t,n,r),!0):!1,FC=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>cC(r.mapping,e)),e.delete(t,n))},IC=(e,t,n,r,i,a)=>{if(r{let u=gm(a-i,s-o);for(let a=0;a{let o=jC(r,n,i);if(o.length<2||!o.some(e=>e.yIndex!==e.pIndex)||o.some(e=>{let t=n[e.pIndex];return!(e.yChild instanceof mx&&t instanceof Array||e.yChild instanceof lx&&!(t instanceof Array))}))return!1;let s=0,c=0;for(let l of o){LC(e,t,n,r,s,l.yIndex,c,l.pIndex,i,a);let o=n[l.pIndex];PC(e,l.yChild,o,i,a),s=l.yIndex+1,c=l.pIndex+1}return LC(e,t,n,r,s,r.length,c,n.length,i,a),!0},zC=(e,t,n)=>{let r=e.toArray(),i=SC(t),a=i.length,o=r.length,s=gm(o,a),c=0,l=0,u=!1;for(;c{if(t instanceof lx&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof lx){let e=t.getAttributes(),r=n.attrs;for(let n in r)r[n]===null?t.removeAttribute(n):e[n]!==r[n]&&n!==`ychange`&&t.setAttribute(n,r[n]);for(let n in e)r[n]===void 0&&t.removeAttribute(n)}let i=SC(n),a=i.length,o=t.toArray(),s=o.length,c=gm(a,s),l=!1;if(e.transact(()=>{l=RC(e,t,i,o,r,BC)},FS),l)return;let u=0,d=0;for(;u{for(;s-u-d>0&&a-u-d>0;){let n=o[u],c=i[u],l=o[s-d-1],f=i[a-d-1];if(n instanceof mx&&c instanceof Array){DC(n,c)||NC(n,c,r),u+=1;continue}let p=n instanceof lx&&OC(n,c),m=l instanceof lx&&OC(l,f);if(p&&m&&n instanceof lx&&l instanceof lx&&!Array.isArray(c)&&!Array.isArray(f)){let e=zC(n,c,r),t=zC(l,f,r);e.foundMappedChild&&!t.foundMappedChild?m=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor0&&(t.slice(u,u+n).forEach(e=>cC(r.mapping,e)),t.delete(u,n)),u+d>=a)return;let c=[];for(let e=u;e{let n=[];if(!e._item)throw Error(`Position tracking requires integrated text`);for(let r=e._start;r;r=r.right)if(!r.deleted&&r.countable){if(!(r.content instanceof Fx))throw Error(`Position tracking requires string text content`);for(let i=0;i{let r=[{current:-1,target:-1}];return e.forEach((e,n)=>{let i=t.get(`${e.client}:${e.clock}`);i!==void 0&&i>r[r.length-1].target&&r.push({current:n,target:i})}),r.push({current:e.length,target:n}),r},UC=(e,t,n,r,i)=>{let a=VC(e),o=new Map;for(let e=0;e0;--n){let r=s[n-1],o=s[n],c=a.slice(r.current+1,o.current),l=t.slice(r.target+1,o.target);(c.some(e=>i.has(`${e.client}:${e.clock}`))||c.map(e=>e.text).join(``)!==l)&&(e.delete(r.current+1,c.length),e.insert(r.current+1,l))}return VC(e,n)},WC=(e,t)=>!e.target||!t.target?e.target===t.target:e.target.client===t.target.client&&e.target.assoc===t.target.assoc&&e.target.boundary===t.target.boundary&&e.target.tname===t.target.tname&&e.target.clock+e.source.length===t.target.clock&&ty(e.target.type,t.target.type),GC=e=>{let t=[];return e.forEach(e=>{let n=t[t.length-1];n&&n.source.client===e.source.client&&n.source.boundary===e.source.boundary&&n.source.clock+n.source.length===e.source.clock&&WC(n,e)?n.source.length+=e.source.length:t.push({...e,source:{...e.source}})}),t},KC=(e,t)=>{let n=e.doc;if(!n||t.length===0)return;let r=wy(n.store,n.clientID);e.set(`${n.clientID}:${r}`,{version:1,client:n.clientID,clock:r,seen:[...Wv(Jv(n))],transfers:GC(t)})},qC=(e,t)=>{let n=new Map;e.forEach(e=>{let t=`${e.type.client}:${e.type.clock}`,r=n.get(t)??[];r.push(e),n.set(t,r)});let r=[];return n.forEach(e=>{let n=e[0],i=e[e.length-1],a=n.position===null?void 0:t.get(n.position),o=i.position===null?void 0:t.get(i.position);a&&ty(n.type,a.type)||r.push({source:{...n.type,length:1,boundary:`start`},target:a?{...a,assoc:0}:null}),o&&ty(i.type,o.type)||r.push({source:{...n.type,length:1,boundary:`end`},target:o?{...o,assoc:-1}:null})}),r},JC=(e,t,n,r)=>{let i=[];e.forEach(e=>{let n=e.position===null?null:t.get(e.position)??null;n&&ty(e.id,n)||i.push({source:{...e.id,length:1},target:n})});let a=[...e,...r];for(let e of[`start`,`end`]){let r=e===`start`?t:n;a.forEach(t=>{let n=e===`start`?t.position:t.end,a=n===null?null:r.get(n)??null;a&&ty(t.id,a)||i.push({source:{...t.id,length:1,boundary:e},target:a?{client:a.client,clock:a.clock,type:null,boundary:e}:null})})}return i},YC=(e,t,n,r,i,a)=>{let o=e.get(t);if(!(o instanceof lx)||!o._item)throw Error(`Position migration requires synchronized elements`);let s=i.get(`${o._item.id.client}:${o._item.id.clock}`);if(s&&s.position!==r&&(cC(a.mapping,o),e.delete(t,1),o=CC(n,a),e.insert(t,[o])),!(o instanceof lx)||!o._item)throw Error(`Position migration requires integrated elements`);return o},XC=(e,t,n,r)=>{let i=new Map(t.characters.map(e=>[e.position,e])),a=new Set(t.characters.map(e=>`${e.client}:${e.clock}`)),o=new Map,s=new Map(t.nodes.map(e=>[`${e.id.client}:${e.id.clock}`,e])),c=new Map,l=new Map,u=(e,t,r)=>{let d=e.toArray(),f=r;SC(t).forEach((t,r)=>{let p=d[r];if(Array.isArray(t)){if(!(p instanceof mx)||!p._item)throw Error(`Position migration requires integrated text`);let e=t.map(e=>e.text??``).join(``),r=UC(p,e,f,i,a),s=p._item.id;r.forEach(e=>o.set(e.position,{client:e.client,clock:e.clock,type:s})),NC(p,t,n),f+=e.length;return}let m=YC(e,r,t,f,s,n),h=m._item.id,g={client:h.client,clock:h.clock,type:e._item?.id??null,...e._item?{}:{tname:ry(e)}};c.set(f,g),l.set(f+t.nodeSize-1,g),t.isLeaf||u(m,t,f+1),f+=t.nodeSize})};u(e,t.doc,0);let d=[];t.characters.forEach(e=>{let t=e.position===null?null:o.get(e.position)??null;t&&ty(e,t)&&ty(e.type,t.type)||d.push({source:{client:e.client,clock:e.clock,length:1},target:t})}),d.push(...qC(t.characters,o)),d.push(...JC(t.nodes,c,l,t.emptyTexts)),KC(r,d)},ZC=(e,t)=>{let n=e.doc.content,r=0,i=0;for(;rr&&o>r&&n.child(a-1)===t.child(o-1);)s+=n.child(a-1).nodeSize,a--,o--;if(r===a&&r===o)return e;let c=new p(t.cut(i,t.size-s),0,0),l=en(e.doc,i,n.size-s,c);return l!==null&&l.apply(e.doc).doc?.content.eq(t)?e.step(l):e.replace(0,n.size,new p(t,0,0))},QC=class{constructor(e,t=new Map){if(this.prosemirrorView=null,this.mux=aS(),this.isOMark=new Map,this.beforeTransactionSelection=null,this._domSelectionInView=null,this.syncedDoc=null,this.type=e,this.mapping=t,this._observeFunction=this._typeChanged.bind(this),e.doc===null)throw Error(`The Yjs fragment must belong to a document`);this.doc=e.doc,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=oC(this,this.view.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null}}get view(){if(!this.prosemirrorView)throw Error(`The binding has no editor view`);return this.prosemirrorView}get _tr(){return this.view.state.tr.setMeta(`addToHistory`,!1)}_isLocalCursorInView(){return this.view.hasFocus()?(ig&&this._domSelectionInView===null&&(U_(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.view.root,t=`getSelection`in e&&typeof e.getSelection==`function`?e.getSelection():this.view.dom.ownerDocument.getSelection();if(t==null||t.anchorNode==null||t.focusNode==null)return!1;let n=this.view.dom.ownerDocument.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);let r=n.getBoundingClientRect(),i=I_.documentElement;return r.bottom>=0&&r.right>=0&&r.left<=(window.innerWidth||i.clientWidth||0)&&r.top<=(window.innerHeight||i.clientHeight||0)}renderSnapshot(e,t){t||=_y(_v(),new Map),this.view.dispatch(this._tr.setMeta(FS,{snapshot:e,prevSnapshot:t}))}createDocumentTransaction(){let e=this.type.toArray().map(e=>{if(!(e instanceof lx))throw ch();return _C(e,this.view.state.schema,this)}).filter(e=>e!==null);return this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(e),0,0))}unrenderSnapshot(){this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{let e=this.createDocumentTransaction();e.setMeta(FS,{snapshot:null,prevSnapshot:null}),this.view.dispatch(e)})}_forceRerender(){this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{let e=this.beforeTransactionSelection===null?this.view.state.selection:null,t=this.createDocumentTransaction();if(e){let n=gm(_m(e.anchor,0),t.doc.content.size),r=gm(_m(e.head,0),t.doc.content.size);t.setSelection(T.create(t.doc,n,r))}this.view.dispatch(t.setMeta(FS,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=yy(this.doc),e instanceof Uint8Array||t instanceof Uint8Array){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw lh();if(r=new Cv({gc:!1}),Rv(r,t),t=yy(r),Rv(r,e),e=yy(r),i._item===null){let e=Array.from(this.doc.share.keys()).find(e=>Object.is(this.doc.share.get(e),i));i=r.getXmlFragment(e)}else{let e=r.store.clients.get(i._item.id.client)??[],t=e[Ey(e,i._item.id.clock)];if(!(t instanceof Qx&&t.content instanceof Gx&&t.content.type instanceof sx))throw lh();i=t.content.type}}let a=e,o=t??vy;this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{r.transact(e=>{let t=n.permanentUserData;t&&t.dss.forEach(t=>{dv(e,t,e=>{})});let r=(e,r)=>{let i=t?e===`added`?t.getUserByClientId(r.client):t.getUserByDeletedId(r):null;return{user:i,type:e,color:ZS(n.colorMapping,n.colors,i)}},c=yb(i,new gy(o.ds,a.sv)).map(e=>!(e instanceof lx)||!e._item?null:!e._item.deleted||XS(e._item,a)||XS(e._item,o)?_C(e,this.view.state.schema,{mapping:new Map,isOMark:new Map},a,o,r):null).filter(e=>e!==null),l=this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(c),0,0));this.view.dispatch(l.setMeta(FS,{isChangeOrigin:!0}))},FS)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=YS(this.view.state);if(e.length===0||n.snapshot!=null||n.prevSnapshot!=null){this.renderSnapshot(n.snapshot,n.prevSnapshot);return}let r=t.origin instanceof Wy,i=r?t.origin.currStackItem?.meta.get(this):void 0,a=i||this.beforeTransactionSelection,o=i?void 0:this.view.state.doc;this.mux(()=>{let e=(e,t)=>cC(this.mapping,t);dv(t,t.deleteSet,e=>{e instanceof Qx&&e.content instanceof Gx&&cC(this.mapping,e.content.type)}),t.changed.forEach(e),t.changedParentTypes.forEach(e);let n=this.type.toArray().map(e=>{if(!(e instanceof lx))throw ch();return _C(e,this.view.state.schema,this)}).filter(e=>e!==null),i=ZC(this._tr,s.from(n));rC(i,a,this,o),i=i.setMeta(FS,{isChangeOrigin:!0,isUndoRedoOperation:r}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.view.dispatch(i)})}_prosemirrorChanged(e,t=null){let n=YS(this.view.state);n.snapshot==null&&n.prevSnapshot==null&&this.doc.transact(()=>{BC(this.doc,this.type,e,this),t?.doc===e&&XC(this.type,t,this,DS(this.type)),this.syncedDoc=e,this.beforeTransactionSelection=oC(this,this.view.state)},FS)}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))}},$C=(e,t)=>{let n=[],r=[],i=[];if(e.length===0)return{characters:n,nodes:r,emptyTexts:i};let a=(e,t,o)=>{let s=e.toArray(),c=SC(t),l=o;t.content.size===0&&s.forEach(e=>{e instanceof mx&&e._item&&i.push({id:e._item.id,position:o-1,end:o})}),c.forEach((e,t)=>{let i=s[t];if(!Array.isArray(e)){if(!(i instanceof lx)||!i._item)throw Error(`Position tracking requires synchronized editor content`);r.push({id:i._item.id,position:l,end:l+e.nodeSize-1}),e.isLeaf||a(i,e,l+1),l+=e.nodeSize;return}if(!(i instanceof mx))throw Error(`Position tracking requires synchronized editor text`);let o=VC(i,l);n.push(...o),l+=o.length})};return a(e,t,0),{characters:n,nodes:r,emptyTexts:i}},ew=(e,t,n,r)=>{let i=e.toJSON();if(i.stepType!==`replace`&&i.stepType!==`replaceAround`||r!==i.from&&r!==i.to-1)return!1;let a=t.nodeAt(i.from),o=n.nodeAt(i.from);return!a||!o||a.nodeSize!==i.to-i.from?!1:tw(a,o)},tw=(e,t)=>e.type===t.type&&e.content.eq(t.content)&&!e.sameMarkup(t),nw=(e,t)=>{let n=e.toJSON(),r=n.slice??{content:[]};if(n.stepType!==`replace`||r.openStart>0||r.openEnd>0)return!1;let i=t.resolve(n.from),a=t.resolve(n.to);return r.content.every(e=>e.type===`text`)&&i.parent.isTextblock&&i.sameParent(a)},rw=e=>{let t=new Map;return e.descendants((e,n)=>{let r=t.get(e)??[];r.push(n),t.set(e,r)}),t},iw=(e,t,n,r)=>{if(r[n].get(e)?.length!==1)return null;for(let i=n+1;i{let i=n[t].resolve(e),a=[],o=n[t].nodeAt(e);o&&!o.isText&&a.push({node:o,offset:0});for(let t=i.depth;t>0;--t)a.push({node:i.node(t),offset:e-i.before(t)});for(let e of a){let n=iw(e.node,e.offset,t,r);if(n)return n}return null},ow=(e,t,n,r)=>{for(let i=0;i{let r=n?.doc===e.before&&n.doc!==t.syncedDoc?n:null;if(!e.docChanged||!t.prosemirrorView||!r&&e.steps.every((t,n)=>nw(t,e.docs[n])))return r;let i=r??$C(t.type,e.before),a=[...e.docs,e.doc],o=a.map(rw),s=i.characters.map(t=>({...t,position:t.position===null?null:ow(t.position,e,a,o)})),c=t=>({...t,position:t.position===null?null:ow(t.position,e,a,o),end:t.end===null?null:ow(t.end,e,a,o)});return{doc:e.doc,characters:s,nodes:i.nodes.map(c),emptyTexts:i.emptyTexts.map(c)}},cw=[{light:`#ecd44433`,dark:`#ecd444`}],lw=(e,{colors:t=cw,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new QC(e,a);return new D({props:{editable:e=>{let t=YS(e);return t.snapshot==null&&t.prevSnapshot==null}},key:FS,state:{init:(i,a)=>({type:e,doc:s.doc,binding:s,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r,positionMigration:null}),apply:(e,t)=>{let n=e.getMeta(FS);return n!==void 0&&(t=Object.assign({},t,n)),e.docChanged&&(t.addToHistory=e.getMeta(`addToHistory`)!==!1),t.isChangeOrigin=n!==void 0&&!!n.isChangeOrigin,t.isUndoRedoOperation=n!==void 0&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,t={...t,positionMigration:t.isChangeOrigin||t.snapshot||t.prevSnapshot||n?.snapshot!==void 0||n?.prevSnapshot!==void 0?null:sw(e,s,t.positionMigration??null)},s.prosemirrorView===null||n===void 0||n.snapshot==null&&n.prevSnapshot==null||U_(0,()=>{s.prosemirrorView!=null&&(n.restore==null?s._renderSnapshot(n.snapshot,n.prevSnapshot,t):(s._renderSnapshot(n.snapshot,n.snapshot,t),s.mux(()=>{let e=s.prosemirrorView;e&&(e.dispatch(s._tr.setMeta(FS,{restore:!1,snapshot:null,prevSnapshot:null,isChangeOrigin:!0})),s._prosemirrorChanged(e.state.doc))})))}),t}},view:e=>(s.initView(e),a??s._forceRerender(),i(),{update:()=>{let t=YS(e.state);if(t.snapshot==null&&t.prevSnapshot==null){let n=e.state.doc.type.createAndFill();if(!n)throw Error(`The schema cannot create an empty document`);if(o||e.state.doc.content.findDiffStart(n.content)!==null){if(o=!0,t.addToHistory===!1&&!t.isChangeOrigin){let t=IS.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}s.mux(()=>{t.doc.transact(n=>{n.meta.set(`addToHistory`,t.addToHistory),s._prosemirrorChanged(e.state.doc,t.positionMigration??null)},FS)})}}},destroy:()=>{s.destroy()}})})};function uw(e){let t=IS.getState(e);if(!t)throw Error(`The editor requires yUndoPlugin`);return t}var dw=e=>{let t=new Map,n=e=>{e.toArray().forEach(r=>{if(r instanceof lx){let i=r._item.id;t.set(`${i.client}:${i.clock}`,{client:i.client,clock:i.clock,type:e._item?.id??null,...e._item?{}:{tname:ry(e)}}),n(r);return}if(!(r instanceof mx)||!r._item)return;let i=r._item.id;VC(r).forEach(e=>{t.set(`${e.client}:${e.clock}`,{client:e.client,clock:e.clock,type:i})})})};return n(e),t},fw=(e,t)=>{let n=e.doc;if(!n)return;let r=dw(e),i=new Map,a=new Map,o=(e,t)=>{let n=`${e.client}:${e.clock}`,r=`${t.client}:${t.clock}`;i.set(n,e),i.set(r,t);let o=a.get(n)??new Set,s=a.get(r)??new Set;o.add(r),s.add(n),a.set(n,o),a.set(r,s)};t.forEach(e=>e.transfers.forEach(({source:e,target:t})=>{if(t&&!e.boundary)for(let n=0;ne.forEach(e=>{if(e instanceof Qx&&e.redone&&(e.content instanceof Fx||e.content instanceof Gx))for(let t=0;t{if(c.has(t))return;let o=[t],l=[],u=[];for(;o.length>0;){let e=o.pop();if(c.has(e))continue;c.add(e),l.push(e);let t=r.get(e);t&&u.push(t),o.push(...a.get(e)??[])}u.length===1&&l.forEach(e=>{if(r.has(e))return;let t=i.get(e);s.push({source:{client:t.client,clock:t.clock,length:1},target:u[0]});let a=Dy(n.store,t);if(a.content instanceof Gx&&a.content.type instanceof lx)for(let e of[`start`,`end`])s.push({source:{client:t.client,clock:t.clock,length:1,boundary:e},target:{client:u[0].client,clock:u[0].clock,type:null,boundary:e}})})}),KC(t,s)},pw=(e,t,n)=>{let r=DS(e);if(r.size===0)return t[n]();let i=n===`undo`?`undoing`:`redoing`,a=null,o=({stackItem:e})=>{a=e};t.on(`stack-item-popped`,o);try{t.doc.transact(()=>{t[n](),t[i]=!0,t.currStackItem=a,a&&fw(e,r)},t)}finally{t.off(`stack-item-popped`,o),t[i]=!1,t.currStackItem=null}return a},mw=(e,t)=>{let n=YS(e);if(n.snapshot!=null||n.prevSnapshot!=null)return!1;let r=uw(e).undoManager;if(r!=null)return pw(n.type,r,t),!0},hw=e=>mw(e,`undo`),gw=e=>mw(e,`redo`),_w=new Set([`paragraph`]),vw=(e,t)=>!(e instanceof Qx)||!(e.content instanceof Gx)||!(e.content.type instanceof ix||e.content.type instanceof lx&&t.has(e.content.type.nodeName))||e.content.type._length===0,yw=({protectedNodes:e=_w,trackedOrigins:t=[],undoManager:n=null}={})=>new D({key:IS,state:{init:(r,i)=>{let a=YS(i),o=new Set,s=n;if(!s){let n=new Set(a.doc._observers.get(`destroy`));s=new Wy(a.type,{trackedOrigins:new Set([FS,...t]),deleteFilter:t=>vw(t,e),captureTransaction:e=>e.meta.get(`addToHistory`)!==!1}),(a.doc._observers.get(`destroy`)??new Set).forEach(e=>{n.has(e)||o.add(e)})}return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0,destroyListeners:o}},apply:(e,t,n,r)=>{let i=YS(r).binding;return{...t,prevSel:i?oC(i,n):t.prevSel,hasUndoOps:t.undoManager.undoStack.length>0,hasRedoOps:t.undoManager.redoStack.length>0}}},view:e=>{let t=YS(e.state),{undoManager:n,destroyListeners:r}=uw(e.state);return n.on(`stack-item-added`,({stackItem:r})=>{let i=t.binding;if(i){let t=n.undoing||n.redoing?i.beforeTransactionSelection:uw(e.state).prevSel;r.meta.set(i,t)}}),{destroy:()=>{n.destroy(),r.forEach(e=>n.doc.off(`destroy`,e)),r.clear()}}}});function bw(e,t){let n=t||new sx;return BC(n.doc??{transact:e=>e()},n,e,{mapping:new Map,isOMark:new Map}),n}function xw(e){let t=e.toArray(),n=e=>{let t;if(e instanceof mx)t=e.toDelta().map(e=>{let t={type:`text`,text:e.insert},n=e.attributes;return n&&(t.marks=Object.keys(n).map(e=>{let t=n[e],r={type:uC(e)};return Object.keys(t).length&&(r.attrs=t),r})),t});else if(e instanceof lx){t={type:e.nodeName};let r=e.getAttributes();Object.keys(r).length&&(t.attrs=r);let i=e.toArray();i.length&&(t.content=i.map(n).flat())}else lh();return t};return{type:`doc`,content:t.map(n)}}function Sw(e,t,n){return bw(ce.fromJSON(e,t),n)}function Cw(e){return!!e.getMeta(FS)}function ww(e,t){if(t===null)return 0;let n=Ew(e);return PS(n.doc,n.type,t,n.binding.mapping)||0}function Tw(e,t){let n=Ew(e);return xS(t,n.type,n.binding.mapping)}function Ew(e){let t=FS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs sync plugin`);return t}var Dw=class e extends gd{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Ow(e,t){return new Dw(e,Tw(t,e))}function kw(e,t,n){let r=e instanceof Dw?e.yRelativePosition:null;if(Cw(t)&&r)return{position:new Dw(ww(n,r),r),mapResult:null};let i=_d(e,t),a=i.position.position;return{position:new Dw(a,r??Tw(n,a)),mapResult:i.mapResult}}function Aw(e){let t=IS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs undo plugin`);return t.undoManager}var jw=Tp.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>kw(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Ow(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Aw(t).undoStack.length===0?!1:n?hw(t)??!1:!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Aw(t).redoStack.length===0?!1:n?gw(t)??!1:!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=yw(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let t=Aw(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[lw(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,new D({filterTransaction:(e,t)=>(e.getMeta(`inputRule`)&&Aw(t).stopCapturing(),!0)}),this.editor.options.enableContentCheck&&new D({key:new Un(`filterInvalidContent`),filterTransaction:t=>{if(!Cw(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!0}}})].filter(e=>e!==!1)}}),Mw=e=>Array.from(e.entries()).map(([e,t])=>t&&t.user?{clientId:e,...t.user}:{clientId:e}),Nw=()=>null,Pw=e=>Pf(e)&&/^#[0-9a-fA-F]{6}$/.test(e),Fw=e=>({...e,color:Pw(e.color)?e.color:`transparent`}),Iw=Tp.create({name:`collaborationCaret`,priority:999,addOptions(){return{provider:null,user:{name:null,color:null},render:e=>{let t=document.createElement(`span`),{color:n}=Fw(e);t.classList.add(`collaboration-carets__caret`),t.style.borderColor=n;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.style.backgroundColor=n,r.insertBefore(document.createTextNode(e.name),null),t.insertBefore(r,null),t},selectionRender:e=>Pw(e.color)?WS({name:e.name,color:e.color}):{},onUpdate:Nw}},onCreate(){if(this.options.onUpdate!==Nw&&console.warn('[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'),!this.options.provider)throw Error(`The "provider" option is required for the CollaborationCaret extension`)},addStorage(){return{users:[]}},addCommands(){return{updateUser:e=>()=>(this.options.provider.awareness.setLocalStateField(`user`,e),!0),user:e=>({editor:t})=>(console.warn(`[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret`),t.commands.updateUser(e))}},addProseMirrorPlugins(){let{provider:e}=this.options,t=this.storage,n=this.options.user;return[new D({key:new Un(`collaborationCaretAwarenessListener`),view:()=>{let r=()=>{t.users=Mw(e.awareness.states)};return e.awareness.setLocalStateField(`user`,n),t.users=Mw(e.awareness.states),e.awareness.on(`update`,r),{destroy:()=>{e.awareness.off(`update`,r),t.users=[]}}}}),JS(e.awareness,{cursorBuilder:e=>this.options.render(Fw(e)),selectionBuilder:e=>this.options.selectionRender(Fw(e))})]}});function Lw(e={}){return new D({view(t){return new Rw(t,e)}})}var Rw=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc){if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else 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,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.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 c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(!t||i)return null;let a=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=$t(this.editorView.state.doc,a,this.editorView.dragging.slice);e!=null&&(a=e)}return a}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},zw=class e extends w{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):w.near(r)}content(){return p.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new Bw(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!Hw(e)||!Uw(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!E.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};zw.prototype.visible=!1,zw.findFrom=zw.findGapCursorFrom,w.jsonID(`gapcursor`,zw);var Bw=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return zw.valid(t)?new zw(t):w.near(t)}};function Vw(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Hw(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0}else for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||Vw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Uw(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0}else for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||Vw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Ww(){return new D({props:{decorations:Yw,createSelectionBetween(e,t,n){return t.pos==n.pos&&zw.valid(n)?new zw(n):null},handleClick:qw,handleKeyDown:Gw,handleDOMEvents:{beforeinput:Jw}}})}var Gw=Sc({ArrowLeft:Kw(`horiz`,-1),ArrowRight:Kw(`horiz`,1),ArrowUp:Kw(`vert`,-1),ArrowDown:Kw(`vert`,1)});function Kw(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof T){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=zw.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new zw(c))),!0):!1}}function qw(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!zw.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&E.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new zw(r))),!0)}function Jw(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof zw))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new p(i,0,0));return a.setSelection(T.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function Yw(e){if(!(e.selection instanceof zw))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,xs.create(e.doc,[vs.widget(e.selection.head,t,{key:`gapcursor`})])}Tp.create({name:`characterCount`,addOptions(){return{limit:null,autoTrim:!0,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new D({key:new Un(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit,a=this.options.autoTrim;if(i==null||i===0||a===!1){e=!0;return}let o=this.storage.characters({node:r.doc});if(o>i){let t=o-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var Xw=Tp.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[Lw(this.options)]}});Tp.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new D({key:new Un(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return xs.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(vs.node(t,t+e.nodeSize,{class:this.options.className}))}),xs.create(e,a)}}})]}});var Zw=Tp.create({name:`gapCursor`,addProseMirrorPlugins(){return[Ww()]},extendNodeSchema(e){return{allowGapCursor:Nu(k(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Qw=`placeholder`,$w=new Un(`tiptap__placeholder`);function eT(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:a,isEmptyDoc:o,hasAnchor:s,classes:{emptyNode:c,emptyEditor:l}}=e,u=[c];return o&&u.push(l),vs.node(i,i+a.nodeSize,{class:u.join(` `),[r]:typeof n==`function`?n({editor:t,node:a,pos:i,hasAnchor:s}):n})}function tT(e,t){return typeof e==`function`?e(t):e}function nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:a,to:o}){let{anchor:s}=i,c=[],l=e.isEmpty;return r.nodesBetween(a,o,(r,i)=>{let a=s>=i&&s<=i+r.nodeSize,o=!r.isLeaf&&fd(r);return r.type.isTextblock&&(a||!t.showOnlyCurrent)&&o&&c.push(eT({editor:e,isEmptyDoc:l,dataAttribute:n,hasAnchor:a,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:tT(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:a})},node:r,pos:i})),t.includeChildren}),c}function rT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!e.isEditable&&t.showOnlyWhenEditable)return null;let{anchor:a}=i,o=[],s=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(a),c=i.depth>0?i.node(1):i.nodeAfter,l=i.depth>0?i.before(1):a;if(c&&c.type.isTextblock&&fd(c)){let r=a>=l&&a<=l+c.nodeSize;o.push(eT({editor:e,isEmptyDoc:s,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:tT(t.emptyNodeClass,{editor:e,node:c,pos:l,hasAnchor:r})},node:c,pos:l}))}}else o.push(...nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return xs.create(r,o)}function iT(e,t){let n=e.resolve(t);if(n.depth===0){let e=n.nodeAfter??n.nodeBefore;if(!e)return{from:t,to:t};let r=n.nodeAfter?t:t-e.nodeSize;return{from:r,to:r+e.nodeSize}}let r=n.before(1);return{from:r,to:r+n.node(1).nodeSize}}function aT(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function oT(e,t,n){let r=[];return e.forEach((e,i)=>{let a=i,o=a+e.nodeSize,s=a+1,c=o+1;st&&r.push({from:a,to:o})}),r}function sT(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;et.from?n.push(aT(e,iT(e,Math.min(t.to,e.content.size+1)-1))):t.frome.from>=t&&e.to<=c);l.length&&(s=s.remove(l));let u=nT({editor:n,options:r,dataAttribute:i,doc:a,selection:o,from:t,to:c});u.length&&(s=s.add(a,u))}return s}function fT({editor:e,options:t,dataAttribute:n}){return{init(r,i){return rT({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection})??xs.empty},apply(r,i,a,o){return!r.docChanged&&!r.selectionSet?i:dT({decorations:i.map(r.mapping,r.doc),ranges:lT(r,a,o),editor:e,options:t,dataAttribute:n,doc:o.doc,selection:o.selection})}}}function pT(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}function mT({editor:e,options:t}){let n=t.dataAttribute?`data-${pT(t.dataAttribute)}`:`data-${Qw}`,r=t.showOnlyCurrent&&!t.includeChildren;return new D({key:$w,...r?{}:{state:fT({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>rT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>t.showOnlyWhenEditable&&!e.isEditable?xs.empty:$w.getState(n)??xs.empty}})}var hT=Tp.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Qw,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[mT({editor:this.editor,options:this.options})]}});function gT(e,t){return!e.selection.empty&&!pd(e.selection)&&t.isEditable}function _T(e,t){return gT(e,t)&&!t.isFocused&&!t.view.dragging}function vT(){var e;(e=window.getSelection())==null||e.removeAllRanges()}function yT(e){e.focus()}Tp.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new D({key:new Un(`selection`),props:{decorations(n){return _T(n,e)?xs.create(n.doc,[vs.inline(n.selection.from,n.selection.to,{class:t.className})]):null},handleDOMEvents:{blur(t){return gT(t.state,e)&&vT(),!1},focus(t){return gT(t.state,e)&&requestAnimationFrame(()=>{!e.isDestroyed&&t.hasFocus()&&yT(t)}),!1}}}})]}});function bT({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var xT=Tp.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new Un(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new D({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!bT({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!bT({node:r,types:n})}}})]}}),ST=Tp.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Kc(e,t),redo:()=>({state:e,dispatch:t})=>qc(e,t)}},addProseMirrorPlugins(){return[Wc(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),CT=new WeakSet,wT=new WeakSet;function TT(e){let t=e;return CT.add(t),t}function ET(e){return Array.isArray(e)&&CT.has(e)}function DT(e){return e.flatMap(e=>e==null?[]:Array.isArray(e)&&wT.has(e)&&!ET(e)?DT(e):[e])}function OT(e,t){if(e===`slot`)return 0;if(e instanceof Function){let n=e(t);return Array.isArray(n)&&!ET(n)&&!wT.has(n)?TT(n):n}let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);if(Array.isArray(n)){if(ET(n))return TT([e,r,n]);if(n.length===0)return TT([e,r]);let t=DT(n);return t.length===0?TT([e,r]):TT([e,r,...t])}return TT(n==null?[e,r]:[e,r,n])}var kT=(e,t)=>OT(e,t),AT=(e,t)=>{let{state:n}=e,{selection:r}=n;if(!r.empty)return!1;let{$from:i}=r;if(i.parentOffset!==0)return!1;let a=i.depth-1;if(a<0)return!1;let o=i.node(a),s=i.index(a);if(s===0)return!1;if(o.type===t)return e.commands.lift(t.name);let c=o.child(s-1);if(c.type!==t||!c.lastChild?.isTextblock)return!1;let l=i.before()-1-1;return e.commands.command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=i.parent.content,r=new p(n,0,0);return e.replace(l,i.after(),r),e.setSelection(T.create(e.doc,l+n.size)),e.scrollIntoView(),t(e),!0})},jT=/^\s*>\s$/,MT=Jp.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return kT(`blockquote`,{...A(this.options.HTMLAttributes,e),children:kT(`slot`,{})})},parseMarkdown:(e,t)=>{let n=t.parseBlockChildren??t.parseChildren;return t.createNode(`blockquote`,void 0,n(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach((e,r)=>{let i=(t.renderChild?.call(t,e,r)??t.renderChildren([e])).split(` `).map(e=>e.trim()===``?`>`:`> ${e}`);n.push(i.join(` `))}),n.join(` > -`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote(),Backspace:()=>DT(this.editor,this.type)}},addInputRules(){return[Gp({find:OT,type:this.type})]}}),AT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,jT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,MT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,NT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,PT=_p.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return ET(`strong`,{...A(this.options.HTMLAttributes,e),children:ET(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Hp({find:AT,type:this.type}),Hp({find:MT,type:this.type})]},addPasteRules(){return[Yp({find:jT,type:this.type}),Yp({find:NT,type:this.type})]}}),FT=e=>{let t=/`([^`]+)`(?!`)$/.exec(e);return!t||t.index>0&&e[t.index-1]==="`"?null:{index:t.index,text:t[0],replaceWith:t[1]}},IT=e=>{let t=/`([^`]+)`(?!`)/g,n=[],r;for(;(r=t.exec(e))!==null;)r.index>0&&e[r.index-1]==="`"||n.push({index:r.index,text:r[0],replaceWith:r[1]});return n};function LT(e){let t=new Set((e.match(/`+/g)||[]).map(e=>e.length)),n=1;for(;t.has(n);)n+=1;return n}var RT=_p.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t,n)=>{var r;if(!e.content)return``;let i=typeof(n==null||(r=n.meta)==null?void 0:r.markText)==`string`?n.meta.markText:``,a="`".repeat(LT(i)),o=i.startsWith("`")||i.endsWith("`")?` `:``;return`${a}${o}${t.renderChildren(e.content)}${o}${a}`},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Hp({find:FT,type:this.type})]},addPasteRules(){return[Yp({find:IT,type:this.type})]}}),zT=4,BT=/^```([a-z]+)?[\s\n]$/,VT=/^~~~([a-z]+)?[\s\n]$/,HT=Jp.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:zT,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,A(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` -`):`\`\`\`${r}\n\n\`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??zT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,` +`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote(),Backspace:()=>AT(this.editor,this.type)}},addInputRules(){return[Gp({find:jT,type:this.type})]}}),NT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,PT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,FT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,IT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,LT=_p.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return kT(`strong`,{...A(this.options.HTMLAttributes,e),children:kT(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Hp({find:NT,type:this.type}),Hp({find:FT,type:this.type})]},addPasteRules(){return[Yp({find:PT,type:this.type}),Yp({find:IT,type:this.type})]}}),RT=e=>{let t=/`([^`]+)`(?!`)$/.exec(e);return!t||t.index>0&&e[t.index-1]==="`"?null:{index:t.index,text:t[0],replaceWith:t[1]}},zT=e=>{let t=/`([^`]+)`(?!`)/g,n=[],r;for(;(r=t.exec(e))!==null;)r.index>0&&e[r.index-1]==="`"||n.push({index:r.index,text:r[0],replaceWith:r[1]});return n};function BT(e){let t=new Set((e.match(/`+/g)||[]).map(e=>e.length)),n=1;for(;t.has(n);)n+=1;return n}var VT=_p.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t,n)=>{var r;if(!e.content)return``;let i=typeof(n==null||(r=n.meta)==null?void 0:r.markText)==`string`?n.meta.markText:``,a="`".repeat(BT(i)),o=i.startsWith("`")||i.endsWith("`")?` `:``;return`${a}${o}${t.renderChildren(e.content)}${o}${a}`},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Hp({find:RT,type:this.type})]},addPasteRules(){return[Yp({find:zT,type:this.type})]}}),HT=4,UT=/^```([a-z]+)?[\s\n]$/,WT=/^~~~([a-z]+)?[\s\n]$/,GT=Jp.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:HT,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,A(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` +`):`\`\`\`${r}\n\n\`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??HT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,` `,` `).split(` `).map(e=>o+e).join(` -`);return e.replaceWith(t,i,n.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??zT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;return i.parent.type===this.type?a?e.commands.command(({tr:e})=>{let{pos:r}=i,a=i.start(),o=i.end(),s=n.doc.textBetween(a,o,` +`);return e.replaceWith(t,i,n.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??HT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;return i.parent.type===this.type?a?e.commands.command(({tr:e})=>{let{pos:r}=i,a=i.start(),o=i.end(),s=n.doc.textBetween(a,o,` `,` `).split(` `),c=0,l=0,u=r-a;for(let e=0;e=u){c=e;break}l+=s[e].length+1}let d=s[c].match(/^ */)?.[0]||``,f=Math.min(d.length,t);if(f===0)return!0;let p=a;for(let e=0;e{let{from:i,to:a}=r,o=n.doc.textBetween(i,a,` @@ -123,51 +123,51 @@ img.ProseMirror-separator { `).map(e=>{let n=e.match(/^ */)?.[0]||``,r=Math.min(n.length,t);return e.slice(r)}).join(` `);return e.replaceWith(i,a,n.schema.text(o)),!0}):!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let a=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` -`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||r.parentOffset!==0)return!1;let a=r.before();return a>0?!1:e.commands.insertDefaultBlock({pos:a})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(w.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Wp({find:BT,type:this.type,getAttributes:e=>({language:e[1]})}),Wp({find:VT,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new D({key:new Un(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` -`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(T.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),UT=HT,WT=Jp.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||r.parentOffset!==0)return!1;let a=r.before();return a>0?!1:e.commands.insertDefaultBlock({pos:a})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(w.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Wp({find:UT,type:this.type,getAttributes:e=>({language:e[1]})}),Wp({find:WT,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new D({key:new Un(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` +`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(T.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),KT=GT,qT=Jp.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``}),GT=Jp.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,A(this.options.HTMLAttributes,e)]},renderText(){return` +`):``}),JT=Jp.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,A(this.options.HTMLAttributes,e)]},renderText(){return` `},renderMarkdown:()=>` -`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),KT=Jp.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,A(this.options.HTMLAttributes,t),0]},parseMarkdown(e,t){let n=e.depth||1;return this.options.levels.includes(n)?t.createNode(`heading`,{level:n},t.parseInline(e.tokens||[])):t.createNode(`paragraph`,void 0,t.parseInline(e.tokens||[]))},renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>Wp({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),qT=Jp.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,A(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!Df(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return pd(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(T.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(E.create(t.doc,n.pos)):t.setSelection(T.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(T.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Up({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),JT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,YT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,XT=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,ZT=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,QT=_p.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,A(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Hp({find:JT,type:this.type}),Hp({find:XT,type:this.type})]},addPasteRules(){return[Yp({find:YT,type:this.type}),Yp({find:ZT,type:this.type})]}}),$T=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos6kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12b0cam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,eE=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,tE=`numeric`,nE=`ascii`,rE=`alpha`,iE=`asciinumeric`,aE=`alphanumeric`,oE=`domain`,sE=`emoji`,cE=`scheme`,lE=`slashscheme`,uE=`whitespace`;function dE(e,t){return e in t||(t[e]=[]),t[e]}function fE(e,t,n){t[tE]&&(t[iE]=!0,t[aE]=!0),t[nE]&&(t[iE]=!0,t[rE]=!0),t[iE]&&(t[aE]=!0),t[rE]&&(t[aE]=!0),t[aE]&&(t[oE]=!0),t[sE]&&(t[oE]=!0);for(let r in t){let t=dE(r,n);t.indexOf(e)<0&&t.push(e)}}function pE(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function mE(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}mE.groups={},mE.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),gE=(e,t,n,r,i)=>e.tr(t,n,r,i),_E=(e,t,n,r,i)=>e.ts(t,n,r,i),P=(e,t,n,r,i)=>e.tt(t,n,r,i),vE=`WORD`,yE=`UWORD`,bE=`ASCIINUMERICAL`,xE=`ALPHANUMERICAL`,SE=`LOCALHOST`,CE=`TLD`,wE=`UTLD`,TE=`SCHEME`,EE=`SLASH_SCHEME`,DE=`NUM`,OE=`WS`,kE=`NL`,AE=`OPENBRACE`,jE=`CLOSEBRACE`,ME=`OPENBRACKET`,NE=`CLOSEBRACKET`,PE=`OPENPAREN`,FE=`CLOSEPAREN`,IE=`OPENANGLEBRACKET`,LE=`CLOSEANGLEBRACKET`,RE=`FULLWIDTHLEFTPAREN`,zE=`FULLWIDTHRIGHTPAREN`,BE=`LEFTCORNERBRACKET`,VE=`RIGHTCORNERBRACKET`,HE=`LEFTWHITECORNERBRACKET`,UE=`RIGHTWHITECORNERBRACKET`,WE=`FULLWIDTHLESSTHAN`,GE=`FULLWIDTHGREATERTHAN`,KE=`AMPERSAND`,qE=`APOSTROPHE`,JE=`ASTERISK`,YE=`AT`,XE=`BACKSLASH`,ZE=`BACKTICK`,QE=`CARET`,$E=`COLON`,eD=`COMMA`,tD=`DOLLAR`,nD=`DOT`,rD=`EQUALS`,iD=`EXCLAMATION`,aD=`HYPHEN`,oD=`PERCENT`,sD=`PIPE`,cD=`PLUS`,lD=`POUND`,uD=`QUERY`,dD=`QUOTE`,fD=`FULLWIDTHMIDDLEDOT`,pD=`SEMI`,mD=`SLASH`,hD=`TILDE`,gD=`UNDERSCORE`,_D=`EMOJI`,vD=`SYM`,yD=Object.freeze({__proto__:null,ALPHANUMERICAL:xE,AMPERSAND:KE,APOSTROPHE:qE,ASCIINUMERICAL:bE,ASTERISK:JE,AT:YE,BACKSLASH:XE,BACKTICK:ZE,CARET:QE,CLOSEANGLEBRACKET:LE,CLOSEBRACE:jE,CLOSEBRACKET:NE,CLOSEPAREN:FE,COLON:$E,COMMA:eD,DOLLAR:tD,DOT:nD,EMOJI:_D,EQUALS:rD,EXCLAMATION:iD,FULLWIDTHGREATERTHAN:GE,FULLWIDTHLEFTPAREN:RE,FULLWIDTHLESSTHAN:WE,FULLWIDTHMIDDLEDOT:fD,FULLWIDTHRIGHTPAREN:zE,HYPHEN:aD,LEFTCORNERBRACKET:BE,LEFTWHITECORNERBRACKET:HE,LOCALHOST:SE,NL:kE,NUM:DE,OPENANGLEBRACKET:IE,OPENBRACE:AE,OPENBRACKET:ME,OPENPAREN:PE,PERCENT:oD,PIPE:sD,PLUS:cD,POUND:lD,QUERY:uD,QUOTE:dD,RIGHTCORNERBRACKET:VE,RIGHTWHITECORNERBRACKET:UE,SCHEME:TE,SEMI:pD,SLASH:mD,SLASH_SCHEME:EE,SYM:vD,TILDE:hD,TLD:CE,UNDERSCORE:gD,UTLD:wE,UWORD:yE,WORD:vE,WS:OE}),bD=/[a-z]/,xD=/[a-z]/i,SD=/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}]|\u{FE0F}/u;try{xD=RegExp(`\\p{L}`,`u`),SD=RegExp(`\\p{Emoji}`,`u`)}catch{}var CD=/\d/,wD=/\s/,TD=`\r`,ED=` -`,DD=`️`,OD=`‍`,kD=``,AD=null,jD=null;function MD(e=[]){let t={};mE.groups=t;let n=new mE;AD??=ID($T),jD??=ID(eE),P(n,`'`,qE),P(n,`{`,AE),P(n,`}`,jE),P(n,`[`,ME),P(n,`]`,NE),P(n,`(`,PE),P(n,`)`,FE),P(n,`<`,IE),P(n,`>`,LE),P(n,`(`,RE),P(n,`)`,zE),P(n,`「`,BE),P(n,`」`,VE),P(n,`『`,HE),P(n,`』`,UE),P(n,`<`,WE),P(n,`>`,GE),P(n,`&`,KE),P(n,`*`,JE),P(n,`@`,YE),P(n,"`",ZE),P(n,`^`,QE),P(n,`:`,$E),P(n,`,`,eD),P(n,`$`,tD),P(n,`.`,nD),P(n,`=`,rD),P(n,`!`,iD),P(n,`-`,aD),P(n,`%`,oD),P(n,`|`,sD),P(n,`+`,cD),P(n,`#`,lD),P(n,`?`,uD),P(n,`"`,dD),P(n,`/`,mD),P(n,`;`,pD),P(n,`~`,hD),P(n,`_`,gD),P(n,`\\`,XE),P(n,`・`,fD);let r=gE(n,CD,DE,{[tE]:!0});gE(r,CD,r);let i=gE(r,bD,bE,{[iE]:!0}),a=gE(r,xD,xE,{[aE]:!0}),o=gE(n,bD,vE,{[nE]:!0});gE(o,CD,i),gE(o,bD,o),gE(i,CD,i),gE(i,bD,i);let s=gE(n,xD,yE,{[rE]:!0});gE(s,bD),gE(s,CD,a),gE(s,xD,s),gE(a,CD,a),gE(a,bD),gE(a,xD,a);let c=P(n,ED,kE,{[uE]:!0}),l=P(n,TD,OE,{[uE]:!0}),u=gE(n,wD,OE,{[uE]:!0});P(n,kD,u),P(l,ED,c),P(l,kD,u),gE(l,wD,u),P(u,TD),P(u,ED),gE(u,wD,u),P(u,kD,u);let d=gE(n,SD,_D,{[sE]:!0});P(d,`#`),gE(d,SD,d),P(d,DD,d);let f=P(d,OD);P(f,`#`),gE(f,SD,d);let p=[[bD,o],[CD,i]],m=[[bD,null],[xD,s],[CD,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[oE]=!0:bD.test(r)?CD.test(r)?i[iE]=!0:i[nE]=!0:i[tE]=!0,_E(n,r,r,i)}return _E(n,`localhost`,SE,{ascii:!0}),n.jd=new mE(vD),{start:n,tokens:Object.assign({groups:t},yD)}}function ND(e,t){let n=PD(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function PD(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function FD(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var LD={defaultProtocol:`http`,events:null,format:zD,formatHref:zD,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],ignoreClasses:[],render:null};function RD(e,t=null){let n=Object.assign({},LD);e&&(n=Object.assign(n,e instanceof RD?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e=0)return!0;return!1},defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:LD[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function zD(e){return e}function BD(e,t){this.t=`token`,this.v=e,this.tk=t}BD.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=LD.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function VD(e,t){class n extends BD{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var HD=VD(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),UD=VD(`text`),WD=VD(`nl`),GD=VD(`url`,{isLink:!0,toHref(e=LD.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==SE&&e[1].t===$E}}),KD=e=>new mE(e);function qD({groups:e}){let t=e.domain.concat([KE,JE,YE,XE,ZE,QE,tD,rD,aD,DE,oD,sD,cD,lD,mD,vD,hD,gD]),n=[qE,$E,eD,nD,iD,oD,uD,dD,pD,IE,LE,AE,jE,NE,ME,PE,FE,RE,zE,BE,VE,HE,UE,WE,GE],r=[KE,qE,JE,XE,ZE,QE,tD,rD,aD,AE,jE,oD,sD,cD,lD,uD,mD,vD,hD,gD],i=KD(),a=P(i,hD);hE(a,r,a),hE(a,e.domain,a);let o=KD(),s=KD(),c=KD();hE(i,e.domain,o),hE(i,e.scheme,s),hE(i,e.slashscheme,c),hE(o,r,a),hE(o,e.domain,o);let l=P(o,YE);P(a,YE,l),P(s,YE,l),P(c,YE,l);let u=P(a,nD);hE(u,r,a),hE(u,e.domain,a);let d=KD();hE(l,e.domain,d),hE(d,e.domain,d);let f=P(d,nD);hE(f,e.domain,d);let p=KD(HD);hE(f,e.tld,p),hE(f,e.utld,p),P(l,SE,p);let m=P(d,aD);P(m,aD,m),hE(m,e.domain,d),hE(p,e.domain,d),P(p,nD,f),P(p,aD,m);let h=P(o,aD),g=P(o,nD);P(h,aD,h),hE(h,e.domain,o),hE(g,r,a),hE(g,e.domain,o);let _=KD(GD);hE(g,e.tld,_),hE(g,e.utld,_),hE(_,e.domain,o),hE(_,r,a),P(_,nD,g),P(_,aD,h),P(_,YE,l);let v=P(_,$E),y=KD(GD);hE(v,e.numeric,y);let b=KD(GD),x=KD();hE(b,t,b),hE(b,n,x),hE(x,t,b),hE(x,n,x),P(_,mD,b),P(y,mD,b),P(_,uD,x),P(_,lD,b),P(y,uD,x),P(y,lD,b);let S=P(s,$E),C=P(P(P(c,$E),mD),mD);hE(s,e.domain,o),P(s,nD,g),P(s,aD,h),hE(c,e.domain,o),P(c,nD,g),P(c,aD,h),hE(S,e.domain,b),P(S,mD,b),P(S,uD,b),hE(C,e.domain,b),hE(C,t,b),P(C,mD,b);let ee=[[AE,jE],[ME,NE],[PE,FE],[IE,LE],[RE,zE],[BE,VE],[HE,UE],[WE,GE]];for(let e=0;e=0&&p++,m.push(c),s[i]&&s[i].has(c))break;for(let e=0,t=i-m.length+1;e0&&(a.push(YD(UD,t,o)),o=[]),i-=p,d-=p;let e=f.t,r=n.slice(i-d,i);a.push(YD(e,t,r))}}return o.length>0&&a.push(YD(UD,t,o)),a}function YD(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var XD=typeof console<`u`&&console&&console.warn||(()=>{}),ZD=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,QD={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function $D(){return mE.groups={},QD.scanner=null,QD.parser=null,QD.tokenQueue=[],QD.pluginQueue=[],QD.customSchemes=[],QD.initialized=!1,QD}function eO(e,t=!1){if(QD.initialized&&XD(`linkifyjs: already initialized - will not register custom scheme "${e}" ${ZD}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. +`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),YT=Jp.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,A(this.options.HTMLAttributes,t),0]},parseMarkdown(e,t){let n=e.depth||1;return this.options.levels.includes(n)?t.createNode(`heading`,{level:n},t.parseInline(e.tokens||[])):t.createNode(`paragraph`,void 0,t.parseInline(e.tokens||[]))},renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>Wp({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),XT=Jp.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,A(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!Df(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return pd(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(T.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(E.create(t.doc,n.pos)):t.setSelection(T.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(T.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Up({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),ZT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,QT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,$T=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,eE=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,tE=_p.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,A(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Hp({find:ZT,type:this.type}),Hp({find:$T,type:this.type})]},addPasteRules(){return[Yp({find:QT,type:this.type}),Yp({find:eE,type:this.type})]}}),nE=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos6kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12b0cam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,rE=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,iE=`numeric`,aE=`ascii`,oE=`alpha`,sE=`asciinumeric`,cE=`alphanumeric`,lE=`domain`,uE=`emoji`,dE=`scheme`,fE=`slashscheme`,pE=`whitespace`;function mE(e,t){return e in t||(t[e]=[]),t[e]}function hE(e,t,n){t[iE]&&(t[sE]=!0,t[cE]=!0),t[aE]&&(t[sE]=!0,t[oE]=!0),t[sE]&&(t[cE]=!0),t[oE]&&(t[cE]=!0),t[cE]&&(t[lE]=!0),t[uE]&&(t[lE]=!0);for(let r in t){let t=mE(r,n);t.indexOf(e)<0&&t.push(e)}}function gE(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function _E(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}_E.groups={},_E.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),yE=(e,t,n,r,i)=>e.tr(t,n,r,i),bE=(e,t,n,r,i)=>e.ts(t,n,r,i),P=(e,t,n,r,i)=>e.tt(t,n,r,i),xE=`WORD`,SE=`UWORD`,CE=`ASCIINUMERICAL`,wE=`ALPHANUMERICAL`,TE=`LOCALHOST`,EE=`TLD`,DE=`UTLD`,OE=`SCHEME`,kE=`SLASH_SCHEME`,AE=`NUM`,jE=`WS`,ME=`NL`,NE=`OPENBRACE`,PE=`CLOSEBRACE`,FE=`OPENBRACKET`,IE=`CLOSEBRACKET`,LE=`OPENPAREN`,RE=`CLOSEPAREN`,zE=`OPENANGLEBRACKET`,BE=`CLOSEANGLEBRACKET`,VE=`FULLWIDTHLEFTPAREN`,HE=`FULLWIDTHRIGHTPAREN`,UE=`LEFTCORNERBRACKET`,WE=`RIGHTCORNERBRACKET`,GE=`LEFTWHITECORNERBRACKET`,KE=`RIGHTWHITECORNERBRACKET`,qE=`FULLWIDTHLESSTHAN`,JE=`FULLWIDTHGREATERTHAN`,YE=`AMPERSAND`,XE=`APOSTROPHE`,ZE=`ASTERISK`,QE=`AT`,$E=`BACKSLASH`,eD=`BACKTICK`,tD=`CARET`,nD=`COLON`,rD=`COMMA`,iD=`DOLLAR`,aD=`DOT`,oD=`EQUALS`,sD=`EXCLAMATION`,cD=`HYPHEN`,lD=`PERCENT`,uD=`PIPE`,dD=`PLUS`,fD=`POUND`,pD=`QUERY`,mD=`QUOTE`,hD=`FULLWIDTHMIDDLEDOT`,gD=`SEMI`,_D=`SLASH`,vD=`TILDE`,yD=`UNDERSCORE`,bD=`EMOJI`,xD=`SYM`,SD=Object.freeze({__proto__:null,ALPHANUMERICAL:wE,AMPERSAND:YE,APOSTROPHE:XE,ASCIINUMERICAL:CE,ASTERISK:ZE,AT:QE,BACKSLASH:$E,BACKTICK:eD,CARET:tD,CLOSEANGLEBRACKET:BE,CLOSEBRACE:PE,CLOSEBRACKET:IE,CLOSEPAREN:RE,COLON:nD,COMMA:rD,DOLLAR:iD,DOT:aD,EMOJI:bD,EQUALS:oD,EXCLAMATION:sD,FULLWIDTHGREATERTHAN:JE,FULLWIDTHLEFTPAREN:VE,FULLWIDTHLESSTHAN:qE,FULLWIDTHMIDDLEDOT:hD,FULLWIDTHRIGHTPAREN:HE,HYPHEN:cD,LEFTCORNERBRACKET:UE,LEFTWHITECORNERBRACKET:GE,LOCALHOST:TE,NL:ME,NUM:AE,OPENANGLEBRACKET:zE,OPENBRACE:NE,OPENBRACKET:FE,OPENPAREN:LE,PERCENT:lD,PIPE:uD,PLUS:dD,POUND:fD,QUERY:pD,QUOTE:mD,RIGHTCORNERBRACKET:WE,RIGHTWHITECORNERBRACKET:KE,SCHEME:OE,SEMI:gD,SLASH:_D,SLASH_SCHEME:kE,SYM:xD,TILDE:vD,TLD:EE,UNDERSCORE:yD,UTLD:DE,UWORD:SE,WORD:xE,WS:jE}),CD=/[a-z]/,wD=/[a-z]/i,TD=/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}]|\u{FE0F}/u;try{wD=RegExp(`\\p{L}`,`u`),TD=RegExp(`\\p{Emoji}`,`u`)}catch{}var ED=/\d/,DD=/\s/,OD=`\r`,kD=` +`,AD=`️`,jD=`‍`,MD=``,ND=null,PD=null;function FD(e=[]){let t={};_E.groups=t;let n=new _E;ND??=zD(nE),PD??=zD(rE),P(n,`'`,XE),P(n,`{`,NE),P(n,`}`,PE),P(n,`[`,FE),P(n,`]`,IE),P(n,`(`,LE),P(n,`)`,RE),P(n,`<`,zE),P(n,`>`,BE),P(n,`(`,VE),P(n,`)`,HE),P(n,`「`,UE),P(n,`」`,WE),P(n,`『`,GE),P(n,`』`,KE),P(n,`<`,qE),P(n,`>`,JE),P(n,`&`,YE),P(n,`*`,ZE),P(n,`@`,QE),P(n,"`",eD),P(n,`^`,tD),P(n,`:`,nD),P(n,`,`,rD),P(n,`$`,iD),P(n,`.`,aD),P(n,`=`,oD),P(n,`!`,sD),P(n,`-`,cD),P(n,`%`,lD),P(n,`|`,uD),P(n,`+`,dD),P(n,`#`,fD),P(n,`?`,pD),P(n,`"`,mD),P(n,`/`,_D),P(n,`;`,gD),P(n,`~`,vD),P(n,`_`,yD),P(n,`\\`,$E),P(n,`・`,hD);let r=yE(n,ED,AE,{[iE]:!0});yE(r,ED,r);let i=yE(r,CD,CE,{[sE]:!0}),a=yE(r,wD,wE,{[cE]:!0}),o=yE(n,CD,xE,{[aE]:!0});yE(o,ED,i),yE(o,CD,o),yE(i,ED,i),yE(i,CD,i);let s=yE(n,wD,SE,{[oE]:!0});yE(s,CD),yE(s,ED,a),yE(s,wD,s),yE(a,ED,a),yE(a,CD),yE(a,wD,a);let c=P(n,kD,ME,{[pE]:!0}),l=P(n,OD,jE,{[pE]:!0}),u=yE(n,DD,jE,{[pE]:!0});P(n,MD,u),P(l,kD,c),P(l,MD,u),yE(l,DD,u),P(u,OD),P(u,kD),yE(u,DD,u),P(u,MD,u);let d=yE(n,TD,bD,{[uE]:!0});P(d,`#`),yE(d,TD,d),P(d,AD,d);let f=P(d,jD);P(f,`#`),yE(f,TD,d);let p=[[CD,o],[ED,i]],m=[[CD,null],[wD,s],[ED,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[lE]=!0:CD.test(r)?ED.test(r)?i[sE]=!0:i[aE]=!0:i[iE]=!0,bE(n,r,r,i)}return bE(n,`localhost`,TE,{ascii:!0}),n.jd=new _E(xD),{start:n,tokens:Object.assign({groups:t},SD)}}function ID(e,t){let n=LD(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function LD(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function RD(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var BD={defaultProtocol:`http`,events:null,format:HD,formatHref:HD,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],ignoreClasses:[],render:null};function VD(e,t=null){let n=Object.assign({},BD);e&&(n=Object.assign(n,e instanceof VD?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e=0)return!0;return!1},defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:BD[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function HD(e){return e}function UD(e,t){this.t=`token`,this.v=e,this.tk=t}UD.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=BD.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function WD(e,t){class n extends UD{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var GD=WD(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),KD=WD(`text`),qD=WD(`nl`),JD=WD(`url`,{isLink:!0,toHref(e=BD.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==TE&&e[1].t===nD}}),YD=e=>new _E(e);function XD({groups:e}){let t=e.domain.concat([YE,ZE,QE,$E,eD,tD,iD,oD,cD,AE,lD,uD,dD,fD,_D,xD,vD,yD]),n=[XE,nD,rD,aD,sD,lD,pD,mD,gD,zE,BE,NE,PE,IE,FE,LE,RE,VE,HE,UE,WE,GE,KE,qE,JE],r=[YE,XE,ZE,$E,eD,tD,iD,oD,cD,NE,PE,lD,uD,dD,fD,pD,_D,xD,vD,yD],i=YD(),a=P(i,vD);vE(a,r,a),vE(a,e.domain,a);let o=YD(),s=YD(),c=YD();vE(i,e.domain,o),vE(i,e.scheme,s),vE(i,e.slashscheme,c),vE(o,r,a),vE(o,e.domain,o);let l=P(o,QE);P(a,QE,l),P(s,QE,l),P(c,QE,l);let u=P(a,aD);vE(u,r,a),vE(u,e.domain,a);let d=YD();vE(l,e.domain,d),vE(d,e.domain,d);let f=P(d,aD);vE(f,e.domain,d);let p=YD(GD);vE(f,e.tld,p),vE(f,e.utld,p),P(l,TE,p);let m=P(d,cD);P(m,cD,m),vE(m,e.domain,d),vE(p,e.domain,d),P(p,aD,f),P(p,cD,m);let h=P(o,cD),g=P(o,aD);P(h,cD,h),vE(h,e.domain,o),vE(g,r,a),vE(g,e.domain,o);let _=YD(JD);vE(g,e.tld,_),vE(g,e.utld,_),vE(_,e.domain,o),vE(_,r,a),P(_,aD,g),P(_,cD,h),P(_,QE,l);let v=P(_,nD),y=YD(JD);vE(v,e.numeric,y);let b=YD(JD),x=YD();vE(b,t,b),vE(b,n,x),vE(x,t,b),vE(x,n,x),P(_,_D,b),P(y,_D,b),P(_,pD,x),P(_,fD,b),P(y,pD,x),P(y,fD,b);let S=P(s,nD),C=P(P(P(c,nD),_D),_D);vE(s,e.domain,o),P(s,aD,g),P(s,cD,h),vE(c,e.domain,o),P(c,aD,g),P(c,cD,h),vE(S,e.domain,b),P(S,_D,b),P(S,pD,b),vE(C,e.domain,b),vE(C,t,b),P(C,_D,b);let ee=[[NE,PE],[FE,IE],[LE,RE],[zE,BE],[VE,HE],[UE,WE],[GE,KE],[qE,JE]];for(let e=0;e=0&&p++,m.push(c),s[i]&&s[i].has(c))break;for(let e=0,t=i-m.length+1;e0&&(a.push(QD(KD,t,o)),o=[]),i-=p,d-=p;let e=f.t,r=n.slice(i-d,i);a.push(QD(e,t,r))}}return o.length>0&&a.push(QD(KD,t,o)),a}function QD(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var $D=typeof console<`u`&&console&&console.warn||(()=>{}),eO=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,tO={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function nO(){return _E.groups={},tO.scanner=null,tO.parser=null,tO.tokenQueue=[],tO.pluginQueue=[],tO.customSchemes=[],tO.initialized=!1,tO}function rO(e,t=!1){if(tO.initialized&&$D(`linkifyjs: already initialized - will not register custom scheme "${e}" ${eO}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. 1. Must only contain digits, lowercase ASCII letters or "-" 2. Cannot start or end with "-" -3. "-" cannot repeat`);QD.customSchemes.push([e,t])}function tO(){QD.scanner=MD(QD.customSchemes);for(let e=0;ee.mark.type===n);if(!o.length)return;let{nodeAfter:s}=r;if(s&&o.some(e=>e.mark.isInSet(s.marks)))return;let c=e.storedMarks;e.removeMark(a,t.to,n),e.setStoredMarks(c),e.selection.empty&&e.selection.from===t.to&&e.removeStoredMark(n)}function uO(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function dO(e){return new D({key:new Un(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r,s=hu(n.doc,[...t]);if(!t.some(Jc)){let t=[];s.steps.forEach((e,n)=>{if(!(e instanceof Et)||!e.slice.size)return;let r=s.mapping.slice(n+1),i=r.map(e.from,1),a=r.map(e.from+e.slice.size,-1);it.to-e.to),t.forEach(t=>lO(o,t,e.type))}if($u(s).forEach(({newRange:t})=>{let n=_u(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!oO.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(aO).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=nO(n).map(t=>t.toObject(e.defaultProtocol));if(!uO(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>!r.schema.marks.code||!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code)).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{ed(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function fO(e){return new D({key:new Un(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=Xu(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}var pO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,mO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function hO(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function gO(e,t){let n=0,r=0;for(;r0}function _O(e,t,n){let[,r,i]=t;return(t.index?e[t.index-1]:void 0)===`!`||hO(e,t.index??0)||gO(e,t.index??0)?!1:!!r.trim()&&n(i)}function vO(e){let[t,n,r,,i,a,o]=e,s=i??a??o;return{index:e.index??0,text:t,replaceWith:n,data:{href:r,title:s||null,markdown:!0}}}function yO(e,t){return e.index{let n=pO.exec(t);return!n||!_O(t,n,e.isAllowedHref)?null:vO(n)},type:e.type,getAttributes:bO});return new lp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function SO(e){let t=Yp({find:t=>{let n=[];for(let r of t.matchAll(mO))_O(t,r,e.isAllowedHref)&&n.push(vO(r));let r=(e.findPlainUrls?.call(e,t)??[]).filter(e=>!n.some(t=>yO(t,e)));return[...n,...r]},type:e.type,getAttributes:bO});return new vp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.match.data?.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function CO(e){return new D({key:new Un(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=rO(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function wO(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(cO,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}var TO=_p.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{typeof e==`string`?eO(e):eO(e.scheme,e.optionalSlashes)})},onDestroy(){$D()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!wO(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target??null},rel:{default:this.options.HTMLAttributes.rel??null},class:{default:this.options.HTMLAttributes.class??null},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,A(this.options.HTMLAttributes,e),0]:[`a`,A(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[xO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;rO(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!wO(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[SO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!wO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[Yp({find:e,type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(dO({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!wO(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(fO({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(CO({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),EO=`listItem`,DO=`textStyle`,OO=/^\s*([-+*])\s$/,kO=Jp.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(EO,this.editor.getAttributes(DO)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=Gp({find:OO,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=Gp({find:OO,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(DO),editor:this.editor})),[e]}}),AO=(e,t,n)=>{let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;if(!i.parent.isTextblock||i.parentOffset!==i.parent.content.size)return null;let a=-1;for(let e=i.depth;e>0;--e)if(i.node(e).type.name===t){a=e;break}if(a<0)return null;let o=i.node(a),s=i.index(a);if(s+1>=o.childCount)return null;let c=o.child(s+1);if(!n.includes(c.type.name))return null;let l=e.schema.nodes[t],u=!1;if(c.forEach(e=>{e.type===l&&e.childCount>1&&(u=!0)}),!u)return null;let d=e.doc.resolve(i.after()).nodeAfter;if(!d||!n.includes(d.type.name))return null;let f=[];return d.forEach(e=>{f.push(e)}),f.length===0?null:{listItemDepth:a,nestedList:d,nestedListPos:i.after(),insertPos:i.after(a),items:f}},jO=(e,t,n,r)=>{let i=AO(e,n,r);if(!i)return!1;let{selection:a}=e,{nestedList:o,nestedListPos:c,insertPos:l,items:u}=i,d=e.tr;d.delete(c,c+o.nodeSize);let f=d.mapping.map(l);return d.insert(f,s.from(u)),d.setSelection(a.map(d.doc,d.mapping)),t&&t(d),!0},MO=(e,t,n)=>jO(e.state,e.view.dispatch,t,n),NO=(e,t)=>Tp.create({name:`${e}BranchingDeleteKeymap`,priority:101,addKeyboardShortcuts(){let n=()=>MO(this.editor,e,t);return{Delete:n,"Mod-Delete":n}}}),PO=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],FO=`abcdefghijklmnopqrstuvwxyz`,IO=String.raw`\d+|[ivxlcdmIVXLCDM]+|${`[a-zA-Z]{1,2}`}`;function LO(e){let t=e,n=``;for(let[e,r]of PO)for(;t>=e;)n+=r,t-=e;return n}function RO(e){return LO(e).toUpperCase()}function zO(e){let t=e.toLowerCase(),n=0,r=0;for(;n0?t:1}let n=parseInt(e,10);return Number.isNaN(n)?1:n}function GO(e,t){if(e===`numeric`)return String(t);switch(e){case`a`:return HO(t);case`A`:return HO(t).toUpperCase();case`i`:return LO(t);case`I`:return RO(t);default:return String(t)}}function KO(e){if(e.length===0)return!1;let t=UO(e[0])??`numeric`,n=WO(e[0]);if(n<1)return!1;for(let r=0;r(e?.level??$O)>$O;function tk(e){let t=e.tokens?.[0];return!!(e.text&&e.tokens?.length===1&&t?.type===`list`&&t.ordered&&t.raw===e.text)}function nk(e,t){return t.tokenizeInline?t.parseInline(t.tokenizeInline(e)):t.parseInline([{type:`text`,raw:e,text:e}])}var rk=Jp.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0){if(tk(e))return{type:`listItem`,content:[{type:`paragraph`,content:nk(e.text||``,t)}]};let[i,...a]=e.tokens;if(i.type===`heading`)return{type:`listItem`,content:[{type:`paragraph`,content:t.parseInline(i.tokens??[])},...a.length>0?n(a):[]]};if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else if(i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:XO(r)}},renderMarkdown:(e,t,n)=>{let r=e=>{if(e.parentType===`bulletList`)return`- `;if(e.parentType===`orderedList`){var t,n;let r=((t=e.meta)==null||(t=t.parentAttrs)==null?void 0:t.start)||1;return YO((n=e.meta)==null||(n=n.parentAttrs)==null?void 0:n.type,r-1+(e.index||0),`. `)}return`- `},i=op(e,t,r,n,{alignNestedToPrefix:n?.parentType===`orderedList`});if(!ZO(e)||!ek(n))return i;let a=r(n);return`${a}${QO}${i.slice(a.length)}`},addExtensions(){return[NO(this.name,[this.options.bulletListTypeName,this.options.orderedListTypeName])]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),ik=(e,t)=>{let{$from:n}=t.selection,r=il(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},ak=(e,t)=>{let n=ik(e,t);if(!n)return!1;let[,r]=td(t,e,n.$pos.pos+4);return r},ok=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},sk=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!Zl(e.state,t)&&ok(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().command(({tr:e})=>{let t=o.end();return e.delete(n.before(),n.after()).insert(t,n.parent),e.setSelection(T.create(e.doc,t+1)),!0}).command(({state:e,dispatch:t})=>(qn(e,t),!0)).run()}if(!Zl(e.state,t)||!ld(e.state))return!1;let{$from:r}=e.state.selection,i=r.depth-1;return r.node(i).type!==e.schema.nodes[t]||r.index(i)!==0?!1:e.chain().liftListItem(t).run()},ck=(e,t)=>{let n=ak(e,t),r=ik(e,t);return!r||!n?!1:n>r.depth},lk=(e,t)=>{let n=ak(e,t),r=ik(e,t);return!r||!n?!1:n!Zl(e.state,t)||!cd(e.state,t)||!e.state.selection.empty?!1:ck(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():lk(t,e.state)?e.commands.command(({state:e,dispatch:t})=>Jn(e,t)):e.commands.joinItemForward(),dk=(e,t,n)=>{let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:a}=i;if(a.parentOffset!==0||!a.parent.isTextblock||Zl(r,t))return!1;let o=nd(a);if(!o||!n.includes(o.type.name))return!1;let c=o.lastChild;if(!c||c.type.name!==t)return!1;let l=a.parent;if(!c.canReplace(c.childCount,c.childCount,s.from(l)))return!1;let u=a.before(),d=a.after(),f=u-2;return e.commands.command(({tr:e,dispatch:t})=>(t&&(e.delete(u,d).insert(f,s.from(l)),e.setSelection(T.create(e.doc,f+1)),e.scrollIntoView()),!0))},fk=Tp.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&sk(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&sk(e,n,r)&&(t=!0)}),t},Tab:({editor:e})=>{for(let{itemName:t,wrapperNames:n}of this.options.listTypes)if(e.state.schema.nodes[t]!==void 0&&dk(e,t,n))return!0;return!1}}}}),pk=RegExp(`^(\\s*)(${IO})([.)])\\s+(.*)$`),mk=/^\s/,hk={heading:/^#{1,6}(?:\s|$)/,bulletItem:/^[-+*]\s+/,codeFence:/^(?:```|~~~)/,blockMath:/^\$\$/,thematicBreak:/^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/};function gk(e){return pk.test(e.trimStart())}function _k(e){let t=e.trimStart();return hk.bulletItem.test(t)||gk(t)||hk.heading.test(t)||hk.thematicBreak.test(t)&&!t.startsWith(`-`)||/^>\s?/.test(t)||hk.codeFence.test(t)||hk.blockMath.test(t)}function vk(e){return Object.values(hk).some(t=>t.test(e))}function yk(e){let t=[],n=[],r=!1;return e.forEach(e=>{r?n.push(e):e.trim()===``||t.length>0&&_k(e)?(r=!0,n.push(e)):t.push(e)}),{paragraphLines:t,blockLines:n}}function bk(e){let t=[],n=0,r=0;for(;ne.mark.type===n);if(!o.length)return;let{nodeAfter:s}=r;if(s&&o.some(e=>e.mark.isInSet(s.marks)))return;let c=e.storedMarks;e.removeMark(a,t.to,n),e.setStoredMarks(c),e.selection.empty&&e.selection.from===t.to&&e.removeStoredMark(n)}function pO(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function mO(e){return new D({key:new Un(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r,s=hu(n.doc,[...t]);if(!t.some(Jc)){let t=[];s.steps.forEach((e,n)=>{if(!(e instanceof Et)||!e.slice.size)return;let r=s.mapping.slice(n+1),i=r.map(e.from,1),a=r.map(e.from+e.slice.size,-1);it.to-e.to),t.forEach(t=>fO(o,t,e.type))}if($u(s).forEach(({newRange:t})=>{let n=_u(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!lO.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(cO).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=aO(n).map(t=>t.toObject(e.defaultProtocol));if(!pO(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>!r.schema.marks.code||!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code)).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{ed(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function hO(e){return new D({key:new Un(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=Xu(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}var gO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,_O=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function vO(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function yO(e,t){let n=0,r=0;for(;r0}function bO(e,t,n){let[,r,i]=t;return(t.index?e[t.index-1]:void 0)===`!`||vO(e,t.index??0)||yO(e,t.index??0)?!1:!!r.trim()&&n(i)}function xO(e){let[t,n,r,,i,a,o]=e,s=i??a??o;return{index:e.index??0,text:t,replaceWith:n,data:{href:r,title:s||null,markdown:!0}}}function SO(e,t){return e.index{let n=gO.exec(t);return!n||!bO(t,n,e.isAllowedHref)?null:xO(n)},type:e.type,getAttributes:CO});return new lp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function TO(e){let t=Yp({find:t=>{let n=[];for(let r of t.matchAll(_O))bO(t,r,e.isAllowedHref)&&n.push(xO(r));let r=(e.findPlainUrls?.call(e,t)??[]).filter(e=>!n.some(t=>SO(t,e)));return[...n,...r]},type:e.type,getAttributes:CO});return new vp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.match.data?.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function EO(e){return new D({key:new Un(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=oO(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function DO(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(dO,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}var OO=_p.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{typeof e==`string`?rO(e):rO(e.scheme,e.optionalSlashes)})},onDestroy(){nO()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!DO(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target??null},rel:{default:this.options.HTMLAttributes.rel??null},class:{default:this.options.HTMLAttributes.class??null},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,A(this.options.HTMLAttributes,e),0]:[`a`,A(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[wO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;oO(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!DO(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[TO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[Yp({find:e,type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(mO({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(hO({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(EO({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),kO=`listItem`,AO=`textStyle`,jO=/^\s*([-+*])\s$/,MO=Jp.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(kO,this.editor.getAttributes(AO)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=Gp({find:jO,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=Gp({find:jO,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(AO),editor:this.editor})),[e]}}),NO=(e,t,n)=>{let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;if(!i.parent.isTextblock||i.parentOffset!==i.parent.content.size)return null;let a=-1;for(let e=i.depth;e>0;--e)if(i.node(e).type.name===t){a=e;break}if(a<0)return null;let o=i.node(a),s=i.index(a);if(s+1>=o.childCount)return null;let c=o.child(s+1);if(!n.includes(c.type.name))return null;let l=e.schema.nodes[t],u=!1;if(c.forEach(e=>{e.type===l&&e.childCount>1&&(u=!0)}),!u)return null;let d=e.doc.resolve(i.after()).nodeAfter;if(!d||!n.includes(d.type.name))return null;let f=[];return d.forEach(e=>{f.push(e)}),f.length===0?null:{listItemDepth:a,nestedList:d,nestedListPos:i.after(),insertPos:i.after(a),items:f}},PO=(e,t,n,r)=>{let i=NO(e,n,r);if(!i)return!1;let{selection:a}=e,{nestedList:o,nestedListPos:c,insertPos:l,items:u}=i,d=e.tr;d.delete(c,c+o.nodeSize);let f=d.mapping.map(l);return d.insert(f,s.from(u)),d.setSelection(a.map(d.doc,d.mapping)),t&&t(d),!0},FO=(e,t,n)=>PO(e.state,e.view.dispatch,t,n),IO=(e,t)=>Tp.create({name:`${e}BranchingDeleteKeymap`,priority:101,addKeyboardShortcuts(){let n=()=>FO(this.editor,e,t);return{Delete:n,"Mod-Delete":n}}}),LO=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],RO=`abcdefghijklmnopqrstuvwxyz`,zO=String.raw`\d+|[ivxlcdmIVXLCDM]+|${`[a-zA-Z]{1,2}`}`;function BO(e){let t=e,n=``;for(let[e,r]of LO)for(;t>=e;)n+=r,t-=e;return n}function VO(e){return BO(e).toUpperCase()}function HO(e){let t=e.toLowerCase(),n=0,r=0;for(;n0?t:1}let n=parseInt(e,10);return Number.isNaN(n)?1:n}function JO(e,t){if(e===`numeric`)return String(t);switch(e){case`a`:return GO(t);case`A`:return GO(t).toUpperCase();case`i`:return BO(t);case`I`:return VO(t);default:return String(t)}}function YO(e){if(e.length===0)return!1;let t=KO(e[0])??`numeric`,n=qO(e[0]);if(n<1)return!1;for(let r=0;r(e?.level??nk)>nk;function ik(e){let t=e.tokens?.[0];return!!(e.text&&e.tokens?.length===1&&t?.type===`list`&&t.ordered&&t.raw===e.text)}function ak(e,t){return t.tokenizeInline?t.parseInline(t.tokenizeInline(e)):t.parseInline([{type:`text`,raw:e,text:e}])}var ok=Jp.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0){if(ik(e))return{type:`listItem`,content:[{type:`paragraph`,content:ak(e.text||``,t)}]};let[i,...a]=e.tokens;if(i.type===`heading`)return{type:`listItem`,content:[{type:`paragraph`,content:t.parseInline(i.tokens??[])},...a.length>0?n(a):[]]};if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else if(i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:$O(r)}},renderMarkdown:(e,t,n)=>{let r=e=>{if(e.parentType===`bulletList`)return`- `;if(e.parentType===`orderedList`){var t,n;let r=((t=e.meta)==null||(t=t.parentAttrs)==null?void 0:t.start)||1;return QO((n=e.meta)==null||(n=n.parentAttrs)==null?void 0:n.type,r-1+(e.index||0),`. `)}return`- `},i=op(e,t,r,n,{alignNestedToPrefix:n?.parentType===`orderedList`});if(!ek(e)||!rk(n))return i;let a=r(n);return`${a}${tk}${i.slice(a.length)}`},addExtensions(){return[IO(this.name,[this.options.bulletListTypeName,this.options.orderedListTypeName])]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),sk=(e,t)=>{let{$from:n}=t.selection,r=il(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},ck=(e,t)=>{let n=sk(e,t);if(!n)return!1;let[,r]=td(t,e,n.$pos.pos+4);return r},lk=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},uk=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!Zl(e.state,t)&&lk(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().command(({tr:e})=>{let t=o.end();return e.delete(n.before(),n.after()).insert(t,n.parent),e.setSelection(T.create(e.doc,t+1)),!0}).command(({state:e,dispatch:t})=>(qn(e,t),!0)).run()}if(!Zl(e.state,t)||!ld(e.state))return!1;let{$from:r}=e.state.selection,i=r.depth-1;return r.node(i).type!==e.schema.nodes[t]||r.index(i)!==0?!1:e.chain().liftListItem(t).run()},dk=(e,t)=>{let n=ck(e,t),r=sk(e,t);return!r||!n?!1:n>r.depth},fk=(e,t)=>{let n=ck(e,t),r=sk(e,t);return!r||!n?!1:n!Zl(e.state,t)||!cd(e.state,t)||!e.state.selection.empty?!1:dk(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():fk(t,e.state)?e.commands.command(({state:e,dispatch:t})=>Jn(e,t)):e.commands.joinItemForward(),mk=(e,t,n)=>{let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:a}=i;if(a.parentOffset!==0||!a.parent.isTextblock||Zl(r,t))return!1;let o=nd(a);if(!o||!n.includes(o.type.name))return!1;let c=o.lastChild;if(!c||c.type.name!==t)return!1;let l=a.parent;if(!c.canReplace(c.childCount,c.childCount,s.from(l)))return!1;let u=a.before(),d=a.after(),f=u-2;return e.commands.command(({tr:e,dispatch:t})=>(t&&(e.delete(u,d).insert(f,s.from(l)),e.setSelection(T.create(e.doc,f+1)),e.scrollIntoView()),!0))},hk=Tp.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&pk(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&pk(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n,r)&&(t=!0)}),t},Tab:({editor:e})=>{for(let{itemName:t,wrapperNames:n}of this.options.listTypes)if(e.state.schema.nodes[t]!==void 0&&mk(e,t,n))return!0;return!1}}}}),gk=RegExp(`^(\\s*)(${zO})([.)])\\s+(.*)$`),_k=/^\s/,vk={heading:/^#{1,6}(?:\s|$)/,bulletItem:/^[-+*]\s+/,codeFence:/^(?:```|~~~)/,blockMath:/^\$\$/,thematicBreak:/^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/};function yk(e){return gk.test(e.trimStart())}function bk(e){let t=e.trimStart();return vk.bulletItem.test(t)||yk(t)||vk.heading.test(t)||vk.thematicBreak.test(t)&&!t.startsWith(`-`)||/^>\s?/.test(t)||vk.codeFence.test(t)||vk.blockMath.test(t)}function xk(e){return Object.values(vk).some(t=>t.test(e))}function Sk(e){let t=[],n=[],r=!1;return e.forEach(e=>{r?n.push(e):e.trim()===``||t.length>0&&bk(e)?(r=!0,n.push(e)):t.push(e)}),{paragraphLines:t,blockLines:n}}function Ck(e){let t=[],n=0,r=0;for(;ne.trim().length>0);if(t.length===0)return null;let n=[];for(let e of t){let t=e.trim().match(xk);if(!t)return null;n.push({marker:t[1],content:t[3]})}return KO(n.map(e=>e.marker))?{type:`orderedList`,attrs:JO(n[0].marker),content:n.map(e=>({type:`listItem`,content:[{type:`paragraph`,content:[{type:`text`,text:e.content}]}]}))}:null}function Ck(e,t,n){let r=[],i=0;for(;ie.trim().length>0);if(t.length===0)return null;let n=[];for(let e of t){let t=e.trim().match(wk);if(!t)return null;n.push({marker:t[1],content:t[3]})}return YO(n.map(e=>e.marker))?{type:`orderedList`,attrs:ZO(n[0].marker),content:n.map(e=>({type:`listItem`,content:[{type:`paragraph`,content:[{type:`text`,text:e.content}]}]}))}:null}function Ek(e,t,n){let r=[],i=0;for(;it;)f.push(e[d]),d+=1;if(f.length>0){let e=Ck(f,Math.min(...f.map(e=>e.indent)),n);l.push({type:`list`,ordered:!0,start:f[0].number,typeMarker:f[0].type,items:e,raw:f.map(e=>e.raw).join(` -`)})}r.push({type:`list_item`,raw:a.raw,tokens:l}),i=d}else i+=1}return r}function wk(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var Tk=64;function Ek(e,t){let n=[],r=0;for(;n.lengthe.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>{let t=e.getAttribute(`type`);if(t)return t;let n=e.getAttribute(`style`);if(n){let e=jk(n);if(e)return e}let r=e.querySelector(`li`);if(r){let e=r.getAttribute(`style`);if(e){let t=jk(e);if(t)return t}}return null}}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,type:n,...r}=e,i=A(this.options.HTMLAttributes,r);return t!==1&&(i.start=t),n&&n!==`1`&&(i.type=n),[`ol`,i,0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.typeMarker,i=e.items?wk(e.items,t):[],a={};return n!==1&&(a.start=n),r&&(a.type=r),Object.keys(a).length>0?{type:`orderedList`,attrs:a,content:i}:{type:`orderedList`,content:i}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:()=>-1,tokenize:(e,t,n)=>{let[r,i,a]=Dk(e);if(r.length===0)return;let o=Ck(r,r[0].indent,n);if(o.length!==0)return{type:`list`,ordered:!0,start:r[0]?.number||1,typeMarker:r[0]?.type,items:o,raw:a.slice(0,i).join(` -`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Ok,this.editor.getAttributes(kk)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addProseMirrorPlugins(){return[new D({props:{handlePaste:(e,t)=>{if((t.clipboardData?.getData(`text/html`))?.trim())return!1;let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=Sk(n);if(!r)return!1;try{let t=e.state.schema.nodeFromJSON(r),n=e.state.tr.replaceSelectionWith(t);return e.dispatch(n),!0}catch{return!1}}}})]},addInputRules(){let e=(e,t)=>(!t.attrs.type||t.attrs.type===`1`)&&t.childCount+t.attrs.start===+e[1],t=Gp({find:Ak,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:e});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Gp({find:Ak,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(kk)}),joinPredicate:e,editor:this.editor})),[t]}}),Nk=/^\s*(\[([( |x])?\])\s$/,Pk=`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0`,Fk=(e,t,n)=>{var r;return(n==null||(r=n.checkboxLabel)==null?void 0:r.call(n,e,t))||`Task item checkbox for ${e.textContent||`empty task item`}`},Ik=Jp.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51,contentElement:e=>e.querySelector(`div`)??e}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,A(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>op(e,t,`- [${e.attrs?.checked?`x`:` `}] `,void 0,{indentMainContent:!0}),addExtensions(){return this.options.nested?[NO(this.name,[this.options.taskListTypeName])]:[]},addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`);o.style.cssText=Pk;let l=e=>{let t=Fk(e,e.attrs.checked,this.options.a11y);s.setAttribute(`aria-label`,t),o.textContent=t};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=Lu(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[Gp({find:Nk,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),Lk=Jp.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(t){let r={type:`taskList`,raw:t.raw,items:t.items},i=e.slice(t.raw.length);return i.trim()?[r,...n.blockTokens(i)]:[r]}return n.blockTokens(e)},i=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Tp.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(kO.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(rk.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(fk.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(Mk.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(Ik.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(Lk.configure(this.options.taskList)),e}});var Rk=` `,zk=`\xA0`,Bk=Jp.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,A(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===Rk||n[0].text===Rk||n[0].raw===zk||n[0].text===zk)&&r.length===1&&r[0].type===`text`&&(r[0].text===Rk||r[0].text===zk)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){var i,a;let e=Array.isArray(n==null||(i=n.previousNode)==null?void 0:i.content)?n.previousNode.content:[];return(n==null||(a=n.previousNode)==null?void 0:a.type)===`paragraph`&&e.length===0?Rk:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Vk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Hk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Uk=_p.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Hp({find:Vk,type:this.type})]},addPasteRules(){return[Yp({find:Hk,type:this.type})]}}),Wk=Jp.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),Gk=_p.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,A(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`${t.renderChildren(e)}`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.toLowerCase().indexOf(``)},tokenize(e,t,n){if(!/^/i.test(e))return;let r=/\\[\s\S]|`+|<\/u>/gi;r.lastIndex=3;let i=r.exec(e);for(;i;){if(i[0].startsWith("`")){let t=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/.exec(e.slice(i.index));t&&(r.lastIndex=i.index+t[0].length)}else if(!i[0].startsWith(`\\`)){let t=e.slice(3,i.index);return t?{type:`underline`,raw:e.slice(0,r.lastIndex),text:t,tokens:n.inlineTokens(t)}:void 0}i=r.exec(e)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),Kk=Tp.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(PT.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(kT.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(kO.configure(this.options.bulletList)),this.options.code!==!1&&e.push(RT.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(HT.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(WT.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(qw.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Jw.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(GT.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(KT.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(yT.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(qT.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(QT.configure(this.options.italic)),this.options.listItem!==!1&&e.push(rk.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(fk.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(TO.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(Mk.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Bk.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(Uk.configure(this.options.strike)),this.options.text!==!1&&e.push(Wk.configure(this.options.text)),this.options.underline!==!1&&e.push(Gk.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(vT.configure(this.options?.trailingNode)),e}}),qk=Math.min,Jk=Math.max,Yk=Math.round,Xk=Math.floor,Zk=e=>({x:e,y:e}),Qk={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function $k(e,t,n){return Jk(e,qk(t,n))}function eA(e,t){return typeof e==`function`?e(t):e}function tA(e){return e.split(`-`)[0]}function nA(e){return e.split(`-`)[1]}function rA(e){return e===`x`?`y`:`x`}function iA(e){return e===`y`?`height`:`width`}function aA(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function oA(e){return rA(aA(e))}function sA(e,t,n){n===void 0&&(n=!1);let r=nA(e),i=oA(e),a=iA(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=gA(o)),[o,gA(o)]}function cA(e){let t=gA(e);return[lA(e),t,lA(t)]}function lA(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var uA=[`left`,`right`],dA=[`right`,`left`],fA=[`top`,`bottom`],pA=[`bottom`,`top`];function mA(e,t,n){switch(e){case`top`:case`bottom`:return n?t?dA:uA:t?uA:dA;case`left`:case`right`:return t?fA:pA;default:return[]}}function hA(e,t,n,r){let i=nA(e),a=mA(tA(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(lA)))),a}function gA(e){let t=tA(e);return Qk[t]+e.slice(t.length)}function _A(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function vA(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:_A(e)}function yA(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function bA(e,t,n){let{reference:r,floating:i}=e,a=aA(t),o=oA(t),s=iA(o),c=tA(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=nA(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function xA(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=eA(t,e),p=vA(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=yA(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=yA(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var SA=50,CA=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:xA},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=bA(l,r,c),f=r,p=0,m={};for(let n=0;ne<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===aA(t)||te.every(e=>aA(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:te},reset:{placement:t}};let n=te.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=te.filter(e=>{if(x){let t=aA(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},TA=new Set([`left`,`top`]);async function EA(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=tA(n),s=nA(n),c=aA(n)===`y`,l=TA.has(o)?-1:1,u=a&&c?-1:1,d=eA(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var DA=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await EA(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},OA=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=eA(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=aA(i),p=rA(f),m=u[p],h=u[f],g=(e,t)=>$k(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}};function kA(){return typeof window<`u`}function AA(e){return NA(e)?(e.nodeName||``).toLowerCase():`#document`}function jA(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function MA(e){return((NA(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function NA(e){return kA()?e instanceof Node||e instanceof jA(e).Node:!1}function PA(e){return kA()?e instanceof Element||e instanceof jA(e).Element:!1}function FA(e){return kA()?e instanceof HTMLElement||e instanceof jA(e).HTMLElement:!1}function IA(e){return!kA()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof jA(e).ShadowRoot}function LA(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=JA(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function RA(e){return/^(table|td|th)$/.test(AA(e))}function zA(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var BA=/transform|translate|scale|rotate|perspective|filter/,VA=/paint|layout|strict|content/,HA=e=>!!e&&e!==`none`,UA;function WA(e){let t=PA(e)?JA(e):e;return HA(t.transform)||HA(t.translate)||HA(t.scale)||HA(t.rotate)||HA(t.perspective)||!KA()&&(HA(t.backdropFilter)||HA(t.filter))||BA.test(t.willChange||``)||VA.test(t.contain||``)}function GA(e){let t=XA(e);for(;FA(t)&&!qA(t);){if(WA(t))return t;if(zA(t))return null;t=XA(t)}return null}function KA(){return UA??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),UA}function qA(e){return/^(html|body|#document)$/.test(AA(e))}function JA(e){return jA(e).getComputedStyle(e)}function YA(e){return PA(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function XA(e){if(AA(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||IA(e)&&e.host||MA(e);return IA(t)?t.host:t}function ZA(e){let t=XA(e);return qA(t)?(e.ownerDocument||e).body:FA(t)&&LA(t)?t:ZA(t)}function QA(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ZA(e),i=r===e.ownerDocument?.body,a=jA(r);if(i){let e=$A(a);return t.concat(a,a.visualViewport||[],LA(r)?r:[],e&&n?QA(e):[])}return t.concat(r,QA(r,[],n))}function $A(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function ej(e){let t=JA(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=FA(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Yk(n)!==a||Yk(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function tj(e){return PA(e)?e:e.contextElement}function nj(e){let t=tj(e);if(!FA(t))return Zk(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=ej(t),o=(a?Yk(n.width):n.width)/r,s=(a?Yk(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var rj=Zk(0);function ij(e){let t=jA(e);return!KA()||!t.visualViewport?rj:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function aj(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===jA(e)}function oj(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=tj(e),o=Zk(1);t&&(r?PA(r)&&(o=nj(r)):o=nj(e));let s=aj(a,n,r)?ij(a):Zk(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=jA(a),t=PA(r)?jA(r):r,n=e,i=$A(n);for(;i&&t!==n;){let e=nj(i),t=i.getBoundingClientRect(),r=JA(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=jA(i),i=$A(n)}}return yA({width:u,height:d,x:c,y:l})}function sj(e,t){let n=YA(e).scrollLeft;return t?t.left+n:oj(MA(e)).left+n}function cj(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-sj(e,n),y:n.top+t.scrollTop}}function lj(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=MA(r),s=t?zA(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Zk(1),u=Zk(0),d=FA(r);if((d||!a)&&((AA(r)!==`body`||LA(o))&&(c=YA(r)),d)){let e=oj(r);l=nj(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?cj(o,c):Zk(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function uj(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function dj(e){let t=YA(e),n=e.ownerDocument.body,r=Jk(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Jk(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+sj(e),o=-t.scrollTop;return JA(n).direction===`rtl`&&(a+=Jk(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var fj=25;function pj(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=jA(e),a=MA(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!KA()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(sj(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=fj&&(s-=o)}return{width:s,height:c,x:l,y:u}}function mj(e,t){let n=oj(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=nj(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function hj(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=pj(e,n,t);else if(t===`document`)r=dj(MA(e));else if(PA(t))r=mj(t,n);else{let n=ij(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return yA(r)}function gj(e,t){let n=t.get(e);if(n)return n;let r=QA(e,[],!1).filter(e=>PA(e)&&AA(e)!==`body`),i=null,a=JA(e).position===`fixed`,o=a?XA(e):e;for(;PA(o)&&!qA(o);){let e=JA(o),t=WA(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=XA(o)}return t.set(e,r),r}function _j(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?zA(t)?[]:gj(t,this._c):[].concat(n),r],o=hj(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=jA(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Oj(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=tj(e),u=i||a?[...l?QA(l):[],...t?QA(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Dj(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?oj(e):null;c&&g();function g(){let t=oj(e);h&&!Ej(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var kj=DA,Aj=OA,jj=wA,Mj=(e,t,n)=>{let r=new Map,i=n??{},a={...Tj,...i.platform,_c:r};return CA(e,t,{...i,platform:a})};function Nj(e,t){return typeof e==`boolean`?e:t}var Pj=UT.extend({addOptions(){return{...this.parent(),lineNumbers:!1}},addAttributes(){return{...this.parent?.(),lineNumbers:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-line-numbers`);return t===`true`||t!==`false`&&null},renderHTML:e=>typeof e.lineNumbers==`boolean`?{"data-line-numbers":String(e.lineNumbers)}:{}}}},addCommands(){return{...this.parent?.(),toggleCodeLineNumbers:()=>({editor:e,commands:t})=>{if(!e.isActive(this.name))return!1;let n=Nj(e.getAttributes(this.name).lineNumbers,this.options.lineNumbers);return t.updateAttributes(this.name,{lineNumbers:!n})}}},addNodeView(){let e=this.options.lineNumbers,t=this.options.languageClassPrefix??`language-`;return({node:n})=>{let r=document.createElement(`pre`);r.className=`dw-code`;let i=document.createElement(`div`);i.className=`dw-code__gutter`,i.contentEditable=`false`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`code`);r.append(i,a);let o=-1,s=n=>{let s=Nj(n.attrs.lineNumbers,e);r.classList.toggle(`dw-code--numbered`,s),a.className=n.attrs.language?`${t}${String(n.attrs.language)}`:``;let c=s?n.textContent.split(` +`).trim();if(u){let e=n.blockTokens(u);l.push(...e)}let d=i+1,f=[];for(;dt;)f.push(e[d]),d+=1;if(f.length>0){let e=Ek(f,Math.min(...f.map(e=>e.indent)),n);l.push({type:`list`,ordered:!0,start:f[0].number,typeMarker:f[0].type,items:e,raw:f.map(e=>e.raw).join(` +`)})}r.push({type:`list_item`,raw:a.raw,tokens:l}),i=d}else i+=1}return r}function Dk(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var Ok=64;function kk(e,t){let n=[],r=0;for(;n.lengthe.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>{let t=e.getAttribute(`type`);if(t)return t;let n=e.getAttribute(`style`);if(n){let e=Pk(n);if(e)return e}let r=e.querySelector(`li`);if(r){let e=r.getAttribute(`style`);if(e){let t=Pk(e);if(t)return t}}return null}}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,type:n,...r}=e,i=A(this.options.HTMLAttributes,r);return t!==1&&(i.start=t),n&&n!==`1`&&(i.type=n),[`ol`,i,0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.typeMarker,i=e.items?Dk(e.items,t):[],a={};return n!==1&&(a.start=n),r&&(a.type=r),Object.keys(a).length>0?{type:`orderedList`,attrs:a,content:i}:{type:`orderedList`,content:i}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:()=>-1,tokenize:(e,t,n)=>{let[r,i,a]=Ak(e);if(r.length===0)return;let o=Ek(r,r[0].indent,n);if(o.length!==0)return{type:`list`,ordered:!0,start:r[0]?.number||1,typeMarker:r[0]?.type,items:o,raw:a.slice(0,i).join(` +`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(jk,this.editor.getAttributes(Mk)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addProseMirrorPlugins(){return[new D({props:{handlePaste:(e,t)=>{if((t.clipboardData?.getData(`text/html`))?.trim())return!1;let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=Tk(n);if(!r)return!1;try{let t=e.state.schema.nodeFromJSON(r),n=e.state.tr.replaceSelectionWith(t);return e.dispatch(n),!0}catch{return!1}}}})]},addInputRules(){let e=(e,t)=>(!t.attrs.type||t.attrs.type===`1`)&&t.childCount+t.attrs.start===+e[1],t=Gp({find:Nk,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:e});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Gp({find:Nk,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(Mk)}),joinPredicate:e,editor:this.editor})),[t]}}),Ik=/^\s*(\[([( |x])?\])\s$/,Lk=`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0`,Rk=(e,t,n)=>{var r;return(n==null||(r=n.checkboxLabel)==null?void 0:r.call(n,e,t))||`Task item checkbox for ${e.textContent||`empty task item`}`},zk=Jp.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51,contentElement:e=>e.querySelector(`div`)??e}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,A(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>op(e,t,`- [${e.attrs?.checked?`x`:` `}] `,void 0,{indentMainContent:!0}),addExtensions(){return this.options.nested?[IO(this.name,[this.options.taskListTypeName])]:[]},addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`);o.style.cssText=Lk;let l=e=>{let t=Rk(e,e.attrs.checked,this.options.a11y);s.setAttribute(`aria-label`,t),o.textContent=t};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=Lu(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[Gp({find:Ik,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),Bk=Jp.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(t){let r={type:`taskList`,raw:t.raw,items:t.items},i=e.slice(t.raw.length);return i.trim()?[r,...n.blockTokens(i)]:[r]}return n.blockTokens(e)},i=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Tp.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(MO.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(ok.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(hk.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(Fk.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(zk.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(Bk.configure(this.options.taskList)),e}});var Vk=` `,Hk=`\xA0`,Uk=Jp.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,A(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===Vk||n[0].text===Vk||n[0].raw===Hk||n[0].text===Hk)&&r.length===1&&r[0].type===`text`&&(r[0].text===Vk||r[0].text===Hk)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){var i,a;let e=Array.isArray(n==null||(i=n.previousNode)==null?void 0:i.content)?n.previousNode.content:[];return(n==null||(a=n.previousNode)==null?void 0:a.type)===`paragraph`&&e.length===0?Vk:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Wk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Gk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Kk=_p.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Hp({find:Wk,type:this.type})]},addPasteRules(){return[Yp({find:Gk,type:this.type})]}}),qk=Jp.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),Jk=_p.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,A(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`${t.renderChildren(e)}`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.toLowerCase().indexOf(``)},tokenize(e,t,n){if(!/^/i.test(e))return;let r=/\\[\s\S]|`+|<\/u>/gi;r.lastIndex=3;let i=r.exec(e);for(;i;){if(i[0].startsWith("`")){let t=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/.exec(e.slice(i.index));t&&(r.lastIndex=i.index+t[0].length)}else if(!i[0].startsWith(`\\`)){let t=e.slice(3,i.index);return t?{type:`underline`,raw:e.slice(0,r.lastIndex),text:t,tokens:n.inlineTokens(t)}:void 0}i=r.exec(e)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),Yk=Tp.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(LT.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(MT.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(MO.configure(this.options.bulletList)),this.options.code!==!1&&e.push(VT.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(GT.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(qT.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(Xw.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Zw.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(JT.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(YT.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(ST.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(XT.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(tE.configure(this.options.italic)),this.options.listItem!==!1&&e.push(ok.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(hk.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(OO.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(Fk.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Uk.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(Kk.configure(this.options.strike)),this.options.text!==!1&&e.push(qk.configure(this.options.text)),this.options.underline!==!1&&e.push(Jk.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(xT.configure(this.options?.trailingNode)),e}}),Xk=Math.min,Zk=Math.max,Qk=Math.round,$k=Math.floor,eA=e=>({x:e,y:e}),tA={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function nA(e,t,n){return Zk(e,Xk(t,n))}function rA(e,t){return typeof e==`function`?e(t):e}function iA(e){return e.split(`-`)[0]}function aA(e){return e.split(`-`)[1]}function oA(e){return e===`x`?`y`:`x`}function sA(e){return e===`y`?`height`:`width`}function cA(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function lA(e){return oA(cA(e))}function uA(e,t,n){n===void 0&&(n=!1);let r=aA(e),i=lA(e),a=sA(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=yA(o)),[o,yA(o)]}function dA(e){let t=yA(e);return[fA(e),t,fA(t)]}function fA(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var pA=[`left`,`right`],mA=[`right`,`left`],hA=[`top`,`bottom`],gA=[`bottom`,`top`];function _A(e,t,n){switch(e){case`top`:case`bottom`:return n?t?mA:pA:t?pA:mA;case`left`:case`right`:return t?hA:gA;default:return[]}}function vA(e,t,n,r){let i=aA(e),a=_A(iA(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(fA)))),a}function yA(e){let t=iA(e);return tA[t]+e.slice(t.length)}function bA(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function xA(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:bA(e)}function SA(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function CA(e,t,n){let{reference:r,floating:i}=e,a=cA(t),o=lA(t),s=sA(o),c=iA(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=aA(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function wA(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=rA(t,e),p=xA(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=SA(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=SA(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var TA=50,EA=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:wA},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=CA(l,r,c),f=r,p=0,m={};for(let n=0;ne<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===cA(t)||te.every(e=>cA(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:te},reset:{placement:t}};let n=te.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=te.filter(e=>{if(x){let t=cA(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},OA=new Set([`left`,`top`]);async function kA(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=iA(n),s=aA(n),c=cA(n)===`y`,l=OA.has(o)?-1:1,u=a&&c?-1:1,d=rA(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var AA=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await kA(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},jA=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=rA(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=cA(i),p=oA(f),m=u[p],h=u[f],g=(e,t)=>nA(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}};function MA(){return typeof window<`u`}function NA(e){return IA(e)?(e.nodeName||``).toLowerCase():`#document`}function PA(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function FA(e){return((IA(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function IA(e){return MA()?e instanceof Node||e instanceof PA(e).Node:!1}function LA(e){return MA()?e instanceof Element||e instanceof PA(e).Element:!1}function RA(e){return MA()?e instanceof HTMLElement||e instanceof PA(e).HTMLElement:!1}function zA(e){return!MA()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof PA(e).ShadowRoot}function BA(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=ZA(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function VA(e){return/^(table|td|th)$/.test(NA(e))}function HA(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var UA=/transform|translate|scale|rotate|perspective|filter/,WA=/paint|layout|strict|content/,GA=e=>!!e&&e!==`none`,KA;function qA(e){let t=LA(e)?ZA(e):e;return GA(t.transform)||GA(t.translate)||GA(t.scale)||GA(t.rotate)||GA(t.perspective)||!YA()&&(GA(t.backdropFilter)||GA(t.filter))||UA.test(t.willChange||``)||WA.test(t.contain||``)}function JA(e){let t=$A(e);for(;RA(t)&&!XA(t);){if(qA(t))return t;if(HA(t))return null;t=$A(t)}return null}function YA(){return KA??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),KA}function XA(e){return/^(html|body|#document)$/.test(NA(e))}function ZA(e){return PA(e).getComputedStyle(e)}function QA(e){return LA(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $A(e){if(NA(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||zA(e)&&e.host||FA(e);return zA(t)?t.host:t}function ej(e){let t=$A(e);return XA(t)?(e.ownerDocument||e).body:RA(t)&&BA(t)?t:ej(t)}function tj(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ej(e),i=r===e.ownerDocument?.body,a=PA(r);if(i){let e=nj(a);return t.concat(a,a.visualViewport||[],BA(r)?r:[],e&&n?tj(e):[])}return t.concat(r,tj(r,[],n))}function nj(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function rj(e){let t=ZA(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=RA(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Qk(n)!==a||Qk(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function ij(e){return LA(e)?e:e.contextElement}function aj(e){let t=ij(e);if(!RA(t))return eA(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=rj(t),o=(a?Qk(n.width):n.width)/r,s=(a?Qk(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var oj=eA(0);function sj(e){let t=PA(e);return!YA()||!t.visualViewport?oj:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function cj(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===PA(e)}function lj(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=ij(e),o=eA(1);t&&(r?LA(r)&&(o=aj(r)):o=aj(e));let s=cj(a,n,r)?sj(a):eA(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=PA(a),t=LA(r)?PA(r):r,n=e,i=nj(n);for(;i&&t!==n;){let e=aj(i),t=i.getBoundingClientRect(),r=ZA(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=PA(i),i=nj(n)}}return SA({width:u,height:d,x:c,y:l})}function uj(e,t){let n=QA(e).scrollLeft;return t?t.left+n:lj(FA(e)).left+n}function dj(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-uj(e,n),y:n.top+t.scrollTop}}function fj(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=FA(r),s=t?HA(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=eA(1),u=eA(0),d=RA(r);if((d||!a)&&((NA(r)!==`body`||BA(o))&&(c=QA(r)),d)){let e=lj(r);l=aj(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?dj(o,c):eA(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function pj(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function mj(e){let t=QA(e),n=e.ownerDocument.body,r=Zk(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Zk(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+uj(e),o=-t.scrollTop;return ZA(n).direction===`rtl`&&(a+=Zk(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var hj=25;function gj(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=PA(e),a=FA(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!YA()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(uj(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=hj&&(s-=o)}return{width:s,height:c,x:l,y:u}}function _j(e,t){let n=lj(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=aj(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function vj(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=gj(e,n,t);else if(t===`document`)r=mj(FA(e));else if(LA(t))r=_j(t,n);else{let n=sj(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return SA(r)}function yj(e,t){let n=t.get(e);if(n)return n;let r=tj(e,[],!1).filter(e=>LA(e)&&NA(e)!==`body`),i=null,a=ZA(e).position===`fixed`,o=a?$A(e):e;for(;LA(o)&&!XA(o);){let e=ZA(o),t=qA(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=$A(o)}return t.set(e,r),r}function bj(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?HA(t)?[]:yj(t,this._c):[].concat(n),r],o=vj(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=PA(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function jj(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=ij(e),u=i||a?[...l?tj(l):[],...t?tj(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Aj(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?lj(e):null;c&&g();function g(){let t=lj(e);h&&!kj(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Mj=AA,Nj=jA,Pj=DA,Fj=(e,t,n)=>{let r=new Map,i=n??{},a={...Oj,...i.platform,_c:r};return EA(e,t,{...i,platform:a})};function Ij(e,t){return typeof e==`boolean`?e:t}var Lj=KT.extend({addOptions(){return{...this.parent(),lineNumbers:!1}},addAttributes(){return{...this.parent?.(),lineNumbers:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-line-numbers`);return t===`true`||t!==`false`&&null},renderHTML:e=>typeof e.lineNumbers==`boolean`?{"data-line-numbers":String(e.lineNumbers)}:{}}}},addCommands(){return{...this.parent?.(),toggleCodeLineNumbers:()=>({editor:e,commands:t})=>{if(!e.isActive(this.name))return!1;let n=Ij(e.getAttributes(this.name).lineNumbers,this.options.lineNumbers);return t.updateAttributes(this.name,{lineNumbers:!n})}}},addNodeView(){let e=this.options.lineNumbers,t=this.options.languageClassPrefix??`language-`;return({node:n})=>{let r=document.createElement(`pre`);r.className=`dw-code`;let i=document.createElement(`div`);i.className=`dw-code__gutter`,i.contentEditable=`false`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`code`);r.append(i,a);let o=-1,s=n=>{let s=Ij(n.attrs.lineNumbers,e);r.classList.toggle(`dw-code--numbered`,s),a.className=n.attrs.language?`${t}${String(n.attrs.language)}`:``;let c=s?n.textContent.split(` `).length:0;c!==o&&(o=c,i.textContent=Array.from({length:c},(e,t)=>t+1).join(` -`))};return s(n),{dom:r,contentDOM:a,update:e=>e.type===n.type&&(s(e),!0),ignoreMutation:e=>i.contains(e.target)}}}}),Fj=(e,t)=>e===`application/pdf`||typeof t==`string`&&/\.pdf$/i.test(t);function Ij(e,t,n,r){let i=!1,a=null,o=null,s=document.createElement(`div`);return s.className=`dw-pdf__status`,s.textContent=r.blocks.pdfLoading,e.replaceChildren(s),(async()=>{try{let c=await n();if(i)return;o=c.getDocument({url:t});let l=await o.promise;if(i)return;s.remove();let u=Math.max(e.clientWidth-2,200),d=window.devicePixelRatio||1;a=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target;a?.unobserve(e),p(e,Number(e.dataset.page))}},{root:e,rootMargin:`400px 0px`});let f=(await l.getPage(1)).getViewport({scale:1});for(let t=1;t<=l.numPages;t++){let n=document.createElement(`div`);n.className=`dw-pdf__page`,n.dataset.page=String(t),n.style.aspectRatio=`${f.width} / ${f.height}`,n.setAttribute(`aria-label`,r.blocks.pdfPage.replace(`{n}`,String(t))),e.append(n),a.observe(n)}async function p(e,t){let n=await l.getPage(t);if(i)return;let r=u/n.getViewport({scale:1}).width,a=n.getViewport({scale:r*d}),o=document.createElement(`canvas`);o.width=Math.floor(a.width),o.height=Math.floor(a.height),e.style.aspectRatio=`${a.width} / ${a.height}`,e.append(o),await n.render({canvas:o,viewport:a}).promise}}catch{i||(s.textContent=r.blocks.loadFailed)}})(),()=>{i=!0,a?.disconnect(),o?.destroy()}}var Lj={page:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M9 12h6`,`M9 16h6`],"chevron-right":[`M10 6l6 6-6 6`],"chevron-left":[`M14 6l-6 6 6 6`],"chevron-down":[`M6 10l6 6 6-6`],"chevron-up":[`M6 14l6-6 6 6`],plus:[`M12 5v14`,`M5 12h14`],search:[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`],more:[`M6 12h.01`,`M12 12h.01`,`M18 12h.01`],drop:[`M12 4h7v7a7 7 0 1 1-7-7z`],info:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 11v5`,`M12 8h.01`],check:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8 12.5l2.5 2.5L16 9.5`],alert:[`M12 4l9 16H3z`,`M12 10v4`,`M12 17h.01`],error:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M9 9l6 6`,`M15 9l-6 6`],text:[`M5 6h14`,`M12 6v13`],heading:[`M6 5v14`,`M18 5v14`,`M6 12h12`],list:[`M9 6h11`,`M9 12h11`,`M9 18h11`,`M4.5 6h.01`,`M4.5 12h.01`,`M4.5 18h.01`],todo:[`M4 4h7v7H4z`,`M5.5 7.5l1.5 1.5 2.5-2.5`,`M14 7h6`,`M4 14h7v7H4z`,`M14 17h6`],code:[`M9 7l-5 5 5 5`,`M15 7l5 5-5 5`],quote:[`M6 6v12`,`M10 8h9`,`M10 12h9`,`M10 16h6`],image:[`M4 5h16v14H4z`,`M4 16l5-5 4 4 2-2 5 5`,`M15.5 8.5h.01`],table:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 5v14`],lock:[`M6 11h12v9H6z`,`M8.5 11V8a3.5 3.5 0 0 1 7 0v3`],trash:[`M4 7h16`,`M10 4h4`,`M6 7l1 13h10l1-13`,`M10 11v6`,`M14 11v6`],settings:[`M4 7h9`,`M17 7h3`,`M15 5v4`,`M4 17h3`,`M11 17h9`,`M9 15v4`],menu:[`M4 7h16`,`M4 12h16`,`M4 17h16`],close:[`M6 6l12 12`,`M18 6L6 18`],open:[`M8 16L16 8`,`M9 8h7v7`],restore:[`M4.5 13a7.5 7.5 0 1 0 2.2-6.3`,`M5 4v4h4`],"sign-out":[`M14 4h5v16h-5`,`M10 8l-4 4 4 4`,`M6 12h9`],sidebar:[`M4 5h16v14H4z`,`M9.5 5v14`],home:[`M4 11l8-7 8 7`,`M6 9.5V20h12V9.5`,`M10 20v-5h4v5`],sun:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M12 3v1.5`,`M12 19.5V21`,`M3 12h1.5`,`M19.5 12H21`,`M5.6 5.6l1.1 1.1`,`M17.3 17.3l1.1 1.1`,`M5.6 18.4l1.1-1.1`,`M17.3 6.7l1.1-1.1`],moon:[`M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z`],monitor:[`M4 5h16v11H4z`,`M9 20h6`,`M12 16v4`],selector:[`M8 9l4-4 4 4`,`M8 15l4 4 4-4`],star:[`M12 4l2.5 5.2 5.5.8-4 3.9.9 5.6L12 16.9l-4.9 2.6.9-5.6-4-3.9 5.5-.8z`],clock:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 7v5l3 2`],calendar:[`M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z`,`M4 10h16`,`M8 3v4`,`M16 3v4`],share:[`M12 4v11`,`M8 8l4-4 4 4`,`M6 13v7h12v-7`],link:[`M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1`,`M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1`],upload:[`M12 16V4`,`M7 9l5-5 5 5`,`M4 20h16`],download:[`M12 4v12`,`M7 11l5 5 5-5`,`M4 20h16`],file:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`],paperclip:[`M18 11.5l-6.4 6.4a4.2 4.2 0 0 1-6-6l7-7a2.8 2.8 0 0 1 4 4l-7 7a1.4 1.4 0 0 1-2-2l6.4-6.4`],comment:[`M5 5h14v10H9l-4 4z`],at:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1`],bold:[`M7 5h6a3.5 3.5 0 0 1 0 7H7z`,`M7 12h7a3.5 3.5 0 0 1 0 7H7z`],italic:[`M10 5h8`,`M6 19h8`,`M14 5l-4 14`],strike:[`M5 12h14`,`M16 7.5A3.5 3 0 0 0 12.5 5h-1A3.5 3 0 0 0 8 8c0 4 8 3 8 7.5a3.5 3.5 0 0 1-3.5 3.5h-1A3.5 3 0 0 1 8 16.5`],underline:[`M7 4v7a5 5 0 0 0 10 0V4`,`M5 20h14`],"list-ordered":[`M10 6h10`,`M10 12h10`,`M10 18h10`,`M4 5l1.5-1v5`,`M4 15.5a1.5 1.5 0 0 1 3 .5L4 19h3`],divider:[`M4 12h16`],globe:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M3 12h18`,`M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9`,`M12 3C9.5 5.5 8.5 8.5 8.5 12s1 6.5 3.5 9`],bell:[`M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z`,`M10 20a2 2 0 0 0 4 0`],"bell-off":[`M6 16V11a6 6 0 0 1 9.5-4.9`,`M18 11v5l1.5 2H8`,`M10 20a2 2 0 0 0 4 0`,`M4 4l16 16`],smile:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8.5 14a4 4 0 0 0 7 0`,`M9 9.5h.01`,`M15 9.5h.01`],reply:[`M9 7L4 12l5 5`,`M4 12h10a6 6 0 0 1 6 6v1`],pencil:[`M15 5l4 4L8 20H4v-4z`],sigma:[`M18 6V4H6l6 8l-6 8h12v-2`],diagram:[`M4 4h6v5H4z`,`M14 15h6v5h-6z`,`M7 9v4a2 2 0 0 0 2 2h5`],video:[`M4 6h11v12H4z`,`M15 10l5-3v10l-5-3`],archive:[`M4 5h16v4H4z`,`M5 9v10h14V9`,`M10 13h4`],pin:[`M9 4h6`,`M10 4v6l-3 4h10l-3-4V4`,`M12 14v6`],width:[`M3 12h18`,`M7 8l-4 4 4 4`,`M17 8l4 4-4 4`],type:[`M5 7V5h14v2`,`M12 5v14`,`M9 19h6`],server:[`M4 4h16v6H4z`,`M4 14h16v6H4z`,`M8 7h.01`,`M8 17h.01`],users:[`M9 11a3.5 3.5 0 1 0 0-7a3.5 3.5 0 1 0 0 7z`,`M3 20a6 6 0 0 1 12 0`,`M16 4.5a3.5 3.5 0 0 1 0 6.5`,`M18 14a6 6 0 0 1 3 6`],"align-left":[`M4 6h16`,`M4 10h10`,`M4 14h16`,`M4 18h10`],"align-center":[`M4 6h16`,`M7 10h10`,`M4 14h16`,`M7 18h10`],"align-right":[`M4 6h16`,`M10 10h10`,`M4 14h16`,`M10 18h10`],grip:[`M9 6h.01`,`M15 6h.01`,`M9 12h.01`,`M15 12h.01`,`M9 18h.01`,`M15 18h.01`],copy:[`M9 9h11v11H9z`,`M5 15H4V4h11v1`],"arrow-up":[`M12 19V5`,`M6 11l6-6 6 6`],"arrow-down":[`M12 5v14`,`M6 13l6 6 6-6`],callout:[`M4 5h16v14H4z`,`M8 10h.01`,`M11 10h5`,`M8 14h8`],palette:[`M12 3a9 9 0 1 0 0 18c1 0 1.5-.7 1.5-1.5 0-1.2-1-1.5-1-2.5s.8-1.5 2-1.5H17a4 4 0 0 0 4-4c0-4.7-4-8.5-9-8.5z`,`M7.5 11h.01`,`M10 7.5h.01`,`M14.5 7.5h.01`],"page-plus":[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M12 11v6`,`M9 14h6`],tag:[`M4 4h7l9 9-7 7-9-9z`,`M8 8h.01`],grid:[`M4 4h7v7H4z`,`M13 4h7v7h-7z`,`M4 13h7v7H4z`,`M13 13h7v7h-7z`],cards:[`M4 5h16v6H4z`,`M4 15h16v4H4z`],filter:[`M4 5h16l-6 8v6l-4-2v-4z`],layers:[`M12 4l8 4-8 4-8-4z`,`M4 12l8 4 8-4`,`M4 16l8 4 8-4`],journal:[`M6 3h11a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6z`,`M9 3v18`,`M12 8h3`,`M12 12h3`],sliders:[`M5 6h14`,`M5 12h14`,`M5 18h14`,`M9 4v4`,`M15 10v4`,`M11 16v4`],sort:[`M7 4v16`,`M4 7l3-3 3 3`,`M17 20V4`,`M14 17l3 3 3-3`],database:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 10v9`],relation:[`M3 6h7v5H3z`,`M14 13h7v5h-7z`,`M10 8.5h2.5a2 2 0 0 1 2 2V13`],rollup:[`M4 5h16`,`M4 9h16`,`M4 13h16`,`M12 16v5`,`M9 18l3 3 3-3`],edgeless:[`M4 5h16v14H4z`,`M7 15l3-4 3 3 4-5`,`M7 8.5h.01`],cursor:[`M6 4l12 7-5.5 1.5L10 18z`],hand:[`M8 13V6.5a1.5 1.5 0 0 1 3 0V12`,`M11 11V5a1.5 1.5 0 0 1 3 0v6`,`M14 11V6.5a1.5 1.5 0 0 1 3 0V14a6 6 0 0 1-6 6h-1a5 5 0 0 1-4.2-2.3L4.5 14a1.5 1.5 0 0 1 2.5-1.6L8 14`],note:[`M5 4h14v10l-6 6H5z`,`M13 20v-6h6`],shapes:[`M4 13h7v7H4z`,`M16.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M7.5 4l3.5 6H4z`],connector:[`M5 19a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M19 9a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M6.5 15.5C9 10 13 13 17.5 8.5`],pen:[`M4 20l1-4L16 5l3 3L8 19z`,`M14 7l3 3`],eraser:[`M8 20h12`,`M4.5 15.5l9-9 6 6-7.5 7.5H9z`,`M9 11l5 5`],frame:[`M7 3v18`,`M17 3v18`,`M3 7h18`,`M3 17h18`],mindmap:[`M10 10h4v4h-4z`,`M3 4h4v3H3z`,`M17 4h4v3h-4z`,`M3 17h4v3H3z`,`M17 17h4v3h-4z`,`M7 6l3 4`,`M17 6l-3 4`,`M7 18l3-4`,`M17 18l-3-4`],sticker:[`M12 3a9 9 0 1 0 9 9h-5a4 4 0 0 1-4-4z`,`M12 3a9 9 0 0 1 9 9`,`M9 14.5c1.5 1.5 4.5 1.5 6 0`],present:[`M3 4h18`,`M5 4v11h14V4`,`M12 15v3`,`M8 21l4-3 4 3`],"zoom-in":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`,`M11 8v6`],"zoom-out":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`],fit:[`M4 9V4h5`,`M15 4h5v5`,`M20 15v5h-5`,`M9 20H4v-5`],"send-back":[`M4 12h9v8H4z`,`M11 4h9v8h-9z`],group:[`M4 4h3`,`M10 4h4`,`M17 4h3v3`,`M20 10v4`,`M20 17v3h-3`,`M14 20h-4`,`M7 20H4v-3`,`M4 14v-4`,`M8 8h8v8H8z`]},Rj=`http://www.w3.org/2000/svg`;function zj(e,t=18){let n=document.createElementNS(Rj,`svg`);for(let[e,r]of Object.entries({width:String(t),height:String(t),viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`}))n.setAttribute(e,r);for(let t of Lj[e]){let e=document.createElementNS(Rj,`path`);e.setAttribute(`d`,t),n.append(e)}return n}function Bj(e){return()=>{let t=null,n=null,r=null,i=0,a=null,o=()=>a?.items??r?.items??[],s=t=>{let n=o()[t];if(!r||n===void 0)return;let s=e.children?.(n);s?.length?(a={parent:n,items:s},i=0,c()):e.pick(r,n)},c=()=>{if(!t||!r)return;let n=r;if(t.replaceChildren(),e.showQuery){let e=document.createElement(`div`);e.className=`dw-suggest__query`,e.textContent=`/${n.query}`,t.append(e)}if(a){let n=document.createElement(`div`);n.className=`dw-suggest__query`,n.textContent=`‹ ${e.toItem(a.parent).label}`,t.append(n)}let c=o();if(c.length)c.forEach((n,r)=>{let a=e.toItem(n),o=document.createElement(`div`);o.className=r===i?`dw-suggest__item is-active`:`dw-suggest__item`,o.setAttribute(`role`,`option`),o.setAttribute(`aria-selected`,String(r===i)),o.addEventListener(`mousedown`,e=>{e.preventDefault(),s(r)});let c=document.createElement(`span`);c.className=`dw-suggest__icon`,c.append(zj(a.icon??`text`));let l=document.createElement(`span`);l.className=`dw-suggest__text`;let u=document.createElement(`span`);if(u.className=`dw-suggest__label`,u.textContent=a.label,l.append(u),a.description){let e=document.createElement(`span`);e.className=`dw-suggest__desc`,e.textContent=a.description,l.append(e)}if(o.append(c,l),e.children?.(n)?.length){o.setAttribute(`aria-haspopup`,`listbox`);let e=zj(`chevron-right`,14);e.classList.add(`dw-suggest__more`),o.append(e)}t.append(o)}),t.querySelector(`.is-active`)?.scrollIntoView({block:`nearest`});else{let n=document.createElement(`div`);n.className=`dw-suggest__empty`,n.setAttribute(`role`,`status`),n.textContent=e.empty,t.append(n)}},l=()=>{let e=r?.clientRect?.();if(!t||!e)return;let i={getBoundingClientRect:()=>r?.clientRect?.()??e};n?.(),n=Oj(i,t,()=>{t&&Mj(i,t,{placement:`bottom-start`,strategy:`fixed`,middleware:[kj(6),jj(),Aj({padding:8})]}).then(({x:e,y:n})=>{t&&Object.assign(t.style,{left:`${e}px`,top:`${n}px`})})})},u=()=>{n?.(),n=null,t?.remove(),t=null};return{onStart(n){r=n,i=0,a=null,t=document.createElement(`div`),t.className=`dw-suggest`,t.setAttribute(`role`,`listbox`),t.setAttribute(`aria-label`,e.label),document.body.append(t),c(),l()},onUpdate(e){e.items!==r?.items&&(i=0,a=null),r=e,c(),l()},onKeyDown({event:t}){let n=o().length;if(a&&(t.key===`Escape`||t.key===`ArrowLeft`))return a=null,i=0,c(),!0;let r=o()[i];return t.key===`ArrowRight`&&r!==void 0&&e.children?.(r)?.length?(s(i),!0):t.key===`Escape`?(u(),!0):n?t.key===`ArrowDown`||t.key===`ArrowUp`?(i=(i+(t.key===`ArrowDown`?1:-1)+n)%n,c(),!0):t.key===`Enter`||t.key===`Tab`?(s(i),!0):!1:!1},onExit(){r=null,u()}}}}var Vj=[[`text`,`text`,e=>e],[`h1`,`heading`,e=>e.setNode(`heading`,{level:1})],[`h2`,`heading`,e=>e.setNode(`heading`,{level:2})],[`h3`,`heading`,e=>e.setNode(`heading`,{level:3})],[`bullet`,`list`,e=>e.toggleBulletList()],[`ordered`,`list-ordered`,e=>e.toggleOrderedList()],[`todo`,`todo`,e=>e.toggleTaskList()],[`quote`,`quote`,e=>e.setBlockquote()],[`code`,`code`,e=>e.setCodeBlock()],[`callout`,`callout`,e=>e.setCallout()]],Hj=[`paragraph`,`heading`,`codeBlock`,`blockquote`,`bulletList`,`orderedList`,`taskList`,`callout`];function Uj(e){let t={...e};return t.attrs&&`blockId`in t.attrs&&(t.attrs={...t.attrs,blockId:null}),t.content&&=t.content.map(Uj),t}function Wj(e,t,n,r){let i=e.state.doc.nodeAt(t);if(!i)return[];let a=n.blockMenu,o=t+i.nodeSize,c=e.state.doc.resolve(t).index(0),l=[];if(Hj.includes(i.type.name)&&l.push({id:`turnInto`,label:a.turnInto,icon:`text`,children:Vj.map(([r,a,c])=>({id:r,icon:a,label:n.slash[r]?.label??r,run:()=>{if(r===`callout`){if(i.type.name===`callout`)return;let n=i.type.name===`blockquote`?i.content:s.from(i),r=e.schema.nodes.callout.create(null,n),a=e.state.tr.replaceWith(t,o,r);e.view.dispatch(a.setSelection(w.near(a.doc.resolve(t+1))).scrollIntoView()),e.commands.focus();return}let n=e.state.doc,a=w.findFrom(n.resolve(t),1,!0)?.from??t+1,l=w.findFrom(n.resolve(o),-1,!0)?.to??o-1;c(e.chain().focus().setTextSelection({from:a,to:l}).clearNodes()).run()}}))}),[`bulletList`,`orderedList`,`taskList`].includes(i.type.name)&&l.push({id:`groupAsDatabase`,label:n.database.groupAsDatabase,icon:`database`,run:()=>{e.chain().focus().setTextSelection(t+2).groupAsDatabase().run()}}),i.type.name===`codeBlock`){let n=!!e.extensionManager.extensions.find(e=>e.name===`codeBlock`)?.options.lineNumbers,r=Nj(i.attrs.lineNumbers,n);l.push({id:`lineNumbers`,label:r?a.hideLineNumbers:a.showLineNumbers,icon:`list-ordered`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`lineNumbers`,!r))})}if(i.type.name===`fileAttachment`&&Fj(i.attrs.mime,i.attrs.name)){let n=i.attrs.view===`preview`;l.push({id:`pdfView`,label:n?a.showAsFile:a.showPages,icon:n?`paperclip`:`file`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`view`,n?`card`:`preview`))})}return c>0&&l.push({id:`moveUp`,label:a.moveUp,icon:`arrow-up`,run:()=>{let n=e.state.doc.child(c-1),r=e.state.tr.delete(t,o).insert(t-n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),c{let n=e.state.doc.child(c+1),r=e.state.tr.delete(t,o).insert(t+n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),l.push({id:`duplicate`,label:a.duplicate,icon:`plus`,run:()=>{let t=e.schema.nodeFromJSON(Uj(i.toJSON()));e.view.dispatch(e.state.tr.insert(o,t).scrollIntoView())}},{id:`copy`,label:a.copy,icon:`copy`,run:()=>{e.chain().focus().setNodeSelection(t).run(),document.execCommand(`copy`)}}),r&&l.push({id:`copyLink`,label:n.blocks.copyBlockLink,icon:`link`,run:r}),l.push({id:`delete`,label:a.delete,icon:`trash`,danger:!0,run:()=>{e.view.dispatch(e.state.tr.delete(t,o)),e.commands.focus()}}),l}function Gj(e,t,n,r){let i=document.createElement(`div`);i.className=`dw-suggest dw-block-menu`,i.setAttribute(`role`,`menu`),i.setAttribute(`aria-label`,n);let a=t,o=0,s=[],c=()=>{i.replaceChildren(),a.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`dw-suggest__item${t===o?` is-active`:``}${e.danger?` is-danger`:``}`,n.setAttribute(`role`,`menuitem`),n.tabIndex=-1,e.children&&n.setAttribute(`aria-haspopup`,`menu`);let r=document.createElement(`span`);r.className=`dw-suggest__icon`,r.append(zj(e.icon));let a=document.createElement(`span`);if(a.className=`dw-suggest__label`,a.textContent=e.label,n.append(r,a),e.children){let e=zj(`chevron-right`,14);e.classList.add(`dw-block-menu__more`),n.append(e)}n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>l(t)),n.addEventListener(`mouseenter`,()=>{o=t;for(let[e,n]of[...i.children].entries())n.classList.toggle(`is-active`,e===t)}),i.append(n)}),i.children[o]?.focus()},l=e=>{let t=a[e];t&&(t.children?(s.push(a),a=t.children,o=0,c()):(m(),t.run?.()))},u=e=>{e.key===`Escape`||e.key===`ArrowLeft`&&s.length?(e.preventDefault(),e.stopPropagation(),s.length?(a=s.pop(),o=0,c()):m()):e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),o=(o+(e.key===`ArrowDown`?1:-1)+a.length)%a.length,c()):(e.key===`Enter`||e.key===` `||e.key===`ArrowRight`)&&(e.preventDefault(),(e.key!==`ArrowRight`||a[o]?.children)&&l(o))},d=t=>{!i.contains(t.target)&&!e.contains(t.target)&&m()};document.body.append(i);let f=Oj(e,i,()=>{Mj(e,i,{placement:`bottom-start`,strategy:`fixed`,middleware:[kj(4),jj(),Aj({padding:8})]}).then(({x:e,y:t})=>Object.assign(i.style,{left:`${e}px`,top:`${t}px`}))});i.addEventListener(`keydown`,u),document.addEventListener(`mousedown`,d,!0);let p=!1;function m(){p||(p=!0,f(),i.remove(),document.removeEventListener(`mousedown`,d,!0),s=[],r?.())}return c(),m}var Kj=[`paragraph`,`heading`,`blockquote`,`codeBlock`,`bulletList`,`orderedList`,`taskList`,`callout`,`table`,`details`,`image`,`embed`,`linkCard`,`mermaid`,`blockMath`,`drawio`,`excalidraw`,`fileAttachment`],qj=/^[a-z0-9]{6,16}$/;function Jj(e){return/^#?b-([a-z0-9]{6,16})$/.exec(e)?.[1]??``}var Yj=e=>`#b-${e}`;function Xj(){return[...crypto.getRandomValues(new Uint8Array(8))].map(e=>(e%36).toString(36)).join(``)}function Zj(e,t){let n=e.state.doc.nodeAt(t);if(!n)return null;let r=n.attrs.blockId;if(r)return r;if(!e.editable||!Kj.includes(n.type.name))return null;let i=Xj();return e.dispatch(e.state.tr.setNodeAttribute(t,`blockId`,i)),i}async function Qj(e,t,n,r){let i=Zj(e,t);if(!i)return!1;let a=n(Yj(i));try{await navigator.clipboard.writeText(a),r?.(a)}catch{window.prompt(``,a)}return!0}function $j(e,t){let n=-1;return e.descendants((e,r)=>n>=0?!1:(e.attrs.blockId===t&&(n=r),!0)),n}function eM(e,t){let n=$j(e.state.doc,t);if(n<0)return!1;let r=e.view.nodeDOM(n);if(!(r instanceof HTMLElement))return!1;r.scrollIntoView({block:`center`});let i=getComputedStyle(r).getPropertyValue(`--color-selection`).trim()||`rgba(47,125,109,.25)`;return r.animate?.([{backgroundColor:i},{backgroundColor:`transparent`}],{duration:2e3,easing:`ease-out`}),!0}var tM=Tp.create({name:`blockLinks`,addOptions(){return{labels:null,link:void 0,onCopied:void 0}},addGlobalAttributes(){return[{types:Kj,attributes:{blockId:{default:null,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-block-id`);return t&&qj.test(t)?t:null},renderHTML:e=>e.blockId?{"data-block-id":e.blockId}:{}}}}]},addKeyboardShortcuts(){let{link:e,onCopied:t}=this.options;return{"Mod-Shift-c":({editor:n})=>{if(!e)return!1;let r=n.state.selection.$from;if(r.depth<1)return!1;let i=r.before(1),a=n.state.doc.nodeAt(i);return!a||!Kj.includes(a.type.name)||!a.attrs.blockId&&!n.isEditable?!1:(Qj(n.view,i,e,t),!0)}}},addProseMirrorPlugins(){let{link:e,onCopied:t}=this.options,n=this.options.labels,r=this.editor;return[new D({key:new Un(`blockLinks`),view:i=>new iM(i,r,n,e,t)})]}}),nM=``,rM=``,iM=class{view;editor;labels;link;onCopied;gutter=document.createElement(`div`);linkButton=document.createElement(`button`);grip=document.createElement(`button`);pos=-1;closeMenu=null;constructor(e,t,n,r,i){this.view=e,this.editor=t,this.labels=n,this.link=r,this.onCopied=i;let a=this.gutter;a.className=`dw-block-gutter`,a.contentEditable=`false`,a.hidden=!0,a.addEventListener(`mouseleave`,this.leave);let o=this.linkButton;o.type=`button`,o.className=`dw-block-handle`,o.setAttribute(`aria-label`,n.blocks.copyBlockLink),o.title=n.blocks.copyBlockLink,o.innerHTML=nM,o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>void this.copy());let s=this.grip;s.type=`button`,s.className=`dw-block-handle dw-block-grip`,s.setAttribute(`aria-label`,n.blockMenu.open),s.setAttribute(`aria-haspopup`,`menu`),s.setAttribute(`aria-expanded`,`false`),s.title=n.blockMenu.open,s.innerHTML=rM,s.draggable=!0,s.addEventListener(`click`,this.openMenu),s.addEventListener(`dragstart`,this.dragStart),s.addEventListener(`dragend`,()=>this.hide()),r&&a.append(o),a.append(s),e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.gutter.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.gutter)),e}hide=()=>{this.closeMenu||(this.gutter.hidden=!0,this.pos=-1)};leave=e=>{let t=e.relatedTarget;t&&(this.gutter.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.closeMenu)return;let t=e.target;for(;t&&t.parentElement!==this.view.dom;)t=t.parentElement;let n=this.host;if(!t||!n)return this.hide();let r;try{r=this.view.posAtDOM(t,0)}catch{return this.hide()}let i=this.view.state.doc.resolve(Math.min(r,this.view.state.doc.content.size)),a=i.depth>=1?i.before(1):r,o=this.view.state.doc.nodeAt(a);if(!o)return this.hide();let s=!!this.link&&Kj.includes(o.type.name)&&(!!o.attrs.blockId||this.view.editable),c=this.view.editable;if(!s&&!c)return this.hide();this.linkButton.hidden=!s,this.grip.hidden=!c,this.pos=a;let l=t.getBoundingClientRect(),u=n.getBoundingClientRect();this.gutter.style.top=`${l.top-u.top+Math.min(l.height/2,14)-11}px`,this.gutter.hidden=!1};openMenu=()=>{if(this.closeMenu){this.closeMenu();return}let e=this.pos;if(e<0||!this.view.editable)return;let t=this.view.state.doc.nodeAt(e),n=!!this.link&&!!t&&Kj.includes(t.type.name),r=Wj(this.editor,e,this.labels,n?()=>void this.copy(e):void 0);this.grip.setAttribute(`aria-expanded`,`true`),this.closeMenu=Gj(this.grip,r,this.labels.blockMenu.open,()=>{this.closeMenu=null,this.grip.setAttribute(`aria-expanded`,`false`),this.hide()})};dragStart=e=>{let t=this.pos;if(t<0||!e.dataTransfer)return;this.closeMenu?.();let n=E.create(this.view.state.doc,t);this.view.dispatch(this.view.state.tr.setSelection(n)),e.dataTransfer.effectAllowed=`copyMove`,e.dataTransfer.setData(`text/plain`,n.node.textContent);let r=this.view.nodeDOM(t);r instanceof HTMLElement&&e.dataTransfer.setDragImage(r,0,0),this.view.dragging={slice:n.content(),move:!0}};async copy(e=this.pos){e>=0&&this.link&&await Qj(this.view,e,this.link,this.onCopied)}update(){this.pos>=this.view.state.doc.content.size&&this.hide()}destroy(){this.closeMenu?.(),this.gutter.parentElement?.classList.remove(`dw-block-host`),this.gutter.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}},aM,oM;if(typeof WeakMap<`u`){let e=new WeakMap;aM=t=>e.get(t),oM=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;aM=t=>{for(let n=0;n(t==10&&(t=0),e[t++]=n,e[t++]=r)}var sM=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;er&&(a+=i.attrs.colspan)}}for(let e=0;e1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function uM(e,t,n){e.problems||=[];let r={};for(let i=0;i0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function hM(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function gM(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function _M(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=mM(t.$head)||vM(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function vM(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function yM(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function bM(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function xM(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function SM(e,t,n){let r=e.node(-1),i=sM.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function CM(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function wM(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;ee!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Sn(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(yM(r)&&yM(i)&&xM(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return T.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=sM.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n0||u>0){let e=c.attrs;if(l>0&&(e=CM(e,0,l)),u>0&&(e=CM(e,e.colspan-u,u)),s.leftr.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=sM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom0&&(n=c.resolve(a+i.map[s.left])),o.bottom0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=sM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right{t.push(vs.node(n,n+e.nodeSize,{class:`selectedCell`}))}),xs.create(e.doc,t)}function kM({$from:e,$to:t}){if(e.pos==t.pos||e.pos=0&&!(e.after(i+1)=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function AM({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function jM(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof E&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=EM.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=EM.rowSelection(e,e)}else if(!n){let e=sM.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=EM.create(i,t+1,n)}}else r instanceof T&&kM(r)?a=T.create(i,r.from):r instanceof T&&AM(r)&&(a=T.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var MM=new Un(`fix-tables`);function NM(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o{t.type.spec.tableRole==`table`&&(n=FM(e,t,r,n))};return t?t.doc!=e.doc&&NM(t.doc,e.doc,0,r):e.doc.descendants(r),n}function FM(e,t,n,r){let i=sM.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n0?-1:0;TM(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o0&&i0&&t.map[s-1]==c||i0?-1:0;HM(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a0&&i0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i0&&n[a]==n[a-1]||r.right0&&n[i]==n[i-e]||r.bottom0){let e=c+1+l.content.size,t=JM(l)?c+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new EM(n.doc.resolve(c+r.tableStart))),t(n)}return!0}function ZM(e,t){let n=fM(e.schema);return QM(({node:e})=>n[e.type.spec.tableRole])(e,t)}function QM(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof EM){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=hM(r.$from),!i)return!1;a=mM(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=IM(t),u=t.tr;for(let e=0;e{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function eN(e){return function(t,n){if(!gM(t))return!1;if(n){let r=fM(t.schema),i=IM(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}nN(`row`,{useDeprecatedLogic:!0}),nN(`column`,{useDeprecatedLogic:!0});var rN=nN(`cell`,{useDeprecatedLogic:!0});function iN(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function sN(e,t){let n=e.selection;if(!(n instanceof EM))return!1;if(t){let r=e.tr,i=fM(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new p(i,0,0))}),r.docChanged&&t(r)}return!0}function cN(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t=t.length&&t.push(s.empty),n[i]r&&(s=s.type.createChecked(CM(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;ni&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(s.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function fN(e,t,n,r,i,a,o){let c=e.doc.type.schema,l=fM(c),u,d;if(i>t.width)for(let a=0,s=0;at.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e=t.width?!1:n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?d||=l.header_cell.createAndFill():u||=l.cell.createAndFill())}let f=l.row.create(null,s.from(c)),p=[];for(let e=t.height;e{if(!i)return!1;let a=n.selection;if(a instanceof EM)return _N(n,r,w.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=CN(i,e,t);if(o==null)return!1;if(e==`horiz`)return _N(n,r,w.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=SM(i,e,t),s;return s=a?w.near(a,1):t<0?w.near(n.doc.resolve(i.before(-1)),-1):w.near(n.doc.resolve(i.after(-1)),1),_N(n,r,s)}}}function yN(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof EM)o=a;else{let r=CN(i,e,t);if(r==null)return!1;o=new EM(n.doc.resolve(r))}let s=SM(o.$headCell,e,t);return s?_N(n,r,new EM(o.$anchorCell,s)):!1}}function bN(e,t){let n=e.state.doc,r=mM(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new EM(r))),!0):!1}function xN(e,t,n){if(!gM(e.state))return!1;let r=cN(n),i=e.state.selection;if(i instanceof EM){r||={width:1,height:1,rows:[s.from(uN(fM(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=sM.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=dN(r,o.right-o.left,o.bottom-o.top),hN(e.state,e.dispatch,a,o,r),!0}if(r){let t=_M(e.state),n=t.start(-1);return hN(e.state,e.dispatch,n,sM.get(t.node(-1)).findCell(t.pos-n),r),!0}return!1}function SN(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=wN(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof EM)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=mM(e.state.selection.$anchor))!=null&&TN(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=TN(e,n),i=pM.getState(e.state)==null;if(!r||!xM(t,r)){if(i)r=t;else return}let a=new EM(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(pM,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),pM.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(pM,-1))}function o(r){let o=r,s=pM.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(wN(e,o.target)!=n&&(c=TN(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function CN(e,t,n){if(!(e.state.selection instanceof T))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function wN(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function TN(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&mM(e.state.doc.resolve(r))||mM(e.state.doc.resolve(i))}var EN=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),DN(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type&&(this.node=e,DN(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function DN(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;enew r(e,n,t)),new AN(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=ON.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{jN(t,n,e,i)},mouseleave:e=>{MN(e)},mousedown:(e,r)=>{NN(e,r,t,n)}},decorations:e=>{let t=ON.getState(e);if(t&&t.activeHandle>-1)return HN(e,t.activeHandle)},nodeViews:{}}});return a}var AN=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(ON);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return yM(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function jN(e,t,n,r){if(!e.editable)return;let i=ON.getState(e.state);if(i&&!i.dragging){let a=FN(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=IN(e,t,`left`,n):i-t.clientX<=n&&(o=IN(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=sM.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}RN(e,o)}}}function MN(e){if(!e.editable)return;let t=ON.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&RN(e,-1)}function NN(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=ON.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=PN(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(ON,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=ON.getState(e.state);r?.dragging&&(zN(e,r.activeHandle,LN(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(ON,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=ON.getState(e.state);if(i&&i.dragging){let a=LN(i.dragging,t,n);BN(e,i.activeHandle,a,r)}}return BN(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function PN(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;eGN(e),renderHTML:e=>{let t=WN(e.align);return Pf(t)?{style:`text-align: ${t}`}:{}}}}function JN(e){let t=e.parentElement,n=e.closest(`table`);if(!t||!n)return null;let r=Array.from(t.children).indexOf(e),i=n.querySelectorAll(`colgroup > col`)[r]?.getAttribute(`width`);return i?[parseInt(i,10)]:null}function YN(e){let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):JN(e)}var XN=/[ \t\r\n\f]+/g;function ZN(e){return e.children.length>0?!1:(e.textContent??``).replace(XN,``)===``}function QN(e){let t=e.createAndFill();if(!t)throw Error(`[tiptap error]: "${e.name}" has no default content to backfill.`);return t.content}function $N(e,t,n){if(!(n in t))return;let r=t[n];(r===1||r===`1`||r==null)&&delete e[n]}var eP=Jp.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:YN},align:qN()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`,getAttrs:e=>ZN(e)?{}:!1,getContent:(e,t)=>QN(t.nodes[this.name])},{tag:`td`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return $N(t,e,`colspan`),$N(t,e,`rowspan`),[`td`,t,0]}}),tP=Jp.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:YN},align:qN()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`,getAttrs:e=>ZN(e)?{}:!1,getContent:(e,t)=>QN(t.nodes[this.name])},{tag:`th`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return $N(t,e,`colspan`),$N(t,e,`rowspan`),[`th`,t,0]}}),nP=Jp.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,A(this.options.HTMLAttributes,e),0]}});function rP(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function iP(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l!==null)for(let e=0,n=0;e{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function lP(e,t,n,r,i){let a=cP(e),o=[],s=[];for(let e=0;e{let{selection:t}=e.state;if(!uP(t))return!1;let n=0;return vu(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length&&(e.commands.deleteTable(),!0)};function fP(e,t){let n=e.mapping.map(t);if(vu(e.selection.$from,e=>e.type.name===`table`)?.pos===n)return;let r=e.doc.nodeAt(n);if(!r)return;let i=n+r.nodeSize-1;e.setSelection(T.near(e.doc.resolve(i),-1))}function pP(e){let t=``,n=0;for(;ne===`|`?`\\|`:e)+e.slice(i,i+r),n=i+r,a=!0;break}i+=o}a||(t+=e.slice(n,n+r),n+=r)}return t}function mP(e){return e.split(` -`).map(e=>!e.includes(`|`)||!e.includes("`")?e:pP(e)).join(` -`)}function hP(e){return(e||``).replaceAll(``,` `).replace(/\s+/g,` `).trim()}function gP(e,t){return t?e.split(t).join(` -`):e}function _P(e){return e.replace(/\\.|\|/g,e=>e===`|`?`\\|`:e)}function vP(e,t,n={}){if(!e||!e.content||e.content.length===0)return``;let r=[];e.content.forEach(e=>{let i=[];e.content&&e.content.forEach(e=>{let r=``;r=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>gP(t.renderChildren(e),n.cellLineSeparator)).join(` -`):gP(e.content?t.renderChildren(e.content):``,n.cellLineSeparator);let a=_P(hP(r.replace(/[ \t]*\r?\n[ \t]*/g,`
`))),o=e.type===`tableHeader`,s=KN(e.attrs);i.push({text:a,isHeader:o,align:s})}),r.push(i)});let i=r.reduce((e,t)=>Math.max(e,t.length),0);if(i===0)return``;let a=Array.from({length:i}).fill(0);r.forEach(e=>{for(let t=0;ta[t]&&(a[t]=n),a[t]<3&&(a[t]=3)}});let o=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),s=r[0],c=s.some(e=>e.isHeader),l=Array.from({length:i}).fill(null);r.forEach(e=>{for(let t=0;tc&&s[t]&&s[t].text||``);return u+=`| ${d.map((e,t)=>o(e,a[t])).join(` | `)} |\n`,u+=`| ${a.map((e,t)=>{let n=Math.max(3,e),r=l[t];return r===`left`?`:${`-`.repeat(n)}`:r===`right`?`${`-`.repeat(n)}:`:r===`center`?`:${`-`.repeat(n)}:`:`-`.repeat(n)}).join(` | `)} |\n`,(c?r.slice(1):r).forEach(e=>{u+=`| ${Array.from({length:i}).fill(0).map((t,n)=>o(e[n]&&e[n].text||``,a[n])).join(` | `)} |\n`}),u}var yP=new Un(`preserveCellSelectionOnContextMenu`);function bP(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(n)return n.pos;if(!(t.target instanceof Node))return null;try{return e.posAtDOM(t.target,0)}catch{return null}}function xP(e,t){let n=!1;return e.forEachCell((e,r)=>{t>=r&&t{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=WN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=WN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>vP(e,t),markdownTokenizer:{name:`table`,level:`block`,start:e=>{let t=e.split(` +`))};return s(n),{dom:r,contentDOM:a,update:e=>e.type===n.type&&(s(e),!0),ignoreMutation:e=>i.contains(e.target)}}}}),Rj=(e,t)=>e===`application/pdf`||typeof t==`string`&&/\.pdf$/i.test(t);function zj(e,t,n,r){let i=!1,a=null,o=null,s=document.createElement(`div`);return s.className=`dw-pdf__status`,s.textContent=r.blocks.pdfLoading,e.replaceChildren(s),(async()=>{try{let c=await n();if(i)return;o=c.getDocument({url:t});let l=await o.promise;if(i)return;s.remove();let u=Math.max(e.clientWidth-2,200),d=window.devicePixelRatio||1;a=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target;a?.unobserve(e),p(e,Number(e.dataset.page))}},{root:e,rootMargin:`400px 0px`});let f=(await l.getPage(1)).getViewport({scale:1});for(let t=1;t<=l.numPages;t++){let n=document.createElement(`div`);n.className=`dw-pdf__page`,n.dataset.page=String(t),n.style.aspectRatio=`${f.width} / ${f.height}`,n.setAttribute(`aria-label`,r.blocks.pdfPage.replace(`{n}`,String(t))),e.append(n),a.observe(n)}async function p(e,t){let n=await l.getPage(t);if(i)return;let r=u/n.getViewport({scale:1}).width,a=n.getViewport({scale:r*d}),o=document.createElement(`canvas`);o.width=Math.floor(a.width),o.height=Math.floor(a.height),e.style.aspectRatio=`${a.width} / ${a.height}`,e.append(o),await n.render({canvas:o,viewport:a}).promise}}catch{i||(s.textContent=r.blocks.loadFailed)}})(),()=>{i=!0,a?.disconnect(),o?.destroy()}}var Bj={page:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M9 12h6`,`M9 16h6`],"chevron-right":[`M10 6l6 6-6 6`],"chevron-left":[`M14 6l-6 6 6 6`],"chevron-down":[`M6 10l6 6 6-6`],"chevron-up":[`M6 14l6-6 6 6`],plus:[`M12 5v14`,`M5 12h14`],search:[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`],more:[`M6 12h.01`,`M12 12h.01`,`M18 12h.01`],drop:[`M12 4h7v7a7 7 0 1 1-7-7z`],info:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 11v5`,`M12 8h.01`],check:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8 12.5l2.5 2.5L16 9.5`],alert:[`M12 4l9 16H3z`,`M12 10v4`,`M12 17h.01`],error:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M9 9l6 6`,`M15 9l-6 6`],text:[`M5 6h14`,`M12 6v13`],heading:[`M6 5v14`,`M18 5v14`,`M6 12h12`],list:[`M9 6h11`,`M9 12h11`,`M9 18h11`,`M4.5 6h.01`,`M4.5 12h.01`,`M4.5 18h.01`],todo:[`M4 4h7v7H4z`,`M5.5 7.5l1.5 1.5 2.5-2.5`,`M14 7h6`,`M4 14h7v7H4z`,`M14 17h6`],code:[`M9 7l-5 5 5 5`,`M15 7l5 5-5 5`],quote:[`M6 6v12`,`M10 8h9`,`M10 12h9`,`M10 16h6`],image:[`M4 5h16v14H4z`,`M4 16l5-5 4 4 2-2 5 5`,`M15.5 8.5h.01`],table:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 5v14`],lock:[`M6 11h12v9H6z`,`M8.5 11V8a3.5 3.5 0 0 1 7 0v3`],trash:[`M4 7h16`,`M10 4h4`,`M6 7l1 13h10l1-13`,`M10 11v6`,`M14 11v6`],settings:[`M4 7h9`,`M17 7h3`,`M15 5v4`,`M4 17h3`,`M11 17h9`,`M9 15v4`],menu:[`M4 7h16`,`M4 12h16`,`M4 17h16`],close:[`M6 6l12 12`,`M18 6L6 18`],open:[`M8 16L16 8`,`M9 8h7v7`],restore:[`M4.5 13a7.5 7.5 0 1 0 2.2-6.3`,`M5 4v4h4`],"sign-out":[`M14 4h5v16h-5`,`M10 8l-4 4 4 4`,`M6 12h9`],sidebar:[`M4 5h16v14H4z`,`M9.5 5v14`],home:[`M4 11l8-7 8 7`,`M6 9.5V20h12V9.5`,`M10 20v-5h4v5`],sun:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M12 3v1.5`,`M12 19.5V21`,`M3 12h1.5`,`M19.5 12H21`,`M5.6 5.6l1.1 1.1`,`M17.3 17.3l1.1 1.1`,`M5.6 18.4l1.1-1.1`,`M17.3 6.7l1.1-1.1`],moon:[`M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z`],monitor:[`M4 5h16v11H4z`,`M9 20h6`,`M12 16v4`],selector:[`M8 9l4-4 4 4`,`M8 15l4 4 4-4`],star:[`M12 4l2.5 5.2 5.5.8-4 3.9.9 5.6L12 16.9l-4.9 2.6.9-5.6-4-3.9 5.5-.8z`],clock:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 7v5l3 2`],calendar:[`M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z`,`M4 10h16`,`M8 3v4`,`M16 3v4`],share:[`M12 4v11`,`M8 8l4-4 4 4`,`M6 13v7h12v-7`],link:[`M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1`,`M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1`],upload:[`M12 16V4`,`M7 9l5-5 5 5`,`M4 20h16`],download:[`M12 4v12`,`M7 11l5 5 5-5`,`M4 20h16`],file:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`],paperclip:[`M18 11.5l-6.4 6.4a4.2 4.2 0 0 1-6-6l7-7a2.8 2.8 0 0 1 4 4l-7 7a1.4 1.4 0 0 1-2-2l6.4-6.4`],comment:[`M5 5h14v10H9l-4 4z`],at:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1`],bold:[`M7 5h6a3.5 3.5 0 0 1 0 7H7z`,`M7 12h7a3.5 3.5 0 0 1 0 7H7z`],italic:[`M10 5h8`,`M6 19h8`,`M14 5l-4 14`],strike:[`M5 12h14`,`M16 7.5A3.5 3 0 0 0 12.5 5h-1A3.5 3 0 0 0 8 8c0 4 8 3 8 7.5a3.5 3.5 0 0 1-3.5 3.5h-1A3.5 3 0 0 1 8 16.5`],underline:[`M7 4v7a5 5 0 0 0 10 0V4`,`M5 20h14`],"list-ordered":[`M10 6h10`,`M10 12h10`,`M10 18h10`,`M4 5l1.5-1v5`,`M4 15.5a1.5 1.5 0 0 1 3 .5L4 19h3`],divider:[`M4 12h16`],globe:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M3 12h18`,`M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9`,`M12 3C9.5 5.5 8.5 8.5 8.5 12s1 6.5 3.5 9`],bell:[`M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z`,`M10 20a2 2 0 0 0 4 0`],"bell-off":[`M6 16V11a6 6 0 0 1 9.5-4.9`,`M18 11v5l1.5 2H8`,`M10 20a2 2 0 0 0 4 0`,`M4 4l16 16`],smile:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8.5 14a4 4 0 0 0 7 0`,`M9 9.5h.01`,`M15 9.5h.01`],reply:[`M9 7L4 12l5 5`,`M4 12h10a6 6 0 0 1 6 6v1`],pencil:[`M15 5l4 4L8 20H4v-4z`],sigma:[`M18 6V4H6l6 8l-6 8h12v-2`],diagram:[`M4 4h6v5H4z`,`M14 15h6v5h-6z`,`M7 9v4a2 2 0 0 0 2 2h5`],video:[`M4 6h11v12H4z`,`M15 10l5-3v10l-5-3`],archive:[`M4 5h16v4H4z`,`M5 9v10h14V9`,`M10 13h4`],pin:[`M9 4h6`,`M10 4v6l-3 4h10l-3-4V4`,`M12 14v6`],width:[`M3 12h18`,`M7 8l-4 4 4 4`,`M17 8l4 4-4 4`],type:[`M5 7V5h14v2`,`M12 5v14`,`M9 19h6`],server:[`M4 4h16v6H4z`,`M4 14h16v6H4z`,`M8 7h.01`,`M8 17h.01`],users:[`M9 11a3.5 3.5 0 1 0 0-7a3.5 3.5 0 1 0 0 7z`,`M3 20a6 6 0 0 1 12 0`,`M16 4.5a3.5 3.5 0 0 1 0 6.5`,`M18 14a6 6 0 0 1 3 6`],"align-left":[`M4 6h16`,`M4 10h10`,`M4 14h16`,`M4 18h10`],"align-center":[`M4 6h16`,`M7 10h10`,`M4 14h16`,`M7 18h10`],"align-right":[`M4 6h16`,`M10 10h10`,`M4 14h16`,`M10 18h10`],grip:[`M9 6h.01`,`M15 6h.01`,`M9 12h.01`,`M15 12h.01`,`M9 18h.01`,`M15 18h.01`],copy:[`M9 9h11v11H9z`,`M5 15H4V4h11v1`],"arrow-up":[`M12 19V5`,`M6 11l6-6 6 6`],"arrow-down":[`M12 5v14`,`M6 13l6 6 6-6`],callout:[`M4 5h16v14H4z`,`M8 10h.01`,`M11 10h5`,`M8 14h8`],palette:[`M12 3a9 9 0 1 0 0 18c1 0 1.5-.7 1.5-1.5 0-1.2-1-1.5-1-2.5s.8-1.5 2-1.5H17a4 4 0 0 0 4-4c0-4.7-4-8.5-9-8.5z`,`M7.5 11h.01`,`M10 7.5h.01`,`M14.5 7.5h.01`],"page-plus":[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M12 11v6`,`M9 14h6`],tag:[`M4 4h7l9 9-7 7-9-9z`,`M8 8h.01`],grid:[`M4 4h7v7H4z`,`M13 4h7v7h-7z`,`M4 13h7v7H4z`,`M13 13h7v7h-7z`],cards:[`M4 5h16v6H4z`,`M4 15h16v4H4z`],filter:[`M4 5h16l-6 8v6l-4-2v-4z`],layers:[`M12 4l8 4-8 4-8-4z`,`M4 12l8 4 8-4`,`M4 16l8 4 8-4`],journal:[`M6 3h11a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6z`,`M9 3v18`,`M12 8h3`,`M12 12h3`],sliders:[`M5 6h14`,`M5 12h14`,`M5 18h14`,`M9 4v4`,`M15 10v4`,`M11 16v4`],sort:[`M7 4v16`,`M4 7l3-3 3 3`,`M17 20V4`,`M14 17l3 3 3-3`],database:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 10v9`],relation:[`M3 6h7v5H3z`,`M14 13h7v5h-7z`,`M10 8.5h2.5a2 2 0 0 1 2 2V13`],rollup:[`M4 5h16`,`M4 9h16`,`M4 13h16`,`M12 16v5`,`M9 18l3 3 3-3`],edgeless:[`M4 5h16v14H4z`,`M7 15l3-4 3 3 4-5`,`M7 8.5h.01`],cursor:[`M6 4l12 7-5.5 1.5L10 18z`],hand:[`M8 13V6.5a1.5 1.5 0 0 1 3 0V12`,`M11 11V5a1.5 1.5 0 0 1 3 0v6`,`M14 11V6.5a1.5 1.5 0 0 1 3 0V14a6 6 0 0 1-6 6h-1a5 5 0 0 1-4.2-2.3L4.5 14a1.5 1.5 0 0 1 2.5-1.6L8 14`],note:[`M5 4h14v10l-6 6H5z`,`M13 20v-6h6`],shapes:[`M4 13h7v7H4z`,`M16.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M7.5 4l3.5 6H4z`],connector:[`M5 19a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M19 9a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M6.5 15.5C9 10 13 13 17.5 8.5`],pen:[`M4 20l1-4L16 5l3 3L8 19z`,`M14 7l3 3`],eraser:[`M8 20h12`,`M4.5 15.5l9-9 6 6-7.5 7.5H9z`,`M9 11l5 5`],frame:[`M7 3v18`,`M17 3v18`,`M3 7h18`,`M3 17h18`],mindmap:[`M10 10h4v4h-4z`,`M3 4h4v3H3z`,`M17 4h4v3h-4z`,`M3 17h4v3H3z`,`M17 17h4v3h-4z`,`M7 6l3 4`,`M17 6l-3 4`,`M7 18l3-4`,`M17 18l-3-4`],sticker:[`M12 3a9 9 0 1 0 9 9h-5a4 4 0 0 1-4-4z`,`M12 3a9 9 0 0 1 9 9`,`M9 14.5c1.5 1.5 4.5 1.5 6 0`],present:[`M3 4h18`,`M5 4v11h14V4`,`M12 15v3`,`M8 21l4-3 4 3`],"zoom-in":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`,`M11 8v6`],"zoom-out":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`],fit:[`M4 9V4h5`,`M15 4h5v5`,`M20 15v5h-5`,`M9 20H4v-5`],"send-back":[`M4 12h9v8H4z`,`M11 4h9v8h-9z`],group:[`M4 4h3`,`M10 4h4`,`M17 4h3v3`,`M20 10v4`,`M20 17v3h-3`,`M14 20h-4`,`M7 20H4v-3`,`M4 14v-4`,`M8 8h8v8H8z`],sparkles:[`M10 4l1.6 4.4L16 10l-4.4 1.6L10 16l-1.6-4.4L4 10l4.4-1.6z`,`M17 14l.8 2.2L20 17l-2.2.8L17 20l-.8-2.2L14 17l2.2-.8z`,`M17 3v4`,`M15 5h4`],send:[`M4 12l16-8-6 16-2-6z`,`M12 14l8-10`]},Vj=`http://www.w3.org/2000/svg`;function Hj(e,t=18){let n=document.createElementNS(Vj,`svg`);for(let[e,r]of Object.entries({width:String(t),height:String(t),viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`}))n.setAttribute(e,r);for(let t of Bj[e]){let e=document.createElementNS(Vj,`path`);e.setAttribute(`d`,t),n.append(e)}return n}function Uj(e){return()=>{let t=null,n=null,r=null,i=0,a=null,o=()=>a?.items??r?.items??[],s=t=>{let n=o()[t];if(!r||n===void 0)return;let s=e.children?.(n);s?.length?(a={parent:n,items:s},i=0,c()):e.pick(r,n)},c=()=>{if(!t||!r)return;let n=r;if(t.replaceChildren(),e.showQuery){let e=document.createElement(`div`);e.className=`dw-suggest__query`,e.textContent=`/${n.query}`,t.append(e)}if(a){let n=document.createElement(`div`);n.className=`dw-suggest__query`,n.textContent=`‹ ${e.toItem(a.parent).label}`,t.append(n)}let c=o();if(c.length)c.forEach((n,r)=>{let a=e.toItem(n),o=document.createElement(`div`);o.className=r===i?`dw-suggest__item is-active`:`dw-suggest__item`,o.setAttribute(`role`,`option`),o.setAttribute(`aria-selected`,String(r===i)),o.addEventListener(`mousedown`,e=>{e.preventDefault(),s(r)});let c=document.createElement(`span`);c.className=`dw-suggest__icon`,c.append(Hj(a.icon??`text`));let l=document.createElement(`span`);l.className=`dw-suggest__text`;let u=document.createElement(`span`);if(u.className=`dw-suggest__label`,u.textContent=a.label,l.append(u),a.description){let e=document.createElement(`span`);e.className=`dw-suggest__desc`,e.textContent=a.description,l.append(e)}if(o.append(c,l),e.children?.(n)?.length){o.setAttribute(`aria-haspopup`,`listbox`);let e=Hj(`chevron-right`,14);e.classList.add(`dw-suggest__more`),o.append(e)}t.append(o)}),t.querySelector(`.is-active`)?.scrollIntoView({block:`nearest`});else{let n=document.createElement(`div`);n.className=`dw-suggest__empty`,n.setAttribute(`role`,`status`),n.textContent=e.empty,t.append(n)}},l=()=>{let e=r?.clientRect?.();if(!t||!e)return;let i={getBoundingClientRect:()=>r?.clientRect?.()??e};n?.(),n=jj(i,t,()=>{t&&Fj(i,t,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:n})=>{t&&Object.assign(t.style,{left:`${e}px`,top:`${n}px`})})})},u=()=>{n?.(),n=null,t?.remove(),t=null};return{onStart(n){r=n,i=0,a=null,t=document.createElement(`div`),t.className=`dw-suggest`,t.setAttribute(`role`,`listbox`),t.setAttribute(`aria-label`,e.label),document.body.append(t),c(),l()},onUpdate(e){e.items!==r?.items&&(i=0,a=null),r=e,c(),l()},onKeyDown({event:t}){let n=o().length;if(a&&(t.key===`Escape`||t.key===`ArrowLeft`))return a=null,i=0,c(),!0;let r=o()[i];return t.key===`ArrowRight`&&r!==void 0&&e.children?.(r)?.length?(s(i),!0):t.key===`Escape`?(u(),!0):n?t.key===`ArrowDown`||t.key===`ArrowUp`?(i=(i+(t.key===`ArrowDown`?1:-1)+n)%n,c(),!0):t.key===`Enter`||t.key===`Tab`?(s(i),!0):!1:!1},onExit(){r=null,u()}}}}var Wj=[[`text`,`text`,e=>e],[`h1`,`heading`,e=>e.setNode(`heading`,{level:1})],[`h2`,`heading`,e=>e.setNode(`heading`,{level:2})],[`h3`,`heading`,e=>e.setNode(`heading`,{level:3})],[`bullet`,`list`,e=>e.toggleBulletList()],[`ordered`,`list-ordered`,e=>e.toggleOrderedList()],[`todo`,`todo`,e=>e.toggleTaskList()],[`quote`,`quote`,e=>e.setBlockquote()],[`code`,`code`,e=>e.setCodeBlock()],[`callout`,`callout`,e=>e.setCallout()]],Gj=[`paragraph`,`heading`,`codeBlock`,`blockquote`,`bulletList`,`orderedList`,`taskList`,`callout`];function Kj(e){let t={...e};return t.attrs&&`blockId`in t.attrs&&(t.attrs={...t.attrs,blockId:null}),t.content&&=t.content.map(Kj),t}function qj(e,t,n,r){let i=e.state.doc.nodeAt(t);if(!i)return[];let a=n.blockMenu,o=t+i.nodeSize,c=e.state.doc.resolve(t).index(0),l=[];if(Gj.includes(i.type.name)&&l.push({id:`turnInto`,label:a.turnInto,icon:`text`,children:Wj.map(([r,a,c])=>({id:r,icon:a,label:n.slash[r]?.label??r,run:()=>{if(r===`callout`){if(i.type.name===`callout`)return;let n=i.type.name===`blockquote`?i.content:s.from(i),r=e.schema.nodes.callout.create(null,n),a=e.state.tr.replaceWith(t,o,r);e.view.dispatch(a.setSelection(w.near(a.doc.resolve(t+1))).scrollIntoView()),e.commands.focus();return}let n=e.state.doc,a=w.findFrom(n.resolve(t),1,!0)?.from??t+1,l=w.findFrom(n.resolve(o),-1,!0)?.to??o-1;c(e.chain().focus().setTextSelection({from:a,to:l}).clearNodes()).run()}}))}),[`bulletList`,`orderedList`,`taskList`].includes(i.type.name)&&l.push({id:`groupAsDatabase`,label:n.database.groupAsDatabase,icon:`database`,run:()=>{e.chain().focus().setTextSelection(t+2).groupAsDatabase().run()}}),i.type.name===`codeBlock`){let n=!!e.extensionManager.extensions.find(e=>e.name===`codeBlock`)?.options.lineNumbers,r=Ij(i.attrs.lineNumbers,n);l.push({id:`lineNumbers`,label:r?a.hideLineNumbers:a.showLineNumbers,icon:`list-ordered`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`lineNumbers`,!r))})}if(i.type.name===`fileAttachment`&&Rj(i.attrs.mime,i.attrs.name)){let n=i.attrs.view===`preview`;l.push({id:`pdfView`,label:n?a.showAsFile:a.showPages,icon:n?`paperclip`:`file`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`view`,n?`card`:`preview`))})}return c>0&&l.push({id:`moveUp`,label:a.moveUp,icon:`arrow-up`,run:()=>{let n=e.state.doc.child(c-1),r=e.state.tr.delete(t,o).insert(t-n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),c{let n=e.state.doc.child(c+1),r=e.state.tr.delete(t,o).insert(t+n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),l.push({id:`duplicate`,label:a.duplicate,icon:`plus`,run:()=>{let t=e.schema.nodeFromJSON(Kj(i.toJSON()));e.view.dispatch(e.state.tr.insert(o,t).scrollIntoView())}},{id:`copy`,label:a.copy,icon:`copy`,run:()=>{e.chain().focus().setNodeSelection(t).run(),document.execCommand(`copy`)}}),r&&l.push({id:`copyLink`,label:n.blocks.copyBlockLink,icon:`link`,run:r}),l.push({id:`delete`,label:a.delete,icon:`trash`,danger:!0,run:()=>{e.view.dispatch(e.state.tr.delete(t,o)),e.commands.focus()}}),l}function Jj(e,t,n,r){let i=document.createElement(`div`);i.className=`dw-suggest dw-block-menu`,i.setAttribute(`role`,`menu`),i.setAttribute(`aria-label`,n);let a=t,o=0,s=[],c=()=>{i.replaceChildren(),a.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`dw-suggest__item${t===o?` is-active`:``}${e.danger?` is-danger`:``}`,n.setAttribute(`role`,`menuitem`),n.tabIndex=-1,e.children&&n.setAttribute(`aria-haspopup`,`menu`);let r=document.createElement(`span`);r.className=`dw-suggest__icon`,r.append(Hj(e.icon));let a=document.createElement(`span`);if(a.className=`dw-suggest__label`,a.textContent=e.label,n.append(r,a),e.children){let e=Hj(`chevron-right`,14);e.classList.add(`dw-block-menu__more`),n.append(e)}n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>l(t)),n.addEventListener(`mouseenter`,()=>{o=t;for(let[e,n]of[...i.children].entries())n.classList.toggle(`is-active`,e===t)}),i.append(n)}),i.children[o]?.focus()},l=e=>{let t=a[e];t&&(t.children?(s.push(a),a=t.children,o=0,c()):(m(),t.run?.()))},u=e=>{e.key===`Escape`||e.key===`ArrowLeft`&&s.length?(e.preventDefault(),e.stopPropagation(),s.length?(a=s.pop(),o=0,c()):m()):e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),o=(o+(e.key===`ArrowDown`?1:-1)+a.length)%a.length,c()):(e.key===`Enter`||e.key===` `||e.key===`ArrowRight`)&&(e.preventDefault(),(e.key!==`ArrowRight`||a[o]?.children)&&l(o))},d=t=>{!i.contains(t.target)&&!e.contains(t.target)&&m()};document.body.append(i);let f=jj(e,i,()=>{Fj(e,i,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(4),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(i.style,{left:`${e}px`,top:`${t}px`}))});i.addEventListener(`keydown`,u),document.addEventListener(`mousedown`,d,!0);let p=!1;function m(){p||(p=!0,f(),i.remove(),document.removeEventListener(`mousedown`,d,!0),s=[],r?.())}return c(),m}var Yj=[`paragraph`,`heading`,`blockquote`,`codeBlock`,`bulletList`,`orderedList`,`taskList`,`callout`,`table`,`details`,`image`,`embed`,`linkCard`,`mermaid`,`blockMath`,`drawio`,`excalidraw`,`fileAttachment`],Xj=/^[a-z0-9]{6,16}$/;function Zj(e){return/^#?b-([a-z0-9]{6,16})$/.exec(e)?.[1]??``}var Qj=e=>`#b-${e}`;function $j(){return[...crypto.getRandomValues(new Uint8Array(8))].map(e=>(e%36).toString(36)).join(``)}function eM(e,t){let n=e.state.doc.nodeAt(t);if(!n)return null;let r=n.attrs.blockId;if(r)return r;if(!e.editable||!Yj.includes(n.type.name))return null;let i=$j();return e.dispatch(e.state.tr.setNodeAttribute(t,`blockId`,i)),i}async function tM(e,t,n,r){let i=eM(e,t);if(!i)return!1;let a=n(Qj(i));try{await navigator.clipboard.writeText(a),r?.(a)}catch{window.prompt(``,a)}return!0}function nM(e,t){let n=-1;return e.descendants((e,r)=>n>=0?!1:(e.attrs.blockId===t&&(n=r),!0)),n}function rM(e,t){let n=nM(e.state.doc,t);if(n<0)return!1;let r=e.view.nodeDOM(n);if(!(r instanceof HTMLElement))return!1;r.scrollIntoView({block:`center`});let i=getComputedStyle(r).getPropertyValue(`--color-selection`).trim()||`rgba(47,125,109,.25)`;return r.animate?.([{backgroundColor:i},{backgroundColor:`transparent`}],{duration:2e3,easing:`ease-out`}),!0}var iM=Tp.create({name:`blockLinks`,addOptions(){return{labels:null,link:void 0,onCopied:void 0}},addGlobalAttributes(){return[{types:Yj,attributes:{blockId:{default:null,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-block-id`);return t&&Xj.test(t)?t:null},renderHTML:e=>e.blockId?{"data-block-id":e.blockId}:{}}}}]},addKeyboardShortcuts(){let{link:e,onCopied:t}=this.options;return{"Mod-Shift-c":({editor:n})=>{if(!e)return!1;let r=n.state.selection.$from;if(r.depth<1)return!1;let i=r.before(1),a=n.state.doc.nodeAt(i);return!a||!Yj.includes(a.type.name)||!a.attrs.blockId&&!n.isEditable?!1:(tM(n.view,i,e,t),!0)}}},addProseMirrorPlugins(){let{link:e,onCopied:t}=this.options,n=this.options.labels,r=this.editor;return[new D({key:new Un(`blockLinks`),view:i=>new sM(i,r,n,e,t)})]}}),aM=``,oM=``,sM=class{view;editor;labels;link;onCopied;gutter=document.createElement(`div`);linkButton=document.createElement(`button`);grip=document.createElement(`button`);pos=-1;closeMenu=null;constructor(e,t,n,r,i){this.view=e,this.editor=t,this.labels=n,this.link=r,this.onCopied=i;let a=this.gutter;a.className=`dw-block-gutter`,a.contentEditable=`false`,a.hidden=!0,a.addEventListener(`mouseleave`,this.leave);let o=this.linkButton;o.type=`button`,o.className=`dw-block-handle`,o.setAttribute(`aria-label`,n.blocks.copyBlockLink),o.title=n.blocks.copyBlockLink,o.innerHTML=aM,o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>void this.copy());let s=this.grip;s.type=`button`,s.className=`dw-block-handle dw-block-grip`,s.setAttribute(`aria-label`,n.blockMenu.open),s.setAttribute(`aria-haspopup`,`menu`),s.setAttribute(`aria-expanded`,`false`),s.title=n.blockMenu.open,s.innerHTML=oM,s.draggable=!0,s.addEventListener(`click`,this.openMenu),s.addEventListener(`dragstart`,this.dragStart),s.addEventListener(`dragend`,()=>this.hide()),r&&a.append(o),a.append(s),e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.gutter.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.gutter)),e}hide=()=>{this.closeMenu||(this.gutter.hidden=!0,this.pos=-1)};leave=e=>{let t=e.relatedTarget;t&&(this.gutter.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.closeMenu)return;let t=e.target;for(;t&&t.parentElement!==this.view.dom;)t=t.parentElement;let n=this.host;if(!t||!n)return this.hide();let r;try{r=this.view.posAtDOM(t,0)}catch{return this.hide()}let i=this.view.state.doc.resolve(Math.min(r,this.view.state.doc.content.size)),a=i.depth>=1?i.before(1):r,o=this.view.state.doc.nodeAt(a);if(!o)return this.hide();let s=!!this.link&&Yj.includes(o.type.name)&&(!!o.attrs.blockId||this.view.editable),c=this.view.editable;if(!s&&!c)return this.hide();this.linkButton.hidden=!s,this.grip.hidden=!c,this.pos=a;let l=t.getBoundingClientRect(),u=n.getBoundingClientRect();this.gutter.style.top=`${l.top-u.top+Math.min(l.height/2,14)-11}px`,this.gutter.hidden=!1};openMenu=()=>{if(this.closeMenu){this.closeMenu();return}let e=this.pos;if(e<0||!this.view.editable)return;let t=this.view.state.doc.nodeAt(e),n=!!this.link&&!!t&&Yj.includes(t.type.name),r=qj(this.editor,e,this.labels,n?()=>void this.copy(e):void 0);this.grip.setAttribute(`aria-expanded`,`true`),this.closeMenu=Jj(this.grip,r,this.labels.blockMenu.open,()=>{this.closeMenu=null,this.grip.setAttribute(`aria-expanded`,`false`),this.hide()})};dragStart=e=>{let t=this.pos;if(t<0||!e.dataTransfer)return;this.closeMenu?.();let n=E.create(this.view.state.doc,t);this.view.dispatch(this.view.state.tr.setSelection(n)),e.dataTransfer.effectAllowed=`copyMove`,e.dataTransfer.setData(`text/plain`,n.node.textContent);let r=this.view.nodeDOM(t);r instanceof HTMLElement&&e.dataTransfer.setDragImage(r,0,0),this.view.dragging={slice:n.content(),move:!0}};async copy(e=this.pos){e>=0&&this.link&&await tM(this.view,e,this.link,this.onCopied)}update(){this.pos>=this.view.state.doc.content.size&&this.hide()}destroy(){this.closeMenu?.(),this.gutter.parentElement?.classList.remove(`dw-block-host`),this.gutter.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}},cM,lM;if(typeof WeakMap<`u`){let e=new WeakMap;cM=t=>e.get(t),lM=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;cM=t=>{for(let n=0;n(t==10&&(t=0),e[t++]=n,e[t++]=r)}var uM=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;er&&(a+=i.attrs.colspan)}}for(let e=0;e1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function pM(e,t,n){e.problems||=[];let r={};for(let i=0;i0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function vM(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function yM(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function bM(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=_M(t.$head)||xM(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function xM(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function SM(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function CM(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function wM(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function TM(e,t,n){let r=e.node(-1),i=uM.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function EM(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function DM(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;ee!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Sn(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(SM(r)&&SM(i)&&wM(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return T.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=uM.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n0||u>0){let e=c.attrs;if(l>0&&(e=EM(e,0,l)),u>0&&(e=EM(e,e.colspan-u,u)),s.leftr.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=uM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom0&&(n=c.resolve(a+i.map[s.left])),o.bottom0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=uM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right{t.push(vs.node(n,n+e.nodeSize,{class:`selectedCell`}))}),xs.create(e.doc,t)}function MM({$from:e,$to:t}){if(e.pos==t.pos||e.pos=0&&!(e.after(i+1)=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function NM({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function PM(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof E&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=kM.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=kM.rowSelection(e,e)}else if(!n){let e=uM.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=kM.create(i,t+1,n)}}else r instanceof T&&MM(r)?a=T.create(i,r.from):r instanceof T&&NM(r)&&(a=T.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var FM=new Un(`fix-tables`);function IM(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o{t.type.spec.tableRole==`table`&&(n=RM(e,t,r,n))};return t?t.doc!=e.doc&&IM(t.doc,e.doc,0,r):e.doc.descendants(r),n}function RM(e,t,n,r){let i=uM.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n0?-1:0;OM(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o0&&i0&&t.map[s-1]==c||i0?-1:0;GM(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a0&&i0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i0&&n[a]==n[a-1]||r.right0&&n[i]==n[i-e]||r.bottom0){let e=c+1+l.content.size,t=ZM(l)?c+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new kM(n.doc.resolve(c+r.tableStart))),t(n)}return!0}function eN(e,t){let n=hM(e.schema);return tN(({node:e})=>n[e.type.spec.tableRole])(e,t)}function tN(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof kM){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=vM(r.$from),!i)return!1;a=_M(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=zM(t),u=t.tr;for(let e=0;e{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function rN(e){return function(t,n){if(!yM(t))return!1;if(n){let r=hM(t.schema),i=zM(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}aN(`row`,{useDeprecatedLogic:!0}),aN(`column`,{useDeprecatedLogic:!0});var oN=aN(`cell`,{useDeprecatedLogic:!0});function sN(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function uN(e,t){let n=e.selection;if(!(n instanceof kM))return!1;if(t){let r=e.tr,i=hM(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new p(i,0,0))}),r.docChanged&&t(r)}return!0}function dN(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t=t.length&&t.push(s.empty),n[i]r&&(s=s.type.createChecked(EM(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;ni&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(s.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function hN(e,t,n,r,i,a,o){let c=e.doc.type.schema,l=hM(c),u,d;if(i>t.width)for(let a=0,s=0;at.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e=t.width?!1:n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?d||=l.header_cell.createAndFill():u||=l.cell.createAndFill())}let f=l.row.create(null,s.from(c)),p=[];for(let e=t.height;e{if(!i)return!1;let a=n.selection;if(a instanceof kM)return bN(n,r,w.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=EN(i,e,t);if(o==null)return!1;if(e==`horiz`)return bN(n,r,w.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=TM(i,e,t),s;return s=a?w.near(a,1):t<0?w.near(n.doc.resolve(i.before(-1)),-1):w.near(n.doc.resolve(i.after(-1)),1),bN(n,r,s)}}}function SN(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof kM)o=a;else{let r=EN(i,e,t);if(r==null)return!1;o=new kM(n.doc.resolve(r))}let s=TM(o.$headCell,e,t);return s?bN(n,r,new kM(o.$anchorCell,s)):!1}}function CN(e,t){let n=e.state.doc,r=_M(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new kM(r))),!0):!1}function wN(e,t,n){if(!yM(e.state))return!1;let r=dN(n),i=e.state.selection;if(i instanceof kM){r||={width:1,height:1,rows:[s.from(pN(hM(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=uM.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=mN(r,o.right-o.left,o.bottom-o.top),vN(e.state,e.dispatch,a,o,r),!0}if(r){let t=bM(e.state),n=t.start(-1);return vN(e.state,e.dispatch,n,uM.get(t.node(-1)).findCell(t.pos-n),r),!0}return!1}function TN(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=DN(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof kM)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=_M(e.state.selection.$anchor))!=null&&ON(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=ON(e,n),i=gM.getState(e.state)==null;if(!r||!wM(t,r)){if(i)r=t;else return}let a=new kM(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(gM,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),gM.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(gM,-1))}function o(r){let o=r,s=gM.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(DN(e,o.target)!=n&&(c=ON(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function EN(e,t,n){if(!(e.state.selection instanceof T))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function DN(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function ON(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&_M(e.state.doc.resolve(r))||_M(e.state.doc.resolve(i))}var kN=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),AN(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type&&(this.node=e,AN(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function AN(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;enew r(e,n,t)),new NN(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=jN.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{PN(t,n,e,i)},mouseleave:e=>{FN(e)},mousedown:(e,r)=>{IN(e,r,t,n)}},decorations:e=>{let t=jN.getState(e);if(t&&t.activeHandle>-1)return GN(e,t.activeHandle)},nodeViews:{}}});return a}var NN=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(jN);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return SM(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function PN(e,t,n,r){if(!e.editable)return;let i=jN.getState(e.state);if(i&&!i.dragging){let a=RN(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=zN(e,t,`left`,n):i-t.clientX<=n&&(o=zN(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=uM.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}VN(e,o)}}}function FN(e){if(!e.editable)return;let t=jN.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&VN(e,-1)}function IN(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=jN.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=LN(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(jN,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=jN.getState(e.state);r?.dragging&&(HN(e,r.activeHandle,BN(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(jN,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=jN.getState(e.state);if(i&&i.dragging){let a=BN(i.dragging,t,n);UN(e,i.activeHandle,a,r)}}return UN(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function LN(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;eJN(e),renderHTML:e=>{let t=qN(e.align);return Pf(t)?{style:`text-align: ${t}`}:{}}}}function ZN(e){let t=e.parentElement,n=e.closest(`table`);if(!t||!n)return null;let r=Array.from(t.children).indexOf(e),i=n.querySelectorAll(`colgroup > col`)[r]?.getAttribute(`width`);return i?[parseInt(i,10)]:null}function QN(e){let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):ZN(e)}var $N=/[ \t\r\n\f]+/g;function eP(e){return e.children.length>0?!1:(e.textContent??``).replace($N,``)===``}function tP(e){let t=e.createAndFill();if(!t)throw Error(`[tiptap error]: "${e.name}" has no default content to backfill.`);return t.content}function nP(e,t,n){if(!(n in t))return;let r=t[n];(r===1||r===`1`||r==null)&&delete e[n]}var rP=Jp.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:QN},align:XN()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`,getAttrs:e=>eP(e)?{}:!1,getContent:(e,t)=>tP(t.nodes[this.name])},{tag:`td`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return nP(t,e,`colspan`),nP(t,e,`rowspan`),[`td`,t,0]}}),iP=Jp.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:QN},align:XN()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`,getAttrs:e=>eP(e)?{}:!1,getContent:(e,t)=>tP(t.nodes[this.name])},{tag:`th`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return nP(t,e,`colspan`),nP(t,e,`rowspan`),[`th`,t,0]}}),aP=Jp.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,A(this.options.HTMLAttributes,e),0]}});function oP(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function sP(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l!==null)for(let e=0,n=0;e{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function fP(e,t,n,r,i){let a=dP(e),o=[],s=[];for(let e=0;e{let{selection:t}=e.state;if(!pP(t))return!1;let n=0;return vu(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length&&(e.commands.deleteTable(),!0)};function hP(e,t){let n=e.mapping.map(t);if(vu(e.selection.$from,e=>e.type.name===`table`)?.pos===n)return;let r=e.doc.nodeAt(n);if(!r)return;let i=n+r.nodeSize-1;e.setSelection(T.near(e.doc.resolve(i),-1))}function gP(e){let t=``,n=0;for(;ne===`|`?`\\|`:e)+e.slice(i,i+r),n=i+r,a=!0;break}i+=o}a||(t+=e.slice(n,n+r),n+=r)}return t}function _P(e){return e.split(` +`).map(e=>!e.includes(`|`)||!e.includes("`")?e:gP(e)).join(` +`)}function vP(e){return(e||``).replaceAll(``,` `).replace(/\s+/g,` `).trim()}function yP(e,t){return t?e.split(t).join(` +`):e}function bP(e){return e.replace(/\\.|\|/g,e=>e===`|`?`\\|`:e)}function xP(e,t,n={}){if(!e||!e.content||e.content.length===0)return``;let r=[];e.content.forEach(e=>{let i=[];e.content&&e.content.forEach(e=>{let r=``;r=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>yP(t.renderChildren(e),n.cellLineSeparator)).join(` +`):yP(e.content?t.renderChildren(e.content):``,n.cellLineSeparator);let a=bP(vP(r.replace(/[ \t]*\r?\n[ \t]*/g,`
`))),o=e.type===`tableHeader`,s=YN(e.attrs);i.push({text:a,isHeader:o,align:s})}),r.push(i)});let i=r.reduce((e,t)=>Math.max(e,t.length),0);if(i===0)return``;let a=Array.from({length:i}).fill(0);r.forEach(e=>{for(let t=0;ta[t]&&(a[t]=n),a[t]<3&&(a[t]=3)}});let o=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),s=r[0],c=s.some(e=>e.isHeader),l=Array.from({length:i}).fill(null);r.forEach(e=>{for(let t=0;tc&&s[t]&&s[t].text||``);return u+=`| ${d.map((e,t)=>o(e,a[t])).join(` | `)} |\n`,u+=`| ${a.map((e,t)=>{let n=Math.max(3,e),r=l[t];return r===`left`?`:${`-`.repeat(n)}`:r===`right`?`${`-`.repeat(n)}:`:r===`center`?`:${`-`.repeat(n)}:`:`-`.repeat(n)}).join(` | `)} |\n`,(c?r.slice(1):r).forEach(e=>{u+=`| ${Array.from({length:i}).fill(0).map((t,n)=>o(e[n]&&e[n].text||``,a[n])).join(` | `)} |\n`}),u}var SP=new Un(`preserveCellSelectionOnContextMenu`);function CP(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(n)return n.pos;if(!(t.target instanceof Node))return null;try{return e.posAtDOM(t.target,0)}catch{return null}}function wP(e,t){let n=!1;return e.forEachCell((e,r)=>{t>=r&&t{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=qN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=qN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>xP(e,t),markdownTokenizer:{name:`table`,level:`block`,start:e=>{let t=e.split(` `);if(t.length<2)return-1;let n=t[1];return!/^[ \t|:]*-[ \t|:-]*$/.test(n)||!n.includes(`|`)?-1:t[0].includes(`|`)?0:-1},tokenize(e,t,n){let r=e.indexOf(` `),i=r>=0?e.slice(0,r):e,a=i.split(` -`);if(a.length<2)return;let o=a[1];if(!/^[ \t|:]*-[ \t|:-]*$/.test(o)||!o.includes(`|`))return;let s=mP(i);if(s===i)return;let c=n.blockTokens(s)[0];if(c?.type!==`table`||!c.raw)return;let l=c.raw.split(` +`);if(a.length<2)return;let o=a[1];if(!/^[ \t|:]*-[ \t|:-]*$/.test(o)||!o.includes(`|`))return;let s=_P(i);if(s===i)return;let c=n.blockTokens(s)[0];if(c?.type!==`table`||!c.raw)return;let l=c.raw.split(` `).length,u=e.split(` `).slice(0,l).join(` -`);return{...c,raw:u}}},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:a})=>{let o=lP(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(T.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>RM(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>zM(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return VM(e,t&&(e=>{n&&fP(e,n.pos),t(e)}))},addRowBefore:()=>({state:e,dispatch:t})=>WM(e,t),addRowAfter:()=>({state:e,dispatch:t})=>GM(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return qM(e,t&&(e=>{n&&fP(e,n.pos),t(e)}))},deleteTable:()=>({state:e,dispatch:t})=>oN(e,t),mergeCells:()=>({state:e,dispatch:t})=>XM(e,t),splitCell:()=>({state:e,dispatch:t})=>ZM(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>nN(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>nN(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>rN(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>XM(e,t)?!0:ZM(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>$M(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>aN(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>aN(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&PM(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=EM.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:dP,"Mod-Backspace":dP,Delete:dP,"Mod-Delete":dP}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[kN({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:null,lastColumnResizable:this.options.lastColumnResizable})]:[],UN({allowTableNodeSelection:this.options.allowTableNodeSelection}),SP()]},addNodeView(){let e=this.options.View;return e?({node:t,view:n,HTMLAttributes:r})=>{let i=A(this.options.HTMLAttributes,r);return new e(t,this.options.cellMinWidth,n,i)}:null},extendNodeSchema(e){return{tableRole:Nu(k(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}}),wP=Tp.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(CP.configure(this.options.table)),this.options.tableCell!==!1&&e.push(eP.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(tP.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(nP.configure(this.options.tableRow)),e}}),TP=Tp.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Pf(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}});function EP(){return[Lk.configure({HTMLAttributes:{class:`dw-tasks`}}),Ik.configure({nested:!0})]}function DP(){return[wP.configure({table:{resizable:!0,cellMinWidth:60,HTMLAttributes:{class:`dw-table`}}})]}var OP=TP.configure({types:[`heading`,`paragraph`],alignments:[`left`,`center`,`right`]}),kP=Tp.create({name:`headingShortcuts`,addKeyboardShortcuts(){let e={"Mod-Shift-0":()=>this.editor.commands.setParagraph()};for(let t of[1,2,3,4,5,6])e[`Mod-Shift-${t}`]=()=>this.editor.commands.toggleHeading({level:t});return e}}),AP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,jP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,MP=_p.create({name:`highlight`,addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute(`data-color`)||Af(e,`background-color`)||e.style.backgroundColor,renderHTML:e=>Pf(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:`mark`}]},renderHTML({HTMLAttributes:e}){return[`mark`,A(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark(`highlight`,t.parseInline(e.tokens||[])),markdownTokenizer:{name:`highlight`,level:`inline`,start:e=>e.indexOf(`==`),tokenize(e,t,n){let r=/^(==)(?!\s)([^=]*[^=\s])(==)/.exec(e);if(r){let e=r[2].trim(),t=n.inlineTokens(e);return{type:`highlight`,raw:r[0],text:e,tokens:t}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Hp({find:AP,type:this.type})]},addPasteRules(){return[Yp({find:jP,type:this.type})]}}),NP=[`gray`,`red`,`orange`,`yellow`,`green`,`teal`,`blue`,`purple`,`pink`],PP=e=>typeof e==`string`&&NP.includes(e),FP=_p.create({name:`textColor`,addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return PP(t)?t:null},renderHTML:e=>e.color?{"data-color":e.color}:{}}}},parseHTML(){return[{tag:`span[data-color]`,getAttrs:e=>PP(e.getAttribute(`data-color`))?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{class:`dw-text-color`}),0]},addCommands(){return{setTextColor:e=>({commands:t})=>t.setMark(this.name,{color:e}),unsetTextColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),IP=MP.extend({addOptions(){return{...this.parent(),multicolor:!0}},addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return PP(t)?t:null},renderHTML:e=>({"data-color":PP(e.color)?e.color:`yellow`})}}},renderHTML({HTMLAttributes:e}){return[`mark`,A(e,{class:`dw-highlight`}),0]}}),LP=`💡`;function RP(e){let t=e.trim();return t&&[...t].length<=4?t:``}var zP=Jp.create({name:`callout`,group:`block`,content:`block+`,defining:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{emoji:{default:LP,parseHTML:e=>RP(e.getAttribute(`data-emoji`)??``)||LP,renderHTML:e=>({"data-emoji":e.emoji})},color:{default:`blue`,parseHTML:e=>{let t=e.getAttribute(`data-color`);return PP(t)?t:`blue`},renderHTML:e=>({"data-color":e.color})}}},parseHTML(){return[{tag:`aside[data-type=callout]`,contentElement:e=>e.querySelector(`:scope > .callout-body`)??e}]},renderHTML({HTMLAttributes:e}){return[`aside`,A(e,{"data-type":`callout`,class:`dw-callout`}),0]},addCommands(){return{setCallout:e=>({commands:t})=>t.wrapIn(this.name,e),unsetCallout:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;for(let n=t.depth-1;n>0;n--){if(t.node(n).type.name===this.name)return t.index(n)!==0||t.start(n+1)!==t.start()?!1:e.commands.lift(this.name);if(t.index(n)!==0)return!1}return!1}}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`aside`);i.className=`dw-callout`,i.setAttribute(`data-type`,`callout`);let a=document.createElement(`div`);a.className=`dw-callout__side`,a.contentEditable=`false`;let o=document.createElement(`button`);o.type=`button`,o.className=`dw-callout__emoji`;let s=document.createElement(`button`);s.type=`button`,s.className=`dw-callout__color`,a.append(o,s);let c=document.createElement(`div`);c.className=`dw-callout__body`,i.append(a,c);let l=e,u=e=>{let r=t();typeof r==`number`&&n.isEditable&&n.view.dispatch(n.state.tr.setNodeMarkup(r,void 0,{...l.attrs,...e}))};o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>{if(!n.isEditable)return;let e=RP(window.prompt(r?.blocks.calloutEmoji??`Emoji`,l.attrs.emoji)??``);e&&u({emoji:e})}),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=NP.indexOf(l.attrs.color);u({color:NP[(e+1)%NP.length]})});let d=()=>{i.setAttribute(`data-color`,String(l.attrs.color)),o.textContent=String(l.attrs.emoji);let e=r?.blocks.calloutEmoji??`Emoji`;o.setAttribute(`aria-label`,e),o.title=e;let t=r?.blocks.calloutColor??`Colour`;s.setAttribute(`aria-label`,t),s.title=t};return d(),{dom:i,contentDOM:c,update:t=>t.type===e.type&&(l=t,d(),!0),stopEvent:e=>a.contains(e.target),ignoreMutation:e=>a.contains(e.target)}}}}),BP=e=>[e.x+e.w/2,e.y+e.h/2];function VP(e){if(!e.length)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),i=Math.max(i,a.y+a.h);return{x:t,y:n,w:r-t,h:i-n}}var HP=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),UP=(e,t)=>e.x<=t.x+t.w&&t.x<=e.x+e.w&&e.y<=t.y+t.h&&t.y<=e.y+e.h,WP=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h;function GP(e,t){return{x:Math.min(e[0],t[0]),y:Math.min(e[1],t[1]),w:Math.abs(e[0]-t[0]),h:Math.abs(e[1]-t[1])}}function KP([e,t],[n,r],i){if(!i)return[e,t];let a=i*Math.PI/180,o=Math.cos(a),s=Math.sin(a);return[n+(e-n)*o-(t-r)*s,r+(e-n)*s+(t-r)*o]}function qP(e,t){if(!t)return e;let n=BP(e),r=[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>KP(e,n,t));return GP([Math.min(...r.map(e=>e[0])),Math.min(...r.map(e=>e[1]))],[Math.max(...r.map(e=>e[0])),Math.max(...r.map(e=>e[1]))])}function JP([e,t],[n,r],[i,a]){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function YP(e,t){if(t.length===1)return Math.hypot(e[0]-t[0][0],e[1]-t[0][1]);let n=1/0;for(let r=1;re[1]-t[1]),r[0][0]}var ZP={left:[-1,0],right:[1,0],top:[0,-1],bottom:[0,1]};function QP(e,t,n=!1){let[r,i]=BP(e),a=t[0]-r,o=t[1]-i;if(!a&&!o)return[r,i];let s=Math.max(e.w/2,.5),c=Math.max(e.h/2,.5),l=n?1/Math.sqrt(a*a/(s*s)+o*o/(c*c)):Math.min(Math.abs(s/(a||1e-9)),Math.abs(c/(o||1e-9)));return[r+a*l,i+o*l]}var $P=e=>[[`top`,[e.x+e.w/2,e.y]],[`right`,[e.x+e.w,e.y+e.h/2]],[`bottom`,[e.x+e.w/2,e.y+e.h]],[`left`,[e.x,e.y+e.h/2]]];function eF(e,t){let n=e=>{if(!e.id)return[e.x??0,e.y??0];let n=t(e.id);return n?e.pos?[n.box.x+n.box.w*e.pos[0],n.box.y+n.box.h*e.pos[1]]:null:[e.x??0,e.y??0]},r=e=>{let n=e.id?t(e.id):null;return n?BP(n.box):[e.x??0,e.y??0]},i=(e,i)=>{let a=n(e),o=e.id?t(e.id):null;if(a)return{at:a,side:o?XP(o.box,a):null};let s=QP(o.box,n(i)??r(i),o.ellipse);return{at:s,side:XP(o.box,s)}};return[i(e.source,e.target),i(e.target,e.source)]}var tF=e=>Math.round(e*100)/100,nF=e=>e.map((e,t)=>`${t?`L`:`M`}${tF(e[0])} ${tF(e[1])}`).join(` `),rF=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);function iF(e,t,n){let[r,i]=t.at,[a,o]=n.at,s=Math.hypot(a-r,o-i);if(e===`straight`||s<1)return{points:[t.at,n.at],d:nF([t.at,n.at]),mid:[(r+a)/2,(i+o)/2],startAngle:rF(n.at,t.at),endAngle:rF(t.at,n.at)};if(e===`curve`){let e=Math.min(s/2,160),c=t.side?ZP[t.side]:aF(t.at,n.at),l=n.side?ZP[n.side]:aF(n.at,t.at),u=[r+c[0]*e,i+c[1]*e],d=[a+l[0]*e,o+l[1]*e],f=[];for(let e=0;e<=24;e++)f.push(oF(t.at,u,d,n.at,e/24));return{points:f,d:`M${tF(r)} ${tF(i)} C${tF(u[0])} ${tF(u[1])} ${tF(d[0])} ${tF(d[1])} ${tF(a)} ${tF(o)}`,mid:oF(t.at,u,d,n.at,.5),startAngle:rF(u,t.at),endAngle:rF(d,n.at)}}let c=t.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`right`:`left`:o>i?`bottom`:`top`),l=n.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`left`:`right`:o>i?`top`:`bottom`),u=[r+ZP[c][0]*24,i+ZP[c][1]*24],d=[a+ZP[l][0]*24,o+ZP[l][1]*24],f=c===`left`||c===`right`,p=l===`left`||l===`right`,m;if(f&&p){let e=(u[0]+d[0])/2;m=[[e,u[1]],[e,d[1]]]}else if(!f&&!p){let e=(u[1]+d[1])/2;m=[[u[0],e],[d[0],e]]}else m=f?[[d[0],u[1]]]:[[u[0],d[1]]];let h=sF([t.at,u,...m,d,n.at]);return{points:h,d:nF(h),mid:cF(h),startAngle:rF(h[1]??n.at,t.at),endAngle:rF(h[h.length-2]??t.at,n.at)}}function aF(e,t){let n=Math.hypot(t[0]-e[0],t[1]-e[1])||1;return[(t[0]-e[0])/n,(t[1]-e[1])/n]}function oF(e,t,n,r,i){let a=1-i,o=a*a*a,s=3*a*a*i,c=3*a*i*i,l=i*i*i;return[o*e[0]+s*t[0]+c*n[0]+l*r[0],o*e[1]+s*t[1]+c*n[1]+l*r[1]]}function sF(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Math.abs(e[0]-n[0])<.01&&Math.abs(e[1]-n[1])<.01)continue;let r=t[t.length-2];if(r&&e){let i=(e[0]-r[0])*(n[1]-r[1])-(e[1]-r[1])*(n[0]-r[0]);Math.abs(i)<.01&&t.pop()}t.push(n)}return t}function cF(e){let t=0;for(let n=1;n=n&&a>0)return[r[0]+(i[0]-r[0])*n/a,r[1]+(i[1]-r[1])*n/a];n-=a}return e[0]??[0,0]}function lF(e,t,n){let r=e=>[e.x,e.x+e.w/2,e.x+e.w],i=e=>[e.y,e.y+e.h/2,e.y+e.h],a={dx:0,ox:null,vx:0},o={dy:0,oy:null,vy:0},s=n+1,c=n+1;for(let n of t){for(let t of r(e))for(let e of r(n)){let r=Math.abs(e-t);rtypeof e==`string`&&pF.includes(e),hF=[`rect`,`roundrect`,`ellipse`,`diamond`,`triangle`],gF=[`straight`,`curve`,`elbow`],_F=[`none`,`arrow`,`triangle`,`circle`,`diamond`],vF=[`right`,`left`,`radial`],yF=`page`,bF=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,xF=(e,t=``)=>typeof e==`string`?e:t,SF=e=>e===!0,CF=(e,t)=>mF(e)?e:t,wF=(e,t,n)=>typeof e==`string`&&t.includes(e)?e:n;function TF(e){if(!e||typeof e!=`object`)return{x:0,y:0};let t=e,n={};return typeof t.id==`string`&&t.id&&(n.id=t.id),Array.isArray(t.pos)&&t.pos.length===2&&(n.pos=[bF(t.pos[0],.5),bF(t.pos[1],.5)]),n.id||(n.x=bF(t.x,0),n.y=bF(t.y,0)),n}function EF(e){let t={};if(!e||typeof e!=`object`)return t;for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`)continue;let e=r;t[n]={text:xF(e.text),parent:xF(e.parent),pos:bF(e.pos,0)}}return t}function DF(e){let t={id:xF(e.id),index:bF(e.index,0),x:bF(e.x,0),y:bF(e.y,0),w:Math.max(0,bF(e.w,0)),h:Math.max(0,bF(e.h,0)),rotate:bF(e.rotate,0),group:xF(e.group)};switch(e.type){case`shape`:return{...t,type:`shape`,shape:wF(e.shape,hF,`rect`),stroke:CF(e.stroke,`ink`),fill:CF(e.fill,`none`),strokeWidth:bF(e.strokeWidth,2),strokeStyle:wF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),rough:SF(e.rough),text:xF(e.text),textColor:CF(e.textColor,`ink`),fontSize:bF(e.fontSize,18)};case`text`:return{...t,type:`text`,text:xF(e.text),color:CF(e.color,`ink`),fontSize:bF(e.fontSize,24),font:wF(e.font,[``,`serif`,`mono`],``),align:wF(e.align,[`left`,`center`,`right`],`left`),bold:SF(e.bold)};case`connector`:return{...t,type:`connector`,source:TF(e.source),target:TF(e.target),mode:wF(e.mode,gF,`curve`),stroke:CF(e.stroke,`ink`),strokeWidth:bF(e.strokeWidth,2),strokeStyle:wF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),startArrow:wF(e.startArrow,_F,`none`),endArrow:wF(e.endArrow,_F,`arrow`),label:xF(e.label),rough:SF(e.rough)};case`brush`:return{...t,type:`brush`,points:Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&e.length>=2).map(e=>[bF(e[0],0),bF(e[1],0),bF(e[2],.5)]):[],color:CF(e.color,`ink`),size:bF(e.size,4)};case`note`:return{...t,type:`note`,page:SF(e.page),background:CF(e.background,`paper`)};case`frame`:return{...t,type:`frame`,title:xF(e.title),background:CF(e.background,`none`)};case`image`:return{...t,type:`image`,src:xF(e.src),alt:xF(e.alt)};case`embed`:return{...t,type:`embed`,url:xF(e.url)};case`group`:return{...t,type:`group`,title:xF(e.title)};case`mindmap`:return{...t,type:`mindmap`,layout:wF(e.layout,vF,`right`),color:CF(e.color,`blue`),nodes:EF(e.nodes)};default:return null}}var OF=e=>![`connector`,`group`,`mindmap`].includes(e.type),kF=e=>[`shape`,`text`,`image`,`brush`].includes(e.type),AF=e=>![`connector`,`brush`,`group`].includes(e.type),jF=0;function MF(){return jF=(jF+1)%1296,Date.now().toString(36).slice(-6)+jF.toString(36).padStart(2,`0`)+Math.random().toString(36).slice(2,8)}var NF={shape:{shape:`rect`,stroke:`blue`,fill:`blue`,strokeWidth:2,strokeStyle:`solid`,rough:!1,textColor:`ink`},connector:{mode:`curve`,stroke:`gray`,strokeWidth:2,strokeStyle:`solid`,startArrow:`none`,endArrow:`arrow`},brush:{color:`ink`,size:4},text:{color:`ink`,fontSize:24,font:``},note:{background:`yellow`},frame:{background:`none`},mindmap:{layout:`right`,color:`blue`}};function PF(e){let t=structuredClone(NF);if(!e||typeof e!=`object`)return t;for(let n of Object.keys(t)){let r=e[n];if(!r||typeof r!=`object`)continue;let i=DF({...t[n],...r,type:n===`note`?`note`:n});if(i)for(let e of Object.keys(t[n])){let a=r[e];a!==void 0&&i[e]===a&&(t[n][e]=a)}}return t}var FF=[`👍`,`⭐`,`❤️`,`✅`,`❌`,`💡`,`❓`,`❗`,`🎉`,`🔥`,`📌`,`🚀`,`👀`,`🎯`,`⚠️`,`🙂`];function IF(e){return[{id:MF(),type:`text`,text:e,fontSize:64,x:0,y:0,w:0,h:0}]}var LF=[`kanban`,`swot`,`flow`,`brainstorm`,`retro`],RF=e=>[{type:`paragraph`,content:e?[{type:`text`,text:e}]:[]}],zF=(e,t,n,r,i,a=`none`)=>({id:MF(),type:`frame`,title:e,x:t,y:n,w:r,h:i,background:a}),BF=(e,t,n,r,i=220)=>({id:MF(),type:`note`,background:r,x:t,y:n,w:i,h:90,body:RF(e)}),VF=(e,t,n,r,i,a,o)=>({id:MF(),type:`shape`,shape:e,text:t,x:n,y:r,w:i,h:a,stroke:o,fill:o,strokeWidth:2}),HF=(e,t,n=`elbow`)=>({id:MF(),type:`connector`,source:{id:e},target:{id:t},mode:n,stroke:`gray`,endArrow:`arrow`});function UF(e,t){switch(e){case`kanban`:return[[t.todo,`gray`],[t.doing,`blue`],[t.done,`green`]].flatMap(([e,t],n)=>[zF(e,n*300,0,280,520),BF(``,n*300+30,50,t),BF(``,n*300+30,170,t)]);case`swot`:return[[t.strengths,`green`],[t.weaknesses,`red`],[t.opportunities,`blue`],[t.threats,`orange`]].flatMap(([e,t],n)=>[VF(`roundrect`,e,n%2*380,Math.floor(n/2)*300,360,280,t)]);case`flow`:{let e=VF(`ellipse`,t.start,0,0,180,70,`green`),n=VF(`rect`,t.step,0,140,180,80,`blue`),r=VF(`diamond`,t.decision,-10,290,200,120,`orange`),i=VF(`rect`,t.step,280,310,180,80,`blue`),a=VF(`ellipse`,t.end,0,480,180,70,`red`);return[e,n,r,i,a,HF(e.id,n.id),HF(n.id,r.id),HF(r.id,i.id),HF(r.id,a.id)]}case`brainstorm`:{let e=MF(),n={[e]:{text:t.centralIdea,parent:``,pos:0}};for(let r=0;r<4;r++)n[MF()]={text:`${t.idea} ${r+1}`,parent:e,pos:r};return[{id:MF(),type:`mindmap`,layout:`radial`,color:`purple`,x:0,y:0,nodes:n}]}case`retro`:return[[t.wentWell,`green`],[t.toImprove,`orange`],[t.actions,`blue`]].flatMap(([e,t],n)=>[zF(e,n*300,0,280,420),BF(``,n*300+30,50,t)])}}var WF;function GF(){if(WF!==void 0)return WF;try{WF=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{WF=null}return WF}var KF=`"Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif`,qF=`"Source Serif 4 Variable", "Source Serif 4", Georgia, serif`,JF=`"JetBrains Mono Variable", "JetBrains Mono", ui-monospace, monospace`;function YF(e){return e===`serif`?qF:e===`mono`?JF:KF}function XF(e,t,n=KF,r=400){let i=GF();return i?(i.font=`${r} ${t}px ${n}`,i.measureText(e).width):e.length*t*.56}function ZF(e,t,n,r=KF,i=400){let a=[];for(let o of e.split(` -`)){if(!o){a.push(``);continue}let e=``;for(let s of o.split(/(\s+)/)){let o=e+s;if(!e||XF(o,t,r,i)<=n)e=o;else for(a.push(e.trimEnd()),e=s.trimStart();e&&XF(e,t,r,i)>n;){let o=e.length-1;for(;o>1&&XF(e.slice(0,o),t,r,i)>n;)o--;a.push(e.slice(0,o)),e=e.slice(o)}}a.push(e)}return a}function QF(e,t){let n=t===0?18:15,r=t===0?600:400,i=ZF(e||` `,n,260,KF,r),a=Math.max(...i.map(e=>XF(e,n,KF,r)),t===0?60:40);return{w:Math.ceil(a)+(t===0?32:24),h:i.length*Math.round(n*1.4)+(t===0?20:14)}}var $F=56,eI=14;function tI(e){let t=Object.entries(e).filter(([,t])=>!t.parent||!e[t.parent]);return t.sort((e,t)=>e[1].pos-t[1].pos||(e[0]n.parent===t&&e!==t).sort((e,t)=>e[1].pos-t[1].pos||(e[0]e)}function rI(e,t,n){let r=tI(e),i=new Map,a=[];if(!r)return{root:``,boxes:i,edges:a,bounds:{x:0,y:0,w:0,h:0}};let o=new Map,s=new Set,c=(t,r)=>{if(!(s.has(t)||r>50)){s.add(t),o.set(t,n(e[t].text,r));for(let n of nI(e,t))c(n,r+1)}};c(r,0);let l=t=>nI(e,t).filter(e=>o.has(e)),u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;let n=l(e),r=n.reduce((e,t)=>e+d(t),0)+eI*Math.max(0,n.length-1),i=Math.max(o.get(e).h,r);return u.set(e,i),i},f=(e,t,n,r,a,s)=>{let c=o.get(e),u=a===1?t:t-c.w;i.set(e,{id:e,x:u,y:n-c.h/2,w:c.w,h:c.h,depth:r,dir:a,parent:s}),p(e,l(e),a===1?u+c.w+$F:u-$F,n,r+1,a)},p=(e,t,n,r,i,a)=>{let o=r-(t.reduce((e,t)=>e+d(t),0)+eI*Math.max(0,t.length-1))/2;for(let r of t){let t=d(r);f(r,n,o+t/2,i,a,e),o+=t+eI}},m=o.get(r);i.set(r,{id:r,x:0,y:0,w:m.w,h:m.h,depth:0,dir:1,parent:``});let h=m.h/2,g=l(r);if(t===`right`)p(r,g,m.w+$F,h,1,1);else if(t===`left`)p(r,g,-56,h,1,-1);else{let e=Math.ceil(g.length/2);p(r,g.slice(0,e),m.w+$F,h,1,1),p(r,g.slice(e),-56,h,1,-1)}for(let e of i.values()){if(!e.parent)continue;let t=i.get(e.parent),n=e.dir===1?[t.x+t.w,t.y+t.h/2]:[t.x,t.y+t.h/2],r=e.dir===1?[e.x,e.y+e.h/2]:[e.x+e.w,e.y+e.h/2];a.push({from:n,to:r,child:e.id})}let _=1/0,v=1/0,y=-1/0,b=-1/0;for(let e of i.values())_=Math.min(_,e.x),v=Math.min(v,e.y),y=Math.max(y,e.x+e.w),b=Math.max(b,e.y+e.h);return{root:r,boxes:i,edges:a,bounds:{x:_,y:v,w:y-_,h:b-v}}}function iI(e,t,n,r){let i=e.boxes.get(n);if(!i)return null;if(r===`ArrowUp`||r===`ArrowDown`){let a=i.parent?nI(t,i.parent).filter(t=>e.boxes.get(t)?.dir===i.dir):[];return a[a.indexOf(n)+(r===`ArrowUp`?-1:1)]??null}let a=r===`ArrowRight`?1:-1;return i.parent?a===i.dir?nI(t,n)[0]??null:i.parent:nI(t,n).find(t=>e.boxes.get(t)?.dir===a)??null}function aI(e,t){let n=(e[0]+t[0])/2;return`M${e[0]} ${e[1]} C${n} ${e[1]} ${n} ${t[1]} ${t[0]} ${t[1]}`}function oI(e,t,n,r=e=>e){return e*r(.5-t*(.5-n))}function sI(e){return[-e[0],-e[1]]}function cI(e,t){return[e[0]+t[0],e[1]+t[1]]}function lI(e,t){return[e[0]-t[0],e[1]-t[1]]}function uI(e,t){return[e[0]*t,e[1]*t]}function dI(e,t){return[e[0]/t,e[1]/t]}function fI(e){return[e[1],-e[0]]}function pI(e,t){return e[0]*t[0]+e[1]*t[1]}function mI(e,t){return e[0]===t[0]&&e[1]===t[1]}function hI(e){return Math.hypot(e[0],e[1])}function gI(e){return e[0]*e[0]+e[1]*e[1]}function _I(e,t){return gI(lI(e,t))}function vI(e){return dI(e,hI(e))}function yI(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function bI(e,t,n){let r=Math.sin(n),i=Math.cos(n),a=e[0]-t[0],o=e[1]-t[1],s=a*i-o*r,c=a*r+o*i;return[s+t[0],c+t[1]]}function xI(e,t,n){return cI(e,uI(lI(t,e),n))}function SI(e,t,n){return cI(e,uI(t,n))}var{min:CI,PI:wI}=Math,TI=.275,EI=wI+1e-4;function DI(e,t={}){let{size:n=16,smoothing:r=.5,thinning:i=.5,simulatePressure:a=!0,easing:o=e=>e,start:s={},end:c={},last:l=!1}=t,{cap:u=!0,easing:d=e=>e*(2-e)}=s,{cap:f=!0,easing:p=e=>--e*e*e+1}=c;if(e.length===0||n<=0)return[];let m=e[e.length-1].runningLength,h=s.taper===!1?0:s.taper===!0?Math.max(n,m):s.taper,g=c.taper===!1?0:c.taper===!0?Math.max(n,m):c.taper,_=(n*r)**2,v=[],y=[],b=e.slice(0,10).reduce((e,t)=>{let r=t.pressure;if(a){let i=CI(1,t.distance/n);r=CI(1,e+(CI(1,1-i)-e)*(i*TI))}return(e+r)/2},e[0].pressure),x=oI(n,i,e[e.length-1].pressure,o),S,C=e[0].vector,ee=e[0].point,te=ee,ne=ee,re=te,ie=!1;for(let t=0;t_)&&(v.push(ne),ee=ne),re=cI(s,ue),(t<=1||_I(te,re)>_)&&(y.push(re),te=re),b=r,C=c}let ae=e[0].point.slice(0,2),oe=e.length>1?e[e.length-1].point.slice(0,2):cI(e[0].point,[1,1]),se=[],ce=[];if(e.length===1){if(!(h||g)||l){let e=SI(ae,vI(fI(lI(ae,oe))),-(S||x)),t=[];for(let n=1/13,r=n;r<=1;r+=n)t.push(bI(e,ae,EI*2*r));return t}}else{if(!(h||g&&e.length===1)){if(u)for(let e=1/13,t=e;t<=1;t+=e){let e=bI(y[0],ae,EI*t);se.push(e)}else{let e=lI(v[0],y[0]),t=uI(e,.5),n=uI(e,.51);se.push(lI(ae,t),lI(ae,n),cI(ae,n),cI(ae,t))}}let t=fI(sI(e[e.length-1].vector));if(g||h&&e.length===1)ce.push(oe);else if(f){let e=SI(oe,t,x);for(let t=1/29,n=t;n<1;n+=t)ce.push(bI(e,oe,EI*3*n))}else ce.push(cI(oe,uI(t,x)),cI(oe,uI(t,x*.99)),lI(oe,uI(t,x*.99)),lI(oe,uI(t,x)))}return v.concat(ce,y.reverse(),se)}function OI(e,t={}){let{streamline:n=.5,size:r=16,last:i=!1}=t;if(e.length===0)return[];let a=.15+(1-n)*.85,o=Array.isArray(e[0])?e:e.map(({x:e,y:t,pressure:n=.5})=>[e,t,n]);if(o.length===2){let e=o[1];o=o.slice(0,-1);for(let t=1;t<5;t++)o.push(xI(o[0],e,t/4))}o.length===1&&(o=[...o,[...cI(o[0],[1,1]),...o[0].slice(2)]]);let s=[{point:[o[0][0],o[0][1]],pressure:o[0][2]>=0?o[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,l=0,u=s[0],d=o.length-1;for(let e=1;e=0?o[e][2]:.5,vector:vI(lI(u.point,t)),distance:n,runningLength:l},s.push(u)}return s[0].vector=s[1]?.vector||[0,0],s}function kI(e,t={}){return DI(OI(e,t),t)}function AI(e,t,n){if(e&&e.length){let[r,i]=t,a=Math.PI/180*n,o=Math.cos(a),s=Math.sin(a);for(let t of e){let[e,n]=t;t[0]=(e-r)*o-(n-i)*s+r,t[1]=(e-r)*s+(n-i)*o+i}}}function jI(e,t){return e[0]===t[0]&&e[1]===t[1]}function MI(e,t,n,r=1){let i=n,a=Math.max(t,.1),o=e[0]&&e[0][0]&&typeof e[0][0]==`number`?[e]:e,s=[0,0];if(i)for(let e of o)AI(e,s,i);let c=function(e,t,n){let r=[];for(let t of e){let e=[...t];jI(e[0],e[e.length-1])||e.push([e[0][0],e[0][1]]),e.length>2&&r.push(e)}let i=[];t=Math.max(t,.1);let a=[];for(let e of r)for(let t=0;te.ymint.ymin?1:e.xt.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!a.length)return i;let o=[],s=a[0].ymin,c=0;for(;o.length||a.length;){if(a.length){let e=-1;for(let t=0;ts);t++)e=t;a.splice(0,e+1).forEach((e=>{o.push({s,edge:e})}))}if(o=o.filter((e=>!(e.edge.ymax<=s))),o.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),(n!==1||c%t==0)&&o.length>1)for(let e=0;e=o.length)break;let n=o[e].edge,r=o[t].edge;i.push([[Math.round(n.x),s],[Math.round(r.x),s]])}s+=n,o.forEach((e=>{e.edge.x=e.edge.x+n*e.edge.islope})),c++}return i}(o,a,r);if(i){for(let e of o)AI(e,s,-i);(function(e,t,n){let r=[];e.forEach((e=>r.push(...e))),AI(r,t,n)})(c,s,-i)}return c}function NI(e,t){let n=t.hachureAngle+90,r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=1;return t.roughness>=1&&(t.randomizer?.next()||Math.random())>.7&&(i=r),MI(e,r,n,i||1)}var PI=class{constructor(e){this.helper=e}fillPolygons(e,t){return this._fillPolygons(e,t)}_fillPolygons(e,t){let n=NI(e,t);return{type:`fillSketch`,ops:this.renderLines(n,t)}}renderLines(e,t){let n=[];for(let r of e)n.push(...this.helper.doubleLineOps(r[0][0],r[0][1],r[1][0],r[1][1],t));return n}};function FI(e){let t=e[0],n=e[1];return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2)}var II=class extends PI{fillPolygons(e,t){let n=t.hachureGap;n<0&&(n=4*t.strokeWidth),n=Math.max(n,.1);let r=NI(e,Object.assign({},t,{hachureGap:n})),i=Math.PI/180*t.hachureAngle,a=[],o=.5*n*Math.cos(i),s=.5*n*Math.sin(i);for(let[e,t]of r)FI([e,t])&&a.push([[e[0]-o,e[1]+s],[...t]],[[e[0]+o,e[1]-s],[...t]]);return{type:`fillSketch`,ops:this.renderLines(a,t)}}},LI=class extends PI{fillPolygons(e,t){let n=this._fillPolygons(e,t),r=Object.assign({},t,{hachureAngle:t.hachureAngle+90}),i=this._fillPolygons(e,r);return n.ops=n.ops.concat(i.ops),n}},RI=class{constructor(e){this.helper=e}fillPolygons(e,t){let n=NI(e,t=Object.assign({},t,{hachureAngle:0}));return this.dotsOnLines(n,t)}dotsOnLines(e,t){let n=[],r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=t.fillWeight;i<0&&(i=t.strokeWidth/2);let a=r/4;for(let o of e){let e=FI(o),s=e/r,c=Math.ceil(s)-1,l=e-c*r,u=(o[0][0]+o[1][0])/2-r/4,d=Math.min(o[0][1],o[1][1]);for(let e=0;e{let a=FI(e),o=Math.floor(a/(n+r)),s=(a+r-o*(n+r))/2,c=e[0],l=e[1];c[0]>l[0]&&(c=e[1],l=e[0]);let u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let e=0;e{let i=FI(e),a=Math.round(i/(2*t)),o=e[0],s=e[1];o[0]>s[0]&&(o=e[1],s=e[0]);let c=Math.atan((s[1]-o[1])/(s[0]-o[0]));for(let e=0;er%2?e+n:e+t));a.push({key:`C`,data:e}),t=e[4],n=e[5];break}case`Q`:a.push({key:`Q`,data:[...s]}),t=s[2],n=s[3];break;case`q`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`Q`,data:e}),t=e[2],n=e[3];break}case`A`:a.push({key:`A`,data:[...s]}),t=s[5],n=s[6];break;case`a`:t+=s[5],n+=s[6],a.push({key:`A`,data:[s[0],s[1],s[2],s[3],s[4],t,n]});break;case`H`:a.push({key:`H`,data:[...s]}),t=s[0];break;case`h`:t+=s[0],a.push({key:`H`,data:[t]});break;case`V`:a.push({key:`V`,data:[...s]}),n=s[0];break;case`v`:n+=s[0],a.push({key:`V`,data:[n]});break;case`S`:a.push({key:`S`,data:[...s]}),t=s[2],n=s[3];break;case`s`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`S`,data:e}),t=e[2],n=e[3];break}case`T`:a.push({key:`T`,data:[...s]}),t=s[0],n=s[1];break;case`t`:t+=s[0],n+=s[1],a.push({key:`T`,data:[t,n]});break;case`Z`:case`z`:a.push({key:`Z`,data:[]}),t=r,n=i}return a}function XI(e){let t=[],n=``,r=0,i=0,a=0,o=0,s=0,c=0;for(let{key:l,data:u}of e){switch(l){case`M`:t.push({key:`M`,data:[...u]}),[r,i]=u,[a,o]=u;break;case`C`:t.push({key:`C`,data:[...u]}),r=u[4],i=u[5],s=u[2],c=u[3];break;case`L`:t.push({key:`L`,data:[...u]}),[r,i]=u;break;case`H`:r=u[0],t.push({key:`L`,data:[r,i]});break;case`V`:i=u[0],t.push({key:`L`,data:[r,i]});break;case`S`:{let e=0,a=0;n===`C`||n===`S`?(e=r+(r-s),a=i+(i-c)):(e=r,a=i),t.push({key:`C`,data:[e,a,...u]}),s=u[0],c=u[1],r=u[2],i=u[3];break}case`T`:{let[e,a]=u,o=0,l=0;n===`Q`||n===`T`?(o=r+(r-s),l=i+(i-c)):(o=r,l=i);let d=r+2*(o-r)/3,f=i+2*(l-i)/3,p=e+2*(o-e)/3,m=a+2*(l-a)/3;t.push({key:`C`,data:[d,f,p,m,e,a]}),s=o,c=l,r=e,i=a;break}case`Q`:{let[e,n,a,o]=u,l=r+2*(e-r)/3,d=i+2*(n-i)/3,f=a+2*(e-a)/3,p=o+2*(n-o)/3;t.push({key:`C`,data:[l,d,f,p,a,o]}),s=e,c=n,r=a,i=o;break}case`A`:{let e=Math.abs(u[0]),n=Math.abs(u[1]),a=u[2],o=u[3],s=u[4],c=u[5],l=u[6];e===0||n===0?(t.push({key:`C`,data:[r,i,c,l,c,l]}),r=c,i=l):(r!==c||i!==l)&&(QI(r,i,c,l,e,n,a,o,s).forEach((function(e){t.push({key:`C`,data:e})})),r=c,i=l);break}case`Z`:t.push({key:`Z`,data:[]}),r=a,i=o}n=l}return t}function ZI(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function QI(e,t,n,r,i,a,o,s,c,l){let u=(d=o,Math.PI*d/180);var d;let f=[],p=0,m=0,h=0,g=0;if(l)[p,m,h,g]=l;else{[e,t]=ZI(e,t,-u),[n,r]=ZI(n,r,-u);let o=(e-n)/2,l=(t-r)/2,d=o*o/(i*i)+l*l/(a*a);d>1&&(d=Math.sqrt(d),i*=d,a*=d);let f=i*i,_=a*a,v=f*_-f*l*l-_*o*o,y=f*l*l+_*o*o,b=(s===c?-1:1)*Math.sqrt(Math.abs(v/y));h=b*i*l/a+(e+n)/2,g=b*-a*o/i+(t+r)/2,p=Math.asin(parseFloat(((t-g)/a).toFixed(9))),m=Math.asin(parseFloat(((r-g)/a).toFixed(9))),em&&(p-=2*Math.PI),!c&&m>p&&(m-=2*Math.PI)}let _=m-p;if(Math.abs(_)>120*Math.PI/180){let e=m,t=n,s=r;m=c&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,f=QI(n=h+i*Math.cos(m),r=g+a*Math.sin(m),t,s,i,a,o,0,c,[m,e,h,g])}_=m-p;let v=Math.cos(p),y=Math.sin(p),b=Math.cos(m),x=Math.sin(m),S=Math.tan(_/4),C=4/3*i*S,ee=4/3*a*S,te=[e,t],ne=[e+C*y,t-ee*v],re=[n+C*x,r-ee*b],ie=[n,r];if(ne[0]=2*te[0]-ne[0],ne[1]=2*te[1]-ne[1],l)return[ne,re,ie].concat(f);{f=[ne,re,ie].concat(f);let e=[];for(let t=0;t2){let i=[];for(let t=0;t2*Math.PI&&(p=0,m=2*Math.PI);let h=2*Math.PI/c.curveStepCount,g=Math.min(h/2,(m-p)/2),_=_L(g,l,u,d,f,p,m,1,c);if(!c.disableMultiStroke){let e=_L(g,l,u,d,f,p,m,1.5,c);_.push(...e)}return o&&(s?_.push(...fL(l,u,l+d*Math.cos(p),u+f*Math.sin(p),c),...fL(l,u,l+d*Math.cos(m),u+f*Math.sin(m),c)):_.push({op:`lineTo`,data:[l,u]},{op:`lineTo`,data:[l+d*Math.cos(p),u+f*Math.sin(p)]})),{type:`path`,ops:_}}function sL(e,t){let n=XI(YI(JI(e))),r=[],i=[0,0],a=[0,0];for(let{key:e,data:o}of n)switch(e){case`M`:a=[o[0],o[1]],i=[o[0],o[1]];break;case`L`:r.push(...fL(a[0],a[1],o[0],o[1],t)),a=[o[0],o[1]];break;case`C`:{let[e,n,i,s,c,l]=o;r.push(...vL(e,n,i,s,c,l,a,t)),a=[c,l];break}case`Z`:r.push(...fL(a[0],a[1],i[0],i[1],t)),a=[i[0],i[1]]}return{type:`path`,ops:r}}function cL(e,t){let n=[];for(let r of e)if(r.length){let e=t.maxRandomnessOffset||0,i=r.length;if(i>2){n.push({op:`move`,data:[r[0][0]+F(e,t),r[0][1]+F(e,t)]});for(let a=1;a500?.4:-.0016668*c+1.233334;let u=i.maxRandomnessOffset||0;u*u*100>s&&(u=c/10);let d=u/2,f=.2+.2*uL(i),p=i.bowing*i.maxRandomnessOffset*(r-t)/200,m=i.bowing*i.maxRandomnessOffset*(e-n)/200;p=F(p,i,l),m=F(m,i,l);let h=[],g=()=>F(d,i,l),_=()=>F(u,i,l),v=i.preserveVertices;return a&&(o?h.push({op:`move`,data:[e+(v?0:g()),t+(v?0:g())]}):h.push({op:`move`,data:[e+(v?0:F(u,i,l)),t+(v?0:F(u,i,l))]})),o?h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+g(),m+t+(r-t)*f+g(),p+e+2*(n-e)*f+g(),m+t+2*(r-t)*f+g(),n+(v?0:g()),r+(v?0:g())]}):h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+_(),m+t+(r-t)*f+_(),p+e+2*(n-e)*f+_(),m+t+2*(r-t)*f+_(),n+(v?0:_()),r+(v?0:_())]}),h}function mL(e,t,n){let r=[];r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]),r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]);for(let i=1;i3){let a=[],o=1-n.curveTightness;i.push({op:`move`,data:[e[1][0],e[1][1]]});for(let t=1;t+21&&i.push(n)):i.push(n),i.push(e[t+3])}else{let r=.5,a=e[t+0],o=e[t+1],s=e[t+2],c=e[t+3],l=SL(a,o,r),u=SL(o,s,r),d=SL(s,c,r),f=SL(l,u,r),p=SL(u,d,r),m=SL(f,p,r);CL([a,l,f,m],0,n,i),CL([m,p,d,c],0,n,i)}var a,o;return i}function wL(e,t){return TL(e,0,e.length,t)}function TL(e,t,n,r,i){let a=i||[],o=e[t],s=e[n-1],c=0,l=1;for(let r=t+1;rc&&(c=t,l=r)}return Math.sqrt(c)>r?(TL(e,t,l+1,r,a),TL(e,l,n,r,a)):(a.length||a.push(o),a.push(s)),a}function EL(e,t=.15,n){let r=[],i=(e.length-1)/3;for(let n=0;n0?TL(r,0,r.length,n):r}var DL=`none`,OL=class{constructor(e){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:`#000`,strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:`hachure`,fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=e||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions}_d(e,t,n){return{shape:e,sets:t||[],options:n||this.defaultOptions}}line(e,t,n,r,i){let a=this._o(i);return this._d(`line`,[eL(e,t,n,r,a)],a)}rectangle(e,t,n,r,i){let a=this._o(i),o=[],s=nL(e,t,n,r,a);if(a.fill){let i=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]];a.fillStyle===`solid`?o.push(cL([i],a)):o.push(lL([i],a))}return a.stroke!==DL&&o.push(s),this._d(`rectangle`,o,a)}ellipse(e,t,n,r,i){let a=this._o(i),o=[],s=iL(n,r,a),c=aL(e,t,a,s);if(a.fill){if(a.fillStyle===`solid`){let n=aL(e,t,a,s).opset;n.type=`fillPath`,o.push(n)}else o.push(lL([c.estimatedPoints],a))}return a.stroke!==DL&&o.push(c.opset),this._d(`ellipse`,o,a)}circle(e,t,n,r){let i=this.ellipse(e,t,n,n,r);return i.shape=`circle`,i}linearPath(e,t){let n=this._o(t);return this._d(`linearPath`,[tL(e,!1,n)],n)}arc(e,t,n,r,i,a,o=!1,s){let c=this._o(s),l=[],u=oL(e,t,n,r,i,a,o,!0,c);if(o&&c.fill){if(c.fillStyle===`solid`){let o=Object.assign({},c);o.disableMultiStroke=!0;let s=oL(e,t,n,r,i,a,!0,!1,o);s.type=`fillPath`,l.push(s)}else l.push(function(e,t,n,r,i,a,o){let s=e,c=t,l=Math.abs(n/2),u=Math.abs(r/2);l+=F(.01*l,o),u+=F(.01*u,o);let d=i,f=a;for(;d<0;)d+=2*Math.PI,f+=2*Math.PI;f-d>2*Math.PI&&(d=0,f=2*Math.PI);let p=(f-d)/o.curveStepCount,m=[];for(let e=d;e<=f;e+=p)m.push([s+l*Math.cos(e),c+u*Math.sin(e)]);return m.push([s+l*Math.cos(f),c+u*Math.sin(f)]),m.push([s,c]),lL([m],o)}(e,t,n,r,i,a,c))}return c.stroke!==DL&&l.push(u),this._d(`arc`,l,c)}curve(e,t){let n=this._o(t),r=[],i=rL(e,n);if(n.fill&&n.fill!==DL&&e.length>=3){if(n.fillStyle===`solid`){let t=rL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else{let t=EL(function(e,t=0){let n=e.length;if(n<3)throw Error(`A curve must have at least three points.`);let r=[];if(n===3)r.push(yL(e[0]),yL(e[1]),yL(e[2]),yL(e[2]));else{let n=[];n.push(e[0],e[0]);for(let t=1;t{s.length>=4&&a.push(...EL(s,t)),s=[]},l=()=>{c(),a.length&&(i.push(a),a=[])};for(let{key:e,data:t}of r)switch(e){case`M`:l(),o=[t[0],t[1]],a.push(o);break;case`L`:c(),a.push([t[0],t[1]]);break;case`C`:if(!s.length){let e=a.length?a[a.length-1]:o;s.push([e[0],e[1]])}s.push([t[0],t[1]]),s.push([t[2],t[3]]),s.push([t[4],t[5]]);break;case`Z`:c(),a.push([o[0],o[1]])}if(l(),!n)return i;let u=[];for(let e of i){let t=wL(e,n);t.length&&u.push(t)}return u}(e,1,o?4-4*(n.simplification||1):(1+n.roughness)/2),c=sL(e,n);if(i){if(n.fillStyle===`solid`){if(s.length===1){let t=sL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else r.push(cL(s,n))}else r.push(lL(s,n))}return a&&(o?s.forEach((e=>{r.push(tL(e,!1,n))})):r.push(c)),this._d(`path`,r,n)}opsToPath(e,t){let n=``;for(let r of e.ops){let e=typeof t==`number`&&t>=0?r.data.map((e=>+e.toFixed(t))):r.data;switch(r.op){case`move`:n+=`M${e[0]} ${e[1]} `;break;case`bcurveTo`:n+=`C${e[0]} ${e[1]}, ${e[2]} ${e[3]}, ${e[4]} ${e[5]} `;break;case`lineTo`:n+=`L${e[0]} ${e[1]} `}}return n.trim()}toPaths(e){let t=e.sets||[],n=e.options||this.defaultOptions,r=[];for(let e of t){let t=null;switch(e.type){case`path`:t={d:this.opsToPath(e),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:DL};break;case`fillPath`:t={d:this.opsToPath(e),stroke:DL,strokeWidth:0,fill:n.fill||DL};break;case`fillSketch`:t=this.fillSketch(e,n)}t&&r.push(t)}return r}fillSketch(e,t){let n=t.fillWeight;return n<0&&(n=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||DL,strokeWidth:n,fill:DL}}_mergedShape(e){return e.filter(((e,t)=>t===0||e.op!==`move`))}},kL=class{constructor(e,t){this.canvas=e,this.ctx=this.canvas.getContext(`2d`),this.gen=new OL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.ctx,i=e.options.fixedDecimalPlaceDigits;for(let a of t)switch(a.type){case`path`:r.save(),r.strokeStyle=n.stroke===`none`?`transparent`:n.stroke,r.lineWidth=n.strokeWidth,n.strokeLineDash&&r.setLineDash(n.strokeLineDash),n.strokeLineDashOffset&&(r.lineDashOffset=n.strokeLineDashOffset),this._drawToContext(r,a,i),r.restore();break;case`fillPath`:{r.save(),r.fillStyle=n.fill||``;let t=e.shape===`curve`||e.shape===`polygon`||e.shape===`path`?`evenodd`:`nonzero`;this._drawToContext(r,a,i,t),r.restore();break}case`fillSketch`:this.fillSketch(r,a,n)}}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2),e.save(),n.fillLineDash&&e.setLineDash(n.fillLineDash),n.fillLineDashOffset&&(e.lineDashOffset=n.fillLineDashOffset),e.strokeStyle=n.fill||``,e.lineWidth=r,this._drawToContext(e,t,n.fixedDecimalPlaceDigits),e.restore()}_drawToContext(e,t,n,r=`nonzero`){e.beginPath();for(let r of t.ops){let t=typeof n==`number`&&n>=0?r.data.map((e=>+e.toFixed(n))):r.data;switch(r.op){case`move`:e.moveTo(t[0],t[1]);break;case`bcurveTo`:e.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5]);break;case`lineTo`:e.lineTo(t[0],t[1])}}t.type===`fillPath`?e.fill(r):e.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a),a}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a),a}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a),a}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i),i}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n),n}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n),n}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c),c}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n),n}path(e,t){let n=this.gen.path(e,t);return this.draw(n),n}},AL=`http://www.w3.org/2000/svg`,jL=class{constructor(e,t){this.svg=e,this.gen=new OL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,i=r.createElementNS(AL,`g`),a=e.options.fixedDecimalPlaceDigits;for(let o of t){let t=null;switch(o.type){case`path`:t=r.createElementNS(AL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,n.stroke),t.setAttribute(`stroke-width`,n.strokeWidth+``),t.setAttribute(`fill`,`none`),n.strokeLineDash&&t.setAttribute(`stroke-dasharray`,n.strokeLineDash.join(` `).trim()),n.strokeLineDashOffset&&t.setAttribute(`stroke-dashoffset`,`${n.strokeLineDashOffset}`);break;case`fillPath`:t=r.createElementNS(AL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,`none`),t.setAttribute(`stroke-width`,`0`),t.setAttribute(`fill`,n.fill||``),e.shape!==`curve`&&e.shape!==`polygon`||t.setAttribute(`fill-rule`,`evenodd`);break;case`fillSketch`:t=this.fillSketch(r,o,n)}t&&i.appendChild(t)}return i}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let i=e.createElementNS(AL,`path`);return i.setAttribute(`d`,this.opsToPath(t,n.fixedDecimalPlaceDigits)),i.setAttribute(`stroke`,n.fill||``),i.setAttribute(`stroke-width`,r+``),i.setAttribute(`fill`,`none`),n.fillLineDash&&i.setAttribute(`stroke-dasharray`,n.fillLineDash.join(` `).trim()),n.fillLineDashOffset&&i.setAttribute(`stroke-dashoffset`,`${n.fillLineDashOffset}`),i}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(e,t){return this.gen.opsToPath(e,t)}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a)}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a)}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a)}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i)}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n)}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n)}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c)}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n)}path(e,t){let n=this.gen.path(e,t);return this.draw(n)}},ML={canvas:(e,t)=>new kL(e,t),svg:(e,t)=>new jL(e,t),generator:e=>new OL(e),newSeed:()=>OL.newSeed()},NL=(e,t)=>e===`none`?`none`:e===`ink`?t===`fill`?`var(--dw-surface-sunken)`:`var(--dw-ink)`:e===`paper`?t===`fill`?`var(--dw-surface-raised)`:`var(--dw-surface)`:t===`fill`?`color-mix(in srgb, var(--dw-c-${e}) 22%, var(--dw-surface))`:`var(--dw-c-${e})`,PL=e=>e.replace(/&/g,`&`).replace(//g,`>`).replace(/"/g,`"`),FL=e=>Math.round(e*100)/100,IL=`#000001`,LL=`#000002`;function RL(e,t){return e===`dash`?`stroke-dasharray:${FL(t*4)} ${FL(t*3)};`:``}function zL(e){let t=2166136261;for(let n of e)t=Math.imul(t^n.charCodeAt(0),16777619);return(t>>>0)%2**31||1}function BL(e,t,n){switch(e){case`diamond`:return[[t/2,0],[t,n/2],[t/2,n],[0,n/2]];case`triangle`:return[[t/2,0],[t,n],[0,n]];case`rect`:return[[0,0],[t,0],[t,n],[0,n]];default:return null}}function VL(e,t){let n=Math.min(16,e*.15,t*.15);return`M${FL(n)} 0 H${FL(e-n)} Q${FL(e)} 0 ${FL(e)} ${FL(n)} V${FL(t-n)} Q${FL(e)} ${FL(t)} ${FL(e-n)} ${FL(t)} H${FL(n)} Q0 ${FL(t)} 0 ${FL(t-n)} V${FL(n)} Q0 0 ${FL(n)} 0 Z`}function HL(e,t){let{w:n,h:r}=e,i=e.strokeStyle===`none`?`none`:t(e.stroke,`line`),a=t(e.fill,`fill`),o=e.strokeStyle===`none`?0:e.strokeWidth;if(e.rough){let t=ML.generator(),s={seed:zL(e.id),roughness:1.2,bowing:1,strokeWidth:Math.max(o,1),stroke:i===`none`?`none`:IL,fill:a===`none`?void 0:LL,fillStyle:`hachure`,hachureGap:8,fillWeight:1.4,disableMultiStroke:o===0},c=BL(e.shape,n,r),l=e.shape===`ellipse`?t.ellipse(n/2,r/2,n,r,s):e.shape===`roundrect`?t.path(VL(n,r),s):t.polygon(c,s);return t.toPaths(l).map(t=>{if(t.fill===LL)return``;let n=t.stroke===LL,r=n?a.replace(`22%`,`60%`):i;return r===`none`||t.stroke===`none`?``:``}).join(``)}let s=`fill:${a};stroke:${i};stroke-width:${FL(o)};stroke-linejoin:round;${RL(e.strokeStyle,o)}`;return e.shape===`ellipse`?``:e.shape===`roundrect`?``:``}function UL(e,t,n,r,i){if(e===`none`)return``;let a=6+r*2.5,o=(e,r)=>{let i=Math.cos(n),a=Math.sin(n);return`${FL(t[0]+e*i-r*a)},${FL(t[1]+e*a+r*i)}`};switch(e){case`arrow`:return``;case`triangle`:return``;case`circle`:{let[e,t]=o(-a*.45,0).split(`,`).map(Number);return``}case`diamond`:return``}}function WL(e,t,n){let r=e.strokeStyle===`none`?n(`gray`,`line`):n(e.stroke,`line`),i=e.strokeWidth,a;if(e.rough){let n=ML.generator();a=n.toPaths(n.path(t.d,{seed:zL(e.id),roughness:1,strokeWidth:i,stroke:`#000`})).map(e=>``).join(``)}else a=``;let o=t.points[t.points.length-1];return a+UL(e.startArrow,t.points[0],t.startAngle,i,r)+UL(e.endArrow,o,t.endAngle,i,r)}function GL(e,t){let n=kI(e,{size:t,thinning:.55,smoothing:.5,streamline:.4,simulatePressure:e.every(e=>e[2]===.5),last:!0});if(!n.length)return``;let r=(e,t)=>(e+t)/2,i=`M${FL(n[0][0])} ${FL(n[0][1])} Q`;for(let e=0;e`}function qL(e){let t=[];for(let n of e.toArray())if(n instanceof dx)for(let e of n.toDelta()){if(typeof e.insert!=`string`)continue;let n={type:`text`,text:e.insert};e.attributes&&(n.marks=Object.entries(e.attributes).map(([e,t])=>({type:e,attrs:t&&typeof t==`object`?t:{}}))),t.push(n)}else if(n instanceof ox){let e={type:n.nodeName},r=n.getAttributes();Object.keys(r).length&&(e.attrs=r),n.length&&(e.content=qL(n)),t.push(e)}return t}function JL(e,t,n=0){if(n>100)return;let r=0;for(;r{let r=``,i=!1;for(let a of e)a.type===`text`?(r+=a.text??``,i=!0):a.type===`hardBreak`?(t.push(r),r=``):a.content?.length&&a.content.some(e=>e.type!==`text`&&e.type!==`hardBreak`)?(i&&t.push(r),r=``,i=!1,n(a.content)):(i&&t.push(r),t.push((a.content??[]).map(e=>e.text??``).join(``)),r=``,i=!1);i&&t.push(r)};return n(e),t}var XL=`docwell-canvas`,ZL=e=>e.getMap(`surface`);function QL(e){let t={};for(let[n,r]of e.entries())r instanceof Lb?t[n]=r.toJSON():r instanceof pb||(t[n]=r);return DF(t)}function $L(e,t){return(e.type===`frame`?0:1)-(t.type===`frame`?0:1)||e.index-t.index||(e.idt.id))}function eR(){return DF({id:yF,type:`note`,page:!0,background:`paper`,x:0,y:0,w:760,h:400,index:0})}var tR=class{doc;map;undo;cache=null;byId=new Map;listeners=new Set;observer=e=>{this.cache=null;let t=new Set;for(let n of e){if(n.target===this.map){t=null;break}let e=n.target;for(;e&&e.parent!==this.map;)e=e.parent;let r=e&&e._item?.parentSub;r&&t.add(r)}for(let e of this.listeners)e(t)};constructor(e,t={}){this.doc=e,this.map=ZL(e),this.map.observeDeep(this.observer),this.undo=t.undo===!1?null:new Vy(this.map,{trackedOrigins:new Set([XL]),captureTimeout:400})}destroy(){this.map.unobserveDeep(this.observer),this.undo?.destroy(),this.listeners.clear()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}elements(){if(this.cache)return this.cache;let e=[];for(let[t,n]of this.map.entries()){let r=n instanceof Lb?QL(n):null;r&&e.push({...r,id:t})}return e.some(e=>e.type===`note`&&e.page)||e.push(eR()),e.sort($L),this.cache=e,this.byId=new Map(e.map(e=>[e.id,e])),e}get(e){return this.elements(),this.byId.get(e)}get isEmpty(){return this.map.size===0}body(e){let t=this.map.get(e);if(!(t instanceof Lb))return null;let n=t.get(`body`);return n instanceof ix?n:null}nodes(e){let t=this.map.get(e)?.get(`nodes`);return t instanceof Lb?t:null}transact(e){this.doc.transact(e,XL)}nextIndex(){let e=0;for(let t of this.elements())t.type!==`frame`&&(e=Math.max(e,t.index));return e+1}ensure(e){let t=this.map.get(e);if(t instanceof Lb)return t;if(e!==`page`)return null;let n=this.get(e),r=new Lb;this.map.set(e,r);for(let[e,t]of Object.entries(n))e!==`id`&&r.set(e,t);return r}add(e,t){let n=e.id||MF();return this.transact(()=>{let r=new Lb;this.map.set(n,r);let{nodes:i,...a}=e;for(let[e,t]of Object.entries(a))e!==`id`&&t!==void 0&&r.set(e,t);if(`index`in a||r.set(`index`,e.type===`frame`?-this.nextIndex():this.nextIndex()),e.type===`note`&&!e.page){let e=new ix;r.set(`body`,e),JL(e,t?.length?t:[{type:`paragraph`}])}if(e.type===`mindmap`){let e=new Lb;r.set(`nodes`,e);let t=i&&Object.keys(i).length?i:{[MF()]:{text:``,parent:``,pos:0}};for(let[n,r]of Object.entries(t))e.set(n,nR(r))}}),n}update(e,t){this.updateMany([[e,t]])}updateMany(e){e.length&&this.transact(()=>{for(let[t,n]of e){let e=this.ensure(t);if(e)for(let[t,r]of Object.entries(n))t!==`id`&&t!==`type`&&t!==`body`&&t!==`nodes`&&(r===void 0?e.delete(t):rR(e.get(t),r)||e.set(t,r))}})}remove(e){let t=this.elements(),n=new Set;for(let r of e){n.add(r);for(let e of t)e.group===r&&n.add(e.id)}n.delete(yF);for(let e of t)e.type===`note`&&e.page&&n.delete(e.id);n.size&&this.transact(()=>{for(let e of t)if(!(e.type!==`connector`||n.has(e.id)))for(let t of[`source`,`target`]){let r=e[t];if(r.id&&n.has(r.id)){let n=this.endPoint(r);this.map.get(e.id)?.set(t,{x:n[0],y:n[1]})}}for(let e of n)this.map.delete(e);let e=this.elements();for(let t of e.filter(e=>e.type===`group`)){let n=e.filter(e=>e.group===t.id);if(n.length<2){for(let e of n)this.map.get(e.id)?.delete(`group`);this.map.delete(t.id)}}})}endPoint(e){let t=e.id?this.get(e.id):void 0;if(!t)return[e.x??0,e.y??0];let[n,r]=e.pos??[.5,.5];return[t.x+t.w*n,t.y+t.h*r]}reorder(e,t){let n=this.elements().filter(e=>e.type!==`frame`),r=new Set(e),i=n.filter(e=>r.has(e.id));if(!i.length)return;let a=n.filter(e=>!r.has(e.id)),o;if(t===`front`)o=[...a,...i];else if(t===`back`)o=[...i,...a];else{o=[...n];let e=t===`forward`?1:-1,a=e=>o.indexOf(e),s=e===1?[...i].reverse():i;for(let t of s){let n=a(t),i=n+e;i<0||i>=o.length||r.has(o[i].id)||([o[n],o[i]]=[o[i],o[n]])}}this.updateMany(o.map((e,t)=>[e.id,{index:t+1}]).filter(([e,t])=>this.get(e)?.index!==t.index))}groupOf(e){let t=e.filter(e=>{let t=this.get(e);return t&&t.type!==`group`&&!(t.type===`note`&&t.page)});if(t.length<2)return null;let n=MF();return this.transact(()=>{let e=new Lb;this.map.set(n,e),e.set(`type`,`group`),e.set(`index`,this.nextIndex());for(let e of t)this.ensure(e)?.set(`group`,n)}),n}ungroup(e){let t=this.elements().filter(t=>t.group===e).map(e=>e.id);return this.transact(()=>{for(let e of t)this.map.get(e)?.delete(`group`);this.map.delete(e)}),t}addNode(e,t,n,r=``){let i=MF();return this.transact(()=>this.nodes(e)?.set(i,nR({text:r,parent:t,pos:n}))),i}updateNode(e,t,n){this.transact(()=>{let r=this.nodes(e)?.get(t);if(r)for(let[e,t]of Object.entries(n))r.get(e)!==t&&r.set(e,t)})}removeNode(e,t){let n=this.get(e);if(n?.type!==`mindmap`)return;if(t===Object.entries(n.nodes).find(([,e])=>!e.parent)?.[0]){this.remove([e]);return}let r=new Set([t]),i=!0;for(;i;){i=!1;for(let[e,t]of Object.entries(n.nodes))!r.has(e)&&r.has(t.parent)&&(r.add(e),i=!0)}this.transact(()=>{let t=this.nodes(e);for(let e of r)t?.delete(e)})}toJSON(e){let t=this.elements(),n;if(e){n=new Set(e);for(let e of t)n.has(e.group)&&n.add(e.id)}else n=new Set(t.map(e=>e.id));return t.filter(e=>n.has(e.id)).map(e=>{let t={...e,id:e.id,type:e.type},n=e.type===`note`&&!e.page?this.body(e.id):null;return n&&(t.body=qL(n)),t})}insertJSON(e,t=0,n=0){let r=e.filter(e=>e&&typeof e==`object`&&!(e.type===`note`&&e.page)),i=new Map(r.map(e=>[String(e.id),MF()])),a=[],o=this.nextIndex();return this.transact(()=>{for(let e of r){let r=DF(e);if(!r)continue;let s=i.get(String(e.id)),c={...r};if(delete c.id,c.x=r.x+t,c.y=r.y+n,c.index=r.type===`frame`?-o++:o++,c.group=r.group&&i.has(r.group)?i.get(r.group):void 0,r.type===`connector`)for(let e of[`source`,`target`]){let a=r[e];if(a.id&&i.has(a.id))c[e]={id:i.get(a.id),...a.pos?{pos:a.pos}:{}};else if(a.id){let r=this.endPoint(a);c[e]={x:r[0]+t,y:r[1]+n}}else c[e]={x:(a.x??0)+t,y:(a.y??0)+n}}for(let e of Object.keys(c))(c[e]===void 0||c[e]===``)&&delete c[e];this.add({...c,id:s,type:r.type},Array.isArray(e.body)?e.body:void 0),a.push(s)}}),a}load(e){this.transact(()=>{for(let e of[...this.map.keys()])this.map.delete(e);for(let t of e){let e=DF(t);if(!e||!t.id)continue;let n={...e},r=String(t.id);delete n.id;for(let e of Object.keys(n))n[e]===``&&delete n[e];this.add({...n,id:r,type:e.type},Array.isArray(t.body)?t.body:void 0)}})}};function nR(e){let t=new Lb;return t.set(`text`,e.text),t.set(`parent`,e.parent),t.set(`pos`,e.pos),t}function rR(e,t){return e===t?!0:typeof e!=`object`||typeof t!=`object`||!e||!t?!1:JSON.stringify(e)===JSON.stringify(t)}var iR=(e,t=18)=>``,aR={rect:``,roundrect:``,ellipse:``,diamond:``,triangle:``,straight:``,curve:``,elbow:``,none:``,arrow:``,triangleEnd:``,circle:``,diamondEnd:``,solid:``,dash:``,noLine:``,right:``,left:``,radial:``},oR=e=>``;function sR(e){return e===`none`?`background:transparent`:e===`ink`?`background:var(--dw-ink)`:e===`paper`?`background:var(--dw-surface)`:`background:var(--dw-c-${e})`}var cR=class{v;bar;zoomBox;props;zoomLabel;pop=null;popFor=``;fileInput;lastProps=``;closePop=e=>{this.pop&&!this.pop.contains(e.target)&&!e.target.closest?.(`[data-pop]`)&&this.hidePop()};constructor(e){this.v=e;let t=e.root;this.bar=this.div(`dw-cv-ui dw-cv-toolbar`),this.bar.setAttribute(`role`,`toolbar`),this.bar.setAttribute(`aria-label`,e.labels.toolbar),this.zoomBox=this.div(`dw-cv-ui dw-cv-zoom`),this.props=this.div(`dw-cv-ui dw-cv-props`),this.props.setAttribute(`role`,`toolbar`),this.zoomLabel=document.createElement(`button`),this.fileInput=document.createElement(`input`),this.fileInput.type=`file`,this.fileInput.accept=`image/*`,this.fileInput.multiple=!0,this.fileInput.hidden=!0,this.fileInput.addEventListener(`change`,()=>{let t=[...this.fileInput.files??[]];this.fileInput.value=``,t.length&&e.addImages(t)}),t.append(this.bar,this.zoomBox,this.props,this.fileInput),document.addEventListener(`pointerdown`,this.closePop,!0),this.buildZoom(),this.refresh()}destroy(){document.removeEventListener(`pointerdown`,this.closePop,!0)}div(e){let t=document.createElement(`div`);return t.className=e,t}button(e,t,n,r={}){let i=document.createElement(`button`);return i.type=`button`,i.className=`dw-cv-btn${r.cls?` ${r.cls}`:``}`,i.innerHTML=e,i.title=t,i.setAttribute(`aria-label`,t),r.active!==void 0&&i.setAttribute(`aria-pressed`,String(r.active)),r.pop&&(i.dataset.pop=r.pop),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),i.addEventListener(`click`,e=>{e.stopPropagation(),n()}),i}buildBar(){let e=this.v,t=e.labels;if(this.bar.replaceChildren(),this.bar.hidden=e.isPresenting,!e.editable){this.bar.append(this.button(iR(`cursor`),t.select,()=>e.setTool(`select`),{active:e.tool===`select`}),this.button(iR(`hand`),t.hand,()=>e.setTool(`hand`),{active:e.tool===`hand`}),this.sep(),this.button(iR(`present`),t.present,()=>e.present()));return}let n=(t,n,r)=>this.button(iR(n),r,()=>e.setTool(t),{active:e.tool===t}),r=this.button(oR(e.shapeKind),t.shape,()=>{e.setTool(`shape`),this.togglePop(`shape`,r,()=>this.shapePop())},{active:e.tool===`shape`,pop:`shape`}),i=this.button(iR(`pen`),t.pen,()=>{e.setTool(`pen`),this.togglePop(`pen`,i,()=>this.penPop())},{active:e.tool===`pen`,pop:`pen`}),a=this.button(iR(`connector`),t.connector,()=>{e.setTool(`connector`),this.togglePop(`connector`,a,()=>this.connectorPop())},{active:e.tool===`connector`,pop:`connector`}),o=this.button(iR(`sticker`),t.library,()=>this.togglePop(`library`,o,()=>this.libraryPop()),{pop:`library`});this.bar.append(n(`select`,`cursor`,t.select),n(`hand`,`hand`,t.hand),this.sep(),n(`note`,`note`,t.note),n(`text`,`type`,t.text),r,a,i,n(`eraser`,`eraser`,t.eraser),n(`frame`,`frame`,t.frame),n(`mindmap`,`mindmap`,t.mindmap),this.button(iR(`image`),t.image,()=>this.pickImage()),this.button(iR(`link`),t.link,()=>void e.addLink()),o,this.sep(),this.button(iR(`present`),t.present,()=>e.present()))}sep(){return this.div(`dw-cv-sep`)}pickImage(){this.v.editable&&this.v.opts.files?.upload&&this.fileInput.click()}togglePop(e,t,n){if(this.pop&&this.popFor===e)return this.hidePop();this.hidePop();let r=n();r.classList.add(`dw-cv-ui`,`dw-cv-pop`),r.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.v.root.append(r),this.pop=r,this.popFor=e;let i=this.v.root.getBoundingClientRect(),a=t.getBoundingClientRect(),o=r.offsetWidth,s=r.offsetHeight,c=a.left-i.left+a.width/2-o/2;c=Math.max(8,Math.min(i.width-o-8,c));let l=a.top-i.top-s-8;l<8&&(l=a.bottom-i.top+8),r.style.left=`${c}px`,r.style.top=`${l}px`}hidePop(){this.pop?.remove(),this.pop=null,this.popFor=``}row(...e){let t=this.div(`dw-cv-row`);return t.append(...e),t}colorRow(e,t,n,r){let i=this.div(`dw-cv-row dw-cv-colors`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,r);let a=this.v.labels,o=[`ink`,...fF,...n?[`paper`,`none`]:[]];for(let n of o){let r=n===`ink`?a.colorInk:n===`paper`?a.colorPaper:n===`none`?a.colorNone:a.colors[n]??n,o=this.button(``,r,()=>{t(n),this.lastProps=``,this.refresh()},{active:n===e});i.append(o)}return i}shapePop(){let e=this.v,t=e.labels,n=this.div(``);return n.append(this.row(...hF.map(n=>this.button(oR(n),t[n],()=>{e.setShapeKind(n),this.hidePop()},{active:e.shapeKind===n}))),this.row(this.button(`${t.general}`,t.general,()=>{e.setStyle(`shape`,{rough:!1}),this.hidePop()},{active:!e.styles.shape.rough}),this.button(`${t.scribbled}`,t.scribbled,()=>{e.setStyle(`shape`,{rough:!0}),this.hidePop()},{active:e.styles.shape.rough}))),n}penPop(){let e=this.v,t=this.div(``);return t.append(this.colorRow(e.styles.brush.color,t=>e.setStyle(`brush`,{color:t}),!1,e.labels.stroke),this.row(...[2,4,8,14].map(t=>this.button(``,`${e.labels.thickness} ${t}`,()=>{e.setStyle(`brush`,{size:t}),this.hidePop()},{active:e.styles.brush.size===t})))),t}connectorPop(){let e=this.v,t=this.div(``);return t.append(this.row(...gF.map(t=>this.button(oR(t),e.labels[t],()=>{e.setStyle(`connector`,{mode:t}),this.hidePop()},{active:e.styles.connector.mode===t})))),t}libraryPop(){let e=this.v,t=e.labels,n=this.div(`dw-cv-library`),r=this.div(`dw-cv-poptitle`);r.textContent=t.stickers;let i=this.div(`dw-cv-stickers`);for(let t of FF)i.append(this.button(`${t}`,t,()=>{e.insertSticker(t),this.hidePop()}));let a=this.div(`dw-cv-poptitle`);a.textContent=t.templates;let o=this.div(`dw-cv-templates`),s={kanban:t.templateKanban,swot:t.templateSwot,flow:t.templateFlow,brainstorm:t.templateBrainstorm,retro:t.templateRetro};for(let t of LF){let n=this.button(`${s[t]}`,s[t],()=>{e.insertTemplate(t),this.hidePop()},{cls:`dw-cv-wide`});o.append(n)}return n.append(r,i,a,o),n}buildZoom(){let e=this.v,t=e.labels;this.zoomLabel.type=`button`,this.zoomLabel.className=`dw-cv-btn dw-cv-zoomlabel`,this.zoomLabel.title=t.zoomReset,this.zoomLabel.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.zoomLabel.addEventListener(`click`,()=>e.zoomAt(1)),this.zoomBox.append(this.button(iR(`zoom-out`),t.zoomOut,()=>e.zoomBy(.8)),this.zoomLabel,this.button(iR(`zoom-in`),t.zoomIn,()=>e.zoomBy(1.25)),this.button(iR(`fit`),t.zoomFit,()=>e.fit()))}zoomChanged(){this.zoomLabel.textContent=`${Math.round(this.v.zoom*100)}%`}refresh(){this.buildBar();let e=(this.v.editable||this.v.opts.onComment)&&!this.v.editing&&!this.v.isPresenting?this.v.selection():[],t=JSON.stringify([e,this.v.activeNode,this.v.styles.shape.rough]);t!==this.lastProps&&(this.lastProps=t,this.buildProps(e)),this.place()}place(){let e=this.props;if(e.hidden)return;let t=this.v.selectionScreenBox();if(!t){e.hidden=!0;return}let n=this.v.root.getBoundingClientRect(),r=e.offsetWidth,i=e.offsetHeight,a=t.x+t.w/2-r/2;a=Math.max(8,Math.min(n.width-r-8,a));let o=t.y-i-40;o<8&&(o=Math.min(n.height-i-64,t.y+t.h+16)),e.style.left=`${a}px`,e.style.top=`${Math.max(8,o)}px`}buildProps(e){let t=this.props;if(t.replaceChildren(),!e.length){t.hidden=!0;return}t.hidden=!1;let n=this.v,r=n.labels,i=n.opts.onComment,a=()=>this.button(iR(`comment`),r.comment,()=>{let t=e[0].id;i?.({id:t,text:n.elementText(t).slice(0,500)})});if(!n.editable){i&&e.length===1?t.append(a()):t.hidden=!0;return}let o=new Set(e.map(e=>e.type)).size===1?e[0]:null,s=[],c=(e,t,n,r)=>{let i=this.button(t,n,()=>this.togglePop(e,i,r),{pop:e});s.push(i)},l=(e,t,r,i,a)=>c(e,``,t,()=>{let e=this.div(``);return e.append(this.colorRow(r,e=>n.restyle({[i]:e}),a,t)),e}),u=(e,t,r,i,a,o,s,l=e=>e)=>c(e,a(r),t,()=>{let e=this.div(``);return e.append(this.row(...i.map(e=>this.button(a(e),s(e),()=>{n.restyle({[o]:l(e)}),this.hidePop(),this.lastProps=``,this.refresh()},{active:e===r})))),e}),d=(e,t,n,r)=>s.push(this.button(e,t,r,{active:n}));if(o?.type===`shape`)u(`kind`,r.shape,o.shape,hF,oR,`shape`,e=>r[e]),l(`fill`,r.fill,o.fill,`fill`,!0),l(`stroke`,r.stroke,o.stroke,`stroke`,!0),u(`style`,r.lineStyle,o.strokeStyle,[`solid`,`dash`,`none`],e=>oR(e===`none`?`noLine`:e),`strokeStyle`,e=>e===`none`?r.noLine:r[e]),u(`width`,r.thickness,String(o.strokeWidth),[`1`,`2`,`4`,`6`],e=>``,`strokeWidth`,e=>`${r.thickness} ${e}`,Number),d(`${r.scribbled}`,r.scribbled,o.rough,()=>{n.restyle({rough:!o.rough}),this.lastProps=``,this.refresh()}),l(`textColor`,r.textColor,o.textColor,`textColor`,!1);else if(o?.type===`connector`){u(`mode`,r.connector,o.mode,gF,oR,`mode`,e=>r[e]),l(`stroke`,r.stroke,o.stroke,`stroke`,!1),u(`style`,r.lineStyle,o.strokeStyle===`none`?`solid`:o.strokeStyle,[`solid`,`dash`],oR,`strokeStyle`,e=>r[e]);let e=e=>oR(e===`triangle`?`triangleEnd`:e===`diamond`?`diamondEnd`:e);u(`start`,r.startArrow,o.startArrow,_F,t=>`${e(t)}`,`startArrow`,e=>e),u(`end`,r.endArrow,o.endArrow,_F,e,`endArrow`,e=>e)}else o?.type===`brush`?l(`color`,r.stroke,o.color,`color`,!1):o?.type===`text`?(l(`color`,r.textColor,o.color,`color`,!1),u(`size`,r.fontSize,String(o.fontSize),[`16`,`24`,`32`,`48`,`64`],e=>`${e}`,`fontSize`,e=>`${r.fontSize} ${e}`,Number),u(`font`,r.font,o.font||`sans`,[`sans`,`serif`,`mono`],e=>`Aa`,`font`,e=>r[e],e=>e===`sans`?``:e),u(`align`,r.alignLeft,o.align,[`left`,`center`,`right`],e=>iR(`align-${e}`),`align`,e=>r[e===`left`?`alignLeft`:e===`center`?`alignCenter`:`alignRight`]),d(iR(`bold`),r.bold,o.bold,()=>{n.restyle({bold:!o.bold}),this.lastProps=``,this.refresh()})):o?.type===`note`||o?.type===`frame`?l(`bg`,r.background,o.background,`background`,!0):o?.type===`mindmap`?(u(`layout`,r.layout,o.layout,vF,e=>oR(e),`layout`,e=>r[e===`right`?`layoutRight`:e===`left`?`layoutLeft`:`layoutRadial`]),l(`color`,r.stroke,o.color,`color`,!1),n.activeNode?.map===o.id&&s.push(this.button(`+ ${r.addChild}`,r.addChild,()=>n.mindmapAdd(`child`),{cls:`dw-cv-wide`}))):o?.type===`embed`&&e.length===1&&s.push(this.button(iR(`open`),r.openLink,()=>window.open(o.url,`_blank`,`noopener,noreferrer`)));t.append(...s),i&&e.length===1&&t.append(a()),s.length&&t.append(this.sep());let f=e.filter(e=>e.type===`group`);e.length>1&&!f.length&&t.append(this.button(iR(`group`),r.group,()=>n.group())),f.length&&t.append(this.button(iR(`layers`),r.ungroup,()=>n.ungroup()));let p=e.every(e=>e.type===`note`&&e.page);t.append(this.button(iR(`arrow-up`),r.bringFront,()=>n.reorder(`front`)),this.button(iR(`send-back`),r.sendBack,()=>n.reorder(`back`))),p||t.append(this.button(iR(`copy`),r.duplicate,()=>n.duplicate()),this.button(iR(`trash`),r.delete,()=>n.deleteSelection(),{cls:`dw-cv-danger`}))}toast(e){let t=this.div(`dw-cv-ui dw-cv-toast`);t.setAttribute(`role`,`status`),t.textContent=e,this.v.root.append(t),setTimeout(()=>t.remove(),2600)}presentBar(){let e=this.v,t=e.labels,n=this.div(`dw-cv-ui dw-cv-presentbar`),r=this.div(`dw-cv-step`);return r.setAttribute(`aria-live`,`polite`),n.append(this.button(iR(`chevron-left`),t.presentPrevious,()=>e.presentStep(-1)),r,this.button(iR(`chevron-right`),t.presentNext,()=>e.presentStep(1)),this.button(iR(`close`),t.presentExit,()=>e.stopPresenting())),e.root.append(n),this.hidePop(),this.refresh(),n}presentStep(e,t){let n=this.v.root.querySelector(`.dw-cv-step`);n&&(n.textContent=this.v.labels.presentStep.replace(`{n}`,String(e+1)).replace(`{total}`,String(t)))}};function lR(e){let t=getComputedStyle(e),n=(e,n)=>t.getPropertyValue(e).trim()||n,r=n(`--dw-surface`,`#ffffff`),i=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return null;let n=t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))},a=(e,t,n)=>{let r=i(e),a=i(t);return!r||!a?e:`#${r.map((e,t)=>Math.round(e*n+a[t]*(1-n)).toString(16).padStart(2,`0`)).join(``)}`};return(e,t)=>{if(e===`none`)return`none`;if(e===`ink`)return t===`fill`?n(`--dw-surface-sunken`,`#f3f3f1`):n(`--dw-ink`,`#1d1f1e`);if(e===`paper`)return t===`fill`?n(`--dw-surface-raised`,`#ffffff`):r;let i=n(`--dw-c-${e}`,`#888888`);return t===`fill`?a(i,r,.22):i}}function uR(e){let t=[],n=e=>(e.content??[]).map(e=>e.type===`text`?e.text??``:e.type===`hardBreak`?` -`:n(e)).join(``),r=(e,i)=>{for(let a of e)if(a.type===`heading`){let e=Number(a.attrs?.level)||1;t.push({text:n(a),size:[0,26,21,18,16,16,16][e]??16,weight:650})}else if(a.type===`paragraph`)t.push({text:i+n(a),size:15,weight:400});else if(a.type===`listItem`||a.type===`taskItem`){let e=a.type===`taskItem`?a.attrs?.checked?`☑ `:`☐ `:`• `,[i,...o]=a.content??[];i&&t.push({text:e+n(i),size:15,weight:400}),r(o,` `)}else a.type===`codeBlock`?t.push({text:n(a),size:13,weight:400}):a.content?.length&&r(a.content,i)};return r(e,``),t}function dR(e,t,n,r,i,a,o=400,s=`start`){let c=Math.round(r*1.35);return n.map((n,l)=>`${PL(n)}`).join(``)}async function fR(e){if(e.startsWith(`data:`))return e;try{let t=await fetch(e,{credentials:`include`});if(!t.ok)return null;let n=await t.blob();return await new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:null),t.onerror=()=>e(null),t.readAsDataURL(n)})}catch{return null}}async function pR(e){let t=lR(e.root),n=e.elements.filter(e=>e.type!==`group`),r=HP(VP(n.map(t=>e.boxOf(t)))??{x:0,y:0,w:400,h:300},32),i=t(`ink`,`line`),a=[];for(let r of n){let n=e.boxOf(r),o=r.rotate?` rotate(${r.rotate} ${n.w/2} ${n.h/2})`:``,s=e=>`${e}`;switch(r.type){case`shape`:{let e=ZF(r.text,r.fontSize,Math.max(20,n.w-16)),i=Math.round(r.fontSize*1.35),o=n.h/2-e.length*i/2-r.fontSize*.25;a.push(s(HL(r,t)+(r.text?dR(n.w/2,o,e,r.fontSize,t(r.textColor,`line`),KF,400,`middle`):``)));break}case`text`:{let e=YF(r.font),i=r.w?ZF(r.text,r.fontSize,r.w,e):r.text.split(` -`),o=r.align===`center`?n.w/2:r.align===`right`?n.w:0,c=r.align===`center`?`middle`:r.align===`right`?`end`:`start`;a.push(s(dR(o,0,i,r.fontSize,t(r.color,`line`),e,r.bold?650:400,c)));break}case`connector`:{let n=e.routeOf(r);if(a.push(WL(r,n,t)),r.label){let e=Math.min(240,r.label.length*8+16);a.push(``+dR(n.mid[0],n.mid[1]-12+3,[r.label],13,i,KF,400,`middle`))}break}case`brush`:a.push(s(KL(r,t)));break;case`frame`:a.push(s(``+dR(4,-24,[r.title],13,t(`gray`,`line`),KF,600)));break;case`note`:{let o=e.noteBody(r),c=o?uR(qL(o)):[],l=18,u=``;if(r.page&&e.pageTitle){let t=ZF(e.pageTitle,26,n.w-48,KF,650);u+=dR(24,l-4,t,26,i,KF,650),l+=t.length*35+8}for(let e of c){let t=ZF(e.text,e.size,n.w-48,KF,e.weight);if(u+=dR(24,l,t,e.size,i,KF,e.weight),l+=t.length*Math.round(e.size*1.35)+8,l>n.h-12)break}a.push(s(u));break}case`image`:{let i=await fR(e.resolve(r.src));a.push(s(i?``:``));break}case`embed`:a.push(s(``+dR(16,16,ZF(r.url,13,n.w-32),13,t(`blue`,`line`),KF)));break;case`mindmap`:{let n=e.layoutOf(r),o=t(r.color,`line`),s=t(r.color,`fill`),c=n.edges.map(e=>``).join(``);for(let e of n.boxes.values()){let n=e.depth===0?18:15,a=e.depth===0?600:400,l=e.depth===0?o:e.depth===1?s:t(`paper`,`line`),u=e.depth===0?t(`paper`,`line`):i;c+=``;let d=ZF(r.nodes[e.id]?.text||` `,n,260,KF,a);c+=dR(e.x+e.w/2,e.y+(e.h-d.length*Math.round(n*1.4))/2-2,d,n,u,KF,a,`middle`)}a.push(`${c}`);break}}}return{svg:`${a.join(``)}`,box:r}}async function mR(e,t){let{svg:n,box:r}=await pR(t),i=new Blob([n],{type:`image/svg+xml`});if(e===`svg`)return i;let a=Math.min(2,8192/Math.max(r.w,r.h,1)),o=URL.createObjectURL(i);try{let e=await new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>t(Error(`could not draw the canvas`)),n.src=o}),t=document.createElement(`canvas`);t.width=Math.ceil(r.w*a),t.height=Math.ceil(r.h*a);let n=t.getContext(`2d`);if(!n)throw Error(`could not draw the canvas`);return n.drawImage(e,0,0,t.width,t.height),await new Promise((e,n)=>t.toBlob(t=>t?e(t):n(Error(`could not draw the canvas`)),`image/png`))}finally{URL.revokeObjectURL(o)}}var hR=.1,gR=4,_R=`http://www.w3.org/2000/svg`,vR=e=>e instanceof HTMLElement&&(e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`),yR=class{opts;store;labels;root;styles;editable;tool=`select`;shapeKind;selected=new Set;activeNode=null;editing=null;entered=null;world;overlay;ui;view={x:0,y:0,zoom:1};rendered=new Map;measured=new Map;layouts=new Map;routes=new Map;previews=new Map;drag=null;guides=[];marquee=null;hover=null;raf=0;spaceDown=!1;pointers=new Map;pinch=null;presenting=null;comments=[];activeComment=``;resize=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>this.onResize(e));unsub;cleanups=[];saveTimer;constructor(e,t){this.opts=t,this.labels=t.labels??dF,this.editable=t.editable,this.styles=PF(t.styles),this.shapeKind=this.styles.shape.shape,this.store=new tR(t.doc,{undo:t.undo!==!1}),this.root=document.createElement(`div`),this.root.className=`dw-cv`,this.root.tabIndex=0,this.root.setAttribute(`role`,`application`),this.root.dataset.testid=`edgeless-canvas`,this.world=document.createElement(`div`),this.world.className=`dw-cv-world`,this.overlay=document.createElementNS(_R,`svg`),this.overlay.classList.add(`dw-cv-overlay`),this.root.append(this.world,this.overlay),e.append(this.root),this.ui=new cR(this),this.root.classList.toggle(`dw-cv-readonly`,!this.editable),this.unsub=this.store.onChange(()=>this.schedule()),this.listen(),this.render(),this.restoreView()||this.fit(void 0,!1),this.applyView()}destroy(){cancelAnimationFrame(this.raf),clearTimeout(this.saveTimer),this.saveView(),this.unsub(),this.resize?.disconnect();for(let e of this.cleanups)e();for(let e of this.rendered.values())e.note?.destroy();this.rendered.clear(),this.ui.destroy(),this.store.destroy(),this.root.remove()}setEditable(e){if(e!==this.editable){this.editable=e,this.root.classList.toggle(`dw-cv-readonly`,!e),e||(this.stopEditing(),this.tool=`select`);for(let t of this.rendered.values())t.note?.setEditable(e);this.ui.refresh()}}get(e){return this.store.get(e)}elements(){return this.store.elements()}boxOf(e){switch(e.type){case`note`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:e.w,h:t?.h??e.h}}case`text`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:t?.w??e.w,h:t?.h??e.h}}case`group`:return VP(this.elements().filter(t=>t.group===e.id).map(e=>this.outerBox(e)))??{x:e.x,y:e.y,w:0,h:0};case`mindmap`:{let t=this.layoutOf(e);return{x:e.x+t.bounds.x,y:e.y+t.bounds.y,w:t.bounds.w,h:t.bounds.h}}case`connector`:{let t=this.routeOf(e),n=t.points.map(e=>e[0]),r=t.points.map(e=>e[1]);return GP([Math.min(...n),Math.min(...r)],[Math.max(...n),Math.max(...r)])}default:return{x:e.x,y:e.y,w:e.w,h:e.h}}}outerBox(e){let t=this.boxOf(e);return e.rotate?qP(t,e.rotate):t}layoutOf(e){let t=this.layouts.get(e.id),n=JSON.stringify([e.layout,e.nodes]);return t&&t.key===n||(t=rI(e.nodes,e.layout,QF),t.key=n,this.layouts.set(e.id,t)),t}routeOf(e){let t=eF(e,e=>{let t=this.get(e);return!t||t.type===`connector`?null:{box:this.outerBox(t),ellipse:t.type===`shape`&&t.shape===`ellipse`}});return iF(e.mode,t[0],t[1])}selection(){return[...this.selected].map(e=>this.get(e)).filter(e=>!!e)}expanded(e){let t=new Set,n=this.elements();for(let r of e){t.add(r);for(let e of n)e.group===r&&t.add(e.id)}return[...t]}schedule(){this.raf||=requestAnimationFrame(()=>{this.raf=0,this.render()})}render(){let e=this.elements(),t=new Set,n=null;for(let r of e){t.add(r.id);let e=this.rendered.get(r.id);e&&e.type!==r.type&&(e.note?.destroy(),e.el.remove(),e=void 0),e||(e={el:document.createElement(`div`),key:``,type:r.type},e.el.className=`dw-cv-el dw-cv-${r.type}`,e.el.dataset.id=r.id,this.rendered.set(r.id,e),(r.type===`note`||r.type===`text`)&&this.resize?.observe(e.el));let i=this.keyOf(r);e.key===i||this.editing?.id===r.id&&this.stopEditingFn&&r.type!==`note`||(this.draw(e,r),e.key=i),e.el.classList.toggle(`dw-cv-selected`,this.selected.has(r.id)),e.el.classList.toggle(`dw-cv-editing`,this.editing?.id===r.id);let a=n?n.nextElementSibling:this.world.firstElementChild;a!==e.el&&this.world.insertBefore(e.el,a),n=e.el}for(let[e,n]of this.rendered)t.has(e)||(n.note?.destroy(),this.resize?.unobserve(n.el),n.el.remove(),this.rendered.delete(e),this.measured.delete(e),this.selected.delete(e));this.editing&&!t.has(this.editing.id)&&(this.editing=null),this.drawOverlay(),this.ui.refresh()}keyOf(e){if(e.type===`connector`){let t=this.routeOf(e);return this.routes.set(e.id,t),JSON.stringify(e)+t.d}return e.type===`note`&&e.page?JSON.stringify(e)+(this.opts.pageTitle?.()??``):JSON.stringify(e)}place(e,t,n=0,r=!1){e.style.transform=`translate(${t.x}px, ${t.y}px)${n?` rotate(${n}deg)`:``}`,e.style.width=r?``:`${t.w}px`,e.style.height=r?``:`${t.h}px`}draw(e,t){let n=e.el,r=this.editing?.id===t.id;switch(t.type){case`shape`:{this.place(n,t,t.rotate);let e=r?n.querySelector(`.dw-cv-label`):null;n.innerHTML=`${HL(t,NL)}`;let i=e??document.createElement(`div`);i.className=`dw-cv-label`,e||(i.textContent=t.text),i.style.color=NL(t.textColor,`line`),i.style.fontSize=`${t.fontSize}px`,n.append(i);return}case`text`:{n.style.transform=`translate(${t.x}px, ${t.y}px)${t.rotate?` rotate(${t.rotate}deg)`:``}`,n.style.width=t.w?`${t.w}px`:``,n.style.height=``;let e=n.querySelector(`.dw-cv-textbody`);e||(e=document.createElement(`div`),e.className=`dw-cv-textbody`,n.append(e)),r||(e.textContent=t.text),e.dataset.placeholder=this.labels.textPlaceholder,Object.assign(e.style,{color:NL(t.color,`line`),fontSize:`${t.fontSize}px`,fontFamily:YF(t.font),textAlign:t.align,fontWeight:t.bold?`650`:``,whiteSpace:t.w?`pre-wrap`:`pre`});return}case`connector`:{let e=this.routes.get(t.id)??this.routeOf(t),i=this.boxOf(t),a=24+t.strokeWidth*3,o={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2};this.place(n,o);let s=``,c=t.label||r;n.innerHTML=`${WL(t,e,NL)}${s}`+(c?`
${PL(t.label)}
`:``);return}case`brush`:this.place(n,t,t.rotate),n.innerHTML=`${KL(t,NL).replace(``;return;case`note`:this.drawNote(e,t);return;case`frame`:{this.place(n,t);let e=r?n.querySelector(`.dw-cv-frametitle`):null;n.innerHTML=``;let i=e??document.createElement(`div`);i.className=`dw-cv-frametitle`,e||(i.textContent=t.title||this.labels.frameTitle),n.append(i);return}case`image`:{this.place(n,t,t.rotate);let e=this.opts.files?.resolve(t.src)??t.src,r=n.querySelector(`img`);r||(r=document.createElement(`img`),r.draggable=!1,n.replaceChildren(r)),r.getAttribute(`src`)!==e&&(r.src=e),r.alt=t.alt;return}case`embed`:this.drawEmbed(n,t);return;case`group`:n.style.display=`none`;return;case`mindmap`:this.drawMindmap(n,t);return}}drawNote(e,t){let n=e.el;if(n.style.transform=`translate(${t.x}px, ${t.y}px)`,n.style.width=`${t.w}px`,n.style.height=``,n.style.setProperty(`--dw-cv-note-bg`,NL(t.background,`fill`)),n.classList.toggle(`dw-cv-pagenote`,t.page),!e.note){let r=document.createElement(`div`);r.className=`dw-cv-notehead`;let i=document.createElement(`div`);i.className=`dw-cv-notebody`,n.replaceChildren(r,i);let a=t.page?this.opts.doc.getXmlFragment(`default`):this.store.body(t.id);if(a)try{e.note=this.opts.notes.mount(i,{id:t.id,page:t.page,fragment:a,doc:this.opts.doc,editable:this.editable})}catch(e){this.opts.onError?.(e)}}let r=n.querySelector(`.dw-cv-notehead`);r&&(r.textContent=t.page?this.opts.pageTitle?.()||this.labels.pageNote:``)}drawEmbed(e,t){this.place(e,t);let n=this.opts.embedSource?.(t.url)??null;if(n){if(e.querySelector(`iframe`)?.getAttribute(`src`)===n.src)return;let r=document.createElement(`iframe`);r.src=n.src,r.title=t.url,r.allow=`fullscreen; picture-in-picture; encrypted-media`,r.referrerPolicy=`strict-origin-when-cross-origin`,r.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`),e.replaceChildren(r);return}let r=this.previews.get(t.url);r===void 0&&this.opts.links&&(this.previews.set(t.url,`loading`),this.opts.links.preview(t.url).then(e=>this.previews.set(t.url,e)).catch(()=>this.previews.set(t.url,null)).finally(()=>{let e=this.rendered.get(t.id);e&&(e.key=``),this.schedule()}),r=`loading`);let i=r&&r!==`loading`?r:null,a=t.url;try{a=new URL(t.url).hostname}catch{}let o=i?.image?``:``;e.innerHTML=`${o}${PL(i?.title||a)}${i?.description?`${PL(i.description)}`:``}${PL(i?.site||a)}`}drawMindmap(e,t){let n=this.layoutOf(t),r=n.bounds;this.place(e,{x:t.x+r.x,y:t.y+r.y,w:r.w,h:r.h});let i=NL(t.color,`line`),a=NL(t.color,`fill`),o=n.edges.map(e=>``).join(``),s=this.editing?.id===t.id?this.editing.node:void 0,c=s?e.querySelector(`[data-node="${s}"]`):null,l=[...n.boxes.values()].map(e=>{let n=e.depth===0?`dw-cv-node dw-cv-root`:`dw-cv-node`,o=this.activeNode?.map===t.id&&this.activeNode.node===e.id?` dw-cv-active`:``,s=`left:${e.x-r.x}px;top:${e.y-r.y}px;width:${e.w}px;height:${e.h}px;${e.depth===0?`background:${i};color:var(--dw-surface)`:e.depth===1?`background:${a};border-color:${i}`:`border-color:${i}`}`;return`
${PL(t.nodes[e.id]?.text??``)}
`});e.innerHTML=`${o}${l.join(``)}`,c&&s&&e.querySelector(`[data-node="${s}"]`)?.replaceWith(c)}onResize(e){let t=!1;for(let n of e){let e=n.target,r=e.dataset.id;if(!r)continue;let i={w:e.offsetWidth,h:e.offsetHeight},a=this.measured.get(r);a&&a.w===i.w&&a.h===i.h||(this.measured.set(r,i),t=!0)}if(t){for(let e of this.rendered.values())e.type===`connector`&&(e.key=``);this.schedule()}}toScreen([e,t]){return[e*this.view.zoom+this.view.x,t*this.view.zoom+this.view.y]}toWorld(e,t){let n=this.root.getBoundingClientRect();return[(e-n.left-this.view.x)/this.view.zoom,(t-n.top-this.view.y)/this.view.zoom]}get zoom(){return this.view.zoom}selectionScreenBox(){let e=VP(this.selection().map(e=>this.outerBox(e)));if(!e)return null;let[t,n]=this.toScreen([e.x,e.y]);return{x:t,y:n,w:e.w*this.view.zoom,h:e.h*this.view.zoom}}drawOverlay(){let e=[],t=this.view.zoom,n=(e,t)=>{let n=BP(e);return[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>this.toScreen(KP(e,n,t)).join(`,`)).join(` `)};if(this.entered){let t=this.get(this.entered);t&&e.push(``)}if(this.hover&&this.hover!==this.editing?.id){let t=this.get(this.hover);t&&e.push(``)}let r=this.presenting?[]:this.selection();for(let t of r)if(t.type===`connector`){let n=this.routes.get(t.id)??this.routeOf(t);e.push(``)}else e.push(``);if(this.editable&&!this.presenting&&r.length&&!this.editing){let i=r.length===1?r[0]:null;if(i?.type===`connector`){let t=this.routes.get(i.id)??this.routeOf(i);for(let[n,r]of[[`source`,t.points[0]],[`target`,t.points[t.points.length-1]]]){let[t,i]=this.toScreen(r);e.push(``)}}else if(r.some(OF)&&i?.type!==`mindmap`){let a=i?i.rotate:0,o=i?this.boxOf(i):VP(r.map(e=>this.outerBox(e)));r.length>1&&e.push(``);let s=BP(o),c=[[`nw`,[o.x,o.y]],[`n`,[o.x+o.w/2,o.y]],[`ne`,[o.x+o.w,o.y]],[`e`,[o.x+o.w,o.y+o.h/2]],[`se`,[o.x+o.w,o.y+o.h]],[`s`,[o.x+o.w/2,o.y+o.h]],[`sw`,[o.x,o.y+o.h]],[`w`,[o.x,o.y+o.h/2]]],l=i?.type===`note`;for(let[n,r]of c){if(l&&n!==`e`&&n!==`w`||o.w*t<24&&(n===`n`||n===`s`)||o.h*t<24&&(n===`e`||n===`w`))continue;let[i,c]=this.toScreen(KP(r,s,a));e.push(``)}if(i&&kF(i)){let[n,r]=this.toScreen(KP([o.x+o.w/2,o.y-28/t],s,a));e.push(``)}}}if(this.presenting||this.drawComments(e,n),this.marquee){let[n,r]=this.toScreen([this.marquee.x,this.marquee.y]);e.push(``)}for(let t of this.guides){let n=this.toScreen(t.axis===`x`?[t.value,t.from]:[t.from,t.value]),r=this.toScreen(t.axis===`x`?[t.value,t.to]:[t.to,t.value]);e.push(``)}this.overlay.innerHTML=e.join(``),this.ui.place()}applyView(){let{x:e,y:t,zoom:n}=this.view;this.world.style.transform=`translate(${e}px, ${t}px) scale(${n})`;let r=24*n;this.root.style.backgroundSize=`${r}px ${r}px`,this.root.style.backgroundPosition=`${e}px ${t}px`,this.root.style.setProperty(`--dw-cv-zoom`,String(n)),this.drawOverlay(),this.ui.zoomChanged(),clearTimeout(this.saveTimer),this.saveTimer=setTimeout(()=>this.saveView(),500)}saveView(){if(this.opts.viewKey)try{localStorage.setItem(this.opts.viewKey,JSON.stringify(this.view))}catch{}}restoreView(){if(!this.opts.viewKey)return!1;try{let e=JSON.parse(localStorage.getItem(this.opts.viewKey)??`null`);if(e&&[e.x,e.y,e.zoom].every(e=>typeof e==`number`&&Number.isFinite(e))&&e.zoom>0)return this.view={x:e.x,y:e.y,zoom:Math.min(gR,Math.max(hR,e.zoom))},!0}catch{}return!1}zoomAt(e,t){let n=Math.min(gR,Math.max(hR,e)),r=this.root.getBoundingClientRect(),[i,a]=t??[r.width/2,r.height/2],o=(i-this.view.x)/this.view.zoom,s=(a-this.view.y)/this.view.zoom;this.view={zoom:n,x:i-o*n,y:a-s*n},this.applyView()}zoomBy(e){this.zoomAt(this.view.zoom*e)}fit(e,t=!0,n=48){let r=e??VP(this.elements().map(e=>this.outerBox(e))),i=this.root.getBoundingClientRect(),a=i.width||800,o=i.height||600;if(!r)this.view={x:a/2,y:o/3,zoom:1};else{let t=Math.min(gR,Math.max(hR,Math.min((a-n*2)/Math.max(r.w,1),(o-n*2)/Math.max(r.h,1),e?gR:1)));this.view={zoom:t,x:a/2-(r.x+r.w/2)*t,y:o/2-(r.y+r.h/2)*t},!e&&r.h*t>o&&(this.view.y=n-r.y*t)}t&&this.applyView()}animateTo(e){let t={...this.view},n=performance.now(),r=i=>{let a=Math.min(1,(i-n)/350),o=1-(1-a)**3;this.view={x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o,zoom:t.zoom+(e.zoom-t.zoom)*o},this.applyView(),a<1&&requestAnimationFrame(r)};requestAnimationFrame(r)}setTool(e){(this.editable||e===`select`||e===`hand`)&&(this.stopEditing(),this.tool=e,e!==`select`&&this.clearSelection(),this.root.dataset.tool=e,this.ui.refresh())}setShapeKind(e){this.shapeKind=e,this.setStyle(`shape`,{shape:e}),this.setTool(`shape`)}setStyle(e,t){this.styles={...this.styles,[e]:{...this.styles[e],...t}},this.opts.onStyles?.(this.styles)}restyle(e){let t=[];for(let n of this.selection()){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e in n));if(!Object.keys(r).length)continue;t.push([n.id,r]);let i=n.type;if(i in this.styles){let e=Object.fromEntries(Object.entries(r).filter(([e])=>e in this.styles[i]));Object.keys(e).length&&!(n.type===`note`&&n.page)&&this.setStyle(i,e)}}this.store.updateMany(t)}select(e,t=!1){t||this.selected.clear();for(let t of e)this.selected.add(t);this.activeNode&&!this.selected.has(this.activeNode.map)&&(this.activeNode=null),this.refreshSelection()}clearSelection(){(this.selected.size||this.activeNode||this.entered)&&(this.selected.clear(),this.activeNode=null,this.entered=null,this.refreshSelection())}refreshSelection(){for(let[e,t]of this.rendered)t.el.classList.toggle(`dw-cv-selected`,this.selected.has(e)),t.type===`mindmap`&&(t.key=``);this.schedule(),this.drawOverlay(),this.ui.refresh()}pick(e){let t=this.get(e);return t?.group&&this.entered!==t.group&&this.get(t.group)?t.group:e}hit(e){if(!(e instanceof Element)||!this.world.contains(e))return null;let t=e.closest(`[data-id]`);if(!t?.dataset.id)return null;let n=e.closest(`[data-node]`)?.dataset.node;return{id:t.dataset.id,node:n}}connectableAt(e,t,n){for(let r of document.elementsFromPoint(e,t)){let e=this.hit(r);if(!e||n.has(e.id))continue;let t=this.get(e.id);if(t&&AF(t))return t}return null}listen(){let e=(e,t,n,r)=>{e.addEventListener(t,n,r),this.cleanups.push(()=>e.removeEventListener(t,n,r))};e(this.root,`pointerdown`,e=>this.onDown(e)),e(this.root,`pointermove`,e=>this.onMove(e)),e(this.root,`pointerup`,e=>this.onUp(e)),e(this.root,`pointercancel`,e=>this.onUp(e)),e(this.root,`dblclick`,e=>this.onDouble(e)),e(this.root,`wheel`,e=>this.onWheel(e),{passive:!1}),e(this.root,`keydown`,e=>this.onKey(e)),e(this.root,`keyup`,e=>{e.key===` `&&(this.spaceDown=!1,this.root.classList.remove(`dw-cv-panning`))}),e(document,`copy`,e=>this.onCopy(e,!1)),e(document,`cut`,e=>this.onCopy(e,!0)),e(document,`paste`,e=>this.onPaste(e)),e(this.root,`dragover`,e=>{this.editable&&e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),e(this.root,`drop`,e=>{let t=[...e.dataTransfer?.files??[]].filter(e=>e.type.startsWith(`image/`));this.editable&&t.length&&(e.preventDefault(),this.addImages(t,this.toWorld(e.clientX,e.clientY)))}),e(document,`fullscreenchange`,()=>{!document.fullscreenElement&&this.presenting&&this.stopPresenting()}),e(this.root,`click`,e=>{e.target.closest?.(`a.dw-cv-card`)&&this.editable&&e.preventDefault()})}inEditor(e){if(!(e instanceof Element))return!1;if(e.closest(`.dw-cv-ui`))return!0;if(this.editing){let t=this.rendered.get(this.editing.id);if(t&&t.el.contains(e)&&(e.closest(`[contenteditable=true]`)||e.closest(`.dw-cv-notebody`)||e.closest(`iframe`)))return!0}return!(this.editable||!e.closest(`.dw-cv-notebody, a.dw-cv-card`))}onDown(e){let t=e.target instanceof Element?e.target.closest(`[data-comment]`):null;if(t?.dataset.comment){e.preventDefault(),this.opts.onCommentSelect?.(t.dataset.comment);return}if(this.inEditor(e.target)||e.button===2)return;if(e.preventDefault(),this.root.focus({preventScroll:!0}),this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pointers.size===2){this.cancelDrag();let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect();this.pinch={dist:Math.hypot(e[0]-t[0],e[1]-t[1]),mid:[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],zoom:this.view.zoom,vx:this.view.x,vy:this.view.y};return}if(this.pointers.size>2)return;this.editing&&this.stopEditing();let n=this.toWorld(e.clientX,e.clientY),r=e.pointerType===`touch`,i=()=>{this.drag={kind:`pan`,sx:e.clientX,sy:e.clientY,vx:this.view.x,vy:this.view.y},this.root.classList.add(`dw-cv-panning`)};if(this.root.setPointerCapture?.(e.pointerId),e.button===1||this.tool===`hand`||this.spaceDown||this.presenting)return e.preventDefault(),i();let a=e.target;if(!this.editable){let e=this.opts.onComment&&this.tool===`select`?this.hit(a):null;if(e){let t=this.pick(e.id);this.select([t]);return}return i()}switch(this.tool){case`pen`:{let t=document.createElementNS(_R,`svg`);t.classList.add(`dw-cv-temp`),this.world.append(t),this.drag={kind:`pen`,points:[[n[0],n[1],e.pressure||.5]],temp:t};return}case`eraser`:this.drag={kind:`erase`,hits:new Set},this.erase(e);return;case`shape`:case`frame`:this.drag={kind:`create`,type:this.tool,start:n,id:null};return;case`connector`:{let t=this.connectableAt(e.clientX,e.clientY,new Set),r=t?this.endOn(t,n):{x:n[0],y:n[1]},i=this.store.add({type:`connector`,...this.styles.connector,source:r,target:{x:n[0],y:n[1]}});this.drag={kind:`end`,id:i,side:`target`};return}case`note`:this.addNote(n);return;case`text`:this.addText(n);return;case`mindmap`:this.addMindmap(n);return}let o=a.dataset?.handle,s=a.dataset?.end;if(s){let e=this.selection()[0];e?.type===`connector`&&(this.store.undo?.stopCapturing(),this.drag={kind:`end`,id:e.id,side:s});return}if(o===`rotate`){let e=this.selection()[0],t=BP(this.boxOf(e));this.store.undo?.stopCapturing(),this.drag={kind:`rotate`,id:e.id,c:t,a0:Math.atan2(n[1]-t[1],n[0]-t[0]),r0:e.rotate};return}if(o){let e=this.selection(),t=e.length===1?e[0]:null,n=new Map(this.expanded(this.selected).map(e=>[e,this.get(e)]));for(let[e,t]of n){let r=this.measured.get(e);t.type===`text`&&r&&n.set(e,{...t,w:r.w,h:r.h}),t.type===`note`&&r&&n.set(e,{...t,h:r.h})}this.store.undo?.stopCapturing(),this.drag={kind:`resize`,handle:o,box:t?this.boxOf(t):VP(e.map(e=>this.outerBox(e))),deg:t?t.rotate:0,orig:n,keep:e.some(e=>e.type===`image`||e.type===`text`||e.type===`brush`)||e.length>1};return}let c=this.hit(a);if(c){let t=this.pick(c.id),r=this.get(t);if(r?.type===`mindmap`&&c.node){this.activeNode={map:t,node:c.node};let e=this.rendered.get(t);e&&(e.key=``)}else r?.type!==`mindmap`&&(this.activeNode=null);e.shiftKey?(this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.refreshSelection()):this.selected.has(t)?this.refreshSelection():this.select([t]),this.startMove(n,t)}else{if(r)return i();this.entered=null,this.drag={kind:`marquee`,start:n,add:e.shiftKey,base:e.shiftKey?new Set(this.selected):new Set},e.shiftKey||this.clearSelection()}}startMove(e,t){let n=this.expanded(this.selected);for(let e of[...n]){let t=this.get(e);if(t?.type===`frame`)for(let e of this.elements())e.type!==`frame`&&!n.includes(e.id)&&WP(t,this.outerBox(e))&&n.push(...this.expanded([e.id]))}let r=[...new Set(n)].filter(e=>this.get(e)?.type!==`group`),i=new Map(r.map(e=>[e,this.get(e)])),a=VP(r.map(e=>this.outerBox(this.get(e))))??{x:e[0],y:e[1],w:0,h:0};this.store.undo?.stopCapturing(),this.drag={kind:`move`,start:e,ids:r,orig:i,box:a,moved:!1,clickId:t}}endOn(e,t){let n=this.outerBox(e),r=uF(n,t,14/this.view.zoom);return r?{id:e.id,pos:[(r[0]-n.x)/Math.max(n.w,1),(r[1]-n.y)/Math.max(n.h,1)]}:{id:e.id}}onMove(e){if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect(),r=Math.hypot(e[0]-t[0],e[1]-t[1]),i=[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],a=this.pinch,o=Math.min(gR,Math.max(hR,a.zoom*r/Math.max(a.dist,1))),s=(a.mid[0]-a.vx)/a.zoom,c=(a.mid[1]-a.vy)/a.zoom;this.view={zoom:o,x:i[0]-s*o,y:i[1]-c*o},this.applyView();return}let t=this.drag,n=this.toWorld(e.clientX,e.clientY);if(t)switch(t.kind){case`pan`:this.view={...this.view,x:t.vx+e.clientX-t.sx,y:t.vy+e.clientY-t.sy},this.applyView();return;case`move`:{let r=n[0]-t.start[0],i=n[1]-t.start[1];if(!t.moved&&Math.hypot(r,i)*this.view.zoom<3)return;if(t.moved=!0,e.altKey)this.guides=[];else{let e=new Set(t.ids),n=this.visibleBoxes().filter(([t])=>!e.has(t)).map(([,e])=>e),a=lF({...t.box,x:t.box.x+r,y:t.box.y+i},n,6/this.view.zoom);r+=a.dx,i+=a.dy,this.guides=a.guides}let a=[];for(let[e,n]of t.orig)if(n.type===`connector`){let t={};for(let e of[`source`,`target`]){let a=n[e];a.id||(t[e]={x:(a.x??0)+r,y:(a.y??0)+i})}Object.keys(t).length&&a.push([e,t])}else a.push([e,{x:n.x+r,y:n.y+i}]);this.store.updateMany(a);return}case`marquee`:{this.marquee=GP(t.start,n);let e=new Set(t.base),r=this.marquee;for(let t of this.elements()){if(t.group&&this.get(t.group))continue;let n=this.outerBox(t);(t.type===`frame`?WP(r,n):UP(r,n))&&e.add(t.id)}for(let t of this.elements().filter(e=>e.type===`group`))UP(r,this.boxOf(t))&&e.add(t.id);this.selected.clear();for(let t of e)this.selected.add(t);this.refreshSelection();return}case`resize`:this.doResize(t,n,e.shiftKey);return;case`rotate`:{let r=t.r0+(Math.atan2(n[1]-t.c[1],n[0]-t.c[0])-t.a0)*180/Math.PI;e.shiftKey&&(r=Math.round(r/15)*15),r=(r%360+360)%360,this.store.update(t.id,{rotate:Math.round(r*10)/10});return}case`create`:{let r=GP(t.start,n);if(!t.id&&r.w*this.view.zoom<4&&r.h*this.view.zoom<4)return;e.shiftKey&&(r.w=r.h=Math.max(r.w,r.h)),t.id?this.store.update(t.id,{...r}):t.id=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...r}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...r});return}case`end`:{let r=this.get(t.id);if(r?.type!==`connector`)return;let i=r[t.side===`source`?`target`:`source`],a=new Set([t.id]),o=this.connectableAt(e.clientX,e.clientY,a);this.hover=o?.id??null;let s=o&&o.id!==i.id?this.endOn(o,n):{x:n[0],y:n[1]};this.store.update(t.id,{[t.side]:s});return}case`pen`:t.points.push([n[0],n[1],e.pressure||.5]),t.temp.innerHTML=``;return;case`erase`:this.erase(e);return}else if(this.editable&&this.tool===`connector`){let t=this.connectableAt(e.clientX,e.clientY,new Set);(t?.id??null)!==this.hover&&(this.hover=t?.id??null,this.drawOverlay())}}erase(e){let t=this.drag;if(t?.kind!==`erase`)return;let n=this.toWorld(e.clientX,e.clientY),r=6/this.view.zoom;for(let n of document.elementsFromPoint(e.clientX,e.clientY)){let e=this.hit(n);if(!e)continue;let r=this.get(e.id);r&&r.type!==`note`&&r.type!==`frame`&&(t.hits.add(r.id),this.rendered.get(r.id)?.el.classList.add(`dw-cv-erasing`))}for(let e of this.elements())e.type!==`brush`||t.hits.has(e.id)||YP(n,e.points.map(t=>[t[0]+e.x,t[1]+e.y]))<=r+e.size/2&&(t.hits.add(e.id),this.rendered.get(e.id)?.el.classList.add(`dw-cv-erasing`))}doResize(e,t,n){let r=e.box,i=BP(r),a=KP(t,i,-e.deg),o=r.x,s=r.y,c=r.x+r.w,l=r.y+r.h;e.handle.includes(`w`)&&(o=a[0]),e.handle.includes(`e`)&&(c=a[0]),e.handle.includes(`n`)&&(s=a[1]),e.handle.includes(`s`)&&(l=a[1]);let u=8/this.view.zoom;c-o[e[0]*m,e[1]*h,e[2]??.5])}]);break;case`mindmap`:case`group`:v.push([t,{x:e,y:i}]);break;default:v.push([t,{x:e,y:i,w:n.w*m,h:n.h*h}])}}this.store.updateMany(v)}visibleBoxes(){let e=this.root.getBoundingClientRect(),t=GP(this.toWorld(e.left,e.top),this.toWorld(e.right,e.bottom)),n=[];for(let e of this.elements()){if(e.type===`connector`||e.type===`group`)continue;let r=this.outerBox(e);if(UP(t,r)&&n.push([e.id,r]),n.length>300)break}return n}onUp(e){if(this.pointers.delete(e.pointerId),this.pinch){this.pointers.size<2&&(this.pinch=null);return}let t=this.drag;if(this.drag=null,this.root.classList.remove(`dw-cv-panning`),this.guides=[],this.marquee=null,this.hover=null,!t)return;let n=this.toWorld(e.clientX,e.clientY);switch(t.kind){case`create`:{let e=t.id;if(!e){let r=t.type===`frame`?{w:800,h:600}:{w:140,h:100},i={x:n[0]-r.w/2,y:n[1]-r.h/2,...r};e=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...i}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...i})}this.tool=`select`,this.root.dataset.tool=`select`,this.select([e]);break}case`end`:{let e=this.get(t.id);if(e?.type===`connector`){let n=this.routeOf(e),r=n.points[0],i=n.points[n.points.length-1];Math.hypot(r[0]-i[0],r[1]-i[1])*this.view.zoom<8&&this.tool===`connector`?this.store.remove([t.id]):this.tool===`connector`&&this.select([t.id])}break}case`pen`:{t.temp.remove(),t.points.length<2&&t.points.push([t.points[0][0]+.5,t.points[0][1]+.5,.5]);let e=t.points.map(e=>e[0]),n=t.points.map(e=>e[1]),r=this.styles.brush.size,i=Math.min(...e)-r,a=Math.min(...n)-r,o=Math.max(...e)+r-i,s=Math.max(...n)+r-a;this.store.add({type:`brush`,...this.styles.brush,x:i,y:a,w:o,h:s,points:t.points.map(e=>[Math.round((e[0]-i)*10)/10,Math.round((e[1]-a)*10)/10,Math.round((e[2]??.5)*100)/100])});break}case`erase`:for(let e of t.hits)this.rendered.get(e)?.el.classList.remove(`dw-cv-erasing`);t.hits.size&&this.store.remove(t.hits)}this.drawOverlay(),this.ui.refresh()}cancelDrag(){let e=this.drag;e?.kind===`pen`&&e.temp.remove(),this.drag=null,this.marquee=null,this.guides=[]}onDouble(e){if(this.inEditor(e.target)||!this.editable||this.tool!==`select`)return;let t=this.hit(e.target);if(!t){this.addText(this.toWorld(e.clientX,e.clientY));return}let n=this.get(t.id);n&&(n.group&&this.entered!==n.group&&this.get(n.group)?(this.entered=n.group,this.select([n.id])):(n.type!==`frame`||e.target.closest(`.dw-cv-frametitle`))&&this.startEdit(n.id,t.node))}onWheel(e){if(this.presenting||e.target instanceof Element&&e.target.closest(`.dw-cv-ui`))return;e.preventDefault();let t=this.root.getBoundingClientRect();if(e.ctrlKey||e.metaKey){this.zoomAt(this.view.zoom*Math.exp(-e.deltaY*.01),[e.clientX-t.left,e.clientY-t.top]);return}let n=e.deltaMode===1?16:1,r=e.shiftKey&&!e.deltaX?e.deltaY:e.deltaX,i=e.shiftKey&&!e.deltaX?0:e.deltaY;this.view={...this.view,x:this.view.x-r*n,y:this.view.y-i*n},this.applyView()}onKey(e){if(this.presenting){this.presentKey(e);return}if(vR(e.target)||this.inEditor(e.target))return;let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(e.key===` `&&!t){this.spaceDown=!0,this.root.classList.add(`dw-cv-panning`),e.preventDefault();return}if(t&&(n===`=`||n===`+`))return e.preventDefault(),this.zoomBy(1.25);if(t&&n===`-`)return e.preventDefault(),this.zoomBy(.8);if(e.altKey&&!t&&(e.code===`Digit0`||e.code===`Digit1`||e.code===`Digit2`)){if(e.preventDefault(),e.code===`Digit0`)return this.zoomAt(1);if(e.code===`Digit1`)return this.fit();let t=VP(this.selection().map(e=>this.outerBox(e)));return this.fit(t??void 0)}if(e.key===`Escape`){this.entered?(this.select([this.entered]),this.entered=null):this.selected.size?this.clearSelection():this.setTool(`select`);return}if(!this.editable){!t&&n===`h`&&this.setTool(`hand`),!t&&n===`v`&&this.setTool(`select`);return}if(this.activeNode&&this.mindmapKey(e))return;if(t&&n===`z`){e.preventDefault(),e.shiftKey?this.store.undo?.redo():this.store.undo?.undo();return}if(t&&n===`y`){e.preventDefault(),this.store.undo?.redo();return}if(t&&n===`a`){e.preventDefault(),this.select(this.elements().filter(e=>!e.group||!this.get(e.group)).map(e=>e.id));return}if(t&&n===`d`){e.preventDefault(),this.duplicate();return}if(t&&n===`g`){e.preventDefault(),e.shiftKey?this.ungroup():this.group();return}if((e.key===`Delete`||e.key===`Backspace`)&&this.selected.size){e.preventDefault(),this.deleteSelection();return}if(e.key===`Enter`&&this.selected.size===1){e.preventDefault();let t=[...this.selected][0];this.startEdit(t);return}if(e.key.startsWith(`Arrow`)&&this.selected.size){e.preventDefault();let t=e.shiftKey?10:1,n=e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,r=e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0;this.nudge(n,r);return}if(t||e.altKey)return;let r={v:`select`,h:`hand`,n:`note`,t:`text`,s:`shape`,c:`connector`,p:`pen`,e:`eraser`,f:`frame`,m:`mindmap`};r[n]?(e.preventDefault(),this.setTool(r[n])):n===`i`?this.ui.pickImage():n===`l`&&this.addLink()}nudge(e,t){let n=this.expanded(this.selected),r=[];for(let i of n){let n=this.get(i);if(n&&n.type!==`group`){if(n.type===`connector`){let a={};for(let r of[`source`,`target`]){let i=n[r];i.id||(a[r]={x:(i.x??0)+e,y:(i.y??0)+t})}r.push([i,a])}else r.push([i,{x:n.x+e,y:n.y+t}])}}this.store.updateMany(r)}startEdit(e,t){if(!this.editable)return;let n=this.get(e),r=this.rendered.get(e);if(n&&r){if(n.type===`group`)this.entered=e;else if(n.type===`mindmap`){let i=t??(this.activeNode?.map===e?this.activeNode.node:tI(n.nodes));if(!i)return;this.activeNode={map:e,node:i},this.editing={id:e,node:i},this.draw(r,n);let a=r.el.querySelector(`[data-node="${i}"]`);a&&this.editText(a,n.nodes[i]?.text??``,!0,t=>this.store.updateNode(e,i,{text:t}))}else if(n.type!==`image`&&n.type!==`brush`)switch(this.select([e]),this.editing={id:e,node:t},r.el.classList.add(`dw-cv-editing`),this.drawOverlay(),this.ui.refresh(),n.type){case`note`:r.note?.focus();return;case`embed`:return;case`text`:{let t=r.el.querySelector(`.dw-cv-textbody`);t&&this.editText(t,n.text,!1,t=>t.trim()?this.store.update(e,{text:t}):this.store.remove([e]));return}case`shape`:{let t=r.el.querySelector(`.dw-cv-label`);t&&this.editText(t,n.text,!1,t=>this.store.update(e,{text:t}));return}case`frame`:{let t=r.el.querySelector(`.dw-cv-frametitle`);t&&this.editText(t,n.title,!0,t=>this.store.update(e,{title:t}));return}case`connector`:{this.draw(r,n);let t=r.el.querySelector(`.dw-cv-clabel`);t&&this.editText(t,n.label,!0,t=>this.store.update(e,{label:t}));return}}}}editText(e,t,n,r){e.contentEditable=`true`,e.spellcheck=!0,e.textContent=t,e.classList.add(`dw-cv-typing`);let i=!1,a=n=>{if(i)return;i=!0,this.stopEditingFn=null,e.contentEditable=`false`,e.classList.remove(`dw-cv-typing`),e.removeEventListener(`keydown`,o),e.removeEventListener(`blur`,s),e.removeEventListener(`paste`,c);let a=(e.innerText??e.textContent??``).replace(/\n$/,``),l=this.editing?.id;if(this.editing=null,(n&&a!==t||n&&!a.trim())&&r(a),l){let e=this.rendered.get(l);e&&(e.key=``)}this.schedule(),this.ui.refresh()},o=e=>{e.stopPropagation(),e.key===`Escape`||e.key===`Enter`&&(n||e.ctrlKey||e.metaKey)&&!e.shiftKey?(e.preventDefault(),a(!0),this.root.focus({preventScroll:!0})):e.key===`Tab`&&this.activeNode&&(e.preventDefault(),a(!0),this.mindmapAdd(`child`))},s=()=>a(!0),c=e=>{e.preventDefault(),e.stopPropagation(),document.execCommand(`insertText`,!1,e.clipboardData?.getData(`text/plain`)??``)};e.addEventListener(`keydown`,o),e.addEventListener(`blur`,s),e.addEventListener(`paste`,c),this.stopEditingFn=()=>a(!0),e.focus({preventScroll:!0});let l=document.createRange();l.selectNodeContents(e);let u=getSelection();u?.removeAllRanges(),u?.addRange(l)}stopEditingFn=null;stopEditing(){let e=this.stopEditingFn;if(this.stopEditingFn=null,e?.(),this.editing){let e=this.rendered.get(this.editing.id);e?.el.classList.remove(`dw-cv-editing`),e?.note&&document.activeElement&&e.el.contains(document.activeElement)&&document.activeElement.blur(),this.editing=null,this.drawOverlay(),this.ui.refresh()}}frameName(){let e=this.elements().filter(e=>e.type===`frame`).length+1;return`${this.labels.frameTitle} ${e}`}addNote(e){let t=this.store.add({type:`note`,...this.styles.note,x:e[0]-24,y:e[1]-24,w:320,h:120});this.setTool(`select`),this.select([t]),this.render(),this.startEdit(t)}addText(e){let t=this.store.add({type:`text`,...this.styles.text,x:e[0],y:e[1]-this.styles.text.fontSize*.7,w:0,h:0,text:``});this.setTool(`select`),this.render(),this.startEdit(t)}addMindmap(e){let t=`r${Date.now().toString(36)}`,n=this.store.add({type:`mindmap`,...this.styles.mindmap,x:e[0],y:e[1],nodes:{[t]:{text:this.labels.centralIdea,parent:``,pos:0}}});this.setTool(`select`),this.select([n]),this.activeNode={map:n,node:t},this.render(),this.startEdit(n,t)}viewCentre(){let e=this.root.getBoundingClientRect();return this.toWorld(e.left+e.width/2,e.top+e.height/2)}async addImages(e,t){let n=this.opts.files?.upload;if(!n)return;let[r,i]=t??this.viewCentre(),a=[];for(let t of e)try{let e=await n.call(this.opts.files,t),o=await bR(this.opts.files?.resolve(e.url)??e.url),s=Math.min(1,480/Math.max(o.w,1)),c=o.w*s,l=o.h*s;a.push(this.store.add({type:`image`,src:e.url,alt:e.name,x:r-c/2,y:i-l/2,w:c,h:l})),r+=24,i+=24}catch(e){this.opts.onError?.(e)}a.length&&this.select(a)}async addLink(e,t){let n=(e??window.prompt(this.labels.linkPrompt,`https://`))?.trim();if(!n||!/^https?:\/\//i.test(n))return;let[r,i]=t??this.viewCentre(),a=this.opts.embedSource?.(n),o=a?560:380,s=a?a.ratio===`video`?315:420:120,c=this.store.add({type:`embed`,url:n,x:r-o/2,y:i-s/2,w:o,h:s});this.setTool(`select`),this.select([c])}insertElements(e){let t=VP(e.map(e=>({x:Number(e.x)||0,y:Number(e.y)||0,w:Number(e.w)||0,h:Number(e.h)||0})))??{x:0,y:0,w:0,h:0},[n,r]=this.viewCentre(),i=this.store.insertJSON(e,n-(t.x+t.w/2),r-(t.y+t.h/2));this.setTool(`select`),this.select(i.filter(e=>!i.includes(this.get(e)?.group??``)))}insertSticker(e){this.insertElements(IF(e))}insertTemplate(e){this.insertElements(UF(e,this.labels))}deleteSelection(){let e=[...this.selected];this.clearSelection(),this.store.remove(e)}duplicate(){let e=this.store.toJSON(this.selected);if(!e.length)return;let t=this.store.insertJSON(e,24,24);this.select(t.filter(e=>!this.get(e)?.group||!t.includes(this.get(e).group)))}group(){let e=this.store.groupOf([...this.selected]);e&&this.select([e])}ungroup(){let e=this.selection().filter(e=>e.type===`group`),t=e.flatMap(e=>this.store.ungroup(e.id));e.length&&this.select(t)}reorder(e){this.store.reorder(this.expanded(this.selected),e)}mindmapAdd(e){let t=this.activeNode,n=t?this.get(t.map):void 0;if(!t||n?.type!==`mindmap`)return;let r=n.nodes[t.node];if(!r)return;let i=e===`child`||!r.parent?t.node:r.parent,a=nI(n.nodes,i),o;if(e===`sibling`&&r.parent){let e=a.indexOf(t.node),r=n.nodes[a[e]]?.pos??0;o=(r+(a[e+1]?n.nodes[a[e+1]]?.pos??r+2:r+2))/2}else o=a.length?Math.max(...a.map(e=>n.nodes[e]?.pos??0))+1:0;let s=this.store.addNode(t.map,i,o,``);this.activeNode={map:t.map,node:s},this.render(),this.startEdit(t.map,s)}mindmapKey(e){let t=this.activeNode,n=this.get(t.map);if(n?.type!==`mindmap`||!this.selected.has(t.map))return!1;if(e.key===`Tab`)return e.preventDefault(),this.mindmapAdd(`child`),!0;if(e.key===`Enter`)return e.preventDefault(),this.mindmapAdd(`sibling`),!0;if(e.key===`F2`)return e.preventDefault(),this.startEdit(t.map,t.node),!0;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault();let r=n.nodes[t.node]?.parent;return this.store.removeNode(t.map,t.node),this.activeNode=r?{map:t.map,node:r}:null,this.schedule(),!0}if(e.key.startsWith(`Arrow`)&&!e.shiftKey){e.preventDefault();let r=iI(this.layoutOf(n),n.nodes,t.node,e.key);if(r){this.activeNode={map:t.map,node:r};let e=this.rendered.get(t.map);e&&(e.key=``),this.schedule()}return!0}return!1}owns(){let e=document.activeElement;return!!e&&(e===this.root||this.root.contains(e)&&!vR(e)&&!this.inEditor(e))}onCopy(e,t){if(!this.owns()||!this.selected.size||getSelection()?.toString())return;let n=this.store.toJSON(this.selected);e.clipboardData?.setData(`text/plain`,`docwell-canvas:${JSON.stringify(n)}`),e.preventDefault(),t&&this.editable&&this.deleteSelection()}onPaste(e){if(!this.editable||!this.owns())return;let t=[...e.clipboardData?.files??[]].filter(e=>e.type.startsWith(`image/`));if(t.length){e.preventDefault(),this.addImages(t);return}let n=e.clipboardData?.getData(`text/plain`)??``;if(!n)return;if(e.preventDefault(),n.startsWith(`docwell-canvas:`)){try{let e=JSON.parse(n.slice(15));Array.isArray(e)&&this.insertElements(e)}catch{}return}if(/^https?:\/\/\S+$/i.test(n.trim())){this.addLink(n.trim());return}let[r,i]=this.viewCentre(),a=this.store.add({type:`text`,...this.styles.text,x:r,y:i,w:n.length>60?480:0,h:0,text:n});this.select([a])}setComments(e,t=``){this.comments=e;let n=t!==this.activeComment;this.activeComment=t;let r=t?e.find(e=>e.comment===t):void 0;n&&r&&this.reveal(r.element),this.drawOverlay()}reveal(e){let t=this.get(e);if(!t)return;let n=this.outerBox(t),r=this.root.getBoundingClientRect(),[i,a]=this.toScreen([n.x,n.y]),[o,s]=this.toScreen([n.x+n.w,n.y+n.h]);if(i>=0&&a>=0&&o<=r.width&&s<=r.height)return;let c={...this.view};if(n.w*c.zoome.comment===this.activeComment);o&&e.push(``);let[s,c]=this.toScreen([a.x+a.w,a.y]),l=(o??i[0]).comment;e.push(`${PL(this.labels.comment)}${i.length}`)}}async exportImage(e,t=!1){let n=t&&this.selected.size?new Set(this.expanded(this.selected)):null,r=this.elements().filter(e=>!n||n.has(e.id));return mR(e,{root:this.root,elements:r,boxOf:e=>this.boxOf(e),routeOf:e=>this.routes.get(e.id)??this.routeOf(e),layoutOf:e=>this.layoutOf(e),noteBody:e=>e.page?this.opts.doc.getXmlFragment(`default`):this.store.body(e.id),pageTitle:this.opts.pageTitle?.()??``,resolve:e=>this.opts.files?.resolve(e)??e})}frames(){return this.elements().filter(e=>e.type===`frame`).sort((e,t)=>t.index-e.index)}present(){let e=this.frames().map(e=>e.id);if(!e.length){this.ui.toast(this.labels.presentNoFrames);return}this.stopEditing(),this.clearSelection();let t=this.ui.presentBar();this.presenting={frames:e,at:0,bar:t},this.root.classList.add(`dw-cv-presenting`),this.root.requestFullscreen?.().catch(()=>{}),requestAnimationFrame(()=>this.goTo(0))}goTo(e){let t=this.presenting;if(!t)return;t.at=Math.max(0,Math.min(t.frames.length-1,e));let n=this.get(t.frames[t.at]);if(n){let e={...this.view};this.fit(this.boxOf(n),!1,24);let t={...this.view};this.view=e,this.animateTo(t)}this.ui.presentStep(t.at,t.frames.length)}presentStep(e){this.presenting&&this.goTo(this.presenting.at+e)}stopPresenting(){let e=this.presenting;e&&(this.presenting=null,e.bar.remove(),this.root.classList.remove(`dw-cv-presenting`),document.fullscreenElement===this.root&&document.exitFullscreen().catch(()=>{}),this.drawOverlay())}get isPresenting(){return!!this.presenting}presentKey(e){[`ArrowRight`,`ArrowDown`,`PageDown`,` `,`Enter`].includes(e.key)?(e.preventDefault(),this.presentStep(1)):[`ArrowLeft`,`ArrowUp`,`PageUp`,`Backspace`].includes(e.key)?(e.preventDefault(),this.presentStep(-1)):e.key===`Escape`&&(e.preventDefault(),this.stopPresenting())}};function bR(e){return new Promise(t=>{let n=new Image;n.onload=()=>t({w:n.naturalWidth||320,h:n.naturalHeight||240}),n.onerror=()=>t({w:320,h:240}),n.src=e})}var xR={database:`Database`,untitled:`Untitled database`,untitledRow:`Untitled`,newRow:`New record`,addColumn:`Add property`,columnName:`Property name`,search:`Search records`,filter:`Filter`,sort:`Sort`,group:`Group`,properties:`Properties`,more:`More`,addView:`Add view`,viewName:`View name`,renameView:`Rename view`,duplicateView:`Duplicate view`,deleteView:`Delete view`,layout:`Layout`,viewTable:`Table`,viewKanban:`Kanban`,viewCalendar:`Calendar`,noValue:`No value`,checked:`Checked`,unchecked:`Unchecked`,noRows:`No records`,noMatches:`No records match`,rename:`Rename`,type:`Type`,hide:`Hide in view`,show:`Show in view`,sortAscending:`Sort ascending`,sortDescending:`Sort descending`,filterBy:`Filter by this property`,insertLeft:`Insert left`,insertRight:`Insert right`,moveLeft:`Move left`,moveRight:`Move right`,duplicate:`Duplicate`,deleteColumn:`Delete property`,typeTitle:`Title`,typeText:`Text`,typeNumber:`Number`,typeCheckbox:`Checkbox`,typeSelect:`Select`,typeMultiSelect:`Multi-select`,typeDate:`Date`,typeProgress:`Progress`,typeLink:`Link`,typeAttachment:`Attachment`,typeMember:`Member`,typeCreatedTime:`Created time`,typeCreatedBy:`Created by`,typeRelation:`Relation`,typeRollup:`Rollup`,linkedCount:`{n} linked`,rollupDays:`{n} days`,relationTo:`Related database`,relationPick:`Choose a database`,relationThisPage:`On this page`,relationOtherPage:`On another page…`,relationSearchPage:`Find a page`,relationNoDatabases:`No databases on that page`,relationMissing:`The related database is not available.`,linkRecord:`Link a record`,searchRecords:`Search records`,noRecords:`No records`,openRelated:`Open record`,rollupSettings:`Rollup`,rollupRelation:`Relation`,rollupProperty:`Property`,rollupFn:`Calculate`,rollupRecords:`Records`,rollupNeedsRelation:`Add a relation property first.`,fnShowOriginal:`Show values`,fnCount:`Count records`,fnCountValues:`Count values`,fnCountUnique:`Count unique values`,fnCountEmpty:`Count empty`,fnCountNotEmpty:`Count not empty`,fnPercentNotEmpty:`Percent not empty`,fnSum:`Sum`,fnAverage:`Average`,fnMedian:`Median`,fnMin:`Min`,fnMax:`Max`,fnRange:`Range`,fnEarliest:`Earliest date`,fnLatest:`Latest date`,fnChecked:`Checked`,fnPercentChecked:`Percent checked`,openFullPage:`Open as full page`,backToPage:`Back to the page`,recordNotFound:`This record is not in the database any more.`,opContains:`contains`,opNotContains:`does not contain`,opIs:`is`,opIsNot:`is not`,opIsEmpty:`is empty`,opIsNotEmpty:`is not empty`,opGt:`is greater than`,opLt:`is less than`,opGte:`is at least`,opLte:`is at most`,opBefore:`is before`,opAfter:`is after`,opChecked:`is checked`,opUnchecked:`is not checked`,addFilter:`Add filter`,matchAll:`Every filter matches`,matchAny:`Any filter matches`,remove:`Remove`,value:`Value`,noFilters:`No filters yet`,addSort:`Add sort`,ascending:`Ascending`,descending:`Descending`,noSorts:`No sorts yet`,groupBy:`Group by`,noGrouping:`No grouping`,showAll:`Show all`,hideAll:`Hide all`,dateColumn:`Date property`,today:`Today`,previousMonth:`Previous month`,nextMonth:`Next month`,noDateColumn:`Add a date property to place records on the calendar.`,noDate:`No date ({n})`,noGroupColumn:`Add a select, checkbox or member property to sort cards into columns.`,openRow:`Open`,copyLink:`Copy link to record`,deleteRow:`Delete record`,duplicateRow:`Duplicate record`,insertAbove:`Insert above`,insertBelow:`Insert below`,deleteRows:`Delete`,selected:`{n} selected`,selectRow:`Select record`,dragRow:`Drag to move`,close:`Close`,expand:`Full width`,collapse:`Narrow`,previousRow:`Previous record`,nextRow:`Next record`,bodyPlaceholder:`Write about this record…`,bodyReadOnly:`This record has no notes.`,searchOptions:`Find or create a choice`,createOption:`Create “{n}”`,optionColor:`Colour`,deleteOption:`Delete choice`,renameOption:`Rename choice`,searchPeople:`Find a person`,noPeople:`Nobody found`,upload:`Upload a file`,linkPlaceholder:`Paste a link`,clear:`Clear`,exportCsv:`Export as CSV`,importCsv:`Import CSV`,imported:`Added {n} records`,copyNotice:`Copied {n} cells`,readOnly:`Only people who can edit the page can change this database.`,resize:`Drag to change the width`,groupAsDatabase:`Group as database`,done:`Done`},SR={title:`typeTitle`,text:`typeText`,number:`typeNumber`,checkbox:`typeCheckbox`,select:`typeSelect`,multiSelect:`typeMultiSelect`,date:`typeDate`,progress:`typeProgress`,link:`typeLink`,attachment:`typeAttachment`,member:`typeMember`,createdTime:`typeCreatedTime`,createdBy:`typeCreatedBy`,relation:`typeRelation`,rollup:`typeRollup`},CR=(e,t)=>e[SR[t]],wR={contains:`opContains`,notContains:`opNotContains`,is:`opIs`,isNot:`opIsNot`,isEmpty:`opIsEmpty`,isNotEmpty:`opIsNotEmpty`,gt:`opGt`,lt:`opLt`,gte:`opGte`,lte:`opLte`,before:`opBefore`,after:`opAfter`,checked:`opChecked`,unchecked:`opUnchecked`},TR=(e,t)=>e[wR[t]],ER=(e,t)=>t===`kanban`?e.viewKanban:t===`calendar`?e.viewCalendar:e.viewTable,DR=(e,t)=>e.replace(`{n}`,String(t)),{colors:OR,...kR}=dF,AR={slashMenu:`Insert block`,noMatches:`No matching blocks`,slash:{text:{label:`Text`,description:`Plain paragraph`},h1:{label:`Heading 1`,description:`Big section heading`},h2:{label:`Heading 2`,description:`Medium section heading`},h3:{label:`Heading 3`,description:`Small section heading`},otherHeadings:{label:`Other headings`,description:`Headings 4 to 6`},h4:{label:`Heading 4`,description:`A heading below level 3`},h5:{label:`Heading 5`,description:`A heading below level 4`},h6:{label:`Heading 6`,description:`The smallest heading`},bullet:{label:`Bulleted list`,description:`A simple list`},ordered:{label:`Numbered list`,description:`A list with numbers`},todo:{label:`To-do list`,description:`Tasks to tick off (or type [])`},callout:{label:`Callout`,description:`Set a note apart with an emoji and colour`},table:{label:`Table`,description:`Rows and columns`},quote:{label:`Quote`,description:`Set text apart as a quote`},code:{label:`Code block`,description:`Monospaced code`},divider:{label:`Divider`,description:`A line between sections`},image:{label:`Image`,description:`Upload a picture`},file:{label:`File`,description:`Attach a file to download`},math:{label:`Math block`,description:`A formula on its own line (LaTeX)`},mathInline:{label:`Inline math`,description:`A formula inside the text (LaTeX)`},mermaid:{label:`Mermaid diagram`,description:`Flowcharts and sequences from text`},drawio:{label:`Draw.io diagram`,description:`Draw a diagram with diagrams.net`},excalidraw:{label:`Excalidraw drawing`,description:`Sketch by hand`},toc:{label:`Table of contents`,description:`The page's headings, kept up to date`},pageLink:{label:`Link to page`,description:`Link another page (or type [[)`},toggle:{label:`Toggle`,description:`A heading that hides the blocks under it`},embed:{label:`Embed`,description:`A video, design or document from YouTube, Figma and more`},linkCard:{label:`Link card`,description:`A link with its page's title and picture`},syncedPage:{label:`Synced page`,description:`Show another page here, always up to date`},database:{label:`Database`,description:`Records in a table, board or calendar`},newPage:{label:`New page`,description:`Make a page and link it here`},today:{label:`Today`,description:`Insert today's date`},tomorrow:{label:`Tomorrow`,description:`Insert tomorrow's date`},yesterday:{label:`Yesterday`,description:`Insert yesterday's date`},now:{label:`Now`,description:`Insert the date and time`}},format:{bold:`Bold`,italic:`Italic`,strike:`Strikethrough`,code:`Inline code`,link:`Link`,linkPrompt:`Link address (leave empty to remove the link)`,comment:`Comment`,underline:`Underline`,color:`Colour`,textColor:`Text colour`,highlight:`Highlight`,noColor:`Default`,align:`Align`,alignLeft:`Align left`,alignCenter:`Align centre`,alignRight:`Align right`,math:`Inline math`,linkedPage:`Make a linked page`},colors:{gray:`Grey`,red:`Red`,orange:`Orange`,yellow:`Yellow`,green:`Green`,teal:`Teal`,blue:`Blue`,purple:`Purple`,pink:`Pink`},table:{toolbar:`Table`,dragRow:`Drag to move the row`,dragColumn:`Drag to move the column`,moveRowUp:`Move row up`,moveRowDown:`Move row down`,moveColumnLeft:`Move column left`,moveColumnRight:`Move column right`,addRowBefore:`Add row above`,addRowAfter:`Add row below`,addColumnBefore:`Add column left`,addColumnAfter:`Add column right`,deleteRow:`Delete row`,deleteColumn:`Delete column`,toggleHeaderRow:`Header row`,mergeCells:`Merge cells`,splitCell:`Split cell`,deleteTable:`Delete table`},blockMenu:{open:`Drag to move, click for actions`,turnInto:`Turn into`,moveUp:`Move up`,moveDown:`Move down`,duplicate:`Duplicate`,copy:`Copy`,delete:`Delete`,showLineNumbers:`Show line numbers`,hideLineNumbers:`Hide line numbers`,showPages:`Show pages`,showAsFile:`Show as file`},mentions:`Mention someone`,noPeople:`Nobody found`,pageLinks:`Link to a page`,noPages:`No pages found`,blocks:{edit:`Edit`,done:`Done`,cancel:`Cancel`,save:`Save`,remove:`Remove`,saving:`Saving…`,latex:`LaTeX formula`,mermaid:`Mermaid diagram source`,mermaidError:`This diagram has an error:`,emptyDrawio:`Empty diagram. Click to draw.`,emptyExcalidraw:`Empty drawing. Click to sketch.`,loadFailed:`The editor could not be loaded.`,toc:`Contents`,tocEmpty:`Add headings to the page to fill the table of contents.`,expand:`Show contents`,collapse:`Hide contents`,embed:`Embedded content`,embedUrl:`Address of the video, design or document`,embedInvalid:`This address can't be embedded.`,syncedPage:`Synced page`,syncedOpen:`Open`,syncedFold:`Fold`,syncedUnfold:`Unfold`,syncedLoading:`Loading the page…`,syncedDenied:`You can't open this page.`,syncedSelf:`A page can't show itself.`,linkUrl:`Address of the page to link`,copyBlockLink:`Copy link to this block`,calloutEmoji:`Change emoji`,calloutColor:`Change colour`,pdfLoading:`Loading PDF…`,pdfPage:`Page {n}`},find:{find:`Find in page`,replace:`Replace with`,previous:`Previous match`,next:`Next match`,replaceOne:`Replace`,replaceAll:`Replace all`,matchCase:`Match case`,close:`Close`,count:`{current} of {total}`,none:`No matches`},dates:{today:`Today`,tomorrow:`Tomorrow`,yesterday:`Yesterday`,nextWeek:`Next week`,remindWord:`remind`,remindMe:`Remind me`,reminderAt:`Reminder at 9:00 on the day`,someoneElse:`Someone else set a reminder on this date.`,edit:`Change date`,openJournal:`Open journal`},database:xR,edgeless:kR},jR=[`title`,`text`,`number`,`checkbox`,`select`,`multiSelect`,`date`,`progress`,`link`,`attachment`,`member`,`createdTime`,`createdBy`,`relation`,`rollup`],MR=jR.filter(e=>e!==`title`),NR=[`table`,`kanban`,`calendar`];function PR(){let e=new Uint8Array(6);return crypto.getRandomValues(e),[...e].map(e=>e.toString(36).padStart(2,`0`)).join(``).slice(0,10)}function FR(e,t,n){let r=n.find(e=>IR.includes(e.type)),i=n.find(e=>e.type===`date`||e.type===`createdTime`);return{id:PR(),name:t,type:e,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:e===`kanban`?r?.id??null:null,dateColumn:e===`calendar`?i?.id??null:null,widths:{}}}var IR=[`select`,`multiSelect`,`checkbox`,`member`,`createdBy`];function LR(e){let t=BR(e)?e:{},n=(Array.isArray(t.columns)?t.columns:[]).flatMap(e=>{if(!BR(e)||typeof e.id!=`string`||!e.id)return[];let t=jR.includes(String(e.type))?e.type:`text`,n={id:e.id,name:typeof e.name==`string`?e.name:``,type:t};Array.isArray(e.options)&&(n.options=e.options.flatMap(RR));let r=t===`relation`?lz(e.relation):void 0;r&&(n.relation=r);let i=t===`rollup`?uz(e.rollup):void 0;return i&&(n.rollup=i),[n]});n.some(e=>e.type===`title`)||n.unshift({id:PR(),name:``,type:`title`});let r=(Array.isArray(t.rows)?t.rows:[]).flatMap(e=>{if(!BR(e)||typeof e.id!=`string`||!e.id)return[];let t={id:e.id,cells:BR(e.cells)?{...e.cells}:{},createdAt:typeof e.createdAt==`number`?e.createdAt:0,createdBy:zR(e.createdBy)};return Array.isArray(e.body)&&e.body.length&&(t.body=e.body,t.hasBody=!0),[t]}),i=new Set(n.map(e=>e.id)),a=(Array.isArray(t.views)?t.views:[]).flatMap(e=>{if(!BR(e)||typeof e.id!=`string`||!e.id)return[];let t=NR.includes(String(e.type))?e.type:`table`;return[{id:e.id,name:typeof e.name==`string`?e.name:``,type:t,hidden:Array.isArray(e.hidden)?e.hidden.filter(e=>typeof e==`string`):[],filters:Array.isArray(e.filters)?e.filters.filter(e=>BR(e)&&typeof e.column==`string`&&typeof e.op==`string`):[],filterMode:e.filterMode===`or`?`or`:`and`,sorts:Array.isArray(e.sorts)?e.sorts.flatMap(e=>BR(e)&&typeof e.column==`string`?[{column:e.column,desc:!!e.desc}]:[]):[],groupBy:typeof e.groupBy==`string`&&i.has(e.groupBy)?e.groupBy:null,dateColumn:typeof e.dateColumn==`string`&&i.has(e.dateColumn)?e.dateColumn:null,widths:BR(e.widths)?Object.fromEntries(Object.entries(e.widths).filter(e=>typeof e[1]==`number`)):{}}]});return{title:typeof t.title==`string`?t.title:``,columns:n,rows:r,views:a}}function RR(e){return!BR(e)||typeof e.id!=`string`?[]:[{id:e.id,name:typeof e.name==`string`?e.name:``,color:PP(e.color)?e.color:`gray`}]}function zR(e){return BR(e)&&typeof e.id==`string`?{id:e.id,name:typeof e.name==`string`?e.name:``}:null}function BR(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function VR(e){return e.columns.find(e=>e.type===`title`)??e.columns[0]}function HR(e,t){return t.type===`createdTime`?e.createdAt||null:t.type===`createdBy`?e.createdBy?[e.createdBy]:[]:t.type===`rollup`?e.computed?.[t.id]?.value??null:e.cells[t.id]}function UR(e){return e==null||e===``||e===!1||Array.isArray(e)&&e.length===0}function WR(e){return typeof e==`number`&&e>0?GR(new Date(e)):typeof e==`string`&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function GR(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function KR(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e.trim().replace(`,`,`.`));return Number.isFinite(t)?t:null}return null}function qR(e){return Array.isArray(e)?e:[]}function JR(e,t){let n=HR(e,t);switch(t.type){case`title`:case`text`:case`link`:return typeof n==`string`?n:``;case`number`:case`progress`:{let e=KR(n);return e===null?``:String(e)}case`checkbox`:return n===!0?`true`:`false`;case`select`:return t.options?.find(e=>e.id===n)?.name??``;case`multiSelect`:return qR(n).map(e=>t.options?.find(t=>t.id===e)?.name).filter(e=>!!e).join(`, `);case`date`:case`createdTime`:return WR(n);case`attachment`:return qR(n).map(e=>e?.name??``).join(`, `);case`member`:case`createdBy`:return qR(n).map(e=>e?.name??``).join(`, `);case`relation`:case`rollup`:return e.computed?.[t.id]?.text??``}}function YR(e){switch(e){case`number`:case`progress`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`isEmpty`,`isNotEmpty`];case`checkbox`:return[`checked`,`unchecked`];case`select`:return[`is`,`isNot`,`isEmpty`,`isNotEmpty`];case`multiSelect`:case`member`:case`createdBy`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`date`:case`createdTime`:return[`is`,`before`,`after`,`isEmpty`,`isNotEmpty`];case`attachment`:return[`isEmpty`,`isNotEmpty`];case`relation`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`rollup`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`contains`,`isEmpty`,`isNotEmpty`];default:return[`contains`,`notContains`,`is`,`isNot`,`isEmpty`,`isNotEmpty`]}}var XR=e=>![`isEmpty`,`isNotEmpty`,`checked`,`unchecked`].includes(e);function ZR(e,t,n){let r=HR(e,t);if(t.type===`relation`){let e=fz(r).length===0;if(n.op===`isEmpty`)return e;if(n.op===`isNotEmpty`)return!e}if(n.op===`isEmpty`)return UR(r)||JR(e,t)===``;if(n.op===`isNotEmpty`)return!(UR(r)||JR(e,t)===``);if(n.op===`checked`)return r===!0;if(n.op===`unchecked`)return r!==!0;if(n.value===void 0||n.value===null||n.value===``)return!0;switch(t.type===`rollup`&&(typeof r==`number`||r===null)&&[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`].includes(n.op)?`number`:t.type){case`number`:case`progress`:{let e=KR(r),t=KR(n.value);return t===null?!0:e===null?n.op===`isNot`:{is:e===t,isNot:e!==t,gt:e>t,lt:e=t,lte:e<=t}[n.op]}case`select`:return n.op===`is`?r===n.value:r!==n.value;case`multiSelect`:{let e=qR(r).includes(String(n.value));return n.op===`notContains`?!e:e}case`member`:case`createdBy`:{let e=String(n.value).toLowerCase(),t=qR(r).some(t=>t?.id===n.value||t?.name?.toLowerCase().includes(e));return n.op===`notContains`?!t:t}case`date`:case`createdTime`:{let e=WR(r),t=WR(n.value);return e?n.op===`before`?et:e===t:!1}default:{let r=JR(e,t).toLowerCase(),i=String(n.value).toLowerCase();switch(n.op){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`is`:return r===i;case`isNot`:return r!==i;default:return!0}}}}function QR(e,t,n){let r=JR(e,n)===``&&n.type!==`checkbox`,i=JR(t,n)===``&&n.type!==`checkbox`;if(r||i)return r===i?0:r?1:-1;switch(n.type){case`number`:case`progress`:return(KR(HR(e,n))??0)-(KR(HR(t,n))??0);case`checkbox`:return Number(HR(e,n)===!0)-Number(HR(t,n)===!0);case`createdTime`:return e.createdAt-t.createdAt;case`rollup`:{let r=HR(e,n),i=HR(t,n);return typeof r==`number`&&typeof i==`number`?r-i:JR(e,n).localeCompare(JR(t,n),void 0,{numeric:!0,sensitivity:`base`})}case`select`:{let r=e=>n.options?.findIndex(t=>t.id===HR(e,n))??-1;return r(e)-r(t)}default:return JR(e,n).localeCompare(JR(t,n),void 0,{numeric:!0,sensitivity:`base`})}}function $R(e,t,n=``){let r=new Map(e.columns.map(e=>[e.id,e])),i=t.filters.flatMap(e=>{let t=r.get(e.column);return t?[{f:e,col:t}]:[]}),a=n.trim().toLowerCase(),o=e.rows.filter(n=>{if(i.length){let e=({f:e,col:t})=>ZR(n,t,e);if(t.filterMode===`or`?!i.some(e):!i.every(e))return!1}return!a||e.columns.some(e=>JR(n,e).toLowerCase().includes(a))}),s=t.sorts.flatMap(e=>{let t=r.get(e.column);return t?[{col:t,desc:e.desc}]:[]});return s.length&&(o=o.map((e,t)=>({r:e,i:t})).sort((e,t)=>{for(let n of s){let r=QR(e.r,t.r,n.col);if(r!==0){let i=JR(e.r,n.col)===``||JR(t.r,n.col)===``;return n.desc&&!(i&&n.col.type!==`checkbox`)?-r:r}}return e.i-t.i}).map(e=>e.r)),o}function ez(e,t){return e.columns.filter(e=>e.type===`title`||!t.hidden.includes(e.id))}function tz(e,t,n,r,i){let a=new Map,o=(e,t,n)=>(a.has(e)||a.set(e,{key:e,label:t,color:n,rows:[]}),a.get(e));if(t.type===`checkbox`)o(`false`,i),o(`true`,r);else{o(``,n);for(let e of t.options??[])o(e.id,e.name,e.color)}for(let n of e)for(let e of rz(n,t))(a.get(e)??o(e,nz(n,t,e)||e)).rows.push(n);return[...a.values()]}function nz(e,t,n){return qR(HR(e,t)).find(e=>e?.id===n)?.name??``}function rz(e,t){let n=HR(e,t);switch(t.type){case`checkbox`:return[n===!0?`true`:`false`];case`select`:return[typeof n==`string`&&t.options?.some(e=>e.id===n)?n:``];case`multiSelect`:{let e=qR(n).filter(e=>t.options?.some(t=>t.id===e));return e.length?e:[``]}case`member`:case`createdBy`:{let e=qR(n).flatMap(e=>e?.id?[e.id]:[]);return e.length?e:[``]}default:return[``]}}function iz(e,t,n,r,i=[]){let a=HR(e,t);switch(t.type){case`checkbox`:return r===`true`;case`select`:return r||null;case`multiSelect`:{let e=qR(a).filter(e=>e!==n&&e!==r);return r?[...e,r]:e}case`member`:{let e=qR(a).filter(e=>e?.id!==n&&e?.id!==r),t=i.find(e=>e.id===r)??qR(a).find(e=>e?.id===r);return r&&t?[...e,t]:e}default:return a}}function az(e){let t=NP.filter(e=>e!==`gray`);return t[e.length%t.length]}function oz(e,t,n,r){if(t.type===n)return{value:e,options:r};let i=JR({id:``,cells:{[t.id]:e},createdAt:0,createdBy:null},t),a=e=>{let t=e.trim();if(!t)return null;let n=r.find(e=>e.name.toLowerCase()===t.toLowerCase());return n||(n={id:PR(),name:t,color:az(r)},r=[...r,n]),n.id};switch(n){case`title`:case`text`:case`link`:return{value:i||null,options:r};case`number`:return{value:KR(i),options:r};case`progress`:{let e=KR(i);return{value:e===null?null:Math.max(0,Math.min(100,Math.round(e))),options:r}}case`checkbox`:return{value:[`true`,`yes`,`1`,`x`,`✓`,`done`].includes(i.trim().toLowerCase()),options:r};case`select`:return{value:a(i.split(`,`)[0]??``),options:r};case`multiSelect`:{let e=i.split(`,`).flatMap(e=>{let t=a(e);return t?[t]:[]});return{value:[...new Set(e)],options:r}}case`date`:return{value:WR(i)||null,options:r};case`member`:return{value:t.type===`member`||t.type===`createdBy`?e:[],options:r};default:return{value:null,options:r}}}function sz(e,t,n=1){let r=(new Date(e,t,1).getDay()-n+7)%7,i=new Date(e,t,1-r),a=new Date(e,t+1,0).getDate(),o=Math.ceil((r+a)/7);return Array.from({length:o*7},(e,t)=>GR(new Date(i.getFullYear(),i.getMonth(),i.getDate()+t)))}var cz=[`showOriginal`,`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`,`sum`,`average`,`median`,`min`,`max`,`range`,`earliest`,`latest`,`checked`,`percentChecked`];function lz(e){if(BR(e)&&typeof e.database==`string`&&e.database)return{page:typeof e.page==`string`?e.page:``,database:e.database}}function uz(e){if(!BR(e)||typeof e.relation!=`string`)return;let t=cz.includes(String(e.fn))?e.fn:`count`;return{relation:e.relation,property:typeof e.property==`string`?e.property:``,fn:t}}function dz(e){let t=[`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`];switch(e){case`number`:case`progress`:return[`sum`,`average`,`median`,`min`,`max`,`range`,...t,`showOriginal`];case`date`:case`createdTime`:return[`earliest`,`latest`,`range`,...t,`showOriginal`];case`checkbox`:return[`checked`,`percentChecked`,`count`,`showOriginal`];default:return[`showOriginal`,...t]}}var fz=e=>qR(e).filter(e=>typeof e==`string`&&!!e),pz=e=>String(Number.isInteger(e)?e:Math.round(e*100)/100),mz=(e,t)=>Math.round((Date.parse(t)-Date.parse(e))/864e5);function hz(e,t,n,r){let i=t.map(e=>n?HR(e,n):e.id),a=t.map(e=>n?JR(e,n):``),o=a.filter((e,t)=>n?.type===`checkbox`?i[t]===!0:e!==``),s=n?i.map(KR).filter(e=>e!==null):[],c=n?i.map(WR).filter(Boolean).sort():[],l=e=>({text:e===null?``:pz(e),value:e});switch(e){case`count`:return l(t.length);case`countValues`:return l(o.length);case`countUnique`:return l(new Set(o).size);case`countEmpty`:return l(t.length-o.length);case`countNotEmpty`:return l(o.length);case`percentNotEmpty`:return t.length?{text:`${pz(o.length/t.length*100)}%`,value:o.length/t.length*100}:l(null);case`sum`:return l(s.length?s.reduce((e,t)=>e+t,0):null);case`average`:return l(s.length?s.reduce((e,t)=>e+t,0)/s.length:null);case`median`:{if(!s.length)return l(null);let e=[...s].sort((e,t)=>e-t),t=Math.floor(e.length/2);return l(e.length%2?e[t]:(e[t-1]+e[t])/2)}case`min`:return l(s.length?Math.min(...s):null);case`max`:return l(s.length?Math.max(...s):null);case`range`:if(n&&(n.type===`date`||n.type===`createdTime`)){if(!c.length)return l(null);let e=mz(c[0],c[c.length-1]);return{text:r.rollupDays.replace(`{n}`,String(e)),value:e}}return l(s.length?Math.max(...s)-Math.min(...s):null);case`earliest`:return{text:c[0]??``,value:c[0]??null};case`latest`:return{text:c[c.length-1]??``,value:c[c.length-1]??null};case`checked`:return l(i.filter(e=>e===!0).length);case`percentChecked`:return t.length?{text:`${pz(i.filter(e=>e===!0).length/t.length*100)}%`,value:i.filter(e=>e===!0).length/t.length*100}:l(null);case`showOriginal`:{let e=a.filter(Boolean);return{text:e.join(`, `),value:e}}}}function gz(e,t,n){let r=e.columns.filter(e=>e.type===`relation`&&e.relation),i=e.columns.filter(e=>e.type===`rollup`&&e.rollup);if(!r.length&&!i.length)return e;let a=new Map;for(let e of r)a.set(e.id,t(e.relation));let o=e.rows.map(e=>{let t={};for(let i of r){let r=fz(e.cells[i.id]),o=a.get(i.id);if(!o){t[i.id]={text:r.length?n.linkedCount.replace(`{n}`,String(r.length)):``,value:r};continue}let s=o.columns.find(e=>e.type===`title`),c=new Map(o.rows.map(e=>[e.id,e])),l=r.flatMap(e=>{let t=c.get(e);return t?[{id:e,title:s?JR(t,s):``}]:[]});t[i.id]={text:l.map(e=>e.title).join(`, `),value:r,links:l}}for(let o of i){let i=o.rollup,s=r.find(e=>e.id===i.relation),c=s?a.get(s.id):null;if(!s||!c){t[o.id]={text:``,value:null};continue}let l=new Map(c.rows.map(e=>[e.id,e])),u=fz(e.cells[s.id]).flatMap(e=>{let t=l.get(e);return t?[t]:[]}),d=i.property?c.columns.find(e=>e.id===i.property)??null:c.columns.find(e=>e.type===`title`)??null;t[o.id]=hz(i.fn,u,d,n)}return{...e,computed:t}});return{...e,rows:o}}function I(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))if(n!=null&&n!==!1){if(e===`class`)r.className=String(n);else if(e===`on`)for(let[e,t]of Object.entries(n))r.addEventListener(e,t);else e===`dataset`?Object.assign(r.dataset,n):e===`style`?Object.assign(r.style,n):e in r&&typeof n!=`string`?r[e]=n:r.setAttribute(e,n===!0?``:String(n))}for(let e of n.flat())e!=null&&e!==!1&&r.append(e);return r}function _z(e,t=16){return zj(e,t)}function vz(e,t,n,r){let i=I(`button`,{type:`button`,class:r?`dw-db__btn`:`dw-db__btn dw-db__btn--icon`,title:t,"aria-label":t},_z(e,15),r?I(`span`,{},r):null);return i.addEventListener(`click`,e=>{e.preventDefault(),n(e)}),i}var yz=null;function bz(e,t,n={}){yz?.close();let r=I(`div`,{class:`dw-db-pop ${n.class??``}`,role:`dialog`,"aria-label":n.label}),i=!1,a=()=>{i||(i=!0,c(),r.remove(),document.removeEventListener(`mousedown`,o,!0),document.removeEventListener(`keydown`,s,!0),yz?.box===r&&(yz=null),n.onClose?.())},o=t=>{let n=t.target;r.contains(n)||e.contains(n)||n instanceof Element&&n.closest(`.dw-block-menu`)||a()},s=t=>{t.key===`Escape`&&!document.querySelector(`.dw-block-menu`)&&(t.preventDefault(),t.stopPropagation(),a(),e instanceof HTMLElement&&e.focus())};document.body.append(r);let c=Oj(e,r,()=>{Mj(e,r,{placement:n.placement??`bottom-start`,strategy:`fixed`,middleware:[kj(4),jj(),Aj({padding:8})]}).then(({x:e,y:t})=>Object.assign(r.style,{left:`${e}px`,top:`${t}px`}))});return document.addEventListener(`mousedown`,o,!0),document.addEventListener(`keydown`,s,!0),t(r,a),yz={box:r,close:a},yz}function xz(){yz?.close()}function Sz(e,t){let n=I(`input`,{type:t.type??`text`,class:t.class??`dw-db-input`,placeholder:t.placeholder,"aria-label":t.label??t.placeholder});n.value=e;let r=!1,i=()=>{r||(r=!0,t.onCommit(n.value))};return n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(r=!0,t.onCancel?.())}),n.addEventListener(`blur`,i),n}function Cz(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=I(`a`,{href:r,download:e});document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function wz(e){return new Promise(t=>{let n=I(`input`,{type:`file`,accept:e});n.onchange=()=>t(n.files?.[0]??null),n.click()})}var Tz=e=>`fn${e[0].toUpperCase()}${e.slice(1)}`,Ez=(e,t)=>e[Tz(t)];function Dz(e,t,n,r){let i=I(`div`,{class:`dw-db-pop__item${t?` is-active`:``}`,role:`option`,"aria-selected":String(t)},I(`span`,{},e),r?I(`small`,{class:`dw-db-pop__sub`},r):null);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,n),i}function Oz(e,t,n,r){let i=e.store,a=e.linked;if(!i||!a)return;let o=e.labels;bz(t,(e,t)=>{let r=e=>{i.setRelation(n.id,{page:e.page,database:e.database}),t()},s=n.relation,c=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});if((()=>{let e=a.local();c.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},o.relationThisPage),...e.length?e.map(e=>Dz(e.title||o.untitled,!!s&&!s.page&&s.database===e.database,()=>r(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})(),e.append(I(`div`,{class:`dw-db-pop__title`},o.relationPick),c),a.searchPages&&a.databasesOn){let t=I(`input`,{class:`dw-db-input`,placeholder:o.relationSearchPage,"aria-label":o.relationOtherPage}),n=I(`div`,{class:`dw-db-pop__list`,role:`listbox`}),i=0;t.addEventListener(`input`,async()=>{let e=t.value.trim(),c=++i;if(!e)return n.replaceChildren();let l=await a.searchPages(e).catch(()=>[]);c===i&&n.replaceChildren(...l.slice(0,8).map(e=>Dz(e.title||o.untitled,!1,async()=>{let t=await a.databasesOn(e.id).catch(()=>[]);c===i&&n.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},e.title||o.untitled),...t.length?t.map(e=>Dz(e.title||o.untitled,s?.page===e.page&&s.database===e.database,()=>r(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})))}),t.addEventListener(`keydown`,e=>e.stopPropagation()),e.append(I(`div`,{class:`dw-db-pop__heading`},o.relationOtherPage),t,n)}},{class:`dw-db-pop--choices`,label:o.relationTo,onClose:r})}function kz(e,t,n,r,i){let a=e.store,o=e.labels,s=r.relation,c=s?e.linked?.read(s):null;if(!s||!c){if(t.append(I(`div`,{class:`dw-db-pop__empty`},s?o.relationMissing:o.relationPick)),!s&&e.linked){let n=I(`button`,{type:`button`,class:`dw-db__btn`},o.relationTo);n.addEventListener(`click`,()=>{i(),Oz(e,t,r)}),t.append(n)}return}let l=VR(c),u=fz(n.cells[r.id]),d=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),f=I(`input`,{class:`dw-db-input`,placeholder:o.searchRecords,"aria-label":o.linkRecord}),p=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(d,f,p);let m=e=>JR(e,l)||o.untitledRow,h=()=>a.setCell(n.id,r.id,u.length?u:null),g=e=>{u=u.includes(e)?u.filter(t=>t!==e):[...u,e],h(),y()},_=0,v=[],y=()=>{let e=new Map(c.rows.map(e=>[e.id,e]));d.replaceChildren(...u.flatMap(t=>{let n=e.get(t);if(!n)return[];let r=I(`span`,{class:`dw-db-tag`,dataset:{color:`gray`}},m(n)),i=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,()=>g(t)),r.append(i),[r]}));let t=f.value.trim().toLowerCase();v=c.rows.filter(e=>!t||m(e).toLowerCase().includes(t)).slice(0,50),_=Math.min(_,Math.max(0,v.length-1)),p.replaceChildren(...v.length?v.map((e,t)=>{let n=Dz(m(e),t===_,()=>g(e.id));return u.includes(e.id)&&n.prepend(I(`span`,{class:`dw-db-pop__check`},`✓`)),n}):[I(`div`,{class:`dw-db-pop__empty`},o.noRecords)])};f.addEventListener(`input`,()=>{_=0,y()}),f.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),v.length&&(_=(_+(e.key===`ArrowDown`?1:-1)+v.length)%v.length),y();else if(e.key===`Enter`){e.preventDefault();let t=v[_];t&&g(t.id)}else e.key===`Escape`&&(e.preventDefault(),i())}),y(),f.focus({preventScroll:!0})}function Az(e,t,n,r){let i=e.store;if(!i)return;let a=e.labels;bz(t,t=>{let r=e.db.columns.filter(e=>e.type===`relation`);if(!r.length){t.append(I(`div`,{class:`dw-db-pop__empty`},a.rollupNeedsRelation));return}let o=n.rollup??{relation:r[0].id,property:``,fn:`count`},s=(e,t,n,r)=>{let i=I(`select`,{class:`dw-db-input`,"aria-label":e});for(let[e,n]of t)i.append(I(`option`,{value:e},n));return i.value=n,i.addEventListener(`change`,()=>r(i.value)),I(`label`,{class:`dw-db-pop__field`},I(`span`,{},e),i)},c=()=>{let l=r.find(e=>e.id===o.relation)??r[0],u=l.relation?e.linked?.read(l.relation):null,d=[[``,a.rollupRecords]];for(let e of u?.columns??[])d.push([e.id,e.name||CR(a,e.type)]);let f=u?.columns.find(e=>e.id===o.property),p=dz(f?f.type:``);p.includes(o.fn)||(o.fn=o.property?p[0]:`count`),t.replaceChildren(s(a.rollupRelation,r.map(e=>[e.id,e.name||a.typeRelation]),l.id,e=>{o.relation=e,o.property=``,o.fn=`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupProperty,d,o.property,e=>{o.property=e;let t=u?.columns.find(t=>t.id===e);o.fn=e?dz(t?t.type:``)[0]:`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupFn,(o.property?p:[`count`,`showOriginal`]).map(e=>[e,Ez(a,e)]),o.fn,e=>{o.fn=e,i.setRollup(n.id,{...o})}),u?I(`span`):I(`div`,{class:`dw-db-pop__empty`},a.relationMissing))};n.rollup||i.setRollup(n.id,{...o}),c()},{class:`dw-db-pop--choices`,label:a.rollupSettings,onClose:r})}function jz(e,t,n){let r=t.computed?.[n.id],i=I(`span`,{class:`dw-db-tags`});if(r?.links&&n.relation){let t=n.relation;for(let n of r.links){let r=I(`button`,{type:`button`,class:`dw-db-tag dw-db-rel`,dataset:{color:`gray`},title:e.labels.openRelated},n.title||e.labels.untitledRow);r.addEventListener(`click`,r=>{r.stopPropagation(),e.linked?.openRecord(t,n.id)}),i.append(r)}}else r?.text&&i.append(I(`span`,{class:`dw-db-cell__text`},r.text));return i}var Mz={title:`text`,text:`type`,number:`sigma`,checkbox:`todo`,select:`tag`,multiSelect:`layers`,date:`calendar`,progress:`sliders`,link:`link`,attachment:`paperclip`,member:`users`,createdTime:`clock`,createdBy:`at`,relation:`relation`,rollup:`rollup`},Nz=[`title`,`text`,`number`,`link`],Pz=[`createdTime`,`createdBy`,`rollup`];function Fz(e,t){let[n,r,i]=e.split(`-`).map(Number);return!n||!r||!i?e:new Date(n,r-1,i).toLocaleDateString(t,{year:`numeric`,month:`short`,day:`numeric`})}function Iz(e,t,n){let r=I(`span`,{class:`dw-db-tag`,dataset:{color:t??`gray`}},e);if(n){let e=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r.append(e)}return r}function Lz(e){try{let t=new URL(e.includes(`://`)?e:`https://${e}`);return t.protocol===`http:`||t.protocol===`https:`||t.protocol===`mailto:`?t.href:null}catch{return null}}function Rz(e,t,n){let r=HR(t,n),i=e.labels;switch(n.type){case`title`:{let e=typeof r==`string`?r:``;return I(`span`,{class:e?`dw-db-cell__title`:`dw-db-cell__title is-empty`},e||i.untitledRow)}case`text`:return I(`span`,{class:`dw-db-cell__text`},typeof r==`string`?r:``);case`number`:{let t=KR(r);return I(`span`,{class:`dw-db-cell__number`},t===null?``:t.toLocaleString(e.locale))}case`checkbox`:return I(`span`,{class:r===!0?`dw-db-check is-on`:`dw-db-check`,role:`img`,"aria-label":r===!0?i.checked:i.unchecked},r===!0?_z(`check`,13):null);case`select`:{let e=n.options?.find(e=>e.id===r);return I(`span`,{class:`dw-db-tags`},e?Iz(e.name,e.color):null)}case`multiSelect`:return I(`span`,{class:`dw-db-tags`},qR(r).flatMap(e=>{let t=n.options?.find(t=>t.id===e);return t?[Iz(t.name,t.color)]:[]}));case`date`:case`createdTime`:{let t=WR(r);return I(`span`,{class:`dw-db-cell__text`},t?Fz(t,e.locale):``)}case`progress`:{let e=KR(r);if(e===null)return I(`span`);let t=Math.max(0,Math.min(100,e));return I(`span`,{class:`dw-db-progress`},I(`span`,{class:`dw-db-progress__bar`},I(`span`,{class:`dw-db-progress__fill`,style:{width:`${t}%`}})),I(`span`,{class:`dw-db-progress__num`},`${t}%`))}case`link`:{let e=typeof r==`string`?r:``,t=e?Lz(e):null;if(!t)return I(`span`,{class:`dw-db-cell__text`},e);let n=I(`a`,{class:`dw-db-cell__link`,href:t,target:`_blank`,rel:`noopener noreferrer`},e);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}case`attachment`:return I(`span`,{class:`dw-db-tags`},qR(r).map(t=>{let n=I(`a`,{class:`dw-db-file`,href:e.files?e.files.resolve(t.src):t.src,target:`_blank`,rel:`noopener noreferrer`},_z(`paperclip`,12),t.name);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}));case`member`:case`createdBy`:return I(`span`,{class:`dw-db-tags`},qR(r).map(e=>I(`span`,{class:`dw-db-person`},I(`span`,{class:`dw-db-person__dot`},(e?.name||`?`).slice(0,1).toUpperCase()),e?.name??``)));case`relation`:return jz(e,t,n);case`rollup`:{let r=t.computed?.[n.id],i=r?.value;return typeof i==`number`?I(`span`,{class:`dw-db-cell__number`},/^-?\d+(\.\d+)?%?$/.test(r.text)?i.toLocaleString(e.locale,{maximumFractionDigits:2})+(r.text.endsWith(`%`)?`%`:``):r.text):I(`span`,{class:`dw-db-cell__text`},r?.text??``)}}}function zz(e,t,n,r,i){let a=e.store;if(!a||Pz.includes(r.type))return i.onDone();let o=HR(n,r);if(r.type===`checkbox`)return a.setCell(n.id,r.id,o!==!0),i.onDone();e.setEditing(!0);let s=t=>{e.setEditing(!1),i.onDone(t)};if(Nz.includes(r.type)){let e=i.initial??(r.type===`number`?KR(o)?.toString()??``:typeof o==`string`?o:``),c,l=Sz(e,{class:`dw-db-cell__input`,type:(r.type,`text`),label:r.name,onCommit:e=>{let t=e.trim(),i=r.type===`number`?KR(t):r.type===`title`||r.type===`text`?e:t;i!==(o??null)&&(i!==``||o!==void 0)&&a.setCell(n.id,r.id,i),s(c)},onCancel:()=>s()});l.addEventListener(`keydown`,e=>{e.key===`Enter`&&(c=`down`),e.key===`Tab`&&(e.preventDefault(),c=e.shiftKey?`left`:`right`,l.blur())}),t.replaceChildren(l),t.classList.add(`is-editing`),l.focus(),i.initial===void 0?l.select():l.setSelectionRange(l.value.length,l.value.length);return}let c=(e,n=``)=>bz(t,e,{class:n,onClose:()=>s(),label:r.name});switch(r.type){case`select`:case`multiSelect`:c((t,a)=>Bz(e,t,n,r,a,i.initial),`dw-db-pop--choices`);break;case`date`:c((t,i)=>{let s=I(`input`,{type:`date`,class:`dw-db-input`,"aria-label":r.name});s.value=WR(o),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,s.value||null)),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&i()});let c=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.clear);c.addEventListener(`click`,()=>{a.setCell(n.id,r.id,null),i()});let l=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.today);l.addEventListener(`click`,()=>{let e=new Date;a.setCell(n.id,r.id,`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`),i()}),t.append(s,I(`div`,{class:`dw-db-pop__row`},l,c)),s.focus({preventScroll:!0})});break;case`progress`:c((e,t)=>{let i=KR(o)??0,s=I(`input`,{type:`range`,min:`0`,max:`100`,step:`1`,class:`dw-db-range`,"aria-label":r.name});s.value=String(i);let c=I(`span`,{class:`dw-db-progress__num`},`${i}%`);s.addEventListener(`input`,()=>c.textContent=`${s.value}%`),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,Number(s.value))),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&t()}),e.append(I(`div`,{class:`dw-db-pop__row`},s,c)),s.focus({preventScroll:!0})});break;case`member`:c((t,i)=>Vz(e,t,n,r,i),`dw-db-pop--choices`);break;case`attachment`:c(t=>Hz(e,t,n,r),`dw-db-pop--choices`);break;case`relation`:c((t,i)=>kz(e,t,n,r,i),`dw-db-pop--choices`);break;default:s()}}function Bz(e,t,n,r,i,a){let o=e.store,s=e.labels,c=r.type===`multiSelect`,l=[...r.options??[]],u=c?qR(HR(n,r)):[String(HR(n,r)??``)].filter(Boolean),d=0,f=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),p=I(`input`,{class:`dw-db-input`,placeholder:s.searchOptions,"aria-label":s.searchOptions});p.value=a??``;let m=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(f,p,m);let h=()=>o.setCell(n.id,r.id,c?u:u[0]??null),g=e=>{u=c?u.includes(e)?u.filter(t=>t!==e):[...u,e]:u[0]===e?[]:[e],h(),c?b():i()},_=e=>{let t={id:PR(),name:e,color:az(l)};l=[...l,t],o.tx(()=>{o.setOptions(r.id,l),u=c?[...u,t.id]:[t.id],h()}),p.value=``,c?b():i()},v=(t,n)=>{Gj(t,[{id:`rename`,label:s.renameOption,icon:`pencil`,run:()=>{let e=window.prompt(s.renameOption,n.name)?.trim();e&&(l=l.map(t=>t.id===n.id?{...t,name:e}:t),o.setOptions(r.id,l),b())}},{id:`color`,label:s.optionColor,icon:`palette`,children:NP.map(t=>({id:t,label:e.colorNames[t]??t,icon:t===n.color?`check`:`drop`,run:()=>{l=l.map(e=>e.id===n.id?{...e,color:t}:e),o.setOptions(r.id,l),b()}}))},{id:`delete`,label:s.deleteOption,icon:`trash`,danger:!0,run:()=>{l=l.filter(e=>e.id!==n.id),u=u.filter(e=>e!==n.id),o.setOptions(r.id,l),b()}}],s.optionColor,()=>p.focus())},y=[];function b(){f.replaceChildren(...u.flatMap(e=>{let t=l.find(t=>t.id===e);return t?[Iz(t.name,t.color,()=>g(e))]:[]}));let e=p.value.trim();y=l.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())).map(e=>({kind:`option`,o:e})),e&&!l.some(t=>t.name.toLowerCase()===e.toLowerCase())&&y.push({kind:`create`,name:e}),d=Math.min(d,Math.max(0,y.length-1)),m.replaceChildren(...y.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===d?` is-active`:``}`,role:`option`,"aria-selected":String(e.kind===`option`&&u.includes(e.o.id))});if(n.addEventListener(`mousedown`,e=>e.preventDefault()),e.kind===`option`){n.append(I(`span`,{class:`dw-db-pop__check`},u.includes(e.o.id)?_z(`check`,13):null),Iz(e.o.name,e.o.color));let t=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon dw-db-pop__more`,"aria-label":s.optionColor},_z(`more`,14));t.addEventListener(`click`,n=>{n.stopPropagation(),v(t,e.o)}),n.append(t),n.addEventListener(`click`,()=>g(e.o.id))}else n.append(I(`span`,{class:`dw-db-pop__check`},_z(`plus`,13)),I(`span`,{},DR(s.createOption,e.name))),n.addEventListener(`click`,()=>_(e.name));return n}))}p.addEventListener(`input`,()=>{d=0,b()}),p.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(d=(d+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[d];t?.kind===`option`?g(t.o.id):t?.kind===`create`?_(t.name):i()}else e.key===`Backspace`&&!p.value&&c&&u.length&&g(u[u.length-1])}),b(),p.focus({preventScroll:!0}),p.setSelectionRange(p.value.length,p.value.length)}function Vz(e,t,n,r,i){let a=e.store,o=e.labels,s=qR(HR(n,r)).filter(e=>e?.id),c=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),l=I(`input`,{class:`dw-db-input`,placeholder:o.searchPeople,"aria-label":o.searchPeople}),u=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(c,l,u);let d=()=>a.setCell(n.id,r.id,s),f=()=>c.replaceChildren(...s.map(e=>Iz(e.name,`gray`,()=>{s=s.filter(t=>t.id!==e.id),d(),f()}))),p=0,m=[],h=0,g=()=>{u.replaceChildren(...m.length?m.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===h?` is-active`:``}`,role:`option`},I(`span`,{class:`dw-db-person__dot`},(e.name||`?`).slice(0,1).toUpperCase()),I(`span`,{},e.name));return n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>_(e)),n}):[I(`div`,{class:`dw-db-pop__empty`},l.value.trim()?o.noPeople:``)])},_=e=>{s.some(t=>t.id===e.id)||(s=[...s,e]),d(),l.value=``,m=[],f(),g()};l.addEventListener(`input`,async()=>{let t=l.value.trim(),n=++p,r=e.people&&t?await e.people.search(t).catch(()=>[]):[];n===p&&(m=r.slice(0,8).map(e=>({id:e.id,name:e.label})),h=0,g())}),l.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),m.length&&(h=(h+(e.key===`ArrowDown`?1:-1)+m.length)%m.length),g();else if(e.key===`Enter`){e.preventDefault();let t=m[h];t?_(t):i()}}),f(),g(),l.focus({preventScroll:!0})}function Hz(e,t,n,r){let i=e.store,a=e.labels,o=qR(HR(n,r)).filter(e=>e?.src),s=I(`div`,{class:`dw-db-pop__list`}),c=()=>s.replaceChildren(...o.map((t,s)=>{let l=e.files?e.files.resolve(t.src):t.src,u=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":a.remove,title:a.remove},_z(`trash`,14));return u.addEventListener(`click`,()=>{o=o.filter((e,t)=>t!==s),i.setCell(n.id,r.id,o),c()}),I(`div`,{class:`dw-db-pop__item`},I(`a`,{class:`dw-db-file`,href:l,target:`_blank`,rel:`noopener noreferrer`},_z(`paperclip`,12),t.name),u)}));t.append(s);let l=e.files?.upload;if(l){let s=I(`button`,{type:`button`,class:`dw-db__btn`},_z(`upload`,14),I(`span`,{},a.upload));s.addEventListener(`click`,()=>{let t=I(`input`,{type:`file`,multiple:!0});t.onchange=async()=>{for(let a of[...t.files??[]])try{let t=await l.call(e.files,a);o=[...o,{name:t.name,src:t.url,size:t.size,mime:t.mime}],i.setCell(n.id,r.id,o),c()}catch{}},t.click()}),t.append(I(`div`,{class:`dw-db-pop__row`},s))}c()}var Uz=class{host;db;rowId;order;onClose;dom;panel;head=I(`div`,{class:`dw-db-peek__head`});props=I(`div`,{class:`dw-db-peek__props`});bodyEl=I(`div`,{class:`dw-db-peek__body`});unmount=null;editing=0;pending=!1;wide=!1;returnFocus;constructor(e,t,n,r,i){this.host=e,this.db=t,this.rowId=n,this.order=r,this.onClose=i,this.returnFocus=document.activeElement,this.panel=I(`div`,{class:`dw-db-peek__panel`,role:`dialog`,"aria-modal":`true`,tabIndex:-1},this.head,this.props,this.bodyEl),this.dom=I(`div`,{class:e.page?`dw-db-peek dw-db-peek--page`:`dw-db-peek`},this.panel),this.dom.addEventListener(`mousedown`,e=>{e.target===this.dom&&!this.host.page&&this.close()}),this.dom.addEventListener(`keydown`,e=>{e.key===`Escape`&&!document.querySelector(`.dw-db-pop, .dw-block-menu`)&&(e.preventDefault(),e.stopPropagation(),this.close())}),e.page?(this.panel.removeAttribute(`aria-modal`),this.panel.setAttribute(`role`,`region`),e.page.container.replaceChildren(this.dom)):document.body.append(this.dom),this.draw(!0),this.panel.focus({preventScroll:!0})}get row(){return this.rowId}ctx(){return{...this.host.ctx,db:this.db,openRow:e=>this.show(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw(!1))}}}update(e,t){if(this.db=e,t&&(this.host={...this.host,ctx:{...this.host.ctx,...t}}),!e.rows.some(e=>e.id===this.rowId))return this.close();this.editing?this.pending=!0:this.draw(!1)}show(e){e!==this.rowId&&(this.rowId=e,this.draw(!0))}draw(e){let t=this.db.rows.find(e=>e.id===this.rowId);if(!t)return;let n=this.ctx(),r=n.labels,i=n.store;this.panel.classList.toggle(`is-wide`,this.wide);let a=this.order.indexOf(this.rowId),o=vz(`chevron-up`,r.previousRow,()=>this.show(this.order[a-1])),s=vz(`chevron-down`,r.nextRow,()=>this.show(this.order[a+1]));o.disabled=a<=0,s.disabled=a<0||a>=this.order.length-1;let c=this.host.page;this.head.replaceChildren(...c?[vz(`chevron-left`,r.backToPage,()=>this.close())]:[],I(`span`,{class:`dw-db-peek__db`},_z(`database`,14),this.db.title||r.untitled),I(`span`,{class:`dw-db-peek__grow`}),o,s,...c?[]:[vz((this.wide,`width`),this.wide?r.collapse:r.expand,()=>{this.wide=!this.wide,this.panel.classList.toggle(`is-wide`,this.wide)})],...this.host.openPage?[vz(`open`,r.openFullPage,()=>this.host.openPage(this.rowId))]:[],...this.host.copyLink?[vz(`link`,r.copyLink,()=>this.host.copyLink(this.rowId))]:[],...c?[]:[vz(`close`,r.close,()=>this.close())]);let l=VR(this.db),u=String(HR(t,l)??``),d=i?(()=>{let e=I(`input`,{class:`dw-db-peek__title`,placeholder:r.untitledRow,"aria-label":l.name||r.typeTitle});return e.value=u,e.addEventListener(`focus`,()=>n.setEditing(!0)),e.addEventListener(`blur`,()=>{e.value!==u&&i.setCell(t.id,l.id,e.value),n.setEditing(!1)}),e.addEventListener(`keydown`,t=>{t.stopPropagation(),t.key===`Enter`&&e.blur()}),e})():I(`h2`,{class:`dw-db-peek__title`},u||r.untitledRow);this.panel.setAttribute(`aria-label`,u||r.untitledRow);let f=[d,...this.db.columns.filter(e=>e.type!==`title`).map(e=>{let a=I(`div`,{class:`dw-db-peek__value dw-db-t__cell--${e.type}`,tabIndex:i&&!Pz.includes(e.type)?0:-1},Rz(n,t,e)),o=()=>{i&&zz(n,a,t,e,{onDone:()=>this.draw(!1)})};return a.addEventListener(`click`,e=>{e.target.closest(`a, button`)||o()}),a.addEventListener(`keydown`,e=>{e.target===a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}),I(`div`,{class:`dw-db-peek__prop`},I(`div`,{class:`dw-db-peek__label`},_z(Mz[e.type],14),I(`span`,{},e.name||CR(r,e.type))),a)})];if(i){let e=vz(`plus`,r.addColumn,()=>Gj(e,MR.map(e=>({id:e,label:CR(r,e),icon:Mz[e],run:()=>i.addColumn(e,CR(r,e))})),r.addColumn),r.addColumn);e.classList.add(`dw-db-peek__add`),f.push(e)}let p=this.props.contains(document.activeElement);this.props.replaceChildren(...f),p&&this.panel.focus({preventScroll:!0}),e&&(this.unmount?.(),this.bodyEl.replaceChildren(),this.unmount=this.host.mountBody(this.bodyEl,t))}close(e=!0){this.unmount?.(),this.unmount=null,this.dom.remove(),this.onClose(),e&&this.host.page?.onLeave?.(),this.returnFocus instanceof HTMLElement&&this.returnFocus.isConnected&&this.returnFocus.focus({preventScroll:!0})}},Wz=`docwell-database`,Gz=e=>e.getMap(`blocks`);function Kz(e){let t=new Lb;t.set(`title`,e.title);let n=(e,t)=>{let n=new Pb;return n.push(e.map((e,n)=>qz(t(e),n))),n};return t.set(`columns`,n(e.columns,Jz)),t.set(`rows`,n(e.rows,Yz)),t.set(`views`,n(e.views,Xz)),t}function qz(e,t){return e.set(`pos`,t),e}function Jz(e){let t=new Lb;return t.set(`id`,e.id),t.set(`name`,e.name),t.set(`type`,e.type),e.options&&t.set(`options`,e.options),e.relation&&t.set(`relation`,e.relation),e.rollup&&t.set(`rollup`,e.rollup),t}function Yz(e){let t=new Lb;t.set(`id`,e.id),t.set(`createdAt`,e.createdAt),e.createdBy&&t.set(`createdBy`,e.createdBy);let n=new Lb;for(let[t,r]of Object.entries(e.cells))r!=null&&n.set(t,r);return t.set(`cells`,n),t}function Xz(e){let t=new Lb;for(let[n,r]of Object.entries(e))t.set(n,r);return t}function Zz(e){return e.toArray().filter(e=>e instanceof Lb).map((e,t)=>({m:e,p:Qz(e,t),i:t})).sort((e,t)=>e.p-t.p||e.i-t.i).map(e=>e.m)}function Qz(e,t){let n=e?.get(`pos`);return typeof n==`number`?n:t}function $z(e,t,n){let r=n?e.filter(e=>e!==n):e,i=Math.max(0,Math.min(t,r.length)),a=i>0?Qz(r[i-1],i-1):null,o=i{let n=e.get(t);return n instanceof Pb?Zz(n):[]},n=e=>{let t=e.toJSON();return delete t.pos,t},r=new Set,i=t(`rows`).map(e=>{let t=e.get(`cells`),n=e.get(`body`),i=e.get(`id`);return typeof i==`string`&&n instanceof ix&&n.length>0&&r.add(i),{id:i,createdAt:e.get(`createdAt`),createdBy:e.get(`createdBy`),cells:t instanceof Lb?t.toJSON():{}}}),a=LR({title:e.get(`title`),columns:t(`columns`).map(n),rows:i,views:t(`views`).map(n)});for(let e of a.rows)r.has(e.id)&&(e.hasBody=!0);return a}function tB(e,t=``){let n=[{id:PR(),name:e.columnName(`title`),type:`title`},{id:PR(),name:e.columnName(`select`),type:`select`,options:[]}],r=Date.now();return{title:t,columns:n,rows:[0,1,2].map(e=>({id:PR(),cells:{},createdAt:r+e,createdBy:null})),views:[FR(`table`,e.tableView,n)]}}var nB=e=>e==null||e===``||Array.isArray(e)&&!e.length,rB=class{doc;map;me;constructor(e,t,n){this.doc=e,this.map=t,this.me=n}snapshot(){return eB(this.map)}observe(e){let t=()=>e();return this.map.observeDeep(t),()=>this.map.unobserveDeep(t)}tx(e){this.doc.transact(e,Wz)}list(e){let t=this.map.get(e);return t instanceof Pb||(t=new Pb,this.map.set(e,t)),t}find(e,t){let n=Zz(this.list(e)),r=n.findIndex(e=>e.get(`id`)===t);return r<0?null:{item:n[r],index:r}}insertAt(e,t,n){let r=this.list(e),i=Zz(r),a=Math.max(0,Math.min(t??i.length,i.length));for(let e of n)e.set(`pos`,$z(i,a)),i.splice(a++,0,e);r.push(n)}moveTo(e,t,n){let r=this.find(e,t);r&&r.index!==n&&r.item.set(`pos`,$z(Zz(this.list(e)),n,r.item))}remove(e,t){let n=this.list(e),r=n.toArray().indexOf(t);r>=0&&n.delete(r,1)}setTitle(e){this.tx(()=>this.map.set(`title`,e))}addColumn(e,t,n){let r={id:PR(),name:t,type:e};return(e===`select`||e===`multiSelect`)&&(r.options=[]),this.tx(()=>this.insertAt(`columns`,n,[Jz(r)])),r.id}renameColumn(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`name`,t))}setRelation(e,t){this.tx(()=>{let n=this.find(`columns`,e);if(!n)return;let r=n.item.get(`relation`);if(n.item.set(`relation`,t),r&&(r.page!==t.page||r.database!==t.database))for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Lb&&n.delete(e)}})}setRollup(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`rollup`,t))}setOptions(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`options`,t))}changeType(e,t){let n=this.snapshot(),r=n.columns.find(t=>t.id===e);if(!r||r.type===t||r.type===`title`||t===`title`)return;let i=t===`select`||t===`multiSelect`?r.options??[]:[],a=new Map;for(let o of n.rows){let n=oz(o.cells[e],r,t,i);i=n.options,a.set(o.id,n.value)}this.tx(()=>{let n=this.find(`columns`,e);if(n){n.item.set(`type`,t),t===`select`||t===`multiSelect`?n.item.set(`options`,i):n.item.delete(`options`),t!==`relation`&&n.item.delete(`relation`),t!==`rollup`&&n.item.delete(`rollup`);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);if(!(n instanceof Lb))continue;let r=a.get(String(t.get(`id`)));nB(r)||r===!1?n.delete(e):n.set(e,r)}}})}deleteColumn(e){this.tx(()=>{let t=this.find(`columns`,e);if(t&&t.item.get(`type`)!==`title`){this.remove(`columns`,t.item);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Lb&&n.delete(e)}}})}moveColumn(e,t){this.tx(()=>this.moveTo(`columns`,e,t))}duplicateColumn(e,t){let n=this.snapshot().columns.find(t=>t.id===e);if(!n||n.type===`title`)return null;let r={...structuredClone(n),id:PR(),name:t};return this.tx(()=>{let t=this.find(`columns`,e);if(t){this.insertAt(`columns`,t.index+1,[Jz(r)]);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Lb&&n.has(e)&&n.set(r.id,n.get(e))}}}),r.id}addRow(e={},t){return this.addRows([e],t)[0]}addRows(e,t){let n=this.me(),r=Date.now(),i=e.map((e,t)=>({id:PR(),cells:e,createdAt:r+t,createdBy:n}));return this.tx(()=>this.insertAt(`rows`,t,i.map(Yz))),i.map(e=>e.id)}setCell(e,t,n){this.setCells([{row:e,col:t,value:n}])}setCells(e){this.tx(()=>{for(let{row:t,col:n,value:r}of e){let e=this.find(`rows`,t)?.item.get(`cells`);e instanceof Lb&&(nB(r)?e.delete(n):e.set(n,r))}})}deleteRows(e){this.tx(()=>{let t=this.list(`rows`);for(let n=t.length-1;n>=0;n--)e.includes(String(t.get(n)?.get(`id`)))&&t.delete(n,1)})}moveRow(e,t){this.tx(()=>this.moveTo(`rows`,e,t))}duplicateRow(e){let t=this.find(`rows`,e);if(!t)return null;let n=iB(t.item,this.me());return this.tx(()=>this.insertAt(`rows`,t.index+1,[n])),String(n.get(`id`))}rowBody(e){let t=this.find(`rows`,e);if(!t)return null;let n=t.item.get(`body`);if(n instanceof ix)return n;let r=new ix;return this.tx(()=>t.item.set(`body`,r)),r}rowIndex(e){return this.find(`rows`,e)?.index??-1}addView(e,t){let n=FR(e,t,this.snapshot().columns);return this.tx(()=>this.insertAt(`views`,void 0,[Xz(n)])),n.id}updateView(e,t){this.tx(()=>{let n=this.find(`views`,e);if(n)for(let[e,r]of Object.entries(t))n.item.set(e,r)})}duplicateView(e,t){let n=this.snapshot().views.find(t=>t.id===e);if(!n)return null;let r={...structuredClone(n),id:PR(),name:t};return this.tx(()=>{let t=this.find(`views`,e);this.insertAt(`views`,(t?.index??-1)+1,[Xz(r)])}),r.id}deleteView(e){this.tx(()=>{let t=this.find(`views`,e);t&&this.list(`views`).length>1&&this.remove(`views`,t.item)})}moveView(e,t){this.tx(()=>this.moveTo(`views`,e,t))}};function iB(e,t){let n=new Lb;n.set(`id`,PR()),n.set(`createdAt`,Date.now());let r=t??e.get(`createdBy`);BR(r)&&n.set(`createdBy`,r);let i=new Lb,a=e.get(`cells`);if(a instanceof Lb)for(let[e,t]of a.entries())i.set(e,t);n.set(`cells`,i);let o=e.get(`body`);if(o instanceof ix&&o.length){let e=new ix;e.insert(0,o.toArray().map(e=>e.clone())),n.set(`body`,e)}return n}function aB(e,t){let n=eB(e),r=e.get(`rows`);if(r instanceof Pb){let e=new Map;for(let t of r.toArray()){let n=t.get(`body`);n instanceof ix&&n.length&&e.set(String(t.get(`id`)),n)}for(let r of n.rows){let n=e.get(r.id);n&&(r.body=t(n))}}return n}function oB(e,t,n,r){e.transact(()=>{let i=Kz(n);Gz(e).set(t,i);let a=i.get(`rows`),o=new Map(n.rows.map(e=>[e.id,e]));for(let e of a.toArray()){let t=o.get(String(e.get(`id`)))?.body;if(!t?.length)continue;let n=new ix;e.set(`body`,n),r(t,n)}},Wz)}function sB(e,t=`,`){let n=[],r=[],i=``,a=!1,o=0,s=e.replace(/^\uFEFF/,``);for(;o({tr:r,dispatch:i,editor:a})=>{let o=fP(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(T.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>VM(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>HM(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return WM(e,t&&(e=>{n&&hP(e,n.pos),t(e)}))},addRowBefore:()=>({state:e,dispatch:t})=>qM(e,t),addRowAfter:()=>({state:e,dispatch:t})=>JM(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return XM(e,t&&(e=>{n&&hP(e,n.pos),t(e)}))},deleteTable:()=>({state:e,dispatch:t})=>lN(e,t),mergeCells:()=>({state:e,dispatch:t})=>$M(e,t),splitCell:()=>({state:e,dispatch:t})=>eN(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>aN(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>aN(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>oN(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>$M(e,t)?!0:eN(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>nN(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>cN(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>cN(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&LM(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=kM.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:mP,"Mod-Backspace":mP,Delete:mP,"Mod-Delete":mP}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[MN({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:null,lastColumnResizable:this.options.lastColumnResizable})]:[],KN({allowTableNodeSelection:this.options.allowTableNodeSelection}),TP()]},addNodeView(){let e=this.options.View;return e?({node:t,view:n,HTMLAttributes:r})=>{let i=A(this.options.HTMLAttributes,r);return new e(t,this.options.cellMinWidth,n,i)}:null},extendNodeSchema(e){return{tableRole:Nu(k(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}}),DP=Tp.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(EP.configure(this.options.table)),this.options.tableCell!==!1&&e.push(rP.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(iP.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(aP.configure(this.options.tableRow)),e}}),OP=Tp.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Pf(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}});function kP(){return[Bk.configure({HTMLAttributes:{class:`dw-tasks`}}),zk.configure({nested:!0})]}function AP(){return[DP.configure({table:{resizable:!0,cellMinWidth:60,HTMLAttributes:{class:`dw-table`}}})]}var jP=OP.configure({types:[`heading`,`paragraph`],alignments:[`left`,`center`,`right`]}),MP=Tp.create({name:`headingShortcuts`,addKeyboardShortcuts(){let e={"Mod-Shift-0":()=>this.editor.commands.setParagraph()};for(let t of[1,2,3,4,5,6])e[`Mod-Shift-${t}`]=()=>this.editor.commands.toggleHeading({level:t});return e}}),NP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,PP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,FP=_p.create({name:`highlight`,addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute(`data-color`)||Af(e,`background-color`)||e.style.backgroundColor,renderHTML:e=>Pf(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:`mark`}]},renderHTML({HTMLAttributes:e}){return[`mark`,A(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark(`highlight`,t.parseInline(e.tokens||[])),markdownTokenizer:{name:`highlight`,level:`inline`,start:e=>e.indexOf(`==`),tokenize(e,t,n){let r=/^(==)(?!\s)([^=]*[^=\s])(==)/.exec(e);if(r){let e=r[2].trim(),t=n.inlineTokens(e);return{type:`highlight`,raw:r[0],text:e,tokens:t}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Hp({find:NP,type:this.type})]},addPasteRules(){return[Yp({find:PP,type:this.type})]}}),IP=[`gray`,`red`,`orange`,`yellow`,`green`,`teal`,`blue`,`purple`,`pink`],LP=e=>typeof e==`string`&&IP.includes(e),RP=_p.create({name:`textColor`,addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return LP(t)?t:null},renderHTML:e=>e.color?{"data-color":e.color}:{}}}},parseHTML(){return[{tag:`span[data-color]`,getAttrs:e=>LP(e.getAttribute(`data-color`))?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{class:`dw-text-color`}),0]},addCommands(){return{setTextColor:e=>({commands:t})=>t.setMark(this.name,{color:e}),unsetTextColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),zP=FP.extend({addOptions(){return{...this.parent(),multicolor:!0}},addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return LP(t)?t:null},renderHTML:e=>({"data-color":LP(e.color)?e.color:`yellow`})}}},renderHTML({HTMLAttributes:e}){return[`mark`,A(e,{class:`dw-highlight`}),0]}}),BP=`💡`;function VP(e){let t=e.trim();return t&&[...t].length<=4?t:``}var HP=Jp.create({name:`callout`,group:`block`,content:`block+`,defining:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{emoji:{default:BP,parseHTML:e=>VP(e.getAttribute(`data-emoji`)??``)||BP,renderHTML:e=>({"data-emoji":e.emoji})},color:{default:`blue`,parseHTML:e=>{let t=e.getAttribute(`data-color`);return LP(t)?t:`blue`},renderHTML:e=>({"data-color":e.color})}}},parseHTML(){return[{tag:`aside[data-type=callout]`,contentElement:e=>e.querySelector(`:scope > .callout-body`)??e}]},renderHTML({HTMLAttributes:e}){return[`aside`,A(e,{"data-type":`callout`,class:`dw-callout`}),0]},addCommands(){return{setCallout:e=>({commands:t})=>t.wrapIn(this.name,e),unsetCallout:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;for(let n=t.depth-1;n>0;n--){if(t.node(n).type.name===this.name)return t.index(n)!==0||t.start(n+1)!==t.start()?!1:e.commands.lift(this.name);if(t.index(n)!==0)return!1}return!1}}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`aside`);i.className=`dw-callout`,i.setAttribute(`data-type`,`callout`);let a=document.createElement(`div`);a.className=`dw-callout__side`,a.contentEditable=`false`;let o=document.createElement(`button`);o.type=`button`,o.className=`dw-callout__emoji`;let s=document.createElement(`button`);s.type=`button`,s.className=`dw-callout__color`,a.append(o,s);let c=document.createElement(`div`);c.className=`dw-callout__body`,i.append(a,c);let l=e,u=e=>{let r=t();typeof r==`number`&&n.isEditable&&n.view.dispatch(n.state.tr.setNodeMarkup(r,void 0,{...l.attrs,...e}))};o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>{if(!n.isEditable)return;let e=VP(window.prompt(r?.blocks.calloutEmoji??`Emoji`,l.attrs.emoji)??``);e&&u({emoji:e})}),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=IP.indexOf(l.attrs.color);u({color:IP[(e+1)%IP.length]})});let d=()=>{i.setAttribute(`data-color`,String(l.attrs.color)),o.textContent=String(l.attrs.emoji);let e=r?.blocks.calloutEmoji??`Emoji`;o.setAttribute(`aria-label`,e),o.title=e;let t=r?.blocks.calloutColor??`Colour`;s.setAttribute(`aria-label`,t),s.title=t};return d(),{dom:i,contentDOM:c,update:t=>t.type===e.type&&(l=t,d(),!0),stopEvent:e=>a.contains(e.target),ignoreMutation:e=>a.contains(e.target)}}}}),UP=e=>[e.x+e.w/2,e.y+e.h/2];function WP(e){if(!e.length)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),i=Math.max(i,a.y+a.h);return{x:t,y:n,w:r-t,h:i-n}}var GP=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),KP=(e,t)=>e.x<=t.x+t.w&&t.x<=e.x+e.w&&e.y<=t.y+t.h&&t.y<=e.y+e.h,qP=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h;function JP(e,t){return{x:Math.min(e[0],t[0]),y:Math.min(e[1],t[1]),w:Math.abs(e[0]-t[0]),h:Math.abs(e[1]-t[1])}}function YP([e,t],[n,r],i){if(!i)return[e,t];let a=i*Math.PI/180,o=Math.cos(a),s=Math.sin(a);return[n+(e-n)*o-(t-r)*s,r+(e-n)*s+(t-r)*o]}function XP(e,t){if(!t)return e;let n=UP(e),r=[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>YP(e,n,t));return JP([Math.min(...r.map(e=>e[0])),Math.min(...r.map(e=>e[1]))],[Math.max(...r.map(e=>e[0])),Math.max(...r.map(e=>e[1]))])}function ZP([e,t],[n,r],[i,a]){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function QP(e,t){if(t.length===1)return Math.hypot(e[0]-t[0][0],e[1]-t[0][1]);let n=1/0;for(let r=1;re[1]-t[1]),r[0][0]}var eF={left:[-1,0],right:[1,0],top:[0,-1],bottom:[0,1]};function tF(e,t,n=!1){let[r,i]=UP(e),a=t[0]-r,o=t[1]-i;if(!a&&!o)return[r,i];let s=Math.max(e.w/2,.5),c=Math.max(e.h/2,.5),l=n?1/Math.sqrt(a*a/(s*s)+o*o/(c*c)):Math.min(Math.abs(s/(a||1e-9)),Math.abs(c/(o||1e-9)));return[r+a*l,i+o*l]}var nF=e=>[[`top`,[e.x+e.w/2,e.y]],[`right`,[e.x+e.w,e.y+e.h/2]],[`bottom`,[e.x+e.w/2,e.y+e.h]],[`left`,[e.x,e.y+e.h/2]]];function rF(e,t){let n=e=>{if(!e.id)return[e.x??0,e.y??0];let n=t(e.id);return n?e.pos?[n.box.x+n.box.w*e.pos[0],n.box.y+n.box.h*e.pos[1]]:null:[e.x??0,e.y??0]},r=e=>{let n=e.id?t(e.id):null;return n?UP(n.box):[e.x??0,e.y??0]},i=(e,i)=>{let a=n(e),o=e.id?t(e.id):null;if(a)return{at:a,side:o?$P(o.box,a):null};let s=tF(o.box,n(i)??r(i),o.ellipse);return{at:s,side:$P(o.box,s)}};return[i(e.source,e.target),i(e.target,e.source)]}var iF=e=>Math.round(e*100)/100,aF=e=>e.map((e,t)=>`${t?`L`:`M`}${iF(e[0])} ${iF(e[1])}`).join(` `),oF=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);function sF(e,t,n){let[r,i]=t.at,[a,o]=n.at,s=Math.hypot(a-r,o-i);if(e===`straight`||s<1)return{points:[t.at,n.at],d:aF([t.at,n.at]),mid:[(r+a)/2,(i+o)/2],startAngle:oF(n.at,t.at),endAngle:oF(t.at,n.at)};if(e===`curve`){let e=Math.min(s/2,160),c=t.side?eF[t.side]:cF(t.at,n.at),l=n.side?eF[n.side]:cF(n.at,t.at),u=[r+c[0]*e,i+c[1]*e],d=[a+l[0]*e,o+l[1]*e],f=[];for(let e=0;e<=24;e++)f.push(lF(t.at,u,d,n.at,e/24));return{points:f,d:`M${iF(r)} ${iF(i)} C${iF(u[0])} ${iF(u[1])} ${iF(d[0])} ${iF(d[1])} ${iF(a)} ${iF(o)}`,mid:lF(t.at,u,d,n.at,.5),startAngle:oF(u,t.at),endAngle:oF(d,n.at)}}let c=t.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`right`:`left`:o>i?`bottom`:`top`),l=n.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`left`:`right`:o>i?`top`:`bottom`),u=[r+eF[c][0]*24,i+eF[c][1]*24],d=[a+eF[l][0]*24,o+eF[l][1]*24],f=c===`left`||c===`right`,p=l===`left`||l===`right`,m;if(f&&p){let e=(u[0]+d[0])/2;m=[[e,u[1]],[e,d[1]]]}else if(!f&&!p){let e=(u[1]+d[1])/2;m=[[u[0],e],[d[0],e]]}else m=f?[[d[0],u[1]]]:[[u[0],d[1]]];let h=uF([t.at,u,...m,d,n.at]);return{points:h,d:aF(h),mid:dF(h),startAngle:oF(h[1]??n.at,t.at),endAngle:oF(h[h.length-2]??t.at,n.at)}}function cF(e,t){let n=Math.hypot(t[0]-e[0],t[1]-e[1])||1;return[(t[0]-e[0])/n,(t[1]-e[1])/n]}function lF(e,t,n,r,i){let a=1-i,o=a*a*a,s=3*a*a*i,c=3*a*i*i,l=i*i*i;return[o*e[0]+s*t[0]+c*n[0]+l*r[0],o*e[1]+s*t[1]+c*n[1]+l*r[1]]}function uF(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Math.abs(e[0]-n[0])<.01&&Math.abs(e[1]-n[1])<.01)continue;let r=t[t.length-2];if(r&&e){let i=(e[0]-r[0])*(n[1]-r[1])-(e[1]-r[1])*(n[0]-r[0]);Math.abs(i)<.01&&t.pop()}t.push(n)}return t}function dF(e){let t=0;for(let n=1;n=n&&a>0)return[r[0]+(i[0]-r[0])*n/a,r[1]+(i[1]-r[1])*n/a];n-=a}return e[0]??[0,0]}function fF(e,t,n){let r=e=>[e.x,e.x+e.w/2,e.x+e.w],i=e=>[e.y,e.y+e.h/2,e.y+e.h],a={dx:0,ox:null,vx:0},o={dy:0,oy:null,vy:0},s=n+1,c=n+1;for(let n of t){for(let t of r(e))for(let e of r(n)){let r=Math.abs(e-t);rtypeof e==`string`&&gF.includes(e),vF=[`rect`,`roundrect`,`ellipse`,`diamond`,`triangle`],yF=[`straight`,`curve`,`elbow`],bF=[`none`,`arrow`,`triangle`,`circle`,`diamond`],xF=[`right`,`left`,`radial`],SF=`page`,CF=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,wF=(e,t=``)=>typeof e==`string`?e:t,TF=e=>e===!0,EF=(e,t)=>_F(e)?e:t,DF=(e,t,n)=>typeof e==`string`&&t.includes(e)?e:n;function OF(e){if(!e||typeof e!=`object`)return{x:0,y:0};let t=e,n={};return typeof t.id==`string`&&t.id&&(n.id=t.id),Array.isArray(t.pos)&&t.pos.length===2&&(n.pos=[CF(t.pos[0],.5),CF(t.pos[1],.5)]),n.id||(n.x=CF(t.x,0),n.y=CF(t.y,0)),n}function kF(e){let t={};if(!e||typeof e!=`object`)return t;for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`)continue;let e=r;t[n]={text:wF(e.text),parent:wF(e.parent),pos:CF(e.pos,0)}}return t}function AF(e){let t={id:wF(e.id),index:CF(e.index,0),x:CF(e.x,0),y:CF(e.y,0),w:Math.max(0,CF(e.w,0)),h:Math.max(0,CF(e.h,0)),rotate:CF(e.rotate,0),group:wF(e.group)};switch(e.type){case`shape`:return{...t,type:`shape`,shape:DF(e.shape,vF,`rect`),stroke:EF(e.stroke,`ink`),fill:EF(e.fill,`none`),strokeWidth:CF(e.strokeWidth,2),strokeStyle:DF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),rough:TF(e.rough),text:wF(e.text),textColor:EF(e.textColor,`ink`),fontSize:CF(e.fontSize,18)};case`text`:return{...t,type:`text`,text:wF(e.text),color:EF(e.color,`ink`),fontSize:CF(e.fontSize,24),font:DF(e.font,[``,`serif`,`mono`],``),align:DF(e.align,[`left`,`center`,`right`],`left`),bold:TF(e.bold)};case`connector`:return{...t,type:`connector`,source:OF(e.source),target:OF(e.target),mode:DF(e.mode,yF,`curve`),stroke:EF(e.stroke,`ink`),strokeWidth:CF(e.strokeWidth,2),strokeStyle:DF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),startArrow:DF(e.startArrow,bF,`none`),endArrow:DF(e.endArrow,bF,`arrow`),label:wF(e.label),rough:TF(e.rough)};case`brush`:return{...t,type:`brush`,points:Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&e.length>=2).map(e=>[CF(e[0],0),CF(e[1],0),CF(e[2],.5)]):[],color:EF(e.color,`ink`),size:CF(e.size,4)};case`note`:return{...t,type:`note`,page:TF(e.page),background:EF(e.background,`paper`)};case`frame`:return{...t,type:`frame`,title:wF(e.title),background:EF(e.background,`none`)};case`image`:return{...t,type:`image`,src:wF(e.src),alt:wF(e.alt)};case`embed`:return{...t,type:`embed`,url:wF(e.url)};case`group`:return{...t,type:`group`,title:wF(e.title)};case`mindmap`:return{...t,type:`mindmap`,layout:DF(e.layout,xF,`right`),color:EF(e.color,`blue`),nodes:kF(e.nodes)};default:return null}}var jF=e=>![`connector`,`group`,`mindmap`].includes(e.type),MF=e=>[`shape`,`text`,`image`,`brush`].includes(e.type),NF=e=>![`connector`,`brush`,`group`].includes(e.type),PF=0;function FF(){return PF=(PF+1)%1296,Date.now().toString(36).slice(-6)+PF.toString(36).padStart(2,`0`)+Math.random().toString(36).slice(2,8)}var IF={shape:{shape:`rect`,stroke:`blue`,fill:`blue`,strokeWidth:2,strokeStyle:`solid`,rough:!1,textColor:`ink`},connector:{mode:`curve`,stroke:`gray`,strokeWidth:2,strokeStyle:`solid`,startArrow:`none`,endArrow:`arrow`},brush:{color:`ink`,size:4},text:{color:`ink`,fontSize:24,font:``},note:{background:`yellow`},frame:{background:`none`},mindmap:{layout:`right`,color:`blue`}};function LF(e){let t=structuredClone(IF);if(!e||typeof e!=`object`)return t;for(let n of Object.keys(t)){let r=e[n];if(!r||typeof r!=`object`)continue;let i=AF({...t[n],...r,type:n===`note`?`note`:n});if(i)for(let e of Object.keys(t[n])){let a=r[e];a!==void 0&&i[e]===a&&(t[n][e]=a)}}return t}var RF=[`👍`,`⭐`,`❤️`,`✅`,`❌`,`💡`,`❓`,`❗`,`🎉`,`🔥`,`📌`,`🚀`,`👀`,`🎯`,`⚠️`,`🙂`];function zF(e){return[{id:FF(),type:`text`,text:e,fontSize:64,x:0,y:0,w:0,h:0}]}var BF=[`kanban`,`swot`,`flow`,`brainstorm`,`retro`],VF=e=>[{type:`paragraph`,content:e?[{type:`text`,text:e}]:[]}],HF=(e,t,n,r,i,a=`none`)=>({id:FF(),type:`frame`,title:e,x:t,y:n,w:r,h:i,background:a}),UF=(e,t,n,r,i=220)=>({id:FF(),type:`note`,background:r,x:t,y:n,w:i,h:90,body:VF(e)}),WF=(e,t,n,r,i,a,o)=>({id:FF(),type:`shape`,shape:e,text:t,x:n,y:r,w:i,h:a,stroke:o,fill:o,strokeWidth:2}),GF=(e,t,n=`elbow`)=>({id:FF(),type:`connector`,source:{id:e},target:{id:t},mode:n,stroke:`gray`,endArrow:`arrow`});function KF(e,t){switch(e){case`kanban`:return[[t.todo,`gray`],[t.doing,`blue`],[t.done,`green`]].flatMap(([e,t],n)=>[HF(e,n*300,0,280,520),UF(``,n*300+30,50,t),UF(``,n*300+30,170,t)]);case`swot`:return[[t.strengths,`green`],[t.weaknesses,`red`],[t.opportunities,`blue`],[t.threats,`orange`]].flatMap(([e,t],n)=>[WF(`roundrect`,e,n%2*380,Math.floor(n/2)*300,360,280,t)]);case`flow`:{let e=WF(`ellipse`,t.start,0,0,180,70,`green`),n=WF(`rect`,t.step,0,140,180,80,`blue`),r=WF(`diamond`,t.decision,-10,290,200,120,`orange`),i=WF(`rect`,t.step,280,310,180,80,`blue`),a=WF(`ellipse`,t.end,0,480,180,70,`red`);return[e,n,r,i,a,GF(e.id,n.id),GF(n.id,r.id),GF(r.id,i.id),GF(r.id,a.id)]}case`brainstorm`:{let e=FF(),n={[e]:{text:t.centralIdea,parent:``,pos:0}};for(let r=0;r<4;r++)n[FF()]={text:`${t.idea} ${r+1}`,parent:e,pos:r};return[{id:FF(),type:`mindmap`,layout:`radial`,color:`purple`,x:0,y:0,nodes:n}]}case`retro`:return[[t.wentWell,`green`],[t.toImprove,`orange`],[t.actions,`blue`]].flatMap(([e,t],n)=>[HF(e,n*300,0,280,420),UF(``,n*300+30,50,t)])}}var qF;function JF(){if(qF!==void 0)return qF;try{qF=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{qF=null}return qF}var YF=`"Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif`,XF=`"Source Serif 4 Variable", "Source Serif 4", Georgia, serif`,ZF=`"JetBrains Mono Variable", "JetBrains Mono", ui-monospace, monospace`;function QF(e){return e===`serif`?XF:e===`mono`?ZF:YF}function $F(e,t,n=YF,r=400){let i=JF();return i?(i.font=`${r} ${t}px ${n}`,i.measureText(e).width):e.length*t*.56}function eI(e,t,n,r=YF,i=400){let a=[];for(let o of e.split(` +`)){if(!o){a.push(``);continue}let e=``;for(let s of o.split(/(\s+)/)){let o=e+s;if(!e||$F(o,t,r,i)<=n)e=o;else for(a.push(e.trimEnd()),e=s.trimStart();e&&$F(e,t,r,i)>n;){let o=e.length-1;for(;o>1&&$F(e.slice(0,o),t,r,i)>n;)o--;a.push(e.slice(0,o)),e=e.slice(o)}}a.push(e)}return a}function tI(e,t){let n=t===0?18:15,r=t===0?600:400,i=eI(e||` `,n,260,YF,r),a=Math.max(...i.map(e=>$F(e,n,YF,r)),t===0?60:40);return{w:Math.ceil(a)+(t===0?32:24),h:i.length*Math.round(n*1.4)+(t===0?20:14)}}var nI=56,rI=14;function iI(e){let t=Object.entries(e).filter(([,t])=>!t.parent||!e[t.parent]);return t.sort((e,t)=>e[1].pos-t[1].pos||(e[0]n.parent===t&&e!==t).sort((e,t)=>e[1].pos-t[1].pos||(e[0]e)}function oI(e,t,n){let r=iI(e),i=new Map,a=[];if(!r)return{root:``,boxes:i,edges:a,bounds:{x:0,y:0,w:0,h:0}};let o=new Map,s=new Set,c=(t,r)=>{if(!(s.has(t)||r>50)){s.add(t),o.set(t,n(e[t].text,r));for(let n of aI(e,t))c(n,r+1)}};c(r,0);let l=t=>aI(e,t).filter(e=>o.has(e)),u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;let n=l(e),r=n.reduce((e,t)=>e+d(t),0)+rI*Math.max(0,n.length-1),i=Math.max(o.get(e).h,r);return u.set(e,i),i},f=(e,t,n,r,a,s)=>{let c=o.get(e),u=a===1?t:t-c.w;i.set(e,{id:e,x:u,y:n-c.h/2,w:c.w,h:c.h,depth:r,dir:a,parent:s}),p(e,l(e),a===1?u+c.w+nI:u-nI,n,r+1,a)},p=(e,t,n,r,i,a)=>{let o=r-(t.reduce((e,t)=>e+d(t),0)+rI*Math.max(0,t.length-1))/2;for(let r of t){let t=d(r);f(r,n,o+t/2,i,a,e),o+=t+rI}},m=o.get(r);i.set(r,{id:r,x:0,y:0,w:m.w,h:m.h,depth:0,dir:1,parent:``});let h=m.h/2,g=l(r);if(t===`right`)p(r,g,m.w+nI,h,1,1);else if(t===`left`)p(r,g,-56,h,1,-1);else{let e=Math.ceil(g.length/2);p(r,g.slice(0,e),m.w+nI,h,1,1),p(r,g.slice(e),-56,h,1,-1)}for(let e of i.values()){if(!e.parent)continue;let t=i.get(e.parent),n=e.dir===1?[t.x+t.w,t.y+t.h/2]:[t.x,t.y+t.h/2],r=e.dir===1?[e.x,e.y+e.h/2]:[e.x+e.w,e.y+e.h/2];a.push({from:n,to:r,child:e.id})}let _=1/0,v=1/0,y=-1/0,b=-1/0;for(let e of i.values())_=Math.min(_,e.x),v=Math.min(v,e.y),y=Math.max(y,e.x+e.w),b=Math.max(b,e.y+e.h);return{root:r,boxes:i,edges:a,bounds:{x:_,y:v,w:y-_,h:b-v}}}function sI(e,t,n,r){let i=e.boxes.get(n);if(!i)return null;if(r===`ArrowUp`||r===`ArrowDown`){let a=i.parent?aI(t,i.parent).filter(t=>e.boxes.get(t)?.dir===i.dir):[];return a[a.indexOf(n)+(r===`ArrowUp`?-1:1)]??null}let a=r===`ArrowRight`?1:-1;return i.parent?a===i.dir?aI(t,n)[0]??null:i.parent:aI(t,n).find(t=>e.boxes.get(t)?.dir===a)??null}function cI(e,t){let n=(e[0]+t[0])/2;return`M${e[0]} ${e[1]} C${n} ${e[1]} ${n} ${t[1]} ${t[0]} ${t[1]}`}function lI(e,t,n,r=e=>e){return e*r(.5-t*(.5-n))}function uI(e){return[-e[0],-e[1]]}function dI(e,t){return[e[0]+t[0],e[1]+t[1]]}function fI(e,t){return[e[0]-t[0],e[1]-t[1]]}function pI(e,t){return[e[0]*t,e[1]*t]}function mI(e,t){return[e[0]/t,e[1]/t]}function hI(e){return[e[1],-e[0]]}function gI(e,t){return e[0]*t[0]+e[1]*t[1]}function _I(e,t){return e[0]===t[0]&&e[1]===t[1]}function vI(e){return Math.hypot(e[0],e[1])}function yI(e){return e[0]*e[0]+e[1]*e[1]}function bI(e,t){return yI(fI(e,t))}function xI(e){return mI(e,vI(e))}function SI(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function CI(e,t,n){let r=Math.sin(n),i=Math.cos(n),a=e[0]-t[0],o=e[1]-t[1],s=a*i-o*r,c=a*r+o*i;return[s+t[0],c+t[1]]}function wI(e,t,n){return dI(e,pI(fI(t,e),n))}function TI(e,t,n){return dI(e,pI(t,n))}var{min:EI,PI:DI}=Math,OI=.275,kI=DI+1e-4;function AI(e,t={}){let{size:n=16,smoothing:r=.5,thinning:i=.5,simulatePressure:a=!0,easing:o=e=>e,start:s={},end:c={},last:l=!1}=t,{cap:u=!0,easing:d=e=>e*(2-e)}=s,{cap:f=!0,easing:p=e=>--e*e*e+1}=c;if(e.length===0||n<=0)return[];let m=e[e.length-1].runningLength,h=s.taper===!1?0:s.taper===!0?Math.max(n,m):s.taper,g=c.taper===!1?0:c.taper===!0?Math.max(n,m):c.taper,_=(n*r)**2,v=[],y=[],b=e.slice(0,10).reduce((e,t)=>{let r=t.pressure;if(a){let i=EI(1,t.distance/n);r=EI(1,e+(EI(1,1-i)-e)*(i*OI))}return(e+r)/2},e[0].pressure),x=lI(n,i,e[e.length-1].pressure,o),S,C=e[0].vector,ee=e[0].point,te=ee,ne=ee,re=te,ie=!1;for(let t=0;t_)&&(v.push(ne),ee=ne),re=dI(s,ue),(t<=1||bI(te,re)>_)&&(y.push(re),te=re),b=r,C=c}let ae=e[0].point.slice(0,2),oe=e.length>1?e[e.length-1].point.slice(0,2):dI(e[0].point,[1,1]),se=[],ce=[];if(e.length===1){if(!(h||g)||l){let e=TI(ae,xI(hI(fI(ae,oe))),-(S||x)),t=[];for(let n=1/13,r=n;r<=1;r+=n)t.push(CI(e,ae,kI*2*r));return t}}else{if(!(h||g&&e.length===1)){if(u)for(let e=1/13,t=e;t<=1;t+=e){let e=CI(y[0],ae,kI*t);se.push(e)}else{let e=fI(v[0],y[0]),t=pI(e,.5),n=pI(e,.51);se.push(fI(ae,t),fI(ae,n),dI(ae,n),dI(ae,t))}}let t=hI(uI(e[e.length-1].vector));if(g||h&&e.length===1)ce.push(oe);else if(f){let e=TI(oe,t,x);for(let t=1/29,n=t;n<1;n+=t)ce.push(CI(e,oe,kI*3*n))}else ce.push(dI(oe,pI(t,x)),dI(oe,pI(t,x*.99)),fI(oe,pI(t,x*.99)),fI(oe,pI(t,x)))}return v.concat(ce,y.reverse(),se)}function jI(e,t={}){let{streamline:n=.5,size:r=16,last:i=!1}=t;if(e.length===0)return[];let a=.15+(1-n)*.85,o=Array.isArray(e[0])?e:e.map(({x:e,y:t,pressure:n=.5})=>[e,t,n]);if(o.length===2){let e=o[1];o=o.slice(0,-1);for(let t=1;t<5;t++)o.push(wI(o[0],e,t/4))}o.length===1&&(o=[...o,[...dI(o[0],[1,1]),...o[0].slice(2)]]);let s=[{point:[o[0][0],o[0][1]],pressure:o[0][2]>=0?o[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,l=0,u=s[0],d=o.length-1;for(let e=1;e=0?o[e][2]:.5,vector:xI(fI(u.point,t)),distance:n,runningLength:l},s.push(u)}return s[0].vector=s[1]?.vector||[0,0],s}function MI(e,t={}){return AI(jI(e,t),t)}function NI(e,t,n){if(e&&e.length){let[r,i]=t,a=Math.PI/180*n,o=Math.cos(a),s=Math.sin(a);for(let t of e){let[e,n]=t;t[0]=(e-r)*o-(n-i)*s+r,t[1]=(e-r)*s+(n-i)*o+i}}}function PI(e,t){return e[0]===t[0]&&e[1]===t[1]}function FI(e,t,n,r=1){let i=n,a=Math.max(t,.1),o=e[0]&&e[0][0]&&typeof e[0][0]==`number`?[e]:e,s=[0,0];if(i)for(let e of o)NI(e,s,i);let c=function(e,t,n){let r=[];for(let t of e){let e=[...t];PI(e[0],e[e.length-1])||e.push([e[0][0],e[0][1]]),e.length>2&&r.push(e)}let i=[];t=Math.max(t,.1);let a=[];for(let e of r)for(let t=0;te.ymint.ymin?1:e.xt.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!a.length)return i;let o=[],s=a[0].ymin,c=0;for(;o.length||a.length;){if(a.length){let e=-1;for(let t=0;ts);t++)e=t;a.splice(0,e+1).forEach((e=>{o.push({s,edge:e})}))}if(o=o.filter((e=>!(e.edge.ymax<=s))),o.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),(n!==1||c%t==0)&&o.length>1)for(let e=0;e=o.length)break;let n=o[e].edge,r=o[t].edge;i.push([[Math.round(n.x),s],[Math.round(r.x),s]])}s+=n,o.forEach((e=>{e.edge.x=e.edge.x+n*e.edge.islope})),c++}return i}(o,a,r);if(i){for(let e of o)NI(e,s,-i);(function(e,t,n){let r=[];e.forEach((e=>r.push(...e))),NI(r,t,n)})(c,s,-i)}return c}function II(e,t){let n=t.hachureAngle+90,r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=1;return t.roughness>=1&&(t.randomizer?.next()||Math.random())>.7&&(i=r),FI(e,r,n,i||1)}var LI=class{constructor(e){this.helper=e}fillPolygons(e,t){return this._fillPolygons(e,t)}_fillPolygons(e,t){let n=II(e,t);return{type:`fillSketch`,ops:this.renderLines(n,t)}}renderLines(e,t){let n=[];for(let r of e)n.push(...this.helper.doubleLineOps(r[0][0],r[0][1],r[1][0],r[1][1],t));return n}};function RI(e){let t=e[0],n=e[1];return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2)}var zI=class extends LI{fillPolygons(e,t){let n=t.hachureGap;n<0&&(n=4*t.strokeWidth),n=Math.max(n,.1);let r=II(e,Object.assign({},t,{hachureGap:n})),i=Math.PI/180*t.hachureAngle,a=[],o=.5*n*Math.cos(i),s=.5*n*Math.sin(i);for(let[e,t]of r)RI([e,t])&&a.push([[e[0]-o,e[1]+s],[...t]],[[e[0]+o,e[1]-s],[...t]]);return{type:`fillSketch`,ops:this.renderLines(a,t)}}},BI=class extends LI{fillPolygons(e,t){let n=this._fillPolygons(e,t),r=Object.assign({},t,{hachureAngle:t.hachureAngle+90}),i=this._fillPolygons(e,r);return n.ops=n.ops.concat(i.ops),n}},VI=class{constructor(e){this.helper=e}fillPolygons(e,t){let n=II(e,t=Object.assign({},t,{hachureAngle:0}));return this.dotsOnLines(n,t)}dotsOnLines(e,t){let n=[],r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=t.fillWeight;i<0&&(i=t.strokeWidth/2);let a=r/4;for(let o of e){let e=RI(o),s=e/r,c=Math.ceil(s)-1,l=e-c*r,u=(o[0][0]+o[1][0])/2-r/4,d=Math.min(o[0][1],o[1][1]);for(let e=0;e{let a=RI(e),o=Math.floor(a/(n+r)),s=(a+r-o*(n+r))/2,c=e[0],l=e[1];c[0]>l[0]&&(c=e[1],l=e[0]);let u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let e=0;e{let i=RI(e),a=Math.round(i/(2*t)),o=e[0],s=e[1];o[0]>s[0]&&(o=e[1],s=e[0]);let c=Math.atan((s[1]-o[1])/(s[0]-o[0]));for(let e=0;er%2?e+n:e+t));a.push({key:`C`,data:e}),t=e[4],n=e[5];break}case`Q`:a.push({key:`Q`,data:[...s]}),t=s[2],n=s[3];break;case`q`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`Q`,data:e}),t=e[2],n=e[3];break}case`A`:a.push({key:`A`,data:[...s]}),t=s[5],n=s[6];break;case`a`:t+=s[5],n+=s[6],a.push({key:`A`,data:[s[0],s[1],s[2],s[3],s[4],t,n]});break;case`H`:a.push({key:`H`,data:[...s]}),t=s[0];break;case`h`:t+=s[0],a.push({key:`H`,data:[t]});break;case`V`:a.push({key:`V`,data:[...s]}),n=s[0];break;case`v`:n+=s[0],a.push({key:`V`,data:[n]});break;case`S`:a.push({key:`S`,data:[...s]}),t=s[2],n=s[3];break;case`s`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`S`,data:e}),t=e[2],n=e[3];break}case`T`:a.push({key:`T`,data:[...s]}),t=s[0],n=s[1];break;case`t`:t+=s[0],n+=s[1],a.push({key:`T`,data:[t,n]});break;case`Z`:case`z`:a.push({key:`Z`,data:[]}),t=r,n=i}return a}function $I(e){let t=[],n=``,r=0,i=0,a=0,o=0,s=0,c=0;for(let{key:l,data:u}of e){switch(l){case`M`:t.push({key:`M`,data:[...u]}),[r,i]=u,[a,o]=u;break;case`C`:t.push({key:`C`,data:[...u]}),r=u[4],i=u[5],s=u[2],c=u[3];break;case`L`:t.push({key:`L`,data:[...u]}),[r,i]=u;break;case`H`:r=u[0],t.push({key:`L`,data:[r,i]});break;case`V`:i=u[0],t.push({key:`L`,data:[r,i]});break;case`S`:{let e=0,a=0;n===`C`||n===`S`?(e=r+(r-s),a=i+(i-c)):(e=r,a=i),t.push({key:`C`,data:[e,a,...u]}),s=u[0],c=u[1],r=u[2],i=u[3];break}case`T`:{let[e,a]=u,o=0,l=0;n===`Q`||n===`T`?(o=r+(r-s),l=i+(i-c)):(o=r,l=i);let d=r+2*(o-r)/3,f=i+2*(l-i)/3,p=e+2*(o-e)/3,m=a+2*(l-a)/3;t.push({key:`C`,data:[d,f,p,m,e,a]}),s=o,c=l,r=e,i=a;break}case`Q`:{let[e,n,a,o]=u,l=r+2*(e-r)/3,d=i+2*(n-i)/3,f=a+2*(e-a)/3,p=o+2*(n-o)/3;t.push({key:`C`,data:[l,d,f,p,a,o]}),s=e,c=n,r=a,i=o;break}case`A`:{let e=Math.abs(u[0]),n=Math.abs(u[1]),a=u[2],o=u[3],s=u[4],c=u[5],l=u[6];e===0||n===0?(t.push({key:`C`,data:[r,i,c,l,c,l]}),r=c,i=l):(r!==c||i!==l)&&(tL(r,i,c,l,e,n,a,o,s).forEach((function(e){t.push({key:`C`,data:e})})),r=c,i=l);break}case`Z`:t.push({key:`Z`,data:[]}),r=a,i=o}n=l}return t}function eL(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function tL(e,t,n,r,i,a,o,s,c,l){let u=(d=o,Math.PI*d/180);var d;let f=[],p=0,m=0,h=0,g=0;if(l)[p,m,h,g]=l;else{[e,t]=eL(e,t,-u),[n,r]=eL(n,r,-u);let o=(e-n)/2,l=(t-r)/2,d=o*o/(i*i)+l*l/(a*a);d>1&&(d=Math.sqrt(d),i*=d,a*=d);let f=i*i,_=a*a,v=f*_-f*l*l-_*o*o,y=f*l*l+_*o*o,b=(s===c?-1:1)*Math.sqrt(Math.abs(v/y));h=b*i*l/a+(e+n)/2,g=b*-a*o/i+(t+r)/2,p=Math.asin(parseFloat(((t-g)/a).toFixed(9))),m=Math.asin(parseFloat(((r-g)/a).toFixed(9))),em&&(p-=2*Math.PI),!c&&m>p&&(m-=2*Math.PI)}let _=m-p;if(Math.abs(_)>120*Math.PI/180){let e=m,t=n,s=r;m=c&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,f=tL(n=h+i*Math.cos(m),r=g+a*Math.sin(m),t,s,i,a,o,0,c,[m,e,h,g])}_=m-p;let v=Math.cos(p),y=Math.sin(p),b=Math.cos(m),x=Math.sin(m),S=Math.tan(_/4),C=4/3*i*S,ee=4/3*a*S,te=[e,t],ne=[e+C*y,t-ee*v],re=[n+C*x,r-ee*b],ie=[n,r];if(ne[0]=2*te[0]-ne[0],ne[1]=2*te[1]-ne[1],l)return[ne,re,ie].concat(f);{f=[ne,re,ie].concat(f);let e=[];for(let t=0;t2){let i=[];for(let t=0;t2*Math.PI&&(p=0,m=2*Math.PI);let h=2*Math.PI/c.curveStepCount,g=Math.min(h/2,(m-p)/2),_=bL(g,l,u,d,f,p,m,1,c);if(!c.disableMultiStroke){let e=bL(g,l,u,d,f,p,m,1.5,c);_.push(...e)}return o&&(s?_.push(...hL(l,u,l+d*Math.cos(p),u+f*Math.sin(p),c),...hL(l,u,l+d*Math.cos(m),u+f*Math.sin(m),c)):_.push({op:`lineTo`,data:[l,u]},{op:`lineTo`,data:[l+d*Math.cos(p),u+f*Math.sin(p)]})),{type:`path`,ops:_}}function uL(e,t){let n=$I(QI(ZI(e))),r=[],i=[0,0],a=[0,0];for(let{key:e,data:o}of n)switch(e){case`M`:a=[o[0],o[1]],i=[o[0],o[1]];break;case`L`:r.push(...hL(a[0],a[1],o[0],o[1],t)),a=[o[0],o[1]];break;case`C`:{let[e,n,i,s,c,l]=o;r.push(...xL(e,n,i,s,c,l,a,t)),a=[c,l];break}case`Z`:r.push(...hL(a[0],a[1],i[0],i[1],t)),a=[i[0],i[1]]}return{type:`path`,ops:r}}function dL(e,t){let n=[];for(let r of e)if(r.length){let e=t.maxRandomnessOffset||0,i=r.length;if(i>2){n.push({op:`move`,data:[r[0][0]+F(e,t),r[0][1]+F(e,t)]});for(let a=1;a500?.4:-.0016668*c+1.233334;let u=i.maxRandomnessOffset||0;u*u*100>s&&(u=c/10);let d=u/2,f=.2+.2*pL(i),p=i.bowing*i.maxRandomnessOffset*(r-t)/200,m=i.bowing*i.maxRandomnessOffset*(e-n)/200;p=F(p,i,l),m=F(m,i,l);let h=[],g=()=>F(d,i,l),_=()=>F(u,i,l),v=i.preserveVertices;return a&&(o?h.push({op:`move`,data:[e+(v?0:g()),t+(v?0:g())]}):h.push({op:`move`,data:[e+(v?0:F(u,i,l)),t+(v?0:F(u,i,l))]})),o?h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+g(),m+t+(r-t)*f+g(),p+e+2*(n-e)*f+g(),m+t+2*(r-t)*f+g(),n+(v?0:g()),r+(v?0:g())]}):h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+_(),m+t+(r-t)*f+_(),p+e+2*(n-e)*f+_(),m+t+2*(r-t)*f+_(),n+(v?0:_()),r+(v?0:_())]}),h}function _L(e,t,n){let r=[];r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]),r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]);for(let i=1;i3){let a=[],o=1-n.curveTightness;i.push({op:`move`,data:[e[1][0],e[1][1]]});for(let t=1;t+21&&i.push(n)):i.push(n),i.push(e[t+3])}else{let r=.5,a=e[t+0],o=e[t+1],s=e[t+2],c=e[t+3],l=TL(a,o,r),u=TL(o,s,r),d=TL(s,c,r),f=TL(l,u,r),p=TL(u,d,r),m=TL(f,p,r);EL([a,l,f,m],0,n,i),EL([m,p,d,c],0,n,i)}var a,o;return i}function DL(e,t){return OL(e,0,e.length,t)}function OL(e,t,n,r,i){let a=i||[],o=e[t],s=e[n-1],c=0,l=1;for(let r=t+1;rc&&(c=t,l=r)}return Math.sqrt(c)>r?(OL(e,t,l+1,r,a),OL(e,l,n,r,a)):(a.length||a.push(o),a.push(s)),a}function kL(e,t=.15,n){let r=[],i=(e.length-1)/3;for(let n=0;n0?OL(r,0,r.length,n):r}var AL=`none`,jL=class{constructor(e){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:`#000`,strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:`hachure`,fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=e||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions}_d(e,t,n){return{shape:e,sets:t||[],options:n||this.defaultOptions}}line(e,t,n,r,i){let a=this._o(i);return this._d(`line`,[rL(e,t,n,r,a)],a)}rectangle(e,t,n,r,i){let a=this._o(i),o=[],s=aL(e,t,n,r,a);if(a.fill){let i=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]];a.fillStyle===`solid`?o.push(dL([i],a)):o.push(fL([i],a))}return a.stroke!==AL&&o.push(s),this._d(`rectangle`,o,a)}ellipse(e,t,n,r,i){let a=this._o(i),o=[],s=sL(n,r,a),c=cL(e,t,a,s);if(a.fill){if(a.fillStyle===`solid`){let n=cL(e,t,a,s).opset;n.type=`fillPath`,o.push(n)}else o.push(fL([c.estimatedPoints],a))}return a.stroke!==AL&&o.push(c.opset),this._d(`ellipse`,o,a)}circle(e,t,n,r){let i=this.ellipse(e,t,n,n,r);return i.shape=`circle`,i}linearPath(e,t){let n=this._o(t);return this._d(`linearPath`,[iL(e,!1,n)],n)}arc(e,t,n,r,i,a,o=!1,s){let c=this._o(s),l=[],u=lL(e,t,n,r,i,a,o,!0,c);if(o&&c.fill){if(c.fillStyle===`solid`){let o=Object.assign({},c);o.disableMultiStroke=!0;let s=lL(e,t,n,r,i,a,!0,!1,o);s.type=`fillPath`,l.push(s)}else l.push(function(e,t,n,r,i,a,o){let s=e,c=t,l=Math.abs(n/2),u=Math.abs(r/2);l+=F(.01*l,o),u+=F(.01*u,o);let d=i,f=a;for(;d<0;)d+=2*Math.PI,f+=2*Math.PI;f-d>2*Math.PI&&(d=0,f=2*Math.PI);let p=(f-d)/o.curveStepCount,m=[];for(let e=d;e<=f;e+=p)m.push([s+l*Math.cos(e),c+u*Math.sin(e)]);return m.push([s+l*Math.cos(f),c+u*Math.sin(f)]),m.push([s,c]),fL([m],o)}(e,t,n,r,i,a,c))}return c.stroke!==AL&&l.push(u),this._d(`arc`,l,c)}curve(e,t){let n=this._o(t),r=[],i=oL(e,n);if(n.fill&&n.fill!==AL&&e.length>=3){if(n.fillStyle===`solid`){let t=oL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else{let t=kL(function(e,t=0){let n=e.length;if(n<3)throw Error(`A curve must have at least three points.`);let r=[];if(n===3)r.push(SL(e[0]),SL(e[1]),SL(e[2]),SL(e[2]));else{let n=[];n.push(e[0],e[0]);for(let t=1;t{s.length>=4&&a.push(...kL(s,t)),s=[]},l=()=>{c(),a.length&&(i.push(a),a=[])};for(let{key:e,data:t}of r)switch(e){case`M`:l(),o=[t[0],t[1]],a.push(o);break;case`L`:c(),a.push([t[0],t[1]]);break;case`C`:if(!s.length){let e=a.length?a[a.length-1]:o;s.push([e[0],e[1]])}s.push([t[0],t[1]]),s.push([t[2],t[3]]),s.push([t[4],t[5]]);break;case`Z`:c(),a.push([o[0],o[1]])}if(l(),!n)return i;let u=[];for(let e of i){let t=DL(e,n);t.length&&u.push(t)}return u}(e,1,o?4-4*(n.simplification||1):(1+n.roughness)/2),c=uL(e,n);if(i){if(n.fillStyle===`solid`){if(s.length===1){let t=uL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else r.push(dL(s,n))}else r.push(fL(s,n))}return a&&(o?s.forEach((e=>{r.push(iL(e,!1,n))})):r.push(c)),this._d(`path`,r,n)}opsToPath(e,t){let n=``;for(let r of e.ops){let e=typeof t==`number`&&t>=0?r.data.map((e=>+e.toFixed(t))):r.data;switch(r.op){case`move`:n+=`M${e[0]} ${e[1]} `;break;case`bcurveTo`:n+=`C${e[0]} ${e[1]}, ${e[2]} ${e[3]}, ${e[4]} ${e[5]} `;break;case`lineTo`:n+=`L${e[0]} ${e[1]} `}}return n.trim()}toPaths(e){let t=e.sets||[],n=e.options||this.defaultOptions,r=[];for(let e of t){let t=null;switch(e.type){case`path`:t={d:this.opsToPath(e),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:AL};break;case`fillPath`:t={d:this.opsToPath(e),stroke:AL,strokeWidth:0,fill:n.fill||AL};break;case`fillSketch`:t=this.fillSketch(e,n)}t&&r.push(t)}return r}fillSketch(e,t){let n=t.fillWeight;return n<0&&(n=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||AL,strokeWidth:n,fill:AL}}_mergedShape(e){return e.filter(((e,t)=>t===0||e.op!==`move`))}},ML=class{constructor(e,t){this.canvas=e,this.ctx=this.canvas.getContext(`2d`),this.gen=new jL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.ctx,i=e.options.fixedDecimalPlaceDigits;for(let a of t)switch(a.type){case`path`:r.save(),r.strokeStyle=n.stroke===`none`?`transparent`:n.stroke,r.lineWidth=n.strokeWidth,n.strokeLineDash&&r.setLineDash(n.strokeLineDash),n.strokeLineDashOffset&&(r.lineDashOffset=n.strokeLineDashOffset),this._drawToContext(r,a,i),r.restore();break;case`fillPath`:{r.save(),r.fillStyle=n.fill||``;let t=e.shape===`curve`||e.shape===`polygon`||e.shape===`path`?`evenodd`:`nonzero`;this._drawToContext(r,a,i,t),r.restore();break}case`fillSketch`:this.fillSketch(r,a,n)}}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2),e.save(),n.fillLineDash&&e.setLineDash(n.fillLineDash),n.fillLineDashOffset&&(e.lineDashOffset=n.fillLineDashOffset),e.strokeStyle=n.fill||``,e.lineWidth=r,this._drawToContext(e,t,n.fixedDecimalPlaceDigits),e.restore()}_drawToContext(e,t,n,r=`nonzero`){e.beginPath();for(let r of t.ops){let t=typeof n==`number`&&n>=0?r.data.map((e=>+e.toFixed(n))):r.data;switch(r.op){case`move`:e.moveTo(t[0],t[1]);break;case`bcurveTo`:e.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5]);break;case`lineTo`:e.lineTo(t[0],t[1])}}t.type===`fillPath`?e.fill(r):e.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a),a}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a),a}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a),a}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i),i}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n),n}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n),n}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c),c}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n),n}path(e,t){let n=this.gen.path(e,t);return this.draw(n),n}},NL=`http://www.w3.org/2000/svg`,PL=class{constructor(e,t){this.svg=e,this.gen=new jL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,i=r.createElementNS(NL,`g`),a=e.options.fixedDecimalPlaceDigits;for(let o of t){let t=null;switch(o.type){case`path`:t=r.createElementNS(NL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,n.stroke),t.setAttribute(`stroke-width`,n.strokeWidth+``),t.setAttribute(`fill`,`none`),n.strokeLineDash&&t.setAttribute(`stroke-dasharray`,n.strokeLineDash.join(` `).trim()),n.strokeLineDashOffset&&t.setAttribute(`stroke-dashoffset`,`${n.strokeLineDashOffset}`);break;case`fillPath`:t=r.createElementNS(NL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,`none`),t.setAttribute(`stroke-width`,`0`),t.setAttribute(`fill`,n.fill||``),e.shape!==`curve`&&e.shape!==`polygon`||t.setAttribute(`fill-rule`,`evenodd`);break;case`fillSketch`:t=this.fillSketch(r,o,n)}t&&i.appendChild(t)}return i}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let i=e.createElementNS(NL,`path`);return i.setAttribute(`d`,this.opsToPath(t,n.fixedDecimalPlaceDigits)),i.setAttribute(`stroke`,n.fill||``),i.setAttribute(`stroke-width`,r+``),i.setAttribute(`fill`,`none`),n.fillLineDash&&i.setAttribute(`stroke-dasharray`,n.fillLineDash.join(` `).trim()),n.fillLineDashOffset&&i.setAttribute(`stroke-dashoffset`,`${n.fillLineDashOffset}`),i}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(e,t){return this.gen.opsToPath(e,t)}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a)}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a)}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a)}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i)}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n)}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n)}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c)}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n)}path(e,t){let n=this.gen.path(e,t);return this.draw(n)}},FL={canvas:(e,t)=>new ML(e,t),svg:(e,t)=>new PL(e,t),generator:e=>new jL(e),newSeed:()=>jL.newSeed()},IL=(e,t)=>e===`none`?`none`:e===`ink`?t===`fill`?`var(--dw-surface-sunken)`:`var(--dw-ink)`:e===`paper`?t===`fill`?`var(--dw-surface-raised)`:`var(--dw-surface)`:t===`fill`?`color-mix(in srgb, var(--dw-c-${e}) 22%, var(--dw-surface))`:`var(--dw-c-${e})`,LL=e=>e.replace(/&/g,`&`).replace(//g,`>`).replace(/"/g,`"`),RL=e=>Math.round(e*100)/100,zL=`#000001`,BL=`#000002`;function VL(e,t){return e===`dash`?`stroke-dasharray:${RL(t*4)} ${RL(t*3)};`:``}function HL(e){let t=2166136261;for(let n of e)t=Math.imul(t^n.charCodeAt(0),16777619);return(t>>>0)%2**31||1}function UL(e,t,n){switch(e){case`diamond`:return[[t/2,0],[t,n/2],[t/2,n],[0,n/2]];case`triangle`:return[[t/2,0],[t,n],[0,n]];case`rect`:return[[0,0],[t,0],[t,n],[0,n]];default:return null}}function WL(e,t){let n=Math.min(16,e*.15,t*.15);return`M${RL(n)} 0 H${RL(e-n)} Q${RL(e)} 0 ${RL(e)} ${RL(n)} V${RL(t-n)} Q${RL(e)} ${RL(t)} ${RL(e-n)} ${RL(t)} H${RL(n)} Q0 ${RL(t)} 0 ${RL(t-n)} V${RL(n)} Q0 0 ${RL(n)} 0 Z`}function GL(e,t){let{w:n,h:r}=e,i=e.strokeStyle===`none`?`none`:t(e.stroke,`line`),a=t(e.fill,`fill`),o=e.strokeStyle===`none`?0:e.strokeWidth;if(e.rough){let t=FL.generator(),s={seed:HL(e.id),roughness:1.2,bowing:1,strokeWidth:Math.max(o,1),stroke:i===`none`?`none`:zL,fill:a===`none`?void 0:BL,fillStyle:`hachure`,hachureGap:8,fillWeight:1.4,disableMultiStroke:o===0},c=UL(e.shape,n,r),l=e.shape===`ellipse`?t.ellipse(n/2,r/2,n,r,s):e.shape===`roundrect`?t.path(WL(n,r),s):t.polygon(c,s);return t.toPaths(l).map(t=>{if(t.fill===BL)return``;let n=t.stroke===BL,r=n?a.replace(`22%`,`60%`):i;return r===`none`||t.stroke===`none`?``:``}).join(``)}let s=`fill:${a};stroke:${i};stroke-width:${RL(o)};stroke-linejoin:round;${VL(e.strokeStyle,o)}`;return e.shape===`ellipse`?``:e.shape===`roundrect`?``:``}function KL(e,t,n,r,i){if(e===`none`)return``;let a=6+r*2.5,o=(e,r)=>{let i=Math.cos(n),a=Math.sin(n);return`${RL(t[0]+e*i-r*a)},${RL(t[1]+e*a+r*i)}`};switch(e){case`arrow`:return``;case`triangle`:return``;case`circle`:{let[e,t]=o(-a*.45,0).split(`,`).map(Number);return``}case`diamond`:return``}}function qL(e,t,n){let r=e.strokeStyle===`none`?n(`gray`,`line`):n(e.stroke,`line`),i=e.strokeWidth,a;if(e.rough){let n=FL.generator();a=n.toPaths(n.path(t.d,{seed:HL(e.id),roughness:1,strokeWidth:i,stroke:`#000`})).map(e=>``).join(``)}else a=``;let o=t.points[t.points.length-1];return a+KL(e.startArrow,t.points[0],t.startAngle,i,r)+KL(e.endArrow,o,t.endAngle,i,r)}function JL(e,t){let n=MI(e,{size:t,thinning:.55,smoothing:.5,streamline:.4,simulatePressure:e.every(e=>e[2]===.5),last:!0});if(!n.length)return``;let r=(e,t)=>(e+t)/2,i=`M${RL(n[0][0])} ${RL(n[0][1])} Q`;for(let e=0;e`}function XL(e){let t=[];for(let n of e.toArray())if(n instanceof mx)for(let e of n.toDelta()){if(typeof e.insert!=`string`)continue;let n={type:`text`,text:e.insert};e.attributes&&(n.marks=Object.entries(e.attributes).map(([e,t])=>({type:e,attrs:t&&typeof t==`object`?t:{}}))),t.push(n)}else if(n instanceof lx){let e={type:n.nodeName},r=n.getAttributes();Object.keys(r).length&&(e.attrs=r),n.length&&(e.content=XL(n)),t.push(e)}return t}function ZL(e,t,n=0){if(n>100)return;let r=0;for(;r{let r=``,i=!1;for(let a of e)a.type===`text`?(r+=a.text??``,i=!0):a.type===`hardBreak`?(t.push(r),r=``):a.content?.length&&a.content.some(e=>e.type!==`text`&&e.type!==`hardBreak`)?(i&&t.push(r),r=``,i=!1,n(a.content)):(i&&t.push(r),t.push((a.content??[]).map(e=>e.text??``).join(``)),r=``,i=!1);i&&t.push(r)};return n(e),t}var $L=`docwell-canvas`,eR=e=>e.getMap(`surface`);function tR(e){let t={};for(let[n,r]of e.entries())r instanceof Bb?t[n]=r.toJSON():r instanceof gb||(t[n]=r);return AF(t)}function nR(e,t){return(e.type===`frame`?0:1)-(t.type===`frame`?0:1)||e.index-t.index||(e.idt.id))}function rR(){return AF({id:SF,type:`note`,page:!0,background:`paper`,x:0,y:0,w:760,h:400,index:0})}var iR=class{doc;map;undo;cache=null;byId=new Map;listeners=new Set;observer=e=>{this.cache=null;let t=new Set;for(let n of e){if(n.target===this.map){t=null;break}let e=n.target;for(;e&&e.parent!==this.map;)e=e.parent;let r=e&&e._item?.parentSub;r&&t.add(r)}for(let e of this.listeners)e(t)};constructor(e,t={}){this.doc=e,this.map=eR(e),this.map.observeDeep(this.observer),this.undo=t.undo===!1?null:new Wy(this.map,{trackedOrigins:new Set([$L]),captureTimeout:400})}destroy(){this.map.unobserveDeep(this.observer),this.undo?.destroy(),this.listeners.clear()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}elements(){if(this.cache)return this.cache;let e=[];for(let[t,n]of this.map.entries()){let r=n instanceof Bb?tR(n):null;r&&e.push({...r,id:t})}return e.some(e=>e.type===`note`&&e.page)||e.push(rR()),e.sort(nR),this.cache=e,this.byId=new Map(e.map(e=>[e.id,e])),e}get(e){return this.elements(),this.byId.get(e)}get isEmpty(){return this.map.size===0}body(e){let t=this.map.get(e);if(!(t instanceof Bb))return null;let n=t.get(`body`);return n instanceof sx?n:null}nodes(e){let t=this.map.get(e)?.get(`nodes`);return t instanceof Bb?t:null}transact(e){this.doc.transact(e,$L)}nextIndex(){let e=0;for(let t of this.elements())t.type!==`frame`&&(e=Math.max(e,t.index));return e+1}ensure(e){let t=this.map.get(e);if(t instanceof Bb)return t;if(e!==`page`)return null;let n=this.get(e),r=new Bb;this.map.set(e,r);for(let[e,t]of Object.entries(n))e!==`id`&&r.set(e,t);return r}add(e,t){let n=e.id||FF();return this.transact(()=>{let r=new Bb;this.map.set(n,r);let{nodes:i,...a}=e;for(let[e,t]of Object.entries(a))e!==`id`&&t!==void 0&&r.set(e,t);if(`index`in a||r.set(`index`,e.type===`frame`?-this.nextIndex():this.nextIndex()),e.type===`note`&&!e.page){let e=new sx;r.set(`body`,e),ZL(e,t?.length?t:[{type:`paragraph`}])}if(e.type===`mindmap`){let e=new Bb;r.set(`nodes`,e);let t=i&&Object.keys(i).length?i:{[FF()]:{text:``,parent:``,pos:0}};for(let[n,r]of Object.entries(t))e.set(n,aR(r))}}),n}update(e,t){this.updateMany([[e,t]])}updateMany(e){e.length&&this.transact(()=>{for(let[t,n]of e){let e=this.ensure(t);if(e)for(let[t,r]of Object.entries(n))t!==`id`&&t!==`type`&&t!==`body`&&t!==`nodes`&&(r===void 0?e.delete(t):oR(e.get(t),r)||e.set(t,r))}})}remove(e){let t=this.elements(),n=new Set;for(let r of e){n.add(r);for(let e of t)e.group===r&&n.add(e.id)}n.delete(SF);for(let e of t)e.type===`note`&&e.page&&n.delete(e.id);n.size&&this.transact(()=>{for(let e of t)if(!(e.type!==`connector`||n.has(e.id)))for(let t of[`source`,`target`]){let r=e[t];if(r.id&&n.has(r.id)){let n=this.endPoint(r);this.map.get(e.id)?.set(t,{x:n[0],y:n[1]})}}for(let e of n)this.map.delete(e);let e=this.elements();for(let t of e.filter(e=>e.type===`group`)){let n=e.filter(e=>e.group===t.id);if(n.length<2){for(let e of n)this.map.get(e.id)?.delete(`group`);this.map.delete(t.id)}}})}endPoint(e){let t=e.id?this.get(e.id):void 0;if(!t)return[e.x??0,e.y??0];let[n,r]=e.pos??[.5,.5];return[t.x+t.w*n,t.y+t.h*r]}reorder(e,t){let n=this.elements().filter(e=>e.type!==`frame`),r=new Set(e),i=n.filter(e=>r.has(e.id));if(!i.length)return;let a=n.filter(e=>!r.has(e.id)),o;if(t===`front`)o=[...a,...i];else if(t===`back`)o=[...i,...a];else{o=[...n];let e=t===`forward`?1:-1,a=e=>o.indexOf(e),s=e===1?[...i].reverse():i;for(let t of s){let n=a(t),i=n+e;i<0||i>=o.length||r.has(o[i].id)||([o[n],o[i]]=[o[i],o[n]])}}this.updateMany(o.map((e,t)=>[e.id,{index:t+1}]).filter(([e,t])=>this.get(e)?.index!==t.index))}groupOf(e){let t=e.filter(e=>{let t=this.get(e);return t&&t.type!==`group`&&!(t.type===`note`&&t.page)});if(t.length<2)return null;let n=FF();return this.transact(()=>{let e=new Bb;this.map.set(n,e),e.set(`type`,`group`),e.set(`index`,this.nextIndex());for(let e of t)this.ensure(e)?.set(`group`,n)}),n}ungroup(e){let t=this.elements().filter(t=>t.group===e).map(e=>e.id);return this.transact(()=>{for(let e of t)this.map.get(e)?.delete(`group`);this.map.delete(e)}),t}addNode(e,t,n,r=``){let i=FF();return this.transact(()=>this.nodes(e)?.set(i,aR({text:r,parent:t,pos:n}))),i}updateNode(e,t,n){this.transact(()=>{let r=this.nodes(e)?.get(t);if(r)for(let[e,t]of Object.entries(n))r.get(e)!==t&&r.set(e,t)})}removeNode(e,t){let n=this.get(e);if(n?.type!==`mindmap`)return;if(t===Object.entries(n.nodes).find(([,e])=>!e.parent)?.[0]){this.remove([e]);return}let r=new Set([t]),i=!0;for(;i;){i=!1;for(let[e,t]of Object.entries(n.nodes))!r.has(e)&&r.has(t.parent)&&(r.add(e),i=!0)}this.transact(()=>{let t=this.nodes(e);for(let e of r)t?.delete(e)})}toJSON(e){let t=this.elements(),n;if(e){n=new Set(e);for(let e of t)n.has(e.group)&&n.add(e.id)}else n=new Set(t.map(e=>e.id));return t.filter(e=>n.has(e.id)).map(e=>{let t={...e,id:e.id,type:e.type},n=e.type===`note`&&!e.page?this.body(e.id):null;return n&&(t.body=XL(n)),t})}insertJSON(e,t=0,n=0){let r=e.filter(e=>e&&typeof e==`object`&&!(e.type===`note`&&e.page)),i=new Map(r.map(e=>[String(e.id),FF()])),a=[],o=this.nextIndex();return this.transact(()=>{for(let e of r){let r=AF(e);if(!r)continue;let s=i.get(String(e.id)),c={...r};if(delete c.id,c.x=r.x+t,c.y=r.y+n,c.index=r.type===`frame`?-o++:o++,c.group=r.group&&i.has(r.group)?i.get(r.group):void 0,r.type===`connector`)for(let e of[`source`,`target`]){let a=r[e];if(a.id&&i.has(a.id))c[e]={id:i.get(a.id),...a.pos?{pos:a.pos}:{}};else if(a.id){let r=this.endPoint(a);c[e]={x:r[0]+t,y:r[1]+n}}else c[e]={x:(a.x??0)+t,y:(a.y??0)+n}}for(let e of Object.keys(c))(c[e]===void 0||c[e]===``)&&delete c[e];this.add({...c,id:s,type:r.type},Array.isArray(e.body)?e.body:void 0),a.push(s)}}),a}load(e){this.transact(()=>{for(let e of[...this.map.keys()])this.map.delete(e);for(let t of e){let e=AF(t);if(!e||!t.id)continue;let n={...e},r=String(t.id);delete n.id;for(let e of Object.keys(n))n[e]===``&&delete n[e];this.add({...n,id:r,type:e.type},Array.isArray(t.body)?t.body:void 0)}})}};function aR(e){let t=new Bb;return t.set(`text`,e.text),t.set(`parent`,e.parent),t.set(`pos`,e.pos),t}function oR(e,t){return e===t?!0:typeof e!=`object`||typeof t!=`object`||!e||!t?!1:JSON.stringify(e)===JSON.stringify(t)}var sR=(e,t=18)=>``,cR={rect:``,roundrect:``,ellipse:``,diamond:``,triangle:``,straight:``,curve:``,elbow:``,none:``,arrow:``,triangleEnd:``,circle:``,diamondEnd:``,solid:``,dash:``,noLine:``,right:``,left:``,radial:``},lR=e=>``;function uR(e){return e===`none`?`background:transparent`:e===`ink`?`background:var(--dw-ink)`:e===`paper`?`background:var(--dw-surface)`:`background:var(--dw-c-${e})`}var dR=class{v;bar;zoomBox;props;zoomLabel;pop=null;popFor=``;fileInput;lastProps=``;closePop=e=>{this.pop&&!this.pop.contains(e.target)&&!e.target.closest?.(`[data-pop]`)&&this.hidePop()};constructor(e){this.v=e;let t=e.root;this.bar=this.div(`dw-cv-ui dw-cv-toolbar`),this.bar.setAttribute(`role`,`toolbar`),this.bar.setAttribute(`aria-label`,e.labels.toolbar),this.zoomBox=this.div(`dw-cv-ui dw-cv-zoom`),this.props=this.div(`dw-cv-ui dw-cv-props`),this.props.setAttribute(`role`,`toolbar`),this.zoomLabel=document.createElement(`button`),this.fileInput=document.createElement(`input`),this.fileInput.type=`file`,this.fileInput.accept=`image/*`,this.fileInput.multiple=!0,this.fileInput.hidden=!0,this.fileInput.addEventListener(`change`,()=>{let t=[...this.fileInput.files??[]];this.fileInput.value=``,t.length&&e.addImages(t)}),t.append(this.bar,this.zoomBox,this.props,this.fileInput),document.addEventListener(`pointerdown`,this.closePop,!0),this.buildZoom(),this.refresh()}destroy(){document.removeEventListener(`pointerdown`,this.closePop,!0)}div(e){let t=document.createElement(`div`);return t.className=e,t}button(e,t,n,r={}){let i=document.createElement(`button`);return i.type=`button`,i.className=`dw-cv-btn${r.cls?` ${r.cls}`:``}`,i.innerHTML=e,i.title=t,i.setAttribute(`aria-label`,t),r.active!==void 0&&i.setAttribute(`aria-pressed`,String(r.active)),r.pop&&(i.dataset.pop=r.pop),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),i.addEventListener(`click`,e=>{e.stopPropagation(),n()}),i}buildBar(){let e=this.v,t=e.labels;if(this.bar.replaceChildren(),this.bar.hidden=e.isPresenting,!e.editable){this.bar.append(this.button(sR(`cursor`),t.select,()=>e.setTool(`select`),{active:e.tool===`select`}),this.button(sR(`hand`),t.hand,()=>e.setTool(`hand`),{active:e.tool===`hand`}),this.sep(),this.button(sR(`present`),t.present,()=>e.present()));return}let n=(t,n,r)=>this.button(sR(n),r,()=>e.setTool(t),{active:e.tool===t}),r=this.button(lR(e.shapeKind),t.shape,()=>{e.setTool(`shape`),this.togglePop(`shape`,r,()=>this.shapePop())},{active:e.tool===`shape`,pop:`shape`}),i=this.button(sR(`pen`),t.pen,()=>{e.setTool(`pen`),this.togglePop(`pen`,i,()=>this.penPop())},{active:e.tool===`pen`,pop:`pen`}),a=this.button(sR(`connector`),t.connector,()=>{e.setTool(`connector`),this.togglePop(`connector`,a,()=>this.connectorPop())},{active:e.tool===`connector`,pop:`connector`}),o=this.button(sR(`sticker`),t.library,()=>this.togglePop(`library`,o,()=>this.libraryPop()),{pop:`library`});this.bar.append(n(`select`,`cursor`,t.select),n(`hand`,`hand`,t.hand),this.sep(),n(`note`,`note`,t.note),n(`text`,`type`,t.text),r,a,i,n(`eraser`,`eraser`,t.eraser),n(`frame`,`frame`,t.frame),n(`mindmap`,`mindmap`,t.mindmap),this.button(sR(`image`),t.image,()=>this.pickImage()),this.button(sR(`link`),t.link,()=>void e.addLink()),o,this.sep(),this.button(sR(`present`),t.present,()=>e.present()))}sep(){return this.div(`dw-cv-sep`)}pickImage(){this.v.editable&&this.v.opts.files?.upload&&this.fileInput.click()}togglePop(e,t,n){if(this.pop&&this.popFor===e)return this.hidePop();this.hidePop();let r=n();r.classList.add(`dw-cv-ui`,`dw-cv-pop`),r.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.v.root.append(r),this.pop=r,this.popFor=e;let i=this.v.root.getBoundingClientRect(),a=t.getBoundingClientRect(),o=r.offsetWidth,s=r.offsetHeight,c=a.left-i.left+a.width/2-o/2;c=Math.max(8,Math.min(i.width-o-8,c));let l=a.top-i.top-s-8;l<8&&(l=a.bottom-i.top+8),r.style.left=`${c}px`,r.style.top=`${l}px`}hidePop(){this.pop?.remove(),this.pop=null,this.popFor=``}row(...e){let t=this.div(`dw-cv-row`);return t.append(...e),t}colorRow(e,t,n,r){let i=this.div(`dw-cv-row dw-cv-colors`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,r);let a=this.v.labels,o=[`ink`,...hF,...n?[`paper`,`none`]:[]];for(let n of o){let r=n===`ink`?a.colorInk:n===`paper`?a.colorPaper:n===`none`?a.colorNone:a.colors[n]??n,o=this.button(``,r,()=>{t(n),this.lastProps=``,this.refresh()},{active:n===e});i.append(o)}return i}shapePop(){let e=this.v,t=e.labels,n=this.div(``);return n.append(this.row(...vF.map(n=>this.button(lR(n),t[n],()=>{e.setShapeKind(n),this.hidePop()},{active:e.shapeKind===n}))),this.row(this.button(`${t.general}`,t.general,()=>{e.setStyle(`shape`,{rough:!1}),this.hidePop()},{active:!e.styles.shape.rough}),this.button(`${t.scribbled}`,t.scribbled,()=>{e.setStyle(`shape`,{rough:!0}),this.hidePop()},{active:e.styles.shape.rough}))),n}penPop(){let e=this.v,t=this.div(``);return t.append(this.colorRow(e.styles.brush.color,t=>e.setStyle(`brush`,{color:t}),!1,e.labels.stroke),this.row(...[2,4,8,14].map(t=>this.button(``,`${e.labels.thickness} ${t}`,()=>{e.setStyle(`brush`,{size:t}),this.hidePop()},{active:e.styles.brush.size===t})))),t}connectorPop(){let e=this.v,t=this.div(``);return t.append(this.row(...yF.map(t=>this.button(lR(t),e.labels[t],()=>{e.setStyle(`connector`,{mode:t}),this.hidePop()},{active:e.styles.connector.mode===t})))),t}libraryPop(){let e=this.v,t=e.labels,n=this.div(`dw-cv-library`),r=this.div(`dw-cv-poptitle`);r.textContent=t.stickers;let i=this.div(`dw-cv-stickers`);for(let t of RF)i.append(this.button(`${t}`,t,()=>{e.insertSticker(t),this.hidePop()}));let a=this.div(`dw-cv-poptitle`);a.textContent=t.templates;let o=this.div(`dw-cv-templates`),s={kanban:t.templateKanban,swot:t.templateSwot,flow:t.templateFlow,brainstorm:t.templateBrainstorm,retro:t.templateRetro};for(let t of BF){let n=this.button(`${s[t]}`,s[t],()=>{e.insertTemplate(t),this.hidePop()},{cls:`dw-cv-wide`});o.append(n)}return n.append(r,i,a,o),n}buildZoom(){let e=this.v,t=e.labels;this.zoomLabel.type=`button`,this.zoomLabel.className=`dw-cv-btn dw-cv-zoomlabel`,this.zoomLabel.title=t.zoomReset,this.zoomLabel.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.zoomLabel.addEventListener(`click`,()=>e.zoomAt(1)),this.zoomBox.append(this.button(sR(`zoom-out`),t.zoomOut,()=>e.zoomBy(.8)),this.zoomLabel,this.button(sR(`zoom-in`),t.zoomIn,()=>e.zoomBy(1.25)),this.button(sR(`fit`),t.zoomFit,()=>e.fit()))}zoomChanged(){this.zoomLabel.textContent=`${Math.round(this.v.zoom*100)}%`}refresh(){this.buildBar();let e=(this.v.editable||this.v.opts.onComment)&&!this.v.editing&&!this.v.isPresenting?this.v.selection():[],t=JSON.stringify([e,this.v.activeNode,this.v.styles.shape.rough]);t!==this.lastProps&&(this.lastProps=t,this.buildProps(e)),this.place()}place(){let e=this.props;if(e.hidden)return;let t=this.v.selectionScreenBox();if(!t){e.hidden=!0;return}let n=this.v.root.getBoundingClientRect(),r=e.offsetWidth,i=e.offsetHeight,a=t.x+t.w/2-r/2;a=Math.max(8,Math.min(n.width-r-8,a));let o=t.y-i-40;o<8&&(o=Math.min(n.height-i-64,t.y+t.h+16)),e.style.left=`${a}px`,e.style.top=`${Math.max(8,o)}px`}buildProps(e){let t=this.props;if(t.replaceChildren(),!e.length){t.hidden=!0;return}t.hidden=!1;let n=this.v,r=n.labels,i=n.opts.onComment,a=()=>this.button(sR(`comment`),r.comment,()=>{let t=e[0].id;i?.({id:t,text:n.elementText(t).slice(0,500)})});if(!n.editable){i&&e.length===1?t.append(a()):t.hidden=!0;return}let o=new Set(e.map(e=>e.type)).size===1?e[0]:null,s=[],c=(e,t,n,r)=>{let i=this.button(t,n,()=>this.togglePop(e,i,r),{pop:e});s.push(i)},l=(e,t,r,i,a)=>c(e,``,t,()=>{let e=this.div(``);return e.append(this.colorRow(r,e=>n.restyle({[i]:e}),a,t)),e}),u=(e,t,r,i,a,o,s,l=e=>e)=>c(e,a(r),t,()=>{let e=this.div(``);return e.append(this.row(...i.map(e=>this.button(a(e),s(e),()=>{n.restyle({[o]:l(e)}),this.hidePop(),this.lastProps=``,this.refresh()},{active:e===r})))),e}),d=(e,t,n,r)=>s.push(this.button(e,t,r,{active:n}));if(o?.type===`shape`)u(`kind`,r.shape,o.shape,vF,lR,`shape`,e=>r[e]),l(`fill`,r.fill,o.fill,`fill`,!0),l(`stroke`,r.stroke,o.stroke,`stroke`,!0),u(`style`,r.lineStyle,o.strokeStyle,[`solid`,`dash`,`none`],e=>lR(e===`none`?`noLine`:e),`strokeStyle`,e=>e===`none`?r.noLine:r[e]),u(`width`,r.thickness,String(o.strokeWidth),[`1`,`2`,`4`,`6`],e=>``,`strokeWidth`,e=>`${r.thickness} ${e}`,Number),d(`${r.scribbled}`,r.scribbled,o.rough,()=>{n.restyle({rough:!o.rough}),this.lastProps=``,this.refresh()}),l(`textColor`,r.textColor,o.textColor,`textColor`,!1);else if(o?.type===`connector`){u(`mode`,r.connector,o.mode,yF,lR,`mode`,e=>r[e]),l(`stroke`,r.stroke,o.stroke,`stroke`,!1),u(`style`,r.lineStyle,o.strokeStyle===`none`?`solid`:o.strokeStyle,[`solid`,`dash`],lR,`strokeStyle`,e=>r[e]);let e=e=>lR(e===`triangle`?`triangleEnd`:e===`diamond`?`diamondEnd`:e);u(`start`,r.startArrow,o.startArrow,bF,t=>`${e(t)}`,`startArrow`,e=>e),u(`end`,r.endArrow,o.endArrow,bF,e,`endArrow`,e=>e)}else o?.type===`brush`?l(`color`,r.stroke,o.color,`color`,!1):o?.type===`text`?(l(`color`,r.textColor,o.color,`color`,!1),u(`size`,r.fontSize,String(o.fontSize),[`16`,`24`,`32`,`48`,`64`],e=>`${e}`,`fontSize`,e=>`${r.fontSize} ${e}`,Number),u(`font`,r.font,o.font||`sans`,[`sans`,`serif`,`mono`],e=>`Aa`,`font`,e=>r[e],e=>e===`sans`?``:e),u(`align`,r.alignLeft,o.align,[`left`,`center`,`right`],e=>sR(`align-${e}`),`align`,e=>r[e===`left`?`alignLeft`:e===`center`?`alignCenter`:`alignRight`]),d(sR(`bold`),r.bold,o.bold,()=>{n.restyle({bold:!o.bold}),this.lastProps=``,this.refresh()})):o?.type===`note`||o?.type===`frame`?l(`bg`,r.background,o.background,`background`,!0):o?.type===`mindmap`?(u(`layout`,r.layout,o.layout,xF,e=>lR(e),`layout`,e=>r[e===`right`?`layoutRight`:e===`left`?`layoutLeft`:`layoutRadial`]),l(`color`,r.stroke,o.color,`color`,!1),n.activeNode?.map===o.id&&s.push(this.button(`+ ${r.addChild}`,r.addChild,()=>n.mindmapAdd(`child`),{cls:`dw-cv-wide`}))):o?.type===`embed`&&e.length===1&&s.push(this.button(sR(`open`),r.openLink,()=>window.open(o.url,`_blank`,`noopener,noreferrer`)));t.append(...s),i&&e.length===1&&t.append(a()),s.length&&t.append(this.sep());let f=e.filter(e=>e.type===`group`);e.length>1&&!f.length&&t.append(this.button(sR(`group`),r.group,()=>n.group())),f.length&&t.append(this.button(sR(`layers`),r.ungroup,()=>n.ungroup()));let p=e.every(e=>e.type===`note`&&e.page);t.append(this.button(sR(`arrow-up`),r.bringFront,()=>n.reorder(`front`)),this.button(sR(`send-back`),r.sendBack,()=>n.reorder(`back`))),p||t.append(this.button(sR(`copy`),r.duplicate,()=>n.duplicate()),this.button(sR(`trash`),r.delete,()=>n.deleteSelection(),{cls:`dw-cv-danger`}))}toast(e){let t=this.div(`dw-cv-ui dw-cv-toast`);t.setAttribute(`role`,`status`),t.textContent=e,this.v.root.append(t),setTimeout(()=>t.remove(),2600)}presentBar(){let e=this.v,t=e.labels,n=this.div(`dw-cv-ui dw-cv-presentbar`),r=this.div(`dw-cv-step`);return r.setAttribute(`aria-live`,`polite`),n.append(this.button(sR(`chevron-left`),t.presentPrevious,()=>e.presentStep(-1)),r,this.button(sR(`chevron-right`),t.presentNext,()=>e.presentStep(1)),this.button(sR(`close`),t.presentExit,()=>e.stopPresenting())),e.root.append(n),this.hidePop(),this.refresh(),n}presentStep(e,t){let n=this.v.root.querySelector(`.dw-cv-step`);n&&(n.textContent=this.v.labels.presentStep.replace(`{n}`,String(e+1)).replace(`{total}`,String(t)))}};function fR(e){let t=getComputedStyle(e),n=(e,n)=>t.getPropertyValue(e).trim()||n,r=n(`--dw-surface`,`#ffffff`),i=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return null;let n=t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))},a=(e,t,n)=>{let r=i(e),a=i(t);return!r||!a?e:`#${r.map((e,t)=>Math.round(e*n+a[t]*(1-n)).toString(16).padStart(2,`0`)).join(``)}`};return(e,t)=>{if(e===`none`)return`none`;if(e===`ink`)return t===`fill`?n(`--dw-surface-sunken`,`#f3f3f1`):n(`--dw-ink`,`#1d1f1e`);if(e===`paper`)return t===`fill`?n(`--dw-surface-raised`,`#ffffff`):r;let i=n(`--dw-c-${e}`,`#888888`);return t===`fill`?a(i,r,.22):i}}function pR(e){let t=[],n=e=>(e.content??[]).map(e=>e.type===`text`?e.text??``:e.type===`hardBreak`?` +`:n(e)).join(``),r=(e,i)=>{for(let a of e)if(a.type===`heading`){let e=Number(a.attrs?.level)||1;t.push({text:n(a),size:[0,26,21,18,16,16,16][e]??16,weight:650})}else if(a.type===`paragraph`)t.push({text:i+n(a),size:15,weight:400});else if(a.type===`listItem`||a.type===`taskItem`){let e=a.type===`taskItem`?a.attrs?.checked?`☑ `:`☐ `:`• `,[i,...o]=a.content??[];i&&t.push({text:e+n(i),size:15,weight:400}),r(o,` `)}else a.type===`codeBlock`?t.push({text:n(a),size:13,weight:400}):a.content?.length&&r(a.content,i)};return r(e,``),t}function mR(e,t,n,r,i,a,o=400,s=`start`){let c=Math.round(r*1.35);return n.map((n,l)=>`${LL(n)}`).join(``)}async function hR(e){if(e.startsWith(`data:`))return e;try{let t=await fetch(e,{credentials:`include`});if(!t.ok)return null;let n=await t.blob();return await new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:null),t.onerror=()=>e(null),t.readAsDataURL(n)})}catch{return null}}async function gR(e){let t=fR(e.root),n=e.elements.filter(e=>e.type!==`group`),r=GP(WP(n.map(t=>e.boxOf(t)))??{x:0,y:0,w:400,h:300},32),i=t(`ink`,`line`),a=[];for(let r of n){let n=e.boxOf(r),o=r.rotate?` rotate(${r.rotate} ${n.w/2} ${n.h/2})`:``,s=e=>`${e}`;switch(r.type){case`shape`:{let e=eI(r.text,r.fontSize,Math.max(20,n.w-16)),i=Math.round(r.fontSize*1.35),o=n.h/2-e.length*i/2-r.fontSize*.25;a.push(s(GL(r,t)+(r.text?mR(n.w/2,o,e,r.fontSize,t(r.textColor,`line`),YF,400,`middle`):``)));break}case`text`:{let e=QF(r.font),i=r.w?eI(r.text,r.fontSize,r.w,e):r.text.split(` +`),o=r.align===`center`?n.w/2:r.align===`right`?n.w:0,c=r.align===`center`?`middle`:r.align===`right`?`end`:`start`;a.push(s(mR(o,0,i,r.fontSize,t(r.color,`line`),e,r.bold?650:400,c)));break}case`connector`:{let n=e.routeOf(r);if(a.push(qL(r,n,t)),r.label){let e=Math.min(240,r.label.length*8+16);a.push(``+mR(n.mid[0],n.mid[1]-12+3,[r.label],13,i,YF,400,`middle`))}break}case`brush`:a.push(s(YL(r,t)));break;case`frame`:a.push(s(``+mR(4,-24,[r.title],13,t(`gray`,`line`),YF,600)));break;case`note`:{let o=e.noteBody(r),c=o?pR(XL(o)):[],l=18,u=``;if(r.page&&e.pageTitle){let t=eI(e.pageTitle,26,n.w-48,YF,650);u+=mR(24,l-4,t,26,i,YF,650),l+=t.length*35+8}for(let e of c){let t=eI(e.text,e.size,n.w-48,YF,e.weight);if(u+=mR(24,l,t,e.size,i,YF,e.weight),l+=t.length*Math.round(e.size*1.35)+8,l>n.h-12)break}a.push(s(u));break}case`image`:{let i=await hR(e.resolve(r.src));a.push(s(i?``:``));break}case`embed`:a.push(s(``+mR(16,16,eI(r.url,13,n.w-32),13,t(`blue`,`line`),YF)));break;case`mindmap`:{let n=e.layoutOf(r),o=t(r.color,`line`),s=t(r.color,`fill`),c=n.edges.map(e=>``).join(``);for(let e of n.boxes.values()){let n=e.depth===0?18:15,a=e.depth===0?600:400,l=e.depth===0?o:e.depth===1?s:t(`paper`,`line`),u=e.depth===0?t(`paper`,`line`):i;c+=``;let d=eI(r.nodes[e.id]?.text||` `,n,260,YF,a);c+=mR(e.x+e.w/2,e.y+(e.h-d.length*Math.round(n*1.4))/2-2,d,n,u,YF,a,`middle`)}a.push(`${c}`);break}}}return{svg:`${a.join(``)}`,box:r}}async function _R(e,t){let{svg:n,box:r}=await gR(t),i=new Blob([n],{type:`image/svg+xml`});if(e===`svg`)return i;let a=Math.min(2,8192/Math.max(r.w,r.h,1)),o=URL.createObjectURL(i);try{let e=await new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>t(Error(`could not draw the canvas`)),n.src=o}),t=document.createElement(`canvas`);t.width=Math.ceil(r.w*a),t.height=Math.ceil(r.h*a);let n=t.getContext(`2d`);if(!n)throw Error(`could not draw the canvas`);return n.drawImage(e,0,0,t.width,t.height),await new Promise((e,n)=>t.toBlob(t=>t?e(t):n(Error(`could not draw the canvas`)),`image/png`))}finally{URL.revokeObjectURL(o)}}var vR=.1,yR=4,bR=`http://www.w3.org/2000/svg`,xR=e=>e instanceof HTMLElement&&(e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`),SR=class{opts;store;labels;root;styles;editable;tool=`select`;shapeKind;selected=new Set;activeNode=null;editing=null;entered=null;world;overlay;ui;view={x:0,y:0,zoom:1};rendered=new Map;measured=new Map;layouts=new Map;routes=new Map;previews=new Map;drag=null;guides=[];marquee=null;hover=null;raf=0;spaceDown=!1;pointers=new Map;pinch=null;presenting=null;comments=[];activeComment=``;resize=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>this.onResize(e));unsub;cleanups=[];saveTimer;constructor(e,t){this.opts=t,this.labels=t.labels??mF,this.editable=t.editable,this.styles=LF(t.styles),this.shapeKind=this.styles.shape.shape,this.store=new iR(t.doc,{undo:t.undo!==!1}),this.root=document.createElement(`div`),this.root.className=`dw-cv`,this.root.tabIndex=0,this.root.setAttribute(`role`,`application`),this.root.dataset.testid=`edgeless-canvas`,this.world=document.createElement(`div`),this.world.className=`dw-cv-world`,this.overlay=document.createElementNS(bR,`svg`),this.overlay.classList.add(`dw-cv-overlay`),this.root.append(this.world,this.overlay),e.append(this.root),this.ui=new dR(this),this.root.classList.toggle(`dw-cv-readonly`,!this.editable),this.unsub=this.store.onChange(()=>this.schedule()),this.listen(),this.render(),this.restoreView()||this.fit(void 0,!1),this.applyView()}destroy(){cancelAnimationFrame(this.raf),clearTimeout(this.saveTimer),this.saveView(),this.unsub(),this.resize?.disconnect();for(let e of this.cleanups)e();for(let e of this.rendered.values())e.note?.destroy();this.rendered.clear(),this.ui.destroy(),this.store.destroy(),this.root.remove()}setEditable(e){if(e!==this.editable){this.editable=e,this.root.classList.toggle(`dw-cv-readonly`,!e),e||(this.stopEditing(),this.tool=`select`);for(let t of this.rendered.values())t.note?.setEditable(e);this.ui.refresh()}}get(e){return this.store.get(e)}elements(){return this.store.elements()}boxOf(e){switch(e.type){case`note`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:e.w,h:t?.h??e.h}}case`text`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:t?.w??e.w,h:t?.h??e.h}}case`group`:return WP(this.elements().filter(t=>t.group===e.id).map(e=>this.outerBox(e)))??{x:e.x,y:e.y,w:0,h:0};case`mindmap`:{let t=this.layoutOf(e);return{x:e.x+t.bounds.x,y:e.y+t.bounds.y,w:t.bounds.w,h:t.bounds.h}}case`connector`:{let t=this.routeOf(e),n=t.points.map(e=>e[0]),r=t.points.map(e=>e[1]);return JP([Math.min(...n),Math.min(...r)],[Math.max(...n),Math.max(...r)])}default:return{x:e.x,y:e.y,w:e.w,h:e.h}}}outerBox(e){let t=this.boxOf(e);return e.rotate?XP(t,e.rotate):t}layoutOf(e){let t=this.layouts.get(e.id),n=JSON.stringify([e.layout,e.nodes]);return t&&t.key===n||(t=oI(e.nodes,e.layout,tI),t.key=n,this.layouts.set(e.id,t)),t}routeOf(e){let t=rF(e,e=>{let t=this.get(e);return!t||t.type===`connector`?null:{box:this.outerBox(t),ellipse:t.type===`shape`&&t.shape===`ellipse`}});return sF(e.mode,t[0],t[1])}selection(){return[...this.selected].map(e=>this.get(e)).filter(e=>!!e)}expanded(e){let t=new Set,n=this.elements();for(let r of e){t.add(r);for(let e of n)e.group===r&&t.add(e.id)}return[...t]}schedule(){this.raf||=requestAnimationFrame(()=>{this.raf=0,this.render()})}render(){let e=this.elements(),t=new Set,n=null;for(let r of e){t.add(r.id);let e=this.rendered.get(r.id);e&&e.type!==r.type&&(e.note?.destroy(),e.el.remove(),e=void 0),e||(e={el:document.createElement(`div`),key:``,type:r.type},e.el.className=`dw-cv-el dw-cv-${r.type}`,e.el.dataset.id=r.id,this.rendered.set(r.id,e),(r.type===`note`||r.type===`text`)&&this.resize?.observe(e.el));let i=this.keyOf(r);e.key===i||this.editing?.id===r.id&&this.stopEditingFn&&r.type!==`note`||(this.draw(e,r),e.key=i),e.el.classList.toggle(`dw-cv-selected`,this.selected.has(r.id)),e.el.classList.toggle(`dw-cv-editing`,this.editing?.id===r.id);let a=n?n.nextElementSibling:this.world.firstElementChild;a!==e.el&&this.world.insertBefore(e.el,a),n=e.el}for(let[e,n]of this.rendered)t.has(e)||(n.note?.destroy(),this.resize?.unobserve(n.el),n.el.remove(),this.rendered.delete(e),this.measured.delete(e),this.selected.delete(e));this.editing&&!t.has(this.editing.id)&&(this.editing=null),this.drawOverlay(),this.ui.refresh()}keyOf(e){if(e.type===`connector`){let t=this.routeOf(e);return this.routes.set(e.id,t),JSON.stringify(e)+t.d}return e.type===`note`&&e.page?JSON.stringify(e)+(this.opts.pageTitle?.()??``):JSON.stringify(e)}place(e,t,n=0,r=!1){e.style.transform=`translate(${t.x}px, ${t.y}px)${n?` rotate(${n}deg)`:``}`,e.style.width=r?``:`${t.w}px`,e.style.height=r?``:`${t.h}px`}draw(e,t){let n=e.el,r=this.editing?.id===t.id;switch(t.type){case`shape`:{this.place(n,t,t.rotate);let e=r?n.querySelector(`.dw-cv-label`):null;n.innerHTML=`${GL(t,IL)}`;let i=e??document.createElement(`div`);i.className=`dw-cv-label`,e||(i.textContent=t.text),i.style.color=IL(t.textColor,`line`),i.style.fontSize=`${t.fontSize}px`,n.append(i);return}case`text`:{n.style.transform=`translate(${t.x}px, ${t.y}px)${t.rotate?` rotate(${t.rotate}deg)`:``}`,n.style.width=t.w?`${t.w}px`:``,n.style.height=``;let e=n.querySelector(`.dw-cv-textbody`);e||(e=document.createElement(`div`),e.className=`dw-cv-textbody`,n.append(e)),r||(e.textContent=t.text),e.dataset.placeholder=this.labels.textPlaceholder,Object.assign(e.style,{color:IL(t.color,`line`),fontSize:`${t.fontSize}px`,fontFamily:QF(t.font),textAlign:t.align,fontWeight:t.bold?`650`:``,whiteSpace:t.w?`pre-wrap`:`pre`});return}case`connector`:{let e=this.routes.get(t.id)??this.routeOf(t),i=this.boxOf(t),a=24+t.strokeWidth*3,o={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2};this.place(n,o);let s=``,c=t.label||r;n.innerHTML=`${qL(t,e,IL)}${s}`+(c?`
${LL(t.label)}
`:``);return}case`brush`:this.place(n,t,t.rotate),n.innerHTML=`${YL(t,IL).replace(``;return;case`note`:this.drawNote(e,t);return;case`frame`:{this.place(n,t);let e=r?n.querySelector(`.dw-cv-frametitle`):null;n.innerHTML=``;let i=e??document.createElement(`div`);i.className=`dw-cv-frametitle`,e||(i.textContent=t.title||this.labels.frameTitle),n.append(i);return}case`image`:{this.place(n,t,t.rotate);let e=this.opts.files?.resolve(t.src)??t.src,r=n.querySelector(`img`);r||(r=document.createElement(`img`),r.draggable=!1,n.replaceChildren(r)),r.getAttribute(`src`)!==e&&(r.src=e),r.alt=t.alt;return}case`embed`:this.drawEmbed(n,t);return;case`group`:n.style.display=`none`;return;case`mindmap`:this.drawMindmap(n,t);return}}drawNote(e,t){let n=e.el;if(n.style.transform=`translate(${t.x}px, ${t.y}px)`,n.style.width=`${t.w}px`,n.style.height=``,n.style.setProperty(`--dw-cv-note-bg`,IL(t.background,`fill`)),n.classList.toggle(`dw-cv-pagenote`,t.page),!e.note){let r=document.createElement(`div`);r.className=`dw-cv-notehead`;let i=document.createElement(`div`);i.className=`dw-cv-notebody`,n.replaceChildren(r,i);let a=t.page?this.opts.doc.getXmlFragment(`default`):this.store.body(t.id);if(a)try{e.note=this.opts.notes.mount(i,{id:t.id,page:t.page,fragment:a,doc:this.opts.doc,editable:this.editable})}catch(e){this.opts.onError?.(e)}}let r=n.querySelector(`.dw-cv-notehead`);r&&(r.textContent=t.page?this.opts.pageTitle?.()||this.labels.pageNote:``)}drawEmbed(e,t){this.place(e,t);let n=this.opts.embedSource?.(t.url)??null;if(n){if(e.querySelector(`iframe`)?.getAttribute(`src`)===n.src)return;let r=document.createElement(`iframe`);r.src=n.src,r.title=t.url,r.allow=`fullscreen; picture-in-picture; encrypted-media`,r.referrerPolicy=`strict-origin-when-cross-origin`,r.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`),e.replaceChildren(r);return}let r=this.previews.get(t.url);r===void 0&&this.opts.links&&(this.previews.set(t.url,`loading`),this.opts.links.preview(t.url).then(e=>this.previews.set(t.url,e)).catch(()=>this.previews.set(t.url,null)).finally(()=>{let e=this.rendered.get(t.id);e&&(e.key=``),this.schedule()}),r=`loading`);let i=r&&r!==`loading`?r:null,a=t.url;try{a=new URL(t.url).hostname}catch{}let o=i?.image?``:``;e.innerHTML=`${o}${LL(i?.title||a)}${i?.description?`${LL(i.description)}`:``}${LL(i?.site||a)}`}drawMindmap(e,t){let n=this.layoutOf(t),r=n.bounds;this.place(e,{x:t.x+r.x,y:t.y+r.y,w:r.w,h:r.h});let i=IL(t.color,`line`),a=IL(t.color,`fill`),o=n.edges.map(e=>``).join(``),s=this.editing?.id===t.id?this.editing.node:void 0,c=s?e.querySelector(`[data-node="${s}"]`):null,l=[...n.boxes.values()].map(e=>{let n=e.depth===0?`dw-cv-node dw-cv-root`:`dw-cv-node`,o=this.activeNode?.map===t.id&&this.activeNode.node===e.id?` dw-cv-active`:``,s=`left:${e.x-r.x}px;top:${e.y-r.y}px;width:${e.w}px;height:${e.h}px;${e.depth===0?`background:${i};color:var(--dw-surface)`:e.depth===1?`background:${a};border-color:${i}`:`border-color:${i}`}`;return`
${LL(t.nodes[e.id]?.text??``)}
`});e.innerHTML=`${o}${l.join(``)}`,c&&s&&e.querySelector(`[data-node="${s}"]`)?.replaceWith(c)}onResize(e){let t=!1;for(let n of e){let e=n.target,r=e.dataset.id;if(!r)continue;let i={w:e.offsetWidth,h:e.offsetHeight},a=this.measured.get(r);a&&a.w===i.w&&a.h===i.h||(this.measured.set(r,i),t=!0)}if(t){for(let e of this.rendered.values())e.type===`connector`&&(e.key=``);this.schedule()}}toScreen([e,t]){return[e*this.view.zoom+this.view.x,t*this.view.zoom+this.view.y]}toWorld(e,t){let n=this.root.getBoundingClientRect();return[(e-n.left-this.view.x)/this.view.zoom,(t-n.top-this.view.y)/this.view.zoom]}get zoom(){return this.view.zoom}selectionScreenBox(){let e=WP(this.selection().map(e=>this.outerBox(e)));if(!e)return null;let[t,n]=this.toScreen([e.x,e.y]);return{x:t,y:n,w:e.w*this.view.zoom,h:e.h*this.view.zoom}}drawOverlay(){let e=[],t=this.view.zoom,n=(e,t)=>{let n=UP(e);return[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>this.toScreen(YP(e,n,t)).join(`,`)).join(` `)};if(this.entered){let t=this.get(this.entered);t&&e.push(``)}if(this.hover&&this.hover!==this.editing?.id){let t=this.get(this.hover);t&&e.push(``)}let r=this.presenting?[]:this.selection();for(let t of r)if(t.type===`connector`){let n=this.routes.get(t.id)??this.routeOf(t);e.push(``)}else e.push(``);if(this.editable&&!this.presenting&&r.length&&!this.editing){let i=r.length===1?r[0]:null;if(i?.type===`connector`){let t=this.routes.get(i.id)??this.routeOf(i);for(let[n,r]of[[`source`,t.points[0]],[`target`,t.points[t.points.length-1]]]){let[t,i]=this.toScreen(r);e.push(``)}}else if(r.some(jF)&&i?.type!==`mindmap`){let a=i?i.rotate:0,o=i?this.boxOf(i):WP(r.map(e=>this.outerBox(e)));r.length>1&&e.push(``);let s=UP(o),c=[[`nw`,[o.x,o.y]],[`n`,[o.x+o.w/2,o.y]],[`ne`,[o.x+o.w,o.y]],[`e`,[o.x+o.w,o.y+o.h/2]],[`se`,[o.x+o.w,o.y+o.h]],[`s`,[o.x+o.w/2,o.y+o.h]],[`sw`,[o.x,o.y+o.h]],[`w`,[o.x,o.y+o.h/2]]],l=i?.type===`note`;for(let[n,r]of c){if(l&&n!==`e`&&n!==`w`||o.w*t<24&&(n===`n`||n===`s`)||o.h*t<24&&(n===`e`||n===`w`))continue;let[i,c]=this.toScreen(YP(r,s,a));e.push(``)}if(i&&MF(i)){let[n,r]=this.toScreen(YP([o.x+o.w/2,o.y-28/t],s,a));e.push(``)}}}if(this.presenting||this.drawComments(e,n),this.marquee){let[n,r]=this.toScreen([this.marquee.x,this.marquee.y]);e.push(``)}for(let t of this.guides){let n=this.toScreen(t.axis===`x`?[t.value,t.from]:[t.from,t.value]),r=this.toScreen(t.axis===`x`?[t.value,t.to]:[t.to,t.value]);e.push(``)}this.overlay.innerHTML=e.join(``),this.ui.place()}applyView(){let{x:e,y:t,zoom:n}=this.view;this.world.style.transform=`translate(${e}px, ${t}px) scale(${n})`;let r=24*n;this.root.style.backgroundSize=`${r}px ${r}px`,this.root.style.backgroundPosition=`${e}px ${t}px`,this.root.style.setProperty(`--dw-cv-zoom`,String(n)),this.drawOverlay(),this.ui.zoomChanged(),clearTimeout(this.saveTimer),this.saveTimer=setTimeout(()=>this.saveView(),500)}saveView(){if(this.opts.viewKey)try{localStorage.setItem(this.opts.viewKey,JSON.stringify(this.view))}catch{}}restoreView(){if(!this.opts.viewKey)return!1;try{let e=JSON.parse(localStorage.getItem(this.opts.viewKey)??`null`);if(e&&[e.x,e.y,e.zoom].every(e=>typeof e==`number`&&Number.isFinite(e))&&e.zoom>0)return this.view={x:e.x,y:e.y,zoom:Math.min(yR,Math.max(vR,e.zoom))},!0}catch{}return!1}zoomAt(e,t){let n=Math.min(yR,Math.max(vR,e)),r=this.root.getBoundingClientRect(),[i,a]=t??[r.width/2,r.height/2],o=(i-this.view.x)/this.view.zoom,s=(a-this.view.y)/this.view.zoom;this.view={zoom:n,x:i-o*n,y:a-s*n},this.applyView()}zoomBy(e){this.zoomAt(this.view.zoom*e)}fit(e,t=!0,n=48){let r=e??WP(this.elements().map(e=>this.outerBox(e))),i=this.root.getBoundingClientRect(),a=i.width||800,o=i.height||600;if(!r)this.view={x:a/2,y:o/3,zoom:1};else{let t=Math.min(yR,Math.max(vR,Math.min((a-n*2)/Math.max(r.w,1),(o-n*2)/Math.max(r.h,1),e?yR:1)));this.view={zoom:t,x:a/2-(r.x+r.w/2)*t,y:o/2-(r.y+r.h/2)*t},!e&&r.h*t>o&&(this.view.y=n-r.y*t)}t&&this.applyView()}animateTo(e){let t={...this.view},n=performance.now(),r=i=>{let a=Math.min(1,(i-n)/350),o=1-(1-a)**3;this.view={x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o,zoom:t.zoom+(e.zoom-t.zoom)*o},this.applyView(),a<1&&requestAnimationFrame(r)};requestAnimationFrame(r)}setTool(e){(this.editable||e===`select`||e===`hand`)&&(this.stopEditing(),this.tool=e,e!==`select`&&this.clearSelection(),this.root.dataset.tool=e,this.ui.refresh())}setShapeKind(e){this.shapeKind=e,this.setStyle(`shape`,{shape:e}),this.setTool(`shape`)}setStyle(e,t){this.styles={...this.styles,[e]:{...this.styles[e],...t}},this.opts.onStyles?.(this.styles)}restyle(e){let t=[];for(let n of this.selection()){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e in n));if(!Object.keys(r).length)continue;t.push([n.id,r]);let i=n.type;if(i in this.styles){let e=Object.fromEntries(Object.entries(r).filter(([e])=>e in this.styles[i]));Object.keys(e).length&&!(n.type===`note`&&n.page)&&this.setStyle(i,e)}}this.store.updateMany(t)}select(e,t=!1){t||this.selected.clear();for(let t of e)this.selected.add(t);this.activeNode&&!this.selected.has(this.activeNode.map)&&(this.activeNode=null),this.refreshSelection()}clearSelection(){(this.selected.size||this.activeNode||this.entered)&&(this.selected.clear(),this.activeNode=null,this.entered=null,this.refreshSelection())}refreshSelection(){for(let[e,t]of this.rendered)t.el.classList.toggle(`dw-cv-selected`,this.selected.has(e)),t.type===`mindmap`&&(t.key=``);this.schedule(),this.drawOverlay(),this.ui.refresh()}pick(e){let t=this.get(e);return t?.group&&this.entered!==t.group&&this.get(t.group)?t.group:e}hit(e){if(!(e instanceof Element)||!this.world.contains(e))return null;let t=e.closest(`[data-id]`);if(!t?.dataset.id)return null;let n=e.closest(`[data-node]`)?.dataset.node;return{id:t.dataset.id,node:n}}connectableAt(e,t,n){for(let r of document.elementsFromPoint(e,t)){let e=this.hit(r);if(!e||n.has(e.id))continue;let t=this.get(e.id);if(t&&NF(t))return t}return null}listen(){let e=(e,t,n,r)=>{e.addEventListener(t,n,r),this.cleanups.push(()=>e.removeEventListener(t,n,r))};e(this.root,`pointerdown`,e=>this.onDown(e)),e(this.root,`pointermove`,e=>this.onMove(e)),e(this.root,`pointerup`,e=>this.onUp(e)),e(this.root,`pointercancel`,e=>this.onUp(e)),e(this.root,`dblclick`,e=>this.onDouble(e)),e(this.root,`wheel`,e=>this.onWheel(e),{passive:!1}),e(this.root,`keydown`,e=>this.onKey(e)),e(this.root,`keyup`,e=>{e.key===` `&&(this.spaceDown=!1,this.root.classList.remove(`dw-cv-panning`))}),e(document,`copy`,e=>this.onCopy(e,!1)),e(document,`cut`,e=>this.onCopy(e,!0)),e(document,`paste`,e=>this.onPaste(e)),e(this.root,`dragover`,e=>{this.editable&&e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),e(this.root,`drop`,e=>{let t=[...e.dataTransfer?.files??[]].filter(e=>e.type.startsWith(`image/`));this.editable&&t.length&&(e.preventDefault(),this.addImages(t,this.toWorld(e.clientX,e.clientY)))}),e(document,`fullscreenchange`,()=>{!document.fullscreenElement&&this.presenting&&this.stopPresenting()}),e(this.root,`click`,e=>{e.target.closest?.(`a.dw-cv-card`)&&this.editable&&e.preventDefault()})}inEditor(e){if(!(e instanceof Element))return!1;if(e.closest(`.dw-cv-ui`))return!0;if(this.editing){let t=this.rendered.get(this.editing.id);if(t&&t.el.contains(e)&&(e.closest(`[contenteditable=true]`)||e.closest(`.dw-cv-notebody`)||e.closest(`iframe`)))return!0}return!(this.editable||!e.closest(`.dw-cv-notebody, a.dw-cv-card`))}onDown(e){let t=e.target instanceof Element?e.target.closest(`[data-comment]`):null;if(t?.dataset.comment){e.preventDefault(),this.opts.onCommentSelect?.(t.dataset.comment);return}if(this.inEditor(e.target)||e.button===2)return;if(e.preventDefault(),this.root.focus({preventScroll:!0}),this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pointers.size===2){this.cancelDrag();let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect();this.pinch={dist:Math.hypot(e[0]-t[0],e[1]-t[1]),mid:[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],zoom:this.view.zoom,vx:this.view.x,vy:this.view.y};return}if(this.pointers.size>2)return;this.editing&&this.stopEditing();let n=this.toWorld(e.clientX,e.clientY),r=e.pointerType===`touch`,i=()=>{this.drag={kind:`pan`,sx:e.clientX,sy:e.clientY,vx:this.view.x,vy:this.view.y},this.root.classList.add(`dw-cv-panning`)};if(this.root.setPointerCapture?.(e.pointerId),e.button===1||this.tool===`hand`||this.spaceDown||this.presenting)return e.preventDefault(),i();let a=e.target;if(!this.editable){let e=this.opts.onComment&&this.tool===`select`?this.hit(a):null;if(e){let t=this.pick(e.id);this.select([t]);return}return i()}switch(this.tool){case`pen`:{let t=document.createElementNS(bR,`svg`);t.classList.add(`dw-cv-temp`),this.world.append(t),this.drag={kind:`pen`,points:[[n[0],n[1],e.pressure||.5]],temp:t};return}case`eraser`:this.drag={kind:`erase`,hits:new Set},this.erase(e);return;case`shape`:case`frame`:this.drag={kind:`create`,type:this.tool,start:n,id:null};return;case`connector`:{let t=this.connectableAt(e.clientX,e.clientY,new Set),r=t?this.endOn(t,n):{x:n[0],y:n[1]},i=this.store.add({type:`connector`,...this.styles.connector,source:r,target:{x:n[0],y:n[1]}});this.drag={kind:`end`,id:i,side:`target`};return}case`note`:this.addNote(n);return;case`text`:this.addText(n);return;case`mindmap`:this.addMindmap(n);return}let o=a.dataset?.handle,s=a.dataset?.end;if(s){let e=this.selection()[0];e?.type===`connector`&&(this.store.undo?.stopCapturing(),this.drag={kind:`end`,id:e.id,side:s});return}if(o===`rotate`){let e=this.selection()[0],t=UP(this.boxOf(e));this.store.undo?.stopCapturing(),this.drag={kind:`rotate`,id:e.id,c:t,a0:Math.atan2(n[1]-t[1],n[0]-t[0]),r0:e.rotate};return}if(o){let e=this.selection(),t=e.length===1?e[0]:null,n=new Map(this.expanded(this.selected).map(e=>[e,this.get(e)]));for(let[e,t]of n){let r=this.measured.get(e);t.type===`text`&&r&&n.set(e,{...t,w:r.w,h:r.h}),t.type===`note`&&r&&n.set(e,{...t,h:r.h})}this.store.undo?.stopCapturing(),this.drag={kind:`resize`,handle:o,box:t?this.boxOf(t):WP(e.map(e=>this.outerBox(e))),deg:t?t.rotate:0,orig:n,keep:e.some(e=>e.type===`image`||e.type===`text`||e.type===`brush`)||e.length>1};return}let c=this.hit(a);if(c){let t=this.pick(c.id),r=this.get(t);if(r?.type===`mindmap`&&c.node){this.activeNode={map:t,node:c.node};let e=this.rendered.get(t);e&&(e.key=``)}else r?.type!==`mindmap`&&(this.activeNode=null);e.shiftKey?(this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.refreshSelection()):this.selected.has(t)?this.refreshSelection():this.select([t]),this.startMove(n,t)}else{if(r)return i();this.entered=null,this.drag={kind:`marquee`,start:n,add:e.shiftKey,base:e.shiftKey?new Set(this.selected):new Set},e.shiftKey||this.clearSelection()}}startMove(e,t){let n=this.expanded(this.selected);for(let e of[...n]){let t=this.get(e);if(t?.type===`frame`)for(let e of this.elements())e.type!==`frame`&&!n.includes(e.id)&&qP(t,this.outerBox(e))&&n.push(...this.expanded([e.id]))}let r=[...new Set(n)].filter(e=>this.get(e)?.type!==`group`),i=new Map(r.map(e=>[e,this.get(e)])),a=WP(r.map(e=>this.outerBox(this.get(e))))??{x:e[0],y:e[1],w:0,h:0};this.store.undo?.stopCapturing(),this.drag={kind:`move`,start:e,ids:r,orig:i,box:a,moved:!1,clickId:t}}endOn(e,t){let n=this.outerBox(e),r=pF(n,t,14/this.view.zoom);return r?{id:e.id,pos:[(r[0]-n.x)/Math.max(n.w,1),(r[1]-n.y)/Math.max(n.h,1)]}:{id:e.id}}onMove(e){if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect(),r=Math.hypot(e[0]-t[0],e[1]-t[1]),i=[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],a=this.pinch,o=Math.min(yR,Math.max(vR,a.zoom*r/Math.max(a.dist,1))),s=(a.mid[0]-a.vx)/a.zoom,c=(a.mid[1]-a.vy)/a.zoom;this.view={zoom:o,x:i[0]-s*o,y:i[1]-c*o},this.applyView();return}let t=this.drag,n=this.toWorld(e.clientX,e.clientY);if(t)switch(t.kind){case`pan`:this.view={...this.view,x:t.vx+e.clientX-t.sx,y:t.vy+e.clientY-t.sy},this.applyView();return;case`move`:{let r=n[0]-t.start[0],i=n[1]-t.start[1];if(!t.moved&&Math.hypot(r,i)*this.view.zoom<3)return;if(t.moved=!0,e.altKey)this.guides=[];else{let e=new Set(t.ids),n=this.visibleBoxes().filter(([t])=>!e.has(t)).map(([,e])=>e),a=fF({...t.box,x:t.box.x+r,y:t.box.y+i},n,6/this.view.zoom);r+=a.dx,i+=a.dy,this.guides=a.guides}let a=[];for(let[e,n]of t.orig)if(n.type===`connector`){let t={};for(let e of[`source`,`target`]){let a=n[e];a.id||(t[e]={x:(a.x??0)+r,y:(a.y??0)+i})}Object.keys(t).length&&a.push([e,t])}else a.push([e,{x:n.x+r,y:n.y+i}]);this.store.updateMany(a);return}case`marquee`:{this.marquee=JP(t.start,n);let e=new Set(t.base),r=this.marquee;for(let t of this.elements()){if(t.group&&this.get(t.group))continue;let n=this.outerBox(t);(t.type===`frame`?qP(r,n):KP(r,n))&&e.add(t.id)}for(let t of this.elements().filter(e=>e.type===`group`))KP(r,this.boxOf(t))&&e.add(t.id);this.selected.clear();for(let t of e)this.selected.add(t);this.refreshSelection();return}case`resize`:this.doResize(t,n,e.shiftKey);return;case`rotate`:{let r=t.r0+(Math.atan2(n[1]-t.c[1],n[0]-t.c[0])-t.a0)*180/Math.PI;e.shiftKey&&(r=Math.round(r/15)*15),r=(r%360+360)%360,this.store.update(t.id,{rotate:Math.round(r*10)/10});return}case`create`:{let r=JP(t.start,n);if(!t.id&&r.w*this.view.zoom<4&&r.h*this.view.zoom<4)return;e.shiftKey&&(r.w=r.h=Math.max(r.w,r.h)),t.id?this.store.update(t.id,{...r}):t.id=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...r}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...r});return}case`end`:{let r=this.get(t.id);if(r?.type!==`connector`)return;let i=r[t.side===`source`?`target`:`source`],a=new Set([t.id]),o=this.connectableAt(e.clientX,e.clientY,a);this.hover=o?.id??null;let s=o&&o.id!==i.id?this.endOn(o,n):{x:n[0],y:n[1]};this.store.update(t.id,{[t.side]:s});return}case`pen`:t.points.push([n[0],n[1],e.pressure||.5]),t.temp.innerHTML=``;return;case`erase`:this.erase(e);return}else if(this.editable&&this.tool===`connector`){let t=this.connectableAt(e.clientX,e.clientY,new Set);(t?.id??null)!==this.hover&&(this.hover=t?.id??null,this.drawOverlay())}}erase(e){let t=this.drag;if(t?.kind!==`erase`)return;let n=this.toWorld(e.clientX,e.clientY),r=6/this.view.zoom;for(let n of document.elementsFromPoint(e.clientX,e.clientY)){let e=this.hit(n);if(!e)continue;let r=this.get(e.id);r&&r.type!==`note`&&r.type!==`frame`&&(t.hits.add(r.id),this.rendered.get(r.id)?.el.classList.add(`dw-cv-erasing`))}for(let e of this.elements())e.type!==`brush`||t.hits.has(e.id)||QP(n,e.points.map(t=>[t[0]+e.x,t[1]+e.y]))<=r+e.size/2&&(t.hits.add(e.id),this.rendered.get(e.id)?.el.classList.add(`dw-cv-erasing`))}doResize(e,t,n){let r=e.box,i=UP(r),a=YP(t,i,-e.deg),o=r.x,s=r.y,c=r.x+r.w,l=r.y+r.h;e.handle.includes(`w`)&&(o=a[0]),e.handle.includes(`e`)&&(c=a[0]),e.handle.includes(`n`)&&(s=a[1]),e.handle.includes(`s`)&&(l=a[1]);let u=8/this.view.zoom;c-o[e[0]*m,e[1]*h,e[2]??.5])}]);break;case`mindmap`:case`group`:v.push([t,{x:e,y:i}]);break;default:v.push([t,{x:e,y:i,w:n.w*m,h:n.h*h}])}}this.store.updateMany(v)}visibleBoxes(){let e=this.root.getBoundingClientRect(),t=JP(this.toWorld(e.left,e.top),this.toWorld(e.right,e.bottom)),n=[];for(let e of this.elements()){if(e.type===`connector`||e.type===`group`)continue;let r=this.outerBox(e);if(KP(t,r)&&n.push([e.id,r]),n.length>300)break}return n}onUp(e){if(this.pointers.delete(e.pointerId),this.pinch){this.pointers.size<2&&(this.pinch=null);return}let t=this.drag;if(this.drag=null,this.root.classList.remove(`dw-cv-panning`),this.guides=[],this.marquee=null,this.hover=null,!t)return;let n=this.toWorld(e.clientX,e.clientY);switch(t.kind){case`create`:{let e=t.id;if(!e){let r=t.type===`frame`?{w:800,h:600}:{w:140,h:100},i={x:n[0]-r.w/2,y:n[1]-r.h/2,...r};e=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...i}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...i})}this.tool=`select`,this.root.dataset.tool=`select`,this.select([e]);break}case`end`:{let e=this.get(t.id);if(e?.type===`connector`){let n=this.routeOf(e),r=n.points[0],i=n.points[n.points.length-1];Math.hypot(r[0]-i[0],r[1]-i[1])*this.view.zoom<8&&this.tool===`connector`?this.store.remove([t.id]):this.tool===`connector`&&this.select([t.id])}break}case`pen`:{t.temp.remove(),t.points.length<2&&t.points.push([t.points[0][0]+.5,t.points[0][1]+.5,.5]);let e=t.points.map(e=>e[0]),n=t.points.map(e=>e[1]),r=this.styles.brush.size,i=Math.min(...e)-r,a=Math.min(...n)-r,o=Math.max(...e)+r-i,s=Math.max(...n)+r-a;this.store.add({type:`brush`,...this.styles.brush,x:i,y:a,w:o,h:s,points:t.points.map(e=>[Math.round((e[0]-i)*10)/10,Math.round((e[1]-a)*10)/10,Math.round((e[2]??.5)*100)/100])});break}case`erase`:for(let e of t.hits)this.rendered.get(e)?.el.classList.remove(`dw-cv-erasing`);t.hits.size&&this.store.remove(t.hits)}this.drawOverlay(),this.ui.refresh()}cancelDrag(){let e=this.drag;e?.kind===`pen`&&e.temp.remove(),this.drag=null,this.marquee=null,this.guides=[]}onDouble(e){if(this.inEditor(e.target)||!this.editable||this.tool!==`select`)return;let t=this.hit(e.target);if(!t){this.addText(this.toWorld(e.clientX,e.clientY));return}let n=this.get(t.id);n&&(n.group&&this.entered!==n.group&&this.get(n.group)?(this.entered=n.group,this.select([n.id])):(n.type!==`frame`||e.target.closest(`.dw-cv-frametitle`))&&this.startEdit(n.id,t.node))}onWheel(e){if(this.presenting||e.target instanceof Element&&e.target.closest(`.dw-cv-ui`))return;e.preventDefault();let t=this.root.getBoundingClientRect();if(e.ctrlKey||e.metaKey){this.zoomAt(this.view.zoom*Math.exp(-e.deltaY*.01),[e.clientX-t.left,e.clientY-t.top]);return}let n=e.deltaMode===1?16:1,r=e.shiftKey&&!e.deltaX?e.deltaY:e.deltaX,i=e.shiftKey&&!e.deltaX?0:e.deltaY;this.view={...this.view,x:this.view.x-r*n,y:this.view.y-i*n},this.applyView()}onKey(e){if(this.presenting){this.presentKey(e);return}if(xR(e.target)||this.inEditor(e.target))return;let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(e.key===` `&&!t){this.spaceDown=!0,this.root.classList.add(`dw-cv-panning`),e.preventDefault();return}if(t&&(n===`=`||n===`+`))return e.preventDefault(),this.zoomBy(1.25);if(t&&n===`-`)return e.preventDefault(),this.zoomBy(.8);if(e.altKey&&!t&&(e.code===`Digit0`||e.code===`Digit1`||e.code===`Digit2`)){if(e.preventDefault(),e.code===`Digit0`)return this.zoomAt(1);if(e.code===`Digit1`)return this.fit();let t=WP(this.selection().map(e=>this.outerBox(e)));return this.fit(t??void 0)}if(e.key===`Escape`){this.entered?(this.select([this.entered]),this.entered=null):this.selected.size?this.clearSelection():this.setTool(`select`);return}if(!this.editable){!t&&n===`h`&&this.setTool(`hand`),!t&&n===`v`&&this.setTool(`select`);return}if(this.activeNode&&this.mindmapKey(e))return;if(t&&n===`z`){e.preventDefault(),e.shiftKey?this.store.undo?.redo():this.store.undo?.undo();return}if(t&&n===`y`){e.preventDefault(),this.store.undo?.redo();return}if(t&&n===`a`){e.preventDefault(),this.select(this.elements().filter(e=>!e.group||!this.get(e.group)).map(e=>e.id));return}if(t&&n===`d`){e.preventDefault(),this.duplicate();return}if(t&&n===`g`){e.preventDefault(),e.shiftKey?this.ungroup():this.group();return}if((e.key===`Delete`||e.key===`Backspace`)&&this.selected.size){e.preventDefault(),this.deleteSelection();return}if(e.key===`Enter`&&this.selected.size===1){e.preventDefault();let t=[...this.selected][0];this.startEdit(t);return}if(e.key.startsWith(`Arrow`)&&this.selected.size){e.preventDefault();let t=e.shiftKey?10:1,n=e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,r=e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0;this.nudge(n,r);return}if(t||e.altKey)return;let r={v:`select`,h:`hand`,n:`note`,t:`text`,s:`shape`,c:`connector`,p:`pen`,e:`eraser`,f:`frame`,m:`mindmap`};r[n]?(e.preventDefault(),this.setTool(r[n])):n===`i`?this.ui.pickImage():n===`l`&&this.addLink()}nudge(e,t){let n=this.expanded(this.selected),r=[];for(let i of n){let n=this.get(i);if(n&&n.type!==`group`){if(n.type===`connector`){let a={};for(let r of[`source`,`target`]){let i=n[r];i.id||(a[r]={x:(i.x??0)+e,y:(i.y??0)+t})}r.push([i,a])}else r.push([i,{x:n.x+e,y:n.y+t}])}}this.store.updateMany(r)}startEdit(e,t){if(!this.editable)return;let n=this.get(e),r=this.rendered.get(e);if(n&&r){if(n.type===`group`)this.entered=e;else if(n.type===`mindmap`){let i=t??(this.activeNode?.map===e?this.activeNode.node:iI(n.nodes));if(!i)return;this.activeNode={map:e,node:i},this.editing={id:e,node:i},this.draw(r,n);let a=r.el.querySelector(`[data-node="${i}"]`);a&&this.editText(a,n.nodes[i]?.text??``,!0,t=>this.store.updateNode(e,i,{text:t}))}else if(n.type!==`image`&&n.type!==`brush`)switch(this.select([e]),this.editing={id:e,node:t},r.el.classList.add(`dw-cv-editing`),this.drawOverlay(),this.ui.refresh(),n.type){case`note`:r.note?.focus();return;case`embed`:return;case`text`:{let t=r.el.querySelector(`.dw-cv-textbody`);t&&this.editText(t,n.text,!1,t=>t.trim()?this.store.update(e,{text:t}):this.store.remove([e]));return}case`shape`:{let t=r.el.querySelector(`.dw-cv-label`);t&&this.editText(t,n.text,!1,t=>this.store.update(e,{text:t}));return}case`frame`:{let t=r.el.querySelector(`.dw-cv-frametitle`);t&&this.editText(t,n.title,!0,t=>this.store.update(e,{title:t}));return}case`connector`:{this.draw(r,n);let t=r.el.querySelector(`.dw-cv-clabel`);t&&this.editText(t,n.label,!0,t=>this.store.update(e,{label:t}));return}}}}editText(e,t,n,r){e.contentEditable=`true`,e.spellcheck=!0,e.textContent=t,e.classList.add(`dw-cv-typing`);let i=!1,a=n=>{if(i)return;i=!0,this.stopEditingFn=null,e.contentEditable=`false`,e.classList.remove(`dw-cv-typing`),e.removeEventListener(`keydown`,o),e.removeEventListener(`blur`,s),e.removeEventListener(`paste`,c);let a=(e.innerText??e.textContent??``).replace(/\n$/,``),l=this.editing?.id;if(this.editing=null,(n&&a!==t||n&&!a.trim())&&r(a),l){let e=this.rendered.get(l);e&&(e.key=``)}this.schedule(),this.ui.refresh()},o=e=>{e.stopPropagation(),e.key===`Escape`||e.key===`Enter`&&(n||e.ctrlKey||e.metaKey)&&!e.shiftKey?(e.preventDefault(),a(!0),this.root.focus({preventScroll:!0})):e.key===`Tab`&&this.activeNode&&(e.preventDefault(),a(!0),this.mindmapAdd(`child`))},s=()=>a(!0),c=e=>{e.preventDefault(),e.stopPropagation(),document.execCommand(`insertText`,!1,e.clipboardData?.getData(`text/plain`)??``)};e.addEventListener(`keydown`,o),e.addEventListener(`blur`,s),e.addEventListener(`paste`,c),this.stopEditingFn=()=>a(!0),e.focus({preventScroll:!0});let l=document.createRange();l.selectNodeContents(e);let u=getSelection();u?.removeAllRanges(),u?.addRange(l)}stopEditingFn=null;stopEditing(){let e=this.stopEditingFn;if(this.stopEditingFn=null,e?.(),this.editing){let e=this.rendered.get(this.editing.id);e?.el.classList.remove(`dw-cv-editing`),e?.note&&document.activeElement&&e.el.contains(document.activeElement)&&document.activeElement.blur(),this.editing=null,this.drawOverlay(),this.ui.refresh()}}frameName(){let e=this.elements().filter(e=>e.type===`frame`).length+1;return`${this.labels.frameTitle} ${e}`}addNote(e){let t=this.store.add({type:`note`,...this.styles.note,x:e[0]-24,y:e[1]-24,w:320,h:120});this.setTool(`select`),this.select([t]),this.render(),this.startEdit(t)}addText(e){let t=this.store.add({type:`text`,...this.styles.text,x:e[0],y:e[1]-this.styles.text.fontSize*.7,w:0,h:0,text:``});this.setTool(`select`),this.render(),this.startEdit(t)}addMindmap(e){let t=`r${Date.now().toString(36)}`,n=this.store.add({type:`mindmap`,...this.styles.mindmap,x:e[0],y:e[1],nodes:{[t]:{text:this.labels.centralIdea,parent:``,pos:0}}});this.setTool(`select`),this.select([n]),this.activeNode={map:n,node:t},this.render(),this.startEdit(n,t)}viewCentre(){let e=this.root.getBoundingClientRect();return this.toWorld(e.left+e.width/2,e.top+e.height/2)}async addImages(e,t){let n=this.opts.files?.upload;if(!n)return;let[r,i]=t??this.viewCentre(),a=[];for(let t of e)try{let e=await n.call(this.opts.files,t),o=await CR(this.opts.files?.resolve(e.url)??e.url),s=Math.min(1,480/Math.max(o.w,1)),c=o.w*s,l=o.h*s;a.push(this.store.add({type:`image`,src:e.url,alt:e.name,x:r-c/2,y:i-l/2,w:c,h:l})),r+=24,i+=24}catch(e){this.opts.onError?.(e)}a.length&&this.select(a)}async addLink(e,t){let n=(e??window.prompt(this.labels.linkPrompt,`https://`))?.trim();if(!n||!/^https?:\/\//i.test(n))return;let[r,i]=t??this.viewCentre(),a=this.opts.embedSource?.(n),o=a?560:380,s=a?a.ratio===`video`?315:420:120,c=this.store.add({type:`embed`,url:n,x:r-o/2,y:i-s/2,w:o,h:s});this.setTool(`select`),this.select([c])}insertElements(e){let t=WP(e.map(e=>({x:Number(e.x)||0,y:Number(e.y)||0,w:Number(e.w)||0,h:Number(e.h)||0})))??{x:0,y:0,w:0,h:0},[n,r]=this.viewCentre(),i=this.store.insertJSON(e,n-(t.x+t.w/2),r-(t.y+t.h/2));this.setTool(`select`),this.select(i.filter(e=>!i.includes(this.get(e)?.group??``)))}insertSticker(e){this.insertElements(zF(e))}insertTemplate(e){this.insertElements(KF(e,this.labels))}deleteSelection(){let e=[...this.selected];this.clearSelection(),this.store.remove(e)}duplicate(){let e=this.store.toJSON(this.selected);if(!e.length)return;let t=this.store.insertJSON(e,24,24);this.select(t.filter(e=>!this.get(e)?.group||!t.includes(this.get(e).group)))}group(){let e=this.store.groupOf([...this.selected]);e&&this.select([e])}ungroup(){let e=this.selection().filter(e=>e.type===`group`),t=e.flatMap(e=>this.store.ungroup(e.id));e.length&&this.select(t)}reorder(e){this.store.reorder(this.expanded(this.selected),e)}mindmapAdd(e){let t=this.activeNode,n=t?this.get(t.map):void 0;if(!t||n?.type!==`mindmap`)return;let r=n.nodes[t.node];if(!r)return;let i=e===`child`||!r.parent?t.node:r.parent,a=aI(n.nodes,i),o;if(e===`sibling`&&r.parent){let e=a.indexOf(t.node),r=n.nodes[a[e]]?.pos??0;o=(r+(a[e+1]?n.nodes[a[e+1]]?.pos??r+2:r+2))/2}else o=a.length?Math.max(...a.map(e=>n.nodes[e]?.pos??0))+1:0;let s=this.store.addNode(t.map,i,o,``);this.activeNode={map:t.map,node:s},this.render(),this.startEdit(t.map,s)}mindmapKey(e){let t=this.activeNode,n=this.get(t.map);if(n?.type!==`mindmap`||!this.selected.has(t.map))return!1;if(e.key===`Tab`)return e.preventDefault(),this.mindmapAdd(`child`),!0;if(e.key===`Enter`)return e.preventDefault(),this.mindmapAdd(`sibling`),!0;if(e.key===`F2`)return e.preventDefault(),this.startEdit(t.map,t.node),!0;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault();let r=n.nodes[t.node]?.parent;return this.store.removeNode(t.map,t.node),this.activeNode=r?{map:t.map,node:r}:null,this.schedule(),!0}if(e.key.startsWith(`Arrow`)&&!e.shiftKey){e.preventDefault();let r=sI(this.layoutOf(n),n.nodes,t.node,e.key);if(r){this.activeNode={map:t.map,node:r};let e=this.rendered.get(t.map);e&&(e.key=``),this.schedule()}return!0}return!1}owns(){let e=document.activeElement;return!!e&&(e===this.root||this.root.contains(e)&&!xR(e)&&!this.inEditor(e))}onCopy(e,t){if(!this.owns()||!this.selected.size||getSelection()?.toString())return;let n=this.store.toJSON(this.selected);e.clipboardData?.setData(`text/plain`,`docwell-canvas:${JSON.stringify(n)}`),e.preventDefault(),t&&this.editable&&this.deleteSelection()}onPaste(e){if(!this.editable||!this.owns())return;let t=[...e.clipboardData?.files??[]].filter(e=>e.type.startsWith(`image/`));if(t.length){e.preventDefault(),this.addImages(t);return}let n=e.clipboardData?.getData(`text/plain`)??``;if(!n)return;if(e.preventDefault(),n.startsWith(`docwell-canvas:`)){try{let e=JSON.parse(n.slice(15));Array.isArray(e)&&this.insertElements(e)}catch{}return}if(/^https?:\/\/\S+$/i.test(n.trim())){this.addLink(n.trim());return}let[r,i]=this.viewCentre(),a=this.store.add({type:`text`,...this.styles.text,x:r,y:i,w:n.length>60?480:0,h:0,text:n});this.select([a])}setComments(e,t=``){this.comments=e;let n=t!==this.activeComment;this.activeComment=t;let r=t?e.find(e=>e.comment===t):void 0;n&&r&&this.reveal(r.element),this.drawOverlay()}reveal(e){let t=this.get(e);if(!t)return;let n=this.outerBox(t),r=this.root.getBoundingClientRect(),[i,a]=this.toScreen([n.x,n.y]),[o,s]=this.toScreen([n.x+n.w,n.y+n.h]);if(i>=0&&a>=0&&o<=r.width&&s<=r.height)return;let c={...this.view};if(n.w*c.zoome.comment===this.activeComment);o&&e.push(``);let[s,c]=this.toScreen([a.x+a.w,a.y]),l=(o??i[0]).comment;e.push(`${LL(this.labels.comment)}${i.length}`)}}async exportImage(e,t=!1){let n=t&&this.selected.size?new Set(this.expanded(this.selected)):null,r=this.elements().filter(e=>!n||n.has(e.id));return _R(e,{root:this.root,elements:r,boxOf:e=>this.boxOf(e),routeOf:e=>this.routes.get(e.id)??this.routeOf(e),layoutOf:e=>this.layoutOf(e),noteBody:e=>e.page?this.opts.doc.getXmlFragment(`default`):this.store.body(e.id),pageTitle:this.opts.pageTitle?.()??``,resolve:e=>this.opts.files?.resolve(e)??e})}frames(){return this.elements().filter(e=>e.type===`frame`).sort((e,t)=>t.index-e.index)}present(){let e=this.frames().map(e=>e.id);if(!e.length){this.ui.toast(this.labels.presentNoFrames);return}this.stopEditing(),this.clearSelection();let t=this.ui.presentBar();this.presenting={frames:e,at:0,bar:t},this.root.classList.add(`dw-cv-presenting`),this.root.requestFullscreen?.().catch(()=>{}),requestAnimationFrame(()=>this.goTo(0))}goTo(e){let t=this.presenting;if(!t)return;t.at=Math.max(0,Math.min(t.frames.length-1,e));let n=this.get(t.frames[t.at]);if(n){let e={...this.view};this.fit(this.boxOf(n),!1,24);let t={...this.view};this.view=e,this.animateTo(t)}this.ui.presentStep(t.at,t.frames.length)}presentStep(e){this.presenting&&this.goTo(this.presenting.at+e)}stopPresenting(){let e=this.presenting;e&&(this.presenting=null,e.bar.remove(),this.root.classList.remove(`dw-cv-presenting`),document.fullscreenElement===this.root&&document.exitFullscreen().catch(()=>{}),this.drawOverlay())}get isPresenting(){return!!this.presenting}presentKey(e){[`ArrowRight`,`ArrowDown`,`PageDown`,` `,`Enter`].includes(e.key)?(e.preventDefault(),this.presentStep(1)):[`ArrowLeft`,`ArrowUp`,`PageUp`,`Backspace`].includes(e.key)?(e.preventDefault(),this.presentStep(-1)):e.key===`Escape`&&(e.preventDefault(),this.stopPresenting())}};function CR(e){return new Promise(t=>{let n=new Image;n.onload=()=>t({w:n.naturalWidth||320,h:n.naturalHeight||240}),n.onerror=()=>t({w:320,h:240}),n.src=e})}var wR={database:`Database`,untitled:`Untitled database`,untitledRow:`Untitled`,newRow:`New record`,addColumn:`Add property`,columnName:`Property name`,search:`Search records`,filter:`Filter`,sort:`Sort`,group:`Group`,properties:`Properties`,more:`More`,addView:`Add view`,viewName:`View name`,renameView:`Rename view`,duplicateView:`Duplicate view`,deleteView:`Delete view`,layout:`Layout`,viewTable:`Table`,viewKanban:`Kanban`,viewCalendar:`Calendar`,noValue:`No value`,checked:`Checked`,unchecked:`Unchecked`,noRows:`No records`,noMatches:`No records match`,rename:`Rename`,type:`Type`,hide:`Hide in view`,show:`Show in view`,sortAscending:`Sort ascending`,sortDescending:`Sort descending`,filterBy:`Filter by this property`,insertLeft:`Insert left`,insertRight:`Insert right`,moveLeft:`Move left`,moveRight:`Move right`,duplicate:`Duplicate`,deleteColumn:`Delete property`,typeTitle:`Title`,typeText:`Text`,typeNumber:`Number`,typeCheckbox:`Checkbox`,typeSelect:`Select`,typeMultiSelect:`Multi-select`,typeDate:`Date`,typeProgress:`Progress`,typeLink:`Link`,typeAttachment:`Attachment`,typeMember:`Member`,typeCreatedTime:`Created time`,typeCreatedBy:`Created by`,typeRelation:`Relation`,typeRollup:`Rollup`,linkedCount:`{n} linked`,rollupDays:`{n} days`,relationTo:`Related database`,relationPick:`Choose a database`,relationThisPage:`On this page`,relationOtherPage:`On another page…`,relationSearchPage:`Find a page`,relationNoDatabases:`No databases on that page`,relationMissing:`The related database is not available.`,linkRecord:`Link a record`,searchRecords:`Search records`,noRecords:`No records`,openRelated:`Open record`,rollupSettings:`Rollup`,rollupRelation:`Relation`,rollupProperty:`Property`,rollupFn:`Calculate`,rollupRecords:`Records`,rollupNeedsRelation:`Add a relation property first.`,fnShowOriginal:`Show values`,fnCount:`Count records`,fnCountValues:`Count values`,fnCountUnique:`Count unique values`,fnCountEmpty:`Count empty`,fnCountNotEmpty:`Count not empty`,fnPercentNotEmpty:`Percent not empty`,fnSum:`Sum`,fnAverage:`Average`,fnMedian:`Median`,fnMin:`Min`,fnMax:`Max`,fnRange:`Range`,fnEarliest:`Earliest date`,fnLatest:`Latest date`,fnChecked:`Checked`,fnPercentChecked:`Percent checked`,openFullPage:`Open as full page`,backToPage:`Back to the page`,recordNotFound:`This record is not in the database any more.`,opContains:`contains`,opNotContains:`does not contain`,opIs:`is`,opIsNot:`is not`,opIsEmpty:`is empty`,opIsNotEmpty:`is not empty`,opGt:`is greater than`,opLt:`is less than`,opGte:`is at least`,opLte:`is at most`,opBefore:`is before`,opAfter:`is after`,opChecked:`is checked`,opUnchecked:`is not checked`,addFilter:`Add filter`,matchAll:`Every filter matches`,matchAny:`Any filter matches`,remove:`Remove`,value:`Value`,noFilters:`No filters yet`,addSort:`Add sort`,ascending:`Ascending`,descending:`Descending`,noSorts:`No sorts yet`,groupBy:`Group by`,noGrouping:`No grouping`,showAll:`Show all`,hideAll:`Hide all`,dateColumn:`Date property`,today:`Today`,previousMonth:`Previous month`,nextMonth:`Next month`,noDateColumn:`Add a date property to place records on the calendar.`,noDate:`No date ({n})`,noGroupColumn:`Add a select, checkbox or member property to sort cards into columns.`,openRow:`Open`,copyLink:`Copy link to record`,deleteRow:`Delete record`,duplicateRow:`Duplicate record`,insertAbove:`Insert above`,insertBelow:`Insert below`,deleteRows:`Delete`,selected:`{n} selected`,selectRow:`Select record`,dragRow:`Drag to move`,close:`Close`,expand:`Full width`,collapse:`Narrow`,previousRow:`Previous record`,nextRow:`Next record`,bodyPlaceholder:`Write about this record…`,bodyReadOnly:`This record has no notes.`,searchOptions:`Find or create a choice`,createOption:`Create “{n}”`,optionColor:`Colour`,deleteOption:`Delete choice`,renameOption:`Rename choice`,searchPeople:`Find a person`,noPeople:`Nobody found`,upload:`Upload a file`,linkPlaceholder:`Paste a link`,clear:`Clear`,exportCsv:`Export as CSV`,importCsv:`Import CSV`,imported:`Added {n} records`,copyNotice:`Copied {n} cells`,readOnly:`Only people who can edit the page can change this database.`,resize:`Drag to change the width`,groupAsDatabase:`Group as database`,done:`Done`},TR={title:`typeTitle`,text:`typeText`,number:`typeNumber`,checkbox:`typeCheckbox`,select:`typeSelect`,multiSelect:`typeMultiSelect`,date:`typeDate`,progress:`typeProgress`,link:`typeLink`,attachment:`typeAttachment`,member:`typeMember`,createdTime:`typeCreatedTime`,createdBy:`typeCreatedBy`,relation:`typeRelation`,rollup:`typeRollup`},ER=(e,t)=>e[TR[t]],DR={contains:`opContains`,notContains:`opNotContains`,is:`opIs`,isNot:`opIsNot`,isEmpty:`opIsEmpty`,isNotEmpty:`opIsNotEmpty`,gt:`opGt`,lt:`opLt`,gte:`opGte`,lte:`opLte`,before:`opBefore`,after:`opAfter`,checked:`opChecked`,unchecked:`opUnchecked`},OR=(e,t)=>e[DR[t]],kR=(e,t)=>t===`kanban`?e.viewKanban:t===`calendar`?e.viewCalendar:e.viewTable,AR=(e,t)=>e.replace(`{n}`,String(t)),{colors:jR,...MR}=mF,NR={slashMenu:`Insert block`,noMatches:`No matching blocks`,slash:{text:{label:`Text`,description:`Plain paragraph`},h1:{label:`Heading 1`,description:`Big section heading`},h2:{label:`Heading 2`,description:`Medium section heading`},h3:{label:`Heading 3`,description:`Small section heading`},otherHeadings:{label:`Other headings`,description:`Headings 4 to 6`},h4:{label:`Heading 4`,description:`A heading below level 3`},h5:{label:`Heading 5`,description:`A heading below level 4`},h6:{label:`Heading 6`,description:`The smallest heading`},bullet:{label:`Bulleted list`,description:`A simple list`},ordered:{label:`Numbered list`,description:`A list with numbers`},todo:{label:`To-do list`,description:`Tasks to tick off (or type [])`},callout:{label:`Callout`,description:`Set a note apart with an emoji and colour`},table:{label:`Table`,description:`Rows and columns`},quote:{label:`Quote`,description:`Set text apart as a quote`},code:{label:`Code block`,description:`Monospaced code`},divider:{label:`Divider`,description:`A line between sections`},image:{label:`Image`,description:`Upload a picture`},file:{label:`File`,description:`Attach a file to download`},math:{label:`Math block`,description:`A formula on its own line (LaTeX)`},mathInline:{label:`Inline math`,description:`A formula inside the text (LaTeX)`},mermaid:{label:`Mermaid diagram`,description:`Flowcharts and sequences from text`},drawio:{label:`Draw.io diagram`,description:`Draw a diagram with diagrams.net`},excalidraw:{label:`Excalidraw drawing`,description:`Sketch by hand`},toc:{label:`Table of contents`,description:`The page's headings, kept up to date`},pageLink:{label:`Link to page`,description:`Link another page (or type [[)`},toggle:{label:`Toggle`,description:`A heading that hides the blocks under it`},embed:{label:`Embed`,description:`A video, design or document from YouTube, Figma and more`},linkCard:{label:`Link card`,description:`A link with its page's title and picture`},syncedPage:{label:`Synced page`,description:`Show another page here, always up to date`},database:{label:`Database`,description:`Records in a table, board or calendar`},newPage:{label:`New page`,description:`Make a page and link it here`},today:{label:`Today`,description:`Insert today's date`},tomorrow:{label:`Tomorrow`,description:`Insert tomorrow's date`},yesterday:{label:`Yesterday`,description:`Insert yesterday's date`},now:{label:`Now`,description:`Insert the date and time`}},format:{bold:`Bold`,italic:`Italic`,strike:`Strikethrough`,code:`Inline code`,link:`Link`,linkPrompt:`Link address (leave empty to remove the link)`,comment:`Comment`,underline:`Underline`,color:`Colour`,textColor:`Text colour`,highlight:`Highlight`,noColor:`Default`,align:`Align`,alignLeft:`Align left`,alignCenter:`Align centre`,alignRight:`Align right`,math:`Inline math`,linkedPage:`Make a linked page`},colors:{gray:`Grey`,red:`Red`,orange:`Orange`,yellow:`Yellow`,green:`Green`,teal:`Teal`,blue:`Blue`,purple:`Purple`,pink:`Pink`},table:{toolbar:`Table`,dragRow:`Drag to move the row`,dragColumn:`Drag to move the column`,moveRowUp:`Move row up`,moveRowDown:`Move row down`,moveColumnLeft:`Move column left`,moveColumnRight:`Move column right`,addRowBefore:`Add row above`,addRowAfter:`Add row below`,addColumnBefore:`Add column left`,addColumnAfter:`Add column right`,deleteRow:`Delete row`,deleteColumn:`Delete column`,toggleHeaderRow:`Header row`,mergeCells:`Merge cells`,splitCell:`Split cell`,deleteTable:`Delete table`},blockMenu:{open:`Drag to move, click for actions`,turnInto:`Turn into`,moveUp:`Move up`,moveDown:`Move down`,duplicate:`Duplicate`,copy:`Copy`,delete:`Delete`,showLineNumbers:`Show line numbers`,hideLineNumbers:`Hide line numbers`,showPages:`Show pages`,showAsFile:`Show as file`},mentions:`Mention someone`,noPeople:`Nobody found`,pageLinks:`Link to a page`,noPages:`No pages found`,blocks:{edit:`Edit`,done:`Done`,cancel:`Cancel`,save:`Save`,remove:`Remove`,saving:`Saving…`,latex:`LaTeX formula`,mermaid:`Mermaid diagram source`,mermaidError:`This diagram has an error:`,emptyDrawio:`Empty diagram. Click to draw.`,emptyExcalidraw:`Empty drawing. Click to sketch.`,loadFailed:`The editor could not be loaded.`,toc:`Contents`,tocEmpty:`Add headings to the page to fill the table of contents.`,expand:`Show contents`,collapse:`Hide contents`,embed:`Embedded content`,embedUrl:`Address of the video, design or document`,embedInvalid:`This address can't be embedded.`,syncedPage:`Synced page`,syncedOpen:`Open`,syncedFold:`Fold`,syncedUnfold:`Unfold`,syncedLoading:`Loading the page…`,syncedDenied:`You can't open this page.`,syncedSelf:`A page can't show itself.`,linkUrl:`Address of the page to link`,copyBlockLink:`Copy link to this block`,calloutEmoji:`Change emoji`,calloutColor:`Change colour`,pdfLoading:`Loading PDF…`,pdfPage:`Page {n}`,transcribe:`Transcribe`,transcribeHint:`Add a summary and the transcript below, with AI`,transcribing:`Transcribing…`,transcribeFailed:`The recording could not be transcribed.`},find:{find:`Find in page`,replace:`Replace with`,previous:`Previous match`,next:`Next match`,replaceOne:`Replace`,replaceAll:`Replace all`,matchCase:`Match case`,close:`Close`,count:`{current} of {total}`,none:`No matches`},ai:{button:`Ask AI`,rewrite:`Improve writing`,summarize:`Summarise`,translate:`Translate`,continue:`Continue writing`,shorter:`Make shorter`,longer:`Make longer`,fix:`Fix spelling and grammar`,custom:`Ask AI to…`,customPlaceholder:`Tell AI what to do with the selection`,language:`Language`,run:`Go`,working:`Writing…`,replace:`Replace selection`,insertBelow:`Insert below`,discard:`Discard`,stop:`Stop`,retry:`Try again`,failed:`AI could not finish this.`},dates:{today:`Today`,tomorrow:`Tomorrow`,yesterday:`Yesterday`,nextWeek:`Next week`,remindWord:`remind`,remindMe:`Remind me`,reminderAt:`Reminder at 9:00 on the day`,someoneElse:`Someone else set a reminder on this date.`,edit:`Change date`,openJournal:`Open journal`},database:wR,edgeless:MR},PR=[`title`,`text`,`number`,`checkbox`,`select`,`multiSelect`,`date`,`progress`,`link`,`attachment`,`member`,`createdTime`,`createdBy`,`relation`,`rollup`],FR=PR.filter(e=>e!==`title`),IR=[`table`,`kanban`,`calendar`];function LR(){let e=new Uint8Array(6);return crypto.getRandomValues(e),[...e].map(e=>e.toString(36).padStart(2,`0`)).join(``).slice(0,10)}function RR(e,t,n){let r=n.find(e=>zR.includes(e.type)),i=n.find(e=>e.type===`date`||e.type===`createdTime`);return{id:LR(),name:t,type:e,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:e===`kanban`?r?.id??null:null,dateColumn:e===`calendar`?i?.id??null:null,widths:{}}}var zR=[`select`,`multiSelect`,`checkbox`,`member`,`createdBy`];function BR(e){let t=UR(e)?e:{},n=(Array.isArray(t.columns)?t.columns:[]).flatMap(e=>{if(!UR(e)||typeof e.id!=`string`||!e.id)return[];let t=PR.includes(String(e.type))?e.type:`text`,n={id:e.id,name:typeof e.name==`string`?e.name:``,type:t};Array.isArray(e.options)&&(n.options=e.options.flatMap(VR));let r=t===`relation`?fz(e.relation):void 0;r&&(n.relation=r);let i=t===`rollup`?pz(e.rollup):void 0;return i&&(n.rollup=i),[n]});n.some(e=>e.type===`title`)||n.unshift({id:LR(),name:``,type:`title`});let r=(Array.isArray(t.rows)?t.rows:[]).flatMap(e=>{if(!UR(e)||typeof e.id!=`string`||!e.id)return[];let t={id:e.id,cells:UR(e.cells)?{...e.cells}:{},createdAt:typeof e.createdAt==`number`?e.createdAt:0,createdBy:HR(e.createdBy)};return Array.isArray(e.body)&&e.body.length&&(t.body=e.body,t.hasBody=!0),[t]}),i=new Set(n.map(e=>e.id)),a=(Array.isArray(t.views)?t.views:[]).flatMap(e=>{if(!UR(e)||typeof e.id!=`string`||!e.id)return[];let t=IR.includes(String(e.type))?e.type:`table`;return[{id:e.id,name:typeof e.name==`string`?e.name:``,type:t,hidden:Array.isArray(e.hidden)?e.hidden.filter(e=>typeof e==`string`):[],filters:Array.isArray(e.filters)?e.filters.filter(e=>UR(e)&&typeof e.column==`string`&&typeof e.op==`string`):[],filterMode:e.filterMode===`or`?`or`:`and`,sorts:Array.isArray(e.sorts)?e.sorts.flatMap(e=>UR(e)&&typeof e.column==`string`?[{column:e.column,desc:!!e.desc}]:[]):[],groupBy:typeof e.groupBy==`string`&&i.has(e.groupBy)?e.groupBy:null,dateColumn:typeof e.dateColumn==`string`&&i.has(e.dateColumn)?e.dateColumn:null,widths:UR(e.widths)?Object.fromEntries(Object.entries(e.widths).filter(e=>typeof e[1]==`number`)):{}}]});return{title:typeof t.title==`string`?t.title:``,columns:n,rows:r,views:a}}function VR(e){return!UR(e)||typeof e.id!=`string`?[]:[{id:e.id,name:typeof e.name==`string`?e.name:``,color:LP(e.color)?e.color:`gray`}]}function HR(e){return UR(e)&&typeof e.id==`string`?{id:e.id,name:typeof e.name==`string`?e.name:``}:null}function UR(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function WR(e){return e.columns.find(e=>e.type===`title`)??e.columns[0]}function GR(e,t){return t.type===`createdTime`?e.createdAt||null:t.type===`createdBy`?e.createdBy?[e.createdBy]:[]:t.type===`rollup`?e.computed?.[t.id]?.value??null:e.cells[t.id]}function KR(e){return e==null||e===``||e===!1||Array.isArray(e)&&e.length===0}function qR(e){return typeof e==`number`&&e>0?JR(new Date(e)):typeof e==`string`&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function JR(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function YR(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e.trim().replace(`,`,`.`));return Number.isFinite(t)?t:null}return null}function XR(e){return Array.isArray(e)?e:[]}function ZR(e,t){let n=GR(e,t);switch(t.type){case`title`:case`text`:case`link`:return typeof n==`string`?n:``;case`number`:case`progress`:{let e=YR(n);return e===null?``:String(e)}case`checkbox`:return n===!0?`true`:`false`;case`select`:return t.options?.find(e=>e.id===n)?.name??``;case`multiSelect`:return XR(n).map(e=>t.options?.find(t=>t.id===e)?.name).filter(e=>!!e).join(`, `);case`date`:case`createdTime`:return qR(n);case`attachment`:return XR(n).map(e=>e?.name??``).join(`, `);case`member`:case`createdBy`:return XR(n).map(e=>e?.name??``).join(`, `);case`relation`:case`rollup`:return e.computed?.[t.id]?.text??``}}function QR(e){switch(e){case`number`:case`progress`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`isEmpty`,`isNotEmpty`];case`checkbox`:return[`checked`,`unchecked`];case`select`:return[`is`,`isNot`,`isEmpty`,`isNotEmpty`];case`multiSelect`:case`member`:case`createdBy`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`date`:case`createdTime`:return[`is`,`before`,`after`,`isEmpty`,`isNotEmpty`];case`attachment`:return[`isEmpty`,`isNotEmpty`];case`relation`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`rollup`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`contains`,`isEmpty`,`isNotEmpty`];default:return[`contains`,`notContains`,`is`,`isNot`,`isEmpty`,`isNotEmpty`]}}var $R=e=>![`isEmpty`,`isNotEmpty`,`checked`,`unchecked`].includes(e);function ez(e,t,n){let r=GR(e,t);if(t.type===`relation`){let e=hz(r).length===0;if(n.op===`isEmpty`)return e;if(n.op===`isNotEmpty`)return!e}if(n.op===`isEmpty`)return KR(r)||ZR(e,t)===``;if(n.op===`isNotEmpty`)return!(KR(r)||ZR(e,t)===``);if(n.op===`checked`)return r===!0;if(n.op===`unchecked`)return r!==!0;if(n.value===void 0||n.value===null||n.value===``)return!0;switch(t.type===`rollup`&&(typeof r==`number`||r===null)&&[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`].includes(n.op)?`number`:t.type){case`number`:case`progress`:{let e=YR(r),t=YR(n.value);return t===null?!0:e===null?n.op===`isNot`:{is:e===t,isNot:e!==t,gt:e>t,lt:e=t,lte:e<=t}[n.op]}case`select`:return n.op===`is`?r===n.value:r!==n.value;case`multiSelect`:{let e=XR(r).includes(String(n.value));return n.op===`notContains`?!e:e}case`member`:case`createdBy`:{let e=String(n.value).toLowerCase(),t=XR(r).some(t=>t?.id===n.value||t?.name?.toLowerCase().includes(e));return n.op===`notContains`?!t:t}case`date`:case`createdTime`:{let e=qR(r),t=qR(n.value);return e?n.op===`before`?et:e===t:!1}default:{let r=ZR(e,t).toLowerCase(),i=String(n.value).toLowerCase();switch(n.op){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`is`:return r===i;case`isNot`:return r!==i;default:return!0}}}}function tz(e,t,n){let r=ZR(e,n)===``&&n.type!==`checkbox`,i=ZR(t,n)===``&&n.type!==`checkbox`;if(r||i)return r===i?0:r?1:-1;switch(n.type){case`number`:case`progress`:return(YR(GR(e,n))??0)-(YR(GR(t,n))??0);case`checkbox`:return Number(GR(e,n)===!0)-Number(GR(t,n)===!0);case`createdTime`:return e.createdAt-t.createdAt;case`rollup`:{let r=GR(e,n),i=GR(t,n);return typeof r==`number`&&typeof i==`number`?r-i:ZR(e,n).localeCompare(ZR(t,n),void 0,{numeric:!0,sensitivity:`base`})}case`select`:{let r=e=>n.options?.findIndex(t=>t.id===GR(e,n))??-1;return r(e)-r(t)}default:return ZR(e,n).localeCompare(ZR(t,n),void 0,{numeric:!0,sensitivity:`base`})}}function nz(e,t,n=``){let r=new Map(e.columns.map(e=>[e.id,e])),i=t.filters.flatMap(e=>{let t=r.get(e.column);return t?[{f:e,col:t}]:[]}),a=n.trim().toLowerCase(),o=e.rows.filter(n=>{if(i.length){let e=({f:e,col:t})=>ez(n,t,e);if(t.filterMode===`or`?!i.some(e):!i.every(e))return!1}return!a||e.columns.some(e=>ZR(n,e).toLowerCase().includes(a))}),s=t.sorts.flatMap(e=>{let t=r.get(e.column);return t?[{col:t,desc:e.desc}]:[]});return s.length&&(o=o.map((e,t)=>({r:e,i:t})).sort((e,t)=>{for(let n of s){let r=tz(e.r,t.r,n.col);if(r!==0){let i=ZR(e.r,n.col)===``||ZR(t.r,n.col)===``;return n.desc&&!(i&&n.col.type!==`checkbox`)?-r:r}}return e.i-t.i}).map(e=>e.r)),o}function rz(e,t){return e.columns.filter(e=>e.type===`title`||!t.hidden.includes(e.id))}function iz(e,t,n,r,i){let a=new Map,o=(e,t,n)=>(a.has(e)||a.set(e,{key:e,label:t,color:n,rows:[]}),a.get(e));if(t.type===`checkbox`)o(`false`,i),o(`true`,r);else{o(``,n);for(let e of t.options??[])o(e.id,e.name,e.color)}for(let n of e)for(let e of oz(n,t))(a.get(e)??o(e,az(n,t,e)||e)).rows.push(n);return[...a.values()]}function az(e,t,n){return XR(GR(e,t)).find(e=>e?.id===n)?.name??``}function oz(e,t){let n=GR(e,t);switch(t.type){case`checkbox`:return[n===!0?`true`:`false`];case`select`:return[typeof n==`string`&&t.options?.some(e=>e.id===n)?n:``];case`multiSelect`:{let e=XR(n).filter(e=>t.options?.some(t=>t.id===e));return e.length?e:[``]}case`member`:case`createdBy`:{let e=XR(n).flatMap(e=>e?.id?[e.id]:[]);return e.length?e:[``]}default:return[``]}}function sz(e,t,n,r,i=[]){let a=GR(e,t);switch(t.type){case`checkbox`:return r===`true`;case`select`:return r||null;case`multiSelect`:{let e=XR(a).filter(e=>e!==n&&e!==r);return r?[...e,r]:e}case`member`:{let e=XR(a).filter(e=>e?.id!==n&&e?.id!==r),t=i.find(e=>e.id===r)??XR(a).find(e=>e?.id===r);return r&&t?[...e,t]:e}default:return a}}function cz(e){let t=IP.filter(e=>e!==`gray`);return t[e.length%t.length]}function lz(e,t,n,r){if(t.type===n)return{value:e,options:r};let i=ZR({id:``,cells:{[t.id]:e},createdAt:0,createdBy:null},t),a=e=>{let t=e.trim();if(!t)return null;let n=r.find(e=>e.name.toLowerCase()===t.toLowerCase());return n||(n={id:LR(),name:t,color:cz(r)},r=[...r,n]),n.id};switch(n){case`title`:case`text`:case`link`:return{value:i||null,options:r};case`number`:return{value:YR(i),options:r};case`progress`:{let e=YR(i);return{value:e===null?null:Math.max(0,Math.min(100,Math.round(e))),options:r}}case`checkbox`:return{value:[`true`,`yes`,`1`,`x`,`✓`,`done`].includes(i.trim().toLowerCase()),options:r};case`select`:return{value:a(i.split(`,`)[0]??``),options:r};case`multiSelect`:{let e=i.split(`,`).flatMap(e=>{let t=a(e);return t?[t]:[]});return{value:[...new Set(e)],options:r}}case`date`:return{value:qR(i)||null,options:r};case`member`:return{value:t.type===`member`||t.type===`createdBy`?e:[],options:r};default:return{value:null,options:r}}}function uz(e,t,n=1){let r=(new Date(e,t,1).getDay()-n+7)%7,i=new Date(e,t,1-r),a=new Date(e,t+1,0).getDate(),o=Math.ceil((r+a)/7);return Array.from({length:o*7},(e,t)=>JR(new Date(i.getFullYear(),i.getMonth(),i.getDate()+t)))}var dz=[`showOriginal`,`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`,`sum`,`average`,`median`,`min`,`max`,`range`,`earliest`,`latest`,`checked`,`percentChecked`];function fz(e){if(UR(e)&&typeof e.database==`string`&&e.database)return{page:typeof e.page==`string`?e.page:``,database:e.database}}function pz(e){if(!UR(e)||typeof e.relation!=`string`)return;let t=dz.includes(String(e.fn))?e.fn:`count`;return{relation:e.relation,property:typeof e.property==`string`?e.property:``,fn:t}}function mz(e){let t=[`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`];switch(e){case`number`:case`progress`:return[`sum`,`average`,`median`,`min`,`max`,`range`,...t,`showOriginal`];case`date`:case`createdTime`:return[`earliest`,`latest`,`range`,...t,`showOriginal`];case`checkbox`:return[`checked`,`percentChecked`,`count`,`showOriginal`];default:return[`showOriginal`,...t]}}var hz=e=>XR(e).filter(e=>typeof e==`string`&&!!e),gz=e=>String(Number.isInteger(e)?e:Math.round(e*100)/100),_z=(e,t)=>Math.round((Date.parse(t)-Date.parse(e))/864e5);function vz(e,t,n,r){let i=t.map(e=>n?GR(e,n):e.id),a=t.map(e=>n?ZR(e,n):``),o=a.filter((e,t)=>n?.type===`checkbox`?i[t]===!0:e!==``),s=n?i.map(YR).filter(e=>e!==null):[],c=n?i.map(qR).filter(Boolean).sort():[],l=e=>({text:e===null?``:gz(e),value:e});switch(e){case`count`:return l(t.length);case`countValues`:return l(o.length);case`countUnique`:return l(new Set(o).size);case`countEmpty`:return l(t.length-o.length);case`countNotEmpty`:return l(o.length);case`percentNotEmpty`:return t.length?{text:`${gz(o.length/t.length*100)}%`,value:o.length/t.length*100}:l(null);case`sum`:return l(s.length?s.reduce((e,t)=>e+t,0):null);case`average`:return l(s.length?s.reduce((e,t)=>e+t,0)/s.length:null);case`median`:{if(!s.length)return l(null);let e=[...s].sort((e,t)=>e-t),t=Math.floor(e.length/2);return l(e.length%2?e[t]:(e[t-1]+e[t])/2)}case`min`:return l(s.length?Math.min(...s):null);case`max`:return l(s.length?Math.max(...s):null);case`range`:if(n&&(n.type===`date`||n.type===`createdTime`)){if(!c.length)return l(null);let e=_z(c[0],c[c.length-1]);return{text:r.rollupDays.replace(`{n}`,String(e)),value:e}}return l(s.length?Math.max(...s)-Math.min(...s):null);case`earliest`:return{text:c[0]??``,value:c[0]??null};case`latest`:return{text:c[c.length-1]??``,value:c[c.length-1]??null};case`checked`:return l(i.filter(e=>e===!0).length);case`percentChecked`:return t.length?{text:`${gz(i.filter(e=>e===!0).length/t.length*100)}%`,value:i.filter(e=>e===!0).length/t.length*100}:l(null);case`showOriginal`:{let e=a.filter(Boolean);return{text:e.join(`, `),value:e}}}}function yz(e,t,n){let r=e.columns.filter(e=>e.type===`relation`&&e.relation),i=e.columns.filter(e=>e.type===`rollup`&&e.rollup);if(!r.length&&!i.length)return e;let a=new Map;for(let e of r)a.set(e.id,t(e.relation));let o=e.rows.map(e=>{let t={};for(let i of r){let r=hz(e.cells[i.id]),o=a.get(i.id);if(!o){t[i.id]={text:r.length?n.linkedCount.replace(`{n}`,String(r.length)):``,value:r};continue}let s=o.columns.find(e=>e.type===`title`),c=new Map(o.rows.map(e=>[e.id,e])),l=r.flatMap(e=>{let t=c.get(e);return t?[{id:e,title:s?ZR(t,s):``}]:[]});t[i.id]={text:l.map(e=>e.title).join(`, `),value:r,links:l}}for(let o of i){let i=o.rollup,s=r.find(e=>e.id===i.relation),c=s?a.get(s.id):null;if(!s||!c){t[o.id]={text:``,value:null};continue}let l=new Map(c.rows.map(e=>[e.id,e])),u=hz(e.cells[s.id]).flatMap(e=>{let t=l.get(e);return t?[t]:[]}),d=i.property?c.columns.find(e=>e.id===i.property)??null:c.columns.find(e=>e.type===`title`)??null;t[o.id]=vz(i.fn,u,d,n)}return{...e,computed:t}});return{...e,rows:o}}function I(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))if(n!=null&&n!==!1){if(e===`class`)r.className=String(n);else if(e===`on`)for(let[e,t]of Object.entries(n))r.addEventListener(e,t);else e===`dataset`?Object.assign(r.dataset,n):e===`style`?Object.assign(r.style,n):e in r&&typeof n!=`string`?r[e]=n:r.setAttribute(e,n===!0?``:String(n))}for(let e of n.flat())e!=null&&e!==!1&&r.append(e);return r}function bz(e,t=16){return Hj(e,t)}function xz(e,t,n,r){let i=I(`button`,{type:`button`,class:r?`dw-db__btn`:`dw-db__btn dw-db__btn--icon`,title:t,"aria-label":t},bz(e,15),r?I(`span`,{},r):null);return i.addEventListener(`click`,e=>{e.preventDefault(),n(e)}),i}var Sz=null;function Cz(e,t,n={}){Sz?.close();let r=I(`div`,{class:`dw-db-pop ${n.class??``}`,role:`dialog`,"aria-label":n.label}),i=!1,a=()=>{i||(i=!0,c(),r.remove(),document.removeEventListener(`mousedown`,o,!0),document.removeEventListener(`keydown`,s,!0),Sz?.box===r&&(Sz=null),n.onClose?.())},o=t=>{let n=t.target;r.contains(n)||e.contains(n)||n instanceof Element&&n.closest(`.dw-block-menu`)||a()},s=t=>{t.key===`Escape`&&!document.querySelector(`.dw-block-menu`)&&(t.preventDefault(),t.stopPropagation(),a(),e instanceof HTMLElement&&e.focus())};document.body.append(r);let c=jj(e,r,()=>{Fj(e,r,{placement:n.placement??`bottom-start`,strategy:`fixed`,middleware:[Mj(4),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(r.style,{left:`${e}px`,top:`${t}px`}))});return document.addEventListener(`mousedown`,o,!0),document.addEventListener(`keydown`,s,!0),t(r,a),Sz={box:r,close:a},Sz}function wz(){Sz?.close()}function Tz(e,t){let n=I(`input`,{type:t.type??`text`,class:t.class??`dw-db-input`,placeholder:t.placeholder,"aria-label":t.label??t.placeholder});n.value=e;let r=!1,i=()=>{r||(r=!0,t.onCommit(n.value))};return n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(r=!0,t.onCancel?.())}),n.addEventListener(`blur`,i),n}function Ez(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=I(`a`,{href:r,download:e});document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function Dz(e){return new Promise(t=>{let n=I(`input`,{type:`file`,accept:e});n.onchange=()=>t(n.files?.[0]??null),n.click()})}var Oz=e=>`fn${e[0].toUpperCase()}${e.slice(1)}`,kz=(e,t)=>e[Oz(t)];function Az(e,t,n,r){let i=I(`div`,{class:`dw-db-pop__item${t?` is-active`:``}`,role:`option`,"aria-selected":String(t)},I(`span`,{},e),r?I(`small`,{class:`dw-db-pop__sub`},r):null);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,n),i}function jz(e,t,n,r){let i=e.store,a=e.linked;if(!i||!a)return;let o=e.labels;Cz(t,(e,t)=>{let r=e=>{i.setRelation(n.id,{page:e.page,database:e.database}),t()},s=n.relation,c=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});if((()=>{let e=a.local();c.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},o.relationThisPage),...e.length?e.map(e=>Az(e.title||o.untitled,!!s&&!s.page&&s.database===e.database,()=>r(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})(),e.append(I(`div`,{class:`dw-db-pop__title`},o.relationPick),c),a.searchPages&&a.databasesOn){let t=I(`input`,{class:`dw-db-input`,placeholder:o.relationSearchPage,"aria-label":o.relationOtherPage}),n=I(`div`,{class:`dw-db-pop__list`,role:`listbox`}),i=0;t.addEventListener(`input`,async()=>{let e=t.value.trim(),c=++i;if(!e)return n.replaceChildren();let l=await a.searchPages(e).catch(()=>[]);c===i&&n.replaceChildren(...l.slice(0,8).map(e=>Az(e.title||o.untitled,!1,async()=>{let t=await a.databasesOn(e.id).catch(()=>[]);c===i&&n.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},e.title||o.untitled),...t.length?t.map(e=>Az(e.title||o.untitled,s?.page===e.page&&s.database===e.database,()=>r(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})))}),t.addEventListener(`keydown`,e=>e.stopPropagation()),e.append(I(`div`,{class:`dw-db-pop__heading`},o.relationOtherPage),t,n)}},{class:`dw-db-pop--choices`,label:o.relationTo,onClose:r})}function Mz(e,t,n,r,i){let a=e.store,o=e.labels,s=r.relation,c=s?e.linked?.read(s):null;if(!s||!c){if(t.append(I(`div`,{class:`dw-db-pop__empty`},s?o.relationMissing:o.relationPick)),!s&&e.linked){let n=I(`button`,{type:`button`,class:`dw-db__btn`},o.relationTo);n.addEventListener(`click`,()=>{i(),jz(e,t,r)}),t.append(n)}return}let l=WR(c),u=hz(n.cells[r.id]),d=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),f=I(`input`,{class:`dw-db-input`,placeholder:o.searchRecords,"aria-label":o.linkRecord}),p=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(d,f,p);let m=e=>ZR(e,l)||o.untitledRow,h=()=>a.setCell(n.id,r.id,u.length?u:null),g=e=>{u=u.includes(e)?u.filter(t=>t!==e):[...u,e],h(),y()},_=0,v=[],y=()=>{let e=new Map(c.rows.map(e=>[e.id,e]));d.replaceChildren(...u.flatMap(t=>{let n=e.get(t);if(!n)return[];let r=I(`span`,{class:`dw-db-tag`,dataset:{color:`gray`}},m(n)),i=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,()=>g(t)),r.append(i),[r]}));let t=f.value.trim().toLowerCase();v=c.rows.filter(e=>!t||m(e).toLowerCase().includes(t)).slice(0,50),_=Math.min(_,Math.max(0,v.length-1)),p.replaceChildren(...v.length?v.map((e,t)=>{let n=Az(m(e),t===_,()=>g(e.id));return u.includes(e.id)&&n.prepend(I(`span`,{class:`dw-db-pop__check`},`✓`)),n}):[I(`div`,{class:`dw-db-pop__empty`},o.noRecords)])};f.addEventListener(`input`,()=>{_=0,y()}),f.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),v.length&&(_=(_+(e.key===`ArrowDown`?1:-1)+v.length)%v.length),y();else if(e.key===`Enter`){e.preventDefault();let t=v[_];t&&g(t.id)}else e.key===`Escape`&&(e.preventDefault(),i())}),y(),f.focus({preventScroll:!0})}function Nz(e,t,n,r){let i=e.store;if(!i)return;let a=e.labels;Cz(t,t=>{let r=e.db.columns.filter(e=>e.type===`relation`);if(!r.length){t.append(I(`div`,{class:`dw-db-pop__empty`},a.rollupNeedsRelation));return}let o=n.rollup??{relation:r[0].id,property:``,fn:`count`},s=(e,t,n,r)=>{let i=I(`select`,{class:`dw-db-input`,"aria-label":e});for(let[e,n]of t)i.append(I(`option`,{value:e},n));return i.value=n,i.addEventListener(`change`,()=>r(i.value)),I(`label`,{class:`dw-db-pop__field`},I(`span`,{},e),i)},c=()=>{let l=r.find(e=>e.id===o.relation)??r[0],u=l.relation?e.linked?.read(l.relation):null,d=[[``,a.rollupRecords]];for(let e of u?.columns??[])d.push([e.id,e.name||ER(a,e.type)]);let f=u?.columns.find(e=>e.id===o.property),p=mz(f?f.type:``);p.includes(o.fn)||(o.fn=o.property?p[0]:`count`),t.replaceChildren(s(a.rollupRelation,r.map(e=>[e.id,e.name||a.typeRelation]),l.id,e=>{o.relation=e,o.property=``,o.fn=`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupProperty,d,o.property,e=>{o.property=e;let t=u?.columns.find(t=>t.id===e);o.fn=e?mz(t?t.type:``)[0]:`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupFn,(o.property?p:[`count`,`showOriginal`]).map(e=>[e,kz(a,e)]),o.fn,e=>{o.fn=e,i.setRollup(n.id,{...o})}),u?I(`span`):I(`div`,{class:`dw-db-pop__empty`},a.relationMissing))};n.rollup||i.setRollup(n.id,{...o}),c()},{class:`dw-db-pop--choices`,label:a.rollupSettings,onClose:r})}function Pz(e,t,n){let r=t.computed?.[n.id],i=I(`span`,{class:`dw-db-tags`});if(r?.links&&n.relation){let t=n.relation;for(let n of r.links){let r=I(`button`,{type:`button`,class:`dw-db-tag dw-db-rel`,dataset:{color:`gray`},title:e.labels.openRelated},n.title||e.labels.untitledRow);r.addEventListener(`click`,r=>{r.stopPropagation(),e.linked?.openRecord(t,n.id)}),i.append(r)}}else r?.text&&i.append(I(`span`,{class:`dw-db-cell__text`},r.text));return i}var Fz={title:`text`,text:`type`,number:`sigma`,checkbox:`todo`,select:`tag`,multiSelect:`layers`,date:`calendar`,progress:`sliders`,link:`link`,attachment:`paperclip`,member:`users`,createdTime:`clock`,createdBy:`at`,relation:`relation`,rollup:`rollup`},Iz=[`title`,`text`,`number`,`link`],Lz=[`createdTime`,`createdBy`,`rollup`];function Rz(e,t){let[n,r,i]=e.split(`-`).map(Number);return!n||!r||!i?e:new Date(n,r-1,i).toLocaleDateString(t,{year:`numeric`,month:`short`,day:`numeric`})}function zz(e,t,n){let r=I(`span`,{class:`dw-db-tag`,dataset:{color:t??`gray`}},e);if(n){let e=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r.append(e)}return r}function Bz(e){try{let t=new URL(e.includes(`://`)?e:`https://${e}`);return t.protocol===`http:`||t.protocol===`https:`||t.protocol===`mailto:`?t.href:null}catch{return null}}function Vz(e,t,n){let r=GR(t,n),i=e.labels;switch(n.type){case`title`:{let e=typeof r==`string`?r:``;return I(`span`,{class:e?`dw-db-cell__title`:`dw-db-cell__title is-empty`},e||i.untitledRow)}case`text`:return I(`span`,{class:`dw-db-cell__text`},typeof r==`string`?r:``);case`number`:{let t=YR(r);return I(`span`,{class:`dw-db-cell__number`},t===null?``:t.toLocaleString(e.locale))}case`checkbox`:return I(`span`,{class:r===!0?`dw-db-check is-on`:`dw-db-check`,role:`img`,"aria-label":r===!0?i.checked:i.unchecked},r===!0?bz(`check`,13):null);case`select`:{let e=n.options?.find(e=>e.id===r);return I(`span`,{class:`dw-db-tags`},e?zz(e.name,e.color):null)}case`multiSelect`:return I(`span`,{class:`dw-db-tags`},XR(r).flatMap(e=>{let t=n.options?.find(t=>t.id===e);return t?[zz(t.name,t.color)]:[]}));case`date`:case`createdTime`:{let t=qR(r);return I(`span`,{class:`dw-db-cell__text`},t?Rz(t,e.locale):``)}case`progress`:{let e=YR(r);if(e===null)return I(`span`);let t=Math.max(0,Math.min(100,e));return I(`span`,{class:`dw-db-progress`},I(`span`,{class:`dw-db-progress__bar`},I(`span`,{class:`dw-db-progress__fill`,style:{width:`${t}%`}})),I(`span`,{class:`dw-db-progress__num`},`${t}%`))}case`link`:{let e=typeof r==`string`?r:``,t=e?Bz(e):null;if(!t)return I(`span`,{class:`dw-db-cell__text`},e);let n=I(`a`,{class:`dw-db-cell__link`,href:t,target:`_blank`,rel:`noopener noreferrer`},e);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}case`attachment`:return I(`span`,{class:`dw-db-tags`},XR(r).map(t=>{let n=I(`a`,{class:`dw-db-file`,href:e.files?e.files.resolve(t.src):t.src,target:`_blank`,rel:`noopener noreferrer`},bz(`paperclip`,12),t.name);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}));case`member`:case`createdBy`:return I(`span`,{class:`dw-db-tags`},XR(r).map(e=>I(`span`,{class:`dw-db-person`},I(`span`,{class:`dw-db-person__dot`},(e?.name||`?`).slice(0,1).toUpperCase()),e?.name??``)));case`relation`:return Pz(e,t,n);case`rollup`:{let r=t.computed?.[n.id],i=r?.value;return typeof i==`number`?I(`span`,{class:`dw-db-cell__number`},/^-?\d+(\.\d+)?%?$/.test(r.text)?i.toLocaleString(e.locale,{maximumFractionDigits:2})+(r.text.endsWith(`%`)?`%`:``):r.text):I(`span`,{class:`dw-db-cell__text`},r?.text??``)}}}function Hz(e,t,n,r,i){let a=e.store;if(!a||Lz.includes(r.type))return i.onDone();let o=GR(n,r);if(r.type===`checkbox`)return a.setCell(n.id,r.id,o!==!0),i.onDone();e.setEditing(!0);let s=t=>{e.setEditing(!1),i.onDone(t)};if(Iz.includes(r.type)){let e=i.initial??(r.type===`number`?YR(o)?.toString()??``:typeof o==`string`?o:``),c,l=Tz(e,{class:`dw-db-cell__input`,type:(r.type,`text`),label:r.name,onCommit:e=>{let t=e.trim(),i=r.type===`number`?YR(t):r.type===`title`||r.type===`text`?e:t;i!==(o??null)&&(i!==``||o!==void 0)&&a.setCell(n.id,r.id,i),s(c)},onCancel:()=>s()});l.addEventListener(`keydown`,e=>{e.key===`Enter`&&(c=`down`),e.key===`Tab`&&(e.preventDefault(),c=e.shiftKey?`left`:`right`,l.blur())}),t.replaceChildren(l),t.classList.add(`is-editing`),l.focus(),i.initial===void 0?l.select():l.setSelectionRange(l.value.length,l.value.length);return}let c=(e,n=``)=>Cz(t,e,{class:n,onClose:()=>s(),label:r.name});switch(r.type){case`select`:case`multiSelect`:c((t,a)=>Uz(e,t,n,r,a,i.initial),`dw-db-pop--choices`);break;case`date`:c((t,i)=>{let s=I(`input`,{type:`date`,class:`dw-db-input`,"aria-label":r.name});s.value=qR(o),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,s.value||null)),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&i()});let c=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.clear);c.addEventListener(`click`,()=>{a.setCell(n.id,r.id,null),i()});let l=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.today);l.addEventListener(`click`,()=>{let e=new Date;a.setCell(n.id,r.id,`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`),i()}),t.append(s,I(`div`,{class:`dw-db-pop__row`},l,c)),s.focus({preventScroll:!0})});break;case`progress`:c((e,t)=>{let i=YR(o)??0,s=I(`input`,{type:`range`,min:`0`,max:`100`,step:`1`,class:`dw-db-range`,"aria-label":r.name});s.value=String(i);let c=I(`span`,{class:`dw-db-progress__num`},`${i}%`);s.addEventListener(`input`,()=>c.textContent=`${s.value}%`),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,Number(s.value))),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&t()}),e.append(I(`div`,{class:`dw-db-pop__row`},s,c)),s.focus({preventScroll:!0})});break;case`member`:c((t,i)=>Wz(e,t,n,r,i),`dw-db-pop--choices`);break;case`attachment`:c(t=>Gz(e,t,n,r),`dw-db-pop--choices`);break;case`relation`:c((t,i)=>Mz(e,t,n,r,i),`dw-db-pop--choices`);break;default:s()}}function Uz(e,t,n,r,i,a){let o=e.store,s=e.labels,c=r.type===`multiSelect`,l=[...r.options??[]],u=c?XR(GR(n,r)):[String(GR(n,r)??``)].filter(Boolean),d=0,f=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),p=I(`input`,{class:`dw-db-input`,placeholder:s.searchOptions,"aria-label":s.searchOptions});p.value=a??``;let m=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(f,p,m);let h=()=>o.setCell(n.id,r.id,c?u:u[0]??null),g=e=>{u=c?u.includes(e)?u.filter(t=>t!==e):[...u,e]:u[0]===e?[]:[e],h(),c?b():i()},_=e=>{let t={id:LR(),name:e,color:cz(l)};l=[...l,t],o.tx(()=>{o.setOptions(r.id,l),u=c?[...u,t.id]:[t.id],h()}),p.value=``,c?b():i()},v=(t,n)=>{Jj(t,[{id:`rename`,label:s.renameOption,icon:`pencil`,run:()=>{let e=window.prompt(s.renameOption,n.name)?.trim();e&&(l=l.map(t=>t.id===n.id?{...t,name:e}:t),o.setOptions(r.id,l),b())}},{id:`color`,label:s.optionColor,icon:`palette`,children:IP.map(t=>({id:t,label:e.colorNames[t]??t,icon:t===n.color?`check`:`drop`,run:()=>{l=l.map(e=>e.id===n.id?{...e,color:t}:e),o.setOptions(r.id,l),b()}}))},{id:`delete`,label:s.deleteOption,icon:`trash`,danger:!0,run:()=>{l=l.filter(e=>e.id!==n.id),u=u.filter(e=>e!==n.id),o.setOptions(r.id,l),b()}}],s.optionColor,()=>p.focus())},y=[];function b(){f.replaceChildren(...u.flatMap(e=>{let t=l.find(t=>t.id===e);return t?[zz(t.name,t.color,()=>g(e))]:[]}));let e=p.value.trim();y=l.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())).map(e=>({kind:`option`,o:e})),e&&!l.some(t=>t.name.toLowerCase()===e.toLowerCase())&&y.push({kind:`create`,name:e}),d=Math.min(d,Math.max(0,y.length-1)),m.replaceChildren(...y.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===d?` is-active`:``}`,role:`option`,"aria-selected":String(e.kind===`option`&&u.includes(e.o.id))});if(n.addEventListener(`mousedown`,e=>e.preventDefault()),e.kind===`option`){n.append(I(`span`,{class:`dw-db-pop__check`},u.includes(e.o.id)?bz(`check`,13):null),zz(e.o.name,e.o.color));let t=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon dw-db-pop__more`,"aria-label":s.optionColor},bz(`more`,14));t.addEventListener(`click`,n=>{n.stopPropagation(),v(t,e.o)}),n.append(t),n.addEventListener(`click`,()=>g(e.o.id))}else n.append(I(`span`,{class:`dw-db-pop__check`},bz(`plus`,13)),I(`span`,{},AR(s.createOption,e.name))),n.addEventListener(`click`,()=>_(e.name));return n}))}p.addEventListener(`input`,()=>{d=0,b()}),p.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(d=(d+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[d];t?.kind===`option`?g(t.o.id):t?.kind===`create`?_(t.name):i()}else e.key===`Backspace`&&!p.value&&c&&u.length&&g(u[u.length-1])}),b(),p.focus({preventScroll:!0}),p.setSelectionRange(p.value.length,p.value.length)}function Wz(e,t,n,r,i){let a=e.store,o=e.labels,s=XR(GR(n,r)).filter(e=>e?.id),c=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),l=I(`input`,{class:`dw-db-input`,placeholder:o.searchPeople,"aria-label":o.searchPeople}),u=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(c,l,u);let d=()=>a.setCell(n.id,r.id,s),f=()=>c.replaceChildren(...s.map(e=>zz(e.name,`gray`,()=>{s=s.filter(t=>t.id!==e.id),d(),f()}))),p=0,m=[],h=0,g=()=>{u.replaceChildren(...m.length?m.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===h?` is-active`:``}`,role:`option`},I(`span`,{class:`dw-db-person__dot`},(e.name||`?`).slice(0,1).toUpperCase()),I(`span`,{},e.name));return n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>_(e)),n}):[I(`div`,{class:`dw-db-pop__empty`},l.value.trim()?o.noPeople:``)])},_=e=>{s.some(t=>t.id===e.id)||(s=[...s,e]),d(),l.value=``,m=[],f(),g()};l.addEventListener(`input`,async()=>{let t=l.value.trim(),n=++p,r=e.people&&t?await e.people.search(t).catch(()=>[]):[];n===p&&(m=r.slice(0,8).map(e=>({id:e.id,name:e.label})),h=0,g())}),l.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),m.length&&(h=(h+(e.key===`ArrowDown`?1:-1)+m.length)%m.length),g();else if(e.key===`Enter`){e.preventDefault();let t=m[h];t?_(t):i()}}),f(),g(),l.focus({preventScroll:!0})}function Gz(e,t,n,r){let i=e.store,a=e.labels,o=XR(GR(n,r)).filter(e=>e?.src),s=I(`div`,{class:`dw-db-pop__list`}),c=()=>s.replaceChildren(...o.map((t,s)=>{let l=e.files?e.files.resolve(t.src):t.src,u=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":a.remove,title:a.remove},bz(`trash`,14));return u.addEventListener(`click`,()=>{o=o.filter((e,t)=>t!==s),i.setCell(n.id,r.id,o),c()}),I(`div`,{class:`dw-db-pop__item`},I(`a`,{class:`dw-db-file`,href:l,target:`_blank`,rel:`noopener noreferrer`},bz(`paperclip`,12),t.name),u)}));t.append(s);let l=e.files?.upload;if(l){let s=I(`button`,{type:`button`,class:`dw-db__btn`},bz(`upload`,14),I(`span`,{},a.upload));s.addEventListener(`click`,()=>{let t=I(`input`,{type:`file`,multiple:!0});t.onchange=async()=>{for(let a of[...t.files??[]])try{let t=await l.call(e.files,a);o=[...o,{name:t.name,src:t.url,size:t.size,mime:t.mime}],i.setCell(n.id,r.id,o),c()}catch{}},t.click()}),t.append(I(`div`,{class:`dw-db-pop__row`},s))}c()}var Kz=class{host;db;rowId;order;onClose;dom;panel;head=I(`div`,{class:`dw-db-peek__head`});props=I(`div`,{class:`dw-db-peek__props`});bodyEl=I(`div`,{class:`dw-db-peek__body`});unmount=null;editing=0;pending=!1;wide=!1;returnFocus;constructor(e,t,n,r,i){this.host=e,this.db=t,this.rowId=n,this.order=r,this.onClose=i,this.returnFocus=document.activeElement,this.panel=I(`div`,{class:`dw-db-peek__panel`,role:`dialog`,"aria-modal":`true`,tabIndex:-1},this.head,this.props,this.bodyEl),this.dom=I(`div`,{class:e.page?`dw-db-peek dw-db-peek--page`:`dw-db-peek`},this.panel),this.dom.addEventListener(`mousedown`,e=>{e.target===this.dom&&!this.host.page&&this.close()}),this.dom.addEventListener(`keydown`,e=>{e.key===`Escape`&&!document.querySelector(`.dw-db-pop, .dw-block-menu`)&&(e.preventDefault(),e.stopPropagation(),this.close())}),e.page?(this.panel.removeAttribute(`aria-modal`),this.panel.setAttribute(`role`,`region`),e.page.container.replaceChildren(this.dom)):document.body.append(this.dom),this.draw(!0),this.panel.focus({preventScroll:!0})}get row(){return this.rowId}ctx(){return{...this.host.ctx,db:this.db,openRow:e=>this.show(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw(!1))}}}update(e,t){if(this.db=e,t&&(this.host={...this.host,ctx:{...this.host.ctx,...t}}),!e.rows.some(e=>e.id===this.rowId))return this.close();this.editing?this.pending=!0:this.draw(!1)}show(e){e!==this.rowId&&(this.rowId=e,this.draw(!0))}draw(e){let t=this.db.rows.find(e=>e.id===this.rowId);if(!t)return;let n=this.ctx(),r=n.labels,i=n.store;this.panel.classList.toggle(`is-wide`,this.wide);let a=this.order.indexOf(this.rowId),o=xz(`chevron-up`,r.previousRow,()=>this.show(this.order[a-1])),s=xz(`chevron-down`,r.nextRow,()=>this.show(this.order[a+1]));o.disabled=a<=0,s.disabled=a<0||a>=this.order.length-1;let c=this.host.page;this.head.replaceChildren(...c?[xz(`chevron-left`,r.backToPage,()=>this.close())]:[],I(`span`,{class:`dw-db-peek__db`},bz(`database`,14),this.db.title||r.untitled),I(`span`,{class:`dw-db-peek__grow`}),o,s,...c?[]:[xz((this.wide,`width`),this.wide?r.collapse:r.expand,()=>{this.wide=!this.wide,this.panel.classList.toggle(`is-wide`,this.wide)})],...this.host.openPage?[xz(`open`,r.openFullPage,()=>this.host.openPage(this.rowId))]:[],...this.host.copyLink?[xz(`link`,r.copyLink,()=>this.host.copyLink(this.rowId))]:[],...c?[]:[xz(`close`,r.close,()=>this.close())]);let l=WR(this.db),u=String(GR(t,l)??``),d=i?(()=>{let e=I(`input`,{class:`dw-db-peek__title`,placeholder:r.untitledRow,"aria-label":l.name||r.typeTitle});return e.value=u,e.addEventListener(`focus`,()=>n.setEditing(!0)),e.addEventListener(`blur`,()=>{e.value!==u&&i.setCell(t.id,l.id,e.value),n.setEditing(!1)}),e.addEventListener(`keydown`,t=>{t.stopPropagation(),t.key===`Enter`&&e.blur()}),e})():I(`h2`,{class:`dw-db-peek__title`},u||r.untitledRow);this.panel.setAttribute(`aria-label`,u||r.untitledRow);let f=[d,...this.db.columns.filter(e=>e.type!==`title`).map(e=>{let a=I(`div`,{class:`dw-db-peek__value dw-db-t__cell--${e.type}`,tabIndex:i&&!Lz.includes(e.type)?0:-1},Vz(n,t,e)),o=()=>{i&&Hz(n,a,t,e,{onDone:()=>this.draw(!1)})};return a.addEventListener(`click`,e=>{e.target.closest(`a, button`)||o()}),a.addEventListener(`keydown`,e=>{e.target===a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}),I(`div`,{class:`dw-db-peek__prop`},I(`div`,{class:`dw-db-peek__label`},bz(Fz[e.type],14),I(`span`,{},e.name||ER(r,e.type))),a)})];if(i){let e=xz(`plus`,r.addColumn,()=>Jj(e,FR.map(e=>({id:e,label:ER(r,e),icon:Fz[e],run:()=>i.addColumn(e,ER(r,e))})),r.addColumn),r.addColumn);e.classList.add(`dw-db-peek__add`),f.push(e)}let p=this.props.contains(document.activeElement);this.props.replaceChildren(...f),p&&this.panel.focus({preventScroll:!0}),e&&(this.unmount?.(),this.bodyEl.replaceChildren(),this.unmount=this.host.mountBody(this.bodyEl,t))}close(e=!0){this.unmount?.(),this.unmount=null,this.dom.remove(),this.onClose(),e&&this.host.page?.onLeave?.(),this.returnFocus instanceof HTMLElement&&this.returnFocus.isConnected&&this.returnFocus.focus({preventScroll:!0})}},qz=`docwell-database`,Jz=e=>e.getMap(`blocks`);function Yz(e){let t=new Bb;t.set(`title`,e.title);let n=(e,t)=>{let n=new Lb;return n.push(e.map((e,n)=>Xz(t(e),n))),n};return t.set(`columns`,n(e.columns,Zz)),t.set(`rows`,n(e.rows,Qz)),t.set(`views`,n(e.views,$z)),t}function Xz(e,t){return e.set(`pos`,t),e}function Zz(e){let t=new Bb;return t.set(`id`,e.id),t.set(`name`,e.name),t.set(`type`,e.type),e.options&&t.set(`options`,e.options),e.relation&&t.set(`relation`,e.relation),e.rollup&&t.set(`rollup`,e.rollup),t}function Qz(e){let t=new Bb;t.set(`id`,e.id),t.set(`createdAt`,e.createdAt),e.createdBy&&t.set(`createdBy`,e.createdBy);let n=new Bb;for(let[t,r]of Object.entries(e.cells))r!=null&&n.set(t,r);return t.set(`cells`,n),t}function $z(e){let t=new Bb;for(let[n,r]of Object.entries(e))t.set(n,r);return t}function eB(e){return e.toArray().filter(e=>e instanceof Bb).map((e,t)=>({m:e,p:tB(e,t),i:t})).sort((e,t)=>e.p-t.p||e.i-t.i).map(e=>e.m)}function tB(e,t){let n=e?.get(`pos`);return typeof n==`number`?n:t}function nB(e,t,n){let r=n?e.filter(e=>e!==n):e,i=Math.max(0,Math.min(t,r.length)),a=i>0?tB(r[i-1],i-1):null,o=i{let n=e.get(t);return n instanceof Lb?eB(n):[]},n=e=>{let t=e.toJSON();return delete t.pos,t},r=new Set,i=t(`rows`).map(e=>{let t=e.get(`cells`),n=e.get(`body`),i=e.get(`id`);return typeof i==`string`&&n instanceof sx&&n.length>0&&r.add(i),{id:i,createdAt:e.get(`createdAt`),createdBy:e.get(`createdBy`),cells:t instanceof Bb?t.toJSON():{}}}),a=BR({title:e.get(`title`),columns:t(`columns`).map(n),rows:i,views:t(`views`).map(n)});for(let e of a.rows)r.has(e.id)&&(e.hasBody=!0);return a}function iB(e,t=``){let n=[{id:LR(),name:e.columnName(`title`),type:`title`},{id:LR(),name:e.columnName(`select`),type:`select`,options:[]}],r=Date.now();return{title:t,columns:n,rows:[0,1,2].map(e=>({id:LR(),cells:{},createdAt:r+e,createdBy:null})),views:[RR(`table`,e.tableView,n)]}}var aB=e=>e==null||e===``||Array.isArray(e)&&!e.length,oB=class{doc;map;me;constructor(e,t,n){this.doc=e,this.map=t,this.me=n}snapshot(){return rB(this.map)}observe(e){let t=()=>e();return this.map.observeDeep(t),()=>this.map.unobserveDeep(t)}tx(e){this.doc.transact(e,qz)}list(e){let t=this.map.get(e);return t instanceof Lb||(t=new Lb,this.map.set(e,t)),t}find(e,t){let n=eB(this.list(e)),r=n.findIndex(e=>e.get(`id`)===t);return r<0?null:{item:n[r],index:r}}insertAt(e,t,n){let r=this.list(e),i=eB(r),a=Math.max(0,Math.min(t??i.length,i.length));for(let e of n)e.set(`pos`,nB(i,a)),i.splice(a++,0,e);r.push(n)}moveTo(e,t,n){let r=this.find(e,t);r&&r.index!==n&&r.item.set(`pos`,nB(eB(this.list(e)),n,r.item))}remove(e,t){let n=this.list(e),r=n.toArray().indexOf(t);r>=0&&n.delete(r,1)}setTitle(e){this.tx(()=>this.map.set(`title`,e))}addColumn(e,t,n){let r={id:LR(),name:t,type:e};return(e===`select`||e===`multiSelect`)&&(r.options=[]),this.tx(()=>this.insertAt(`columns`,n,[Zz(r)])),r.id}renameColumn(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`name`,t))}setRelation(e,t){this.tx(()=>{let n=this.find(`columns`,e);if(!n)return;let r=n.item.get(`relation`);if(n.item.set(`relation`,t),r&&(r.page!==t.page||r.database!==t.database))for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.delete(e)}})}setRollup(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`rollup`,t))}setOptions(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`options`,t))}changeType(e,t){let n=this.snapshot(),r=n.columns.find(t=>t.id===e);if(!r||r.type===t||r.type===`title`||t===`title`)return;let i=t===`select`||t===`multiSelect`?r.options??[]:[],a=new Map;for(let o of n.rows){let n=lz(o.cells[e],r,t,i);i=n.options,a.set(o.id,n.value)}this.tx(()=>{let n=this.find(`columns`,e);if(n){n.item.set(`type`,t),t===`select`||t===`multiSelect`?n.item.set(`options`,i):n.item.delete(`options`),t!==`relation`&&n.item.delete(`relation`),t!==`rollup`&&n.item.delete(`rollup`);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);if(!(n instanceof Bb))continue;let r=a.get(String(t.get(`id`)));aB(r)||r===!1?n.delete(e):n.set(e,r)}}})}deleteColumn(e){this.tx(()=>{let t=this.find(`columns`,e);if(t&&t.item.get(`type`)!==`title`){this.remove(`columns`,t.item);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.delete(e)}}})}moveColumn(e,t){this.tx(()=>this.moveTo(`columns`,e,t))}duplicateColumn(e,t){let n=this.snapshot().columns.find(t=>t.id===e);if(!n||n.type===`title`)return null;let r={...structuredClone(n),id:LR(),name:t};return this.tx(()=>{let t=this.find(`columns`,e);if(t){this.insertAt(`columns`,t.index+1,[Zz(r)]);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.has(e)&&n.set(r.id,n.get(e))}}}),r.id}addRow(e={},t){return this.addRows([e],t)[0]}addRows(e,t){let n=this.me(),r=Date.now(),i=e.map((e,t)=>({id:LR(),cells:e,createdAt:r+t,createdBy:n}));return this.tx(()=>this.insertAt(`rows`,t,i.map(Qz))),i.map(e=>e.id)}setCell(e,t,n){this.setCells([{row:e,col:t,value:n}])}setCells(e){this.tx(()=>{for(let{row:t,col:n,value:r}of e){let e=this.find(`rows`,t)?.item.get(`cells`);e instanceof Bb&&(aB(r)?e.delete(n):e.set(n,r))}})}deleteRows(e){this.tx(()=>{let t=this.list(`rows`);for(let n=t.length-1;n>=0;n--)e.includes(String(t.get(n)?.get(`id`)))&&t.delete(n,1)})}moveRow(e,t){this.tx(()=>this.moveTo(`rows`,e,t))}duplicateRow(e){let t=this.find(`rows`,e);if(!t)return null;let n=sB(t.item,this.me());return this.tx(()=>this.insertAt(`rows`,t.index+1,[n])),String(n.get(`id`))}rowBody(e){let t=this.find(`rows`,e);if(!t)return null;let n=t.item.get(`body`);if(n instanceof sx)return n;let r=new sx;return this.tx(()=>t.item.set(`body`,r)),r}rowIndex(e){return this.find(`rows`,e)?.index??-1}addView(e,t){let n=RR(e,t,this.snapshot().columns);return this.tx(()=>this.insertAt(`views`,void 0,[$z(n)])),n.id}updateView(e,t){this.tx(()=>{let n=this.find(`views`,e);if(n)for(let[e,r]of Object.entries(t))n.item.set(e,r)})}duplicateView(e,t){let n=this.snapshot().views.find(t=>t.id===e);if(!n)return null;let r={...structuredClone(n),id:LR(),name:t};return this.tx(()=>{let t=this.find(`views`,e);this.insertAt(`views`,(t?.index??-1)+1,[$z(r)])}),r.id}deleteView(e){this.tx(()=>{let t=this.find(`views`,e);t&&this.list(`views`).length>1&&this.remove(`views`,t.item)})}moveView(e,t){this.tx(()=>this.moveTo(`views`,e,t))}};function sB(e,t){let n=new Bb;n.set(`id`,LR()),n.set(`createdAt`,Date.now());let r=t??e.get(`createdBy`);UR(r)&&n.set(`createdBy`,r);let i=new Bb,a=e.get(`cells`);if(a instanceof Bb)for(let[e,t]of a.entries())i.set(e,t);n.set(`cells`,i);let o=e.get(`body`);if(o instanceof sx&&o.length){let e=new sx;e.insert(0,o.toArray().map(e=>e.clone())),n.set(`body`,e)}return n}function cB(e,t){let n=rB(e),r=e.get(`rows`);if(r instanceof Lb){let e=new Map;for(let t of r.toArray()){let n=t.get(`body`);n instanceof sx&&n.length&&e.set(String(t.get(`id`)),n)}for(let r of n.rows){let n=e.get(r.id);n&&(r.body=t(n))}}return n}function lB(e,t,n,r){e.transact(()=>{let i=Yz(n);Jz(e).set(t,i);let a=i.get(`rows`),o=new Map(n.rows.map(e=>[e.id,e]));for(let e of a.toArray()){let t=o.get(String(e.get(`id`)))?.body;if(!t?.length)continue;let n=new sx;e.set(`body`,n),r(t,n)}},qz)}function uB(e,t=`,`){let n=[],r=[],i=``,a=!1,o=0,s=e.replace(/^\uFEFF/,``);for(;oe.map(e=>cB(e,t)).join(t)).join(`\r -`)}function uB(e,t,n){return lB([t.map(e=>e.name),...n.map(e=>t.map(t=>JR(e,t)))])}function dB(e){let t=e.map(e=>e.trim()).filter(Boolean);if(!t.length)return`text`;if(t.every(e=>KR(e)!==null))return`number`;if(t.every(e=>/^\d{4}-\d{2}-\d{2}/.test(e)))return`date`;if(t.every(e=>/^(true|false|yes|no)$/i.test(e)))return`checkbox`;if(t.every(e=>/^https?:\/\/\S+$/.test(e)))return`link`;let n=new Set(t.map(e=>e.toLowerCase()));return t.length>=4&&n.size<=Math.max(2,t.length/3)&&t.every(e=>e.length<=40)?`select`:`text`}function fB(e,t,n){let r=e.trim();if(!r)return null;let i=e=>{let t=n.find(t=>t.name.toLowerCase()===e.toLowerCase());return t||(t={id:PR(),name:e,color:az(n)},n.push(t)),t.id};switch(t.type){case`number`:return KR(r);case`progress`:{let e=KR(r.replace(`%`,``));return e===null?null:Math.max(0,Math.min(100,Math.round(e)))}case`checkbox`:return/^(true|yes|1|x|✓|done)$/i.test(r);case`date`:return WR(r)||null;case`select`:return i(r);case`multiSelect`:return[...new Set(r.split(/[,;]/).map(e=>e.trim()).filter(Boolean).map(i))];case`member`:case`attachment`:case`createdBy`:case`createdTime`:return null;default:return r}}function pB(e,t=`,`){let n=sB(e,t).filter(e=>e.some(e=>e.trim())),r=n[0]??[],i=n.slice(1),a=r.map((e,t)=>({id:PR(),name:e.trim()||`${t+1}`,type:t===0?`title`:dB(i.map(e=>e[t]??``))}));for(let e of a)e.type===`select`&&(e.options=[]);return{columns:a,rows:i.map(e=>{let t={};return a.forEach((n,r)=>{let i=fB(e[r]??``,n,n.options??[]);i!==null&&(!Array.isArray(i)||i.length)&&(t[n.id]=i)}),t})}}function mB(e,t){let n=[];return{index:e.map(e=>{let r=t.find(t=>t.name.trim().toLowerCase()===e.trim().toLowerCase());return!r&&e.trim()&&n.push(e.trim()),r??null}),missing:n}}function hB(e,t,n,r){let i=I(`select`,{class:`dw-db-select`,"aria-label":n});for(let n of t){let t=I(`option`,{value:n.value},n.label);n.value===e&&(t.selected=!0),i.append(t)}return i.addEventListener(`change`,()=>r(i.value)),i.addEventListener(`keydown`,e=>e.stopPropagation()),i}var gB=e=>e.map(e=>({value:e.id,label:e.name||`…`}));function _B(e,t,n,r){let i=e.labels;if(!XR(n.op))return null;if(t.type===`select`||t.type===`multiSelect`)return hB(typeof n.value==`string`?n.value:``,[{value:``,label:`—`},...(t.options??[]).map(e=>({value:e.id,label:e.name}))],i.value,r);let a=t.type===`date`||t.type===`createdTime`?`date`:t.type===`number`||t.type===`progress`?`number`:`text`,o=I(`input`,{class:`dw-db-input dw-db-input--small`,type:a,"aria-label":i.value,placeholder:i.value});return o.value=n.value===void 0||n.value===null?``:String(n.value),o.addEventListener(`keydown`,e=>e.stopPropagation()),o.addEventListener(`change`,()=>r(a===`number`?o.value===``?null:Number(o.value):o.value)),o}function vB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.filters),s=()=>r?.updateView(n.id,{filters:o}),c=()=>{t.replaceChildren(),o.length>1&&t.append(hB(n.filterMode,[{value:`and`,label:i.matchAll},{value:`or`,label:i.matchAny}],i.filter,e=>{n.filterMode=e,r?.updateView(n.id,{filterMode:n.filterMode})})),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noFilters)),o.forEach((n,r)=>{let l=a.find(e=>e.id===n.column);if(!l)return;let u=YR(l.type),d=I(`div`,{class:`dw-db-pop__line`},hB(n.column,gB(a),i.filter,e=>{let t=a.find(t=>t.id===e);o[r]={column:e,op:YR(t.type)[0]},s(),c()}),hB(n.op,u.map(e=>({value:e,label:TR(i,e)})),i.filter,e=>{o[r]={...n,op:e},XR(e)||delete o[r].value,s(),c()}),_B(e,l,n,e=>{o[r]={...o[r],value:e},s()}),CB(i.remove,()=>{o.splice(r,1),s(),c()}));t.append(d)}),r&&t.append(wB(i.addFilter,()=>{let e=a.find(e=>e.type!==`title`)??a[0];o.push({column:e.id,op:YR(e.type)[0]}),s(),c()}))};c()}function yB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.sorts),s=()=>r?.updateView(n.id,{sorts:o}),c=()=>{t.replaceChildren(),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noSorts)),o.forEach((e,n)=>{t.append(I(`div`,{class:`dw-db-pop__line`},hB(e.column,gB(a),i.sort,t=>{o[n]={...e,column:t},s()}),hB(e.desc?`desc`:`asc`,[{value:`asc`,label:i.ascending},{value:`desc`,label:i.descending}],i.sort,t=>{o[n]={...e,desc:t===`desc`},s()}),CB(i.remove,()=>{o.splice(n,1),s(),c()})))}),r&&t.append(wB(i.addSort,()=>{let e=new Set(o.map(e=>e.column)),t=a.find(t=>!e.has(t.id))??a[0];o.push({column:t.id,desc:!1}),s(),c()}))};c()}function bB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>IR.includes(e.type)),o=a.map(e=>({value:e.id,label:e.name||CR(i,e.type)}));n.type!==`kanban`&&o.unshift({value:``,label:i.noGrouping}),t.append(I(`label`,{class:`dw-db-pop__label`},i.groupBy),a.length||n.type!==`kanban`?hB(n.groupBy??``,o,i.groupBy,e=>r?.updateView(n.id,{groupBy:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noGroupColumn))}function xB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`date`||e.type===`createdTime`);t.append(I(`label`,{class:`dw-db-pop__label`},i.dateColumn),a.length?hB(n.dateColumn??``,[{value:``,label:`—`},...a.map(e=>({value:e.id,label:e.name||CR(i,e.type)}))],i.dateColumn,e=>r?.updateView(n.id,{dateColumn:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noDateColumn))}function SB(e,t,n){let r=e.store,i=e.labels,a=[...n.hidden],o=()=>r?.updateView(n.id,{hidden:a}),s=()=>{t.replaceChildren();let n=e.db.columns.filter(e=>e.type!==`title`);if(r&&n.length){let e=I(`button`,{type:`button`,class:`dw-db__btn`},a.length?i.showAll:i.hideAll);e.addEventListener(`click`,()=>{a=a.length?[]:n.map(e=>e.id),o(),s()}),t.append(I(`div`,{class:`dw-db-pop__row dw-db-pop__row--end`},e))}for(let n of e.db.columns){let e=n.type===`title`||!a.includes(n.id),c=I(`button`,{type:`button`,class:`dw-db-pop__item`,role:`switch`,"aria-checked":String(e),disabled:n.type===`title`||!r},I(`span`,{class:`dw-db-pop__check`},_z(Mz[n.type],14)),I(`span`,{class:`dw-db-pop__grow`},n.name||CR(i,n.type)),I(`span`,{class:e?`dw-db-switch is-on`:`dw-db-switch`}));c.addEventListener(`click`,()=>{a=e?[...a,n.id]:a.filter(e=>e!==n.id),o(),s()}),t.append(c)}};s()}function CB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":e,title:e},_z(`close`,14));return n.addEventListener(`click`,t),n}function wB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},_z(`plus`,14),I(`span`,{},e));return n.addEventListener(`click`,t),n}var TB=6,EB=48;function DB(e,t){e.classList.add(`dw-db-touch-handle`);let n=!1,r=-1,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0,f,p=0,m=()=>document.elementFromPoint(o,s),h=()=>{clearTimeout(f),cancelAnimationFrame(d),u&&(u.remove(),u=null,t.end()),t.source.classList.remove(`is-held`,`is-dragging`),n=!1,r=-1,p=Date.now()},g=()=>{if(!u)return;let e=oinnerWidth-EB),n=sinnerHeight-EB),r=!1;for(let[i,a]of[[`x`,e],[`y`,n]]){if(!a)continue;let e=OB(t.source,i)??(i===`y`?document.scrollingElement:null);if(!e)continue;let n=i===`x`?`scrollLeft`:`scrollTop`,o=e[n];e[n]+=a*12,r||=e[n]!==o}r&&t.over(m(),o,s),d=requestAnimationFrame(g)},_=e=>[...e.changedTouches].find(e=>e.identifier===r);e.addEventListener(`touchstart`,u=>{if(n||u.touches.length!==1)return;let d=u.changedTouches[0],p=u.target.closest(`input, textarea, select, [contenteditable='true']`);p&&e.contains(p)||(u.preventDefault(),n=!0,r=d.identifier,i=o=d.clientX,a=s=d.clientY,c=Date.now(),l=u.target,f=setTimeout(()=>{t.source.classList.add(`is-held`),navigator.vibrate?.(10)},500))},{passive:!1}),e.addEventListener(`touchmove`,e=>{let r=n&&_(e);if(r){if(e.preventDefault(),o=r.clientX,s=r.clientY,!u){if(Math.hypot(o-i,s-a)<=TB)return;clearTimeout(f),t.source.classList.remove(`is-held`),u=t.ghost();let e=t.source.getBoundingClientRect();Object.assign(u.style,{position:`fixed`,left:`${e.left}px`,top:`${e.top}px`,width:`${Math.max(80,Math.min(e.width,innerWidth-Math.max(e.left,0)-8))}px`,margin:`0`,pointerEvents:`none`,zIndex:`1000`}),u.classList.add(`dw-db-ghost`),document.body.append(u),t.source.classList.add(`is-dragging`),d=requestAnimationFrame(g)}u.style.transform=`translate(${o-i}px, ${s-a}px)`,t.over(m(),o,s)}},{passive:!1}),e.addEventListener(`touchend`,e=>{if(!n||!_(e))return;e.preventDefault();let r=u!==null,i=Date.now()-c>=500,a=l;r&&t.drop(m(),o,s),h(),r||(i&&t.hold?t.hold():a instanceof HTMLElement&&a.click())}),e.addEventListener(`touchcancel`,e=>{n&&_(e)&&h()});for(let t of[`contextmenu`,`dragstart`])e.addEventListener(t,e=>{(n||Date.now()-p<800)&&(e.preventDefault(),e.stopPropagation())},!0)}function OB(e,t){for(let n=e.parentElement;n;n=n.parentElement){let e=getComputedStyle(n),r=t===`x`?e.overflowX:e.overflowY;if((t===`x`?n.scrollWidth>n.clientWidth:n.scrollHeight>n.clientHeight)&&(r===`auto`||r===`scroll`))return n}return null}var kB=200,AB=class{host;dom=I(`div`,{class:`dw-db`,dataset:{type:`database`},contentEditable:`false`});db;viewId=null;search=``;editing=0;pending=!1;limit=kB;collapsed=new Set;sel=null;anchor=null;picked=new Set;month;titleEl=I(`div`,{class:`dw-db__title`});tabs=I(`div`,{class:`dw-db__tabs`,role:`tablist`});tools=I(`div`,{class:`dw-db__tools`});body=I(`div`,{class:`dw-db__body`});bulk=I(`div`,{class:`dw-db__bulk`});searchInput;buttons;constructor(e,t){this.host=e,this.db=t;let n=new Date;this.month={y:n.getFullYear(),m:n.getMonth()};let r=e.labels;this.searchInput=I(`input`,{class:`dw-db-input dw-db__search`,placeholder:r.search,"aria-label":r.search,hidden:!0}),this.searchInput.addEventListener(`input`,()=>{this.search=this.searchInput.value,this.limit=kB,this.drawBody()}),this.searchInput.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(this.searchInput.value=``,this.search=``,this.searchInput.hidden=!0,this.drawBody())}),this.buttons={search:vz(`search`,r.search,()=>{this.searchInput.hidden=!this.searchInput.hidden,this.searchInput.hidden||this.searchInput.focus()}),filter:vz(`filter`,r.filter,e=>this.panel(e,`filter`),r.filter),sort:vz(`sort`,r.sort,e=>this.panel(e,`sort`),r.sort),group:vz(`layers`,r.group,e=>this.panel(e,`group`),r.group),props:vz(`sliders`,r.properties,e=>this.panel(e,`props`)),more:vz(`more`,r.more,()=>this.moreMenu()),add:vz(`plus`,r.newRow,()=>this.addRow(),r.newRow)},this.buttons.add.classList.add(`dw-db__btn--primary`);let i=I(`div`,{class:`dw-db__head`},this.titleEl),a=I(`div`,{class:`dw-db__bar`},this.tabs,this.tools);this.tools.append(this.searchInput,this.buttons.search,this.buttons.filter,this.buttons.sort,this.buttons.group,this.buttons.props,this.buttons.more,this.buttons.add),this.dom.append(i,a,this.bulk,this.body),this.draw()}get labels(){return this.host.labels}get editable(){return!!this.host.store}get view(){return this.db.views.find(e=>e.id===this.viewId)??this.db.views[0]??jB}ctx(){return{...this.host,db:this.db,openRow:e=>this.openRow(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw())}}}update(e,t){this.db=e,t&&(this.host={...this.host,...t}),this.editing?this.pending=!0:this.draw()}destroy(){xz()}draw(){this.drawTitle(),this.drawTabs(),this.drawTools(),this.drawBody()}drawTitle(){let e=this.labels,t=this.db.title;if(this.titleEl.querySelector(`input`)===document.activeElement)return;if(!this.editable){this.titleEl.replaceChildren(I(`span`,{class:t?``:`is-empty`},t||e.untitled));return}let n=I(`input`,{class:`dw-db__title-input`,placeholder:e.untitled,"aria-label":e.untitled});n.value=t,n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&n.blur()}),n.addEventListener(`change`,()=>this.host.store?.setTitle(n.value)),this.titleEl.replaceChildren(n)}drawTabs(){let e=this.labels,t=this.view;if(this.tabs.replaceChildren(...this.db.views.map(n=>{let r=I(`button`,{type:`button`,class:n.id===t.id?`dw-db__tab is-active`:`dw-db__tab`,role:`tab`,"aria-selected":String(n.id===t.id)},_z(n.type===`kanban`?`cards`:n.type===`calendar`?`calendar`:`table`,14),I(`span`,{},n.name||ER(e,n.type)));return r.addEventListener(`click`,()=>{if(n.id===t.id&&this.editable)return this.viewMenu(r,n);this.viewId=n.id,this.sel=null,this.limit=kB,this.draw()}),r.addEventListener(`contextmenu`,e=>{this.editable&&(e.preventDefault(),this.viewMenu(r,n))}),r})),this.editable){let t=vz(`plus`,e.addView,()=>Gj(t,NR.map(t=>({id:t,label:ER(e,t),icon:t===`kanban`?`cards`:t===`calendar`?`calendar`:`table`,run:()=>{this.showView(this.host.store.addView(t,ER(e,t)))}})),e.addView));this.tabs.append(t)}}drawTools(){let e=this.view,t=this.buttons,n=(e,t)=>{e.classList.toggle(`is-on`,t>0);let n=e.querySelector(`span`);n&&(n.textContent=t?`${e.title} ${t}`:e.title)};n(t.filter,e.filters.length),n(t.sort,e.sorts.length),t.sort.hidden=e.type===`calendar`,t.group.classList.toggle(`is-on`,!!e.groupBy&&e.type===`table`),t.group.hidden=e.type===`calendar`,t.add.hidden=!this.editable,this.drawBulk()}drawBulk(){let e=[...this.picked].filter(e=>this.db.rows.some(t=>t.id===e));if(this.picked=new Set(e),this.bulk.hidden=!e.length||!this.editable,this.bulk.hidden)return this.bulk.replaceChildren();let t=this.labels;this.bulk.replaceChildren(I(`span`,{},DR(t.selected,e.length)),vz(`trash`,t.deleteRows,()=>{this.host.store?.deleteRows(e),this.picked.clear()},t.deleteRows),vz(`close`,t.close,()=>{this.picked.clear(),this.draw()}))}panel(e,t){let n=e.currentTarget;bz(n,e=>{let n=this.ctx(),r=this.view;t===`filter`?vB(n,e,r):t===`sort`?yB(n,e,r):t===`group`?bB(n,e,r):(r.type===`calendar`&&xB(n,e,r),r.type===`kanban`&&bB(n,e,r),SB(n,e,r))},{class:`dw-db-pop--panel`,label:n.title,placement:`bottom-end`})}viewMenu(e,t){let n=this.labels,r=this.host.store,i=[{id:`rename`,label:n.renameView,icon:`pencil`,run:()=>{let e=window.prompt(n.viewName,t.name)?.trim();e&&r.updateView(t.id,{name:e})}},{id:`layout`,label:n.layout,icon:`grid`,children:NR.map(e=>({id:e,label:ER(n,e),icon:e===t.type?`check`:e===`kanban`?`cards`:e===`calendar`?`calendar`:`table`,run:()=>this.setLayout(t,e)}))},{id:`duplicate`,label:n.duplicateView,icon:`copy`,run:()=>{this.showView(r.duplicateView(t.id,`${t.name||ER(n,t.type)} 2`))}}];this.db.views.length>1&&i.push({id:`delete`,label:n.deleteView,icon:`trash`,danger:!0,run:()=>r.deleteView(t.id)}),Gj(e,i,n.layout)}showView(e){e&&(this.viewId=e,this.sel=null,this.limit=kB,this.draw())}setLayout(e,t){let n={type:t},r=this.db.columns;t===`kanban`&&!e.groupBy&&(n.groupBy=r.find(e=>[`select`,`multiSelect`,`checkbox`,`member`].includes(e.type))?.id??null),t===`calendar`&&!e.dateColumn&&(n.dateColumn=r.find(e=>e.type===`date`)?.id??null),t===`calendar`&&!n.dateColumn&&!e.dateColumn&&this.host.store&&(n.dateColumn=this.host.store.addColumn(`date`,this.labels.typeDate)),this.host.store?.updateView(e.id,n)}moreMenu(){let e=this.labels,t=this.view,n=[{id:`csv`,label:e.exportCsv,icon:`download`,run:()=>{let n=ez(this.db,t);Cz(`${(this.db.title||e.untitled).replace(/[\\/:*?"<>|]+/g,` `).trim()}.csv`,`\uFEFF${uB(this.db,n,$R(this.db,t,this.search))}`,`text/csv`)}}];this.editable&&(n.push({id:`import`,label:e.importCsv,icon:`upload`,run:()=>void this.importCsv()}),n.push({id:`view`,label:e.layout,icon:`grid`,run:()=>this.viewMenu(this.buttons.more,t)})),Gj(this.buttons.more,n,e.more)}async importCsv(){let e=this.host.store,t=await wz(`.csv,text/csv,.tsv,text/tab-separated-values`);if(!e||!t)return;let n=await t.text(),r=t.name.endsWith(`.tsv`)?` `:`,`,i=sB(n,r).filter(e=>e.some(e=>e.trim()));i.length<2||e.tx(()=>{if(this.db.rows.every(e=>!JR(e,VR(this.db)))){let t=pB(n,r);e.deleteRows(this.db.rows.map(e=>e.id));let i=VR(this.db),[a,...o]=t.columns,s=new Map;a&&(e.renameColumn(i.id,a.name),s.set(a.id,i.id));for(let t of o){let n=this.db.columns.find(e=>e.name.toLowerCase()===t.name.toLowerCase()&&e.type!==`title`);n&&e.deleteColumn(n.id);let r=e.addColumn(t.type,t.name);t.options&&e.setOptions(r,t.options),s.set(t.id,r)}e.addRows(t.rows.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[s.get(e)??e,t])))),this.host.notify?.(DR(this.labels.imported,t.rows.length));return}let{index:t,missing:a}=mB(i[0],this.db.columns),o=new Map(a.map(t=>[t,e.addColumn(`text`,t)])),s=i[0].map((e,n)=>{let r=t[n];if(r)return r;let i=o.get(e.trim());return i?{id:i,name:e,type:`text`}:null}),c=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),l=i.slice(1).map(e=>{let t={};return s.forEach((n,r)=>{if(!n)return;let i=fB(e[r]??``,n,c.get(n.id)??[]);i!==null&&(t[n.id]=i)}),t});for(let t of this.db.columns){let n=c.get(t.id);n&&n.length!==(t.options?.length??0)&&e.setOptions(t.id,n)}e.addRows(l),this.host.notify?.(DR(this.labels.imported,l.length))})}addRow(e={},t=!1){let n=this.host.store;if(!n)return;let r=this.view;for(let t of r.filters){let n=this.db.columns.find(e=>e.id===t.column);!n||t.column in e||(t.op===`is`&&(n.type===`select`||n.type===`text`)&&t.value&&(e[n.id]=t.value),t.op===`contains`&&n.type===`multiSelect`&&t.value&&(e[n.id]=[t.value]),t.op===`checked`&&(e[n.id]=!0))}let i=n.addRow(e);t||r.type!==`table`?this.openRow(i):(this.sel={row:i,col:VR(this.db).id},queueMicrotask(()=>this.startEdit()))}openRow(e){let t=$R(this.db,this.view,this.search).map(e=>e.id);this.host.openRow(e,t)}drawBody(){let e=this.view;e.type===`kanban`?this.drawKanban(e):e.type===`calendar`?this.drawCalendar(e):this.drawTable(e)}tableRows=[];tableCols=[];grid=null;drawTable(e){let t=this.labels,n=ez(this.db,e),r=$R(this.db,e,this.search),i=e.groupBy?this.db.columns.find(t=>t.id===e.groupBy):void 0,a=i?tz(r,i,t.noValue,t.checked,t.unchecked).filter(e=>e.rows.length||e.key!==``):[{key:``,label:``,rows:r}];this.tableCols=n,this.tableRows=[];let o=this.editable,s=e.sorts.length>0,c=I(`colgroup`,{},I(`col`,{class:`dw-db-t__gutter-col`}),n.map(t=>I(`col`,{style:{width:`${e.widths[t.id]??(t.type===`title`?240:160)}px`}})),o?I(`col`,{class:`dw-db-t__add-col`}):null),l=I(`table`,{class:`dw-db-t`},c,I(`thead`,{},I(`tr`,{},I(`th`,{class:`dw-db-t__gutter`,"aria-hidden":`true`}),n.map((e,t)=>this.headerCell(e,t,c.children[t+1])),o?I(`th`,{class:`dw-db-t__add`},vz(`plus`,t.addColumn,e=>this.addColumnMenu(e.currentTarget))):null))),u=0;for(let r of a){let a=I(`tbody`,{}),c=`${e.id}:${r.key}`;if(i){let e=!this.collapsed.has(c),t=I(`button`,{type:`button`,class:`dw-db-t__group`,"aria-expanded":String(e)},_z(e?`chevron-down`:`chevron-right`,14),r.key&&i.type!==`checkbox`&&i.type!==`member`&&i.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:r.color??`gray`}},r.label):I(`span`,{},r.label),I(`span`,{class:`dw-db-t__count`},String(r.rows.length)));if(t.addEventListener(`click`,()=>{e?this.collapsed.add(c):this.collapsed.delete(c),this.drawBody()}),a.append(I(`tr`,{class:`dw-db-t__group-row`},I(`td`,{colSpan:n.length+2},t))),!e){l.append(a);continue}}for(let e of r.rows){if(u>=this.limit)break;u++,this.tableRows.push(e),a.append(this.tableRow(e,n,o&&!s))}if(o&&u{let e={};i&&r.key?e[i.id]=iz({id:``,cells:{},createdAt:0,createdBy:null},i,``,r.key,r.rows.flatMap(e=>MB(HR(e,i)))):i?.type===`checkbox`&&(e[i.id]=r.key===`true`),this.addRow(e)}),a.append(I(`tr`,{class:`dw-db-t__new-row`},I(`td`,{colSpan:n.length+2},e)))}l.append(a)}let d=[],f=I(`div`,{class:`dw-db-t__wrap`,role:`grid`,tabIndex:0,"aria-label":this.db.title||t.database},l);if(d.push(f),r.length||d.push(I(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),r.length>u&&u>=this.limit){let e=I(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${r.length-u})`);e.addEventListener(`click`,()=>{this.limit+=kB,this.drawBody()}),d.push(e)}this.grid=f,f.addEventListener(`keydown`,e=>this.onGridKey(e)),f.addEventListener(`copy`,e=>this.onCopy(e)),f.addEventListener(`paste`,e=>this.onPaste(e));let p=this.body.querySelector(`.dw-db-t__wrap`)?.scrollLeft??0,m=this.body.contains(document.activeElement);this.body.replaceChildren(...d),f.scrollLeft=p,this.markSelection(),m&&this.sel&&f.focus({preventScroll:!0})}headerCell(e,t,n){let r=this.labels,i=I(`span`,{class:`dw-db-t__name`},e.name||CR(r,e.type)),a=I(`button`,{type:`button`,class:`dw-db-t__head`,"aria-haspopup":`menu`,draggable:this.editable},_z(Mz[e.type],14),i),o=I(`th`,{dataset:{col:e.id}},a);if(a.addEventListener(`click`,()=>this.columnMenu(a,e,t)),this.editable){a.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-column`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),o.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-column`)&&(e.preventDefault(),o.classList.add(`is-drop`))}),o.addEventListener(`dragleave`,()=>o.classList.remove(`is-drop`)),o.addEventListener(`drop`,t=>{o.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-column`);n&&n!==e.id&&(t.preventDefault(),this.host.store?.moveColumn(n,this.db.columns.findIndex(t=>t.id===e.id)))});let t=I(`span`,{class:`dw-db-t__resize`,title:r.resize,"aria-hidden":`true`});t.addEventListener(`pointerdown`,r=>{r.preventDefault(),r.stopPropagation();let i=r.clientX,a=n.getBoundingClientRect().width||160,o=a;t.setPointerCapture(r.pointerId);let s=e=>{o=Math.max(72,Math.round(a+e.clientX-i)),n.style.width=`${o}px`},c=()=>{t.removeEventListener(`pointermove`,s),t.removeEventListener(`pointerup`,c);let n=this.view;o!==a&&this.host.store?.updateView(n.id,{widths:{...n.widths,[e.id]:o}})};t.addEventListener(`pointermove`,s),t.addEventListener(`pointerup`,c)}),o.append(t)}return o}columnMenu(e,t,n){let r=this.labels,i=this.host.store,a=this.view,o=e=>({id:e?`desc`:`asc`,label:e?r.sortDescending:r.sortAscending,icon:e?`arrow-down`:`arrow-up`,run:()=>i?.updateView(a.id,{sorts:[{column:t.id,desc:e}]})});if(!i){Gj(e,[o(!1),o(!0)],t.name);return}let s=this.db.columns,c=s.findIndex(e=>e.id===t.id),l=[{id:`rename`,label:r.rename,icon:`pencil`,run:()=>this.renameColumn(t)}];t.type!==`title`&&l.push({id:`type`,label:r.type,icon:Mz[t.type],children:MR.map(n=>({id:n,label:CR(r,n),icon:n===t.type?`check`:Mz[n],run:()=>{i.changeType(t.id,n),(n===`relation`||n===`rollup`)&&queueMicrotask(()=>this.linkSettings(e,t.id))}}))}),t.type===`relation`&&l.push({id:`relationTo`,label:r.relationTo,icon:`relation`,run:()=>this.linkSettings(e,t.id)}),t.type===`rollup`&&l.push({id:`rollup`,label:r.rollupSettings,icon:`rollup`,run:()=>this.linkSettings(e,t.id)}),l.push(o(!1),o(!0),{id:`filter`,label:r.filterBy,icon:`filter`,run:()=>{i.updateView(a.id,{filters:[...a.filters,{column:t.id,op:YR(t.type)[0]}]}),this.buttons.filter.click()}}),t.type!==`title`&&l.push({id:`hide`,label:r.hide,icon:`close`,run:()=>i.updateView(a.id,{hidden:[...a.hidden,t.id]})}),l.push({id:`left`,label:r.insertLeft,icon:`plus`,run:()=>this.insertColumn(c)},{id:`right`,label:r.insertRight,icon:`plus`,run:()=>this.insertColumn(c+1)}),c>0&&l.push({id:`moveLeft`,label:r.moveLeft,icon:`arrow-up`,run:()=>i.moveColumn(t.id,c-1)}),ci.moveColumn(t.id,c+1)}),t.type!==`title`&&l.push({id:`duplicate`,label:r.duplicate,icon:`copy`,run:()=>i.duplicateColumn(t.id,`${t.name} 2`)},{id:`delete`,label:r.deleteColumn,icon:`trash`,danger:!0,run:()=>i.deleteColumn(t.id)}),Gj(e,l,t.name||CR(r,t.type))}linkSettings(e,t){let n=this.db.columns.find(e=>e.id===t),r=e.isConnected?e:this.dom.querySelector(`[data-col="${t}"]`)??this.dom;n?.type===`relation`?Oz(this.ctx(),r,n):n?.type===`rollup`&&Az(this.ctx(),r,n)}insertColumn(e){let t=this.host.store;if(!t)return;let n=t.addColumn(`text`,this.labels.typeText,e);queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}addColumnMenu(e){let t=this.labels;Gj(e,MR.map(e=>({id:e,label:CR(t,e),icon:Mz[e],run:()=>{let n=this.host.store?.addColumn(e,CR(t,e));queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}})),t.addColumn)}renameColumn(e){let t=this.body.querySelector(`th[data-col="${CSS.escape(e.id)}"]`),n=this.host.store;if(!n)return;if(!t){let t=window.prompt(this.labels.columnName,e.name)?.trim();t&&n.renameColumn(e.id,t);return}let r=this.ctx();r.setEditing(!0);let i=Sz(e.name,{class:`dw-db-t__name-input`,label:this.labels.columnName,onCommit:t=>{t.trim()&&t.trim()!==e.name&&n.renameColumn(e.id,t.trim()),r.setEditing(!1),this.drawBody()},onCancel:()=>{r.setEditing(!1),this.drawBody()}});t.replaceChildren(i),i.focus(),i.select()}tableRow(e,t,n){let r=this.labels,i=I(`tr`,{dataset:{row:e.id},class:this.picked.has(e.id)?`is-picked`:``}),a=I(`td`,{class:`dw-db-t__gutter`});if(this.editable){let t=I(`input`,{type:`checkbox`,class:`dw-db-t__pick`,"aria-label":r.selectRow,checked:this.picked.has(e.id)});if(t.addEventListener(`change`,()=>{t.checked?this.picked.add(e.id):this.picked.delete(e.id),i.classList.toggle(`is-picked`,t.checked),this.drawBulk()}),a.append(t),n){let t=I(`span`,{class:`dw-db-t__grip`,draggable:!0,title:r.dragRow,"aria-hidden":`true`},_z(`grip`,14));t.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),t.dataTransfer?.setDragImage(i,0,0)}),a.append(t),i.addEventListener(`dragover`,e=>{if(!e.dataTransfer?.types.includes(`application/x-docwell-row`))return;e.preventDefault();let t=e.clientY>i.getBoundingClientRect().top+i.offsetHeight/2;i.classList.toggle(`is-drop-below`,t),i.classList.toggle(`is-drop-above`,!t)}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop-below`,`is-drop-above`)),i.addEventListener(`drop`,t=>{let n=i.classList.contains(`is-drop-below`);i.classList.remove(`is-drop-below`,`is-drop-above`);let r=t.dataTransfer?.getData(`application/x-docwell-row`);r&&r!==e.id&&this.host.store&&(t.preventDefault(),this.moveRowBeside(r,e.id,n))});let n=null,o=()=>n?.classList.remove(`is-drop-below`,`is-drop-above`),s=e=>{let t=e?.closest(`tr[data-row]`);return t&&t.parentElement===i.parentElement&&t!==i?t:null},c=(e,t)=>t>e.getBoundingClientRect().top+e.offsetHeight/2;DB(t,{source:i,ghost:()=>I(`div`,{class:`dw-db-ghost--row`},JR(e,VR(this.db))||r.untitledRow),over:(e,t,r)=>{o(),n=s(e),n&&n.classList.add(c(n,r)?`is-drop-below`:`is-drop-above`)},drop:(t,n,r)=>{let i=s(t);i?.dataset.row&&this.moveRowBeside(e.id,i.dataset.row,c(i,r))},end:o,hold:()=>this.rowMenu(i,e)})}}i.append(a);for(let n of t){let t=I(`td`,{dataset:{col:n.id},class:`dw-db-t__cell dw-db-t__cell--${n.type}`,role:`gridcell`},Rz(this.ctx(),e,n));if(n.type===`title`){let n=I(`button`,{type:`button`,class:`dw-db-t__open`,title:r.openRow},_z(`open`,13),I(`span`,{},r.openRow));n.addEventListener(`click`,t=>{t.stopPropagation(),this.openRow(e.id)}),t.append(n)}t.addEventListener(`mousedown`,t=>{t.target.closest(`input, button, a`)||(this.anchor=t.shiftKey&&this.sel?this.anchor??this.sel:null,this.sel={row:e.id,col:n.id},t.shiftKey||(this.anchor=null),this.markSelection(),t.preventDefault(),this.grid?.focus({preventScroll:!0}))});let a=!1;t.addEventListener(`pointerdown`,e=>a=e.pointerType===`touch`),t.addEventListener(`click`,e=>{e.target.closest(`input, button, a`)||e.shiftKey||(n.type===`checkbox`||a)&&this.startEdit()}),t.addEventListener(`dblclick`,()=>this.startEdit()),i.append(t)}return this.editable&&i.append(I(`td`,{class:`dw-db-t__add`})),i.addEventListener(`contextmenu`,t=>{(this.editable||this.host.copyLink)&&(t.preventDefault(),this.rowMenu(i,e))}),i}moveRowBeside(e,t,n){let r=this.host.store;if(!r||e===t)return;let i=r.rowIndex(e),a=r.rowIndex(t)+ +!!n;ithis.openRow(t.id)}];if(i&&a.push({id:`link`,label:n.copyLink,icon:`link`,run:()=>i(t.id)}),r){let e=r.rowIndex(t.id);a.push({id:`above`,label:n.insertAbove,icon:`arrow-up`,run:()=>r.addRow({},e)},{id:`below`,label:n.insertBelow,icon:`arrow-down`,run:()=>r.addRow({},e+1)},{id:`duplicate`,label:n.duplicateRow,icon:`copy`,run:()=>r.duplicateRow(t.id)},{id:`delete`,label:n.deleteRow,icon:`trash`,danger:!0,run:()=>r.deleteRows([t.id])})}Gj(e,a,n.openRow)}range(){if(!this.sel)return null;let e=e=>this.tableRows.findIndex(t=>t.id===e),t=e=>this.tableCols.findIndex(t=>t.id===e),n=this.anchor??this.sel,[r,i,a,o]=[e(n.row),e(this.sel.row),t(n.col),t(this.sel.col)];if(i<0||o<0)return null;let s=r<0?i:r,c=a<0?o:a;return{r0:Math.min(s,i),r1:Math.max(s,i),c0:Math.min(c,o),c1:Math.max(c,o)}}markSelection(){if(!this.grid)return;for(let e of this.grid.querySelectorAll(`.is-selected, .is-in-range`))e.classList.remove(`is-selected`,`is-in-range`);let e=this.range();if(!e||!this.sel)return;for(let t=e.r0;t<=e.r1;t++)for(let n=e.c0;n<=e.c1;n++)this.cellEl(this.tableRows[t].id,this.tableCols[n].id)?.classList.add(`is-in-range`);let t=this.cellEl(this.sel.row,this.sel.col);t?.classList.add(`is-selected`),t?.scrollIntoView({block:`nearest`,inline:`nearest`})}cellEl(e,t){return this.grid?.querySelector(`tr[data-row="${CSS.escape(e)}"] td[data-col="${CSS.escape(t)}"]`)??null}startEdit(e){if(!this.sel||!this.host.store)return;let t=this.db.rows.find(e=>e.id===this.sel.row),n=this.db.columns.find(e=>e.id===this.sel.col),r=this.cellEl(this.sel.row,this.sel.col);t&&n&&r&&zz(this.ctx(),r,t,n,{initial:e,onDone:e=>{e&&this.moveSel(+(e===`down`),e===`right`?1:e===`left`?-1:0,!1),this.drawBody(),this.grid?.focus({preventScroll:!0})}})}moveSel(e,t,n){let r=this.tableRows,i=this.tableCols;if(!r.length||!i.length)return;if(!this.sel)return this.sel={row:r[0].id,col:i[0].id},this.markSelection();this.anchor=n?this.anchor??{...this.sel}:null;let a=Math.max(0,Math.min(r.length-1,r.findIndex(e=>e.id===this.sel.row)+e)),o=Math.max(0,Math.min(i.length-1,i.findIndex(e=>e.id===this.sel.col)+t));this.sel={row:r[a].id,col:i[o].id},this.markSelection()}onGridKey(e){if(e.target.closest(`input, select, textarea`))return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`z`)return e.preventDefault(),e.shiftKey?this.host.redo():this.host.undo();if(t&&e.key.toLowerCase()===`y`)return e.preventDefault(),this.host.redo();if(t)return;let n={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(n)return e.preventDefault(),this.moveSel(n[0],n[1],e.shiftKey);if(this.sel){if(e.key===`Tab`)return e.preventDefault(),this.moveSel(0,e.shiftKey?-1:1,!1);if(e.key===`Escape`)this.sel=null,this.anchor=null,this.markSelection();else{if(e.key===`Enter`||e.key===`F2`)return e.preventDefault(),this.startEdit();if(e.key===` `)return e.preventDefault(),this.db.columns.find(e=>e.id===this.sel.col)?.type===`title`?this.openRow(this.sel.row):this.startEdit();if((e.key===`Delete`||e.key===`Backspace`)&&this.host.store){e.preventDefault();let t=this.range();if(!t)return;let n=[];for(let e=t.r0;e<=t.r1;e++)for(let r=t.c0;r<=t.c1;r++){let t=this.tableCols[r];Pz.includes(t.type)||n.push({row:this.tableRows[e].id,col:t.id,value:null})}this.host.store.setCells(n)}else if(e.key.length===1&&this.host.store){let t=this.db.columns.find(e=>e.id===this.sel.col);t&&(Nz.includes(t.type)||t.type===`select`||t.type===`multiSelect`)&&(e.preventDefault(),this.startEdit(e.key))}}}}onCopy(e){if(e.target.closest(`input, textarea`))return;let t=this.range();if(!t||!e.clipboardData)return;e.preventDefault();let n=[];for(let e=t.r0;e<=t.r1;e++){let r=[];for(let n=t.c0;n<=t.c1;n++)r.push(JR(this.tableRows[e],this.tableCols[n]));n.push(r)}e.clipboardData.setData(`text/plain`,lB(n,` `)),this.host.notify?.(DR(this.labels.copyNotice,(t.r1-t.r0+1)*(t.c1-t.c0+1)))}onPaste(e){if(e.target.closest(`input, textarea`))return;let t=this.host.store,n=e.clipboardData?.getData(`text/plain`);if(!t||!n||!this.sel)return;e.preventDefault();let r=sB(n.replace(/\r?\n$/,``),(n.includes(` `),` `)),i=this.tableRows.findIndex(e=>e.id===this.sel.row),a=this.tableCols.findIndex(e=>e.id===this.sel.col);if(i<0||a<0)return;let o=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),s=[],c=[];r.forEach((e,t)=>{let n=this.tableRows[i+t],r={};e.forEach((e,t)=>{let i=this.tableCols[a+t];if(!i||Pz.includes(i.type))return;let c=fB(e,i,o.get(i.id)??[]);n?s.push({row:n.id,col:i.id,value:c}):c!==null&&(r[i.id]=c)}),n||c.push(r)}),t.tx(()=>{for(let e of this.db.columns){let n=o.get(e.id);n&&n.length!==(e.options?.length??0)&&t.setOptions(e.id,n)}t.setCells(s),c.length&&t.addRows(c)})}drawKanban(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.groupBy);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noGroupColumn));return}let r=$R(this.db,e,this.search),i=tz(r,n,t.noValue,t.checked,t.unchecked),a=ez(this.db,e).filter(e=>e.type!==`title`&&e.id!==n.id),o=VR(this.db),s=r.flatMap(e=>MB(HR(e,n))),c=I(`div`,{class:`dw-db-k`}),l=(t,r,i,a)=>{let o=this.host.store,c=this.db.rows.find(e=>e.id===t);o&&c&&o.tx(()=>{if(r!==i&&o.setCell(t,n.id,iz(c,n,r,i,s)),a&&a!==t&&!e.sorts.length){let e=o.rowIndex(t),n=o.rowIndex(a);e0)continue;let r=I(`div`,{class:`dw-db-k__cards`,dataset:{group:e.key}}),i=I(`div`,{class:`dw-db-k__head`},e.key&&n.type!==`checkbox`&&n.type!==`member`&&n.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:e.color??`gray`}},e.label):I(`span`,{class:`dw-db-k__label`},e.label),I(`span`,{class:`dw-db-t__count`},String(e.rows.length)));for(let t of e.rows.slice(0,this.limit)){let i=I(`div`,{class:`dw-db-k__card`,tabIndex:0,role:`button`,draggable:this.editable&&!Pz.includes(n.type),dataset:{row:t.id}},I(`div`,{class:`dw-db-k__title`},Rz(this.ctx(),t,o)),a.flatMap(e=>JR(t,e)===``||e.type===`checkbox`&&HR(t,e)!==!0?[]:[I(`div`,{class:`dw-db-k__prop`,title:e.name},Rz(this.ctx(),t,e))]));if(i.addEventListener(`click`,()=>this.openRow(t.id)),i.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openRow(t.id))}),i.addEventListener(`dragstart`,n=>{n.dataTransfer?.setData(`application/x-docwell-card`,JSON.stringify({row:t.id,from:e.key})),n.dataTransfer&&(n.dataTransfer.effectAllowed=`move`),i.classList.add(`is-dragging`)}),i.addEventListener(`dragend`,()=>i.classList.remove(`is-dragging`)),i.draggable){let n=I(`span`,{class:`dw-db-k__grip`,"aria-hidden":`true`},_z(`grip`,14));i.append(n);let r=null,a=e=>{let t=e?.closest(`.dw-db-k__cards`);return t&&c.contains(t)?t:null};DB(n,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{r?.classList.remove(`is-drop`),r=a(e),r?.classList.add(`is-drop`)},drop:n=>{let r=a(n);r&&l(t.id,e.key,r.dataset.group??``,n?.closest(`.dw-db-k__card`)?.dataset.row)},end:()=>r?.classList.remove(`is-drop`)})}r.append(i)}if(this.editable){let i=I(`button`,{type:`button`,class:`dw-db-t__new`},_z(`plus`,14),I(`span`,{},t.newRow));i.addEventListener(`click`,()=>{let t={id:``,cells:{},createdAt:0,createdBy:null};this.addRow(e.key||n.type===`checkbox`?{[n.id]:iz(t,n,``,e.key,s)}:{},!0)}),r.append(i),r.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-card`)&&(e.preventDefault(),r.classList.add(`is-drop`))}),r.addEventListener(`dragleave`,e=>{r.contains(e.relatedTarget)||r.classList.remove(`is-drop`)}),r.addEventListener(`drop`,t=>{r.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-card`),i=this.host.store;if(!n||!i)return;t.preventDefault();let{row:a,from:o}=JSON.parse(n);l(a,o,e.key,t.target.closest(`.dw-db-k__card`)?.dataset.row)})}c.append(I(`section`,{class:`dw-db-k__col`,"aria-label":e.label},i,r))}this.body.replaceChildren(c)}drawCalendar(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.dateColumn);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noDateColumn));return}let r=this.editable&&n.type===`date`,{y:i,m:a}=this.month,o=sz(i,a),s=$R(this.db,e,this.search),c=new Map,l=[];for(let e of s){let t=WR(HR(e,n));t?c.set(t,[...c.get(t)??[],e]):l.push(e)}let u=VR(this.db),d=GR(new Date),f=new Date(i,a,1).toLocaleDateString(this.host.locale,{month:`long`,year:`numeric`}),p=e=>{let t=new Date(i,a+e,1);this.month={y:t.getFullYear(),m:t.getMonth()},this.drawBody()},m=I(`div`,{class:`dw-db-c__nav`},I(`strong`,{class:`dw-db-c__month`},f),vz(`chevron-left`,t.previousMonth,()=>p(-1)),vz(`chevron-right`,t.nextMonth,()=>p(1)),vz(`calendar`,t.today,()=>{let e=new Date;this.month={y:e.getFullYear(),m:e.getMonth()},this.drawBody()},t.today)),h=o.slice(0,7).map(e=>{let[t,n,r]=e.split(`-`).map(Number);return I(`div`,{class:`dw-db-c__wd`},new Date(t,n-1,r).toLocaleDateString(this.host.locale,{weekday:`short`}))}),g=e=>{let i=I(`button`,{type:`button`,class:`dw-db-c__chip`,draggable:r,dataset:{row:e.id}},JR(e,u)||t.untitledRow);if(i.addEventListener(`click`,()=>this.openRow(e.id)),i.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row-date`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),r){let t=null,r=e=>{let t=e?.closest(`.dw-db-c__day`);return t&&this.body.contains(t)?t:null};DB(i,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{t?.classList.remove(`is-drop`),t=r(e),t?.classList.add(`is-drop`)},drop:t=>{let i=r(t)?.dataset.day;i&&this.host.store?.setCell(e.id,n.id,i)},end:()=>t?.classList.remove(`is-drop`)})}return i},_=I(`div`,{class:`dw-db-c__grid`,role:`grid`},h);for(let e of o){let i=I(`div`,{class:`dw-db-c__day${Number(e.slice(5,7))===a+1?``:` is-out`}${e===d?` is-today`:``}`,role:`gridcell`,dataset:{day:e}},I(`span`,{class:`dw-db-c__num`},String(Number(e.slice(8)))),(c.get(e)??[]).map(g));if(this.editable&&n.type===`date`){let r=I(`button`,{type:`button`,class:`dw-db-c__add`,"aria-label":`${t.newRow} ${e}`,title:t.newRow},_z(`plus`,12));r.addEventListener(`click`,()=>this.addRow({[n.id]:e},!0)),i.append(r)}r&&(i.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-row-date`)&&(e.preventDefault(),i.classList.add(`is-drop`))}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop`)),i.addEventListener(`drop`,t=>{i.classList.remove(`is-drop`);let r=t.dataTransfer?.getData(`application/x-docwell-row-date`);r&&(t.preventDefault(),this.host.store?.setCell(r,n.id,e))})),_.append(i)}let v=[m,_];l.length&&v.push(I(`details`,{class:`dw-db-c__undated`},I(`summary`,{},DR(t.noDate,l.length)),I(`div`,{class:`dw-db-c__chips`},l.slice(0,this.limit).map(g)))),this.body.replaceChildren(I(`div`,{class:`dw-db-c`},v))}},jB={id:``,name:``,type:`table`,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:null,dateColumn:null,widths:{}};function MB(e){return Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`):[]}var NB=`[A-Za-z0-9]{1,32}`,PB=(e,t)=>`#r-${e}-${t}`;function FB(e){let t=RegExp(`^#?r-(${NB})-(${NB})$`).exec(e);return t?{database:t[1],row:t[2]}:null}var IB=`dw-open-record`;function LB(e,t,n,r){let i=-1;if(e.state.doc.descendants((e,n)=>i>=0?!1:(e.type.name===`database`&&e.attrs.id===t&&(i=n),!0)),i<0)return!1;let a=e.view.nodeDOM(i);if(!(a instanceof HTMLElement))return!1;let o={row:n,...r};return a.dispatchEvent(new CustomEvent(IB,{detail:o})),!!o.found}async function RB(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}var zB=e=>(e??AR).database;function BB(e){let t=zB(e);return{tableView:t.viewTable,columnName:e=>e===`title`?t.typeTitle:CR(t,e)}}var VB=e=>vw(e).content??[];function HB(e,t){let n=[];return e.forEach(e=>{e.type.name===`database`?n.push(t(e)):e.content.size?n.push(e.copy(HB(e.content,t))):n.push(e)}),s.from(n)}function UB(e){let t=!1;return e.descendants(e=>(e.type.name===`database`&&(t=!0),!t)),t}var WB=Jp.create({name:`database`,group:`block`,atom:!0,draggable:!0,selectable:!0,addOptions(){return{labels:null,doc:void 0,readOnlyDoc:!1,undoScope:!0,files:void 0,people:void 0,me:void 0,rowExtensions:void 0,notify:void 0,recordLink:void 0,onLinkCopied:void 0,linkedPages:void 0,pages:void 0,onNavigate:void 0,recordPage:void 0}},addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-id`)??``,renderHTML:e=>({"data-id":e.id})},data:{default:null,parseHTML:e=>{try{let t=e.getAttribute(`data-db`);return t?JSON.parse(t):null}catch{return null}},renderHTML:e=>e.data?{"data-db":JSON.stringify(e.data)}:{}}}},parseHTML(){return[{tag:`div[data-type='database']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=A(t,{"data-type":`database`});if(!e.attrs.data)return[`div`,n];let r=LR(e.attrs.data),i=r.views[0],a=r.columns.filter(e=>e.type===`title`||!i?.hidden.includes(e.id));return[`div`,n,[`p`,{},[`strong`,{},r.title||zB(this.options.labels).untitled]],[`table`,{},[`tr`,{},...a.map(e=>[`th`,{},e.name])],...r.rows.map(e=>[`tr`,{},...a.map(t=>[`td`,{},JR(e,t)])])]]},renderText({node:e}){let t=e.attrs.data?LR(e.attrs.data):null;if(!t)return``;let n=VR(t);return[t.title,...t.rows.map(e=>JR(e,n))].filter(Boolean).join(` -`)},onCreate(){let{doc:e,readOnlyDoc:t,undoScope:n}=this.options;e&&!t&&n&&(NS.getState(this.editor.state)?.undoManager)?.addToScope(Gz(e))},addCommands(){let e=e=>{let t=PR(),{doc:n,readOnlyDoc:r}=this.options;return!n||r?{id:t,data:e}:(oB(n,t,e,(e,t)=>GB(this.editor,e,t)),{id:t,data:null})};return{insertDatabase:t=>({commands:n})=>n.insertContent([{type:this.name,attrs:e(t??tB(BB(this.options.labels)))},{type:`paragraph`}]),groupAsDatabase:()=>({state:t,dispatch:n,commands:r})=>{let i=JB(t.selection.$from,t.selection.$to);if(!i)return!1;if(!n)return!0;let a=zB(this.options.labels),o={id:PR(),name:a.typeTitle,type:`title`},s=[o],c=i.checks?{id:PR(),name:a.done,type:`checkbox`}:null;c&&s.push(c);let l=Date.now(),u={title:``,columns:s,rows:i.items.map((e,t)=>({id:PR(),cells:{[o.id]:e.text,...c&&e.checked?{[c.id]:!0}:{}},createdAt:l+t,createdBy:this.options.me?.()??null,body:e.rest.length?e.rest:void 0})),views:[FR(`table`,a.viewTable,s)]},d=this.type.create(e(u));return r.command(({tr:e})=>(e.replaceWith(i.from,i.to,d),e.setSelection(E.create(e.doc,i.from)),!0))}}},addKeyboardShortcuts(){return{"Mod-g":()=>this.editor.commands.groupAsDatabase()}},addProseMirrorPlugins(){let{doc:e,readOnlyDoc:t}=this.options,n=e&&!t?e:null,r=this.editor;return[new D({key:new Un(`databaseClipboard`),props:{transformCopied:t=>!e||!UB(t.content)?t:new p(HB(t.content,t=>{let n=Gz(e).get(String(t.attrs.id));return n instanceof Lb?t.type.create({...t.attrs,data:aB(n,VB)}):t}),t.openStart,t.openEnd),transformPasted:e=>UB(e.content)?new p(HB(e.content,e=>{let t=PR();if(!n)return e.type.create({...e.attrs,id:t});let i=e.attrs.data?LR(e.attrs.data):null,a=Gz(n).get(String(e.attrs.id)),o=i??(a instanceof Lb?aB(a,VB):tB(BB(this.options.labels)));return oB(n,t,qB(o),(e,t)=>GB(r,e,t)),e.type.create({id:t,data:null})}),e.openStart,e.openEnd):e},appendTransaction:(e,t,i)=>{if(!n||!e.some(e=>e.docChanged&&!e.getMeta(MS))||!e.some(e=>e.steps.some(e=>UB(e.slice?.content??s.empty))))return null;let a=new Set,o=[];if(i.doc.descendants((e,t)=>{if(e.type.name!==`database`)return;let n=String(e.attrs.id);return n&&a.has(n)&&o.push({pos:t,node:e}),a.add(n),!1}),!o.length)return null;let c=i.tr;for(let{pos:e,node:t}of o){let i=Gz(n).get(String(t.attrs.id)),a=PR();i instanceof Lb&&oB(n,a,qB(aB(i,VB)),(e,t)=>GB(r,e,t)),c.setNodeMarkup(e,void 0,{...t.attrs,id:a,data:null})}return c}})]},addNodeView(){let e=this.options;return({node:t,editor:n,getPos:r})=>{let i=t,a=e.labels??AR,o=e.doc,s=()=>n.isEditable&&!!o&&!e.readOnlyDoc,c=null,l=null,u=null,d=null,f=I(`div`,{class:`dw-db-node`}),p=()=>String(i.attrs.id),m=()=>{let e=o?Gz(o).get(p()):void 0;return e instanceof Lb?e:null},h=()=>{let t=m();return t?eB(t):i.attrs.data?LR(i.attrs.data):tB(BB(e.labels))},g=e=>{let t=o?Gz(o).get(e):void 0;if(t instanceof Lb)return eB(t);let r=null;return n.state.doc.descendants(t=>!r&&(t.type.name===`database`&&t.attrs.id===e&&t.attrs.data&&(r=LR(t.attrs.data)),!0)),r},_=new Map,v=t=>{let n=e.linkedPages;if(!n)return null;let r=_.get(t);if(!r){let e=n.open(t),i=e.onChange(ne);e.doc.on(`update`,ne),r={provider:e,stop:()=>{i(),e.doc.off(`update`,ne),e.destroy()}},_.set(t,r)}return r.provider},y=t=>!t||t===e.linkedPages?.self,b=new Set,x=e=>{if(y(e.page))return b.add(e.database),e.database===p()?h():g(e.database);let t=v(e.page);if(!t?.synced)return null;let n=Gz(t.doc).get(e.database);return n instanceof Lb?eB(n):null},S=(e,t,n)=>{let r=[],i=e=>{for(let a of e.toArray())if(a instanceof ox){if(a.nodeName===`database`){let e=String(a.getAttribute(`id`)??``);e&&r.push({page:t,database:e,title:n(e)?.title??``})}else i(a)}};return i(e),r},C={local:()=>{let e=[];return n.state.doc.descendants(t=>(t.type.name===`database`&&t.attrs.id&&t.attrs.id!==p()&&e.push({page:``,database:String(t.attrs.id),title:g(String(t.attrs.id))?.title??``}),!0)),e},searchPages:e.pages?t=>e.pages.search(t).then(e=>e.filter(e=>!y(e.id)).map(e=>({id:e.id,title:e.title}))):void 0,databasesOn:e.linkedPages?e=>new Promise(t=>{let n=v(e),r=()=>{t(S(n.doc.getXmlFragment(`default`),e,e=>{let t=Gz(n.doc).get(e);return t instanceof Lb?eB(t):null}))};if(n.synced)return r();let i=setTimeout(()=>{a(),t([])},8e3),a=n.onChange(()=>{n.synced&&(clearTimeout(i),a(),r())})}):void 0,read:x,openRecord:(t,r)=>{y(t.page)?LB(n,t.database,r):e.onNavigate?.(`/p/${encodeURIComponent(t.page)}${PB(t.database,r)}`)}},ee=e=>{for(let t of e)if((t.path.length?[String(t.path[0])]:[...t.keysChanged??[]]).some(e=>e!==p()&&b.has(e)))return ne()};o&&Gz(o).observeDeep(ee);let te;function ne(){clearTimeout(te),te=setTimeout(()=>de(),60)}let re=()=>gz(h(),x,a.database),ie=()=>({labels:a.database,colorNames:a.colors,locale:a.locale,files:e.files,people:e.people,store:c,linked:C}),ae=(t,n)=>{let r=e.rowExtensions;if(!r)return null;let i=m(),o=null;if(i&&(o=c?c.rowBody(n.id):KB(i,n.id),!o))return t.append(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),null;let s=new Vp({element:t,editable:!!c,extensions:r(o),content:o?void 0:{type:`doc`,content:n.body??[{type:`paragraph`}]},editorProps:{attributes:{class:`dw-prose dw-db-peek__prose`}}});return!o&&!n.body?.length&&t.replaceChildren(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),()=>s.destroy()},oe=e.recordLink,se=oe?t=>{let n=oe(PB(p(),t));RB(n).then(t=>t&&e.onLinkCopied?.(n))}:void 0;f.addEventListener(IB,e=>{let t=e.detail,n=re();n.rows.some(e=>e.id===t.row)&&(t.found=!0,t.container||f.scrollIntoView?.({block:`start`}),ue(t.row,n.rows.map(e=>e.id),t.container?{container:t.container,onLeave:t.onClose}:void 0))});let ce=e.recordPage,le,ue=(e,t,n)=>{u?.close(!1),le=n,u=new Uz({ctx:{...ie()},mountBody:ae,copyLink:se,openPage:ce&&!n?e=>ce(p(),e):void 0,page:n},re(),e,t,()=>{u=null,le=void 0})},de=()=>{let e=re();d?.update(e,{store:c}),u?.update(e,{store:c})},fe=()=>{if(l?.(),l=null,c=null,!o)return;let t=m();if(!t&&s()){let a=i.attrs.data?LR(i.attrs.data):tB(BB(e.labels)),s=p()?p():PR();oB(o,s,a,(e,t)=>GB(n,e,t)),queueMicrotask(()=>{let e=typeof r==`function`?r():void 0;e!==void 0&&n.state.doc.nodeAt(e)?.type.name===`database`&&n.view.dispatch(n.state.tr.setNodeMarkup(e,void 0,{...i.attrs,id:s,data:null}).setMeta(`addToHistory`,!1))}),t=Gz(o).get(s)}let a=Gz(o),d=e=>{if(!e.keysChanged.has(p()))return;fe(),de();let t=u?.row;t&&re().rows.some(e=>e.id===t)&&ue(t,[t],le)};if(a.observe(d),t){s()&&(c=new rB(o,t,()=>e.me?.()??null));let n=t,r=()=>de();n.observeDeep(r),l=()=>{a.unobserve(d),n.unobserveDeep(r)}}else l=()=>a.unobserve(d)};fe(),d=new AB({...ie(),openRow:ue,undo:()=>n.commands.undo?.(),redo:()=>n.commands.redo?.(),notify:e.notify,copyLink:se},re()),f.append(d.dom);let pe=s(),me=()=>{s()!==pe&&(pe=s(),fe(),de())};return n.on(`update`,me),n.on(`transaction`,me),{dom:f,update(e){if(e.type!==i.type)return!1;let t=e.attrs.id!==i.attrs.id;return i=e,t&&fe(),de(),!0},ignoreMutation:()=>!0,stopEvent:e=>e.type!==`dragstart`||e.target!==f,destroy(){l?.(),clearTimeout(te),o&&Gz(o).unobserveDeep(ee);for(let e of _.values())e.stop();_.clear(),u?.close(!1),d?.destroy(),n.off(`update`,me),n.off(`transaction`,me)}}}}});function GB(e,t,n){try{yw(e.schema,{type:`doc`,content:t},n)}catch{}}function KB(e,t){let n=e.get(`rows`);if(!(n instanceof Pb))return null;for(let e of n.toArray())if(e.get(`id`)===t){let t=e.get(`body`);return t instanceof ix&&t.length?t:null}return null}function qB(e){return{...e,rows:e.rows.map(e=>({...e,id:PR()}))}}function JB(e,t){for(let t=e.depth;t>0;t--){let n=e.node(t);if([`bulletList`,`orderedList`,`taskList`].includes(n.type.name)){let r=[];return n.forEach(e=>{let t=e.firstChild,n=[];e.forEach((e,t,r)=>{r>0&&n.push(e.toJSON())}),r.push({text:t?.textContent??``,checked:!!e.attrs.checked,rest:n})}),{from:e.before(t),to:e.after(t),checks:n.type.name===`taskList`,items:r}}}if(e.depth<1)return null;let n=e.before(1),r=t.after(Math.min(1,t.depth)||1),i=[];return e.doc.nodesBetween(n,r,(e,t)=>t=r?!1:(e.isTextblock&&e.textContent.trim()&&i.push({text:e.textContent,checked:!1,rest:[]}),!e.isTextblock)),i.length>1?{from:n,to:r,checks:!1,items:i}:null}function YB(e){let t=MS.getState(e);return t?.type&&t.binding&&t.doc?t:null}function XB(e,t){let n=YB(e);if(!n||!t?.from||!t.to)return null;try{let r=e=>jS(n.doc,n.type,ly(gg(e)),n.binding.mapping),i=r(t.from),a=r(t.to);return i===null||a===null||a<=i||a>e.doc.content.size?null:{from:i,to:a}}catch{return null}}var ZB=new Un(`docwellComments`);function QB(e,t,n){let r=[];for(let i of t){let t=XB(e,i.anchor);t&&r.push(vs.inline(t.from,t.to,{class:i.id===n?`dw-comment is-active`:`dw-comment`,"data-comment":i.id}))}return xs.create(e.doc,r)}var $B=Tp.create({name:`commentHighlights`,addOptions(){return{onSelect:void 0}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:ZB,state:{init:()=>({marks:[],active:``,decos:xs.empty}),apply(e,t,n,r){let i=e.getMeta(ZB);if(i)return{...i,decos:QB(r,i.marks,i.active)};if(!e.docChanged||!t.marks.length)return t;let a=e.getMeta(MS)?.isChangeOrigin;return{...t,decos:a?QB(r,t.marks,t.active):t.decos.map(e.mapping,e.doc)}}},props:{decorations:e=>ZB.getState(e)?.decos??xs.empty,handleClick(t,n,r){let i=r.target?.closest?.(`[data-comment]`)?.getAttribute(`data-comment`);return i&&e()?.(i),!1}}})]}}),eV=/^(\d{4})-(\d{2})-(\d{2})$/;function tV(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function nV(e){let t=eV.exec(e);if(!t)return null;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return tV(n)===e?n:null}function rV(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function iV(e,t){return Math.round((t.getTime()-e.getTime())/864e5)}function aV(e,t,n=new Date){let r=nV(e);if(!r)return e;let i=t.dates,a=iV(rV(n,0),r);return a===0?i.today:a===1?i.tomorrow:a===-1?i.yesterday:new Intl.DateTimeFormat(t.locale,{month:`short`,day:`numeric`,year:r.getFullYear()===n.getFullYear()?void 0:`numeric`}).format(r)}function oV(e,t){let n=nV(e);return n?new Intl.DateTimeFormat(t.locale,{dateStyle:`full`}).format(n):e}function sV(e,t,n,r=new Date){let i=t.dates,a=e.trim().toLowerCase(),o=!1;for(let e of new Set([i.remindWord.toLowerCase(),`remind`])){if(a.startsWith(e)){o=!0,a=a.slice(e.length).trim();break}if(a.length>=3&&e.startsWith(a)){o=!0,a=``;break}}if(o&&!n)return[];let s=rV(r,0);if(!a)return o?[1,0,7].map(e=>({date:tV(rV(s,e)),remind:o})):[{date:tV(s),remind:!1},...n?[{date:tV(rV(s,1)),remind:!0}]:[]];let c=[{words:[i.today,`today`],date:s},{words:[i.tomorrow,`tomorrow`],date:rV(s,1)},{words:[i.nextWeek,`next week`],date:rV(s,7)}];o||c.push({words:[i.yesterday,`yesterday`],date:rV(s,-1)});let l=e=>new Intl.DateTimeFormat(e,{weekday:`long`});for(let e=1;e<=7;e++){let n=rV(s,e);c.push({words:[l(t.locale).format(n),l(`en`).format(n)],date:n})}let u=[];nV(a)&&u.push({date:a,remind:o});for(let e of c)e.words.some(e=>e.toLowerCase().startsWith(a))&&u.push({date:tV(e.date),remind:o});return u.filter((e,t)=>u.findIndex(t=>t.date===e.date)===t).slice(0,5)}function cV(e,t){let n=e.toLowerCase().split(` `),r=[t.dates.remindWord,`remind`,t.dates.nextWeek.split(` `)[0]??``,`next`];return n.length>1&&n.length<=3&&r.some(e=>e&&e.toLowerCase()===n[0])}var lV=Jp.create({name:`dateMention`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:void 0,me:()=>void 0,onOpen:void 0}},addAttributes(){return{date:{default:``,parseHTML:e=>e.getAttribute(`data-date`)??``,renderHTML:e=>({"data-date":e.date})},remind:{default:``,parseHTML:e=>e.getAttribute(`data-remind`)??``,renderHTML:e=>e.remind?{"data-remind":e.remind}:{}},tz:{default:``,parseHTML:e=>e.getAttribute(`data-tz`)??``,renderHTML:e=>e.tz?{"data-tz":e.tz}:{}}}},parseHTML(){return[{tag:`span[data-type="date"]`}]},renderHTML({node:e,HTMLAttributes:t}){return[`span`,A({"data-type":`date`,class:`dw-date`},t),aV(e.attrs.date,this.options.labels)]},renderText({node:e}){return aV(e.attrs.date,this.options.labels)},addNodeView(){let{labels:e,me:t,onOpen:n}=this.options;return({node:r,editor:i,getPos:a})=>{let o=r,s=document.createElement(`span`);s.dataset.type=`date`,s.className=`dw-date`,s.contentEditable=`false`,s.classList.toggle(`is-link`,!!n);let c=null,l=()=>{let t=o.attrs.date,n=o.attrs.remind,r=!!nV(t)&&t{let t=typeof a==`function`?a():void 0;t!==void 0&&i.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...o.attrs,...e}),!0)).run()};return s.addEventListener(`mousedown`,r=>{c||(i.isEditable?(r.preventDefault(),c=fV(s,i,o,e,t(),u,()=>c=null,n)):n&&nV(o.attrs.date)&&(r.preventDefault(),n(o.attrs.date)))}),{dom:s,update(e){return e.type===o.type&&(o=e,l(),!0)},ignoreMutation:()=>!0,stopEvent:e=>s.contains(e.target)&&e.type!==`mousedown`,destroy(){c?.()}}}}});function uV(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone??``}catch{return``}}function dV(e,t,n,r){let i={date:n.date,remind:n.remind&&r?r:``,tz:n.remind&&r?uV():``};e.chain().focus().insertContentAt(t,[{type:`dateMention`,attrs:i},{type:`text`,text:` `}]).run()}function fV(e,t,n,r,i,a,o,s){let c=r.dates,l=document.createElement(`div`);l.className=`dw-date-pop`,l.setAttribute(`role`,`dialog`),l.setAttribute(`aria-label`,c.edit);let u=document.createElement(`input`);u.type=`date`,u.className=`dw-input`,u.value=n.attrs.date,u.setAttribute(`aria-label`,c.edit),u.addEventListener(`change`,()=>{nV(u.value)&&a({date:u.value})}),l.append(u);let d=n.attrs.remind;if(d&&d!==i){let e=document.createElement(`p`);e.className=`dw-date-pop__note`,e.textContent=c.someoneElse,l.append(e)}else if(i){let e=document.createElement(`label`);e.className=`dw-date-pop__check`;let t=document.createElement(`input`);t.type=`checkbox`,t.checked=d===i,t.addEventListener(`change`,()=>a(t.checked?{remind:i,tz:uV()}:{remind:``,tz:``})),e.append(t,document.createTextNode(c.remindMe));let n=document.createElement(`span`);n.className=`dw-date-pop__note`,n.textContent=c.reminderAt,l.append(e,n)}if(s){let e=document.createElement(`button`);e.type=`button`,e.className=`dw-date-pop__open`,e.textContent=c.openJournal??`Open journal`,e.addEventListener(`click`,()=>{let e=n.attrs.date;h(),nV(e)&&s(e)}),l.append(e)}document.body.append(l);let f=Oj(e,l,()=>{Mj(e,l,{placement:`bottom-start`,strategy:`fixed`,middleware:[kj(6),jj(),Aj({padding:8})]}).then(({x:e,y:t})=>Object.assign(l.style,{left:`${e}px`,top:`${t}px`}))}),p=t=>{!l.contains(t.target)&&!e.contains(t.target)&&h()},m=e=>{e.key===`Escape`&&(e.preventDefault(),h(),t.commands.focus())};function h(){f(),l.remove(),document.removeEventListener(`mousedown`,p,!0),document.removeEventListener(`keydown`,m,!0),o()}return document.addEventListener(`mousedown`,p,!0),document.addEventListener(`keydown`,m,!0),u.focus(),h}function pV(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=kf(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.map(kf).join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function mV(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,` -`);return/\s/.test(n)}):!1}function hV(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function gV(e,t,n,r){return n?()=>{let n=r.getState(e.state)?.decorationId;return t.dom.querySelector(`[data-decoration-id="${n}"]`)?.getBoundingClientRect()||null}:hV(e)}function _V({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a?.({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!mV(r)}function vV({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function yV({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:r,decorationEmptyClass:i,renderer:a,dispatchExit:o}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var s;return a==null||(s=a.onKeyDown)==null||s.call(a,{view:t,event:n,range:i.range}),o(t),!0}return(a==null||(r=a.onKeyDown)==null?void 0:r.call(a,{view:t,event:n,range:i.range}))||!1},decorations(a){let{active:o,range:s,decorationId:c,query:l}=e.getState(a);if(!o)return null;let u=!l?.length,d=[n];return u&&d.push(i),xs.create(a.doc,[vs.inline(s.from,s.to,{nodeName:t,class:d.join(` `),"data-decoration-id":c||void 0,"data-decoration-content":r})])}}}function bV({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(yf.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}}function xV({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i?.(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e?.()},e)}),s=()=>{n?.abort(),a(),n=null};return{abort:s,fetch:async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}}}}function SV({placement:e,offset:t,flip:n,floatingUi:r}){var i;let a=[kj({mainAxis:t.mainAxis??4,crossAxis:t.crossAxis??0})];return n&&a.push(jj()),r!=null&&(i=r.middleware)!=null&&i.length&&a.push(...r.middleware),{placement:e,strategy:r?.strategy??`absolute`,middleware:a}}function CV(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function wV({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,s={})=>{let c={getBoundingClientRect:()=>e()??new DOMRect,contextElement:t},l=!1,u=!o.isConnected;u&&CV(r).appendChild(o),s.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let d=Oj(c,o,()=>{Mj(c,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{s.onPosition?s.onPosition({x:e,y:t,placement:n,strategy:r}):(Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),l||(l=!0,o.style.visibility=``))})},s.autoUpdate),f;return i&&(f=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,f,!0)),()=>{d(),f&&document.removeEventListener(`pointerdown`,f,!0),u&&o.remove()}}}function TV({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,_=xV({editor:e,items:n}),v=SV({placement:s,offset:c,flip:u,floatingUi:d});function y(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{let b=t.getState(d),x=t.getState(n.state);if(!b||!x)return;let S=null,C=b.query!==x.query,ee=b.text!==x.text,te=b.range.from!==x.range.from||b.range.to!==x.range.to,ne=C||ee||te;if(!b.active&&x.active)S=`started`;else if(b.active&&!x.active)S=`stopped`;else if(x.active&&ne)S=`updated`;else return;let re=S===`stopped`?b:x,ie=n.dom.querySelector(`[data-decoration-id="${re.decorationId}"]`),ae=m(n,ie),oe=i===0||(re.query?re.query.length>=i:!1),se=(S===`started`||S===`updated`)&&oe;if(g={editor:e,range:re.range,query:re.query||``,text:re.text||``,items:o??[],command:t=>p({editor:e,range:re.range,props:t}),decorationNode:ie,clientRect:ae,loading:se,placement:s,offset:{mainAxis:c.mainAxis??4,crossAxis:c.crossAxis??0},container:l,flip:u,floatingUi:v,mount:wV({getReferenceRect:ae,contextElement:n.dom,config:v,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},S===`started`){var ce;r==null||(ce=r.onBeforeStart)==null||ce.call(r,g)}if(S===`updated`){var le;r==null||(le=r.onBeforeUpdate)==null||le.call(r,g)}if(S===`started`&&y(S,g),S===`started`||S===`updated`){if(!se)_.abort(),g={...g,items:o??[],loading:!1};else{g={...g,items:o??[],loading:!0},S=`updated`,y(S,g);let e=await _.fetch(re.query||``,a);if(e.status===`aborted`)return;if(!t.getState(n.state)?.active){_.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}}S===`stopped`?(_.abort(),y(S,g),g=void 0):S===`updated`&&y(S,g)},destroy:()=>{var e;_.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}var EV=new Un(`suggestion`);function DV({pluginKey:e=EV,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],minQueryLength:p=0,debounce:m=0,initialItems:h,placement:g=`bottom-start`,offset:_={},container:v,flip:y=!0,floatingUi:b,dismissOnOutsideClick:x=!0,render:S=()=>({}),allow:C=()=>!0,findSuggestionMatch:ee=pV,shouldShow:te,shouldResetDismissed:ne}){let re=S?.(),ie=r&&!i,ae=(n,r)=>gV(t,n,r,e);function oe(e){return _V({...e,editor:t,shouldResetDismissed:ne,effectiveAllowSpaces:ie})}let se=t=>vV({view:t,pluginKeyRef:e});return new D({key:e,view:()=>TV({editor:t,pluginKey:e,items:f,renderer:re,minQueryLength:p,debounce:m,initialItems:h,placement:g,offset:_,container:v,flip:y,floatingUi:b,dismissOnOutsideClick:x,command:d,clientRectFor:ae,dispatchExit:se}),state:bV({editor:t,char:n,effectiveAllowSpaces:ie,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,findSuggestionMatch:ee,allow:C,shouldShow:te,shouldKeepDismissed:oe,pluginKey:e}),props:yV({pluginKey:e,decorationTag:s,decorationClass:c,decorationContent:l,decorationEmptyClass:u,renderer:re,dispatchExit:se})})}var OV=DV,kV=e=>`/p/${encodeURIComponent(e)}`,AV=/^\/p\/([A-Za-z0-9_-]+)\/?(?:[?#].*)?$/;function jV(e){return AV.exec(e)?.[1]??``}function MV(e,t,n,r=`Untitled`){let i=`${n.icon?`${n.icon} `:``}${n.title||r}`;e.chain().focus().deleteRange(t).insertContent([{type:`text`,text:i,marks:[{type:`link`,attrs:{href:kV(n.id)}}]},{type:`text`,text:` `}]).run()}async function NV(e,t,n){if(!t.create)return;let{from:r,to:i,empty:a}=e.state.selection,o=a?``:e.state.doc.textBetween(r,i,` `).trim().slice(0,200),s=await t.create(o);a||!o?MV(e,{from:r,to:r},s,n):e.chain().focus().setTextSelection({from:r,to:i}).setLink({href:kV(s.id)}).run()}var PV=Tp.create({name:`pageLinks`,addOptions(){return{host:void 0,labels:null,onNavigate:void 0}},addProseMirrorPlugins(){let{host:e,onNavigate:t}=this.options,n=this.options.labels,r=[];return e&&r.push(OV({editor:this.editor,pluginKey:new Un(`pageLinks`),char:`[[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Bj({label:n.pageLinks,empty:n.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>MV(e.editor,e.range,t)})})),t&&r.push(new D({key:new Un(`pageLinkClicks`),props:{handleClick:(e,n,r)=>{let i=(r.target?.closest?.(`a[href]`))?.getAttribute(`href`)??``;return!jV(i)||e.editable&&!(r.ctrlKey||r.metaKey)?!1:(r.preventDefault(),t(i),!0)}}})),r}});function FV(e,t,n){e.chain().focus().deleteRange(t).insertSyncedPage(n).run()}var IV=Jp.create({name:`syncedPage`,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,pages:void 0,labels:null,onNavigate:void 0,nested:void 0}},addAttributes(){return{page:{default:``,parseHTML:e=>e.getAttribute(`data-page`)??``,renderHTML:e=>({"data-page":e.page})},title:{default:``,parseHTML:e=>e.getAttribute(`data-title`)??``,renderHTML:e=>e.title?{"data-title":e.title}:{}},icon:{default:``,parseHTML:e=>e.getAttribute(`data-icon`)??``,renderHTML:e=>e.icon?{"data-icon":e.icon}:{}},folded:{default:!1,parseHTML:e=>e.hasAttribute(`data-folded`),renderHTML:e=>e.folded?{"data-folded":``}:{}}}},parseHTML(){return[{tag:`div[data-type='syncedPage']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=`${e.attrs.icon?`${e.attrs.icon} `:``}${e.attrs.title||`…`}`;return[`div`,A(t,{"data-type":`syncedPage`}),[`a`,{href:kV(String(e.attrs.page))},n]]},addCommands(){return{insertSyncedPage:e=>({commands:t})=>t.insertContent([{type:this.name,attrs:{page:e.id,title:e.title,icon:e.icon??``}},{type:`paragraph`}])}},addProseMirrorPlugins(){let{pages:e}=this.options,t=this.options.labels;return e?[OV({editor:this.editor,pluginKey:new Un(`syncedPages`),char:`![[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Bj({label:t.blocks.syncedPage,empty:t.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>FV(e.editor,e.range,t)})})]:[]},addNodeView(){let{host:e,onNavigate:t,nested:n}=this.options,r=this.options.labels.blocks;return({node:i,editor:a,getPos:o})=>{let s=i,c=String(s.attrs.page),l=document.createElement(`div`);l.className=`dw-synced`,l.dataset.type=`syncedPage`,l.contentEditable=`false`;let u=document.createElement(`div`);u.className=`dw-synced__head`;let d=document.createElement(`a`);d.className=`dw-synced__title`,d.href=kV(c);let f=zj(`copy`,14);f.classList.add(`dw-synced__badge`);let p=document.createElement(`button`);p.type=`button`,p.className=`dw-synced__btn`;let m=document.createElement(`button`);m.type=`button`,m.className=`dw-synced__btn`,m.textContent=r.syncedOpen,u.append(f,d,p,m);let h=document.createElement(`div`);h.className=`dw-synced__body`,l.append(u,h);let g=e=>{e.preventDefault(),t?t(kV(c)):window.location.assign(kV(c))};d.addEventListener(`click`,g),m.addEventListener(`click`,g);let _=e=>{let t=typeof o==`function`?o():void 0;t!==void 0&&a.view.dispatch(a.state.tr.setNodeMarkup(t,void 0,{...s.attrs,...e}))},v=null,y=()=>v??!!s.attrs.folded;p.addEventListener(`click`,()=>{a.isEditable?_({folded:!s.attrs.folded}):(v=!y(),ne())});let b=null,x=null,S=null,C=e=>{let t=document.createElement(`p`);t.className=`dw-synced__note`,t.textContent=e,h.replaceChildren(t)},ee=()=>{S?.(),x?.destroy(),b?.destroy(),S=null,x=null,b=null},te=()=>{if(x||!e||!n)return;if(c===e.self)return C(r.syncedSelf);b=e.open(c),C(r.syncedLoading);let t=b,i=()=>{t.status===`denied`?(ee(),C(r.syncedDenied)):t.synced&&!x&&(h.replaceChildren(),x=new Vp({element:h,editable:!1,extensions:n(t.doc),editorProps:{attributes:{class:`dw-prose`}}}))};S=t.onChange(i),i()};function ne(){let t=s.attrs.title;d.textContent=`${s.attrs.icon?`${s.attrs.icon} `:``}${t||r.syncedPage}`;let n=y();l.classList.toggle(`is-folded`,n),p.textContent=n?r.syncedUnfold:r.syncedFold,p.setAttribute(`aria-expanded`,String(!n)),n?(ee(),h.replaceChildren()):e?te():h.replaceChildren()}return ne(),e?.meta(c).then(e=>{e?a.isEditable&&(e.title!==s.attrs.title||e.icon!==s.attrs.icon)?_({title:e.title,icon:e.icon}):d.textContent=`${e.icon?`${e.icon} `:``}${e.title||r.syncedPage}`:y()||C(r.syncedDenied)}),{dom:l,update(e){return e.type!==s.type||String(e.attrs.page)!==c?!1:(s=e,ne(),!0)},ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof globalThis.Node&&(u.contains(e.target)||h.contains(e.target)),destroy:ee}}}});function LV(e){let t=document.createElement(`div`);t.className=`dw-diagram-editor`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,e);let n=document.createElement(`p`);n.className=`dw-diagram-editor__status`,t.append(n),document.body.append(t);let r=document.body.style.overflow;return document.body.style.overflow=`hidden`,{root:t,status:e=>{n.textContent=e,n.hidden=!e},close:()=>{t.remove(),document.body.style.overflow=r}}}async function RV(e,t){let n=await fetch(e.resolve(t));if(!n.ok)throw Error(`loading the drawing failed (${n.status})`);return n.text()}function zV(e,t){return new File([e],t,{type:`image/svg+xml`})}function BV(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n)}function VV(e,t,n){return new Promise(r=>{let i=LV(n.slash.drawio?.label??`Draw.io`),a=document.createElement(`iframe`),o=new URL(e);for(let[e,t]of Object.entries({embed:`1`,proto:`json`,spin:`1`,saveAndExit:`1`,noExitBtn:`0`}))o.searchParams.set(e,t);a.src=o.toString(),a.className=`dw-diagram-editor__frame`,a.title=n.slash.drawio?.label??`Draw.io`;let s=document.createElement(`div`);s.className=`dw-diagram-editor__bar`;let c=document.createElement(`button`);c.type=`button`,c.className=`dw-source__btn`,c.textContent=n.blocks.cancel,c.addEventListener(`click`,()=>d(null)),s.append(c),i.root.append(s,a),i.status(``);let l=e=>a.contentWindow?.postMessage(JSON.stringify(e),o.origin),u=!1,d=e=>{window.removeEventListener(`message`,f),i.close(),r(e)},f=e=>{if(e.source!==a.contentWindow||e.origin!==o.origin||typeof e.data!=`string`)return;let n;try{n=JSON.parse(e.data)}catch{return}switch(n.event){case`init`:l({action:`load`,autosave:0,xml:t?`data:image/svg+xml;base64,${BV(t)}`:``});break;case`save`:u=!0,l({action:`export`,format:`xmlsvg`,spinKey:`saving`});break;case`export`:{let e=n.data??``,t=e.indexOf(`,`),r=e.slice(0,t),i=e.slice(t+1),a=r.includes(`;base64`)?new TextDecoder().decode(Uint8Array.from(atob(i),e=>e.charCodeAt(0))):decodeURIComponent(i);d(u?a:null);break}case`exit`:d(null)}};window.addEventListener(`message`,f)})}async function HV(e,t,n){let r=LV(n.slash.excalidraw?.label??`Excalidraw`);r.status(``);try{let{openExcalidraw:i}=await e();return await i(r.root,t,n)}finally{r.close()}}var UV=!1;function WV(e){return Jp.create({name:e,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,loadExcalidraw:void 0,labels:null,drawioUrl:void 0,onError:void 0}},addAttributes(){return{src:{default:``},alt:{default:``}}},parseHTML(){return[{tag:`figure[data-type='${e}']`,getAttrs:e=>({src:e.querySelector(`img`)?.getAttribute(`src`)??``})}]},renderHTML({node:t,HTMLAttributes:n}){return[`figure`,A(n,{"data-type":e}),[`img`,{src:String(t.attrs.src),alt:String(t.attrs.alt||e)}]]},addCommands(){return{insertDiagram:e=>({commands:t})=>(UV=!0,t.insertContent({type:e,attrs:{src:``}}))}},addNodeView(){return({node:t,editor:n,getPos:r})=>{let i=this.options,a=i.labels,o=document.createElement(`figure`);o.className=`dw-diagram dw-diagram--${e}`,o.setAttribute(`data-type`,e);let s=document.createElement(`img`);s.className=`dw-diagram__img`;let c=document.createElement(`p`);c.className=`dw-diagram__empty`,c.textContent=e===`drawio`?a.blocks.emptyDrawio:a.blocks.emptyExcalidraw;let l=document.createElement(`button`);l.type=`button`,l.className=`dw-diagram__edit`,l.textContent=a.blocks.edit,o.append(s,c,l);let u=``,d=t=>{u=String(t.attrs.src??``),s.hidden=!u,c.hidden=!!u,u&&(s.src=i.host?i.host.resolve(u):u,s.alt=String(t.attrs.alt||a.slash[e]?.label||e))};d(t);let f=!1,p=async()=>{if(!f&&m()&&i.host?.upload){f=!0;try{let t=u?await RV(i.host,u):``,o=e===`drawio`?await VV(i.drawioUrl||`https://embed.diagrams.net`,t,a):await HV(i.loadExcalidraw,t,a);if(o===null)return;let s=await i.host.upload(zV(o,`${e===`drawio`?`diagram.drawio`:`drawing.excalidraw`}.svg`)),c=typeof r==`function`?r():void 0;c!==void 0&&GV(n,c,e,s.url)}catch(e){i.onError?.(e)}finally{f=!1}}},m=()=>n.isEditable&&!!i.host?.upload&&(e===`drawio`||!!i.loadExcalidraw),h=()=>l.hidden=!m()||!u;return h(),n.on(`update`,h),o.addEventListener(`dblclick`,()=>void p()),c.addEventListener(`click`,()=>void p()),l.addEventListener(`click`,()=>void p()),UV&&(UV=!1,queueMicrotask(()=>void p())),{dom:o,update:t=>t.type.name===e&&(d(t),h(),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target===l||e.target===c,destroy:()=>n.off(`update`,h)}}}})}function GV(e,t,n,r){e.chain().setNodeSelection(t).updateAttributes(n,{src:r}).run()}var KV=WV(`drawio`),qV=WV(`excalidraw`),JV=null;function YV(e){JV?.();let t=document.createElement(`div`);t.className=`dw-source`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,e.label);let n=document.createElement(e.multiline?`textarea`:`input`);n.className=`dw-source__field`+(e.monospace?` dw-source__field--mono`:``),n.value=e.value,n.setAttribute(`aria-label`,e.label),n.spellcheck=!1,n instanceof HTMLTextAreaElement&&(n.rows=Math.min(16,Math.max(4,e.value.split(` -`).length+1)));let r=document.createElement(`div`);r.className=`dw-source__actions`;let i=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`dw-source__btn ${t}`,r.textContent=e,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,n),r};e.onRemove&&r.append(i(e.labels.remove,`dw-source__btn--danger`,()=>{u(!0),e.onRemove()}));let a=document.createElement(`span`);a.style.flex=`1`,r.append(a,i(e.labels.cancel,``,()=>u()),i(e.labels.done,`dw-source__btn--primary`,()=>o())),t.append(n,r),document.body.append(t);let o=()=>{let t=n.value;u(!0),e.onSave(t)};n.addEventListener(`input`,()=>e.onInput?.(n.value)),n.addEventListener(`keydown`,t=>{let n=t;n.key===`Escape`?(n.preventDefault(),u()):n.key===`Enter`&&(n.ctrlKey||n.metaKey||!e.multiline)&&(n.preventDefault(),o()),n.stopPropagation()});let s=n=>{!t.contains(n.target)&&!e.anchor.contains(n.target)&&u()};setTimeout(()=>document.addEventListener(`mousedown`,s),0);let c=Oj(e.anchor,t,()=>{Mj(e.anchor,t,{placement:`bottom-start`,middleware:[kj(6),jj(),Aj({padding:8})]}).then(({x:e,y:n})=>Object.assign(t.style,{left:`${e}px`,top:`${n}px`}))}),l=!1;function u(n=!1){l||(l=!0,c(),document.removeEventListener(`mousedown`,s),t.remove(),JV===d&&(JV=null),n||e.onCancel?.())}let d=()=>u();return JV=d,n.focus(),e.multiline||n.select(),d}var XV=[{pattern:/^https:\/\/(?:www\.|m\.)?youtube\.com\/(?:watch\?(?:.*&)?v=|shorts\/|embed\/|live\/)([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/youtu\.be\/([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?vimeo\.com\/(?:video\/)?(\d+)/,src:e=>`https://player.vimeo.com/video/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([\da-f]{32})/,src:e=>`https://www.loom.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[\w-]+/,src:(e,t)=>`https://www.figma.com/embed?embed_host=docwell&url=${encodeURIComponent(t.href)}`},{pattern:/^https:\/\/codepen\.io\/([\w-]+)\/(?:pen|embed)\/([\w-]+)/,src:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{pattern:/^https:\/\/open\.spotify\.com\/(?:embed\/)?(track|album|playlist|episode|show)\/(\w+)/,src:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`,ratio:`audio`},{pattern:/^https:\/\/docs\.google\.com\/(document|spreadsheets|presentation)\/d\/([\w-]+)/,src:e=>`https://docs.google.com/${e[1]}/d/${e[2]}/preview`,ratio:`tall`},{pattern:/^https:\/\/(?:www\.)?google\.com\/maps\/embed\?/,src:(e,t)=>t.href}];function ZV(e){let t;try{t=new URL(e.trim())}catch{return null}for(let e of XV){let n=e.pattern.exec(t.href);if(n)return{src:e.src(n,t),ratio:e.ratio??`video`}}return null}function QV(e){try{let t=new URL(e.trim());return t.protocol===`https:`||t.protocol===`http:`?t.href:``}catch{return``}}var $V=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}};function eH(e,t,n){let{node:r}=e.view.domAtPos(e.state.selection.from),i=r instanceof HTMLElement?r:r.parentElement??e.view.dom;return new Promise(e=>{let r=t.blocks;YV({anchor:i,value:`https://`,label:n,labels:{done:r.done,cancel:r.cancel,remove:r.remove},onSave:t=>e(QV(t)),onCancel:()=>e(``)})})}async function tH(e,t,n,r){let i=await eH(e,t,t.blocks.embedUrl);i&&(ZV(i)?e.chain().focus().insertEmbed(i).run():await rH(e,i,n,r))}async function nH(e,t,n,r){let i=await eH(e,t,t.blocks.linkUrl);i&&await rH(e,i,n,r)}async function rH(e,t,n,r){let i={url:t};if(n)try{i={...await n.preview(t),url:t}}catch(e){r?.(e)}e.chain().focus().insertLinkCard(i).run()}var iH=Jp.create({name:`embed`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{url:{default:``,parseHTML:e=>e.getAttribute(`data-url`)??``,renderHTML:e=>({"data-url":e.url})}}},parseHTML(){return[{tag:`div[data-type='embed']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=QV(String(e.attrs.url));return[`div`,A(t,{"data-type":`embed`}),[`a`,{href:n},n]]},addCommands(){return{insertEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e}})}},addNodeView(){return({node:e})=>{let t=this.options.labels.blocks,n=document.createElement(`figure`);n.className=`dw-embed`,n.setAttribute(`data-type`,`embed`),n.contentEditable=`false`;let r=e=>{let r=QV(e),i=ZV(r);if(n.replaceChildren(),!i){let e=document.createElement(`a`);e.href=r,e.target=`_blank`,e.rel=`noopener noreferrer`,e.textContent=r||t.embedInvalid,n.append(e);return}n.dataset.ratio=i.ratio;let a=document.createElement(`iframe`);a.className=`dw-embed__frame`,a.src=i.src,a.title=`${t.embed}: ${$V(r)}`,a.loading=`lazy`,a.allow=`fullscreen; picture-in-picture; encrypted-media; clipboard-write`,a.referrerPolicy=`strict-origin-when-cross-origin`,a.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`);let o=document.createElement(`figcaption`);o.className=`dw-embed__caption`;let s=document.createElement(`a`);s.href=r,s.target=`_blank`,s.rel=`noopener noreferrer`,s.textContent=$V(r),o.append(s),n.append(a,o)},i=String(e.attrs.url);return r(i),{dom:n,update:e=>e.type.name===`embed`&&(e.attrs.url!==i&&r(i=String(e.attrs.url)),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`)}}}}),aH=Jp.create({name:`linkCard`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){let e=e=>({default:``,parseHTML:t=>t.getAttribute(`data-${e}`)??``,renderHTML:t=>({[`data-${e}`]:t[e]})});return{url:e(`url`),title:e(`title`),description:e(`description`),image:e(`image`),site:e(`site`)}},parseHTML(){return[{tag:`div[data-type='link-card']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=QV(String(e.attrs.url));return[`div`,A(t,{"data-type":`link-card`}),[`a`,{href:n},String(e.attrs.title||n)]]},addCommands(){return{insertLinkCard:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e.url,title:e.title??``,description:e.description??``,image:e.image??``,site:e.site??``}})}},addNodeView(){return({node:e})=>{let t=document.createElement(`a`);t.className=`dw-linkcard`,t.setAttribute(`data-type`,`link-card`),t.contentEditable=`false`,t.target=`_blank`,t.rel=`noopener noreferrer`;let n=e=>{let n=QV(String(e.url));t.href=n,t.replaceChildren();let r=document.createElement(`span`);r.className=`dw-linkcard__text`;let i=document.createElement(`span`);if(i.className=`dw-linkcard__title`,i.textContent=String(e.title||``)||$V(n),r.append(i),e.description){let t=document.createElement(`span`);t.className=`dw-linkcard__desc`,t.textContent=String(e.description),r.append(t)}let a=document.createElement(`span`);a.className=`dw-linkcard__site`,a.textContent=String(e.site||``)||$V(n),r.append(a),t.append(r);let o=QV(String(e.image||``));if(o.startsWith(`https:`)){let e=document.createElement(`img`);e.className=`dw-linkcard__image`,e.src=o,e.alt=``,e.loading=`lazy`,e.referrerPolicy=`no-referrer`,e.onerror=()=>e.remove(),t.append(e)}},r=e;return n(e.attrs),t.addEventListener(`click`,e=>{this.editor.view.editable&&!(e.ctrlKey||e.metaKey)&&e.preventDefault()}),{dom:t,update:e=>e.type.name===`linkCard`&&(e.attrs!==r.attrs&&n(e.attrs),r=e,!0),ignoreMutation:()=>!0}}}}),oH=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,sH=Jp.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,A(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize,i=new Set([`src`,`width`,`height`]);return({node:a,getPos:o,HTMLAttributes:s,editor:c})=>{let l=document.createElement(`img`);l.draggable=!1;let u=A(this.options.HTMLAttributes,s);Object.entries(u).forEach(([e,t])=>{if(t!=null)switch(e){case`src`:case`width`:case`height`:break;default:l.setAttribute(e,t)}}),u.src!==null&&(l.src=u.src);let d={...s},f=e=>{typeof e==`string`&&e!==``?l.getAttribute(`src`)!==e&&(l.src=e):(l.hasAttribute(`src`)&&l.removeAttribute(`src`),l.src!==``&&(l.src=``))};f(s.src);let p=new qp({element:l,editor:c,node:a,getPos:o,onResize:(e,t)=>{l.style.width=`${e}px`,l.style.height=`${t}px`},onCommit:(e,t)=>{let n=o();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:e=>{if(e.type!==a.type)return!1;let t=Lu(e,c.extensionManager.attributes.filter(t=>t.type===e.type.name));return Object.keys(d).forEach(e=>{!i.has(e)&&!(e in t)&&l.removeAttribute(e)}),Object.entries(t).forEach(([e,t])=>{i.has(e)||(t==null?l.removeAttribute(e):l.setAttribute(e,t))}),f(t.src),d=t,!0},options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),m=p.dom,h=()=>{m.style.visibility=``,m.style.pointerEvents=``};return m.style.visibility=`hidden`,m.style.pointerEvents=`none`,l.complete&&l.naturalWidth>0?h():(l.onload=h,l.onerror=h),p}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[Up({find:oH,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});async function cH(e,t,n,r){if(t.upload)for(let i of n){let n=await t.upload(i),a=n.mime.startsWith(`image/`)?{type:`image`,attrs:{src:n.url,alt:n.name}}:{type:`fileAttachment`,attrs:{url:n.url,name:n.name,size:n.size,mime:n.mime,view:Fj(n.mime,n.name)?`preview`:`card`}};e.chain().focus().insertContentAt(r??e.state.selection.to,a).run(),r=void 0}}var lH=sH.extend({addOptions(){return{...this.parent(),host:void 0,inline:!1,allowBase64:!1}},addNodeView(){return({node:e})=>{let t=document.createElement(`img`),n=e=>{let n=String(e.attrs.src??``);t.src=this.options.host?this.options.host.resolve(n):n,t.alt=String(e.attrs.alt??``),e.attrs.title&&(t.title=String(e.attrs.title))};return n(e),t.draggable=!0,{dom:t,update:t=>t.type===e.type&&(n(t),!0)}}}});function uH(e){if(!e)return``;let t=[`B`,`KB`,`MB`,`GB`],n=0,r=e;for(;r>=1024&&n({editor:e,commands:t})=>{let n=e.getAttributes(this.name);return!e.isActive(this.name)||!Fj(n.mime,n.name)?!1:t.updateAttributes(this.name,{view:n.view===`preview`?`card`:`preview`})}}},parseHTML(){return[{tag:`div[data-type=file]`,getAttrs:e=>({url:e.getAttribute(`data-url`)??``,name:e.getAttribute(`data-name`)??e.textContent??`file`,size:Number(e.getAttribute(`data-size`)??0),mime:e.getAttribute(`data-mime`)??``,view:e.getAttribute(`data-view`)===`preview`?`preview`:`card`})}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`file`,"data-url":e.attrs.url,"data-name":e.attrs.name,"data-size":e.attrs.size,"data-mime":e.attrs.mime,"data-view":e.attrs.view}),[`a`,{href:e.attrs.url,download:e.attrs.name},e.attrs.name]]},addNodeView(){return({node:e})=>{let{host:t,loadPdf:n,labels:r}=this.options,i=document.createElement(`div`);i.className=`dw-file-block`,i.setAttribute(`data-type`,`file`);let a=document.createElement(`div`);a.className=`dw-file`;let o=document.createElement(`a`);o.className=`dw-file__name`,o.target=`_blank`,o.rel=`noopener`;let s=document.createElement(`span`);s.className=`dw-file__size`,a.append(o,s),i.append(a);let c=null,l=null,u=``,d=e=>{let a=String(e.attrs.url??``),d=t?t.resolve(a):a;o.href=d,o.textContent=String(e.attrs.name??`file`),s.textContent=uH(Number(e.attrs.size??0)),!(e.attrs.view===`preview`&&Fj(e.attrs.mime,e.attrs.name)&&a)||!n||!r?(l?.(),l=null,c?.remove(),c=null,u=``):u!==d&&(l?.(),c||(c=document.createElement(`div`),c.className=`dw-pdf`,c.tabIndex=0,c.setAttribute(`role`,`document`),i.append(c)),c.setAttribute(`aria-label`,String(e.attrs.name??`PDF`)),u=d,l=Ij(c,d,n,r))};return d(e),{dom:i,update:t=>t.type===e.type&&(d(t),!0),stopEvent:e=>!!c&&c.contains(e.target)&&e.type!==`mousedown`,ignoreMutation:()=>!0,destroy:()=>l?.()}}}}),fH=Tp.create({name:`fileDrop`,addOptions(){return{host:void 0,onError:void 0}},addProseMirrorPlugins(){let e=this.options.host;return e?[pH(()=>this.editor,e,this.options.onError)]:[]}});function pH(e,t,n){let r=(r,i)=>{let a=e();return!a||!r.length||!t.upload?!1:(cH(a,t,r,i).catch(n),!0)};return new D({key:new Un(`docwellFileDrop`),props:{handlePaste(e,t){return r([...t.clipboardData?.files??[]])},handleDrop(e,t){let n=[...t.dataTransfer?.files??[]];if(!n.length)return!1;let i=e.posAtCoords({left:t.clientX,top:t.clientY});return t.preventDefault(),r(n,i?.pos)}}})}var mH=new Un(`dwFind`),hH=``;function gH(e,t,n=!1){if(!t)return[];let r=n?t:t.toLowerCase(),i=[];return e.descendants((e,t)=>{if(!e.isTextblock)return!0;let a=``,o=[];e.forEach((e,n)=>{let r=t+1+n;if(e.isText){let t=e.text??``;for(let e=0;ee.from>=r);return a===-1&&(a=i.length?0:-1),{term:t,caseSensitive:n,matches:i,current:a}}function vH(e,t){return t&&e.setSelection(T.create(e.doc,t.from,t.to)).scrollIntoView(),e}var yH=Tp.create({name:`findReplace`,addCommands(){return{setFind:(e,t=!1)=>({state:n,tr:r,dispatch:i})=>{let a=_H(n.doc,e,t,n.selection.from);return r.setMeta(mH,{term:e,caseSensitive:t,near:n.selection.from}),i&&i(vH(r,a.matches[a.current])),!0},findStep:e=>({state:t,tr:n,dispatch:r})=>{let i=mH.getState(t);if(!i?.matches.length)return!1;let a=(i.current+e+i.matches.length)%i.matches.length;return n.setMeta(mH,{current:a}),r&&r(vH(n,i.matches[a])),!0},replaceCurrent:e=>({state:t,tr:n,dispatch:r})=>{let i=mH.getState(t),a=i?.matches[i.current];if(!i||!a)return!1;if(r){n.insertText(e,a.from,a.to),n.setMeta(mH,{term:i.term,caseSensitive:i.caseSensitive,near:a.from+e.length});let t=_H(n.doc,i.term,i.caseSensitive,a.from+e.length);r(vH(n,t.matches[t.current]))}return!0},replaceAll:e=>({state:t,tr:n,dispatch:r})=>{let i=mH.getState(t);if(!i?.matches.length)return!1;if(r){for(let t of[...i.matches].reverse())n.insertText(e,t.from,t.to);n.setMeta(mH,{term:i.term,caseSensitive:i.caseSensitive,near:0}),r(n)}return!0},clearFind:()=>({tr:e,dispatch:t})=>(t&&t(e.setMeta(mH,{clear:!0})),!0)}},addProseMirrorPlugins(){let e={term:``,caseSensitive:!1,matches:[],current:-1};return[new D({key:mH,state:{init:()=>e,apply(t,n,r,i){let a=t.getMeta(mH);if(a&&`clear`in a)return e;if(a&&`term`in a)return _H(i.doc,a.term,a.caseSensitive,a.near);if(a&&`current`in a)return{...n,current:a.current};if(!n.term||!t.docChanged)return n;let o=n.matches[n.current]?.from??0;return _H(i.doc,n.term,n.caseSensitive,t.mapping.map(o))}},props:{decorations(e){let t=mH.getState(e);return t?.matches.length?xs.create(e.doc,t.matches.map((e,n)=>vs.inline(e.from,e.to,{class:n===t.current?`dw-find dw-find-current`:`dw-find`}))):null}}})]}}),L=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15e.replace(bH,`-$1`).toLowerCase(),SH={"&":`&`,">":`>`,"<":`<`,'"':`"`,"'":`'`},CH=/[&><"']/g,wH=e=>String(e).replace(CH,e=>SH[e]),TH=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?TH(e.body[0]):e:e.type===`font`?TH(e.body):e,EH=new Set([`mathord`,`textord`,`atom`]),DH=e=>EH.has(TH(e).type),OH=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},kH={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format `},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color `,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro `,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness `,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size `,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand `,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function AH(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function jH(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:AH(Array.isArray(e.type)?e.type[0]:e.type)}function MH(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?jH(r):a?a(i):i}var NH=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(kH)){var n=kH[t];n&&MH(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new L(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=OH(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},PH=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return UH[WH[this.id]]}sub(){return UH[GH[this.id]]}fracNum(){return UH[KH[this.id]]}fracDen(){return UH[qH[this.id]]}cramp(){return UH[JH[this.id]]}text(){return UH[YH[this.id]]}isTight(){return this.size>=2}},FH=0,IH=1,LH=2,RH=3,zH=4,BH=5,VH=6,HH=7,UH=[new PH(FH,0,!1),new PH(IH,0,!0),new PH(LH,1,!1),new PH(RH,1,!0),new PH(zH,2,!1),new PH(BH,2,!0),new PH(VH,3,!1),new PH(HH,3,!0)],WH=[zH,BH,zH,BH,VH,HH,VH,HH],GH=[BH,BH,BH,BH,HH,HH,HH,HH],KH=[LH,RH,zH,BH,VH,HH,VH,HH],qH=[RH,RH,BH,BH,HH,HH,HH,HH],JH=[IH,IH,RH,RH,BH,BH,HH,HH],YH=[FH,IH,LH,RH,LH,RH,LH,RH],R={DISPLAY:UH[FH],TEXT:UH[LH],SCRIPT:UH[zH],SCRIPTSCRIPT:UH[VH]},XH=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function ZH(e){for(var t=0;t=i[0]&&e<=i[1])return n.name}return null}var QH=[];XH.forEach(e=>e.blocks.forEach(e=>QH.push(...e)));function $H(e){for(var t=0;t=QH[t]&&e<=QH[t+1])return!0;return!1}var eU=e=>e+` `+e,tU=80,nU=function(e,t){return`M95,`+(622+e+t)+` +`&&o++):i+=e,o++}return(i!==``||r.length)&&(r.push(i),n.push(r)),n}function dB(e,t){return e.includes(t)||/["\r\n]/.test(e)||/^\s|\s$/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function fB(e,t=`,`){return e.map(e=>e.map(e=>dB(e,t)).join(t)).join(`\r +`)}function pB(e,t,n){return fB([t.map(e=>e.name),...n.map(e=>t.map(t=>ZR(e,t)))])}function mB(e){let t=e.map(e=>e.trim()).filter(Boolean);if(!t.length)return`text`;if(t.every(e=>YR(e)!==null))return`number`;if(t.every(e=>/^\d{4}-\d{2}-\d{2}/.test(e)))return`date`;if(t.every(e=>/^(true|false|yes|no)$/i.test(e)))return`checkbox`;if(t.every(e=>/^https?:\/\/\S+$/.test(e)))return`link`;let n=new Set(t.map(e=>e.toLowerCase()));return t.length>=4&&n.size<=Math.max(2,t.length/3)&&t.every(e=>e.length<=40)?`select`:`text`}function hB(e,t,n){let r=e.trim();if(!r)return null;let i=e=>{let t=n.find(t=>t.name.toLowerCase()===e.toLowerCase());return t||(t={id:LR(),name:e,color:cz(n)},n.push(t)),t.id};switch(t.type){case`number`:return YR(r);case`progress`:{let e=YR(r.replace(`%`,``));return e===null?null:Math.max(0,Math.min(100,Math.round(e)))}case`checkbox`:return/^(true|yes|1|x|✓|done)$/i.test(r);case`date`:return qR(r)||null;case`select`:return i(r);case`multiSelect`:return[...new Set(r.split(/[,;]/).map(e=>e.trim()).filter(Boolean).map(i))];case`member`:case`attachment`:case`createdBy`:case`createdTime`:return null;default:return r}}function gB(e,t=`,`){let n=uB(e,t).filter(e=>e.some(e=>e.trim())),r=n[0]??[],i=n.slice(1),a=r.map((e,t)=>({id:LR(),name:e.trim()||`${t+1}`,type:t===0?`title`:mB(i.map(e=>e[t]??``))}));for(let e of a)e.type===`select`&&(e.options=[]);return{columns:a,rows:i.map(e=>{let t={};return a.forEach((n,r)=>{let i=hB(e[r]??``,n,n.options??[]);i!==null&&(!Array.isArray(i)||i.length)&&(t[n.id]=i)}),t})}}function _B(e,t){let n=[];return{index:e.map(e=>{let r=t.find(t=>t.name.trim().toLowerCase()===e.trim().toLowerCase());return!r&&e.trim()&&n.push(e.trim()),r??null}),missing:n}}function vB(e,t,n,r){let i=I(`select`,{class:`dw-db-select`,"aria-label":n});for(let n of t){let t=I(`option`,{value:n.value},n.label);n.value===e&&(t.selected=!0),i.append(t)}return i.addEventListener(`change`,()=>r(i.value)),i.addEventListener(`keydown`,e=>e.stopPropagation()),i}var yB=e=>e.map(e=>({value:e.id,label:e.name||`…`}));function bB(e,t,n,r){let i=e.labels;if(!$R(n.op))return null;if(t.type===`select`||t.type===`multiSelect`)return vB(typeof n.value==`string`?n.value:``,[{value:``,label:`—`},...(t.options??[]).map(e=>({value:e.id,label:e.name}))],i.value,r);let a=t.type===`date`||t.type===`createdTime`?`date`:t.type===`number`||t.type===`progress`?`number`:`text`,o=I(`input`,{class:`dw-db-input dw-db-input--small`,type:a,"aria-label":i.value,placeholder:i.value});return o.value=n.value===void 0||n.value===null?``:String(n.value),o.addEventListener(`keydown`,e=>e.stopPropagation()),o.addEventListener(`change`,()=>r(a===`number`?o.value===``?null:Number(o.value):o.value)),o}function xB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.filters),s=()=>r?.updateView(n.id,{filters:o}),c=()=>{t.replaceChildren(),o.length>1&&t.append(vB(n.filterMode,[{value:`and`,label:i.matchAll},{value:`or`,label:i.matchAny}],i.filter,e=>{n.filterMode=e,r?.updateView(n.id,{filterMode:n.filterMode})})),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noFilters)),o.forEach((n,r)=>{let l=a.find(e=>e.id===n.column);if(!l)return;let u=QR(l.type),d=I(`div`,{class:`dw-db-pop__line`},vB(n.column,yB(a),i.filter,e=>{let t=a.find(t=>t.id===e);o[r]={column:e,op:QR(t.type)[0]},s(),c()}),vB(n.op,u.map(e=>({value:e,label:OR(i,e)})),i.filter,e=>{o[r]={...n,op:e},$R(e)||delete o[r].value,s(),c()}),bB(e,l,n,e=>{o[r]={...o[r],value:e},s()}),EB(i.remove,()=>{o.splice(r,1),s(),c()}));t.append(d)}),r&&t.append(DB(i.addFilter,()=>{let e=a.find(e=>e.type!==`title`)??a[0];o.push({column:e.id,op:QR(e.type)[0]}),s(),c()}))};c()}function SB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.sorts),s=()=>r?.updateView(n.id,{sorts:o}),c=()=>{t.replaceChildren(),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noSorts)),o.forEach((e,n)=>{t.append(I(`div`,{class:`dw-db-pop__line`},vB(e.column,yB(a),i.sort,t=>{o[n]={...e,column:t},s()}),vB(e.desc?`desc`:`asc`,[{value:`asc`,label:i.ascending},{value:`desc`,label:i.descending}],i.sort,t=>{o[n]={...e,desc:t===`desc`},s()}),EB(i.remove,()=>{o.splice(n,1),s(),c()})))}),r&&t.append(DB(i.addSort,()=>{let e=new Set(o.map(e=>e.column)),t=a.find(t=>!e.has(t.id))??a[0];o.push({column:t.id,desc:!1}),s(),c()}))};c()}function CB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>zR.includes(e.type)),o=a.map(e=>({value:e.id,label:e.name||ER(i,e.type)}));n.type!==`kanban`&&o.unshift({value:``,label:i.noGrouping}),t.append(I(`label`,{class:`dw-db-pop__label`},i.groupBy),a.length||n.type!==`kanban`?vB(n.groupBy??``,o,i.groupBy,e=>r?.updateView(n.id,{groupBy:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noGroupColumn))}function wB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`date`||e.type===`createdTime`);t.append(I(`label`,{class:`dw-db-pop__label`},i.dateColumn),a.length?vB(n.dateColumn??``,[{value:``,label:`—`},...a.map(e=>({value:e.id,label:e.name||ER(i,e.type)}))],i.dateColumn,e=>r?.updateView(n.id,{dateColumn:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noDateColumn))}function TB(e,t,n){let r=e.store,i=e.labels,a=[...n.hidden],o=()=>r?.updateView(n.id,{hidden:a}),s=()=>{t.replaceChildren();let n=e.db.columns.filter(e=>e.type!==`title`);if(r&&n.length){let e=I(`button`,{type:`button`,class:`dw-db__btn`},a.length?i.showAll:i.hideAll);e.addEventListener(`click`,()=>{a=a.length?[]:n.map(e=>e.id),o(),s()}),t.append(I(`div`,{class:`dw-db-pop__row dw-db-pop__row--end`},e))}for(let n of e.db.columns){let e=n.type===`title`||!a.includes(n.id),c=I(`button`,{type:`button`,class:`dw-db-pop__item`,role:`switch`,"aria-checked":String(e),disabled:n.type===`title`||!r},I(`span`,{class:`dw-db-pop__check`},bz(Fz[n.type],14)),I(`span`,{class:`dw-db-pop__grow`},n.name||ER(i,n.type)),I(`span`,{class:e?`dw-db-switch is-on`:`dw-db-switch`}));c.addEventListener(`click`,()=>{a=e?[...a,n.id]:a.filter(e=>e!==n.id),o(),s()}),t.append(c)}};s()}function EB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":e,title:e},bz(`close`,14));return n.addEventListener(`click`,t),n}function DB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},bz(`plus`,14),I(`span`,{},e));return n.addEventListener(`click`,t),n}var OB=6,kB=48;function AB(e,t){e.classList.add(`dw-db-touch-handle`);let n=!1,r=-1,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0,f,p=0,m=()=>document.elementFromPoint(o,s),h=()=>{clearTimeout(f),cancelAnimationFrame(d),u&&(u.remove(),u=null,t.end()),t.source.classList.remove(`is-held`,`is-dragging`),n=!1,r=-1,p=Date.now()},g=()=>{if(!u)return;let e=oinnerWidth-kB),n=sinnerHeight-kB),r=!1;for(let[i,a]of[[`x`,e],[`y`,n]]){if(!a)continue;let e=jB(t.source,i)??(i===`y`?document.scrollingElement:null);if(!e)continue;let n=i===`x`?`scrollLeft`:`scrollTop`,o=e[n];e[n]+=a*12,r||=e[n]!==o}r&&t.over(m(),o,s),d=requestAnimationFrame(g)},_=e=>[...e.changedTouches].find(e=>e.identifier===r);e.addEventListener(`touchstart`,u=>{if(n||u.touches.length!==1)return;let d=u.changedTouches[0],p=u.target.closest(`input, textarea, select, [contenteditable='true']`);p&&e.contains(p)||(u.preventDefault(),n=!0,r=d.identifier,i=o=d.clientX,a=s=d.clientY,c=Date.now(),l=u.target,f=setTimeout(()=>{t.source.classList.add(`is-held`),navigator.vibrate?.(10)},500))},{passive:!1}),e.addEventListener(`touchmove`,e=>{let r=n&&_(e);if(r){if(e.preventDefault(),o=r.clientX,s=r.clientY,!u){if(Math.hypot(o-i,s-a)<=OB)return;clearTimeout(f),t.source.classList.remove(`is-held`),u=t.ghost();let e=t.source.getBoundingClientRect();Object.assign(u.style,{position:`fixed`,left:`${e.left}px`,top:`${e.top}px`,width:`${Math.max(80,Math.min(e.width,innerWidth-Math.max(e.left,0)-8))}px`,margin:`0`,pointerEvents:`none`,zIndex:`1000`}),u.classList.add(`dw-db-ghost`),document.body.append(u),t.source.classList.add(`is-dragging`),d=requestAnimationFrame(g)}u.style.transform=`translate(${o-i}px, ${s-a}px)`,t.over(m(),o,s)}},{passive:!1}),e.addEventListener(`touchend`,e=>{if(!n||!_(e))return;e.preventDefault();let r=u!==null,i=Date.now()-c>=500,a=l;r&&t.drop(m(),o,s),h(),r||(i&&t.hold?t.hold():a instanceof HTMLElement&&a.click())}),e.addEventListener(`touchcancel`,e=>{n&&_(e)&&h()});for(let t of[`contextmenu`,`dragstart`])e.addEventListener(t,e=>{(n||Date.now()-p<800)&&(e.preventDefault(),e.stopPropagation())},!0)}function jB(e,t){for(let n=e.parentElement;n;n=n.parentElement){let e=getComputedStyle(n),r=t===`x`?e.overflowX:e.overflowY;if((t===`x`?n.scrollWidth>n.clientWidth:n.scrollHeight>n.clientHeight)&&(r===`auto`||r===`scroll`))return n}return null}var MB=200,NB=class{host;dom=I(`div`,{class:`dw-db`,dataset:{type:`database`},contentEditable:`false`});db;viewId=null;search=``;editing=0;pending=!1;limit=MB;collapsed=new Set;sel=null;anchor=null;picked=new Set;month;titleEl=I(`div`,{class:`dw-db__title`});tabs=I(`div`,{class:`dw-db__tabs`,role:`tablist`});tools=I(`div`,{class:`dw-db__tools`});body=I(`div`,{class:`dw-db__body`});bulk=I(`div`,{class:`dw-db__bulk`});searchInput;buttons;constructor(e,t){this.host=e,this.db=t;let n=new Date;this.month={y:n.getFullYear(),m:n.getMonth()};let r=e.labels;this.searchInput=I(`input`,{class:`dw-db-input dw-db__search`,placeholder:r.search,"aria-label":r.search,hidden:!0}),this.searchInput.addEventListener(`input`,()=>{this.search=this.searchInput.value,this.limit=MB,this.drawBody()}),this.searchInput.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(this.searchInput.value=``,this.search=``,this.searchInput.hidden=!0,this.drawBody())}),this.buttons={search:xz(`search`,r.search,()=>{this.searchInput.hidden=!this.searchInput.hidden,this.searchInput.hidden||this.searchInput.focus()}),filter:xz(`filter`,r.filter,e=>this.panel(e,`filter`),r.filter),sort:xz(`sort`,r.sort,e=>this.panel(e,`sort`),r.sort),group:xz(`layers`,r.group,e=>this.panel(e,`group`),r.group),props:xz(`sliders`,r.properties,e=>this.panel(e,`props`)),more:xz(`more`,r.more,()=>this.moreMenu()),add:xz(`plus`,r.newRow,()=>this.addRow(),r.newRow)},this.buttons.add.classList.add(`dw-db__btn--primary`);let i=I(`div`,{class:`dw-db__head`},this.titleEl),a=I(`div`,{class:`dw-db__bar`},this.tabs,this.tools);this.tools.append(this.searchInput,this.buttons.search,this.buttons.filter,this.buttons.sort,this.buttons.group,this.buttons.props,this.buttons.more,this.buttons.add),this.dom.append(i,a,this.bulk,this.body),this.draw()}get labels(){return this.host.labels}get editable(){return!!this.host.store}get view(){return this.db.views.find(e=>e.id===this.viewId)??this.db.views[0]??PB}ctx(){return{...this.host,db:this.db,openRow:e=>this.openRow(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw())}}}update(e,t){this.db=e,t&&(this.host={...this.host,...t}),this.editing?this.pending=!0:this.draw()}destroy(){wz()}draw(){this.drawTitle(),this.drawTabs(),this.drawTools(),this.drawBody()}drawTitle(){let e=this.labels,t=this.db.title;if(this.titleEl.querySelector(`input`)===document.activeElement)return;if(!this.editable){this.titleEl.replaceChildren(I(`span`,{class:t?``:`is-empty`},t||e.untitled));return}let n=I(`input`,{class:`dw-db__title-input`,placeholder:e.untitled,"aria-label":e.untitled});n.value=t,n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&n.blur()}),n.addEventListener(`change`,()=>this.host.store?.setTitle(n.value)),this.titleEl.replaceChildren(n)}drawTabs(){let e=this.labels,t=this.view;if(this.tabs.replaceChildren(...this.db.views.map(n=>{let r=I(`button`,{type:`button`,class:n.id===t.id?`dw-db__tab is-active`:`dw-db__tab`,role:`tab`,"aria-selected":String(n.id===t.id)},bz(n.type===`kanban`?`cards`:n.type===`calendar`?`calendar`:`table`,14),I(`span`,{},n.name||kR(e,n.type)));return r.addEventListener(`click`,()=>{if(n.id===t.id&&this.editable)return this.viewMenu(r,n);this.viewId=n.id,this.sel=null,this.limit=MB,this.draw()}),r.addEventListener(`contextmenu`,e=>{this.editable&&(e.preventDefault(),this.viewMenu(r,n))}),r})),this.editable){let t=xz(`plus`,e.addView,()=>Jj(t,IR.map(t=>({id:t,label:kR(e,t),icon:t===`kanban`?`cards`:t===`calendar`?`calendar`:`table`,run:()=>{this.showView(this.host.store.addView(t,kR(e,t)))}})),e.addView));this.tabs.append(t)}}drawTools(){let e=this.view,t=this.buttons,n=(e,t)=>{e.classList.toggle(`is-on`,t>0);let n=e.querySelector(`span`);n&&(n.textContent=t?`${e.title} ${t}`:e.title)};n(t.filter,e.filters.length),n(t.sort,e.sorts.length),t.sort.hidden=e.type===`calendar`,t.group.classList.toggle(`is-on`,!!e.groupBy&&e.type===`table`),t.group.hidden=e.type===`calendar`,t.add.hidden=!this.editable,this.drawBulk()}drawBulk(){let e=[...this.picked].filter(e=>this.db.rows.some(t=>t.id===e));if(this.picked=new Set(e),this.bulk.hidden=!e.length||!this.editable,this.bulk.hidden)return this.bulk.replaceChildren();let t=this.labels;this.bulk.replaceChildren(I(`span`,{},AR(t.selected,e.length)),xz(`trash`,t.deleteRows,()=>{this.host.store?.deleteRows(e),this.picked.clear()},t.deleteRows),xz(`close`,t.close,()=>{this.picked.clear(),this.draw()}))}panel(e,t){let n=e.currentTarget;Cz(n,e=>{let n=this.ctx(),r=this.view;t===`filter`?xB(n,e,r):t===`sort`?SB(n,e,r):t===`group`?CB(n,e,r):(r.type===`calendar`&&wB(n,e,r),r.type===`kanban`&&CB(n,e,r),TB(n,e,r))},{class:`dw-db-pop--panel`,label:n.title,placement:`bottom-end`})}viewMenu(e,t){let n=this.labels,r=this.host.store,i=[{id:`rename`,label:n.renameView,icon:`pencil`,run:()=>{let e=window.prompt(n.viewName,t.name)?.trim();e&&r.updateView(t.id,{name:e})}},{id:`layout`,label:n.layout,icon:`grid`,children:IR.map(e=>({id:e,label:kR(n,e),icon:e===t.type?`check`:e===`kanban`?`cards`:e===`calendar`?`calendar`:`table`,run:()=>this.setLayout(t,e)}))},{id:`duplicate`,label:n.duplicateView,icon:`copy`,run:()=>{this.showView(r.duplicateView(t.id,`${t.name||kR(n,t.type)} 2`))}}];this.db.views.length>1&&i.push({id:`delete`,label:n.deleteView,icon:`trash`,danger:!0,run:()=>r.deleteView(t.id)}),Jj(e,i,n.layout)}showView(e){e&&(this.viewId=e,this.sel=null,this.limit=MB,this.draw())}setLayout(e,t){let n={type:t},r=this.db.columns;t===`kanban`&&!e.groupBy&&(n.groupBy=r.find(e=>[`select`,`multiSelect`,`checkbox`,`member`].includes(e.type))?.id??null),t===`calendar`&&!e.dateColumn&&(n.dateColumn=r.find(e=>e.type===`date`)?.id??null),t===`calendar`&&!n.dateColumn&&!e.dateColumn&&this.host.store&&(n.dateColumn=this.host.store.addColumn(`date`,this.labels.typeDate)),this.host.store?.updateView(e.id,n)}moreMenu(){let e=this.labels,t=this.view,n=[{id:`csv`,label:e.exportCsv,icon:`download`,run:()=>{let n=rz(this.db,t);Ez(`${(this.db.title||e.untitled).replace(/[\\/:*?"<>|]+/g,` `).trim()}.csv`,`\uFEFF${pB(this.db,n,nz(this.db,t,this.search))}`,`text/csv`)}}];this.editable&&(n.push({id:`import`,label:e.importCsv,icon:`upload`,run:()=>void this.importCsv()}),n.push({id:`view`,label:e.layout,icon:`grid`,run:()=>this.viewMenu(this.buttons.more,t)})),Jj(this.buttons.more,n,e.more)}async importCsv(){let e=this.host.store,t=await Dz(`.csv,text/csv,.tsv,text/tab-separated-values`);if(!e||!t)return;let n=await t.text(),r=t.name.endsWith(`.tsv`)?` `:`,`,i=uB(n,r).filter(e=>e.some(e=>e.trim()));i.length<2||e.tx(()=>{if(this.db.rows.every(e=>!ZR(e,WR(this.db)))){let t=gB(n,r);e.deleteRows(this.db.rows.map(e=>e.id));let i=WR(this.db),[a,...o]=t.columns,s=new Map;a&&(e.renameColumn(i.id,a.name),s.set(a.id,i.id));for(let t of o){let n=this.db.columns.find(e=>e.name.toLowerCase()===t.name.toLowerCase()&&e.type!==`title`);n&&e.deleteColumn(n.id);let r=e.addColumn(t.type,t.name);t.options&&e.setOptions(r,t.options),s.set(t.id,r)}e.addRows(t.rows.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[s.get(e)??e,t])))),this.host.notify?.(AR(this.labels.imported,t.rows.length));return}let{index:t,missing:a}=_B(i[0],this.db.columns),o=new Map(a.map(t=>[t,e.addColumn(`text`,t)])),s=i[0].map((e,n)=>{let r=t[n];if(r)return r;let i=o.get(e.trim());return i?{id:i,name:e,type:`text`}:null}),c=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),l=i.slice(1).map(e=>{let t={};return s.forEach((n,r)=>{if(!n)return;let i=hB(e[r]??``,n,c.get(n.id)??[]);i!==null&&(t[n.id]=i)}),t});for(let t of this.db.columns){let n=c.get(t.id);n&&n.length!==(t.options?.length??0)&&e.setOptions(t.id,n)}e.addRows(l),this.host.notify?.(AR(this.labels.imported,l.length))})}addRow(e={},t=!1){let n=this.host.store;if(!n)return;let r=this.view;for(let t of r.filters){let n=this.db.columns.find(e=>e.id===t.column);!n||t.column in e||(t.op===`is`&&(n.type===`select`||n.type===`text`)&&t.value&&(e[n.id]=t.value),t.op===`contains`&&n.type===`multiSelect`&&t.value&&(e[n.id]=[t.value]),t.op===`checked`&&(e[n.id]=!0))}let i=n.addRow(e);t||r.type!==`table`?this.openRow(i):(this.sel={row:i,col:WR(this.db).id},queueMicrotask(()=>this.startEdit()))}openRow(e){let t=nz(this.db,this.view,this.search).map(e=>e.id);this.host.openRow(e,t)}drawBody(){let e=this.view;e.type===`kanban`?this.drawKanban(e):e.type===`calendar`?this.drawCalendar(e):this.drawTable(e)}tableRows=[];tableCols=[];grid=null;drawTable(e){let t=this.labels,n=rz(this.db,e),r=nz(this.db,e,this.search),i=e.groupBy?this.db.columns.find(t=>t.id===e.groupBy):void 0,a=i?iz(r,i,t.noValue,t.checked,t.unchecked).filter(e=>e.rows.length||e.key!==``):[{key:``,label:``,rows:r}];this.tableCols=n,this.tableRows=[];let o=this.editable,s=e.sorts.length>0,c=I(`colgroup`,{},I(`col`,{class:`dw-db-t__gutter-col`}),n.map(t=>I(`col`,{style:{width:`${e.widths[t.id]??(t.type===`title`?240:160)}px`}})),o?I(`col`,{class:`dw-db-t__add-col`}):null),l=I(`table`,{class:`dw-db-t`},c,I(`thead`,{},I(`tr`,{},I(`th`,{class:`dw-db-t__gutter`,"aria-hidden":`true`}),n.map((e,t)=>this.headerCell(e,t,c.children[t+1])),o?I(`th`,{class:`dw-db-t__add`},xz(`plus`,t.addColumn,e=>this.addColumnMenu(e.currentTarget))):null))),u=0;for(let r of a){let a=I(`tbody`,{}),c=`${e.id}:${r.key}`;if(i){let e=!this.collapsed.has(c),t=I(`button`,{type:`button`,class:`dw-db-t__group`,"aria-expanded":String(e)},bz(e?`chevron-down`:`chevron-right`,14),r.key&&i.type!==`checkbox`&&i.type!==`member`&&i.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:r.color??`gray`}},r.label):I(`span`,{},r.label),I(`span`,{class:`dw-db-t__count`},String(r.rows.length)));if(t.addEventListener(`click`,()=>{e?this.collapsed.add(c):this.collapsed.delete(c),this.drawBody()}),a.append(I(`tr`,{class:`dw-db-t__group-row`},I(`td`,{colSpan:n.length+2},t))),!e){l.append(a);continue}}for(let e of r.rows){if(u>=this.limit)break;u++,this.tableRows.push(e),a.append(this.tableRow(e,n,o&&!s))}if(o&&u{let e={};i&&r.key?e[i.id]=sz({id:``,cells:{},createdAt:0,createdBy:null},i,``,r.key,r.rows.flatMap(e=>FB(GR(e,i)))):i?.type===`checkbox`&&(e[i.id]=r.key===`true`),this.addRow(e)}),a.append(I(`tr`,{class:`dw-db-t__new-row`},I(`td`,{colSpan:n.length+2},e)))}l.append(a)}let d=[],f=I(`div`,{class:`dw-db-t__wrap`,role:`grid`,tabIndex:0,"aria-label":this.db.title||t.database},l);if(d.push(f),r.length||d.push(I(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),r.length>u&&u>=this.limit){let e=I(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${r.length-u})`);e.addEventListener(`click`,()=>{this.limit+=MB,this.drawBody()}),d.push(e)}this.grid=f,f.addEventListener(`keydown`,e=>this.onGridKey(e)),f.addEventListener(`copy`,e=>this.onCopy(e)),f.addEventListener(`paste`,e=>this.onPaste(e));let p=this.body.querySelector(`.dw-db-t__wrap`)?.scrollLeft??0,m=this.body.contains(document.activeElement);this.body.replaceChildren(...d),f.scrollLeft=p,this.markSelection(),m&&this.sel&&f.focus({preventScroll:!0})}headerCell(e,t,n){let r=this.labels,i=I(`span`,{class:`dw-db-t__name`},e.name||ER(r,e.type)),a=I(`button`,{type:`button`,class:`dw-db-t__head`,"aria-haspopup":`menu`,draggable:this.editable},bz(Fz[e.type],14),i),o=I(`th`,{dataset:{col:e.id}},a);if(a.addEventListener(`click`,()=>this.columnMenu(a,e,t)),this.editable){a.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-column`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),o.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-column`)&&(e.preventDefault(),o.classList.add(`is-drop`))}),o.addEventListener(`dragleave`,()=>o.classList.remove(`is-drop`)),o.addEventListener(`drop`,t=>{o.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-column`);n&&n!==e.id&&(t.preventDefault(),this.host.store?.moveColumn(n,this.db.columns.findIndex(t=>t.id===e.id)))});let t=I(`span`,{class:`dw-db-t__resize`,title:r.resize,"aria-hidden":`true`});t.addEventListener(`pointerdown`,r=>{r.preventDefault(),r.stopPropagation();let i=r.clientX,a=n.getBoundingClientRect().width||160,o=a;t.setPointerCapture(r.pointerId);let s=e=>{o=Math.max(72,Math.round(a+e.clientX-i)),n.style.width=`${o}px`},c=()=>{t.removeEventListener(`pointermove`,s),t.removeEventListener(`pointerup`,c);let n=this.view;o!==a&&this.host.store?.updateView(n.id,{widths:{...n.widths,[e.id]:o}})};t.addEventListener(`pointermove`,s),t.addEventListener(`pointerup`,c)}),o.append(t)}return o}columnMenu(e,t,n){let r=this.labels,i=this.host.store,a=this.view,o=e=>({id:e?`desc`:`asc`,label:e?r.sortDescending:r.sortAscending,icon:e?`arrow-down`:`arrow-up`,run:()=>i?.updateView(a.id,{sorts:[{column:t.id,desc:e}]})});if(!i){Jj(e,[o(!1),o(!0)],t.name);return}let s=this.db.columns,c=s.findIndex(e=>e.id===t.id),l=[{id:`rename`,label:r.rename,icon:`pencil`,run:()=>this.renameColumn(t)}];t.type!==`title`&&l.push({id:`type`,label:r.type,icon:Fz[t.type],children:FR.map(n=>({id:n,label:ER(r,n),icon:n===t.type?`check`:Fz[n],run:()=>{i.changeType(t.id,n),(n===`relation`||n===`rollup`)&&queueMicrotask(()=>this.linkSettings(e,t.id))}}))}),t.type===`relation`&&l.push({id:`relationTo`,label:r.relationTo,icon:`relation`,run:()=>this.linkSettings(e,t.id)}),t.type===`rollup`&&l.push({id:`rollup`,label:r.rollupSettings,icon:`rollup`,run:()=>this.linkSettings(e,t.id)}),l.push(o(!1),o(!0),{id:`filter`,label:r.filterBy,icon:`filter`,run:()=>{i.updateView(a.id,{filters:[...a.filters,{column:t.id,op:QR(t.type)[0]}]}),this.buttons.filter.click()}}),t.type!==`title`&&l.push({id:`hide`,label:r.hide,icon:`close`,run:()=>i.updateView(a.id,{hidden:[...a.hidden,t.id]})}),l.push({id:`left`,label:r.insertLeft,icon:`plus`,run:()=>this.insertColumn(c)},{id:`right`,label:r.insertRight,icon:`plus`,run:()=>this.insertColumn(c+1)}),c>0&&l.push({id:`moveLeft`,label:r.moveLeft,icon:`arrow-up`,run:()=>i.moveColumn(t.id,c-1)}),ci.moveColumn(t.id,c+1)}),t.type!==`title`&&l.push({id:`duplicate`,label:r.duplicate,icon:`copy`,run:()=>i.duplicateColumn(t.id,`${t.name} 2`)},{id:`delete`,label:r.deleteColumn,icon:`trash`,danger:!0,run:()=>i.deleteColumn(t.id)}),Jj(e,l,t.name||ER(r,t.type))}linkSettings(e,t){let n=this.db.columns.find(e=>e.id===t),r=e.isConnected?e:this.dom.querySelector(`[data-col="${t}"]`)??this.dom;n?.type===`relation`?jz(this.ctx(),r,n):n?.type===`rollup`&&Nz(this.ctx(),r,n)}insertColumn(e){let t=this.host.store;if(!t)return;let n=t.addColumn(`text`,this.labels.typeText,e);queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}addColumnMenu(e){let t=this.labels;Jj(e,FR.map(e=>({id:e,label:ER(t,e),icon:Fz[e],run:()=>{let n=this.host.store?.addColumn(e,ER(t,e));queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}})),t.addColumn)}renameColumn(e){let t=this.body.querySelector(`th[data-col="${CSS.escape(e.id)}"]`),n=this.host.store;if(!n)return;if(!t){let t=window.prompt(this.labels.columnName,e.name)?.trim();t&&n.renameColumn(e.id,t);return}let r=this.ctx();r.setEditing(!0);let i=Tz(e.name,{class:`dw-db-t__name-input`,label:this.labels.columnName,onCommit:t=>{t.trim()&&t.trim()!==e.name&&n.renameColumn(e.id,t.trim()),r.setEditing(!1),this.drawBody()},onCancel:()=>{r.setEditing(!1),this.drawBody()}});t.replaceChildren(i),i.focus(),i.select()}tableRow(e,t,n){let r=this.labels,i=I(`tr`,{dataset:{row:e.id},class:this.picked.has(e.id)?`is-picked`:``}),a=I(`td`,{class:`dw-db-t__gutter`});if(this.editable){let t=I(`input`,{type:`checkbox`,class:`dw-db-t__pick`,"aria-label":r.selectRow,checked:this.picked.has(e.id)});if(t.addEventListener(`change`,()=>{t.checked?this.picked.add(e.id):this.picked.delete(e.id),i.classList.toggle(`is-picked`,t.checked),this.drawBulk()}),a.append(t),n){let t=I(`span`,{class:`dw-db-t__grip`,draggable:!0,title:r.dragRow,"aria-hidden":`true`},bz(`grip`,14));t.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),t.dataTransfer?.setDragImage(i,0,0)}),a.append(t),i.addEventListener(`dragover`,e=>{if(!e.dataTransfer?.types.includes(`application/x-docwell-row`))return;e.preventDefault();let t=e.clientY>i.getBoundingClientRect().top+i.offsetHeight/2;i.classList.toggle(`is-drop-below`,t),i.classList.toggle(`is-drop-above`,!t)}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop-below`,`is-drop-above`)),i.addEventListener(`drop`,t=>{let n=i.classList.contains(`is-drop-below`);i.classList.remove(`is-drop-below`,`is-drop-above`);let r=t.dataTransfer?.getData(`application/x-docwell-row`);r&&r!==e.id&&this.host.store&&(t.preventDefault(),this.moveRowBeside(r,e.id,n))});let n=null,o=()=>n?.classList.remove(`is-drop-below`,`is-drop-above`),s=e=>{let t=e?.closest(`tr[data-row]`);return t&&t.parentElement===i.parentElement&&t!==i?t:null},c=(e,t)=>t>e.getBoundingClientRect().top+e.offsetHeight/2;AB(t,{source:i,ghost:()=>I(`div`,{class:`dw-db-ghost--row`},ZR(e,WR(this.db))||r.untitledRow),over:(e,t,r)=>{o(),n=s(e),n&&n.classList.add(c(n,r)?`is-drop-below`:`is-drop-above`)},drop:(t,n,r)=>{let i=s(t);i?.dataset.row&&this.moveRowBeside(e.id,i.dataset.row,c(i,r))},end:o,hold:()=>this.rowMenu(i,e)})}}i.append(a);for(let n of t){let t=I(`td`,{dataset:{col:n.id},class:`dw-db-t__cell dw-db-t__cell--${n.type}`,role:`gridcell`},Vz(this.ctx(),e,n));if(n.type===`title`){let n=I(`button`,{type:`button`,class:`dw-db-t__open`,title:r.openRow},bz(`open`,13),I(`span`,{},r.openRow));n.addEventListener(`click`,t=>{t.stopPropagation(),this.openRow(e.id)}),t.append(n)}t.addEventListener(`mousedown`,t=>{t.target.closest(`input, button, a`)||(this.anchor=t.shiftKey&&this.sel?this.anchor??this.sel:null,this.sel={row:e.id,col:n.id},t.shiftKey||(this.anchor=null),this.markSelection(),t.preventDefault(),this.grid?.focus({preventScroll:!0}))});let a=!1;t.addEventListener(`pointerdown`,e=>a=e.pointerType===`touch`),t.addEventListener(`click`,e=>{e.target.closest(`input, button, a`)||e.shiftKey||(n.type===`checkbox`||a)&&this.startEdit()}),t.addEventListener(`dblclick`,()=>this.startEdit()),i.append(t)}return this.editable&&i.append(I(`td`,{class:`dw-db-t__add`})),i.addEventListener(`contextmenu`,t=>{(this.editable||this.host.copyLink)&&(t.preventDefault(),this.rowMenu(i,e))}),i}moveRowBeside(e,t,n){let r=this.host.store;if(!r||e===t)return;let i=r.rowIndex(e),a=r.rowIndex(t)+ +!!n;ithis.openRow(t.id)}];if(i&&a.push({id:`link`,label:n.copyLink,icon:`link`,run:()=>i(t.id)}),r){let e=r.rowIndex(t.id);a.push({id:`above`,label:n.insertAbove,icon:`arrow-up`,run:()=>r.addRow({},e)},{id:`below`,label:n.insertBelow,icon:`arrow-down`,run:()=>r.addRow({},e+1)},{id:`duplicate`,label:n.duplicateRow,icon:`copy`,run:()=>r.duplicateRow(t.id)},{id:`delete`,label:n.deleteRow,icon:`trash`,danger:!0,run:()=>r.deleteRows([t.id])})}Jj(e,a,n.openRow)}range(){if(!this.sel)return null;let e=e=>this.tableRows.findIndex(t=>t.id===e),t=e=>this.tableCols.findIndex(t=>t.id===e),n=this.anchor??this.sel,[r,i,a,o]=[e(n.row),e(this.sel.row),t(n.col),t(this.sel.col)];if(i<0||o<0)return null;let s=r<0?i:r,c=a<0?o:a;return{r0:Math.min(s,i),r1:Math.max(s,i),c0:Math.min(c,o),c1:Math.max(c,o)}}markSelection(){if(!this.grid)return;for(let e of this.grid.querySelectorAll(`.is-selected, .is-in-range`))e.classList.remove(`is-selected`,`is-in-range`);let e=this.range();if(!e||!this.sel)return;for(let t=e.r0;t<=e.r1;t++)for(let n=e.c0;n<=e.c1;n++)this.cellEl(this.tableRows[t].id,this.tableCols[n].id)?.classList.add(`is-in-range`);let t=this.cellEl(this.sel.row,this.sel.col);t?.classList.add(`is-selected`),t?.scrollIntoView({block:`nearest`,inline:`nearest`})}cellEl(e,t){return this.grid?.querySelector(`tr[data-row="${CSS.escape(e)}"] td[data-col="${CSS.escape(t)}"]`)??null}startEdit(e){if(!this.sel||!this.host.store)return;let t=this.db.rows.find(e=>e.id===this.sel.row),n=this.db.columns.find(e=>e.id===this.sel.col),r=this.cellEl(this.sel.row,this.sel.col);t&&n&&r&&Hz(this.ctx(),r,t,n,{initial:e,onDone:e=>{e&&this.moveSel(+(e===`down`),e===`right`?1:e===`left`?-1:0,!1),this.drawBody(),this.grid?.focus({preventScroll:!0})}})}moveSel(e,t,n){let r=this.tableRows,i=this.tableCols;if(!r.length||!i.length)return;if(!this.sel)return this.sel={row:r[0].id,col:i[0].id},this.markSelection();this.anchor=n?this.anchor??{...this.sel}:null;let a=Math.max(0,Math.min(r.length-1,r.findIndex(e=>e.id===this.sel.row)+e)),o=Math.max(0,Math.min(i.length-1,i.findIndex(e=>e.id===this.sel.col)+t));this.sel={row:r[a].id,col:i[o].id},this.markSelection()}onGridKey(e){if(e.target.closest(`input, select, textarea`))return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`z`)return e.preventDefault(),e.shiftKey?this.host.redo():this.host.undo();if(t&&e.key.toLowerCase()===`y`)return e.preventDefault(),this.host.redo();if(t)return;let n={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(n)return e.preventDefault(),this.moveSel(n[0],n[1],e.shiftKey);if(this.sel){if(e.key===`Tab`)return e.preventDefault(),this.moveSel(0,e.shiftKey?-1:1,!1);if(e.key===`Escape`)this.sel=null,this.anchor=null,this.markSelection();else{if(e.key===`Enter`||e.key===`F2`)return e.preventDefault(),this.startEdit();if(e.key===` `)return e.preventDefault(),this.db.columns.find(e=>e.id===this.sel.col)?.type===`title`?this.openRow(this.sel.row):this.startEdit();if((e.key===`Delete`||e.key===`Backspace`)&&this.host.store){e.preventDefault();let t=this.range();if(!t)return;let n=[];for(let e=t.r0;e<=t.r1;e++)for(let r=t.c0;r<=t.c1;r++){let t=this.tableCols[r];Lz.includes(t.type)||n.push({row:this.tableRows[e].id,col:t.id,value:null})}this.host.store.setCells(n)}else if(e.key.length===1&&this.host.store){let t=this.db.columns.find(e=>e.id===this.sel.col);t&&(Iz.includes(t.type)||t.type===`select`||t.type===`multiSelect`)&&(e.preventDefault(),this.startEdit(e.key))}}}}onCopy(e){if(e.target.closest(`input, textarea`))return;let t=this.range();if(!t||!e.clipboardData)return;e.preventDefault();let n=[];for(let e=t.r0;e<=t.r1;e++){let r=[];for(let n=t.c0;n<=t.c1;n++)r.push(ZR(this.tableRows[e],this.tableCols[n]));n.push(r)}e.clipboardData.setData(`text/plain`,fB(n,` `)),this.host.notify?.(AR(this.labels.copyNotice,(t.r1-t.r0+1)*(t.c1-t.c0+1)))}onPaste(e){if(e.target.closest(`input, textarea`))return;let t=this.host.store,n=e.clipboardData?.getData(`text/plain`);if(!t||!n||!this.sel)return;e.preventDefault();let r=uB(n.replace(/\r?\n$/,``),(n.includes(` `),` `)),i=this.tableRows.findIndex(e=>e.id===this.sel.row),a=this.tableCols.findIndex(e=>e.id===this.sel.col);if(i<0||a<0)return;let o=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),s=[],c=[];r.forEach((e,t)=>{let n=this.tableRows[i+t],r={};e.forEach((e,t)=>{let i=this.tableCols[a+t];if(!i||Lz.includes(i.type))return;let c=hB(e,i,o.get(i.id)??[]);n?s.push({row:n.id,col:i.id,value:c}):c!==null&&(r[i.id]=c)}),n||c.push(r)}),t.tx(()=>{for(let e of this.db.columns){let n=o.get(e.id);n&&n.length!==(e.options?.length??0)&&t.setOptions(e.id,n)}t.setCells(s),c.length&&t.addRows(c)})}drawKanban(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.groupBy);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noGroupColumn));return}let r=nz(this.db,e,this.search),i=iz(r,n,t.noValue,t.checked,t.unchecked),a=rz(this.db,e).filter(e=>e.type!==`title`&&e.id!==n.id),o=WR(this.db),s=r.flatMap(e=>FB(GR(e,n))),c=I(`div`,{class:`dw-db-k`}),l=(t,r,i,a)=>{let o=this.host.store,c=this.db.rows.find(e=>e.id===t);o&&c&&o.tx(()=>{if(r!==i&&o.setCell(t,n.id,sz(c,n,r,i,s)),a&&a!==t&&!e.sorts.length){let e=o.rowIndex(t),n=o.rowIndex(a);e0)continue;let r=I(`div`,{class:`dw-db-k__cards`,dataset:{group:e.key}}),i=I(`div`,{class:`dw-db-k__head`},e.key&&n.type!==`checkbox`&&n.type!==`member`&&n.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:e.color??`gray`}},e.label):I(`span`,{class:`dw-db-k__label`},e.label),I(`span`,{class:`dw-db-t__count`},String(e.rows.length)));for(let t of e.rows.slice(0,this.limit)){let i=I(`div`,{class:`dw-db-k__card`,tabIndex:0,role:`button`,draggable:this.editable&&!Lz.includes(n.type),dataset:{row:t.id}},I(`div`,{class:`dw-db-k__title`},Vz(this.ctx(),t,o)),a.flatMap(e=>ZR(t,e)===``||e.type===`checkbox`&&GR(t,e)!==!0?[]:[I(`div`,{class:`dw-db-k__prop`,title:e.name},Vz(this.ctx(),t,e))]));if(i.addEventListener(`click`,()=>this.openRow(t.id)),i.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openRow(t.id))}),i.addEventListener(`dragstart`,n=>{n.dataTransfer?.setData(`application/x-docwell-card`,JSON.stringify({row:t.id,from:e.key})),n.dataTransfer&&(n.dataTransfer.effectAllowed=`move`),i.classList.add(`is-dragging`)}),i.addEventListener(`dragend`,()=>i.classList.remove(`is-dragging`)),i.draggable){let n=I(`span`,{class:`dw-db-k__grip`,"aria-hidden":`true`},bz(`grip`,14));i.append(n);let r=null,a=e=>{let t=e?.closest(`.dw-db-k__cards`);return t&&c.contains(t)?t:null};AB(n,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{r?.classList.remove(`is-drop`),r=a(e),r?.classList.add(`is-drop`)},drop:n=>{let r=a(n);r&&l(t.id,e.key,r.dataset.group??``,n?.closest(`.dw-db-k__card`)?.dataset.row)},end:()=>r?.classList.remove(`is-drop`)})}r.append(i)}if(this.editable){let i=I(`button`,{type:`button`,class:`dw-db-t__new`},bz(`plus`,14),I(`span`,{},t.newRow));i.addEventListener(`click`,()=>{let t={id:``,cells:{},createdAt:0,createdBy:null};this.addRow(e.key||n.type===`checkbox`?{[n.id]:sz(t,n,``,e.key,s)}:{},!0)}),r.append(i),r.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-card`)&&(e.preventDefault(),r.classList.add(`is-drop`))}),r.addEventListener(`dragleave`,e=>{r.contains(e.relatedTarget)||r.classList.remove(`is-drop`)}),r.addEventListener(`drop`,t=>{r.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-card`),i=this.host.store;if(!n||!i)return;t.preventDefault();let{row:a,from:o}=JSON.parse(n);l(a,o,e.key,t.target.closest(`.dw-db-k__card`)?.dataset.row)})}c.append(I(`section`,{class:`dw-db-k__col`,"aria-label":e.label},i,r))}this.body.replaceChildren(c)}drawCalendar(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.dateColumn);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noDateColumn));return}let r=this.editable&&n.type===`date`,{y:i,m:a}=this.month,o=uz(i,a),s=nz(this.db,e,this.search),c=new Map,l=[];for(let e of s){let t=qR(GR(e,n));t?c.set(t,[...c.get(t)??[],e]):l.push(e)}let u=WR(this.db),d=JR(new Date),f=new Date(i,a,1).toLocaleDateString(this.host.locale,{month:`long`,year:`numeric`}),p=e=>{let t=new Date(i,a+e,1);this.month={y:t.getFullYear(),m:t.getMonth()},this.drawBody()},m=I(`div`,{class:`dw-db-c__nav`},I(`strong`,{class:`dw-db-c__month`},f),xz(`chevron-left`,t.previousMonth,()=>p(-1)),xz(`chevron-right`,t.nextMonth,()=>p(1)),xz(`calendar`,t.today,()=>{let e=new Date;this.month={y:e.getFullYear(),m:e.getMonth()},this.drawBody()},t.today)),h=o.slice(0,7).map(e=>{let[t,n,r]=e.split(`-`).map(Number);return I(`div`,{class:`dw-db-c__wd`},new Date(t,n-1,r).toLocaleDateString(this.host.locale,{weekday:`short`}))}),g=e=>{let i=I(`button`,{type:`button`,class:`dw-db-c__chip`,draggable:r,dataset:{row:e.id}},ZR(e,u)||t.untitledRow);if(i.addEventListener(`click`,()=>this.openRow(e.id)),i.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row-date`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),r){let t=null,r=e=>{let t=e?.closest(`.dw-db-c__day`);return t&&this.body.contains(t)?t:null};AB(i,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{t?.classList.remove(`is-drop`),t=r(e),t?.classList.add(`is-drop`)},drop:t=>{let i=r(t)?.dataset.day;i&&this.host.store?.setCell(e.id,n.id,i)},end:()=>t?.classList.remove(`is-drop`)})}return i},_=I(`div`,{class:`dw-db-c__grid`,role:`grid`},h);for(let e of o){let i=I(`div`,{class:`dw-db-c__day${Number(e.slice(5,7))===a+1?``:` is-out`}${e===d?` is-today`:``}`,role:`gridcell`,dataset:{day:e}},I(`span`,{class:`dw-db-c__num`},String(Number(e.slice(8)))),(c.get(e)??[]).map(g));if(this.editable&&n.type===`date`){let r=I(`button`,{type:`button`,class:`dw-db-c__add`,"aria-label":`${t.newRow} ${e}`,title:t.newRow},bz(`plus`,12));r.addEventListener(`click`,()=>this.addRow({[n.id]:e},!0)),i.append(r)}r&&(i.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-row-date`)&&(e.preventDefault(),i.classList.add(`is-drop`))}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop`)),i.addEventListener(`drop`,t=>{i.classList.remove(`is-drop`);let r=t.dataTransfer?.getData(`application/x-docwell-row-date`);r&&(t.preventDefault(),this.host.store?.setCell(r,n.id,e))})),_.append(i)}let v=[m,_];l.length&&v.push(I(`details`,{class:`dw-db-c__undated`},I(`summary`,{},AR(t.noDate,l.length)),I(`div`,{class:`dw-db-c__chips`},l.slice(0,this.limit).map(g)))),this.body.replaceChildren(I(`div`,{class:`dw-db-c`},v))}},PB={id:``,name:``,type:`table`,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:null,dateColumn:null,widths:{}};function FB(e){return Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`):[]}var IB=`[A-Za-z0-9]{1,32}`,LB=(e,t)=>`#r-${e}-${t}`;function RB(e){let t=RegExp(`^#?r-(${IB})-(${IB})$`).exec(e);return t?{database:t[1],row:t[2]}:null}var zB=`dw-open-record`;function BB(e,t,n,r){let i=-1;if(e.state.doc.descendants((e,n)=>i>=0?!1:(e.type.name===`database`&&e.attrs.id===t&&(i=n),!0)),i<0)return!1;let a=e.view.nodeDOM(i);if(!(a instanceof HTMLElement))return!1;let o={row:n,...r};return a.dispatchEvent(new CustomEvent(zB,{detail:o})),!!o.found}async function VB(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}var HB=e=>(e??NR).database;function UB(e){let t=HB(e);return{tableView:t.viewTable,columnName:e=>e===`title`?t.typeTitle:ER(t,e)}}var WB=e=>xw(e).content??[];function GB(e,t){let n=[];return e.forEach(e=>{e.type.name===`database`?n.push(t(e)):e.content.size?n.push(e.copy(GB(e.content,t))):n.push(e)}),s.from(n)}function KB(e){let t=!1;return e.descendants(e=>(e.type.name===`database`&&(t=!0),!t)),t}var qB=Jp.create({name:`database`,group:`block`,atom:!0,draggable:!0,selectable:!0,addOptions(){return{labels:null,doc:void 0,readOnlyDoc:!1,undoScope:!0,files:void 0,people:void 0,me:void 0,rowExtensions:void 0,notify:void 0,recordLink:void 0,onLinkCopied:void 0,linkedPages:void 0,pages:void 0,onNavigate:void 0,recordPage:void 0}},addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-id`)??``,renderHTML:e=>({"data-id":e.id})},data:{default:null,parseHTML:e=>{try{let t=e.getAttribute(`data-db`);return t?JSON.parse(t):null}catch{return null}},renderHTML:e=>e.data?{"data-db":JSON.stringify(e.data)}:{}}}},parseHTML(){return[{tag:`div[data-type='database']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=A(t,{"data-type":`database`});if(!e.attrs.data)return[`div`,n];let r=BR(e.attrs.data),i=r.views[0],a=r.columns.filter(e=>e.type===`title`||!i?.hidden.includes(e.id));return[`div`,n,[`p`,{},[`strong`,{},r.title||HB(this.options.labels).untitled]],[`table`,{},[`tr`,{},...a.map(e=>[`th`,{},e.name])],...r.rows.map(e=>[`tr`,{},...a.map(t=>[`td`,{},ZR(e,t)])])]]},renderText({node:e}){let t=e.attrs.data?BR(e.attrs.data):null;if(!t)return``;let n=WR(t);return[t.title,...t.rows.map(e=>ZR(e,n))].filter(Boolean).join(` +`)},onCreate(){let{doc:e,readOnlyDoc:t,undoScope:n}=this.options;e&&!t&&n&&(IS.getState(this.editor.state)?.undoManager)?.addToScope(Jz(e))},addCommands(){let e=e=>{let t=LR(),{doc:n,readOnlyDoc:r}=this.options;return!n||r?{id:t,data:e}:(lB(n,t,e,(e,t)=>JB(this.editor,e,t)),{id:t,data:null})};return{insertDatabase:t=>({commands:n})=>n.insertContent([{type:this.name,attrs:e(t??iB(UB(this.options.labels)))},{type:`paragraph`}]),groupAsDatabase:()=>({state:t,dispatch:n,commands:r})=>{let i=ZB(t.selection.$from,t.selection.$to);if(!i)return!1;if(!n)return!0;let a=HB(this.options.labels),o={id:LR(),name:a.typeTitle,type:`title`},s=[o],c=i.checks?{id:LR(),name:a.done,type:`checkbox`}:null;c&&s.push(c);let l=Date.now(),u={title:``,columns:s,rows:i.items.map((e,t)=>({id:LR(),cells:{[o.id]:e.text,...c&&e.checked?{[c.id]:!0}:{}},createdAt:l+t,createdBy:this.options.me?.()??null,body:e.rest.length?e.rest:void 0})),views:[RR(`table`,a.viewTable,s)]},d=this.type.create(e(u));return r.command(({tr:e})=>(e.replaceWith(i.from,i.to,d),e.setSelection(E.create(e.doc,i.from)),!0))}}},addKeyboardShortcuts(){return{"Mod-g":()=>this.editor.commands.groupAsDatabase()}},addProseMirrorPlugins(){let{doc:e,readOnlyDoc:t}=this.options,n=e&&!t?e:null,r=this.editor;return[new D({key:new Un(`databaseClipboard`),props:{transformCopied:t=>!e||!KB(t.content)?t:new p(GB(t.content,t=>{let n=Jz(e).get(String(t.attrs.id));return n instanceof Bb?t.type.create({...t.attrs,data:cB(n,WB)}):t}),t.openStart,t.openEnd),transformPasted:e=>KB(e.content)?new p(GB(e.content,e=>{let t=LR();if(!n)return e.type.create({...e.attrs,id:t});let i=e.attrs.data?BR(e.attrs.data):null,a=Jz(n).get(String(e.attrs.id)),o=i??(a instanceof Bb?cB(a,WB):iB(UB(this.options.labels)));return lB(n,t,XB(o),(e,t)=>JB(r,e,t)),e.type.create({id:t,data:null})}),e.openStart,e.openEnd):e},appendTransaction:(e,t,i)=>{if(!n||!e.some(e=>e.docChanged&&!e.getMeta(FS))||!e.some(e=>e.steps.some(e=>KB(e.slice?.content??s.empty))))return null;let a=new Set,o=[];if(i.doc.descendants((e,t)=>{if(e.type.name!==`database`)return;let n=String(e.attrs.id);return n&&a.has(n)&&o.push({pos:t,node:e}),a.add(n),!1}),!o.length)return null;let c=i.tr;for(let{pos:e,node:t}of o){let i=Jz(n).get(String(t.attrs.id)),a=LR();i instanceof Bb&&lB(n,a,XB(cB(i,WB)),(e,t)=>JB(r,e,t)),c.setNodeMarkup(e,void 0,{...t.attrs,id:a,data:null})}return c}})]},addNodeView(){let e=this.options;return({node:t,editor:n,getPos:r})=>{let i=t,a=e.labels??NR,o=e.doc,s=()=>n.isEditable&&!!o&&!e.readOnlyDoc,c=null,l=null,u=null,d=null,f=I(`div`,{class:`dw-db-node`}),p=()=>String(i.attrs.id),m=()=>{let e=o?Jz(o).get(p()):void 0;return e instanceof Bb?e:null},h=()=>{let t=m();return t?rB(t):i.attrs.data?BR(i.attrs.data):iB(UB(e.labels))},g=e=>{let t=o?Jz(o).get(e):void 0;if(t instanceof Bb)return rB(t);let r=null;return n.state.doc.descendants(t=>!r&&(t.type.name===`database`&&t.attrs.id===e&&t.attrs.data&&(r=BR(t.attrs.data)),!0)),r},_=new Map,v=t=>{let n=e.linkedPages;if(!n)return null;let r=_.get(t);if(!r){let e=n.open(t),i=e.onChange(ne);e.doc.on(`update`,ne),r={provider:e,stop:()=>{i(),e.doc.off(`update`,ne),e.destroy()}},_.set(t,r)}return r.provider},y=t=>!t||t===e.linkedPages?.self,b=new Set,x=e=>{if(y(e.page))return b.add(e.database),e.database===p()?h():g(e.database);let t=v(e.page);if(!t?.synced)return null;let n=Jz(t.doc).get(e.database);return n instanceof Bb?rB(n):null},S=(e,t,n)=>{let r=[],i=e=>{for(let a of e.toArray())if(a instanceof lx){if(a.nodeName===`database`){let e=String(a.getAttribute(`id`)??``);e&&r.push({page:t,database:e,title:n(e)?.title??``})}else i(a)}};return i(e),r},C={local:()=>{let e=[];return n.state.doc.descendants(t=>(t.type.name===`database`&&t.attrs.id&&t.attrs.id!==p()&&e.push({page:``,database:String(t.attrs.id),title:g(String(t.attrs.id))?.title??``}),!0)),e},searchPages:e.pages?t=>e.pages.search(t).then(e=>e.filter(e=>!y(e.id)).map(e=>({id:e.id,title:e.title}))):void 0,databasesOn:e.linkedPages?e=>new Promise(t=>{let n=v(e),r=()=>{t(S(n.doc.getXmlFragment(`default`),e,e=>{let t=Jz(n.doc).get(e);return t instanceof Bb?rB(t):null}))};if(n.synced)return r();let i=setTimeout(()=>{a(),t([])},8e3),a=n.onChange(()=>{n.synced&&(clearTimeout(i),a(),r())})}):void 0,read:x,openRecord:(t,r)=>{y(t.page)?BB(n,t.database,r):e.onNavigate?.(`/p/${encodeURIComponent(t.page)}${LB(t.database,r)}`)}},ee=e=>{for(let t of e)if((t.path.length?[String(t.path[0])]:[...t.keysChanged??[]]).some(e=>e!==p()&&b.has(e)))return ne()};o&&Jz(o).observeDeep(ee);let te;function ne(){clearTimeout(te),te=setTimeout(()=>de(),60)}let re=()=>yz(h(),x,a.database),ie=()=>({labels:a.database,colorNames:a.colors,locale:a.locale,files:e.files,people:e.people,store:c,linked:C}),ae=(t,n)=>{let r=e.rowExtensions;if(!r)return null;let i=m(),o=null;if(i&&(o=c?c.rowBody(n.id):YB(i,n.id),!o))return t.append(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),null;let s=new Vp({element:t,editable:!!c,extensions:r(o),content:o?void 0:{type:`doc`,content:n.body??[{type:`paragraph`}]},editorProps:{attributes:{class:`dw-prose dw-db-peek__prose`}}});return!o&&!n.body?.length&&t.replaceChildren(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),()=>s.destroy()},oe=e.recordLink,se=oe?t=>{let n=oe(LB(p(),t));VB(n).then(t=>t&&e.onLinkCopied?.(n))}:void 0;f.addEventListener(zB,e=>{let t=e.detail,n=re();n.rows.some(e=>e.id===t.row)&&(t.found=!0,t.container||f.scrollIntoView?.({block:`start`}),ue(t.row,n.rows.map(e=>e.id),t.container?{container:t.container,onLeave:t.onClose}:void 0))});let ce=e.recordPage,le,ue=(e,t,n)=>{u?.close(!1),le=n,u=new Kz({ctx:{...ie()},mountBody:ae,copyLink:se,openPage:ce&&!n?e=>ce(p(),e):void 0,page:n},re(),e,t,()=>{u=null,le=void 0})},de=()=>{let e=re();d?.update(e,{store:c}),u?.update(e,{store:c})},fe=()=>{if(l?.(),l=null,c=null,!o)return;let t=m();if(!t&&s()){let a=i.attrs.data?BR(i.attrs.data):iB(UB(e.labels)),s=p()?p():LR();lB(o,s,a,(e,t)=>JB(n,e,t)),queueMicrotask(()=>{let e=typeof r==`function`?r():void 0;e!==void 0&&n.state.doc.nodeAt(e)?.type.name===`database`&&n.view.dispatch(n.state.tr.setNodeMarkup(e,void 0,{...i.attrs,id:s,data:null}).setMeta(`addToHistory`,!1))}),t=Jz(o).get(s)}let a=Jz(o),d=e=>{if(!e.keysChanged.has(p()))return;fe(),de();let t=u?.row;t&&re().rows.some(e=>e.id===t)&&ue(t,[t],le)};if(a.observe(d),t){s()&&(c=new oB(o,t,()=>e.me?.()??null));let n=t,r=()=>de();n.observeDeep(r),l=()=>{a.unobserve(d),n.unobserveDeep(r)}}else l=()=>a.unobserve(d)};fe(),d=new NB({...ie(),openRow:ue,undo:()=>n.commands.undo?.(),redo:()=>n.commands.redo?.(),notify:e.notify,copyLink:se},re()),f.append(d.dom);let pe=s(),me=()=>{s()!==pe&&(pe=s(),fe(),de())};return n.on(`update`,me),n.on(`transaction`,me),{dom:f,update(e){if(e.type!==i.type)return!1;let t=e.attrs.id!==i.attrs.id;return i=e,t&&fe(),de(),!0},ignoreMutation:()=>!0,stopEvent:e=>e.type!==`dragstart`||e.target!==f,destroy(){l?.(),clearTimeout(te),o&&Jz(o).unobserveDeep(ee);for(let e of _.values())e.stop();_.clear(),u?.close(!1),d?.destroy(),n.off(`update`,me),n.off(`transaction`,me)}}}}});function JB(e,t,n){try{Sw(e.schema,{type:`doc`,content:t},n)}catch{}}function YB(e,t){let n=e.get(`rows`);if(!(n instanceof Lb))return null;for(let e of n.toArray())if(e.get(`id`)===t){let t=e.get(`body`);return t instanceof sx&&t.length?t:null}return null}function XB(e){return{...e,rows:e.rows.map(e=>({...e,id:LR()}))}}function ZB(e,t){for(let t=e.depth;t>0;t--){let n=e.node(t);if([`bulletList`,`orderedList`,`taskList`].includes(n.type.name)){let r=[];return n.forEach(e=>{let t=e.firstChild,n=[];e.forEach((e,t,r)=>{r>0&&n.push(e.toJSON())}),r.push({text:t?.textContent??``,checked:!!e.attrs.checked,rest:n})}),{from:e.before(t),to:e.after(t),checks:n.type.name===`taskList`,items:r}}}if(e.depth<1)return null;let n=e.before(1),r=t.after(Math.min(1,t.depth)||1),i=[];return e.doc.nodesBetween(n,r,(e,t)=>t=r?!1:(e.isTextblock&&e.textContent.trim()&&i.push({text:e.textContent,checked:!1,rest:[]}),!e.isTextblock)),i.length>1?{from:n,to:r,checks:!1,items:i}:null}function QB(e){let t=FS.getState(e);return t?.type&&t.binding&&t.doc?t:null}function $B(e,t){let n=QB(e);if(!n||!t?.from||!t.to)return null;try{let r=e=>PS(n.doc,n.type,fy(yg(e)),n.binding.mapping),i=r(t.from),a=r(t.to);return i===null||a===null||a<=i||a>e.doc.content.size?null:{from:i,to:a}}catch{return null}}var eV=new Un(`docwellComments`);function tV(e,t,n){let r=[];for(let i of t){let t=$B(e,i.anchor);t&&r.push(vs.inline(t.from,t.to,{class:i.id===n?`dw-comment is-active`:`dw-comment`,"data-comment":i.id}))}return xs.create(e.doc,r)}var nV=Tp.create({name:`commentHighlights`,addOptions(){return{onSelect:void 0}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:eV,state:{init:()=>({marks:[],active:``,decos:xs.empty}),apply(e,t,n,r){let i=e.getMeta(eV);if(i)return{...i,decos:tV(r,i.marks,i.active)};if(!e.docChanged||!t.marks.length)return t;let a=e.getMeta(FS)?.isChangeOrigin;return{...t,decos:a?tV(r,t.marks,t.active):t.decos.map(e.mapping,e.doc)}}},props:{decorations:e=>eV.getState(e)?.decos??xs.empty,handleClick(t,n,r){let i=r.target?.closest?.(`[data-comment]`)?.getAttribute(`data-comment`);return i&&e()?.(i),!1}}})]}}),rV=/^(\d{4})-(\d{2})-(\d{2})$/;function iV(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function aV(e){let t=rV.exec(e);if(!t)return null;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return iV(n)===e?n:null}function oV(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function sV(e,t){return Math.round((t.getTime()-e.getTime())/864e5)}function cV(e,t,n=new Date){let r=aV(e);if(!r)return e;let i=t.dates,a=sV(oV(n,0),r);return a===0?i.today:a===1?i.tomorrow:a===-1?i.yesterday:new Intl.DateTimeFormat(t.locale,{month:`short`,day:`numeric`,year:r.getFullYear()===n.getFullYear()?void 0:`numeric`}).format(r)}function lV(e,t){let n=aV(e);return n?new Intl.DateTimeFormat(t.locale,{dateStyle:`full`}).format(n):e}function uV(e,t,n,r=new Date){let i=t.dates,a=e.trim().toLowerCase(),o=!1;for(let e of new Set([i.remindWord.toLowerCase(),`remind`])){if(a.startsWith(e)){o=!0,a=a.slice(e.length).trim();break}if(a.length>=3&&e.startsWith(a)){o=!0,a=``;break}}if(o&&!n)return[];let s=oV(r,0);if(!a)return o?[1,0,7].map(e=>({date:iV(oV(s,e)),remind:o})):[{date:iV(s),remind:!1},...n?[{date:iV(oV(s,1)),remind:!0}]:[]];let c=[{words:[i.today,`today`],date:s},{words:[i.tomorrow,`tomorrow`],date:oV(s,1)},{words:[i.nextWeek,`next week`],date:oV(s,7)}];o||c.push({words:[i.yesterday,`yesterday`],date:oV(s,-1)});let l=e=>new Intl.DateTimeFormat(e,{weekday:`long`});for(let e=1;e<=7;e++){let n=oV(s,e);c.push({words:[l(t.locale).format(n),l(`en`).format(n)],date:n})}let u=[];aV(a)&&u.push({date:a,remind:o});for(let e of c)e.words.some(e=>e.toLowerCase().startsWith(a))&&u.push({date:iV(e.date),remind:o});return u.filter((e,t)=>u.findIndex(t=>t.date===e.date)===t).slice(0,5)}function dV(e,t){let n=e.toLowerCase().split(` `),r=[t.dates.remindWord,`remind`,t.dates.nextWeek.split(` `)[0]??``,`next`];return n.length>1&&n.length<=3&&r.some(e=>e&&e.toLowerCase()===n[0])}var fV=Jp.create({name:`dateMention`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:void 0,me:()=>void 0,onOpen:void 0}},addAttributes(){return{date:{default:``,parseHTML:e=>e.getAttribute(`data-date`)??``,renderHTML:e=>({"data-date":e.date})},remind:{default:``,parseHTML:e=>e.getAttribute(`data-remind`)??``,renderHTML:e=>e.remind?{"data-remind":e.remind}:{}},tz:{default:``,parseHTML:e=>e.getAttribute(`data-tz`)??``,renderHTML:e=>e.tz?{"data-tz":e.tz}:{}}}},parseHTML(){return[{tag:`span[data-type="date"]`}]},renderHTML({node:e,HTMLAttributes:t}){return[`span`,A({"data-type":`date`,class:`dw-date`},t),cV(e.attrs.date,this.options.labels)]},renderText({node:e}){return cV(e.attrs.date,this.options.labels)},addNodeView(){let{labels:e,me:t,onOpen:n}=this.options;return({node:r,editor:i,getPos:a})=>{let o=r,s=document.createElement(`span`);s.dataset.type=`date`,s.className=`dw-date`,s.contentEditable=`false`,s.classList.toggle(`is-link`,!!n);let c=null,l=()=>{let t=o.attrs.date,n=o.attrs.remind,r=!!aV(t)&&t{let t=typeof a==`function`?a():void 0;t!==void 0&&i.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...o.attrs,...e}),!0)).run()};return s.addEventListener(`mousedown`,r=>{c||(i.isEditable?(r.preventDefault(),c=hV(s,i,o,e,t(),u,()=>c=null,n)):n&&aV(o.attrs.date)&&(r.preventDefault(),n(o.attrs.date)))}),{dom:s,update(e){return e.type===o.type&&(o=e,l(),!0)},ignoreMutation:()=>!0,stopEvent:e=>s.contains(e.target)&&e.type!==`mousedown`,destroy(){c?.()}}}}});function pV(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone??``}catch{return``}}function mV(e,t,n,r){let i={date:n.date,remind:n.remind&&r?r:``,tz:n.remind&&r?pV():``};e.chain().focus().insertContentAt(t,[{type:`dateMention`,attrs:i},{type:`text`,text:` `}]).run()}function hV(e,t,n,r,i,a,o,s){let c=r.dates,l=document.createElement(`div`);l.className=`dw-date-pop`,l.setAttribute(`role`,`dialog`),l.setAttribute(`aria-label`,c.edit);let u=document.createElement(`input`);u.type=`date`,u.className=`dw-input`,u.value=n.attrs.date,u.setAttribute(`aria-label`,c.edit),u.addEventListener(`change`,()=>{aV(u.value)&&a({date:u.value})}),l.append(u);let d=n.attrs.remind;if(d&&d!==i){let e=document.createElement(`p`);e.className=`dw-date-pop__note`,e.textContent=c.someoneElse,l.append(e)}else if(i){let e=document.createElement(`label`);e.className=`dw-date-pop__check`;let t=document.createElement(`input`);t.type=`checkbox`,t.checked=d===i,t.addEventListener(`change`,()=>a(t.checked?{remind:i,tz:pV()}:{remind:``,tz:``})),e.append(t,document.createTextNode(c.remindMe));let n=document.createElement(`span`);n.className=`dw-date-pop__note`,n.textContent=c.reminderAt,l.append(e,n)}if(s){let e=document.createElement(`button`);e.type=`button`,e.className=`dw-date-pop__open`,e.textContent=c.openJournal??`Open journal`,e.addEventListener(`click`,()=>{let e=n.attrs.date;h(),aV(e)&&s(e)}),l.append(e)}document.body.append(l);let f=jj(e,l,()=>{Fj(e,l,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(l.style,{left:`${e}px`,top:`${t}px`}))}),p=t=>{!l.contains(t.target)&&!e.contains(t.target)&&h()},m=e=>{e.key===`Escape`&&(e.preventDefault(),h(),t.commands.focus())};function h(){f(),l.remove(),document.removeEventListener(`mousedown`,p,!0),document.removeEventListener(`keydown`,m,!0),o()}return document.addEventListener(`mousedown`,p,!0),document.addEventListener(`keydown`,m,!0),u.focus(),h}function gV(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=kf(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.map(kf).join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function _V(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,` +`);return/\s/.test(n)}):!1}function vV(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function yV(e,t,n,r){return n?()=>{let n=r.getState(e.state)?.decorationId;return t.dom.querySelector(`[data-decoration-id="${n}"]`)?.getBoundingClientRect()||null}:vV(e)}function bV({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a?.({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!_V(r)}function xV({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function SV({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:r,decorationEmptyClass:i,renderer:a,dispatchExit:o}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var s;return a==null||(s=a.onKeyDown)==null||s.call(a,{view:t,event:n,range:i.range}),o(t),!0}return(a==null||(r=a.onKeyDown)==null?void 0:r.call(a,{view:t,event:n,range:i.range}))||!1},decorations(a){let{active:o,range:s,decorationId:c,query:l}=e.getState(a);if(!o)return null;let u=!l?.length,d=[n];return u&&d.push(i),xs.create(a.doc,[vs.inline(s.from,s.to,{nodeName:t,class:d.join(` `),"data-decoration-id":c||void 0,"data-decoration-content":r})])}}}function CV({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(yf.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}}function wV({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i?.(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e?.()},e)}),s=()=>{n?.abort(),a(),n=null};return{abort:s,fetch:async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}}}}function TV({placement:e,offset:t,flip:n,floatingUi:r}){var i;let a=[Mj({mainAxis:t.mainAxis??4,crossAxis:t.crossAxis??0})];return n&&a.push(Pj()),r!=null&&(i=r.middleware)!=null&&i.length&&a.push(...r.middleware),{placement:e,strategy:r?.strategy??`absolute`,middleware:a}}function EV(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function DV({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,s={})=>{let c={getBoundingClientRect:()=>e()??new DOMRect,contextElement:t},l=!1,u=!o.isConnected;u&&EV(r).appendChild(o),s.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let d=jj(c,o,()=>{Fj(c,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{s.onPosition?s.onPosition({x:e,y:t,placement:n,strategy:r}):(Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),l||(l=!0,o.style.visibility=``))})},s.autoUpdate),f;return i&&(f=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,f,!0)),()=>{d(),f&&document.removeEventListener(`pointerdown`,f,!0),u&&o.remove()}}}function OV({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,_=wV({editor:e,items:n}),v=TV({placement:s,offset:c,flip:u,floatingUi:d});function y(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{let b=t.getState(d),x=t.getState(n.state);if(!b||!x)return;let S=null,C=b.query!==x.query,ee=b.text!==x.text,te=b.range.from!==x.range.from||b.range.to!==x.range.to,ne=C||ee||te;if(!b.active&&x.active)S=`started`;else if(b.active&&!x.active)S=`stopped`;else if(x.active&&ne)S=`updated`;else return;let re=S===`stopped`?b:x,ie=n.dom.querySelector(`[data-decoration-id="${re.decorationId}"]`),ae=m(n,ie),oe=i===0||(re.query?re.query.length>=i:!1),se=(S===`started`||S===`updated`)&&oe;if(g={editor:e,range:re.range,query:re.query||``,text:re.text||``,items:o??[],command:t=>p({editor:e,range:re.range,props:t}),decorationNode:ie,clientRect:ae,loading:se,placement:s,offset:{mainAxis:c.mainAxis??4,crossAxis:c.crossAxis??0},container:l,flip:u,floatingUi:v,mount:DV({getReferenceRect:ae,contextElement:n.dom,config:v,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},S===`started`){var ce;r==null||(ce=r.onBeforeStart)==null||ce.call(r,g)}if(S===`updated`){var le;r==null||(le=r.onBeforeUpdate)==null||le.call(r,g)}if(S===`started`&&y(S,g),S===`started`||S===`updated`){if(!se)_.abort(),g={...g,items:o??[],loading:!1};else{g={...g,items:o??[],loading:!0},S=`updated`,y(S,g);let e=await _.fetch(re.query||``,a);if(e.status===`aborted`)return;if(!t.getState(n.state)?.active){_.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}}S===`stopped`?(_.abort(),y(S,g),g=void 0):S===`updated`&&y(S,g)},destroy:()=>{var e;_.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}var kV=new Un(`suggestion`);function AV({pluginKey:e=kV,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],minQueryLength:p=0,debounce:m=0,initialItems:h,placement:g=`bottom-start`,offset:_={},container:v,flip:y=!0,floatingUi:b,dismissOnOutsideClick:x=!0,render:S=()=>({}),allow:C=()=>!0,findSuggestionMatch:ee=gV,shouldShow:te,shouldResetDismissed:ne}){let re=S?.(),ie=r&&!i,ae=(n,r)=>yV(t,n,r,e);function oe(e){return bV({...e,editor:t,shouldResetDismissed:ne,effectiveAllowSpaces:ie})}let se=t=>xV({view:t,pluginKeyRef:e});return new D({key:e,view:()=>OV({editor:t,pluginKey:e,items:f,renderer:re,minQueryLength:p,debounce:m,initialItems:h,placement:g,offset:_,container:v,flip:y,floatingUi:b,dismissOnOutsideClick:x,command:d,clientRectFor:ae,dispatchExit:se}),state:CV({editor:t,char:n,effectiveAllowSpaces:ie,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,findSuggestionMatch:ee,allow:C,shouldShow:te,shouldKeepDismissed:oe,pluginKey:e}),props:SV({pluginKey:e,decorationTag:s,decorationClass:c,decorationContent:l,decorationEmptyClass:u,renderer:re,dispatchExit:se})})}var jV=AV,MV=e=>`/p/${encodeURIComponent(e)}`,NV=/^\/p\/([A-Za-z0-9_-]+)\/?(?:[?#].*)?$/;function PV(e){return NV.exec(e)?.[1]??``}function FV(e,t,n,r=`Untitled`){let i=`${n.icon?`${n.icon} `:``}${n.title||r}`;e.chain().focus().deleteRange(t).insertContent([{type:`text`,text:i,marks:[{type:`link`,attrs:{href:MV(n.id)}}]},{type:`text`,text:` `}]).run()}async function IV(e,t,n){if(!t.create)return;let{from:r,to:i,empty:a}=e.state.selection,o=a?``:e.state.doc.textBetween(r,i,` `).trim().slice(0,200),s=await t.create(o);a||!o?FV(e,{from:r,to:r},s,n):e.chain().focus().setTextSelection({from:r,to:i}).setLink({href:MV(s.id)}).run()}var LV=Tp.create({name:`pageLinks`,addOptions(){return{host:void 0,labels:null,onNavigate:void 0}},addProseMirrorPlugins(){let{host:e,onNavigate:t}=this.options,n=this.options.labels,r=[];return e&&r.push(jV({editor:this.editor,pluginKey:new Un(`pageLinks`),char:`[[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Uj({label:n.pageLinks,empty:n.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>FV(e.editor,e.range,t)})})),t&&r.push(new D({key:new Un(`pageLinkClicks`),props:{handleClick:(e,n,r)=>{let i=(r.target?.closest?.(`a[href]`))?.getAttribute(`href`)??``;return!PV(i)||e.editable&&!(r.ctrlKey||r.metaKey)?!1:(r.preventDefault(),t(i),!0)}}})),r}});function RV(e,t,n){e.chain().focus().deleteRange(t).insertSyncedPage(n).run()}var zV=Jp.create({name:`syncedPage`,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,pages:void 0,labels:null,onNavigate:void 0,nested:void 0}},addAttributes(){return{page:{default:``,parseHTML:e=>e.getAttribute(`data-page`)??``,renderHTML:e=>({"data-page":e.page})},title:{default:``,parseHTML:e=>e.getAttribute(`data-title`)??``,renderHTML:e=>e.title?{"data-title":e.title}:{}},icon:{default:``,parseHTML:e=>e.getAttribute(`data-icon`)??``,renderHTML:e=>e.icon?{"data-icon":e.icon}:{}},folded:{default:!1,parseHTML:e=>e.hasAttribute(`data-folded`),renderHTML:e=>e.folded?{"data-folded":``}:{}}}},parseHTML(){return[{tag:`div[data-type='syncedPage']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=`${e.attrs.icon?`${e.attrs.icon} `:``}${e.attrs.title||`…`}`;return[`div`,A(t,{"data-type":`syncedPage`}),[`a`,{href:MV(String(e.attrs.page))},n]]},addCommands(){return{insertSyncedPage:e=>({commands:t})=>t.insertContent([{type:this.name,attrs:{page:e.id,title:e.title,icon:e.icon??``}},{type:`paragraph`}])}},addProseMirrorPlugins(){let{pages:e}=this.options,t=this.options.labels;return e?[jV({editor:this.editor,pluginKey:new Un(`syncedPages`),char:`![[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Uj({label:t.blocks.syncedPage,empty:t.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>RV(e.editor,e.range,t)})})]:[]},addNodeView(){let{host:e,onNavigate:t,nested:n}=this.options,r=this.options.labels.blocks;return({node:i,editor:a,getPos:o})=>{let s=i,c=String(s.attrs.page),l=document.createElement(`div`);l.className=`dw-synced`,l.dataset.type=`syncedPage`,l.contentEditable=`false`;let u=document.createElement(`div`);u.className=`dw-synced__head`;let d=document.createElement(`a`);d.className=`dw-synced__title`,d.href=MV(c);let f=Hj(`copy`,14);f.classList.add(`dw-synced__badge`);let p=document.createElement(`button`);p.type=`button`,p.className=`dw-synced__btn`;let m=document.createElement(`button`);m.type=`button`,m.className=`dw-synced__btn`,m.textContent=r.syncedOpen,u.append(f,d,p,m);let h=document.createElement(`div`);h.className=`dw-synced__body`,l.append(u,h);let g=e=>{e.preventDefault(),t?t(MV(c)):window.location.assign(MV(c))};d.addEventListener(`click`,g),m.addEventListener(`click`,g);let _=e=>{let t=typeof o==`function`?o():void 0;t!==void 0&&a.view.dispatch(a.state.tr.setNodeMarkup(t,void 0,{...s.attrs,...e}))},v=null,y=()=>v??!!s.attrs.folded;p.addEventListener(`click`,()=>{a.isEditable?_({folded:!s.attrs.folded}):(v=!y(),ne())});let b=null,x=null,S=null,C=e=>{let t=document.createElement(`p`);t.className=`dw-synced__note`,t.textContent=e,h.replaceChildren(t)},ee=()=>{S?.(),x?.destroy(),b?.destroy(),S=null,x=null,b=null},te=()=>{if(x||!e||!n)return;if(c===e.self)return C(r.syncedSelf);b=e.open(c),C(r.syncedLoading);let t=b,i=()=>{t.status===`denied`?(ee(),C(r.syncedDenied)):t.synced&&!x&&(h.replaceChildren(),x=new Vp({element:h,editable:!1,extensions:n(t.doc),editorProps:{attributes:{class:`dw-prose`}}}))};S=t.onChange(i),i()};function ne(){let t=s.attrs.title;d.textContent=`${s.attrs.icon?`${s.attrs.icon} `:``}${t||r.syncedPage}`;let n=y();l.classList.toggle(`is-folded`,n),p.textContent=n?r.syncedUnfold:r.syncedFold,p.setAttribute(`aria-expanded`,String(!n)),n?(ee(),h.replaceChildren()):e?te():h.replaceChildren()}return ne(),e?.meta(c).then(e=>{e?a.isEditable&&(e.title!==s.attrs.title||e.icon!==s.attrs.icon)?_({title:e.title,icon:e.icon}):d.textContent=`${e.icon?`${e.icon} `:``}${e.title||r.syncedPage}`:y()||C(r.syncedDenied)}),{dom:l,update(e){return e.type!==s.type||String(e.attrs.page)!==c?!1:(s=e,ne(),!0)},ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof globalThis.Node&&(u.contains(e.target)||h.contains(e.target)),destroy:ee}}}});function BV(e){let t=document.createElement(`div`);t.className=`dw-diagram-editor`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,e);let n=document.createElement(`p`);n.className=`dw-diagram-editor__status`,t.append(n),document.body.append(t);let r=document.body.style.overflow;return document.body.style.overflow=`hidden`,{root:t,status:e=>{n.textContent=e,n.hidden=!e},close:()=>{t.remove(),document.body.style.overflow=r}}}async function VV(e,t){let n=await fetch(e.resolve(t));if(!n.ok)throw Error(`loading the drawing failed (${n.status})`);return n.text()}function HV(e,t){return new File([e],t,{type:`image/svg+xml`})}function UV(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n)}function WV(e,t,n){return new Promise(r=>{let i=BV(n.slash.drawio?.label??`Draw.io`),a=document.createElement(`iframe`),o=new URL(e);for(let[e,t]of Object.entries({embed:`1`,proto:`json`,spin:`1`,saveAndExit:`1`,noExitBtn:`0`}))o.searchParams.set(e,t);a.src=o.toString(),a.className=`dw-diagram-editor__frame`,a.title=n.slash.drawio?.label??`Draw.io`;let s=document.createElement(`div`);s.className=`dw-diagram-editor__bar`;let c=document.createElement(`button`);c.type=`button`,c.className=`dw-source__btn`,c.textContent=n.blocks.cancel,c.addEventListener(`click`,()=>d(null)),s.append(c),i.root.append(s,a),i.status(``);let l=e=>a.contentWindow?.postMessage(JSON.stringify(e),o.origin),u=!1,d=e=>{window.removeEventListener(`message`,f),i.close(),r(e)},f=e=>{if(e.source!==a.contentWindow||e.origin!==o.origin||typeof e.data!=`string`)return;let n;try{n=JSON.parse(e.data)}catch{return}switch(n.event){case`init`:l({action:`load`,autosave:0,xml:t?`data:image/svg+xml;base64,${UV(t)}`:``});break;case`save`:u=!0,l({action:`export`,format:`xmlsvg`,spinKey:`saving`});break;case`export`:{let e=n.data??``,t=e.indexOf(`,`),r=e.slice(0,t),i=e.slice(t+1),a=r.includes(`;base64`)?new TextDecoder().decode(Uint8Array.from(atob(i),e=>e.charCodeAt(0))):decodeURIComponent(i);d(u?a:null);break}case`exit`:d(null)}};window.addEventListener(`message`,f)})}async function GV(e,t,n){let r=BV(n.slash.excalidraw?.label??`Excalidraw`);r.status(``);try{let{openExcalidraw:i}=await e();return await i(r.root,t,n)}finally{r.close()}}var KV=!1;function qV(e){return Jp.create({name:e,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,loadExcalidraw:void 0,labels:null,drawioUrl:void 0,onError:void 0}},addAttributes(){return{src:{default:``},alt:{default:``}}},parseHTML(){return[{tag:`figure[data-type='${e}']`,getAttrs:e=>({src:e.querySelector(`img`)?.getAttribute(`src`)??``})}]},renderHTML({node:t,HTMLAttributes:n}){return[`figure`,A(n,{"data-type":e}),[`img`,{src:String(t.attrs.src),alt:String(t.attrs.alt||e)}]]},addCommands(){return{insertDiagram:e=>({commands:t})=>(KV=!0,t.insertContent({type:e,attrs:{src:``}}))}},addNodeView(){return({node:t,editor:n,getPos:r})=>{let i=this.options,a=i.labels,o=document.createElement(`figure`);o.className=`dw-diagram dw-diagram--${e}`,o.setAttribute(`data-type`,e);let s=document.createElement(`img`);s.className=`dw-diagram__img`;let c=document.createElement(`p`);c.className=`dw-diagram__empty`,c.textContent=e===`drawio`?a.blocks.emptyDrawio:a.blocks.emptyExcalidraw;let l=document.createElement(`button`);l.type=`button`,l.className=`dw-diagram__edit`,l.textContent=a.blocks.edit,o.append(s,c,l);let u=``,d=t=>{u=String(t.attrs.src??``),s.hidden=!u,c.hidden=!!u,u&&(s.src=i.host?i.host.resolve(u):u,s.alt=String(t.attrs.alt||a.slash[e]?.label||e))};d(t);let f=!1,p=async()=>{if(!f&&m()&&i.host?.upload){f=!0;try{let t=u?await VV(i.host,u):``,o=e===`drawio`?await WV(i.drawioUrl||`https://embed.diagrams.net`,t,a):await GV(i.loadExcalidraw,t,a);if(o===null)return;let s=await i.host.upload(HV(o,`${e===`drawio`?`diagram.drawio`:`drawing.excalidraw`}.svg`)),c=typeof r==`function`?r():void 0;c!==void 0&&JV(n,c,e,s.url)}catch(e){i.onError?.(e)}finally{f=!1}}},m=()=>n.isEditable&&!!i.host?.upload&&(e===`drawio`||!!i.loadExcalidraw),h=()=>l.hidden=!m()||!u;return h(),n.on(`update`,h),o.addEventListener(`dblclick`,()=>void p()),c.addEventListener(`click`,()=>void p()),l.addEventListener(`click`,()=>void p()),KV&&(KV=!1,queueMicrotask(()=>void p())),{dom:o,update:t=>t.type.name===e&&(d(t),h(),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target===l||e.target===c,destroy:()=>n.off(`update`,h)}}}})}function JV(e,t,n,r){e.chain().setNodeSelection(t).updateAttributes(n,{src:r}).run()}var YV=qV(`drawio`),XV=qV(`excalidraw`),ZV=null;function QV(e){ZV?.();let t=document.createElement(`div`);t.className=`dw-source`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,e.label);let n=document.createElement(e.multiline?`textarea`:`input`);n.className=`dw-source__field`+(e.monospace?` dw-source__field--mono`:``),n.value=e.value,n.setAttribute(`aria-label`,e.label),n.spellcheck=!1,n instanceof HTMLTextAreaElement&&(n.rows=Math.min(16,Math.max(4,e.value.split(` +`).length+1)));let r=document.createElement(`div`);r.className=`dw-source__actions`;let i=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`dw-source__btn ${t}`,r.textContent=e,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,n),r};e.onRemove&&r.append(i(e.labels.remove,`dw-source__btn--danger`,()=>{u(!0),e.onRemove()}));let a=document.createElement(`span`);a.style.flex=`1`,r.append(a,i(e.labels.cancel,``,()=>u()),i(e.labels.done,`dw-source__btn--primary`,()=>o())),t.append(n,r),document.body.append(t);let o=()=>{let t=n.value;u(!0),e.onSave(t)};n.addEventListener(`input`,()=>e.onInput?.(n.value)),n.addEventListener(`keydown`,t=>{let n=t;n.key===`Escape`?(n.preventDefault(),u()):n.key===`Enter`&&(n.ctrlKey||n.metaKey||!e.multiline)&&(n.preventDefault(),o()),n.stopPropagation()});let s=n=>{!t.contains(n.target)&&!e.anchor.contains(n.target)&&u()};setTimeout(()=>document.addEventListener(`mousedown`,s),0);let c=jj(e.anchor,t,()=>{Fj(e.anchor,t,{placement:`bottom-start`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:n})=>Object.assign(t.style,{left:`${e}px`,top:`${n}px`}))}),l=!1;function u(n=!1){l||(l=!0,c(),document.removeEventListener(`mousedown`,s),t.remove(),ZV===d&&(ZV=null),n||e.onCancel?.())}let d=()=>u();return ZV=d,n.focus(),e.multiline||n.select(),d}var $V=[{pattern:/^https:\/\/(?:www\.|m\.)?youtube\.com\/(?:watch\?(?:.*&)?v=|shorts\/|embed\/|live\/)([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/youtu\.be\/([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?vimeo\.com\/(?:video\/)?(\d+)/,src:e=>`https://player.vimeo.com/video/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([\da-f]{32})/,src:e=>`https://www.loom.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[\w-]+/,src:(e,t)=>`https://www.figma.com/embed?embed_host=docwell&url=${encodeURIComponent(t.href)}`},{pattern:/^https:\/\/codepen\.io\/([\w-]+)\/(?:pen|embed)\/([\w-]+)/,src:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{pattern:/^https:\/\/open\.spotify\.com\/(?:embed\/)?(track|album|playlist|episode|show)\/(\w+)/,src:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`,ratio:`audio`},{pattern:/^https:\/\/docs\.google\.com\/(document|spreadsheets|presentation)\/d\/([\w-]+)/,src:e=>`https://docs.google.com/${e[1]}/d/${e[2]}/preview`,ratio:`tall`},{pattern:/^https:\/\/(?:www\.)?google\.com\/maps\/embed\?/,src:(e,t)=>t.href}];function eH(e){let t;try{t=new URL(e.trim())}catch{return null}for(let e of $V){let n=e.pattern.exec(t.href);if(n)return{src:e.src(n,t),ratio:e.ratio??`video`}}return null}function tH(e){try{let t=new URL(e.trim());return t.protocol===`https:`||t.protocol===`http:`?t.href:``}catch{return``}}var nH=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}};function rH(e,t,n){let{node:r}=e.view.domAtPos(e.state.selection.from),i=r instanceof HTMLElement?r:r.parentElement??e.view.dom;return new Promise(e=>{let r=t.blocks;QV({anchor:i,value:`https://`,label:n,labels:{done:r.done,cancel:r.cancel,remove:r.remove},onSave:t=>e(tH(t)),onCancel:()=>e(``)})})}async function iH(e,t,n,r){let i=await rH(e,t,t.blocks.embedUrl);i&&(eH(i)?e.chain().focus().insertEmbed(i).run():await oH(e,i,n,r))}async function aH(e,t,n,r){let i=await rH(e,t,t.blocks.linkUrl);i&&await oH(e,i,n,r)}async function oH(e,t,n,r){let i={url:t};if(n)try{i={...await n.preview(t),url:t}}catch(e){r?.(e)}e.chain().focus().insertLinkCard(i).run()}var sH=Jp.create({name:`embed`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{url:{default:``,parseHTML:e=>e.getAttribute(`data-url`)??``,renderHTML:e=>({"data-url":e.url})}}},parseHTML(){return[{tag:`div[data-type='embed']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=tH(String(e.attrs.url));return[`div`,A(t,{"data-type":`embed`}),[`a`,{href:n},n]]},addCommands(){return{insertEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e}})}},addNodeView(){return({node:e})=>{let t=this.options.labels.blocks,n=document.createElement(`figure`);n.className=`dw-embed`,n.setAttribute(`data-type`,`embed`),n.contentEditable=`false`;let r=e=>{let r=tH(e),i=eH(r);if(n.replaceChildren(),!i){let e=document.createElement(`a`);e.href=r,e.target=`_blank`,e.rel=`noopener noreferrer`,e.textContent=r||t.embedInvalid,n.append(e);return}n.dataset.ratio=i.ratio;let a=document.createElement(`iframe`);a.className=`dw-embed__frame`,a.src=i.src,a.title=`${t.embed}: ${nH(r)}`,a.loading=`lazy`,a.allow=`fullscreen; picture-in-picture; encrypted-media; clipboard-write`,a.referrerPolicy=`strict-origin-when-cross-origin`,a.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`);let o=document.createElement(`figcaption`);o.className=`dw-embed__caption`;let s=document.createElement(`a`);s.href=r,s.target=`_blank`,s.rel=`noopener noreferrer`,s.textContent=nH(r),o.append(s),n.append(a,o)},i=String(e.attrs.url);return r(i),{dom:n,update:e=>e.type.name===`embed`&&(e.attrs.url!==i&&r(i=String(e.attrs.url)),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`)}}}}),cH=Jp.create({name:`linkCard`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){let e=e=>({default:``,parseHTML:t=>t.getAttribute(`data-${e}`)??``,renderHTML:t=>({[`data-${e}`]:t[e]})});return{url:e(`url`),title:e(`title`),description:e(`description`),image:e(`image`),site:e(`site`)}},parseHTML(){return[{tag:`div[data-type='link-card']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=tH(String(e.attrs.url));return[`div`,A(t,{"data-type":`link-card`}),[`a`,{href:n},String(e.attrs.title||n)]]},addCommands(){return{insertLinkCard:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e.url,title:e.title??``,description:e.description??``,image:e.image??``,site:e.site??``}})}},addNodeView(){return({node:e})=>{let t=document.createElement(`a`);t.className=`dw-linkcard`,t.setAttribute(`data-type`,`link-card`),t.contentEditable=`false`,t.target=`_blank`,t.rel=`noopener noreferrer`;let n=e=>{let n=tH(String(e.url));t.href=n,t.replaceChildren();let r=document.createElement(`span`);r.className=`dw-linkcard__text`;let i=document.createElement(`span`);if(i.className=`dw-linkcard__title`,i.textContent=String(e.title||``)||nH(n),r.append(i),e.description){let t=document.createElement(`span`);t.className=`dw-linkcard__desc`,t.textContent=String(e.description),r.append(t)}let a=document.createElement(`span`);a.className=`dw-linkcard__site`,a.textContent=String(e.site||``)||nH(n),r.append(a),t.append(r);let o=tH(String(e.image||``));if(o.startsWith(`https:`)){let e=document.createElement(`img`);e.className=`dw-linkcard__image`,e.src=o,e.alt=``,e.loading=`lazy`,e.referrerPolicy=`no-referrer`,e.onerror=()=>e.remove(),t.append(e)}},r=e;return n(e.attrs),t.addEventListener(`click`,e=>{this.editor.view.editable&&!(e.ctrlKey||e.metaKey)&&e.preventDefault()}),{dom:t,update:e=>e.type.name===`linkCard`&&(e.attrs!==r.attrs&&n(e.attrs),r=e,!0),ignoreMutation:()=>!0}}}}),lH=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,uH=Jp.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,A(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize,i=new Set([`src`,`width`,`height`]);return({node:a,getPos:o,HTMLAttributes:s,editor:c})=>{let l=document.createElement(`img`);l.draggable=!1;let u=A(this.options.HTMLAttributes,s);Object.entries(u).forEach(([e,t])=>{if(t!=null)switch(e){case`src`:case`width`:case`height`:break;default:l.setAttribute(e,t)}}),u.src!==null&&(l.src=u.src);let d={...s},f=e=>{typeof e==`string`&&e!==``?l.getAttribute(`src`)!==e&&(l.src=e):(l.hasAttribute(`src`)&&l.removeAttribute(`src`),l.src!==``&&(l.src=``))};f(s.src);let p=new qp({element:l,editor:c,node:a,getPos:o,onResize:(e,t)=>{l.style.width=`${e}px`,l.style.height=`${t}px`},onCommit:(e,t)=>{let n=o();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:e=>{if(e.type!==a.type)return!1;let t=Lu(e,c.extensionManager.attributes.filter(t=>t.type===e.type.name));return Object.keys(d).forEach(e=>{!i.has(e)&&!(e in t)&&l.removeAttribute(e)}),Object.entries(t).forEach(([e,t])=>{i.has(e)||(t==null?l.removeAttribute(e):l.setAttribute(e,t))}),f(t.src),d=t,!0},options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),m=p.dom,h=()=>{m.style.visibility=``,m.style.pointerEvents=``};return m.style.visibility=`hidden`,m.style.pointerEvents=`none`,l.complete&&l.naturalWidth>0?h():(l.onload=h,l.onerror=h),p}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[Up({find:lH,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function dH(e,t){return/^(audio|video)\//.test(e)||/\.(mp3|mp4|mpeg|mpga|m4a|wav|webm|ogg|oga|flac|aac|opus|mov)$/i.test(t)}async function fH(e,t,n,r){if(t.upload)for(let i of n){let n=await t.upload(i),a=n.mime.startsWith(`image/`)?{type:`image`,attrs:{src:n.url,alt:n.name}}:{type:`fileAttachment`,attrs:{url:n.url,name:n.name,size:n.size,mime:n.mime,view:Rj(n.mime,n.name)?`preview`:`card`}};e.chain().focus().insertContentAt(r??e.state.selection.to,a).run(),r=void 0}}var pH=uH.extend({addOptions(){return{...this.parent(),host:void 0,inline:!1,allowBase64:!1}},addNodeView(){return({node:e})=>{let t=document.createElement(`img`),n=e=>{let n=String(e.attrs.src??``);t.src=this.options.host?this.options.host.resolve(n):n,t.alt=String(e.attrs.alt??``),e.attrs.title&&(t.title=String(e.attrs.title))};return n(e),t.draggable=!0,{dom:t,update:t=>t.type===e.type&&(n(t),!0)}}}});function mH(e){if(!e)return``;let t=[`B`,`KB`,`MB`,`GB`],n=0,r=e;for(;r>=1024&&n({editor:e,commands:t})=>{let n=e.getAttributes(this.name);return!e.isActive(this.name)||!Rj(n.mime,n.name)?!1:t.updateAttributes(this.name,{view:n.view===`preview`?`card`:`preview`})}}},parseHTML(){return[{tag:`div[data-type=file]`,getAttrs:e=>({url:e.getAttribute(`data-url`)??``,name:e.getAttribute(`data-name`)??e.textContent??`file`,size:Number(e.getAttribute(`data-size`)??0),mime:e.getAttribute(`data-mime`)??``,view:e.getAttribute(`data-view`)===`preview`?`preview`:`card`})}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`file`,"data-url":e.attrs.url,"data-name":e.attrs.name,"data-size":e.attrs.size,"data-mime":e.attrs.mime,"data-view":e.attrs.view}),[`a`,{href:e.attrs.url,download:e.attrs.name},e.attrs.name]]},addNodeView(){return({node:e,editor:t,getPos:n})=>{let{host:r,loadPdf:i,labels:a}=this.options,o=document.createElement(`div`);o.className=`dw-file-block`,o.setAttribute(`data-type`,`file`);let s=document.createElement(`div`);s.className=`dw-file`;let c=document.createElement(`a`);c.className=`dw-file__name`,c.target=`_blank`,c.rel=`noopener`;let l=document.createElement(`span`);l.className=`dw-file__size`,s.append(c,l),o.append(s);let u=null,d=null,f=e,p=async()=>{let e=r?.transcribe;if(e&&u&&a){u.disabled=!0,u.textContent=a.blocks.transcribing,d&&(d.textContent=``);try{let r=await e(String(f.attrs.url??``),String(f.attrs.name??`file`)),i=typeof n==`function`?n():void 0;i!==void 0&&r&&t.chain().insertContentAt(i+f.nodeSize,r).run()}catch(e){d&&(d.textContent=e instanceof Error&&e.message?e.message:a.blocks.transcribeFailed)}finally{u&&(u.disabled=!1,u.textContent=a.blocks.transcribe)}}},m=null,h=null,g=``,_=e=>{let n=String(e.attrs.url??``),_=r?r.resolve(n):n;c.href=_,c.textContent=String(e.attrs.name??`file`),l.textContent=mH(Number(e.attrs.size??0)),f=e;let v=!!r?.transcribe&&!!a&&t.isEditable&&dH(String(e.attrs.mime??``),String(e.attrs.name??``));v&&!u&&a?(u=document.createElement(`button`),u.type=`button`,u.className=`dw-file__action`,u.textContent=a.blocks.transcribe,u.title=a.blocks.transcribeHint,u.setAttribute(`data-testid`,`file-transcribe`),u.addEventListener(`click`,()=>void p()),d=document.createElement(`span`),d.className=`dw-file__status`,d.setAttribute(`role`,`status`),s.append(u),o.append(d)):!v&&u&&(u.remove(),d?.remove(),u=d=null),!(e.attrs.view===`preview`&&Rj(e.attrs.mime,e.attrs.name)&&n)||!i||!a?(h?.(),h=null,m?.remove(),m=null,g=``):g!==_&&(h?.(),m||(m=document.createElement(`div`),m.className=`dw-pdf`,m.tabIndex=0,m.setAttribute(`role`,`document`),o.append(m)),m.setAttribute(`aria-label`,String(e.attrs.name??`PDF`)),g=_,h=zj(m,_,i,a))};return _(e),{dom:o,update:t=>t.type===e.type&&(_(t),!0),stopEvent:e=>!!u&&u.contains(e.target)||!!m&&m.contains(e.target)&&e.type!==`mousedown`,ignoreMutation:()=>!0,destroy:()=>h?.()}}}}),gH=Tp.create({name:`fileDrop`,addOptions(){return{host:void 0,onError:void 0}},addProseMirrorPlugins(){let e=this.options.host;return e?[_H(()=>this.editor,e,this.options.onError)]:[]}});function _H(e,t,n){let r=(r,i)=>{let a=e();return!a||!r.length||!t.upload?!1:(fH(a,t,r,i).catch(n),!0)};return new D({key:new Un(`docwellFileDrop`),props:{handlePaste(e,t){return r([...t.clipboardData?.files??[]])},handleDrop(e,t){let n=[...t.dataTransfer?.files??[]];if(!n.length)return!1;let i=e.posAtCoords({left:t.clientX,top:t.clientY});return t.preventDefault(),r(n,i?.pos)}}})}var vH=new Un(`dwFind`),yH=``;function bH(e,t,n=!1){if(!t)return[];let r=n?t:t.toLowerCase(),i=[];return e.descendants((e,t)=>{if(!e.isTextblock)return!0;let a=``,o=[];e.forEach((e,n)=>{let r=t+1+n;if(e.isText){let t=e.text??``;for(let e=0;ee.from>=r);return a===-1&&(a=i.length?0:-1),{term:t,caseSensitive:n,matches:i,current:a}}function SH(e,t){return t&&e.setSelection(T.create(e.doc,t.from,t.to)).scrollIntoView(),e}var CH=Tp.create({name:`findReplace`,addCommands(){return{setFind:(e,t=!1)=>({state:n,tr:r,dispatch:i})=>{let a=xH(n.doc,e,t,n.selection.from);return r.setMeta(vH,{term:e,caseSensitive:t,near:n.selection.from}),i&&i(SH(r,a.matches[a.current])),!0},findStep:e=>({state:t,tr:n,dispatch:r})=>{let i=vH.getState(t);if(!i?.matches.length)return!1;let a=(i.current+e+i.matches.length)%i.matches.length;return n.setMeta(vH,{current:a}),r&&r(SH(n,i.matches[a])),!0},replaceCurrent:e=>({state:t,tr:n,dispatch:r})=>{let i=vH.getState(t),a=i?.matches[i.current];if(!i||!a)return!1;if(r){n.insertText(e,a.from,a.to),n.setMeta(vH,{term:i.term,caseSensitive:i.caseSensitive,near:a.from+e.length});let t=xH(n.doc,i.term,i.caseSensitive,a.from+e.length);r(SH(n,t.matches[t.current]))}return!0},replaceAll:e=>({state:t,tr:n,dispatch:r})=>{let i=vH.getState(t);if(!i?.matches.length)return!1;if(r){for(let t of[...i.matches].reverse())n.insertText(e,t.from,t.to);n.setMeta(vH,{term:i.term,caseSensitive:i.caseSensitive,near:0}),r(n)}return!0},clearFind:()=>({tr:e,dispatch:t})=>(t&&t(e.setMeta(vH,{clear:!0})),!0)}},addProseMirrorPlugins(){let e={term:``,caseSensitive:!1,matches:[],current:-1};return[new D({key:vH,state:{init:()=>e,apply(t,n,r,i){let a=t.getMeta(vH);if(a&&`clear`in a)return e;if(a&&`term`in a)return xH(i.doc,a.term,a.caseSensitive,a.near);if(a&&`current`in a)return{...n,current:a.current};if(!n.term||!t.docChanged)return n;let o=n.matches[n.current]?.from??0;return xH(i.doc,n.term,n.caseSensitive,t.mapping.map(o))}},props:{decorations(e){let t=vH.getState(e);return t?.matches.length?xs.create(e.doc,t.matches.map((e,n)=>vs.inline(e.from,e.to,{class:n===t.current?`dw-find dw-find-current`:`dw-find`}))):null}}})]}}),L=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15e.replace(wH,`-$1`).toLowerCase(),EH={"&":`&`,">":`>`,"<":`<`,'"':`"`,"'":`'`},DH=/[&><"']/g,OH=e=>String(e).replace(DH,e=>EH[e]),kH=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?kH(e.body[0]):e:e.type===`font`?kH(e.body):e,AH=new Set([`mathord`,`textord`,`atom`]),jH=e=>AH.has(kH(e).type),MH=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},NH={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format `},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color `,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro `,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness `,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size `,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand `,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function PH(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function FH(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:PH(Array.isArray(e.type)?e.type[0]:e.type)}function IH(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?FH(r):a?a(i):i}var LH=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(NH)){var n=NH[t];n&&IH(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new L(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=MH(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},RH=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return qH[JH[this.id]]}sub(){return qH[YH[this.id]]}fracNum(){return qH[XH[this.id]]}fracDen(){return qH[ZH[this.id]]}cramp(){return qH[QH[this.id]]}text(){return qH[$H[this.id]]}isTight(){return this.size>=2}},zH=0,BH=1,VH=2,HH=3,UH=4,WH=5,GH=6,KH=7,qH=[new RH(zH,0,!1),new RH(BH,0,!0),new RH(VH,1,!1),new RH(HH,1,!0),new RH(UH,2,!1),new RH(WH,2,!0),new RH(GH,3,!1),new RH(KH,3,!0)],JH=[UH,WH,UH,WH,GH,KH,GH,KH],YH=[WH,WH,WH,WH,KH,KH,KH,KH],XH=[VH,HH,UH,WH,GH,KH,GH,KH],ZH=[HH,HH,WH,WH,KH,KH,KH,KH],QH=[BH,BH,HH,HH,WH,WH,KH,KH],$H=[zH,BH,VH,HH,VH,HH,VH,HH],R={DISPLAY:qH[zH],TEXT:qH[VH],SCRIPT:qH[UH],SCRIPTSCRIPT:qH[GH]},eU=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function tU(e){for(var t=0;t=i[0]&&e<=i[1])return n.name}return null}var nU=[];eU.forEach(e=>e.blocks.forEach(e=>nU.push(...e)));function rU(e){for(var t=0;t=nU[t]&&e<=nU[t+1])return!0;return!1}var iU=e=>e+` `+e,aU=80,oU=function(e,t){return`M95,`+(622+e+t)+` c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 @@ -178,7 +178,7 @@ c5.3,-9.3,12,-14,20,-14 H400000v`+(40+e)+`H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z -M`+(834+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},rU=function(e,t){return`M263,`+(601+e+t)+`c0.7,0,18,39.7,52,119 +M`+(834+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},sU=function(e,t){return`M263,`+(601+e+t)+`c0.7,0,18,39.7,52,119 c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120 c340,-704.7,510.7,-1060.3,512,-1067 l`+e/2.084+` -`+e+` @@ -188,7 +188,7 @@ s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5, c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1 s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26 c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z -M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},iU=function(e,t){return`M983 `+(10+e+t)+` +M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},cU=function(e,t){return`M983 `+(10+e+t)+` l`+e/3.13+` -`+e+` c4,-6.7,10,-10,18,-10 H400000v`+(40+e)+` H1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7 @@ -197,7 +197,7 @@ c-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30 c26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722 c56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5 c53.7,-170.3,84.5,-266.8,92.5,-289.5z -M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},aU=function(e,t){return`M424,`+(2398+e+t)+` +M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},lU=function(e,t){return`M424,`+(2398+e+t)+` c-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514 c0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20 s-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121 @@ -207,18 +207,18 @@ v`+(40+e)+`H1014.6 s-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185 c-2,6,-10,9,-24,9 c-8,0,-12,-0.7,-12,-2z M`+(1001+e)+` `+t+` -h400000v`+(40+e)+`h-400000z`},oU=function(e,t){return`M473,`+(2713+e+t)+` +h400000v`+(40+e)+`h-400000z`},uU=function(e,t){return`M473,`+(2713+e+t)+` c339.3,-1799.3,509.3,-2700,510,-2702 l`+e/5.298+` -`+e+` c3.3,-7.3,9.3,-11,18,-11 H400000v`+(40+e)+`H1017.7 s-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9 c-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200 c0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26 s76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104, -606zM`+(1001+e)+` `+t+`h400000v`+(40+e)+`H1017.7z`},sU=function(e){var t=e/2;return`M400000 `+e+` H0 L`+t+` 0 l65 45 L145 `+(e-80)+` H400000z`},cU=function(e,t,n){var r=n-54-t-e;return`M702 `+(e+t)+`H400000`+(40+e)+` +606zM`+(1001+e)+` `+t+`h400000v`+(40+e)+`H1017.7z`},dU=function(e){var t=e/2;return`M400000 `+e+` H0 L`+t+` 0 l65 45 L145 `+(e-80)+` H400000z`},fU=function(e,t,n){var r=n-54-t-e;return`M702 `+(e+t)+`H400000`+(40+e)+` H742v`+r+`l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1 h-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170 c-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667 -219 661 l218 661zM702 `+t+`H400000v`+(40+e)+`H742z`},lU=function(e,t,n){t=1e3*t;var r=``;switch(e){case`sqrtMain`:r=nU(t,tU);break;case`sqrtSize1`:r=rU(t,tU);break;case`sqrtSize2`:r=iU(t,tU);break;case`sqrtSize3`:r=aU(t,tU);break;case`sqrtSize4`:r=oU(t,tU);break;case`sqrtTall`:r=cU(t,tU,n)}return r},uU=function(e,t){switch(e){case`⎜`:return eU(`M291 0 H417 V`+t+` H291z`);case`∣`:return eU(`M145 0 H188 V`+t+` H145z`);case`∥`:return eU(`M145 0 H188 V`+t+` H145z`)+eU(`M367 0 H410 V`+t+` H367z`);case`⎟`:return eU(`M457 0 H583 V`+t+` H457z`);case`⎢`:return eU(`M319 0 H403 V`+t+` H319z`);case`⎥`:return eU(`M263 0 H347 V`+t+` H263z`);case`⎪`:return eU(`M384 0 H504 V`+t+` H384z`);case`⏐`:return eU(`M312 0 H355 V`+t+` H312z`);case`‖`:return eU(`M257 0 H300 V`+t+` H257z`)+eU(`M478 0 H521 V`+t+` H478z`);default:return``}},dU={doubleleftarrow:`M262 157 +219 661 l218 661zM702 `+t+`H400000v`+(40+e)+`H742z`},pU=function(e,t,n){t=1e3*t;var r=``;switch(e){case`sqrtMain`:r=oU(t,aU);break;case`sqrtSize1`:r=sU(t,aU);break;case`sqrtSize2`:r=cU(t,aU);break;case`sqrtSize3`:r=lU(t,aU);break;case`sqrtSize4`:r=uU(t,aU);break;case`sqrtTall`:r=fU(t,aU,n)}return r},mU=function(e,t){switch(e){case`⎜`:return iU(`M291 0 H417 V`+t+` H291z`);case`∣`:return iU(`M145 0 H188 V`+t+` H145z`);case`∥`:return iU(`M145 0 H188 V`+t+` H145z`)+iU(`M367 0 H410 V`+t+` H367z`);case`⎟`:return iU(`M457 0 H583 V`+t+` H457z`);case`⎢`:return iU(`M319 0 H403 V`+t+` H319z`);case`⎥`:return iU(`M263 0 H347 V`+t+` H263z`);case`⎪`:return iU(`M384 0 H504 V`+t+` H384z`);case`⏐`:return iU(`M312 0 H355 V`+t+` H312z`);case`‖`:return iU(`M257 0 H300 V`+t+` H257z`)+iU(`M478 0 H521 V`+t+` H478z`);default:return``}},hU={doubleleftarrow:`M262 157 l10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3 0-12.2.5-14.5 1.5-2.3 1-4.8 4.5-7.5 10.5-49.3 97.3-121.7 169.3-217 216-28 14-57.3 25-88 33-6.7 2-11 3.8-13 5.5-2 1.7-3 4.2-3 7.5s1 5.8 3 7.5 @@ -264,10 +264,10 @@ m0 0v40h400000v-40z`,leftharpoondown:`M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 v40h399900v-40zM0 241v40h399900v-40zm0 0v40h399900v-40z`,lefthook:`M400000 281 H103s-33-11.2-61-33.5S0 197.3 0 164s14.2-61.2 42.5 -83.5C70.8 58.2 104 47 142 47 c16.7 0 25 6.7 25 20 0 12-8.7 18.7-26 20-40 3.3 -68.7 15.7-86 37-10 12-15 25.3-15 40 0 22.7 9.8 40.7 29.5 54 19.7 13.3 43.5 21 - 71.5 23h399859zM103 281v-40h399897v40z`,leftlinesegment:eU(`M40 281 V428 H0 V94 H40 V241 H400000 v40z`),leftbracketunder:eU(`M0 0 h120 V290 H399995 v120 H0z`),leftbracketover:eU(`M0 440 h120 V150 H399995 v-120 H0z`),leftmapsto:eU(`M40 281 V448H0V74H40V241H400000v40z`),leftToFrom:`M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23 + 71.5 23h399859zM103 281v-40h399897v40z`,leftlinesegment:iU(`M40 281 V428 H0 V94 H40 V241 H400000 v40z`),leftbracketunder:iU(`M0 0 h120 V290 H399995 v120 H0z`),leftbracketover:iU(`M0 440 h120 V150 H399995 v-120 H0z`),leftmapsto:iU(`M40 281 V448H0V74H40V241H400000v40z`),leftToFrom:`M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23 -.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8 c28.7-32 52-65.7 70-101 10.7-23.3 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 265.3 - 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z`,longequal:eU(`M0 50 h400000 v40H0z m0 194h40000v40H0z`),midbrace:`M200428 334 + 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z`,longequal:iU(`M0 50 h400000 v40H0z m0 194h40000v40H0z`),midbrace:`M200428 334 c-100.7-8.3-195.3-44-280-108-55.3-42-101.7-93-139-153l-9-14c-2.7 4-5.7 8.7-9 14 -53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7 311.7-78.3 403-201 6-8 9.7-12 11-12 .7-.7 6.7-1 18-1s17.3.3 18 1c1.3 0 5 4 11 @@ -316,7 +316,7 @@ m0 0v40h399900v-40z m100 194v40h399900v-40zm0 0v40h399900v-40z`,rightharpoondown m0-194v40h400000v-40zm0 0v40h400000v-40z`,righthook:`M399859 241c-764 0 0 0 0 0 40-3.3 68.7-15.7 86-37 10-12 15-25.3 15-40 0-22.7-9.8-40.7-29.5-54-19.7-13.3-43.5-21-71.5-23-17.3-1.3-26-8-26-20 0 -13.3 8.7-20 26-20 38 0 71 11.2 99 33.5 0 0 7 5.6 21 16.7 14 11.2 21 33.5 21 - 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z`,rightlinesegment:eU(`M399960 241 V94 h40 V428 h-40 V281 H0 v-40z`),rightbracketunder:eU(`M399995 0 h-120 V290 H0 v120 H400000z`),rightbracketover:eU(`M399995 440 h-120 V150 H0 v-120 H399995z`),rightToFrom:`M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23 + 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z`,rightlinesegment:iU(`M399960 241 V94 h40 V428 h-40 V281 H0 v-40z`),rightbracketunder:iU(`M399995 0 h-120 V290 H0 v120 H400000z`),rightbracketover:iU(`M399995 440 h-120 V150 H0 v-120 H399995z`),rightToFrom:`M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32 -52 65.7-70 101-10.7 23.3-16 35.7-16 37 0 .7 7.7 1 23 1h23c24-69.3 71.3-125 142 -167z M100 147v40h399900v-40zM0 341v40h399900v-40z`,twoheadleftarrow:`M0 167c68 40 @@ -389,7 +389,7 @@ M93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z` c4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199, -231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6 c-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z -M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`},fU=function(e,t){switch(e){case`lbrack`:return`M403 1759 V84 H666 V0 H319 V1759 v`+t+` v1759 v84 h347 v-84 +M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`},gU=function(e,t){switch(e){case`lbrack`:return`M403 1759 V84 H666 V0 H319 V1759 v`+t+` v1759 v84 h347 v-84 H403z M403 1759 V0 H319 V1759 v`+t+` v1759 v84 h84z`;case`rbrack`:return`M347 1759 V0 H0 V84 H263 V1759 v`+t+` v1759 H0 v84 H347z M347 1759 V0 H263 V1759 v`+t+` v1759 h84z`;case`vert`:return`M145 15 v585 v`+t+` v585 c2.667,10,9.667,15,21,15 c10,0,16.667,-5,20,-15 v-585 v`+-t+` v-585 c-2.667,-10,-9.667,-15,-21,-15 @@ -417,17 +417,80 @@ c-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6 c0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17 c242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558 l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7, --470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;default:throw Error(`Unknown stretchy delimiter.`)}};function pU(e){return`toText`in e}var mU=class{constructor(e){this.children=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.children=e,this.classes=[],this.height=0,this.depth=0,this.maxFontSize=0,this.style={}}hasClass(e){return this.classes.includes(e)}toNode(){for(var e=document.createDocumentFragment(),t=0;t{if(pU(e))return e.toText();throw Error(`Expected MathDomNode with toText, got `+e.constructor.name)}).join(``)}},hU={pt:1,mm:7227/2540,cm:7227/254,in:72.27,bp:803/800,pc:12,dd:1238/1157,cc:14856/1157,nd:685/642,nc:1370/107,sp:1/65536,px:803/800},gU={ex:!0,em:!0,mu:!0},_U=function(e){return typeof e!=`string`&&(e=e.unit),e in hU||e in gU||e===`ex`},vU=function(e,t){var n;if(e.unit in hU)n=hU[e.unit]/t.fontMetrics().ptPerEm/t.sizeMultiplier;else if(e.unit===`mu`)n=t.fontMetrics().cssEmPerMu;else{var r=t.style.isTight()?t.havingStyle(t.style.text()):t;if(e.unit===`ex`)n=r.fontMetrics().xHeight;else if(e.unit===`em`)n=r.fontMetrics().quad;else throw new L(`Invalid unit: '`+e.unit+`'`);r!==t&&(n*=r.sizeMultiplier/t.sizeMultiplier)}return Math.min(e.number*n,t.maxSize)},z=function(e){return+e.toFixed(4)+`em`},yU=function(e){return e.filter(e=>e).join(` `)},bU=function(e){var t=``;for(var n of Object.keys(e)){var r=e[n];r!==void 0&&(t+=xH(n)+`:`+r+`;`)}return t},xU=function(e,t,n){if(this.classes=e||[],this.attributes={},this.height=0,this.depth=0,this.maxFontSize=0,this.style=n||{},t){t.style.isTight()&&this.classes.push(`mtight`);var r=t.getColor();r&&(this.style.color=r)}},SU=function(e){var t=document.createElement(e);t.className=yU(this.classes),Object.assign(t.style,this.style);for(var n of Object.keys(this.attributes))t.setAttribute(n,this.attributes[n]);for(var r=0;r/=\x00-\x1f]/,wU=function(e){var t=`<`+e;this.classes.length&&(t+=` class="`+wH(yU(this.classes))+`"`);var n=bU(this.style);n&&(t+=` style="`+wH(n)+`"`);for(var r of Object.keys(this.attributes)){if(CU.test(r))throw new L(`Invalid attribute name '`+r+`'`);t+=` `+r+`="`+wH(this.attributes[r])+`"`}t+=`>`;for(var i=0;i`,t},TU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.width=void 0,this.maxFontSize=void 0,this.style=void 0,this.italic=void 0,xU.call(this,e,n,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return SU.call(this,`span`)}toMarkup(){return wU.call(this,`span`)}},EU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,xU.call(this,t,r),this.children=n||[],this.setAttribute(`href`,e)}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return SU.call(this,`a`)}toMarkup(){return wU.call(this,`a`)}},DU=class{constructor(e,t,n){this.src=void 0,this.alt=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.alt=t,this.src=e,this.classes=[`mord`],this.height=0,this.depth=0,this.maxFontSize=0,this.style=n}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createElement(`img`);return e.src=this.src,e.alt=this.alt,e.className=`mord`,Object.assign(e.style,this.style),e}toMarkup(){var e=``+wH(this.alt)+``,e}},OU={î:`ı̂`,ï:`ı̈`,í:`ı́`,ì:`ı̀`},kU=class{constructor(e,t,n,r,i,a,o,s){this.text=void 0,this.height=void 0,this.depth=void 0,this.italic=void 0,this.skew=void 0,this.width=void 0,this.maxFontSize=void 0,this.classes=void 0,this.style=void 0,this.text=e,this.height=t||0,this.depth=n||0,this.italic=r||0,this.skew=i||0,this.width=a||0,this.classes=o||[],this.style=s||{},this.maxFontSize=0;var c=ZH(this.text.charCodeAt(0));c&&this.classes.push(c+`_fallback`),/[îïíì]/.test(this.text)&&(this.text=OU[this.text])}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createTextNode(this.text),t=null;return this.italic>0&&(t=document.createElement(`span`),t.style.marginRight=z(this.italic)),this.classes.length>0&&(t||=document.createElement(`span`),t.className=yU(this.classes)),Object.keys(this.style).length>0&&(t||=document.createElement(`span`),Object.assign(t.style,this.style)),t?(t.appendChild(e),t):e}toMarkup(){var e=!1,t=`0&&(n+=`margin-right:`+z(this.italic)+`;`),n+=bU(this.style),n&&(e=!0,t+=` style="`+wH(n)+`"`);var r=wH(this.text);return e?(t+=`>`,t+=r,t+=``,t):r}},AU=class{constructor(e,t){this.children=void 0,this.attributes=void 0,this.children=e||[],this.attributes=t||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);for(var n=0;n`;for(var n=0;n`,e}},jU=class{constructor(e,t){this.pathName=void 0,this.alternate=void 0,this.pathName=e,this.alternate=t}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return this.alternate?e.setAttribute(`d`,this.alternate):e.setAttribute(`d`,dU[this.pathName]),e}toMarkup(){return this.alternate?``:``}},MU=class{constructor(e){this.attributes=void 0,this.attributes=e||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);return e}toMarkup(){var e=``,e}};function NU(e){if(e instanceof kU)return e;throw Error(`Expected symbolNode but got `+String(e)+`.`)}function PU(e){if(e instanceof TU)return e;throw Error(`Expected span but got `+String(e)+`.`)}var FU=e=>e instanceof TU||e instanceof EU||e instanceof mU,IU={"AMS-Regular":{32:[0,0,0,0,.25],65:[0,.68889,0,0,.72222],66:[0,.68889,0,0,.66667],67:[0,.68889,0,0,.72222],68:[0,.68889,0,0,.72222],69:[0,.68889,0,0,.66667],70:[0,.68889,0,0,.61111],71:[0,.68889,0,0,.77778],72:[0,.68889,0,0,.77778],73:[0,.68889,0,0,.38889],74:[.16667,.68889,0,0,.5],75:[0,.68889,0,0,.77778],76:[0,.68889,0,0,.66667],77:[0,.68889,0,0,.94445],78:[0,.68889,0,0,.72222],79:[.16667,.68889,0,0,.77778],80:[0,.68889,0,0,.61111],81:[.16667,.68889,0,0,.77778],82:[0,.68889,0,0,.72222],83:[0,.68889,0,0,.55556],84:[0,.68889,0,0,.66667],85:[0,.68889,0,0,.72222],86:[0,.68889,0,0,.72222],87:[0,.68889,0,0,1],88:[0,.68889,0,0,.72222],89:[0,.68889,0,0,.72222],90:[0,.68889,0,0,.66667],107:[0,.68889,0,0,.55556],160:[0,0,0,0,.25],165:[0,.675,.025,0,.75],174:[.15559,.69224,0,0,.94666],240:[0,.68889,0,0,.55556],295:[0,.68889,0,0,.54028],710:[0,.825,0,0,2.33334],732:[0,.9,0,0,2.33334],770:[0,.825,0,0,2.33334],771:[0,.9,0,0,2.33334],989:[.08167,.58167,0,0,.77778],1008:[0,.43056,.04028,0,.66667],8245:[0,.54986,0,0,.275],8463:[0,.68889,0,0,.54028],8487:[0,.68889,0,0,.72222],8498:[0,.68889,0,0,.55556],8502:[0,.68889,0,0,.66667],8503:[0,.68889,0,0,.44445],8504:[0,.68889,0,0,.66667],8513:[0,.68889,0,0,.63889],8592:[-.03598,.46402,0,0,.5],8594:[-.03598,.46402,0,0,.5],8602:[-.13313,.36687,0,0,1],8603:[-.13313,.36687,0,0,1],8606:[.01354,.52239,0,0,1],8608:[.01354,.52239,0,0,1],8610:[.01354,.52239,0,0,1.11111],8611:[.01354,.52239,0,0,1.11111],8619:[0,.54986,0,0,1],8620:[0,.54986,0,0,1],8621:[-.13313,.37788,0,0,1.38889],8622:[-.13313,.36687,0,0,1],8624:[0,.69224,0,0,.5],8625:[0,.69224,0,0,.5],8630:[0,.43056,0,0,1],8631:[0,.43056,0,0,1],8634:[.08198,.58198,0,0,.77778],8635:[.08198,.58198,0,0,.77778],8638:[.19444,.69224,0,0,.41667],8639:[.19444,.69224,0,0,.41667],8642:[.19444,.69224,0,0,.41667],8643:[.19444,.69224,0,0,.41667],8644:[.1808,.675,0,0,1],8646:[.1808,.675,0,0,1],8647:[.1808,.675,0,0,1],8648:[.19444,.69224,0,0,.83334],8649:[.1808,.675,0,0,1],8650:[.19444,.69224,0,0,.83334],8651:[.01354,.52239,0,0,1],8652:[.01354,.52239,0,0,1],8653:[-.13313,.36687,0,0,1],8654:[-.13313,.36687,0,0,1],8655:[-.13313,.36687,0,0,1],8666:[.13667,.63667,0,0,1],8667:[.13667,.63667,0,0,1],8669:[-.13313,.37788,0,0,1],8672:[-.064,.437,0,0,1.334],8674:[-.064,.437,0,0,1.334],8705:[0,.825,0,0,.5],8708:[0,.68889,0,0,.55556],8709:[.08167,.58167,0,0,.77778],8717:[0,.43056,0,0,.42917],8722:[-.03598,.46402,0,0,.5],8724:[.08198,.69224,0,0,.77778],8726:[.08167,.58167,0,0,.77778],8733:[0,.69224,0,0,.77778],8736:[0,.69224,0,0,.72222],8737:[0,.69224,0,0,.72222],8738:[.03517,.52239,0,0,.72222],8739:[.08167,.58167,0,0,.22222],8740:[.25142,.74111,0,0,.27778],8741:[.08167,.58167,0,0,.38889],8742:[.25142,.74111,0,0,.5],8756:[0,.69224,0,0,.66667],8757:[0,.69224,0,0,.66667],8764:[-.13313,.36687,0,0,.77778],8765:[-.13313,.37788,0,0,.77778],8769:[-.13313,.36687,0,0,.77778],8770:[-.03625,.46375,0,0,.77778],8774:[.30274,.79383,0,0,.77778],8776:[-.01688,.48312,0,0,.77778],8778:[.08167,.58167,0,0,.77778],8782:[.06062,.54986,0,0,.77778],8783:[.06062,.54986,0,0,.77778],8785:[.08198,.58198,0,0,.77778],8786:[.08198,.58198,0,0,.77778],8787:[.08198,.58198,0,0,.77778],8790:[0,.69224,0,0,.77778],8791:[.22958,.72958,0,0,.77778],8796:[.08198,.91667,0,0,.77778],8806:[.25583,.75583,0,0,.77778],8807:[.25583,.75583,0,0,.77778],8808:[.25142,.75726,0,0,.77778],8809:[.25142,.75726,0,0,.77778],8812:[.25583,.75583,0,0,.5],8814:[.20576,.70576,0,0,.77778],8815:[.20576,.70576,0,0,.77778],8816:[.30274,.79383,0,0,.77778],8817:[.30274,.79383,0,0,.77778],8818:[.22958,.72958,0,0,.77778],8819:[.22958,.72958,0,0,.77778],8822:[.1808,.675,0,0,.77778],8823:[.1808,.675,0,0,.77778],8828:[.13667,.63667,0,0,.77778],8829:[.13667,.63667,0,0,.77778],8830:[.22958,.72958,0,0,.77778],8831:[.22958,.72958,0,0,.77778],8832:[.20576,.70576,0,0,.77778],8833:[.20576,.70576,0,0,.77778],8840:[.30274,.79383,0,0,.77778],8841:[.30274,.79383,0,0,.77778],8842:[.13597,.63597,0,0,.77778],8843:[.13597,.63597,0,0,.77778],8847:[.03517,.54986,0,0,.77778],8848:[.03517,.54986,0,0,.77778],8858:[.08198,.58198,0,0,.77778],8859:[.08198,.58198,0,0,.77778],8861:[.08198,.58198,0,0,.77778],8862:[0,.675,0,0,.77778],8863:[0,.675,0,0,.77778],8864:[0,.675,0,0,.77778],8865:[0,.675,0,0,.77778],8872:[0,.69224,0,0,.61111],8873:[0,.69224,0,0,.72222],8874:[0,.69224,0,0,.88889],8876:[0,.68889,0,0,.61111],8877:[0,.68889,0,0,.61111],8878:[0,.68889,0,0,.72222],8879:[0,.68889,0,0,.72222],8882:[.03517,.54986,0,0,.77778],8883:[.03517,.54986,0,0,.77778],8884:[.13667,.63667,0,0,.77778],8885:[.13667,.63667,0,0,.77778],8888:[0,.54986,0,0,1.11111],8890:[.19444,.43056,0,0,.55556],8891:[.19444,.69224,0,0,.61111],8892:[.19444,.69224,0,0,.61111],8901:[0,.54986,0,0,.27778],8903:[.08167,.58167,0,0,.77778],8905:[.08167,.58167,0,0,.77778],8906:[.08167,.58167,0,0,.77778],8907:[0,.69224,0,0,.77778],8908:[0,.69224,0,0,.77778],8909:[-.03598,.46402,0,0,.77778],8910:[0,.54986,0,0,.76042],8911:[0,.54986,0,0,.76042],8912:[.03517,.54986,0,0,.77778],8913:[.03517,.54986,0,0,.77778],8914:[0,.54986,0,0,.66667],8915:[0,.54986,0,0,.66667],8916:[0,.69224,0,0,.66667],8918:[.0391,.5391,0,0,.77778],8919:[.0391,.5391,0,0,.77778],8920:[.03517,.54986,0,0,1.33334],8921:[.03517,.54986,0,0,1.33334],8922:[.38569,.88569,0,0,.77778],8923:[.38569,.88569,0,0,.77778],8926:[.13667,.63667,0,0,.77778],8927:[.13667,.63667,0,0,.77778],8928:[.30274,.79383,0,0,.77778],8929:[.30274,.79383,0,0,.77778],8934:[.23222,.74111,0,0,.77778],8935:[.23222,.74111,0,0,.77778],8936:[.23222,.74111,0,0,.77778],8937:[.23222,.74111,0,0,.77778],8938:[.20576,.70576,0,0,.77778],8939:[.20576,.70576,0,0,.77778],8940:[.30274,.79383,0,0,.77778],8941:[.30274,.79383,0,0,.77778],8994:[.19444,.69224,0,0,.77778],8995:[.19444,.69224,0,0,.77778],9416:[.15559,.69224,0,0,.90222],9484:[0,.69224,0,0,.5],9488:[0,.69224,0,0,.5],9492:[0,.37788,0,0,.5],9496:[0,.37788,0,0,.5],9585:[.19444,.68889,0,0,.88889],9586:[.19444,.74111,0,0,.88889],9632:[0,.675,0,0,.77778],9633:[0,.675,0,0,.77778],9650:[0,.54986,0,0,.72222],9651:[0,.54986,0,0,.72222],9654:[.03517,.54986,0,0,.77778],9660:[0,.54986,0,0,.72222],9661:[0,.54986,0,0,.72222],9664:[.03517,.54986,0,0,.77778],9674:[.11111,.69224,0,0,.66667],9733:[.19444,.69224,0,0,.94445],10003:[0,.69224,0,0,.83334],10016:[0,.69224,0,0,.83334],10731:[.11111,.69224,0,0,.66667],10846:[.19444,.75583,0,0,.61111],10877:[.13667,.63667,0,0,.77778],10878:[.13667,.63667,0,0,.77778],10885:[.25583,.75583,0,0,.77778],10886:[.25583,.75583,0,0,.77778],10887:[.13597,.63597,0,0,.77778],10888:[.13597,.63597,0,0,.77778],10889:[.26167,.75726,0,0,.77778],10890:[.26167,.75726,0,0,.77778],10891:[.48256,.98256,0,0,.77778],10892:[.48256,.98256,0,0,.77778],10901:[.13667,.63667,0,0,.77778],10902:[.13667,.63667,0,0,.77778],10933:[.25142,.75726,0,0,.77778],10934:[.25142,.75726,0,0,.77778],10935:[.26167,.75726,0,0,.77778],10936:[.26167,.75726,0,0,.77778],10937:[.26167,.75726,0,0,.77778],10938:[.26167,.75726,0,0,.77778],10949:[.25583,.75583,0,0,.77778],10950:[.25583,.75583,0,0,.77778],10955:[.28481,.79383,0,0,.77778],10956:[.28481,.79383,0,0,.77778],57350:[.08167,.58167,0,0,.22222],57351:[.08167,.58167,0,0,.38889],57352:[.08167,.58167,0,0,.77778],57353:[0,.43056,.04028,0,.66667],57356:[.25142,.75726,0,0,.77778],57357:[.25142,.75726,0,0,.77778],57358:[.41951,.91951,0,0,.77778],57359:[.30274,.79383,0,0,.77778],57360:[.30274,.79383,0,0,.77778],57361:[.41951,.91951,0,0,.77778],57366:[.25142,.75726,0,0,.77778],57367:[.25142,.75726,0,0,.77778],57368:[.25142,.75726,0,0,.77778],57369:[.25142,.75726,0,0,.77778],57370:[.13597,.63597,0,0,.77778],57371:[.13597,.63597,0,0,.77778]},"Caligraphic-Regular":{32:[0,0,0,0,.25],65:[0,.68333,0,.19445,.79847],66:[0,.68333,.03041,.13889,.65681],67:[0,.68333,.05834,.13889,.52653],68:[0,.68333,.02778,.08334,.77139],69:[0,.68333,.08944,.11111,.52778],70:[0,.68333,.09931,.11111,.71875],71:[.09722,.68333,.0593,.11111,.59487],72:[0,.68333,.00965,.11111,.84452],73:[0,.68333,.07382,0,.54452],74:[.09722,.68333,.18472,.16667,.67778],75:[0,.68333,.01445,.05556,.76195],76:[0,.68333,0,.13889,.68972],77:[0,.68333,0,.13889,1.2009],78:[0,.68333,.14736,.08334,.82049],79:[0,.68333,.02778,.11111,.79611],80:[0,.68333,.08222,.08334,.69556],81:[.09722,.68333,0,.11111,.81667],82:[0,.68333,0,.08334,.8475],83:[0,.68333,.075,.13889,.60556],84:[0,.68333,.25417,0,.54464],85:[0,.68333,.09931,.08334,.62583],86:[0,.68333,.08222,0,.61278],87:[0,.68333,.08222,.08334,.98778],88:[0,.68333,.14643,.13889,.7133],89:[.09722,.68333,.08222,.08334,.66834],90:[0,.68333,.07944,.13889,.72473],160:[0,0,0,0,.25]},"Fraktur-Regular":{32:[0,0,0,0,.25],33:[0,.69141,0,0,.29574],34:[0,.69141,0,0,.21471],38:[0,.69141,0,0,.73786],39:[0,.69141,0,0,.21201],40:[.24982,.74947,0,0,.38865],41:[.24982,.74947,0,0,.38865],42:[0,.62119,0,0,.27764],43:[.08319,.58283,0,0,.75623],44:[0,.10803,0,0,.27764],45:[.08319,.58283,0,0,.75623],46:[0,.10803,0,0,.27764],47:[.24982,.74947,0,0,.50181],48:[0,.47534,0,0,.50181],49:[0,.47534,0,0,.50181],50:[0,.47534,0,0,.50181],51:[.18906,.47534,0,0,.50181],52:[.18906,.47534,0,0,.50181],53:[.18906,.47534,0,0,.50181],54:[0,.69141,0,0,.50181],55:[.18906,.47534,0,0,.50181],56:[0,.69141,0,0,.50181],57:[.18906,.47534,0,0,.50181],58:[0,.47534,0,0,.21606],59:[.12604,.47534,0,0,.21606],61:[-.13099,.36866,0,0,.75623],63:[0,.69141,0,0,.36245],65:[0,.69141,0,0,.7176],66:[0,.69141,0,0,.88397],67:[0,.69141,0,0,.61254],68:[0,.69141,0,0,.83158],69:[0,.69141,0,0,.66278],70:[.12604,.69141,0,0,.61119],71:[0,.69141,0,0,.78539],72:[.06302,.69141,0,0,.7203],73:[0,.69141,0,0,.55448],74:[.12604,.69141,0,0,.55231],75:[0,.69141,0,0,.66845],76:[0,.69141,0,0,.66602],77:[0,.69141,0,0,1.04953],78:[0,.69141,0,0,.83212],79:[0,.69141,0,0,.82699],80:[.18906,.69141,0,0,.82753],81:[.03781,.69141,0,0,.82699],82:[0,.69141,0,0,.82807],83:[0,.69141,0,0,.82861],84:[0,.69141,0,0,.66899],85:[0,.69141,0,0,.64576],86:[0,.69141,0,0,.83131],87:[0,.69141,0,0,1.04602],88:[0,.69141,0,0,.71922],89:[.18906,.69141,0,0,.83293],90:[.12604,.69141,0,0,.60201],91:[.24982,.74947,0,0,.27764],93:[.24982,.74947,0,0,.27764],94:[0,.69141,0,0,.49965],97:[0,.47534,0,0,.50046],98:[0,.69141,0,0,.51315],99:[0,.47534,0,0,.38946],100:[0,.62119,0,0,.49857],101:[0,.47534,0,0,.40053],102:[.18906,.69141,0,0,.32626],103:[.18906,.47534,0,0,.5037],104:[.18906,.69141,0,0,.52126],105:[0,.69141,0,0,.27899],106:[0,.69141,0,0,.28088],107:[0,.69141,0,0,.38946],108:[0,.69141,0,0,.27953],109:[0,.47534,0,0,.76676],110:[0,.47534,0,0,.52666],111:[0,.47534,0,0,.48885],112:[.18906,.52396,0,0,.50046],113:[.18906,.47534,0,0,.48912],114:[0,.47534,0,0,.38919],115:[0,.47534,0,0,.44266],116:[0,.62119,0,0,.33301],117:[0,.47534,0,0,.5172],118:[0,.52396,0,0,.5118],119:[0,.52396,0,0,.77351],120:[.18906,.47534,0,0,.38865],121:[.18906,.47534,0,0,.49884],122:[.18906,.47534,0,0,.39054],160:[0,0,0,0,.25],8216:[0,.69141,0,0,.21471],8217:[0,.69141,0,0,.21471],58112:[0,.62119,0,0,.49749],58113:[0,.62119,0,0,.4983],58114:[.18906,.69141,0,0,.33328],58115:[.18906,.69141,0,0,.32923],58116:[.18906,.47534,0,0,.50343],58117:[0,.69141,0,0,.33301],58118:[0,.62119,0,0,.33409],58119:[0,.47534,0,0,.50073]},"Main-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.35],34:[0,.69444,0,0,.60278],35:[.19444,.69444,0,0,.95833],36:[.05556,.75,0,0,.575],37:[.05556,.75,0,0,.95833],38:[0,.69444,0,0,.89444],39:[0,.69444,0,0,.31944],40:[.25,.75,0,0,.44722],41:[.25,.75,0,0,.44722],42:[0,.75,0,0,.575],43:[.13333,.63333,0,0,.89444],44:[.19444,.15556,0,0,.31944],45:[0,.44444,0,0,.38333],46:[0,.15556,0,0,.31944],47:[.25,.75,0,0,.575],48:[0,.64444,0,0,.575],49:[0,.64444,0,0,.575],50:[0,.64444,0,0,.575],51:[0,.64444,0,0,.575],52:[0,.64444,0,0,.575],53:[0,.64444,0,0,.575],54:[0,.64444,0,0,.575],55:[0,.64444,0,0,.575],56:[0,.64444,0,0,.575],57:[0,.64444,0,0,.575],58:[0,.44444,0,0,.31944],59:[.19444,.44444,0,0,.31944],60:[.08556,.58556,0,0,.89444],61:[-.10889,.39111,0,0,.89444],62:[.08556,.58556,0,0,.89444],63:[0,.69444,0,0,.54305],64:[0,.69444,0,0,.89444],65:[0,.68611,0,0,.86944],66:[0,.68611,0,0,.81805],67:[0,.68611,0,0,.83055],68:[0,.68611,0,0,.88194],69:[0,.68611,0,0,.75555],70:[0,.68611,0,0,.72361],71:[0,.68611,0,0,.90416],72:[0,.68611,0,0,.9],73:[0,.68611,0,0,.43611],74:[0,.68611,0,0,.59444],75:[0,.68611,0,0,.90138],76:[0,.68611,0,0,.69166],77:[0,.68611,0,0,1.09166],78:[0,.68611,0,0,.9],79:[0,.68611,0,0,.86388],80:[0,.68611,0,0,.78611],81:[.19444,.68611,0,0,.86388],82:[0,.68611,0,0,.8625],83:[0,.68611,0,0,.63889],84:[0,.68611,0,0,.8],85:[0,.68611,0,0,.88472],86:[0,.68611,.01597,0,.86944],87:[0,.68611,.01597,0,1.18888],88:[0,.68611,0,0,.86944],89:[0,.68611,.02875,0,.86944],90:[0,.68611,0,0,.70277],91:[.25,.75,0,0,.31944],92:[.25,.75,0,0,.575],93:[.25,.75,0,0,.31944],94:[0,.69444,0,0,.575],95:[.31,.13444,.03194,0,.575],97:[0,.44444,0,0,.55902],98:[0,.69444,0,0,.63889],99:[0,.44444,0,0,.51111],100:[0,.69444,0,0,.63889],101:[0,.44444,0,0,.52708],102:[0,.69444,.10903,0,.35139],103:[.19444,.44444,.01597,0,.575],104:[0,.69444,0,0,.63889],105:[0,.69444,0,0,.31944],106:[.19444,.69444,0,0,.35139],107:[0,.69444,0,0,.60694],108:[0,.69444,0,0,.31944],109:[0,.44444,0,0,.95833],110:[0,.44444,0,0,.63889],111:[0,.44444,0,0,.575],112:[.19444,.44444,0,0,.63889],113:[.19444,.44444,0,0,.60694],114:[0,.44444,0,0,.47361],115:[0,.44444,0,0,.45361],116:[0,.63492,0,0,.44722],117:[0,.44444,0,0,.63889],118:[0,.44444,.01597,0,.60694],119:[0,.44444,.01597,0,.83055],120:[0,.44444,0,0,.60694],121:[.19444,.44444,.01597,0,.60694],122:[0,.44444,0,0,.51111],123:[.25,.75,0,0,.575],124:[.25,.75,0,0,.31944],125:[.25,.75,0,0,.575],126:[.35,.34444,0,0,.575],160:[0,0,0,0,.25],163:[0,.69444,0,0,.86853],168:[0,.69444,0,0,.575],172:[0,.44444,0,0,.76666],176:[0,.69444,0,0,.86944],177:[.13333,.63333,0,0,.89444],184:[.17014,0,0,0,.51111],198:[0,.68611,0,0,1.04166],215:[.13333,.63333,0,0,.89444],216:[.04861,.73472,0,0,.89444],223:[0,.69444,0,0,.59722],230:[0,.44444,0,0,.83055],247:[.13333,.63333,0,0,.89444],248:[.09722,.54167,0,0,.575],305:[0,.44444,0,0,.31944],338:[0,.68611,0,0,1.16944],339:[0,.44444,0,0,.89444],567:[.19444,.44444,0,0,.35139],710:[0,.69444,0,0,.575],711:[0,.63194,0,0,.575],713:[0,.59611,0,0,.575],714:[0,.69444,0,0,.575],715:[0,.69444,0,0,.575],728:[0,.69444,0,0,.575],729:[0,.69444,0,0,.31944],730:[0,.69444,0,0,.86944],732:[0,.69444,0,0,.575],733:[0,.69444,0,0,.575],915:[0,.68611,0,0,.69166],916:[0,.68611,0,0,.95833],920:[0,.68611,0,0,.89444],923:[0,.68611,0,0,.80555],926:[0,.68611,0,0,.76666],928:[0,.68611,0,0,.9],931:[0,.68611,0,0,.83055],933:[0,.68611,0,0,.89444],934:[0,.68611,0,0,.83055],936:[0,.68611,0,0,.89444],937:[0,.68611,0,0,.83055],8211:[0,.44444,.03194,0,.575],8212:[0,.44444,.03194,0,1.14999],8216:[0,.69444,0,0,.31944],8217:[0,.69444,0,0,.31944],8220:[0,.69444,0,0,.60278],8221:[0,.69444,0,0,.60278],8224:[.19444,.69444,0,0,.51111],8225:[.19444,.69444,0,0,.51111],8242:[0,.55556,0,0,.34444],8407:[0,.72444,.15486,0,.575],8463:[0,.69444,0,0,.66759],8465:[0,.69444,0,0,.83055],8467:[0,.69444,0,0,.47361],8472:[.19444,.44444,0,0,.74027],8476:[0,.69444,0,0,.83055],8501:[0,.69444,0,0,.70277],8592:[-.10889,.39111,0,0,1.14999],8593:[.19444,.69444,0,0,.575],8594:[-.10889,.39111,0,0,1.14999],8595:[.19444,.69444,0,0,.575],8596:[-.10889,.39111,0,0,1.14999],8597:[.25,.75,0,0,.575],8598:[.19444,.69444,0,0,1.14999],8599:[.19444,.69444,0,0,1.14999],8600:[.19444,.69444,0,0,1.14999],8601:[.19444,.69444,0,0,1.14999],8636:[-.10889,.39111,0,0,1.14999],8637:[-.10889,.39111,0,0,1.14999],8640:[-.10889,.39111,0,0,1.14999],8641:[-.10889,.39111,0,0,1.14999],8656:[-.10889,.39111,0,0,1.14999],8657:[.19444,.69444,0,0,.70277],8658:[-.10889,.39111,0,0,1.14999],8659:[.19444,.69444,0,0,.70277],8660:[-.10889,.39111,0,0,1.14999],8661:[.25,.75,0,0,.70277],8704:[0,.69444,0,0,.63889],8706:[0,.69444,.06389,0,.62847],8707:[0,.69444,0,0,.63889],8709:[.05556,.75,0,0,.575],8711:[0,.68611,0,0,.95833],8712:[.08556,.58556,0,0,.76666],8715:[.08556,.58556,0,0,.76666],8722:[.13333,.63333,0,0,.89444],8723:[.13333,.63333,0,0,.89444],8725:[.25,.75,0,0,.575],8726:[.25,.75,0,0,.575],8727:[-.02778,.47222,0,0,.575],8728:[-.02639,.47361,0,0,.575],8729:[-.02639,.47361,0,0,.575],8730:[.18,.82,0,0,.95833],8733:[0,.44444,0,0,.89444],8734:[0,.44444,0,0,1.14999],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.31944],8741:[.25,.75,0,0,.575],8743:[0,.55556,0,0,.76666],8744:[0,.55556,0,0,.76666],8745:[0,.55556,0,0,.76666],8746:[0,.55556,0,0,.76666],8747:[.19444,.69444,.12778,0,.56875],8764:[-.10889,.39111,0,0,.89444],8768:[.19444,.69444,0,0,.31944],8771:[.00222,.50222,0,0,.89444],8773:[.027,.638,0,0,.894],8776:[.02444,.52444,0,0,.89444],8781:[.00222,.50222,0,0,.89444],8801:[.00222,.50222,0,0,.89444],8804:[.19667,.69667,0,0,.89444],8805:[.19667,.69667,0,0,.89444],8810:[.08556,.58556,0,0,1.14999],8811:[.08556,.58556,0,0,1.14999],8826:[.08556,.58556,0,0,.89444],8827:[.08556,.58556,0,0,.89444],8834:[.08556,.58556,0,0,.89444],8835:[.08556,.58556,0,0,.89444],8838:[.19667,.69667,0,0,.89444],8839:[.19667,.69667,0,0,.89444],8846:[0,.55556,0,0,.76666],8849:[.19667,.69667,0,0,.89444],8850:[.19667,.69667,0,0,.89444],8851:[0,.55556,0,0,.76666],8852:[0,.55556,0,0,.76666],8853:[.13333,.63333,0,0,.89444],8854:[.13333,.63333,0,0,.89444],8855:[.13333,.63333,0,0,.89444],8856:[.13333,.63333,0,0,.89444],8857:[.13333,.63333,0,0,.89444],8866:[0,.69444,0,0,.70277],8867:[0,.69444,0,0,.70277],8868:[0,.69444,0,0,.89444],8869:[0,.69444,0,0,.89444],8900:[-.02639,.47361,0,0,.575],8901:[-.02639,.47361,0,0,.31944],8902:[-.02778,.47222,0,0,.575],8968:[.25,.75,0,0,.51111],8969:[.25,.75,0,0,.51111],8970:[.25,.75,0,0,.51111],8971:[.25,.75,0,0,.51111],8994:[-.13889,.36111,0,0,1.14999],8995:[-.13889,.36111,0,0,1.14999],9651:[.19444,.69444,0,0,1.02222],9657:[-.02778,.47222,0,0,.575],9661:[.19444,.69444,0,0,1.02222],9667:[-.02778,.47222,0,0,.575],9711:[.19444,.69444,0,0,1.14999],9824:[.12963,.69444,0,0,.89444],9825:[.12963,.69444,0,0,.89444],9826:[.12963,.69444,0,0,.89444],9827:[.12963,.69444,0,0,.89444],9837:[0,.75,0,0,.44722],9838:[.19444,.69444,0,0,.44722],9839:[.19444,.69444,0,0,.44722],10216:[.25,.75,0,0,.44722],10217:[.25,.75,0,0,.44722],10815:[0,.68611,0,0,.9],10927:[.19667,.69667,0,0,.89444],10928:[.19667,.69667,0,0,.89444],57376:[.19444,.69444,0,0,0]},"Main-BoldItalic":{32:[0,0,0,0,.25],33:[0,.69444,.11417,0,.38611],34:[0,.69444,.07939,0,.62055],35:[.19444,.69444,.06833,0,.94444],37:[.05556,.75,.12861,0,.94444],38:[0,.69444,.08528,0,.88555],39:[0,.69444,.12945,0,.35555],40:[.25,.75,.15806,0,.47333],41:[.25,.75,.03306,0,.47333],42:[0,.75,.14333,0,.59111],43:[.10333,.60333,.03306,0,.88555],44:[.19444,.14722,0,0,.35555],45:[0,.44444,.02611,0,.41444],46:[0,.14722,0,0,.35555],47:[.25,.75,.15806,0,.59111],48:[0,.64444,.13167,0,.59111],49:[0,.64444,.13167,0,.59111],50:[0,.64444,.13167,0,.59111],51:[0,.64444,.13167,0,.59111],52:[.19444,.64444,.13167,0,.59111],53:[0,.64444,.13167,0,.59111],54:[0,.64444,.13167,0,.59111],55:[.19444,.64444,.13167,0,.59111],56:[0,.64444,.13167,0,.59111],57:[0,.64444,.13167,0,.59111],58:[0,.44444,.06695,0,.35555],59:[.19444,.44444,.06695,0,.35555],61:[-.10889,.39111,.06833,0,.88555],63:[0,.69444,.11472,0,.59111],64:[0,.69444,.09208,0,.88555],65:[0,.68611,0,0,.86555],66:[0,.68611,.0992,0,.81666],67:[0,.68611,.14208,0,.82666],68:[0,.68611,.09062,0,.87555],69:[0,.68611,.11431,0,.75666],70:[0,.68611,.12903,0,.72722],71:[0,.68611,.07347,0,.89527],72:[0,.68611,.17208,0,.8961],73:[0,.68611,.15681,0,.47166],74:[0,.68611,.145,0,.61055],75:[0,.68611,.14208,0,.89499],76:[0,.68611,0,0,.69777],77:[0,.68611,.17208,0,1.07277],78:[0,.68611,.17208,0,.8961],79:[0,.68611,.09062,0,.85499],80:[0,.68611,.0992,0,.78721],81:[.19444,.68611,.09062,0,.85499],82:[0,.68611,.02559,0,.85944],83:[0,.68611,.11264,0,.64999],84:[0,.68611,.12903,0,.7961],85:[0,.68611,.17208,0,.88083],86:[0,.68611,.18625,0,.86555],87:[0,.68611,.18625,0,1.15999],88:[0,.68611,.15681,0,.86555],89:[0,.68611,.19803,0,.86555],90:[0,.68611,.14208,0,.70888],91:[.25,.75,.1875,0,.35611],93:[.25,.75,.09972,0,.35611],94:[0,.69444,.06709,0,.59111],95:[.31,.13444,.09811,0,.59111],97:[0,.44444,.09426,0,.59111],98:[0,.69444,.07861,0,.53222],99:[0,.44444,.05222,0,.53222],100:[0,.69444,.10861,0,.59111],101:[0,.44444,.085,0,.53222],102:[.19444,.69444,.21778,0,.4],103:[.19444,.44444,.105,0,.53222],104:[0,.69444,.09426,0,.59111],105:[0,.69326,.11387,0,.35555],106:[.19444,.69326,.1672,0,.35555],107:[0,.69444,.11111,0,.53222],108:[0,.69444,.10861,0,.29666],109:[0,.44444,.09426,0,.94444],110:[0,.44444,.09426,0,.64999],111:[0,.44444,.07861,0,.59111],112:[.19444,.44444,.07861,0,.59111],113:[.19444,.44444,.105,0,.53222],114:[0,.44444,.11111,0,.50167],115:[0,.44444,.08167,0,.48694],116:[0,.63492,.09639,0,.385],117:[0,.44444,.09426,0,.62055],118:[0,.44444,.11111,0,.53222],119:[0,.44444,.11111,0,.76777],120:[0,.44444,.12583,0,.56055],121:[.19444,.44444,.105,0,.56166],122:[0,.44444,.13889,0,.49055],126:[.35,.34444,.11472,0,.59111],160:[0,0,0,0,.25],168:[0,.69444,.11473,0,.59111],176:[0,.69444,0,0,.94888],184:[.17014,0,0,0,.53222],198:[0,.68611,.11431,0,1.02277],216:[.04861,.73472,.09062,0,.88555],223:[.19444,.69444,.09736,0,.665],230:[0,.44444,.085,0,.82666],248:[.09722,.54167,.09458,0,.59111],305:[0,.44444,.09426,0,.35555],338:[0,.68611,.11431,0,1.14054],339:[0,.44444,.085,0,.82666],567:[.19444,.44444,.04611,0,.385],710:[0,.69444,.06709,0,.59111],711:[0,.63194,.08271,0,.59111],713:[0,.59444,.10444,0,.59111],714:[0,.69444,.08528,0,.59111],715:[0,.69444,0,0,.59111],728:[0,.69444,.10333,0,.59111],729:[0,.69444,.12945,0,.35555],730:[0,.69444,0,0,.94888],732:[0,.69444,.11472,0,.59111],733:[0,.69444,.11472,0,.59111],915:[0,.68611,.12903,0,.69777],916:[0,.68611,0,0,.94444],920:[0,.68611,.09062,0,.88555],923:[0,.68611,0,0,.80666],926:[0,.68611,.15092,0,.76777],928:[0,.68611,.17208,0,.8961],931:[0,.68611,.11431,0,.82666],933:[0,.68611,.10778,0,.88555],934:[0,.68611,.05632,0,.82666],936:[0,.68611,.10778,0,.88555],937:[0,.68611,.0992,0,.82666],8211:[0,.44444,.09811,0,.59111],8212:[0,.44444,.09811,0,1.18221],8216:[0,.69444,.12945,0,.35555],8217:[0,.69444,.12945,0,.35555],8220:[0,.69444,.16772,0,.62055],8221:[0,.69444,.07939,0,.62055]},"Main-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.12417,0,.30667],34:[0,.69444,.06961,0,.51444],35:[.19444,.69444,.06616,0,.81777],37:[.05556,.75,.13639,0,.81777],38:[0,.69444,.09694,0,.76666],39:[0,.69444,.12417,0,.30667],40:[.25,.75,.16194,0,.40889],41:[.25,.75,.03694,0,.40889],42:[0,.75,.14917,0,.51111],43:[.05667,.56167,.03694,0,.76666],44:[.19444,.10556,0,0,.30667],45:[0,.43056,.02826,0,.35778],46:[0,.10556,0,0,.30667],47:[.25,.75,.16194,0,.51111],48:[0,.64444,.13556,0,.51111],49:[0,.64444,.13556,0,.51111],50:[0,.64444,.13556,0,.51111],51:[0,.64444,.13556,0,.51111],52:[.19444,.64444,.13556,0,.51111],53:[0,.64444,.13556,0,.51111],54:[0,.64444,.13556,0,.51111],55:[.19444,.64444,.13556,0,.51111],56:[0,.64444,.13556,0,.51111],57:[0,.64444,.13556,0,.51111],58:[0,.43056,.0582,0,.30667],59:[.19444,.43056,.0582,0,.30667],61:[-.13313,.36687,.06616,0,.76666],63:[0,.69444,.1225,0,.51111],64:[0,.69444,.09597,0,.76666],65:[0,.68333,0,0,.74333],66:[0,.68333,.10257,0,.70389],67:[0,.68333,.14528,0,.71555],68:[0,.68333,.09403,0,.755],69:[0,.68333,.12028,0,.67833],70:[0,.68333,.13305,0,.65277],71:[0,.68333,.08722,0,.77361],72:[0,.68333,.16389,0,.74333],73:[0,.68333,.15806,0,.38555],74:[0,.68333,.14028,0,.525],75:[0,.68333,.14528,0,.76888],76:[0,.68333,0,0,.62722],77:[0,.68333,.16389,0,.89666],78:[0,.68333,.16389,0,.74333],79:[0,.68333,.09403,0,.76666],80:[0,.68333,.10257,0,.67833],81:[.19444,.68333,.09403,0,.76666],82:[0,.68333,.03868,0,.72944],83:[0,.68333,.11972,0,.56222],84:[0,.68333,.13305,0,.71555],85:[0,.68333,.16389,0,.74333],86:[0,.68333,.18361,0,.74333],87:[0,.68333,.18361,0,.99888],88:[0,.68333,.15806,0,.74333],89:[0,.68333,.19383,0,.74333],90:[0,.68333,.14528,0,.61333],91:[.25,.75,.1875,0,.30667],93:[.25,.75,.10528,0,.30667],94:[0,.69444,.06646,0,.51111],95:[.31,.12056,.09208,0,.51111],97:[0,.43056,.07671,0,.51111],98:[0,.69444,.06312,0,.46],99:[0,.43056,.05653,0,.46],100:[0,.69444,.10333,0,.51111],101:[0,.43056,.07514,0,.46],102:[.19444,.69444,.21194,0,.30667],103:[.19444,.43056,.08847,0,.46],104:[0,.69444,.07671,0,.51111],105:[0,.65536,.1019,0,.30667],106:[.19444,.65536,.14467,0,.30667],107:[0,.69444,.10764,0,.46],108:[0,.69444,.10333,0,.25555],109:[0,.43056,.07671,0,.81777],110:[0,.43056,.07671,0,.56222],111:[0,.43056,.06312,0,.51111],112:[.19444,.43056,.06312,0,.51111],113:[.19444,.43056,.08847,0,.46],114:[0,.43056,.10764,0,.42166],115:[0,.43056,.08208,0,.40889],116:[0,.61508,.09486,0,.33222],117:[0,.43056,.07671,0,.53666],118:[0,.43056,.10764,0,.46],119:[0,.43056,.10764,0,.66444],120:[0,.43056,.12042,0,.46389],121:[.19444,.43056,.08847,0,.48555],122:[0,.43056,.12292,0,.40889],126:[.35,.31786,.11585,0,.51111],160:[0,0,0,0,.25],168:[0,.66786,.10474,0,.51111],176:[0,.69444,0,0,.83129],184:[.17014,0,0,0,.46],198:[0,.68333,.12028,0,.88277],216:[.04861,.73194,.09403,0,.76666],223:[.19444,.69444,.10514,0,.53666],230:[0,.43056,.07514,0,.71555],248:[.09722,.52778,.09194,0,.51111],338:[0,.68333,.12028,0,.98499],339:[0,.43056,.07514,0,.71555],710:[0,.69444,.06646,0,.51111],711:[0,.62847,.08295,0,.51111],713:[0,.56167,.10333,0,.51111],714:[0,.69444,.09694,0,.51111],715:[0,.69444,0,0,.51111],728:[0,.69444,.10806,0,.51111],729:[0,.66786,.11752,0,.30667],730:[0,.69444,0,0,.83129],732:[0,.66786,.11585,0,.51111],733:[0,.69444,.1225,0,.51111],915:[0,.68333,.13305,0,.62722],916:[0,.68333,0,0,.81777],920:[0,.68333,.09403,0,.76666],923:[0,.68333,0,0,.69222],926:[0,.68333,.15294,0,.66444],928:[0,.68333,.16389,0,.74333],931:[0,.68333,.12028,0,.71555],933:[0,.68333,.11111,0,.76666],934:[0,.68333,.05986,0,.71555],936:[0,.68333,.11111,0,.76666],937:[0,.68333,.10257,0,.71555],8211:[0,.43056,.09208,0,.51111],8212:[0,.43056,.09208,0,1.02222],8216:[0,.69444,.12417,0,.30667],8217:[0,.69444,.12417,0,.30667],8220:[0,.69444,.1685,0,.51444],8221:[0,.69444,.06961,0,.51444],8463:[0,.68889,0,0,.54028]},"Main-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.27778],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.77778],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.19444,.10556,0,0,.27778],45:[0,.43056,0,0,.33333],46:[0,.10556,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.64444,0,0,.5],49:[0,.64444,0,0,.5],50:[0,.64444,0,0,.5],51:[0,.64444,0,0,.5],52:[0,.64444,0,0,.5],53:[0,.64444,0,0,.5],54:[0,.64444,0,0,.5],55:[0,.64444,0,0,.5],56:[0,.64444,0,0,.5],57:[0,.64444,0,0,.5],58:[0,.43056,0,0,.27778],59:[.19444,.43056,0,0,.27778],60:[.0391,.5391,0,0,.77778],61:[-.13313,.36687,0,0,.77778],62:[.0391,.5391,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.77778],65:[0,.68333,0,0,.75],66:[0,.68333,0,0,.70834],67:[0,.68333,0,0,.72222],68:[0,.68333,0,0,.76389],69:[0,.68333,0,0,.68056],70:[0,.68333,0,0,.65278],71:[0,.68333,0,0,.78472],72:[0,.68333,0,0,.75],73:[0,.68333,0,0,.36111],74:[0,.68333,0,0,.51389],75:[0,.68333,0,0,.77778],76:[0,.68333,0,0,.625],77:[0,.68333,0,0,.91667],78:[0,.68333,0,0,.75],79:[0,.68333,0,0,.77778],80:[0,.68333,0,0,.68056],81:[.19444,.68333,0,0,.77778],82:[0,.68333,0,0,.73611],83:[0,.68333,0,0,.55556],84:[0,.68333,0,0,.72222],85:[0,.68333,0,0,.75],86:[0,.68333,.01389,0,.75],87:[0,.68333,.01389,0,1.02778],88:[0,.68333,0,0,.75],89:[0,.68333,.025,0,.75],90:[0,.68333,0,0,.61111],91:[.25,.75,0,0,.27778],92:[.25,.75,0,0,.5],93:[.25,.75,0,0,.27778],94:[0,.69444,0,0,.5],95:[.31,.12056,.02778,0,.5],97:[0,.43056,0,0,.5],98:[0,.69444,0,0,.55556],99:[0,.43056,0,0,.44445],100:[0,.69444,0,0,.55556],101:[0,.43056,0,0,.44445],102:[0,.69444,.07778,0,.30556],103:[.19444,.43056,.01389,0,.5],104:[0,.69444,0,0,.55556],105:[0,.66786,0,0,.27778],106:[.19444,.66786,0,0,.30556],107:[0,.69444,0,0,.52778],108:[0,.69444,0,0,.27778],109:[0,.43056,0,0,.83334],110:[0,.43056,0,0,.55556],111:[0,.43056,0,0,.5],112:[.19444,.43056,0,0,.55556],113:[.19444,.43056,0,0,.52778],114:[0,.43056,0,0,.39167],115:[0,.43056,0,0,.39445],116:[0,.61508,0,0,.38889],117:[0,.43056,0,0,.55556],118:[0,.43056,.01389,0,.52778],119:[0,.43056,.01389,0,.72222],120:[0,.43056,0,0,.52778],121:[.19444,.43056,.01389,0,.52778],122:[0,.43056,0,0,.44445],123:[.25,.75,0,0,.5],124:[.25,.75,0,0,.27778],125:[.25,.75,0,0,.5],126:[.35,.31786,0,0,.5],160:[0,0,0,0,.25],163:[0,.69444,0,0,.76909],167:[.19444,.69444,0,0,.44445],168:[0,.66786,0,0,.5],172:[0,.43056,0,0,.66667],176:[0,.69444,0,0,.75],177:[.08333,.58333,0,0,.77778],182:[.19444,.69444,0,0,.61111],184:[.17014,0,0,0,.44445],198:[0,.68333,0,0,.90278],215:[.08333,.58333,0,0,.77778],216:[.04861,.73194,0,0,.77778],223:[0,.69444,0,0,.5],230:[0,.43056,0,0,.72222],247:[.08333,.58333,0,0,.77778],248:[.09722,.52778,0,0,.5],305:[0,.43056,0,0,.27778],338:[0,.68333,0,0,1.01389],339:[0,.43056,0,0,.77778],567:[.19444,.43056,0,0,.30556],710:[0,.69444,0,0,.5],711:[0,.62847,0,0,.5],713:[0,.56778,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.66786,0,0,.27778],730:[0,.69444,0,0,.75],732:[0,.66786,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.68333,0,0,.625],916:[0,.68333,0,0,.83334],920:[0,.68333,0,0,.77778],923:[0,.68333,0,0,.69445],926:[0,.68333,0,0,.66667],928:[0,.68333,0,0,.75],931:[0,.68333,0,0,.72222],933:[0,.68333,0,0,.77778],934:[0,.68333,0,0,.72222],936:[0,.68333,0,0,.77778],937:[0,.68333,0,0,.72222],8211:[0,.43056,.02778,0,.5],8212:[0,.43056,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5],8224:[.19444,.69444,0,0,.44445],8225:[.19444,.69444,0,0,.44445],8230:[0,.123,0,0,1.172],8242:[0,.55556,0,0,.275],8407:[0,.71444,.15382,0,.5],8463:[0,.68889,0,0,.54028],8465:[0,.69444,0,0,.72222],8467:[0,.69444,0,.11111,.41667],8472:[.19444,.43056,0,.11111,.63646],8476:[0,.69444,0,0,.72222],8501:[0,.69444,0,0,.61111],8592:[-.13313,.36687,0,0,1],8593:[.19444,.69444,0,0,.5],8594:[-.13313,.36687,0,0,1],8595:[.19444,.69444,0,0,.5],8596:[-.13313,.36687,0,0,1],8597:[.25,.75,0,0,.5],8598:[.19444,.69444,0,0,1],8599:[.19444,.69444,0,0,1],8600:[.19444,.69444,0,0,1],8601:[.19444,.69444,0,0,1],8614:[.011,.511,0,0,1],8617:[.011,.511,0,0,1.126],8618:[.011,.511,0,0,1.126],8636:[-.13313,.36687,0,0,1],8637:[-.13313,.36687,0,0,1],8640:[-.13313,.36687,0,0,1],8641:[-.13313,.36687,0,0,1],8652:[.011,.671,0,0,1],8656:[-.13313,.36687,0,0,1],8657:[.19444,.69444,0,0,.61111],8658:[-.13313,.36687,0,0,1],8659:[.19444,.69444,0,0,.61111],8660:[-.13313,.36687,0,0,1],8661:[.25,.75,0,0,.61111],8704:[0,.69444,0,0,.55556],8706:[0,.69444,.05556,.08334,.5309],8707:[0,.69444,0,0,.55556],8709:[.05556,.75,0,0,.5],8711:[0,.68333,0,0,.83334],8712:[.0391,.5391,0,0,.66667],8715:[.0391,.5391,0,0,.66667],8722:[.08333,.58333,0,0,.77778],8723:[.08333,.58333,0,0,.77778],8725:[.25,.75,0,0,.5],8726:[.25,.75,0,0,.5],8727:[-.03472,.46528,0,0,.5],8728:[-.05555,.44445,0,0,.5],8729:[-.05555,.44445,0,0,.5],8730:[.2,.8,0,0,.83334],8733:[0,.43056,0,0,.77778],8734:[0,.43056,0,0,1],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.27778],8741:[.25,.75,0,0,.5],8743:[0,.55556,0,0,.66667],8744:[0,.55556,0,0,.66667],8745:[0,.55556,0,0,.66667],8746:[0,.55556,0,0,.66667],8747:[.19444,.69444,.11111,0,.41667],8764:[-.13313,.36687,0,0,.77778],8768:[.19444,.69444,0,0,.27778],8771:[-.03625,.46375,0,0,.77778],8773:[-.022,.589,0,0,.778],8776:[-.01688,.48312,0,0,.77778],8781:[-.03625,.46375,0,0,.77778],8784:[-.133,.673,0,0,.778],8801:[-.03625,.46375,0,0,.77778],8804:[.13597,.63597,0,0,.77778],8805:[.13597,.63597,0,0,.77778],8810:[.0391,.5391,0,0,1],8811:[.0391,.5391,0,0,1],8826:[.0391,.5391,0,0,.77778],8827:[.0391,.5391,0,0,.77778],8834:[.0391,.5391,0,0,.77778],8835:[.0391,.5391,0,0,.77778],8838:[.13597,.63597,0,0,.77778],8839:[.13597,.63597,0,0,.77778],8846:[0,.55556,0,0,.66667],8849:[.13597,.63597,0,0,.77778],8850:[.13597,.63597,0,0,.77778],8851:[0,.55556,0,0,.66667],8852:[0,.55556,0,0,.66667],8853:[.08333,.58333,0,0,.77778],8854:[.08333,.58333,0,0,.77778],8855:[.08333,.58333,0,0,.77778],8856:[.08333,.58333,0,0,.77778],8857:[.08333,.58333,0,0,.77778],8866:[0,.69444,0,0,.61111],8867:[0,.69444,0,0,.61111],8868:[0,.69444,0,0,.77778],8869:[0,.69444,0,0,.77778],8872:[.249,.75,0,0,.867],8900:[-.05555,.44445,0,0,.5],8901:[-.05555,.44445,0,0,.27778],8902:[-.03472,.46528,0,0,.5],8904:[.005,.505,0,0,.9],8942:[.03,.903,0,0,.278],8943:[-.19,.313,0,0,1.172],8945:[-.1,.823,0,0,1.282],8968:[.25,.75,0,0,.44445],8969:[.25,.75,0,0,.44445],8970:[.25,.75,0,0,.44445],8971:[.25,.75,0,0,.44445],8994:[-.14236,.35764,0,0,1],8995:[-.14236,.35764,0,0,1],9136:[.244,.744,0,0,.412],9137:[.244,.745,0,0,.412],9651:[.19444,.69444,0,0,.88889],9657:[-.03472,.46528,0,0,.5],9661:[.19444,.69444,0,0,.88889],9667:[-.03472,.46528,0,0,.5],9711:[.19444,.69444,0,0,1],9824:[.12963,.69444,0,0,.77778],9825:[.12963,.69444,0,0,.77778],9826:[.12963,.69444,0,0,.77778],9827:[.12963,.69444,0,0,.77778],9837:[0,.75,0,0,.38889],9838:[.19444,.69444,0,0,.38889],9839:[.19444,.69444,0,0,.38889],10216:[.25,.75,0,0,.38889],10217:[.25,.75,0,0,.38889],10222:[.244,.744,0,0,.412],10223:[.244,.745,0,0,.412],10229:[.011,.511,0,0,1.609],10230:[.011,.511,0,0,1.638],10231:[.011,.511,0,0,1.859],10232:[.024,.525,0,0,1.609],10233:[.024,.525,0,0,1.638],10234:[.024,.525,0,0,1.858],10236:[.011,.511,0,0,1.638],10815:[0,.68333,0,0,.75],10927:[.13597,.63597,0,0,.77778],10928:[.13597,.63597,0,0,.77778],57376:[.19444,.69444,0,0,0]},"Math-BoldItalic":{32:[0,0,0,0,.25],48:[0,.44444,0,0,.575],49:[0,.44444,0,0,.575],50:[0,.44444,0,0,.575],51:[.19444,.44444,0,0,.575],52:[.19444,.44444,0,0,.575],53:[.19444,.44444,0,0,.575],54:[0,.64444,0,0,.575],55:[.19444,.44444,0,0,.575],56:[0,.64444,0,0,.575],57:[.19444,.44444,0,0,.575],65:[0,.68611,0,0,.86944],66:[0,.68611,.04835,0,.8664],67:[0,.68611,.06979,0,.81694],68:[0,.68611,.03194,0,.93812],69:[0,.68611,.05451,0,.81007],70:[0,.68611,.15972,0,.68889],71:[0,.68611,0,0,.88673],72:[0,.68611,.08229,0,.98229],73:[0,.68611,.07778,0,.51111],74:[0,.68611,.10069,0,.63125],75:[0,.68611,.06979,0,.97118],76:[0,.68611,0,0,.75555],77:[0,.68611,.11424,0,1.14201],78:[0,.68611,.11424,0,.95034],79:[0,.68611,.03194,0,.83666],80:[0,.68611,.15972,0,.72309],81:[.19444,.68611,0,0,.86861],82:[0,.68611,.00421,0,.87235],83:[0,.68611,.05382,0,.69271],84:[0,.68611,.15972,0,.63663],85:[0,.68611,.11424,0,.80027],86:[0,.68611,.25555,0,.67778],87:[0,.68611,.15972,0,1.09305],88:[0,.68611,.07778,0,.94722],89:[0,.68611,.25555,0,.67458],90:[0,.68611,.06979,0,.77257],97:[0,.44444,0,0,.63287],98:[0,.69444,0,0,.52083],99:[0,.44444,0,0,.51342],100:[0,.69444,0,0,.60972],101:[0,.44444,0,0,.55361],102:[.19444,.69444,.11042,0,.56806],103:[.19444,.44444,.03704,0,.5449],104:[0,.69444,0,0,.66759],105:[0,.69326,0,0,.4048],106:[.19444,.69326,.0622,0,.47083],107:[0,.69444,.01852,0,.6037],108:[0,.69444,.0088,0,.34815],109:[0,.44444,0,0,1.0324],110:[0,.44444,0,0,.71296],111:[0,.44444,0,0,.58472],112:[.19444,.44444,0,0,.60092],113:[.19444,.44444,.03704,0,.54213],114:[0,.44444,.03194,0,.5287],115:[0,.44444,0,0,.53125],116:[0,.63492,0,0,.41528],117:[0,.44444,0,0,.68102],118:[0,.44444,.03704,0,.56666],119:[0,.44444,.02778,0,.83148],120:[0,.44444,0,0,.65903],121:[.19444,.44444,.03704,0,.59028],122:[0,.44444,.04213,0,.55509],160:[0,0,0,0,.25],915:[0,.68611,.15972,0,.65694],916:[0,.68611,0,0,.95833],920:[0,.68611,.03194,0,.86722],923:[0,.68611,0,0,.80555],926:[0,.68611,.07458,0,.84125],928:[0,.68611,.08229,0,.98229],931:[0,.68611,.05451,0,.88507],933:[0,.68611,.15972,0,.67083],934:[0,.68611,0,0,.76666],936:[0,.68611,.11653,0,.71402],937:[0,.68611,.04835,0,.8789],945:[0,.44444,0,0,.76064],946:[.19444,.69444,.03403,0,.65972],947:[.19444,.44444,.06389,0,.59003],948:[0,.69444,.03819,0,.52222],949:[0,.44444,0,0,.52882],950:[.19444,.69444,.06215,0,.50833],951:[.19444,.44444,.03704,0,.6],952:[0,.69444,.03194,0,.5618],953:[0,.44444,0,0,.41204],954:[0,.44444,0,0,.66759],955:[0,.69444,0,0,.67083],956:[.19444,.44444,0,0,.70787],957:[0,.44444,.06898,0,.57685],958:[.19444,.69444,.03021,0,.50833],959:[0,.44444,0,0,.58472],960:[0,.44444,.03704,0,.68241],961:[.19444,.44444,0,0,.6118],962:[.09722,.44444,.07917,0,.42361],963:[0,.44444,.03704,0,.68588],964:[0,.44444,.13472,0,.52083],965:[0,.44444,.03704,0,.63055],966:[.19444,.44444,0,0,.74722],967:[.19444,.44444,0,0,.71805],968:[.19444,.69444,.03704,0,.75833],969:[0,.44444,.03704,0,.71782],977:[0,.69444,0,0,.69155],981:[.19444,.69444,0,0,.7125],982:[0,.44444,.03194,0,.975],1009:[.19444,.44444,0,0,.6118],1013:[0,.44444,0,0,.48333],57649:[0,.44444,0,0,.39352],57911:[.19444,.44444,0,0,.43889]},"Math-Italic":{32:[0,0,0,0,.25],48:[0,.43056,0,0,.5],49:[0,.43056,0,0,.5],50:[0,.43056,0,0,.5],51:[.19444,.43056,0,0,.5],52:[.19444,.43056,0,0,.5],53:[.19444,.43056,0,0,.5],54:[0,.64444,0,0,.5],55:[.19444,.43056,0,0,.5],56:[0,.64444,0,0,.5],57:[.19444,.43056,0,0,.5],65:[0,.68333,0,.13889,.75],66:[0,.68333,.05017,.08334,.75851],67:[0,.68333,.07153,.08334,.71472],68:[0,.68333,.02778,.05556,.82792],69:[0,.68333,.05764,.08334,.7382],70:[0,.68333,.13889,.08334,.64306],71:[0,.68333,0,.08334,.78625],72:[0,.68333,.08125,.05556,.83125],73:[0,.68333,.07847,.11111,.43958],74:[0,.68333,.09618,.16667,.55451],75:[0,.68333,.07153,.05556,.84931],76:[0,.68333,0,.02778,.68056],77:[0,.68333,.10903,.08334,.97014],78:[0,.68333,.10903,.08334,.80347],79:[0,.68333,.02778,.08334,.76278],80:[0,.68333,.13889,.08334,.64201],81:[.19444,.68333,0,.08334,.79056],82:[0,.68333,.00773,.08334,.75929],83:[0,.68333,.05764,.08334,.6132],84:[0,.68333,.13889,.08334,.58438],85:[0,.68333,.10903,.02778,.68278],86:[0,.68333,.22222,0,.58333],87:[0,.68333,.13889,0,.94445],88:[0,.68333,.07847,.08334,.82847],89:[0,.68333,.22222,0,.58056],90:[0,.68333,.07153,.08334,.68264],97:[0,.43056,0,0,.52859],98:[0,.69444,0,0,.42917],99:[0,.43056,0,.05556,.43276],100:[0,.69444,0,.16667,.52049],101:[0,.43056,0,.05556,.46563],102:[.19444,.69444,.10764,.16667,.48959],103:[.19444,.43056,.03588,.02778,.47697],104:[0,.69444,0,0,.57616],105:[0,.65952,0,0,.34451],106:[.19444,.65952,.05724,0,.41181],107:[0,.69444,.03148,0,.5206],108:[0,.69444,.01968,.08334,.29838],109:[0,.43056,0,0,.87801],110:[0,.43056,0,0,.60023],111:[0,.43056,0,.05556,.48472],112:[.19444,.43056,0,.08334,.50313],113:[.19444,.43056,.03588,.08334,.44641],114:[0,.43056,.02778,.05556,.45116],115:[0,.43056,0,.05556,.46875],116:[0,.61508,0,.08334,.36111],117:[0,.43056,0,.02778,.57246],118:[0,.43056,.03588,.02778,.48472],119:[0,.43056,.02691,.08334,.71592],120:[0,.43056,0,.02778,.57153],121:[.19444,.43056,.03588,.05556,.49028],122:[0,.43056,.04398,.05556,.46505],160:[0,0,0,0,.25],915:[0,.68333,.13889,.08334,.61528],916:[0,.68333,0,.16667,.83334],920:[0,.68333,.02778,.08334,.76278],923:[0,.68333,0,.16667,.69445],926:[0,.68333,.07569,.08334,.74236],928:[0,.68333,.08125,.05556,.83125],931:[0,.68333,.05764,.08334,.77986],933:[0,.68333,.13889,.05556,.58333],934:[0,.68333,0,.08334,.66667],936:[0,.68333,.11,.05556,.61222],937:[0,.68333,.05017,.08334,.7724],945:[0,.43056,.0037,.02778,.6397],946:[.19444,.69444,.05278,.08334,.56563],947:[.19444,.43056,.05556,0,.51773],948:[0,.69444,.03785,.05556,.44444],949:[0,.43056,0,.08334,.46632],950:[.19444,.69444,.07378,.08334,.4375],951:[.19444,.43056,.03588,.05556,.49653],952:[0,.69444,.02778,.08334,.46944],953:[0,.43056,0,.05556,.35394],954:[0,.43056,0,0,.57616],955:[0,.69444,0,0,.58334],956:[.19444,.43056,0,.02778,.60255],957:[0,.43056,.06366,.02778,.49398],958:[.19444,.69444,.04601,.11111,.4375],959:[0,.43056,0,.05556,.48472],960:[0,.43056,.03588,0,.57003],961:[.19444,.43056,0,.08334,.51702],962:[.09722,.43056,.07986,.08334,.36285],963:[0,.43056,.03588,0,.57141],964:[0,.43056,.1132,.02778,.43715],965:[0,.43056,.03588,.02778,.54028],966:[.19444,.43056,0,.08334,.65417],967:[.19444,.43056,0,.05556,.62569],968:[.19444,.69444,.03588,.11111,.65139],969:[0,.43056,.03588,0,.62245],977:[0,.69444,0,.08334,.59144],981:[.19444,.69444,0,.08334,.59583],982:[0,.43056,.02778,0,.82813],1009:[.19444,.43056,0,.08334,.51702],1013:[0,.43056,0,.05556,.4059],57649:[0,.43056,0,.02778,.32246],57911:[.19444,.43056,0,.08334,.38403]},"SansSerif-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.36667],34:[0,.69444,0,0,.55834],35:[.19444,.69444,0,0,.91667],36:[.05556,.75,0,0,.55],37:[.05556,.75,0,0,1.02912],38:[0,.69444,0,0,.83056],39:[0,.69444,0,0,.30556],40:[.25,.75,0,0,.42778],41:[.25,.75,0,0,.42778],42:[0,.75,0,0,.55],43:[.11667,.61667,0,0,.85556],44:[.10556,.13056,0,0,.30556],45:[0,.45833,0,0,.36667],46:[0,.13056,0,0,.30556],47:[.25,.75,0,0,.55],48:[0,.69444,0,0,.55],49:[0,.69444,0,0,.55],50:[0,.69444,0,0,.55],51:[0,.69444,0,0,.55],52:[0,.69444,0,0,.55],53:[0,.69444,0,0,.55],54:[0,.69444,0,0,.55],55:[0,.69444,0,0,.55],56:[0,.69444,0,0,.55],57:[0,.69444,0,0,.55],58:[0,.45833,0,0,.30556],59:[.10556,.45833,0,0,.30556],61:[-.09375,.40625,0,0,.85556],63:[0,.69444,0,0,.51945],64:[0,.69444,0,0,.73334],65:[0,.69444,0,0,.73334],66:[0,.69444,0,0,.73334],67:[0,.69444,0,0,.70278],68:[0,.69444,0,0,.79445],69:[0,.69444,0,0,.64167],70:[0,.69444,0,0,.61111],71:[0,.69444,0,0,.73334],72:[0,.69444,0,0,.79445],73:[0,.69444,0,0,.33056],74:[0,.69444,0,0,.51945],75:[0,.69444,0,0,.76389],76:[0,.69444,0,0,.58056],77:[0,.69444,0,0,.97778],78:[0,.69444,0,0,.79445],79:[0,.69444,0,0,.79445],80:[0,.69444,0,0,.70278],81:[.10556,.69444,0,0,.79445],82:[0,.69444,0,0,.70278],83:[0,.69444,0,0,.61111],84:[0,.69444,0,0,.73334],85:[0,.69444,0,0,.76389],86:[0,.69444,.01528,0,.73334],87:[0,.69444,.01528,0,1.03889],88:[0,.69444,0,0,.73334],89:[0,.69444,.0275,0,.73334],90:[0,.69444,0,0,.67223],91:[.25,.75,0,0,.34306],93:[.25,.75,0,0,.34306],94:[0,.69444,0,0,.55],95:[.35,.10833,.03056,0,.55],97:[0,.45833,0,0,.525],98:[0,.69444,0,0,.56111],99:[0,.45833,0,0,.48889],100:[0,.69444,0,0,.56111],101:[0,.45833,0,0,.51111],102:[0,.69444,.07639,0,.33611],103:[.19444,.45833,.01528,0,.55],104:[0,.69444,0,0,.56111],105:[0,.69444,0,0,.25556],106:[.19444,.69444,0,0,.28611],107:[0,.69444,0,0,.53056],108:[0,.69444,0,0,.25556],109:[0,.45833,0,0,.86667],110:[0,.45833,0,0,.56111],111:[0,.45833,0,0,.55],112:[.19444,.45833,0,0,.56111],113:[.19444,.45833,0,0,.56111],114:[0,.45833,.01528,0,.37222],115:[0,.45833,0,0,.42167],116:[0,.58929,0,0,.40417],117:[0,.45833,0,0,.56111],118:[0,.45833,.01528,0,.5],119:[0,.45833,.01528,0,.74445],120:[0,.45833,0,0,.5],121:[.19444,.45833,.01528,0,.5],122:[0,.45833,0,0,.47639],126:[.35,.34444,0,0,.55],160:[0,0,0,0,.25],168:[0,.69444,0,0,.55],176:[0,.69444,0,0,.73334],180:[0,.69444,0,0,.55],184:[.17014,0,0,0,.48889],305:[0,.45833,0,0,.25556],567:[.19444,.45833,0,0,.28611],710:[0,.69444,0,0,.55],711:[0,.63542,0,0,.55],713:[0,.63778,0,0,.55],728:[0,.69444,0,0,.55],729:[0,.69444,0,0,.30556],730:[0,.69444,0,0,.73334],732:[0,.69444,0,0,.55],733:[0,.69444,0,0,.55],915:[0,.69444,0,0,.58056],916:[0,.69444,0,0,.91667],920:[0,.69444,0,0,.85556],923:[0,.69444,0,0,.67223],926:[0,.69444,0,0,.73334],928:[0,.69444,0,0,.79445],931:[0,.69444,0,0,.79445],933:[0,.69444,0,0,.85556],934:[0,.69444,0,0,.79445],936:[0,.69444,0,0,.85556],937:[0,.69444,0,0,.79445],8211:[0,.45833,.03056,0,.55],8212:[0,.45833,.03056,0,1.10001],8216:[0,.69444,0,0,.30556],8217:[0,.69444,0,0,.30556],8220:[0,.69444,0,0,.55834],8221:[0,.69444,0,0,.55834]},"SansSerif-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.05733,0,.31945],34:[0,.69444,.00316,0,.5],35:[.19444,.69444,.05087,0,.83334],36:[.05556,.75,.11156,0,.5],37:[.05556,.75,.03126,0,.83334],38:[0,.69444,.03058,0,.75834],39:[0,.69444,.07816,0,.27778],40:[.25,.75,.13164,0,.38889],41:[.25,.75,.02536,0,.38889],42:[0,.75,.11775,0,.5],43:[.08333,.58333,.02536,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,.01946,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,.13164,0,.5],48:[0,.65556,.11156,0,.5],49:[0,.65556,.11156,0,.5],50:[0,.65556,.11156,0,.5],51:[0,.65556,.11156,0,.5],52:[0,.65556,.11156,0,.5],53:[0,.65556,.11156,0,.5],54:[0,.65556,.11156,0,.5],55:[0,.65556,.11156,0,.5],56:[0,.65556,.11156,0,.5],57:[0,.65556,.11156,0,.5],58:[0,.44444,.02502,0,.27778],59:[.125,.44444,.02502,0,.27778],61:[-.13,.37,.05087,0,.77778],63:[0,.69444,.11809,0,.47222],64:[0,.69444,.07555,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,.08293,0,.66667],67:[0,.69444,.11983,0,.63889],68:[0,.69444,.07555,0,.72223],69:[0,.69444,.11983,0,.59722],70:[0,.69444,.13372,0,.56945],71:[0,.69444,.11983,0,.66667],72:[0,.69444,.08094,0,.70834],73:[0,.69444,.13372,0,.27778],74:[0,.69444,.08094,0,.47222],75:[0,.69444,.11983,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,.08094,0,.875],78:[0,.69444,.08094,0,.70834],79:[0,.69444,.07555,0,.73611],80:[0,.69444,.08293,0,.63889],81:[.125,.69444,.07555,0,.73611],82:[0,.69444,.08293,0,.64584],83:[0,.69444,.09205,0,.55556],84:[0,.69444,.13372,0,.68056],85:[0,.69444,.08094,0,.6875],86:[0,.69444,.1615,0,.66667],87:[0,.69444,.1615,0,.94445],88:[0,.69444,.13372,0,.66667],89:[0,.69444,.17261,0,.66667],90:[0,.69444,.11983,0,.61111],91:[.25,.75,.15942,0,.28889],93:[.25,.75,.08719,0,.28889],94:[0,.69444,.0799,0,.5],95:[.35,.09444,.08616,0,.5],97:[0,.44444,.00981,0,.48056],98:[0,.69444,.03057,0,.51667],99:[0,.44444,.08336,0,.44445],100:[0,.69444,.09483,0,.51667],101:[0,.44444,.06778,0,.44445],102:[0,.69444,.21705,0,.30556],103:[.19444,.44444,.10836,0,.5],104:[0,.69444,.01778,0,.51667],105:[0,.67937,.09718,0,.23889],106:[.19444,.67937,.09162,0,.26667],107:[0,.69444,.08336,0,.48889],108:[0,.69444,.09483,0,.23889],109:[0,.44444,.01778,0,.79445],110:[0,.44444,.01778,0,.51667],111:[0,.44444,.06613,0,.5],112:[.19444,.44444,.0389,0,.51667],113:[.19444,.44444,.04169,0,.51667],114:[0,.44444,.10836,0,.34167],115:[0,.44444,.0778,0,.38333],116:[0,.57143,.07225,0,.36111],117:[0,.44444,.04169,0,.51667],118:[0,.44444,.10836,0,.46111],119:[0,.44444,.10836,0,.68334],120:[0,.44444,.09169,0,.46111],121:[.19444,.44444,.10836,0,.46111],122:[0,.44444,.08752,0,.43472],126:[.35,.32659,.08826,0,.5],160:[0,0,0,0,.25],168:[0,.67937,.06385,0,.5],176:[0,.69444,0,0,.73752],184:[.17014,0,0,0,.44445],305:[0,.44444,.04169,0,.23889],567:[.19444,.44444,.04169,0,.26667],710:[0,.69444,.0799,0,.5],711:[0,.63194,.08432,0,.5],713:[0,.60889,.08776,0,.5],714:[0,.69444,.09205,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,.09483,0,.5],729:[0,.67937,.07774,0,.27778],730:[0,.69444,0,0,.73752],732:[0,.67659,.08826,0,.5],733:[0,.69444,.09205,0,.5],915:[0,.69444,.13372,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,.07555,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,.12816,0,.66667],928:[0,.69444,.08094,0,.70834],931:[0,.69444,.11983,0,.72222],933:[0,.69444,.09031,0,.77778],934:[0,.69444,.04603,0,.72222],936:[0,.69444,.09031,0,.77778],937:[0,.69444,.08293,0,.72222],8211:[0,.44444,.08616,0,.5],8212:[0,.44444,.08616,0,1],8216:[0,.69444,.07816,0,.27778],8217:[0,.69444,.07816,0,.27778],8220:[0,.69444,.14205,0,.5],8221:[0,.69444,.00316,0,.5]},"SansSerif-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.31945],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.75834],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,0,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.65556,0,0,.5],49:[0,.65556,0,0,.5],50:[0,.65556,0,0,.5],51:[0,.65556,0,0,.5],52:[0,.65556,0,0,.5],53:[0,.65556,0,0,.5],54:[0,.65556,0,0,.5],55:[0,.65556,0,0,.5],56:[0,.65556,0,0,.5],57:[0,.65556,0,0,.5],58:[0,.44444,0,0,.27778],59:[.125,.44444,0,0,.27778],61:[-.13,.37,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,0,0,.66667],67:[0,.69444,0,0,.63889],68:[0,.69444,0,0,.72223],69:[0,.69444,0,0,.59722],70:[0,.69444,0,0,.56945],71:[0,.69444,0,0,.66667],72:[0,.69444,0,0,.70834],73:[0,.69444,0,0,.27778],74:[0,.69444,0,0,.47222],75:[0,.69444,0,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,0,0,.875],78:[0,.69444,0,0,.70834],79:[0,.69444,0,0,.73611],80:[0,.69444,0,0,.63889],81:[.125,.69444,0,0,.73611],82:[0,.69444,0,0,.64584],83:[0,.69444,0,0,.55556],84:[0,.69444,0,0,.68056],85:[0,.69444,0,0,.6875],86:[0,.69444,.01389,0,.66667],87:[0,.69444,.01389,0,.94445],88:[0,.69444,0,0,.66667],89:[0,.69444,.025,0,.66667],90:[0,.69444,0,0,.61111],91:[.25,.75,0,0,.28889],93:[.25,.75,0,0,.28889],94:[0,.69444,0,0,.5],95:[.35,.09444,.02778,0,.5],97:[0,.44444,0,0,.48056],98:[0,.69444,0,0,.51667],99:[0,.44444,0,0,.44445],100:[0,.69444,0,0,.51667],101:[0,.44444,0,0,.44445],102:[0,.69444,.06944,0,.30556],103:[.19444,.44444,.01389,0,.5],104:[0,.69444,0,0,.51667],105:[0,.67937,0,0,.23889],106:[.19444,.67937,0,0,.26667],107:[0,.69444,0,0,.48889],108:[0,.69444,0,0,.23889],109:[0,.44444,0,0,.79445],110:[0,.44444,0,0,.51667],111:[0,.44444,0,0,.5],112:[.19444,.44444,0,0,.51667],113:[.19444,.44444,0,0,.51667],114:[0,.44444,.01389,0,.34167],115:[0,.44444,0,0,.38333],116:[0,.57143,0,0,.36111],117:[0,.44444,0,0,.51667],118:[0,.44444,.01389,0,.46111],119:[0,.44444,.01389,0,.68334],120:[0,.44444,0,0,.46111],121:[.19444,.44444,.01389,0,.46111],122:[0,.44444,0,0,.43472],126:[.35,.32659,0,0,.5],160:[0,0,0,0,.25],168:[0,.67937,0,0,.5],176:[0,.69444,0,0,.66667],184:[.17014,0,0,0,.44445],305:[0,.44444,0,0,.23889],567:[.19444,.44444,0,0,.26667],710:[0,.69444,0,0,.5],711:[0,.63194,0,0,.5],713:[0,.60889,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.67937,0,0,.27778],730:[0,.69444,0,0,.66667],732:[0,.67659,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.69444,0,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,0,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,0,0,.66667],928:[0,.69444,0,0,.70834],931:[0,.69444,0,0,.72222],933:[0,.69444,0,0,.77778],934:[0,.69444,0,0,.72222],936:[0,.69444,0,0,.77778],937:[0,.69444,0,0,.72222],8211:[0,.44444,.02778,0,.5],8212:[0,.44444,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5]},"Script-Regular":{32:[0,0,0,0,.25],65:[0,.7,.22925,0,.80253],66:[0,.7,.04087,0,.90757],67:[0,.7,.1689,0,.66619],68:[0,.7,.09371,0,.77443],69:[0,.7,.18583,0,.56162],70:[0,.7,.13634,0,.89544],71:[0,.7,.17322,0,.60961],72:[0,.7,.29694,0,.96919],73:[0,.7,.19189,0,.80907],74:[.27778,.7,.19189,0,1.05159],75:[0,.7,.31259,0,.91364],76:[0,.7,.19189,0,.87373],77:[0,.7,.15981,0,1.08031],78:[0,.7,.3525,0,.9015],79:[0,.7,.08078,0,.73787],80:[0,.7,.08078,0,1.01262],81:[0,.7,.03305,0,.88282],82:[0,.7,.06259,0,.85],83:[0,.7,.19189,0,.86767],84:[0,.7,.29087,0,.74697],85:[0,.7,.25815,0,.79996],86:[0,.7,.27523,0,.62204],87:[0,.7,.27523,0,.80532],88:[0,.7,.26006,0,.94445],89:[0,.7,.2939,0,.70961],90:[0,.7,.24037,0,.8212],160:[0,0,0,0,.25]},"Size1-Regular":{32:[0,0,0,0,.25],40:[.35001,.85,0,0,.45834],41:[.35001,.85,0,0,.45834],47:[.35001,.85,0,0,.57778],91:[.35001,.85,0,0,.41667],92:[.35001,.85,0,0,.57778],93:[.35001,.85,0,0,.41667],123:[.35001,.85,0,0,.58334],125:[.35001,.85,0,0,.58334],160:[0,0,0,0,.25],710:[0,.72222,0,0,.55556],732:[0,.72222,0,0,.55556],770:[0,.72222,0,0,.55556],771:[0,.72222,0,0,.55556],8214:[-99e-5,.601,0,0,.77778],8593:[1e-5,.6,0,0,.66667],8595:[1e-5,.6,0,0,.66667],8657:[1e-5,.6,0,0,.77778],8659:[1e-5,.6,0,0,.77778],8719:[.25001,.75,0,0,.94445],8720:[.25001,.75,0,0,.94445],8721:[.25001,.75,0,0,1.05556],8730:[.35001,.85,0,0,1],8739:[-.00599,.606,0,0,.33333],8741:[-.00599,.606,0,0,.55556],8747:[.30612,.805,.19445,0,.47222],8748:[.306,.805,.19445,0,.47222],8749:[.306,.805,.19445,0,.47222],8750:[.30612,.805,.19445,0,.47222],8896:[.25001,.75,0,0,.83334],8897:[.25001,.75,0,0,.83334],8898:[.25001,.75,0,0,.83334],8899:[.25001,.75,0,0,.83334],8968:[.35001,.85,0,0,.47222],8969:[.35001,.85,0,0,.47222],8970:[.35001,.85,0,0,.47222],8971:[.35001,.85,0,0,.47222],9168:[-99e-5,.601,0,0,.66667],10216:[.35001,.85,0,0,.47222],10217:[.35001,.85,0,0,.47222],10752:[.25001,.75,0,0,1.11111],10753:[.25001,.75,0,0,1.11111],10754:[.25001,.75,0,0,1.11111],10756:[.25001,.75,0,0,.83334],10758:[.25001,.75,0,0,.83334]},"Size2-Regular":{32:[0,0,0,0,.25],40:[.65002,1.15,0,0,.59722],41:[.65002,1.15,0,0,.59722],47:[.65002,1.15,0,0,.81111],91:[.65002,1.15,0,0,.47222],92:[.65002,1.15,0,0,.81111],93:[.65002,1.15,0,0,.47222],123:[.65002,1.15,0,0,.66667],125:[.65002,1.15,0,0,.66667],160:[0,0,0,0,.25],710:[0,.75,0,0,1],732:[0,.75,0,0,1],770:[0,.75,0,0,1],771:[0,.75,0,0,1],8719:[.55001,1.05,0,0,1.27778],8720:[.55001,1.05,0,0,1.27778],8721:[.55001,1.05,0,0,1.44445],8730:[.65002,1.15,0,0,1],8747:[.86225,1.36,.44445,0,.55556],8748:[.862,1.36,.44445,0,.55556],8749:[.862,1.36,.44445,0,.55556],8750:[.86225,1.36,.44445,0,.55556],8896:[.55001,1.05,0,0,1.11111],8897:[.55001,1.05,0,0,1.11111],8898:[.55001,1.05,0,0,1.11111],8899:[.55001,1.05,0,0,1.11111],8968:[.65002,1.15,0,0,.52778],8969:[.65002,1.15,0,0,.52778],8970:[.65002,1.15,0,0,.52778],8971:[.65002,1.15,0,0,.52778],10216:[.65002,1.15,0,0,.61111],10217:[.65002,1.15,0,0,.61111],10752:[.55001,1.05,0,0,1.51112],10753:[.55001,1.05,0,0,1.51112],10754:[.55001,1.05,0,0,1.51112],10756:[.55001,1.05,0,0,1.11111],10758:[.55001,1.05,0,0,1.11111]},"Size3-Regular":{32:[0,0,0,0,.25],40:[.95003,1.45,0,0,.73611],41:[.95003,1.45,0,0,.73611],47:[.95003,1.45,0,0,1.04445],91:[.95003,1.45,0,0,.52778],92:[.95003,1.45,0,0,1.04445],93:[.95003,1.45,0,0,.52778],123:[.95003,1.45,0,0,.75],125:[.95003,1.45,0,0,.75],160:[0,0,0,0,.25],710:[0,.75,0,0,1.44445],732:[0,.75,0,0,1.44445],770:[0,.75,0,0,1.44445],771:[0,.75,0,0,1.44445],8730:[.95003,1.45,0,0,1],8968:[.95003,1.45,0,0,.58334],8969:[.95003,1.45,0,0,.58334],8970:[.95003,1.45,0,0,.58334],8971:[.95003,1.45,0,0,.58334],10216:[.95003,1.45,0,0,.75],10217:[.95003,1.45,0,0,.75]},"Size4-Regular":{32:[0,0,0,0,.25],40:[1.25003,1.75,0,0,.79167],41:[1.25003,1.75,0,0,.79167],47:[1.25003,1.75,0,0,1.27778],91:[1.25003,1.75,0,0,.58334],92:[1.25003,1.75,0,0,1.27778],93:[1.25003,1.75,0,0,.58334],123:[1.25003,1.75,0,0,.80556],125:[1.25003,1.75,0,0,.80556],160:[0,0,0,0,.25],710:[0,.825,0,0,1.8889],732:[0,.825,0,0,1.8889],770:[0,.825,0,0,1.8889],771:[0,.825,0,0,1.8889],8730:[1.25003,1.75,0,0,1],8968:[1.25003,1.75,0,0,.63889],8969:[1.25003,1.75,0,0,.63889],8970:[1.25003,1.75,0,0,.63889],8971:[1.25003,1.75,0,0,.63889],9115:[.64502,1.155,0,0,.875],9116:[1e-5,.6,0,0,.875],9117:[.64502,1.155,0,0,.875],9118:[.64502,1.155,0,0,.875],9119:[1e-5,.6,0,0,.875],9120:[.64502,1.155,0,0,.875],9121:[.64502,1.155,0,0,.66667],9122:[-99e-5,.601,0,0,.66667],9123:[.64502,1.155,0,0,.66667],9124:[.64502,1.155,0,0,.66667],9125:[-99e-5,.601,0,0,.66667],9126:[.64502,1.155,0,0,.66667],9127:[1e-5,.9,0,0,.88889],9128:[.65002,1.15,0,0,.88889],9129:[.90001,0,0,0,.88889],9130:[0,.3,0,0,.88889],9131:[1e-5,.9,0,0,.88889],9132:[.65002,1.15,0,0,.88889],9133:[.90001,0,0,0,.88889],9143:[.88502,.915,0,0,1.05556],10216:[1.25003,1.75,0,0,.80556],10217:[1.25003,1.75,0,0,.80556],57344:[-.00499,.605,0,0,1.05556],57345:[-.00499,.605,0,0,1.05556],57680:[0,.12,0,0,.45],57681:[0,.12,0,0,.45],57682:[0,.12,0,0,.45],57683:[0,.12,0,0,.45]},"Typewriter-Regular":{32:[0,0,0,0,.525],33:[0,.61111,0,0,.525],34:[0,.61111,0,0,.525],35:[0,.61111,0,0,.525],36:[.08333,.69444,0,0,.525],37:[.08333,.69444,0,0,.525],38:[0,.61111,0,0,.525],39:[0,.61111,0,0,.525],40:[.08333,.69444,0,0,.525],41:[.08333,.69444,0,0,.525],42:[0,.52083,0,0,.525],43:[-.08056,.53055,0,0,.525],44:[.13889,.125,0,0,.525],45:[-.08056,.53055,0,0,.525],46:[0,.125,0,0,.525],47:[.08333,.69444,0,0,.525],48:[0,.61111,0,0,.525],49:[0,.61111,0,0,.525],50:[0,.61111,0,0,.525],51:[0,.61111,0,0,.525],52:[0,.61111,0,0,.525],53:[0,.61111,0,0,.525],54:[0,.61111,0,0,.525],55:[0,.61111,0,0,.525],56:[0,.61111,0,0,.525],57:[0,.61111,0,0,.525],58:[0,.43056,0,0,.525],59:[.13889,.43056,0,0,.525],60:[-.05556,.55556,0,0,.525],61:[-.19549,.41562,0,0,.525],62:[-.05556,.55556,0,0,.525],63:[0,.61111,0,0,.525],64:[0,.61111,0,0,.525],65:[0,.61111,0,0,.525],66:[0,.61111,0,0,.525],67:[0,.61111,0,0,.525],68:[0,.61111,0,0,.525],69:[0,.61111,0,0,.525],70:[0,.61111,0,0,.525],71:[0,.61111,0,0,.525],72:[0,.61111,0,0,.525],73:[0,.61111,0,0,.525],74:[0,.61111,0,0,.525],75:[0,.61111,0,0,.525],76:[0,.61111,0,0,.525],77:[0,.61111,0,0,.525],78:[0,.61111,0,0,.525],79:[0,.61111,0,0,.525],80:[0,.61111,0,0,.525],81:[.13889,.61111,0,0,.525],82:[0,.61111,0,0,.525],83:[0,.61111,0,0,.525],84:[0,.61111,0,0,.525],85:[0,.61111,0,0,.525],86:[0,.61111,0,0,.525],87:[0,.61111,0,0,.525],88:[0,.61111,0,0,.525],89:[0,.61111,0,0,.525],90:[0,.61111,0,0,.525],91:[.08333,.69444,0,0,.525],92:[.08333,.69444,0,0,.525],93:[.08333,.69444,0,0,.525],94:[0,.61111,0,0,.525],95:[.09514,0,0,0,.525],96:[0,.61111,0,0,.525],97:[0,.43056,0,0,.525],98:[0,.61111,0,0,.525],99:[0,.43056,0,0,.525],100:[0,.61111,0,0,.525],101:[0,.43056,0,0,.525],102:[0,.61111,0,0,.525],103:[.22222,.43056,0,0,.525],104:[0,.61111,0,0,.525],105:[0,.61111,0,0,.525],106:[.22222,.61111,0,0,.525],107:[0,.61111,0,0,.525],108:[0,.61111,0,0,.525],109:[0,.43056,0,0,.525],110:[0,.43056,0,0,.525],111:[0,.43056,0,0,.525],112:[.22222,.43056,0,0,.525],113:[.22222,.43056,0,0,.525],114:[0,.43056,0,0,.525],115:[0,.43056,0,0,.525],116:[0,.55358,0,0,.525],117:[0,.43056,0,0,.525],118:[0,.43056,0,0,.525],119:[0,.43056,0,0,.525],120:[0,.43056,0,0,.525],121:[.22222,.43056,0,0,.525],122:[0,.43056,0,0,.525],123:[.08333,.69444,0,0,.525],124:[.08333,.69444,0,0,.525],125:[.08333,.69444,0,0,.525],126:[0,.61111,0,0,.525],127:[0,.61111,0,0,.525],160:[0,0,0,0,.525],176:[0,.61111,0,0,.525],184:[.19445,0,0,0,.525],305:[0,.43056,0,0,.525],567:[.22222,.43056,0,0,.525],711:[0,.56597,0,0,.525],713:[0,.56555,0,0,.525],714:[0,.61111,0,0,.525],715:[0,.61111,0,0,.525],728:[0,.61111,0,0,.525],730:[0,.61111,0,0,.525],770:[0,.61111,0,0,.525],771:[0,.61111,0,0,.525],776:[0,.61111,0,0,.525],915:[0,.61111,0,0,.525],916:[0,.61111,0,0,.525],920:[0,.61111,0,0,.525],923:[0,.61111,0,0,.525],926:[0,.61111,0,0,.525],928:[0,.61111,0,0,.525],931:[0,.61111,0,0,.525],933:[0,.61111,0,0,.525],934:[0,.61111,0,0,.525],936:[0,.61111,0,0,.525],937:[0,.61111,0,0,.525],8216:[0,.61111,0,0,.525],8217:[0,.61111,0,0,.525],8242:[0,.61111,0,0,.525],9251:[.11111,.21944,0,0,.525]}},LU={slant:[.25,.25,.25],space:[0,0,0],stretch:[0,0,0],shrink:[0,0,0],xHeight:[.431,.431,.431],quad:[1,1.171,1.472],extraSpace:[0,0,0],num1:[.677,.732,.925],num2:[.394,.384,.387],num3:[.444,.471,.504],denom1:[.686,.752,1.025],denom2:[.345,.344,.532],sup1:[.413,.503,.504],sup2:[.363,.431,.404],sup3:[.289,.286,.294],sub1:[.15,.143,.2],sub2:[.247,.286,.4],supDrop:[.386,.353,.494],subDrop:[.05,.071,.1],delim1:[2.39,1.7,1.98],delim2:[1.01,1.157,1.42],axisHeight:[.25,.25,.25],defaultRuleThickness:[.04,.049,.049],bigOpSpacing1:[.111,.111,.111],bigOpSpacing2:[.166,.166,.166],bigOpSpacing3:[.2,.2,.2],bigOpSpacing4:[.6,.611,.611],bigOpSpacing5:[.1,.143,.143],sqrtRuleThickness:[.04,.04,.04],ptPerEm:[10,10,10],doubleRuleSep:[.2,.2,.2],arrayRuleWidth:[.04,.04,.04],fboxsep:[.3,.3,.3],fboxrule:[.04,.04,.04]},RU={Å:`A`,Ð:`D`,Þ:`o`,å:`a`,ð:`d`,þ:`o`,А:`A`,Б:`B`,В:`B`,Г:`F`,Д:`A`,Е:`E`,Ж:`K`,З:`3`,И:`N`,Й:`N`,К:`K`,Л:`N`,М:`M`,Н:`H`,О:`O`,П:`N`,Р:`P`,С:`C`,Т:`T`,У:`y`,Ф:`O`,Х:`X`,Ц:`U`,Ч:`h`,Ш:`W`,Щ:`W`,Ъ:`B`,Ы:`X`,Ь:`B`,Э:`3`,Ю:`X`,Я:`R`,а:`a`,б:`b`,в:`a`,г:`r`,д:`y`,е:`e`,ж:`m`,з:`e`,и:`n`,й:`n`,к:`n`,л:`n`,м:`m`,н:`n`,о:`o`,п:`n`,р:`p`,с:`c`,т:`o`,у:`y`,ф:`b`,х:`x`,ц:`n`,ч:`n`,ш:`w`,щ:`w`,ъ:`a`,ы:`m`,ь:`a`,э:`e`,ю:`m`,я:`r`};function zU(e,t){IU[e]=t}function BU(e,t,n){if(!IU[t])throw Error(`Font metrics not found for font: `+t+`.`);var r=e.charCodeAt(0),i=IU[t][r];if(!i&&e[0]in RU&&(r=RU[e[0]].charCodeAt(0),i=IU[t][r]),!i&&n===`text`&&$H(r)&&(i=IU[t][77]),i)return{depth:i[0],height:i[1],italic:i[2],skew:i[3],width:i[4]}}var VU={};function HU(e){var t=e>=5?0:e>=3?1:2;if(!VU[t]){var n=VU[t]={cssEmPerMu:LU.quad[t]/18};for(var r of Object.keys(LU))n[r]=LU[r][t]}return VU[t]}var UU={math:{},text:{}};function B(e,t,n,r,i,a){UU[e][i]={font:t,group:n,replace:r},a&&r&&(UU[e][r]=UU[e][i])}var V=`math`,H=`text`,U=`main`,W=`ams`,WU=`accent-token`,G=`bin`,GU=`close`,KU=`inner`,K=`mathord`,qU=`op-token`,JU=`open`,YU=`punct`,q=`rel`,XU=`spacing`,J=`textord`;B(V,U,q,`≡`,`\\equiv`,!0),B(V,U,q,`≺`,`\\prec`,!0),B(V,U,q,`≻`,`\\succ`,!0),B(V,U,q,`∼`,`\\sim`,!0),B(V,U,q,`⊥`,`\\perp`),B(V,U,q,`⪯`,`\\preceq`,!0),B(V,U,q,`⪰`,`\\succeq`,!0),B(V,U,q,`≃`,`\\simeq`,!0),B(V,U,q,`∣`,`\\mid`,!0),B(V,U,q,`≪`,`\\ll`,!0),B(V,U,q,`≫`,`\\gg`,!0),B(V,U,q,`≍`,`\\asymp`,!0),B(V,U,q,`∥`,`\\parallel`),B(V,U,q,`⋈`,`\\bowtie`,!0),B(V,U,q,`⌣`,`\\smile`,!0),B(V,U,q,`⊑`,`\\sqsubseteq`,!0),B(V,U,q,`⊒`,`\\sqsupseteq`,!0),B(V,U,q,`≐`,`\\doteq`,!0),B(V,U,q,`⌢`,`\\frown`,!0),B(V,U,q,`∋`,`\\ni`,!0),B(V,U,q,`∝`,`\\propto`,!0),B(V,U,q,`⊢`,`\\vdash`,!0),B(V,U,q,`⊣`,`\\dashv`,!0),B(V,U,q,`∋`,`\\owns`),B(V,U,YU,`.`,`\\ldotp`),B(V,U,YU,`⋅`,`\\cdotp`),B(V,U,YU,`⋅`,`·`),B(H,U,J,`⋅`,`·`),B(V,U,J,`#`,`\\#`),B(H,U,J,`#`,`\\#`),B(V,U,J,`&`,`\\&`),B(H,U,J,`&`,`\\&`),B(V,U,J,`ℵ`,`\\aleph`,!0),B(V,U,J,`∀`,`\\forall`,!0),B(V,U,J,`ℏ`,`\\hbar`,!0),B(V,U,J,`∃`,`\\exists`,!0),B(V,U,J,`∇`,`\\nabla`,!0),B(V,U,J,`♭`,`\\flat`,!0),B(V,U,J,`ℓ`,`\\ell`,!0),B(V,U,J,`♮`,`\\natural`,!0),B(V,U,J,`♣`,`\\clubsuit`,!0),B(V,U,J,`℘`,`\\wp`,!0),B(V,U,J,`♯`,`\\sharp`,!0),B(V,U,J,`♢`,`\\diamondsuit`,!0),B(V,U,J,`ℜ`,`\\Re`,!0),B(V,U,J,`♡`,`\\heartsuit`,!0),B(V,U,J,`ℑ`,`\\Im`,!0),B(V,U,J,`♠`,`\\spadesuit`,!0),B(V,U,J,`§`,`\\S`,!0),B(H,U,J,`§`,`\\S`),B(V,U,J,`¶`,`\\P`,!0),B(H,U,J,`¶`,`\\P`),B(V,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\textdagger`),B(V,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\textdaggerdbl`),B(V,U,GU,`⎱`,`\\rmoustache`,!0),B(V,U,JU,`⎰`,`\\lmoustache`,!0),B(V,U,GU,`⟯`,`\\rgroup`,!0),B(V,U,JU,`⟮`,`\\lgroup`,!0),B(V,U,G,`∓`,`\\mp`,!0),B(V,U,G,`⊖`,`\\ominus`,!0),B(V,U,G,`⊎`,`\\uplus`,!0),B(V,U,G,`⊓`,`\\sqcap`,!0),B(V,U,G,`∗`,`\\ast`),B(V,U,G,`⊔`,`\\sqcup`,!0),B(V,U,G,`◯`,`\\bigcirc`,!0),B(V,U,G,`∙`,`\\bullet`,!0),B(V,U,G,`‡`,`\\ddagger`),B(V,U,G,`≀`,`\\wr`,!0),B(V,U,G,`⨿`,`\\amalg`),B(V,U,G,`&`,`\\And`),B(V,U,q,`⟵`,`\\longleftarrow`,!0),B(V,U,q,`⇐`,`\\Leftarrow`,!0),B(V,U,q,`⟸`,`\\Longleftarrow`,!0),B(V,U,q,`⟶`,`\\longrightarrow`,!0),B(V,U,q,`⇒`,`\\Rightarrow`,!0),B(V,U,q,`⟹`,`\\Longrightarrow`,!0),B(V,U,q,`↔`,`\\leftrightarrow`,!0),B(V,U,q,`⟷`,`\\longleftrightarrow`,!0),B(V,U,q,`⇔`,`\\Leftrightarrow`,!0),B(V,U,q,`⟺`,`\\Longleftrightarrow`,!0),B(V,U,q,`↦`,`\\mapsto`,!0),B(V,U,q,`⟼`,`\\longmapsto`,!0),B(V,U,q,`↗`,`\\nearrow`,!0),B(V,U,q,`↩`,`\\hookleftarrow`,!0),B(V,U,q,`↪`,`\\hookrightarrow`,!0),B(V,U,q,`↘`,`\\searrow`,!0),B(V,U,q,`↼`,`\\leftharpoonup`,!0),B(V,U,q,`⇀`,`\\rightharpoonup`,!0),B(V,U,q,`↙`,`\\swarrow`,!0),B(V,U,q,`↽`,`\\leftharpoondown`,!0),B(V,U,q,`⇁`,`\\rightharpoondown`,!0),B(V,U,q,`↖`,`\\nwarrow`,!0),B(V,U,q,`⇌`,`\\rightleftharpoons`,!0),B(V,W,q,`≮`,`\\nless`,!0),B(V,W,q,``,`\\@nleqslant`),B(V,W,q,``,`\\@nleqq`),B(V,W,q,`⪇`,`\\lneq`,!0),B(V,W,q,`≨`,`\\lneqq`,!0),B(V,W,q,``,`\\@lvertneqq`),B(V,W,q,`⋦`,`\\lnsim`,!0),B(V,W,q,`⪉`,`\\lnapprox`,!0),B(V,W,q,`⊀`,`\\nprec`,!0),B(V,W,q,`⋠`,`\\npreceq`,!0),B(V,W,q,`⋨`,`\\precnsim`,!0),B(V,W,q,`⪹`,`\\precnapprox`,!0),B(V,W,q,`≁`,`\\nsim`,!0),B(V,W,q,``,`\\@nshortmid`),B(V,W,q,`∤`,`\\nmid`,!0),B(V,W,q,`⊬`,`\\nvdash`,!0),B(V,W,q,`⊭`,`\\nvDash`,!0),B(V,W,q,`⋪`,`\\ntriangleleft`),B(V,W,q,`⋬`,`\\ntrianglelefteq`,!0),B(V,W,q,`⊊`,`\\subsetneq`,!0),B(V,W,q,``,`\\@varsubsetneq`),B(V,W,q,`⫋`,`\\subsetneqq`,!0),B(V,W,q,``,`\\@varsubsetneqq`),B(V,W,q,`≯`,`\\ngtr`,!0),B(V,W,q,``,`\\@ngeqslant`),B(V,W,q,``,`\\@ngeqq`),B(V,W,q,`⪈`,`\\gneq`,!0),B(V,W,q,`≩`,`\\gneqq`,!0),B(V,W,q,``,`\\@gvertneqq`),B(V,W,q,`⋧`,`\\gnsim`,!0),B(V,W,q,`⪊`,`\\gnapprox`,!0),B(V,W,q,`⊁`,`\\nsucc`,!0),B(V,W,q,`⋡`,`\\nsucceq`,!0),B(V,W,q,`⋩`,`\\succnsim`,!0),B(V,W,q,`⪺`,`\\succnapprox`,!0),B(V,W,q,`≆`,`\\ncong`,!0),B(V,W,q,``,`\\@nshortparallel`),B(V,W,q,`∦`,`\\nparallel`,!0),B(V,W,q,`⊯`,`\\nVDash`,!0),B(V,W,q,`⋫`,`\\ntriangleright`),B(V,W,q,`⋭`,`\\ntrianglerighteq`,!0),B(V,W,q,``,`\\@nsupseteqq`),B(V,W,q,`⊋`,`\\supsetneq`,!0),B(V,W,q,``,`\\@varsupsetneq`),B(V,W,q,`⫌`,`\\supsetneqq`,!0),B(V,W,q,``,`\\@varsupsetneqq`),B(V,W,q,`⊮`,`\\nVdash`,!0),B(V,W,q,`⪵`,`\\precneqq`,!0),B(V,W,q,`⪶`,`\\succneqq`,!0),B(V,W,q,``,`\\@nsubseteqq`),B(V,W,G,`⊴`,`\\unlhd`),B(V,W,G,`⊵`,`\\unrhd`),B(V,W,q,`↚`,`\\nleftarrow`,!0),B(V,W,q,`↛`,`\\nrightarrow`,!0),B(V,W,q,`⇍`,`\\nLeftarrow`,!0),B(V,W,q,`⇏`,`\\nRightarrow`,!0),B(V,W,q,`↮`,`\\nleftrightarrow`,!0),B(V,W,q,`⇎`,`\\nLeftrightarrow`,!0),B(V,W,q,`△`,`\\vartriangle`),B(V,W,J,`ℏ`,`\\hslash`),B(V,W,J,`▽`,`\\triangledown`),B(V,W,J,`◊`,`\\lozenge`),B(V,W,J,`Ⓢ`,`\\circledS`),B(V,W,J,`®`,`\\circledR`),B(H,W,J,`®`,`\\circledR`),B(V,W,J,`∡`,`\\measuredangle`,!0),B(V,W,J,`∄`,`\\nexists`),B(V,W,J,`℧`,`\\mho`),B(V,W,J,`Ⅎ`,`\\Finv`,!0),B(V,W,J,`⅁`,`\\Game`,!0),B(V,W,J,`‵`,`\\backprime`),B(V,W,J,`▲`,`\\blacktriangle`),B(V,W,J,`▼`,`\\blacktriangledown`),B(V,W,J,`■`,`\\blacksquare`),B(V,W,J,`⧫`,`\\blacklozenge`),B(V,W,J,`★`,`\\bigstar`),B(V,W,J,`∢`,`\\sphericalangle`,!0),B(V,W,J,`∁`,`\\complement`,!0),B(V,W,J,`ð`,`\\eth`,!0),B(H,U,J,`ð`,`ð`),B(V,W,J,`╱`,`\\diagup`),B(V,W,J,`╲`,`\\diagdown`),B(V,W,J,`□`,`\\square`),B(V,W,J,`□`,`\\Box`),B(V,W,J,`◊`,`\\Diamond`),B(V,W,J,`¥`,`\\yen`,!0),B(H,W,J,`¥`,`\\yen`,!0),B(V,W,J,`✓`,`\\checkmark`,!0),B(H,W,J,`✓`,`\\checkmark`),B(V,W,J,`ℶ`,`\\beth`,!0),B(V,W,J,`ℸ`,`\\daleth`,!0),B(V,W,J,`ℷ`,`\\gimel`,!0),B(V,W,J,`ϝ`,`\\digamma`,!0),B(V,W,J,`ϰ`,`\\varkappa`),B(V,W,JU,`┌`,`\\@ulcorner`,!0),B(V,W,GU,`┐`,`\\@urcorner`,!0),B(V,W,JU,`└`,`\\@llcorner`,!0),B(V,W,GU,`┘`,`\\@lrcorner`,!0),B(V,W,q,`≦`,`\\leqq`,!0),B(V,W,q,`⩽`,`\\leqslant`,!0),B(V,W,q,`⪕`,`\\eqslantless`,!0),B(V,W,q,`≲`,`\\lesssim`,!0),B(V,W,q,`⪅`,`\\lessapprox`,!0),B(V,W,q,`≊`,`\\approxeq`,!0),B(V,W,G,`⋖`,`\\lessdot`),B(V,W,q,`⋘`,`\\lll`,!0),B(V,W,q,`≶`,`\\lessgtr`,!0),B(V,W,q,`⋚`,`\\lesseqgtr`,!0),B(V,W,q,`⪋`,`\\lesseqqgtr`,!0),B(V,W,q,`≑`,`\\doteqdot`),B(V,W,q,`≓`,`\\risingdotseq`,!0),B(V,W,q,`≒`,`\\fallingdotseq`,!0),B(V,W,q,`∽`,`\\backsim`,!0),B(V,W,q,`⋍`,`\\backsimeq`,!0),B(V,W,q,`⫅`,`\\subseteqq`,!0),B(V,W,q,`⋐`,`\\Subset`,!0),B(V,W,q,`⊏`,`\\sqsubset`,!0),B(V,W,q,`≼`,`\\preccurlyeq`,!0),B(V,W,q,`⋞`,`\\curlyeqprec`,!0),B(V,W,q,`≾`,`\\precsim`,!0),B(V,W,q,`⪷`,`\\precapprox`,!0),B(V,W,q,`⊲`,`\\vartriangleleft`),B(V,W,q,`⊴`,`\\trianglelefteq`),B(V,W,q,`⊨`,`\\vDash`,!0),B(V,W,q,`⊪`,`\\Vvdash`,!0),B(V,W,q,`⌣`,`\\smallsmile`),B(V,W,q,`⌢`,`\\smallfrown`),B(V,W,q,`≏`,`\\bumpeq`,!0),B(V,W,q,`≎`,`\\Bumpeq`,!0),B(V,W,q,`≧`,`\\geqq`,!0),B(V,W,q,`⩾`,`\\geqslant`,!0),B(V,W,q,`⪖`,`\\eqslantgtr`,!0),B(V,W,q,`≳`,`\\gtrsim`,!0),B(V,W,q,`⪆`,`\\gtrapprox`,!0),B(V,W,G,`⋗`,`\\gtrdot`),B(V,W,q,`⋙`,`\\ggg`,!0),B(V,W,q,`≷`,`\\gtrless`,!0),B(V,W,q,`⋛`,`\\gtreqless`,!0),B(V,W,q,`⪌`,`\\gtreqqless`,!0),B(V,W,q,`≖`,`\\eqcirc`,!0),B(V,W,q,`≗`,`\\circeq`,!0),B(V,W,q,`≜`,`\\triangleq`,!0),B(V,W,q,`∼`,`\\thicksim`),B(V,W,q,`≈`,`\\thickapprox`),B(V,W,q,`⫆`,`\\supseteqq`,!0),B(V,W,q,`⋑`,`\\Supset`,!0),B(V,W,q,`⊐`,`\\sqsupset`,!0),B(V,W,q,`≽`,`\\succcurlyeq`,!0),B(V,W,q,`⋟`,`\\curlyeqsucc`,!0),B(V,W,q,`≿`,`\\succsim`,!0),B(V,W,q,`⪸`,`\\succapprox`,!0),B(V,W,q,`⊳`,`\\vartriangleright`),B(V,W,q,`⊵`,`\\trianglerighteq`),B(V,W,q,`⊩`,`\\Vdash`,!0),B(V,W,q,`∣`,`\\shortmid`),B(V,W,q,`∥`,`\\shortparallel`),B(V,W,q,`≬`,`\\between`,!0),B(V,W,q,`⋔`,`\\pitchfork`,!0),B(V,W,q,`∝`,`\\varpropto`),B(V,W,q,`◀`,`\\blacktriangleleft`),B(V,W,q,`∴`,`\\therefore`,!0),B(V,W,q,`∍`,`\\backepsilon`),B(V,W,q,`▶`,`\\blacktriangleright`),B(V,W,q,`∵`,`\\because`,!0),B(V,W,q,`⋘`,`\\llless`),B(V,W,q,`⋙`,`\\gggtr`),B(V,W,G,`⊲`,`\\lhd`),B(V,W,G,`⊳`,`\\rhd`),B(V,W,q,`≂`,`\\eqsim`,!0),B(V,U,q,`⋈`,`\\Join`),B(V,W,q,`≑`,`\\Doteq`,!0),B(V,W,G,`∔`,`\\dotplus`,!0),B(V,W,G,`∖`,`\\smallsetminus`),B(V,W,G,`⋒`,`\\Cap`,!0),B(V,W,G,`⋓`,`\\Cup`,!0),B(V,W,G,`⩞`,`\\doublebarwedge`,!0),B(V,W,G,`⊟`,`\\boxminus`,!0),B(V,W,G,`⊞`,`\\boxplus`,!0),B(V,W,G,`⋇`,`\\divideontimes`,!0),B(V,W,G,`⋉`,`\\ltimes`,!0),B(V,W,G,`⋊`,`\\rtimes`,!0),B(V,W,G,`⋋`,`\\leftthreetimes`,!0),B(V,W,G,`⋌`,`\\rightthreetimes`,!0),B(V,W,G,`⋏`,`\\curlywedge`,!0),B(V,W,G,`⋎`,`\\curlyvee`,!0),B(V,W,G,`⊝`,`\\circleddash`,!0),B(V,W,G,`⊛`,`\\circledast`,!0),B(V,W,G,`⋅`,`\\centerdot`),B(V,W,G,`⊺`,`\\intercal`,!0),B(V,W,G,`⋒`,`\\doublecap`),B(V,W,G,`⋓`,`\\doublecup`),B(V,W,G,`⊠`,`\\boxtimes`,!0),B(V,W,q,`⇢`,`\\dashrightarrow`,!0),B(V,W,q,`⇠`,`\\dashleftarrow`,!0),B(V,W,q,`⇇`,`\\leftleftarrows`,!0),B(V,W,q,`⇆`,`\\leftrightarrows`,!0),B(V,W,q,`⇚`,`\\Lleftarrow`,!0),B(V,W,q,`↞`,`\\twoheadleftarrow`,!0),B(V,W,q,`↢`,`\\leftarrowtail`,!0),B(V,W,q,`↫`,`\\looparrowleft`,!0),B(V,W,q,`⇋`,`\\leftrightharpoons`,!0),B(V,W,q,`↶`,`\\curvearrowleft`,!0),B(V,W,q,`↺`,`\\circlearrowleft`,!0),B(V,W,q,`↰`,`\\Lsh`,!0),B(V,W,q,`⇈`,`\\upuparrows`,!0),B(V,W,q,`↿`,`\\upharpoonleft`,!0),B(V,W,q,`⇃`,`\\downharpoonleft`,!0),B(V,U,q,`⊶`,`\\origof`,!0),B(V,U,q,`⊷`,`\\imageof`,!0),B(V,W,q,`⊸`,`\\multimap`,!0),B(V,W,q,`↭`,`\\leftrightsquigarrow`,!0),B(V,W,q,`⇉`,`\\rightrightarrows`,!0),B(V,W,q,`⇄`,`\\rightleftarrows`,!0),B(V,W,q,`↠`,`\\twoheadrightarrow`,!0),B(V,W,q,`↣`,`\\rightarrowtail`,!0),B(V,W,q,`↬`,`\\looparrowright`,!0),B(V,W,q,`↷`,`\\curvearrowright`,!0),B(V,W,q,`↻`,`\\circlearrowright`,!0),B(V,W,q,`↱`,`\\Rsh`,!0),B(V,W,q,`⇊`,`\\downdownarrows`,!0),B(V,W,q,`↾`,`\\upharpoonright`,!0),B(V,W,q,`⇂`,`\\downharpoonright`,!0),B(V,W,q,`⇝`,`\\rightsquigarrow`,!0),B(V,W,q,`⇝`,`\\leadsto`),B(V,W,q,`⇛`,`\\Rrightarrow`,!0),B(V,W,q,`↾`,`\\restriction`),B(V,U,J,`‘`,"`"),B(V,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\textdollar`),B(V,U,J,`%`,`\\%`),B(H,U,J,`%`,`\\%`),B(V,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\textunderscore`),B(V,U,J,`∠`,`\\angle`,!0),B(V,U,J,`∞`,`\\infty`,!0),B(V,U,J,`′`,`\\prime`),B(V,U,J,`△`,`\\triangle`),B(V,U,J,`Γ`,`\\Gamma`,!0),B(V,U,J,`Δ`,`\\Delta`,!0),B(V,U,J,`Θ`,`\\Theta`,!0),B(V,U,J,`Λ`,`\\Lambda`,!0),B(V,U,J,`Ξ`,`\\Xi`,!0),B(V,U,J,`Π`,`\\Pi`,!0),B(V,U,J,`Σ`,`\\Sigma`,!0),B(V,U,J,`Υ`,`\\Upsilon`,!0),B(V,U,J,`Φ`,`\\Phi`,!0),B(V,U,J,`Ψ`,`\\Psi`,!0),B(V,U,J,`Ω`,`\\Omega`,!0),B(V,U,J,`A`,`Α`),B(V,U,J,`B`,`Β`),B(V,U,J,`E`,`Ε`),B(V,U,J,`Z`,`Ζ`),B(V,U,J,`H`,`Η`),B(V,U,J,`I`,`Ι`),B(V,U,J,`K`,`Κ`),B(V,U,J,`M`,`Μ`),B(V,U,J,`N`,`Ν`),B(V,U,J,`O`,`Ο`),B(V,U,J,`P`,`Ρ`),B(V,U,J,`T`,`Τ`),B(V,U,J,`X`,`Χ`),B(V,U,J,`¬`,`\\neg`,!0),B(V,U,J,`¬`,`\\lnot`),B(V,U,J,`⊤`,`\\top`),B(V,U,J,`⊥`,`\\bot`),B(V,U,J,`∅`,`\\emptyset`),B(V,W,J,`∅`,`\\varnothing`),B(V,U,K,`α`,`\\alpha`,!0),B(V,U,K,`β`,`\\beta`,!0),B(V,U,K,`γ`,`\\gamma`,!0),B(V,U,K,`δ`,`\\delta`,!0),B(V,U,K,`ϵ`,`\\epsilon`,!0),B(V,U,K,`ζ`,`\\zeta`,!0),B(V,U,K,`η`,`\\eta`,!0),B(V,U,K,`θ`,`\\theta`,!0),B(V,U,K,`ι`,`\\iota`,!0),B(V,U,K,`κ`,`\\kappa`,!0),B(V,U,K,`λ`,`\\lambda`,!0),B(V,U,K,`μ`,`\\mu`,!0),B(V,U,K,`ν`,`\\nu`,!0),B(V,U,K,`ξ`,`\\xi`,!0),B(V,U,K,`ο`,`\\omicron`,!0),B(V,U,K,`π`,`\\pi`,!0),B(V,U,K,`ρ`,`\\rho`,!0),B(V,U,K,`σ`,`\\sigma`,!0),B(V,U,K,`τ`,`\\tau`,!0),B(V,U,K,`υ`,`\\upsilon`,!0),B(V,U,K,`ϕ`,`\\phi`,!0),B(V,U,K,`χ`,`\\chi`,!0),B(V,U,K,`ψ`,`\\psi`,!0),B(V,U,K,`ω`,`\\omega`,!0),B(V,U,K,`ε`,`\\varepsilon`,!0),B(V,U,K,`ϑ`,`\\vartheta`,!0),B(V,U,K,`ϖ`,`\\varpi`,!0),B(V,U,K,`ϱ`,`\\varrho`,!0),B(V,U,K,`ς`,`\\varsigma`,!0),B(V,U,K,`φ`,`\\varphi`,!0),B(V,U,G,`∗`,`*`,!0),B(V,U,G,`+`,`+`),B(V,U,G,`−`,`-`,!0),B(V,U,G,`⋅`,`\\cdot`,!0),B(V,U,G,`∘`,`\\circ`,!0),B(V,U,G,`÷`,`\\div`,!0),B(V,U,G,`±`,`\\pm`,!0),B(V,U,G,`×`,`\\times`,!0),B(V,U,G,`∩`,`\\cap`,!0),B(V,U,G,`∪`,`\\cup`,!0),B(V,U,G,`∖`,`\\setminus`,!0),B(V,U,G,`∧`,`\\land`),B(V,U,G,`∨`,`\\lor`),B(V,U,G,`∧`,`\\wedge`,!0),B(V,U,G,`∨`,`\\vee`,!0),B(V,U,J,`√`,`\\surd`),B(V,U,JU,`⟨`,`\\langle`,!0),B(V,U,JU,`∣`,`\\lvert`),B(V,U,JU,`∥`,`\\lVert`),B(V,U,GU,`?`,`?`),B(V,U,GU,`!`,`!`),B(V,U,GU,`⟩`,`\\rangle`,!0),B(V,U,GU,`∣`,`\\rvert`),B(V,U,GU,`∥`,`\\rVert`),B(V,U,q,`=`,`=`),B(V,U,q,`:`,`:`),B(V,U,q,`≈`,`\\approx`,!0),B(V,U,q,`≅`,`\\cong`,!0),B(V,U,q,`≥`,`\\ge`),B(V,U,q,`≥`,`\\geq`,!0),B(V,U,q,`←`,`\\gets`),B(V,U,q,`>`,`\\gt`,!0),B(V,U,q,`∈`,`\\in`,!0),B(V,U,q,``,`\\@not`),B(V,U,q,`⊂`,`\\subset`,!0),B(V,U,q,`⊃`,`\\supset`,!0),B(V,U,q,`⊆`,`\\subseteq`,!0),B(V,U,q,`⊇`,`\\supseteq`,!0),B(V,W,q,`⊈`,`\\nsubseteq`,!0),B(V,W,q,`⊉`,`\\nsupseteq`,!0),B(V,U,q,`⊨`,`\\models`),B(V,U,q,`←`,`\\leftarrow`,!0),B(V,U,q,`≤`,`\\le`),B(V,U,q,`≤`,`\\leq`,!0),B(V,U,q,`<`,`\\lt`,!0),B(V,U,q,`→`,`\\rightarrow`,!0),B(V,U,q,`→`,`\\to`),B(V,W,q,`≱`,`\\ngeq`,!0),B(V,W,q,`≰`,`\\nleq`,!0),B(V,U,XU,`\xA0`,`\\ `),B(V,U,XU,`\xA0`,`\\space`),B(V,U,XU,`\xA0`,`\\nobreakspace`),B(H,U,XU,`\xA0`,`\\ `),B(H,U,XU,`\xA0`,` `),B(H,U,XU,`\xA0`,`\\space`),B(H,U,XU,`\xA0`,`\\nobreakspace`),B(V,U,XU,``,`\\nobreak`),B(V,U,XU,``,`\\allowbreak`),B(V,U,YU,`,`,`,`),B(V,U,YU,`;`,`;`),B(V,W,G,`⊼`,`\\barwedge`,!0),B(V,W,G,`⊻`,`\\veebar`,!0),B(V,U,G,`⊙`,`\\odot`,!0),B(V,U,G,`⊕`,`\\oplus`,!0),B(V,U,G,`⊗`,`\\otimes`,!0),B(V,U,J,`∂`,`\\partial`,!0),B(V,U,G,`⊘`,`\\oslash`,!0),B(V,W,G,`⊚`,`\\circledcirc`,!0),B(V,W,G,`⊡`,`\\boxdot`,!0),B(V,U,G,`△`,`\\bigtriangleup`),B(V,U,G,`▽`,`\\bigtriangledown`),B(V,U,G,`†`,`\\dagger`),B(V,U,G,`⋄`,`\\diamond`),B(V,U,G,`⋆`,`\\star`),B(V,U,G,`◃`,`\\triangleleft`),B(V,U,G,`▹`,`\\triangleright`),B(V,U,JU,`{`,`\\{`),B(H,U,J,`{`,`\\{`),B(H,U,J,`{`,`\\textbraceleft`),B(V,U,GU,`}`,`\\}`),B(H,U,J,`}`,`\\}`),B(H,U,J,`}`,`\\textbraceright`),B(V,U,JU,`{`,`\\lbrace`),B(V,U,GU,`}`,`\\rbrace`),B(V,U,JU,`[`,`\\lbrack`,!0),B(H,U,J,`[`,`\\lbrack`,!0),B(V,U,GU,`]`,`\\rbrack`,!0),B(H,U,J,`]`,`\\rbrack`,!0),B(V,U,JU,`(`,`\\lparen`,!0),B(V,U,GU,`)`,`\\rparen`,!0),B(H,U,J,`<`,`\\textless`,!0),B(H,U,J,`>`,`\\textgreater`,!0),B(V,U,JU,`⌊`,`\\lfloor`,!0),B(V,U,GU,`⌋`,`\\rfloor`,!0),B(V,U,JU,`⌈`,`\\lceil`,!0),B(V,U,GU,`⌉`,`\\rceil`,!0),B(V,U,J,`\\`,`\\backslash`),B(V,U,J,`∣`,`|`),B(V,U,J,`∣`,`\\vert`),B(H,U,J,`|`,`\\textbar`,!0),B(V,U,J,`∥`,`\\|`),B(V,U,J,`∥`,`\\Vert`),B(H,U,J,`∥`,`\\textbardbl`),B(H,U,J,`~`,`\\textasciitilde`),B(H,U,J,`\\`,`\\textbackslash`),B(H,U,J,`^`,`\\textasciicircum`),B(V,U,q,`↑`,`\\uparrow`,!0),B(V,U,q,`⇑`,`\\Uparrow`,!0),B(V,U,q,`↓`,`\\downarrow`,!0),B(V,U,q,`⇓`,`\\Downarrow`,!0),B(V,U,q,`↕`,`\\updownarrow`,!0),B(V,U,q,`⇕`,`\\Updownarrow`,!0),B(V,U,qU,`∐`,`\\coprod`),B(V,U,qU,`⋁`,`\\bigvee`),B(V,U,qU,`⋀`,`\\bigwedge`),B(V,U,qU,`⨄`,`\\biguplus`),B(V,U,qU,`⋂`,`\\bigcap`),B(V,U,qU,`⋃`,`\\bigcup`),B(V,U,qU,`∫`,`\\int`),B(V,U,qU,`∫`,`\\intop`),B(V,U,qU,`∬`,`\\iint`),B(V,U,qU,`∭`,`\\iiint`),B(V,U,qU,`∏`,`\\prod`),B(V,U,qU,`∑`,`\\sum`),B(V,U,qU,`⨂`,`\\bigotimes`),B(V,U,qU,`⨁`,`\\bigoplus`),B(V,U,qU,`⨀`,`\\bigodot`),B(V,U,qU,`∮`,`\\oint`),B(V,U,qU,`∯`,`\\oiint`),B(V,U,qU,`∰`,`\\oiiint`),B(V,U,qU,`⨆`,`\\bigsqcup`),B(V,U,qU,`∫`,`\\smallint`),B(H,U,KU,`…`,`\\textellipsis`),B(V,U,KU,`…`,`\\mathellipsis`),B(H,U,KU,`…`,`\\ldots`,!0),B(V,U,KU,`…`,`\\ldots`,!0),B(V,U,KU,`⋯`,`\\@cdots`,!0),B(V,U,KU,`⋱`,`\\ddots`,!0),B(V,U,J,`⋮`,`\\varvdots`),B(H,U,J,`⋮`,`\\varvdots`),B(V,U,WU,`ˊ`,`\\acute`),B(V,U,WU,`ˋ`,`\\grave`),B(V,U,WU,`¨`,`\\ddot`),B(V,U,WU,`~`,`\\tilde`),B(V,U,WU,`ˉ`,`\\bar`),B(V,U,WU,`˘`,`\\breve`),B(V,U,WU,`ˇ`,`\\check`),B(V,U,WU,`^`,`\\hat`),B(V,U,WU,`⃗`,`\\vec`),B(V,U,WU,`˙`,`\\dot`),B(V,U,WU,`˚`,`\\mathring`),B(V,U,K,``,`\\@imath`),B(V,U,K,``,`\\@jmath`),B(V,U,J,`ı`,`ı`),B(V,U,J,`ȷ`,`ȷ`),B(H,U,J,`ı`,`\\i`,!0),B(H,U,J,`ȷ`,`\\j`,!0),B(H,U,J,`ß`,`\\ss`,!0),B(H,U,J,`æ`,`\\ae`,!0),B(H,U,J,`œ`,`\\oe`,!0),B(H,U,J,`ø`,`\\o`,!0),B(H,U,J,`Æ`,`\\AE`,!0),B(H,U,J,`Œ`,`\\OE`,!0),B(H,U,J,`Ø`,`\\O`,!0),B(H,U,WU,`ˊ`,`\\'`),B(H,U,WU,`ˋ`,"\\`"),B(H,U,WU,`ˆ`,`\\^`),B(H,U,WU,`˜`,`\\~`),B(H,U,WU,`ˉ`,`\\=`),B(H,U,WU,`˘`,`\\u`),B(H,U,WU,`˙`,`\\.`),B(H,U,WU,`¸`,`\\c`),B(H,U,WU,`˚`,`\\r`),B(H,U,WU,`ˇ`,`\\v`),B(H,U,WU,`¨`,`\\"`),B(H,U,WU,`˝`,`\\H`),B(H,U,WU,`◯`,`\\textcircled`);var ZU={"--":!0,"---":!0,"``":!0,"''":!0};B(H,U,J,`–`,`--`,!0),B(H,U,J,`–`,`\\textendash`),B(H,U,J,`—`,`---`,!0),B(H,U,J,`—`,`\\textemdash`),B(H,U,J,`‘`,"`",!0),B(H,U,J,`‘`,`\\textquoteleft`),B(H,U,J,`’`,`'`,!0),B(H,U,J,`’`,`\\textquoteright`),B(H,U,J,`“`,"``",!0),B(H,U,J,`“`,`\\textquotedblleft`),B(H,U,J,`”`,`''`,!0),B(H,U,J,`”`,`\\textquotedblright`),B(V,U,J,`°`,`\\degree`,!0),B(H,U,J,`°`,`\\degree`),B(H,U,J,`°`,`\\textdegree`,!0),B(V,U,J,`£`,`\\pounds`),B(V,U,J,`£`,`\\mathsterling`,!0),B(H,U,J,`£`,`\\pounds`),B(H,U,J,`£`,`\\textsterling`,!0),B(V,W,J,`✠`,`\\maltese`),B(H,W,J,`✠`,`\\maltese`);for(var QU=`0123456789/@."`,$U=0;$U{var t=e.charCodeAt(0),n=e.charCodeAt(1),r=(t-55296)*1024+(n-56320)+65536;if(119808<=r&&r<120484)return EW[Math.floor((r-119808)/26)];if(120782<=r&&r<=120831)return DW[Math.floor((r-120782)/10)];if(r===120485||r===120486)return EW[0];if(120486{if(yU(e.classes)!==yU(t.classes)||e.skew!==t.skew||e.maxFontSize!==t.maxFontSize||e.italic!==0&&e.hasClass(`mathnormal`))return!1;if(e.classes.length===1){var n=e.classes[0];if(n===`mbin`||n===`mord`)return!1}for(var r of Object.keys(e.style))if(e.style[r]!==t.style[r])return!1;for(var i of Object.keys(t.style))if(e.style[i]!==t.style[i])return!1;return!0},FW=e=>{for(var t=0;tt&&(t=a.height),a.depth>n&&(n=a.depth),a.maxFontSize>r&&(r=a.maxFontSize)}e.height=t,e.depth=n,e.maxFontSize=r},X=function(e,t,n,r){var i=new TU(e,t,n,r);return IW(i),i},LW=(e,t,n,r)=>new TU(e,t,n,r),RW=function(e,t,n){var r=X([e],[],t);return r.height=Math.max(n||t.fontMetrics().defaultRuleThickness,t.minRuleThickness),r.style.borderBottomWidth=z(r.height),r.maxFontSize=1,r},zW=function(e,t,n,r){var i=new EU(e,t,n,r);return IW(i),i},BW=function(e){var t=new mU(e);return IW(t),t},VW=function(e,t){return e instanceof mU?X([],[e],t):e},HW=function(e){if(e.positionType===`individualShift`){for(var t=e.children,n=[t[0]],r=-t[0].shift-t[0].elem.depth,i=r,a=1;a{var n=X([`mspace`],[],t),r=vU(e,t);return n.style.marginRight=z(r),n},GW=(e,t,n)=>{var r,i;switch(e){case`amsrm`:r=`AMS`;break;case`textrm`:r=`Main`;break;case`textsf`:r=`SansSerif`;break;case`texttt`:r=`Typewriter`;break;default:r=e}return i=t===`textbf`&&n===`textit`?`BoldItalic`:t===`textbf`?`Bold`:n===`textit`?`Italic`:`Regular`,r+`-`+i},KW={mathbf:{variant:`bold`,fontName:`Main-Bold`},mathrm:{variant:`normal`,fontName:`Main-Regular`},textit:{variant:`italic`,fontName:`Main-Italic`},mathit:{variant:`italic`,fontName:`Main-Italic`},mathnormal:{variant:`italic`,fontName:`Math-Italic`},mathsfit:{variant:`sans-serif-italic`,fontName:`SansSerif-Italic`},mathbb:{variant:`double-struck`,fontName:`AMS-Regular`},mathcal:{variant:`script`,fontName:`Caligraphic-Regular`},mathfrak:{variant:`fraktur`,fontName:`Fraktur-Regular`},mathscr:{variant:`script`,fontName:`Script-Regular`},mathsf:{variant:`sans-serif`,fontName:`SansSerif-Regular`},mathtt:{variant:`monospace`,fontName:`Typewriter-Regular`}},qW={vec:[`vec`,.471,.714],oiintSize1:[`oiintSize1`,.957,.499],oiintSize2:[`oiintSize2`,1.472,.659],oiiintSize1:[`oiiintSize1`,1.304,.499],oiiintSize2:[`oiiintSize2`,1.98,.659]},JW=function(e,t){var n=qW[e],r=n[0],i=n[1],a=n[2],o=LW([`katex-overlay`],[new AU([new jU(r)],{width:z(i),height:z(a),style:`width:`+z(i),viewBox:`0 0 `+1e3*i+` `+1e3*a,preserveAspectRatio:`xMinYMin`})],t);return o.height=a,o.style.height=z(a),o.style.width=z(i),o},YW={number:3,unit:`mu`},XW={number:4,unit:`mu`},ZW={number:5,unit:`mu`},QW={mord:{mop:YW,mbin:XW,mrel:ZW,minner:YW},mop:{mord:YW,mop:YW,mrel:ZW,minner:YW},mbin:{mord:XW,mop:XW,mopen:XW,minner:XW},mrel:{mord:ZW,mop:ZW,mopen:ZW,minner:ZW},mopen:{},mclose:{mop:YW,mbin:XW,mrel:ZW,minner:YW},mpunct:{mord:YW,mop:YW,mrel:ZW,mopen:YW,mclose:YW,mpunct:YW,minner:YW},minner:{mord:YW,mop:YW,mbin:XW,mrel:ZW,mopen:YW,mpunct:YW,minner:YW}},$W={mord:{mop:YW},mop:{mord:YW,mop:YW},mbin:{},mrel:{},mopen:{},mclose:{mop:YW},mpunct:{},minner:{mop:YW}},eG={},tG={},nG={};function Z(e){for(var t=e.type,n=e.names,r=e.htmlBuilder,i=e.mathmlBuilder,a=0;a{var n=t.classes[0],r=e.classes[0];n===`mbin`&&sG.has(r)?t.classes[0]=`mord`:r===`mbin`&&oG.has(n)&&(e.classes[0]=`mord`)},{node:u},d,f),dG(i,(e,t)=>{var n=mG(t),r=mG(e),i=n&&r?e.hasClass(`mtight`)?$W[n]?.[r]:QW[n]?.[r]:null;if(i)return WW(i,c)},{node:u},d,f),i},dG=function(e,t,n,r,i){r&&e.push(r);for(var a=0;an=>{e.splice(t+1,0,n),a++})(a)}}r&&e.pop()},fG=function(e){return e instanceof mU||e instanceof EU||e instanceof TU&&e.hasClass(`enclosing`)?e:null},pG=function(e,t){var n=fG(e);if(n){var r=n.children;if(r.length){if(t===`right`)return pG(r[r.length-1],`right`);if(t===`left`)return pG(r[0],`left`)}}return e},mG=function(e,t){return e?(t&&(e=pG(e,t)),lG[e.classes[0]]||null):null},hG=function(e,t){var n=[`nulldelimiter`].concat(e.baseSizingClasses());return X(t.concat(n))},gG=function(e,t,n){if(!e)return X();if(tG[e.type]){var r=tG[e.type](e,t);if(n&&t.size!==n.size){r=X(t.sizingClasses(n),[r],t);var i=t.sizeMultiplier/n.sizeMultiplier;r.height*=i,r.depth*=i}return r}throw new L(`Got group of unknown type: '`+e.type+`'`)};function _G(e,t){var n=X([`katex-base`],e,t),r=X([`katex-strut`]);return r.style.height=z(n.height+n.depth),n.depth&&(r.style.verticalAlign=z(-n.depth)),n.children.unshift(r),n}function vG(e,t){var n=null;e.length===1&&e[0].type===`tag`&&(n=e[0].tag,e=e[0].body);var r=uG(e,t,`root`),i;r.length===2&&r[1].hasClass(`katex-tag`)&&(i=r.pop());for(var a=[],o=[],s=0;s0&&(a.push(_G(o,t)),o=[]),a.push(r[s]));o.length>0&&a.push(_G(o,t));var l;n?(l=_G(uG(n,t,!0),t),l.classes=[`katex-tag`],a.push(l)):i&&a.push(i);var u=X([`katex-html`],a);if(u.setAttribute(`aria-hidden`,`true`),l){var d=l.children[0];d.style.height=z(u.height+u.depth),u.depth&&(d.style.verticalAlign=z(-u.depth))}return u}function yG(e){return new mU(e)}var Q=class{constructor(e,t,n){this.type=void 0,this.attributes=void 0,this.children=void 0,this.classes=void 0,this.type=e,this.attributes={},this.children=t||[],this.classes=n||[]}setAttribute(e,t){this.attributes[e]=t}getAttribute(e){return this.attributes[e]}toNode(){var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,this.type);for(var t of Object.entries(this.attributes)){var n=t[0],r=t[1];e.setAttribute(n,r)}this.classes.length>0&&(e.className=yU(this.classes));for(var i=0;i0&&(e+=` class ="`+wH(yU(this.classes))+`"`),e+=`>`;for(var i=0;i`,e}toText(){return this.children.map(e=>e.toText()).join(``)}},bG=class{constructor(e){this.text=void 0,this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return wH(this.toText())}toText(){return this.text}},xG=class{constructor(e){this.width=void 0,this.character=void 0,this.width=e,this.character=e>=.05555&&e<=.05556?` `:e>=.1666&&e<=.1667?` `:e>=.2222&&e<=.2223?` `:e>=.2777&&e<=.2778?`  `:e>=-.05556&&e<=-.05555?` ⁣`:e>=-.1667&&e<=-.1666?` ⁣`:e>=-.2223&&e<=-.2222?` ⁣`:e>=-.2778&&e<=-.2777?` ⁣`:null}toNode(){if(this.character)return document.createTextNode(this.character);var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`mspace`);return e.setAttribute(`width`,z(this.width)),e}toMarkup(){return this.character?``+this.character+``:``}toText(){return this.character?this.character:` `}},SG=new Set([`\\imath`,`\\jmath`]),CG=new Set([`mrow`,`mtable`]),wG=function(e,t,n){var r,i;return UU[t][e]&&UU[t][e].replace&&e.charCodeAt(0)!==55349&&(!Object.prototype.hasOwnProperty.call(ZU,e)||(n==null||(r=n.fontFamily)==null?void 0:r.slice(4,6))!==`tt`&&(n==null||(i=n.font)==null?void 0:i.slice(4,6))!==`tt`)&&(e=UU[t][e].replace),new bG(e)},TG=function(e){return e.length===1?e[0]:new Q(`mrow`,e)},EG={mathit:`italic`,boldsymbol:e=>e.type===`textord`?`bold`:`bold-italic`,mathbf:`bold`,mathbb:`double-struck`,mathsfit:`sans-serif-italic`,mathfrak:`fraktur`,mathscr:`script`,mathcal:`script`,mathsf:`sans-serif`,mathtt:`monospace`},DG=(e,t)=>{if(e.mode===`text`){if(t.fontFamily===`texttt`)return`monospace`;if(t.fontFamily===`textsf`)return t.fontShape===`textit`&&t.fontWeight===`textbf`?`sans-serif-bold-italic`:t.fontShape===`textit`?`sans-serif-italic`:t.fontWeight===`textbf`?`bold-sans-serif`:`sans-serif`;if(t.fontShape===`textit`&&t.fontWeight===`textbf`)return`bold-italic`;if(t.fontShape===`textit`)return`italic`;if(t.fontWeight===`textbf`)return`bold`}var n=t.font;if(!n||n===`mathnormal`)return null;var r=e.mode,i=EG[n];if(i)return typeof i==`function`?i(e):i;var a=e.text;if(SG.has(a))return null;if(UU[r][a]){var o=UU[r][a].replace;o&&(a=o)}var s=KW[n].fontName;return BU(a,s,r)?KW[n].variant:null};function OG(e){if(!e)return!1;if(e.type===`mi`&&e.children.length===1){var t=e.children[0];return t instanceof bG&&t.text===`.`}if(e.type===`mo`&&e.children.length===1&&e.getAttribute(`separator`)===`true`&&e.getAttribute(`lspace`)===`0em`&&e.getAttribute(`rspace`)===`0em`){var n=e.children[0];return n instanceof bG&&n.text===`,`}return!1}var kG=function(e,t,n){if(e.length===1){var r=jG(e[0],t);return n&&r instanceof Q&&r.type===`mo`&&(r.setAttribute(`lspace`,`0em`),r.setAttribute(`rspace`,`0em`)),[r]}for(var i=[],a,o=0;o=1&&(a.type===`mn`||OG(a))){var c=s.children[0];c instanceof Q&&c.type===`mn`&&(c.children=[...a.children,...c.children],i.pop())}else if(a.type===`mi`&&a.children.length===1){var l=a.children[0];if(l instanceof bG&&l.text===`̸`&&(s.type===`mo`||s.type===`mi`||s.type===`mn`)){var u=s.children[0];u instanceof bG&&u.text.length>0&&(u.text=u.text.slice(0,1)+`̸`+u.text.slice(1),i.pop())}}}i.push(s),a=s}return i},AG=function(e,t,n){return TG(kG(e,t,n))},jG=function(e,t){if(!e)return new Q(`mrow`);if(nG[e.type])return nG[e.type](e,t);throw new L(`Got group of unknown type: '`+e.type+`'`)};function MG(e,t,n,r,i){var a=kG(e,n),o=a.length===1&&a[0]instanceof Q&&CG.has(a[0].type)?a[0]:new Q(`mrow`,a),s=new Q(`annotation`,[new bG(t)]);s.setAttribute(`encoding`,`application/x-tex`);var c=new Q(`math`,[new Q(`semantics`,[o,s])]);return c.setAttribute(`xmlns`,`http://www.w3.org/1998/Math/MathML`),r&&c.setAttribute(`display`,`block`),X([i?`katex`:`katex-mathml`],[c])}var NG=[[1,1,1],[2,1,1],[3,1,1],[4,2,1],[5,2,1],[6,3,1],[7,4,2],[8,6,3],[9,7,6],[10,8,7],[11,10,9]],PG=[.5,.6,.7,.8,.9,1,1.2,1.44,1.728,2.074,2.488],FG=function(e,t){return t.size<2?e:NG[e-1][t.size-1]},IG=class e{constructor(t){this.style=void 0,this.color=void 0,this.size=void 0,this.textSize=void 0,this.phantom=void 0,this.font=void 0,this.fontFamily=void 0,this.fontWeight=void 0,this.fontShape=void 0,this.sizeMultiplier=void 0,this.maxSize=void 0,this.minRuleThickness=void 0,this._fontMetrics=void 0,this.style=t.style,this.color=t.color,this.size=t.size||e.BASESIZE,this.textSize=t.textSize||this.size,this.phantom=!!t.phantom,this.font=t.font||``,this.fontFamily=t.fontFamily||``,this.fontWeight=t.fontWeight||``,this.fontShape=t.fontShape||``,this.sizeMultiplier=PG[this.size-1],this.maxSize=t.maxSize,this.minRuleThickness=t.minRuleThickness,this._fontMetrics=void 0}extend(t){var n={style:this.style,size:this.size,textSize:this.textSize,color:this.color,phantom:this.phantom,font:this.font,fontFamily:this.fontFamily,fontWeight:this.fontWeight,fontShape:this.fontShape,maxSize:this.maxSize,minRuleThickness:this.minRuleThickness};return Object.assign(n,t),new e(n)}havingStyle(e){return this.style===e?this:this.extend({style:e,size:FG(this.textSize,e)})}havingCrampedStyle(){return this.havingStyle(this.style.cramp())}havingSize(e){return this.size===e&&this.textSize===e?this:this.extend({style:this.style.text(),size:e,textSize:e,sizeMultiplier:PG[e-1]})}havingBaseStyle(t){t||=this.style.text();var n=FG(e.BASESIZE,t);return this.size===n&&this.textSize===e.BASESIZE&&this.style===t?this:this.extend({style:t,size:n})}havingBaseSizing(){var e;switch(this.style.id){case 4:case 5:e=3;break;case 6:case 7:e=1;break;default:e=6}return this.extend({style:this.style.text(),size:e})}withColor(e){return this.extend({color:e})}withPhantom(){return this.extend({phantom:!0})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:``})}withTextFontWeight(e){return this.extend({fontWeight:e,font:``})}withTextFontShape(e){return this.extend({fontShape:e,font:``})}sizingClasses(e){return e.size===this.size?[]:[`katex-sizing`,`reset-size`+e.size,`size`+this.size]}baseSizingClasses(){return this.size===e.BASESIZE?[]:[`katex-sizing`,`reset-size`+this.size,`size`+e.BASESIZE]}fontMetrics(){return this._fontMetrics||=HU(this.size),this._fontMetrics}getColor(){return this.phantom?`transparent`:this.color}};IG.BASESIZE=6;var LG=function(e){return new IG({style:e.displayMode?R.DISPLAY:R.TEXT,maxSize:e.maxSize,minRuleThickness:e.minRuleThickness})},RG=function(e,t){if(t.displayMode){var n=[`katex-display`];t.leqno&&n.push(`leqno`),t.fleqn&&n.push(`fleqn`),e=X(n,[e])}return e},zG=function(e,t,n){var r=LG(n),i;return n.output===`mathml`?MG(e,t,r,n.displayMode,!0):(i=n.output===`html`?X([`katex`],[vG(e,r)]):X([`katex`],[MG(e,t,r,n.displayMode,!1),vG(e,r)]),RG(i,n))},BG=function(e,t,n){return RG(X([`katex`],[vG(e,LG(n))]),n)},VG={widehat:`^`,widecheck:`ˇ`,widetilde:`~`,utilde:`~`,overleftarrow:`←`,underleftarrow:`←`,xleftarrow:`←`,overrightarrow:`→`,underrightarrow:`→`,xrightarrow:`→`,underbrace:`⏟`,overbrace:`⏞`,underbracket:`⎵`,overbracket:`⎴`,overgroup:`⏠`,undergroup:`⏡`,overleftrightarrow:`↔`,underleftrightarrow:`↔`,xleftrightarrow:`↔`,Overrightarrow:`⇒`,xRightarrow:`⇒`,overleftharpoon:`↼`,xleftharpoonup:`↼`,overrightharpoon:`⇀`,xrightharpoonup:`⇀`,xLeftarrow:`⇐`,xLeftrightarrow:`⇔`,xhookleftarrow:`↩`,xhookrightarrow:`↪`,xmapsto:`↦`,xrightharpoondown:`⇁`,xleftharpoondown:`↽`,xrightleftharpoons:`⇌`,xleftrightharpoons:`⇋`,xtwoheadleftarrow:`↞`,xtwoheadrightarrow:`↠`,xlongequal:`=`,xtofrom:`⇄`,xrightleftarrows:`⇄`,xrightequilibrium:`⇌`,xleftequilibrium:`⇋`,"\\cdrightarrow":`→`,"\\cdleftarrow":`←`,"\\cdlongequal":`=`},HG=function(e){var t=new Q(`mo`,[new bG(VG[e.replace(/^\\/,``)])]);return t.setAttribute(`stretchy`,`true`),t},UG={overrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],overleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],underrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],underleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],xrightarrow:[[`rightarrow`],1.469,522,`xMaxYMin`],"\\cdrightarrow":[[`rightarrow`],3,522,`xMaxYMin`],xleftarrow:[[`leftarrow`],1.469,522,`xMinYMin`],"\\cdleftarrow":[[`leftarrow`],3,522,`xMinYMin`],Overrightarrow:[[`doublerightarrow`],.888,560,`xMaxYMin`],xRightarrow:[[`doublerightarrow`],1.526,560,`xMaxYMin`],xLeftarrow:[[`doubleleftarrow`],1.526,560,`xMinYMin`],overleftharpoon:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoonup:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoondown:[[`leftharpoondown`],.888,522,`xMinYMin`],overrightharpoon:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoonup:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoondown:[[`rightharpoondown`],.888,522,`xMaxYMin`],xlongequal:[[`longequal`],.888,334,`xMinYMin`],"\\cdlongequal":[[`longequal`],3,334,`xMinYMin`],xtwoheadleftarrow:[[`twoheadleftarrow`],.888,334,`xMinYMin`],xtwoheadrightarrow:[[`twoheadrightarrow`],.888,334,`xMaxYMin`],overleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],overbrace:[[`leftbrace`,`midbrace`,`rightbrace`],1.6,548],underbrace:[[`leftbraceunder`,`midbraceunder`,`rightbraceunder`],1.6,548],underleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],xleftrightarrow:[[`leftarrow`,`rightarrow`],1.75,522],xLeftrightarrow:[[`doubleleftarrow`,`doublerightarrow`],1.75,560],xrightleftharpoons:[[`leftharpoondownplus`,`rightharpoonplus`],1.75,716],xleftrightharpoons:[[`leftharpoonplus`,`rightharpoondownplus`],1.75,716],xhookleftarrow:[[`leftarrow`,`righthook`],1.08,522],xhookrightarrow:[[`lefthook`,`rightarrow`],1.08,522],overlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],underlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],overbracket:[[`leftbracketover`,`rightbracketover`],1.6,440],underbracket:[[`leftbracketunder`,`rightbracketunder`],1.6,410],overgroup:[[`leftgroup`,`rightgroup`],.888,342],undergroup:[[`leftgroupunder`,`rightgroupunder`],.888,342],xmapsto:[[`leftmapsto`,`rightarrow`],1.5,522],xtofrom:[[`leftToFrom`,`rightToFrom`],1.75,528],xrightleftarrows:[[`baraboveleftarrow`,`rightarrowabovebar`],1.75,901],xrightequilibrium:[[`baraboveshortleftharpoon`,`rightharpoonaboveshortbar`],1.75,716],xleftequilibrium:[[`shortbaraboveleftharpoon`,`shortrightharpoonabovebar`],1.75,716]},WG=new Set([`widehat`,`widecheck`,`widetilde`,`utilde`]),GG=function(e,t){function n(){var n=4e5,r=e.label.slice(1);if(WG.has(r)&&`base`in e){var i=e.base.type===`ordgroup`?e.base.body.length:1,a,o,s;if(i>5)r===`widehat`||r===`widecheck`?(a=420,n=2364,s=.42,o=r+`4`):(a=312,n=2340,s=.34,o=`tilde4`);else{var c=[1,1,2,2,3,3][i];r===`widehat`||r===`widecheck`?(n=[0,1062,2364,2364,2364][c],a=[0,239,300,360,420][c],s=[0,.24,.3,.3,.36,.42][c],o=r+c):(n=[0,600,1033,2339,2340][c],a=[0,260,286,306,312][c],s=[0,.26,.286,.3,.306,.34][c],o=`tilde`+c)}return{span:LW([],[new AU([new jU(o)],{width:`100%`,height:z(s),viewBox:`0 0 `+n+` `+a,preserveAspectRatio:`none`})],t),minWidth:0,height:s}}var l=[],u=UG[r];if(!u)throw Error(`No SVG data for "`+r+`".`);var d=u[0],f=u[1],p=u[2],m=p/1e3,h=d.length,g,_;if(h===1){if(u.length!==4)throw Error(`Expected 4-tuple for single-path SVG data "`+r+`".`);g=[`hide-tail`],_=[u[3]]}else if(h===2)g=[`halfarrow-left`,`halfarrow-right`],_=[`xMinYMin`,`xMaxYMin`];else if(h===3)g=[`brace-left`,`brace-center`,`brace-right`],_=[`xMinYMin`,`xMidYMin`,`xMaxYMin`];else throw Error(`Correct katexImagesData or update code here to support - `+h+` children.`);for(var v=0;v0&&(i.style.minWidth=z(a)),i},KG=function(e,t,n,r,i){var a,o=e.height+e.depth+n+r;if(/fbox|color|angl/.test(t)){if(a=X([`katex-stretchy`,t],[],i),t===`fbox`){var s=i.color&&i.getColor();s&&(a.style.borderColor=s)}}else{var c=[];/^[bx]cancel$/.test(t)&&c.push(new MU({x1:`0`,y1:`0`,x2:`100%`,y2:`100%`,"stroke-width":`0.046em`})),/^x?cancel$/.test(t)&&c.push(new MU({x1:`0`,y1:`100%`,x2:`100%`,y2:`0`,"stroke-width":`0.046em`})),a=LW([],[new AU(c,{width:`100%`,height:z(o)})],i)}return a.height=o,a.style.height=z(o),a},qG=[`bin`,`close`,`inner`,`open`,`punct`,`rel`],JG=[`accent-token`,`mathord`,`op-token`,`spacing`,`textord`],YG=new Set(qG),XG=new Set(JG);function ZG(e){return YG.has(e)}function QG(e,t){if(!e||e.type!==t)throw Error(`Expected node of type `+t+`, but got `+(e?`node of type `+e.type:String(e)));return e}function $G(e){var t=eK(e);if(!t)throw Error(`Expected node of symbol group type, but got `+(e?`node of type `+e.type:String(e)));return t}function eK(e){return e.type===`atom`||XG.has(e.type)?e:null}function tK(e,t,n){var r=``;for(var i of e.body)if(i.type===`textord`)r+=i.text;else if(n&&i.type===`spacing`&&i.text===` `)r+=` `;else throw new L(t,e);return r}var nK=e=>{if(e instanceof kU)return e;if(FU(e)&&e.children.length===1)return nK(e.children[0])},rK=(e,t)=>{var n,r,i;e&&e.type===`supsub`?(r=QG(e.base,`accent`),n=r.base,e.base=n,i=PU(gG(e,t)),e.base=r):(r=QG(e,`accent`),n=r.base);var a=gG(n,t.havingCrampedStyle()),o=r.isShifty&&DH(n),s=0;o&&(s=nK(a)?.skew??0);var c=r.label===`\\c`,l=c?a.height+a.depth:Math.min(a.height,t.fontMetrics().xHeight),u;if(r.isStretchy)u=GG(r,t),u=UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`elem`,elem:u,wrapperClasses:[`svg-align`],wrapperStyle:s>0?{width:`calc(100% - `+z(2*s)+`)`,marginLeft:z(2*s)}:void 0}]});else{var d,f;r.label===`\\vec`?(d=JW(`vec`,t),f=qW.vec[1]):(d=NW({type:`textord`,mode:r.mode,text:r.label},t),d=NU(d),d.italic=0,f=d.width,c&&(l+=d.depth)),u=X([`accent-body`],[d]);var p=r.label===`\\textcircled`;p&&(u.classes.push(`accent-full`),l=a.height);var m=s;p||(m-=f/2),u.style.left=z(m),r.label===`\\textcircled`&&(u.style.top=`.2em`),u=UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:-l},{type:`elem`,elem:u}]})}var h=X([`mord`,`katex-accent`],[u],t);return i?(i.children[0]=h,i.height=Math.max(h.height,i.height),i.classes[0]=`mord`,i):h},iK=(e,t)=>{var n=e.isStretchy?HG(e.label):new Q(`mo`,[wG(e.label,e.mode)]),r=new Q(`mover`,[jG(e.base,t),n]);return r.setAttribute(`accent`,`true`),r},aK=new RegExp([`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`].map(e=>`\\`+e).join(`|`));Z({type:`accent`,names:[`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`,`\\widecheck`,`\\widehat`,`\\widetilde`,`\\overrightarrow`,`\\overleftarrow`,`\\Overrightarrow`,`\\overleftrightarrow`,`\\overgroup`,`\\overlinesegment`,`\\overleftharpoon`,`\\overrightharpoon`],numArgs:1,handler:(e,t)=>{var n=iG(t[0]),r=!aK.test(e.funcName),i=!r||e.funcName===`\\widehat`||e.funcName===`\\widetilde`||e.funcName===`\\widecheck`;return{type:`accent`,mode:e.parser.mode,label:e.funcName,isStretchy:r,isShifty:i,base:n}},htmlBuilder:rK,mathmlBuilder:iK}),Z({type:`accent`,names:[`\\'`,"\\`",`\\^`,`\\~`,`\\=`,`\\u`,`\\.`,`\\"`,`\\c`,`\\r`,`\\H`,`\\v`,`\\textcircled`],numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`primitive`],handler:(e,t)=>{var n=t[0],r=e.parser.mode;return r===`math`&&(e.parser.settings.reportNonstrict(`mathVsTextAccents`,`LaTeX's accent `+e.funcName+` works only in text mode`),r=`text`),{type:`accent`,mode:r,label:e.funcName,isStretchy:!1,isShifty:!0,base:n}}}),Z({type:`accentUnder`,names:[`\\underleftarrow`,`\\underrightarrow`,`\\underleftrightarrow`,`\\undergroup`,`\\underlinesegment`,`\\utilde`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`accentUnder`,mode:n.mode,label:r,base:i}},htmlBuilder:(e,t)=>{var n=gG(e.base,t),r=GG(e,t),i=e.label===`\\utilde`?.12:0;return X([`mord`,`accentunder`],[UW({positionType:`top`,positionData:n.height,children:[{type:`elem`,elem:r,wrapperClasses:[`svg-align`]},{type:`kern`,size:i},{type:`elem`,elem:n}]})],t)},mathmlBuilder:(e,t)=>{var n=HG(e.label),r=new Q(`munder`,[jG(e.base,t),n]);return r.setAttribute(`accentunder`,`true`),r}});var oK=e=>{var t=new Q(`mpadded`,e?[e]:[]);return t.setAttribute(`width`,`+0.6em`),t.setAttribute(`lspace`,`0.3em`),t};Z({type:`xArrow`,names:[`\\xleftarrow`,`\\xrightarrow`,`\\xLeftarrow`,`\\xRightarrow`,`\\xleftrightarrow`,`\\xLeftrightarrow`,`\\xhookleftarrow`,`\\xhookrightarrow`,`\\xmapsto`,`\\xrightharpoondown`,`\\xrightharpoonup`,`\\xleftharpoondown`,`\\xleftharpoonup`,`\\xrightleftharpoons`,`\\xleftrightharpoons`,`\\xlongequal`,`\\xtwoheadrightarrow`,`\\xtwoheadleftarrow`,`\\xtofrom`,`\\xrightleftarrows`,`\\xrightequilibrium`,`\\xleftequilibrium`,`\\\\cdrightarrow`,`\\\\cdleftarrow`,`\\\\cdlongequal`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=e.funcName;return{type:`xArrow`,mode:r.mode,label:i,body:t[0],below:n[0]}},htmlBuilder(e,t){var n=t.style,r=t.havingStyle(n.sup()),i=VW(gG(e.body,r,t),t),a=e.label.slice(0,2)===`\\x`?`x`:`cd`;i.classes.push(a+`-arrow-pad`);var o;e.below&&(r=t.havingStyle(n.sub()),o=VW(gG(e.below,r,t),t),o.classes.push(a+`-arrow-pad`));var s=GG(e,t),c=-t.fontMetrics().axisHeight+.5*s.height,l=-t.fontMetrics().axisHeight-.5*s.height-.111;(i.depth>.25||e.label===`\\xleftequilibrium`)&&(l-=i.depth);var u;if(o){var d=-t.fontMetrics().axisHeight+o.height+.5*s.height+.111;u=UW({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]},{type:`elem`,elem:o,shift:d}]})}else u=UW({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]}]});return X([`mrel`,`x-arrow`],[u],t)},mathmlBuilder(e,t){var n=HG(e.label);n.setAttribute(`minsize`,e.label.charAt(0)===`x`?`1.75em`:`3.0em`);var r;if(e.body){var i=oK(jG(e.body,t));r=e.below?new Q(`munderover`,[n,oK(jG(e.below,t)),i]):new Q(`mover`,[n,i])}else e.below?r=new Q(`munder`,[n,oK(jG(e.below,t))]):(r=oK(),r=new Q(`mover`,[n,r]));return r}});function sK(e,t){var n=uG(e.body,t,!0);return X([e.mclass],n,t)}function cK(e,t){var n,r=kG(e.body,t);return e.mclass===`minner`?n=new Q(`mpadded`,r):e.mclass===`mord`?e.isCharacterBox?(n=r[0],n.type=`mi`):n=new Q(`mi`,r):(e.isCharacterBox?(n=r[0],n.type=`mo`):n=new Q(`mo`,r),e.mclass===`mbin`?(n.attributes.lspace=`0.22em`,n.attributes.rspace=`0.22em`):e.mclass===`mpunct`?(n.attributes.lspace=`0em`,n.attributes.rspace=`0.17em`):(e.mclass===`mopen`||e.mclass===`mclose`)&&(n.attributes.lspace=`0em`,n.attributes.rspace=`0em`)),n}Z({type:`mclass`,names:[`\\mathord`,`\\mathbin`,`\\mathrel`,`\\mathopen`,`\\mathclose`,`\\mathpunct`,`\\mathinner`],numArgs:1,primitive:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`mclass`,mode:n.mode,mclass:`m`+r.slice(5),body:aG(i),isCharacterBox:DH(i)}},htmlBuilder:sK,mathmlBuilder:cK});var lK=e=>{var t=e.type===`ordgroup`&&e.body.length?e.body[0]:e;return t.type===`atom`&&(t.family===`bin`||t.family===`rel`)?`m`+t.family:`mord`};Z({type:`mclass`,names:[`\\@binrel`],numArgs:2,handler(e,t){return{type:`mclass`,mode:e.parser.mode,mclass:lK(t[0]),body:aG(t[1]),isCharacterBox:DH(t[1])}}}),Z({type:`mclass`,names:[`\\stackrel`,`\\overset`,`\\underset`],numArgs:2,handler(e,t){var n=e.parser,r=e.funcName,i=t[1],a=t[0],o=r===`\\stackrel`?`mrel`:lK(i),s={type:`op`,mode:i.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:r!==`\\stackrel`,body:aG(i)},c=r===`\\underset`?{type:`supsub`,mode:a.mode,base:s,sub:a}:{type:`supsub`,mode:a.mode,base:s,sup:a};return{type:`mclass`,mode:n.mode,mclass:o,body:[c],isCharacterBox:DH(c)}}}),Z({type:`pmb`,names:[`\\pmb`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`pmb`,mode:e.parser.mode,mclass:lK(t[0]),body:aG(t[0])}},htmlBuilder(e,t){var n=uG(e.body,t,!0),r=X([e.mclass],n,t);return r.style.textShadow=`0.02em 0.01em 0.04px`,r},mathmlBuilder(e,t){var n=new Q(`mstyle`,kG(e.body,t));return n.setAttribute(`style`,`text-shadow: 0.02em 0.01em 0.04px`),n}});var uK={">":`\\\\cdrightarrow`,"<":`\\\\cdleftarrow`,"=":`\\\\cdlongequal`,A:`\\uparrow`,V:`\\downarrow`,"|":`\\Vert`,".":`no arrow`},dK=()=>({type:`styling`,body:[],mode:`math`,style:`display`,resetFont:!0}),fK=e=>e.type===`textord`&&e.text===`@`,pK=(e,t)=>(e.type===`mathord`||e.type===`atom`)&&e.text===t;function mK(e,t,n){var r=uK[e];switch(r){case`\\\\cdrightarrow`:case`\\\\cdleftarrow`:return n.callFunction(r,[t[0]],[t[1]]);case`\\uparrow`:case`\\downarrow`:var i=n.callFunction(`\\\\cdleft`,[t[0]],[]),a={type:`atom`,text:r,mode:`math`,family:`rel`},o={type:`ordgroup`,mode:`math`,body:[i,n.callFunction(`\\Big`,[a],[]),n.callFunction(`\\\\cdright`,[t[1]],[])]};return n.callFunction(`\\\\cdparent`,[o],[]);case`\\\\cdlongequal`:return n.callFunction(`\\\\cdlongequal`,[],[]);case`\\Vert`:return n.callFunction(`\\Big`,[{type:`textord`,text:`\\Vert`,mode:`math`}],[]);default:return{type:`textord`,text:` `,mode:`math`}}}function hK(e){var t=[];for(e.gullet.beginGroup(),e.gullet.macros.set(`\\cr`,`\\\\\\relax`),e.gullet.beginGroup();;){t.push(e.parseExpression(!1,`\\\\`)),e.gullet.endGroup(),e.gullet.beginGroup();var n=e.fetch().text;if(n===`&`||n===`\\\\`)e.consume();else if(n===`\\end`){t[t.length-1].length===0&&t.pop();break}else throw new L(`Expected \\\\ or \\cr or \\end`,e.nextToken)}for(var r=[],i=[r],a=0;aAV`.includes(l))for(var d=0;d<2;d++){for(var f=!0,p=c+1;pAV=|." after @`,o[c])}var m={type:`styling`,body:[mK(l,u,e)],mode:`math`,style:`display`,resetFont:!0};r.push(m),s=dK()}a%2==0?r.push(s):r.shift(),r=[],i.push(r)}return e.gullet.endGroup(),e.gullet.endGroup(),{type:`array`,mode:`math`,body:i,arraystretch:1,addJot:!0,rowGaps:[null],cols:Array(i[0].length).fill({type:`align`,align:`c`,pregap:.25,postgap:.25}),colSeparationType:`CD`,hLinesBeforeRow:Array(i.length+1).fill([])}}Z({type:`cdlabel`,names:[`\\\\cdleft`,`\\\\cdright`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`cdlabel`,mode:n.mode,side:r.slice(4),label:t[0]}},htmlBuilder(e,t){var n=t.havingStyle(t.style.sup()),r=VW(gG(e.label,n,t),t);return r.classes.push(`cd-label-`+e.side),r.style.bottom=z(.8-r.depth),r.height=0,r.depth=0,r},mathmlBuilder(e,t){var n=new Q(`mrow`,[jG(e.label,t)]);return n=new Q(`mpadded`,[n]),n.setAttribute(`width`,`0`),e.side===`left`&&n.setAttribute(`lspace`,`-1width`),n.setAttribute(`voffset`,`0.7em`),n=new Q(`mstyle`,[n]),n.setAttribute(`displaystyle`,`false`),n.setAttribute(`scriptlevel`,`1`),n}}),Z({type:`cdlabelparent`,names:[`\\\\cdparent`],numArgs:1,handler(e,t){return{type:`cdlabelparent`,mode:e.parser.mode,fragment:t[0]}},htmlBuilder(e,t){var n=VW(gG(e.fragment,t),t);return n.classes.push(`cd-vert-arrow`),n},mathmlBuilder(e,t){return new Q(`mrow`,[jG(e.fragment,t)])}}),Z({type:`textord`,names:[`\\@char`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=tK(QG(t[0],`ordgroup`),`\\@char has non-numeric argument`),i=parseInt(r),a;if(isNaN(i))throw new L(`\\@char has non-numeric argument `+r);if(i<0||i>1114111)throw new L(`\\@char with invalid code point `+r);return i<=65535?a=String.fromCharCode(i):(i-=65536,a=String.fromCharCode((i>>10)+55296,(i&1023)+56320)),{type:`textord`,mode:n.mode,text:a}}}),Z({type:`color`,names:[`\\textcolor`],numArgs:2,allowedInText:!0,argTypes:[`color`,`original`],handler(e,t){var n=e.parser,r=QG(t[0],`color-token`).color,i=t[1];return{type:`color`,mode:n.mode,color:r,body:aG(i)}},htmlBuilder:(e,t)=>BW(uG(e.body,t.withColor(e.color),!1)),mathmlBuilder:(e,t)=>{var n=new Q(`mstyle`,kG(e.body,t.withColor(e.color)));return n.setAttribute(`mathcolor`,e.color),n}}),Z({type:`color`,names:[`\\color`],numArgs:1,allowedInText:!0,argTypes:[`color`],handler(e,t){var n=e.parser,r=e.breakOnTokenText,i=QG(t[0],`color-token`).color;n.gullet.macros.set(`\\current@color`,i);var a=n.parseExpression(!0,r);return{type:`color`,mode:n.mode,color:i,body:a}}}),Z({type:`cr`,names:[`\\\\`],numArgs:0,numOptionalArgs:0,allowedInText:!0,handler(e,t,n){var r=e.parser,i=r.gullet.future().text===`[`?r.parseSizeGroup(!0):null,a=!r.settings.displayMode||!r.settings.useStrictBehavior(`newLineInDisplayMode`,`In LaTeX, \\\\ or \\newline does nothing in display mode`);return{type:`cr`,mode:r.mode,newLine:a,size:i&&QG(i,`size`).value}},htmlBuilder(e,t){var n=X([`mspace`],[],t);return e.newLine&&(n.classes.push(`katex-newline`),e.size&&(n.style.marginTop=z(vU(e.size,t)))),n},mathmlBuilder(e,t){var n=new Q(`mspace`);return e.newLine&&(n.setAttribute(`linebreak`,`newline`),e.size&&n.setAttribute(`height`,z(vU(e.size,t)))),n}});var gK={"\\global":`\\global`,"\\long":`\\\\globallong`,"\\\\globallong":`\\\\globallong`,"\\def":`\\gdef`,"\\gdef":`\\gdef`,"\\edef":`\\xdef`,"\\xdef":`\\xdef`,"\\let":`\\\\globallet`,"\\futurelet":`\\\\globalfuture`},_K=e=>{var t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new L(`Expected a control sequence`,e);return t},vK=e=>{var t=e.gullet.popToken();return t.text===`=`&&(t=e.gullet.popToken(),t.text===` `&&(t=e.gullet.popToken())),t},yK=(e,t,n,r)=>{var i=e.gullet.macros.get(n.text);i??=(n.noexpand=!0,{tokens:[n],numArgs:0,unexpandable:!e.gullet.isExpandable(n.text)}),e.gullet.macros.set(t,i,r)};Z({type:`internal`,names:[`\\global`,`\\long`,`\\\\globallong`],numArgs:0,allowedInText:!0,handler(e){var t=e.parser,n=e.funcName;t.consumeSpaces();var r=t.fetch();if(gK[r.text])return(n===`\\global`||n===`\\\\globallong`)&&(r.text=gK[r.text]),QG(t.parseFunction(),`internal`);throw new L(`Invalid token after macro prefix`,r)}}),Z({type:`internal`,names:[`\\def`,`\\gdef`,`\\edef`,`\\xdef`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=t.gullet.popToken(),i=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(i))throw new L(`Expected a control sequence`,r);for(var a=0,o,s=[[]];t.gullet.future().text!==`{`;)if(r=t.gullet.popToken(),r.text===`#`){if(t.gullet.future().text===`{`){o=t.gullet.future(),s[a].push(`{`);break}if(r=t.gullet.popToken(),!/^[1-9]$/.test(r.text))throw new L(`Invalid argument number "`+r.text+`"`);if(parseInt(r.text)!==a+1)throw new L(`Argument number "`+r.text+`" out of order`);a++,s.push([])}else if(r.text===`EOF`)throw new L(`Expected a macro definition`);else s[a].push(r.text);var c=t.gullet.consumeArg().tokens;return o&&c.unshift(o),(n===`\\edef`||n===`\\xdef`)&&(c=t.gullet.expandTokens(c),c.reverse()),t.gullet.macros.set(i,{tokens:c,numArgs:a,delimiters:s},n===gK[n]),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\let`,`\\\\globallet`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=_K(t.gullet.popToken());return t.gullet.consumeSpaces(),yK(t,r,vK(t),n===`\\\\globallet`),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\futurelet`,`\\\\globalfuture`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=_K(t.gullet.popToken()),i=t.gullet.popToken(),a=t.gullet.popToken();return yK(t,r,a,n===`\\\\globalfuture`),t.gullet.pushToken(a),t.gullet.pushToken(i),{type:`internal`,mode:t.mode}}});var bK=function(e,t,n){var r=BU(UU.math[e]&&UU.math[e].replace||e,t,n);if(!r)throw Error(`Unsupported symbol `+e+` and font size `+t+`.`);return r},xK=function(e,t,n,r){var i=n.havingBaseStyle(t),a=X(r.concat(i.sizingClasses(n)),[e],n),o=i.sizeMultiplier/n.sizeMultiplier;return a.height*=o,a.depth*=o,a.maxFontSize=i.sizeMultiplier,a},SK=function(e,t,n){var r=t.havingBaseStyle(n),i=(1-t.sizeMultiplier/r.sizeMultiplier)*t.fontMetrics().axisHeight;e.classes.push(`delimcenter`),e.style.top=z(i),e.height-=i,e.depth+=i},CK=function(e,t,n,r,i,a){var o=xK(AW(e,`Main-Regular`,i,r),t,r,a);return n&&SK(o,r,t),o},wK=function(e,t,n,r){return AW(e,`Size`+t+`-Regular`,n,r)},TK=function(e,t,n,r,i,a){var o=wK(e,t,i,r),s=xK(X([`delimsizing`,`size`+t],[o],r),R.TEXT,r,a);return n&&SK(s,r,R.TEXT),s},EK=function(e,t,n){return{type:`elem`,elem:X([`delimsizinginner`,t===`Size1-Regular`?`delim-size1`:`delim-size4`],[X([],[AW(e,t,n)])])}},DK=function(e,t,n){var r=IU[`Size4-Regular`][e.charCodeAt(0)]?IU[`Size4-Regular`][e.charCodeAt(0)][4]:IU[`Size1-Regular`][e.charCodeAt(0)][4],i=LW([],[new AU([new jU(`inner`,uU(e,Math.round(1e3*t)))],{width:z(r),height:z(t),style:`width:`+z(r),viewBox:`0 0 `+1e3*r+` `+Math.round(1e3*t),preserveAspectRatio:`xMinYMin`})],n);return i.height=t,i.style.height=z(t),i.style.width=z(r),{type:`elem`,elem:i}},OK=.008,kK={type:`kern`,size:-1*OK},AK=new Set([`|`,`\\lvert`,`\\rvert`,`\\vert`]),jK=new Set([`\\|`,`\\lVert`,`\\rVert`,`\\Vert`]),MK=function(e,t,n,r,i,a){var o,s,c,l,u=``,d=0;o=c=l=e,s=null;var f=`Size1-Regular`;e===`\\uparrow`?c=l=`⏐`:e===`\\Uparrow`?c=l=`‖`:e===`\\downarrow`?o=c=`⏐`:e===`\\Downarrow`?o=c=`‖`:e===`\\updownarrow`?(o=`\\uparrow`,c=`⏐`,l=`\\downarrow`):e===`\\Updownarrow`?(o=`\\Uparrow`,c=`‖`,l=`\\Downarrow`):AK.has(e)?(c=`∣`,u=`vert`,d=333):jK.has(e)?(c=`∥`,u=`doublevert`,d=556):e===`[`||e===`\\lbrack`?(o=`⎡`,c=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lbrack`,d=667):e===`]`||e===`\\rbrack`?(o=`⎤`,c=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rbrack`,d=667):e===`\\lfloor`||e===`⌊`?(c=o=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lfloor`,d=667):e===`\\lceil`||e===`⌈`?(o=`⎡`,c=l=`⎢`,f=`Size4-Regular`,u=`lceil`,d=667):e===`\\rfloor`||e===`⌋`?(c=o=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rfloor`,d=667):e===`\\rceil`||e===`⌉`?(o=`⎤`,c=l=`⎥`,f=`Size4-Regular`,u=`rceil`,d=667):e===`(`||e===`\\lparen`?(o=`⎛`,c=`⎜`,l=`⎝`,f=`Size4-Regular`,u=`lparen`,d=875):e===`)`||e===`\\rparen`?(o=`⎞`,c=`⎟`,l=`⎠`,f=`Size4-Regular`,u=`rparen`,d=875):e===`\\{`||e===`\\lbrace`?(o=`⎧`,s=`⎨`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\}`||e===`\\rbrace`?(o=`⎫`,s=`⎬`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lgroup`||e===`⟮`?(o=`⎧`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\rgroup`||e===`⟯`?(o=`⎫`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lmoustache`||e===`⎰`?(o=`⎧`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):(e===`\\rmoustache`||e===`⎱`)&&(o=`⎫`,l=`⎩`,c=`⎪`,f=`Size4-Regular`);var p=bK(o,f,i),m=p.height+p.depth,h=bK(c,f,i),g=h.height+h.depth,_=bK(l,f,i),v=_.height+_.depth,y=0,b=1;if(s!==null){var x=bK(s,f,i);y=x.height+x.depth,b=2}var S=m+v+y,C=S+Math.max(0,Math.ceil((t-S)/(b*g)))*b*g,ee=r.fontMetrics().axisHeight;n&&(ee*=r.sizeMultiplier);var te=C/2-ee,ne=[];if(u.length>0){var re=C-m-v,ie=Math.round(C*1e3),ae=fU(u,Math.round(re*1e3)),oe=new jU(u,ae),se=z(d/1e3),ce=z(ie/1e3),le=LW([],[new AU([oe],{width:se,height:ce,viewBox:`0 0 `+d+` `+ie})],r);le.height=ie/1e3,le.style.width=se,le.style.height=ce,ne.push({type:`elem`,elem:le})}else{if(ne.push(EK(l,f,i)),ne.push(kK),s===null){var ue=C-m-v+2*OK;ne.push(DK(c,ue,r))}else{var de=(C-m-v-y)/2+2*OK;ne.push(DK(c,de,r)),ne.push(kK),ne.push(EK(s,f,i)),ne.push(kK),ne.push(DK(c,de,r))}ne.push(kK),ne.push(EK(o,f,i))}var fe=r.havingBaseStyle(R.TEXT);return xK(X([`delimsizing`,`mult`],[UW({positionType:`bottom`,positionData:te,children:ne})],fe),R.TEXT,r,a)},NK=80,PK=.08,FK=function(e,t,n,r,i){return LW([`hide-tail`],[new AU([new jU(e,lU(e,r,n))],{width:`400em`,height:z(t),viewBox:`0 0 400000 `+n,preserveAspectRatio:`xMinYMin slice`})],i)},IK=function(e,t){var n=t.havingBaseSizing(),r=KK(`\\surd`,e*n.sizeMultiplier,WK,n),i=n.sizeMultiplier,a=Math.max(0,t.minRuleThickness-t.fontMetrics().sqrtRuleThickness),o,s,c,l,u;return r.type===`small`?(l=1e3+1e3*a+NK,e<1?i=1:e<1.4&&(i=.7),s=(1+a+PK)/i,c=(1+a)/i,o=FK(`sqrtMain`,s,l,a,t),o.style.minWidth=`0.853em`,u=.833/i):r.type===`large`?(l=(1e3+NK)*BK[r.size],c=(BK[r.size]+a)/i,s=(BK[r.size]+a+PK)/i,o=FK(`sqrtSize`+r.size,s,l,a,t),o.style.minWidth=`1.02em`,u=1/i):(s=e+a+PK,c=e+a,l=Math.floor(1e3*e+a)+NK,o=FK(`sqrtTall`,s,l,a,t),o.style.minWidth=`0.742em`,u=1.056),o.height=c,o.style.height=z(s),{span:o,advanceWidth:u,ruleWidth:(t.fontMetrics().sqrtRuleThickness+a)*i}},LK=new Set([`(`,`\\lparen`,`)`,`\\rparen`,`[`,`\\lbrack`,`]`,`\\rbrack`,`\\{`,`\\lbrace`,`\\}`,`\\rbrace`,`\\lfloor`,`\\rfloor`,`⌊`,`⌋`,`\\lceil`,`\\rceil`,`⌈`,`⌉`,`\\surd`]),RK=new Set([`\\uparrow`,`\\downarrow`,`\\updownarrow`,`\\Uparrow`,`\\Downarrow`,`\\Updownarrow`,`|`,`\\|`,`\\vert`,`\\Vert`,`\\lvert`,`\\rvert`,`\\lVert`,`\\rVert`,`\\lgroup`,`\\rgroup`,`⟮`,`⟯`,`\\lmoustache`,`\\rmoustache`,`⎰`,`⎱`]),zK=new Set([`<`,`>`,`\\langle`,`\\rangle`,`/`,`\\backslash`,`\\lt`,`\\gt`]),BK=[0,1.2,1.8,2.4,3],VK=function(e,t,n,r,i){if(e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`),LK.has(e)||zK.has(e))return TK(e,t,!1,n,r,i);if(RK.has(e))return MK(e,BK[t],!1,n,r,i);throw new L(`Illegal delimiter: '`+e+`'`)},HK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4}],UK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`stack`}],WK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4},{type:`stack`}],GK=function(e){if(e.type===`small`)return`Main-Regular`;if(e.type===`large`)return`Size`+e.size+`-Regular`;if(e.type===`stack`)return`Size4-Regular`;var t=e.type;throw Error(`Add support for delim type '`+t+`' here.`)},KK=function(e,t,n,r){for(var i=Math.min(2,3-r.style.size);it)return a}return n[n.length-1]},qK=function(e,t,n,r,i,a){e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`);var o=zK.has(e)?HK:LK.has(e)?WK:UK,s=KK(e,t,o,r);return s.type===`small`?CK(e,s.style,n,r,i,a):s.type===`large`?TK(e,s.size,n,r,i,a):MK(e,t,n,r,i,a)},JK=function(e,t,n,r,i,a){var o=r.fontMetrics().axisHeight*r.sizeMultiplier,s=901,c=5/r.fontMetrics().ptPerEm,l=Math.max(t-o,n+o);return qK(e,Math.max(l/500*s,2*l-c),!0,r,i,a)},YK={"\\bigl":{mclass:`mopen`,size:1},"\\Bigl":{mclass:`mopen`,size:2},"\\biggl":{mclass:`mopen`,size:3},"\\Biggl":{mclass:`mopen`,size:4},"\\bigr":{mclass:`mclose`,size:1},"\\Bigr":{mclass:`mclose`,size:2},"\\biggr":{mclass:`mclose`,size:3},"\\Biggr":{mclass:`mclose`,size:4},"\\bigm":{mclass:`mrel`,size:1},"\\Bigm":{mclass:`mrel`,size:2},"\\biggm":{mclass:`mrel`,size:3},"\\Biggm":{mclass:`mrel`,size:4},"\\big":{mclass:`mord`,size:1},"\\Big":{mclass:`mord`,size:2},"\\bigg":{mclass:`mord`,size:3},"\\Bigg":{mclass:`mord`,size:4}},XK=new Set(`(,\\lparen,),\\rparen,[,\\lbrack,],\\rbrack,\\{,\\lbrace,\\},\\rbrace,\\lfloor,\\rfloor,⌊,⌋,\\lceil,\\rceil,⌈,⌉,<,>,\\langle,⟨,\\rangle,⟩,\\lt,\\gt,\\lvert,\\rvert,\\lVert,\\rVert,\\lgroup,\\rgroup,⟮,⟯,\\lmoustache,\\rmoustache,⎰,⎱,/,\\backslash,|,\\vert,\\|,\\Vert,\\uparrow,\\Uparrow,\\downarrow,\\Downarrow,\\updownarrow,\\Updownarrow,.`.split(`,`));function ZK(e){return`isMiddle`in e}function QK(e,t){var n=eK(e);if(n&&XK.has(n.text))return n;throw n?new L(`Invalid delimiter '`+n.text+`' after '`+t.funcName+`'`,e):new L(`Invalid delimiter type '`+e.type+`'`,e)}Z({type:`delimsizing`,names:[`\\bigl`,`\\Bigl`,`\\biggl`,`\\Biggl`,`\\bigr`,`\\Bigr`,`\\biggr`,`\\Biggr`,`\\bigm`,`\\Bigm`,`\\biggm`,`\\Biggm`,`\\big`,`\\Big`,`\\bigg`,`\\Bigg`],numArgs:1,argTypes:[`primitive`],handler:(e,t)=>{var n=QK(iG(t[0]),e);return{type:`delimsizing`,mode:e.parser.mode,size:YK[e.funcName].size,mclass:YK[e.funcName].mclass,delim:n.text}},htmlBuilder:(e,t)=>e.delim===`.`?X([e.mclass]):VK(e.delim,e.size,t,e.mode,[e.mclass]),mathmlBuilder:e=>{var t=[];e.delim!==`.`&&t.push(wG(e.delim,e.mode));var n=new Q(`mo`,t);e.mclass===`mopen`||e.mclass===`mclose`?n.setAttribute(`fence`,`true`):n.setAttribute(`fence`,`false`),n.setAttribute(`stretchy`,`true`);var r=z(BK[e.size]);return n.setAttribute(`minsize`,r),n.setAttribute(`maxsize`,r),n}});function $K(e){if(!e.body)throw Error(`Bug: The leftright ParseNode wasn't fully parsed.`)}Z({type:`leftright-right`,names:[`\\right`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser.gullet.macros.get(`\\current@color`);if(n&&typeof n!=`string`)throw new L(`\\current@color set to non-string in \\right`);return{type:`leftright-right`,mode:e.parser.mode,delim:QK(t[0],e).text,color:n}}}),Z({type:`leftright`,names:[`\\left`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=QK(t[0],e),r=e.parser;++r.leftrightDepth;var i=r.parseExpression(!1);--r.leftrightDepth,r.expect(`\\right`,!1);var a=QG(r.parseFunction(),`leftright-right`);return{type:`leftright`,mode:r.mode,body:i,left:n.text,right:a.delim,rightColor:a.color}},htmlBuilder:(e,t)=>{$K(e);for(var n=uG(e.body,t,!0,[`mopen`,`mclose`]),r=0,i=0,a=!1,o=0;o{$K(e);var n=kG(e.body,t);if(e.left!==`.`){var r=new Q(`mo`,[wG(e.left,e.mode)]);r.setAttribute(`fence`,`true`),n.unshift(r)}if(e.right!==`.`){var i=new Q(`mo`,[wG(e.right,e.mode)]);i.setAttribute(`fence`,`true`),e.rightColor&&i.setAttribute(`mathcolor`,e.rightColor),n.push(i)}return TG(n)}}),Z({type:`middle`,names:[`\\middle`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=QK(t[0],e);if(!e.parser.leftrightDepth)throw new L(`\\middle without preceding \\left`,n);return{type:`middle`,mode:e.parser.mode,delim:n.text}},htmlBuilder:(e,t)=>{var n;return e.delim===`.`?n=hG(t,[]):(n=VK(e.delim,1,t,e.mode,[]),n.isMiddle={delim:e.delim,options:t}),n},mathmlBuilder:(e,t)=>{var n=new Q(`mo`,[e.delim===`\\vert`||e.delim===`|`?wG(`|`,`text`):wG(e.delim,e.mode)]);return n.setAttribute(`fence`,`true`),n.setAttribute(`lspace`,`0.05em`),n.setAttribute(`rspace`,`0.05em`),n}}),Z({type:`enclose`,names:[`\\colorbox`],numArgs:2,allowedInText:!0,argTypes:[`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=QG(t[0],`color-token`).color,o=t[1];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:a,body:o}},htmlBuilder:(e,t)=>{var n=VW(gG(e.body,t),t),r=e.label.slice(1),i=t.sizeMultiplier,a,o,s=DH(e.body);if(r===`sout`)a=X([`katex-stretchy`,`katex-sout`]),a.height=t.fontMetrics().defaultRuleThickness/i,o=-.5*t.fontMetrics().xHeight;else if(r===`phase`){var c=vU({number:.6,unit:`pt`},t),l=vU({number:.35,unit:`ex`},t),u=t.havingBaseSizing();i/=u.sizeMultiplier;var d=n.height+n.depth+c+l;n.style.paddingLeft=z(d/2+c);var f=Math.floor(1e3*d*i);a=LW([`hide-tail`],[new AU([new jU(`phase`,sU(f))],{width:`400em`,height:z(f/1e3),viewBox:`0 0 400000 `+f,preserveAspectRatio:`xMinYMin slice`})],t),a.style.height=z(d),o=n.depth+c+l}else{/cancel/.test(r)?s||n.classes.push(`cancel-pad`):r===`angl`?n.classes.push(`anglpad`):n.classes.push(`boxpad`);var p,m,h=0;/box/.test(r)?(h=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness),p=t.fontMetrics().fboxsep+(r===`colorbox`?0:h),m=p):r===`angl`?(h=Math.max(t.fontMetrics().defaultRuleThickness,t.minRuleThickness),p=4*h,m=Math.max(0,.25-n.depth)):(p=s?.2:0,m=p),a=KG(n,r,p,m,t),/fbox|boxed|fcolorbox/.test(r)?(a.style.borderStyle=`solid`,a.style.borderWidth=z(h)):r===`angl`&&h!==.049&&(a.style.borderTopWidth=z(h),a.style.borderRightWidth=z(h)),o=n.depth+m,e.backgroundColor&&(a.style.backgroundColor=e.backgroundColor,e.borderColor&&(a.style.borderColor=e.borderColor))}var g;if(e.backgroundColor)g=UW({positionType:`individualShift`,children:[{type:`elem`,elem:a,shift:o},{type:`elem`,elem:n,shift:0}]});else{var _=/cancel|phase/.test(r)?[`svg-align`]:[];g=UW({positionType:`individualShift`,children:[{type:`elem`,elem:n,shift:0},{type:`elem`,elem:a,shift:o,wrapperClasses:_}]})}return/cancel/.test(r)&&(g.height=n.height,g.depth=n.depth),/cancel/.test(r)&&!s?X([`mord`,`cancel-lap`],[g],t):X([`mord`],[g],t)},mathmlBuilder:(e,t)=>{var n,r=new Q(e.label.includes(`colorbox`)?`mpadded`:`menclose`,[jG(e.body,t)]);switch(e.label){case`\\cancel`:r.setAttribute(`notation`,`updiagonalstrike`);break;case`\\bcancel`:r.setAttribute(`notation`,`downdiagonalstrike`);break;case`\\phase`:r.setAttribute(`notation`,`phasorangle`);break;case`\\sout`:r.setAttribute(`notation`,`horizontalstrike`);break;case`\\fbox`:r.setAttribute(`notation`,`box`);break;case`\\angl`:r.setAttribute(`notation`,`actuarial`);break;case`\\fcolorbox`:case`\\colorbox`:if(n=t.fontMetrics().fboxsep*t.fontMetrics().ptPerEm,r.setAttribute(`width`,`+`+2*n+`pt`),r.setAttribute(`height`,`+`+2*n+`pt`),r.setAttribute(`lspace`,n+`pt`),r.setAttribute(`voffset`,n+`pt`),e.label===`\\fcolorbox`){var i=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness);r.setAttribute(`style`,`border: `+z(i)+` solid `+e.borderColor)}break;case`\\xcancel`:r.setAttribute(`notation`,`updiagonalstrike downdiagonalstrike`)}return e.backgroundColor&&r.setAttribute(`mathbackground`,e.backgroundColor),r}}),Z({type:`enclose`,names:[`\\fcolorbox`],numArgs:3,allowedInText:!0,argTypes:[`color`,`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=QG(t[0],`color-token`).color,o=QG(t[1],`color-token`).color,s=t[2];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:o,borderColor:a,body:s}}}),Z({type:`enclose`,names:[`\\fbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\fbox`,body:t[0]}}}),Z({type:`enclose`,names:[`\\cancel`,`\\bcancel`,`\\xcancel`,`\\phase`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\sout`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName;n.mode===`math`&&n.settings.reportNonstrict(`mathVsSout`,`LaTeX's \\sout works only in text mode`);var i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\angl`],numArgs:1,argTypes:[`hbox`],allowedInText:!1,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\angl`,body:t[0]}}});var eq={};function tq(e){for(var t=e.type,n=e.names,r=e.props,i=e.handler,a=e.htmlBuilder,o=e.mathmlBuilder,s={type:t,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:i},c=0;c{if(!e.parser.settings.displayMode)throw new L(`{`+e.envName+`} can be used only in display mode.`)},sq=new Set([`gather`,`gather*`]);function cq(e){if(!e.includes(`ed`))return!e.includes(`*`)}function lq(e,t,n){var r=t.hskipBeforeAndAfter,i=t.addJot,a=t.cols,o=t.arraystretch,s=t.colSeparationType,c=t.autoTag,l=t.singleRow,u=t.emptySingleRow,d=t.maxNumCols,f=t.leqno;if(e.gullet.beginGroup(),l||e.gullet.macros.set(`\\cr`,`\\\\\\relax`),!o){var p=e.gullet.expandMacroAsText(`\\arraystretch`);if(p==null)o=1;else if(o=parseFloat(p),!o||o<0)throw new L(`Invalid \\arraystretch: `+p)}e.gullet.beginGroup();var m=[],h=[m],g=[],_=[],v=c==null?void 0:[];function y(){c&&e.gullet.macros.set(`\\@eqnsw`,`1`,!0)}function b(){v&&(e.gullet.macros.get(`\\df@tag`)?(v.push(e.subparse([new iq(`\\df@tag`)])),e.gullet.macros.set(`\\df@tag`,void 0,!0)):v.push(!!c&&e.gullet.macros.get(`\\@eqnsw`)===`1`))}for(y(),_.push(aq(e));;){var x=e.parseExpression(!1,l?`\\end`:`\\\\`);e.gullet.endGroup(),e.gullet.beginGroup();var S={type:`ordgroup`,mode:e.mode,body:x};n&&(S={type:`styling`,mode:e.mode,style:n,resetFont:!0,body:[S]}),m.push(S);var C=e.fetch().text;if(C===`&`){if(d&&m.length===d){if(l||s)throw new L(`Too many tab characters: &`,e.nextToken);e.settings.reportNonstrict(`textEnv`,`Too few columns specified in the {array} column argument.`)}e.consume()}else if(C===`\\end`){b(),m.length===1&&S.type===`styling`&&S.body.length===1&&S.body[0].type===`ordgroup`&&S.body[0].body.length===0&&(h.length>1||!u)&&!Array.isArray(v?.[v.length-1])&&!(c&&v?.[v.length-1]===!0)&&h.pop(),_.length0&&(_+=.25),c.push({pos:_,isDashed:e[t]})}for(v(a[0]),n=0;n0&&(te+=g,xe))for(n=0;n=o)){var ve=void 0;(r>0||e.hskipBeforeAndAfter)&&(ve=fe?.pregap??d,ve!==0&&(ae=X([`arraycolsep`],[]),ae.style.width=z(ve),ie.push(ae)));var ye=[];for(n=0;n0){for(var Ee=RW(`katex-hline`,t,l),De=RW(`katex-hdashline`,t,l),Oe=[{type:`elem`,elem:Te,shift:0}];c.length>0;){var ke=c.pop(),Ae=ke.pos-ne;ke.isDashed?Oe.push({type:`elem`,elem:De,shift:Ae}):Oe.push({type:`elem`,elem:Ee,shift:Ae})}Te=UW({positionType:`individualShift`,children:Oe})}if(se.length===0)return X([`mord`],[Te],t);var je=X([`katex-tag`],[UW({positionType:`individualShift`,children:se})],t);return BW([Te,je])},fq={c:`center `,l:`left `,r:`right `},pq=function(e,t){for(var n=[],r=new Q(`mtd`,[],[`mtr-glue`]),i=new Q(`mtd`,[],[`mml-eqn-num`]),a=0;a0){var p=e.cols,m=``,h=!1,g=0,_=p.length;p[0].type===`separator`&&(d+=`top `,g=1),p[p.length-1].type===`separator`&&(d+=`bottom `,--_);for(var v=g;v<_;v++){var y=p[v];y.type===`align`?(f+=fq[y.align],h&&(m+=`none `),h=!0):y.type===`separator`&&(h&&=(m+=y.separator===`|`?`solid `:`dashed `,!1))}l.setAttribute(`columnalign`,f.trim()),/[sd]/.test(m)&&l.setAttribute(`columnlines`,m.trim())}if(e.colSeparationType===`align`){for(var b=e.cols||[],x=``,S=1;S0?`left `:``,d+=ee[ee.length-1].length>0?`right `:``;for(var te=1;te0&&u&&(p=1),n[d]={type:`align`,align:f,pregap:p,postgap:0}}return i.colSeparationType=u?`align`:`alignat`,i};tq({type:`array`,names:[`array`,`darray`],props:{numArgs:1},handler(e,t){var n=(eK(t[0])?[t[0]]:QG(t[0],`ordgroup`).body).map(function(e){var t=$G(e).text;if(`lcr`.includes(t))return{type:`align`,align:t};if(t===`|`)return{type:`separator`,separator:`|`};if(t===`:`)return{type:`separator`,separator:`:`};throw new L(`Unknown column alignment: `+t,e)}),r={cols:n,hskipBeforeAndAfter:!0,maxNumCols:n.length};return lq(e.parser,r,uq(e.envName))},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`matrix`,`pmatrix`,`bmatrix`,`Bmatrix`,`vmatrix`,`Vmatrix`,`matrix*`,`pmatrix*`,`bmatrix*`,`Bmatrix*`,`vmatrix*`,`Vmatrix*`],props:{numArgs:0},handler(e){var t={matrix:null,pmatrix:[`(`,`)`],bmatrix:[`[`,`]`],Bmatrix:[`\\{`,`\\}`],vmatrix:[`|`,`|`],Vmatrix:[`\\Vert`,`\\Vert`]}[e.envName.replace(`*`,``)],n=`c`,r={hskipBeforeAndAfter:!1,cols:[{type:`align`,align:n}]};if(e.envName.charAt(e.envName.length-1)===`*`){var i=e.parser;if(i.consumeSpaces(),i.fetch().text===`[`){if(i.consume(),i.consumeSpaces(),n=i.fetch().text,!`lcr`.includes(n))throw new L(`Expected l or c or r`,i.nextToken);i.consume(),i.consumeSpaces(),i.expect(`]`),i.consume(),r.cols=[{type:`align`,align:n}]}}var a=lq(e.parser,r,uq(e.envName)),o=Math.max(0,...a.body.map(e=>e.length));return a.cols=Array(o).fill({type:`align`,align:n}),t?{type:`leftright`,mode:e.mode,body:[a],left:t[0],right:t[1],rightColor:void 0}:a},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`smallmatrix`],props:{numArgs:0},handler(e){var t=lq(e.parser,{arraystretch:.5},`script`);return t.colSeparationType=`small`,t},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`subarray`],props:{numArgs:1},handler(e,t){var n=(eK(t[0])?[t[0]]:QG(t[0],`ordgroup`).body).map(function(e){var t=$G(e).text;if(`lc`.includes(t))return{type:`align`,align:t};throw new L(`Unknown column alignment: `+t,e)});if(n.length>1)throw new L(`{subarray} can contain only one column`);var r={cols:n,hskipBeforeAndAfter:!1,arraystretch:.5},i=lq(e.parser,r,`script`);if(i.body.length>0&&i.body[0].length>1)throw new L(`{subarray} can contain only one column`);return i},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`cases`,`dcases`,`rcases`,`drcases`],props:{numArgs:0},handler(e){var t=lq(e.parser,{arraystretch:1.2,cols:[{type:`align`,align:`l`,pregap:0,postgap:1},{type:`align`,align:`l`,pregap:0,postgap:0}]},uq(e.envName));return{type:`leftright`,mode:e.mode,body:[t],left:e.envName.includes(`r`)?`.`:`\\{`,right:e.envName.includes(`r`)?`\\}`:`.`,rightColor:void 0}},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`align`,`align*`,`aligned`,`split`],props:{numArgs:0},handler:mq,htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`gathered`,`gather`,`gather*`],props:{numArgs:0},handler(e){sq.has(e.envName)&&oq(e);var t={cols:[{type:`align`,align:`c`}],addJot:!0,colSeparationType:`gather`,autoTag:cq(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return lq(e.parser,t,`display`)},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`alignat`,`alignat*`,`alignedat`],props:{numArgs:1},handler:mq,htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`equation`,`equation*`],props:{numArgs:0},handler(e){oq(e);var t={autoTag:cq(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,leqno:e.parser.settings.leqno};return lq(e.parser,t,`display`)},htmlBuilder:dq,mathmlBuilder:pq}),tq({type:`array`,names:[`CD`],props:{numArgs:0},handler(e){return oq(e),hK(e.parser)},htmlBuilder:dq,mathmlBuilder:pq}),$(`\\nonumber`,`\\gdef\\@eqnsw{0}`),$(`\\notag`,`\\nonumber`),Z({type:`text`,names:[`\\hline`,`\\hdashline`],numArgs:0,allowedInText:!0,allowedInMath:!0,handler(e,t){throw new L(e.funcName+` valid only within array environment`)}});var hq=eq;Z({type:`environment`,names:[`\\begin`,`\\end`],numArgs:1,argTypes:[`text`],handler(e,t){var n=e.parser,r=e.funcName,i=t[0];if(i.type!==`ordgroup`)throw new L(`Invalid environment name`,i);var a=tK(i,`Environment name should contain only text characters and spaces`,!0);if(r===`\\begin`){if(!Object.prototype.hasOwnProperty.call(hq,a))throw new L(`No such environment: `+a,i);var o=hq[a],s=n.parseArguments(`\\begin{`+a+`}`,o),c=s.args,l=s.optArgs,u={mode:n.mode,envName:a,parser:n},d=o.handler(u,c,l);n.expect(`\\end`,!1);var f=n.nextToken,p=QG(n.parseFunction(),`environment`);if(p.name!==a)throw new L(`Mismatch: \\begin{`+a+`} matched by \\end{`+p.name+`}`,f);return d}return{type:`environment`,mode:n.mode,name:a,nameGroup:i}}});var gq=(e,t)=>{var n=e.font,r=t.withFont(n);return gG(e.body,r)},_q=(e,t)=>{var n=e.font,r=t.withFont(n);return jG(e.body,r)},vq={"\\Bbb":`\\mathbb`,"\\bold":`\\mathbf`,"\\frak":`\\mathfrak`};Z({type:`font`,names:[`\\mathrm`,`\\mathit`,`\\mathbf`,`\\mathnormal`,`\\mathsfit`,`\\mathbb`,`\\mathcal`,`\\mathfrak`,`\\mathscr`,`\\mathsf`,`\\mathtt`,`\\Bbb`,`\\bold`,`\\frak`],numArgs:1,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=iG(t[0]),a=r in vq?vq[r]:r;return{type:`font`,mode:n.mode,font:a.slice(1),body:i}},htmlBuilder:gq,mathmlBuilder:_q}),Z({type:`mclass`,names:[`\\boldsymbol`,`\\bm`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`mclass`,mode:n.mode,mclass:lK(r),body:[{type:`font`,mode:n.mode,font:`boldsymbol`,body:r}],isCharacterBox:DH(r)}}}),Z({type:`font`,names:[`\\rm`,`\\sf`,`\\tt`,`\\bf`,`\\it`,`\\cal`],numArgs:0,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=e.breakOnTokenText,a=n.mode,o=n.parseExpression(!0,i);return{type:`font`,mode:a,font:`math`+r.slice(1),body:{type:`ordgroup`,mode:n.mode,body:o}}}});var yq=(e,t)=>{var n=t.style,r=n.fracNum(),i=n.fracDen(),a=t.havingStyle(r),o=gG(e.numer,a,t);if(e.continued){var s=8.5/t.fontMetrics().ptPerEm,c=3.5/t.fontMetrics().ptPerEm;o.height=o.height0?3*f:7*f,h=t.fontMetrics().denom1):(d>0?(p=t.fontMetrics().num2,m=f):(p=t.fontMetrics().num3,m=3*f),h=t.fontMetrics().denom2);var g;if(u){var _=t.fontMetrics().axisHeight;p-o.depth-(_+.5*d){var n=new Q(`mfrac`,[jG(e.numer,t),jG(e.denom,t)]);if(!e.hasBarLine)n.setAttribute(`linethickness`,`0px`);else if(e.barSize){var r=vU(e.barSize,t);n.setAttribute(`linethickness`,z(r))}if(e.leftDelim!=null||e.rightDelim!=null){var i=[];if(e.leftDelim!=null){var a=new Q(`mo`,[new bG(e.leftDelim.replace(`\\`,``))]);a.setAttribute(`fence`,`true`),i.push(a)}if(i.push(n),e.rightDelim!=null){var o=new Q(`mo`,[new bG(e.rightDelim.replace(`\\`,``))]);o.setAttribute(`fence`,`true`),i.push(o)}return TG(i)}return n},xq=(e,t)=>t?{type:`styling`,mode:e.mode,style:t,body:[e]}:e;Z({type:`genfrac`,names:[`\\cfrac`,`\\dfrac`,`\\frac`,`\\tfrac`,`\\dbinom`,`\\binom`,`\\tbinom`,`\\\\atopfrac`,`\\\\bracefrac`,`\\\\brackfrac`],numArgs:2,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0],a=t[1],o,s=null,c=null;switch(r){case`\\cfrac`:case`\\dfrac`:case`\\frac`:case`\\tfrac`:o=!0;break;case`\\\\atopfrac`:o=!1;break;case`\\dbinom`:case`\\binom`:case`\\tbinom`:o=!1,s=`(`,c=`)`;break;case`\\\\bracefrac`:o=!1,s=`\\{`,c=`\\}`;break;case`\\\\brackfrac`:o=!1,s=`[`,c=`]`;break;default:throw Error(`Unrecognized genfrac command`)}var l=r===`\\cfrac`,u=null;return l||r.startsWith(`\\d`)?u=`display`:r.startsWith(`\\t`)&&(u=`text`),xq({type:`genfrac`,mode:n.mode,numer:i,denom:a,continued:l,hasBarLine:o,leftDelim:s,rightDelim:c,barSize:null},u)},htmlBuilder:yq,mathmlBuilder:bq}),Z({type:`infix`,names:[`\\over`,`\\choose`,`\\atop`,`\\brace`,`\\brack`],numArgs:0,infix:!0,handler(e){var t=e.parser,n=e.funcName,r=e.token,i;switch(n){case`\\over`:i=`\\frac`;break;case`\\choose`:i=`\\binom`;break;case`\\atop`:i=`\\\\atopfrac`;break;case`\\brace`:i=`\\\\bracefrac`;break;case`\\brack`:i=`\\\\brackfrac`;break;default:throw Error(`Unrecognized infix genfrac command`)}return{type:`infix`,mode:t.mode,replaceWith:i,token:r}}});var Sq=[`display`,`text`,`script`,`scriptscript`],Cq=function(e){var t=null;return e.length>0&&(t=e,t=t===`.`?null:t),t};Z({type:`genfrac`,names:[`\\genfrac`],numArgs:6,allowedInArgument:!0,argTypes:[`math`,`math`,`size`,`text`,`math`,`math`],handler(e,t){var n=e.parser,r=t[4],i=t[5],a=iG(t[0]),o=a.type===`atom`&&a.family===`open`?Cq(a.text):null,s=iG(t[1]),c=s.type===`atom`&&s.family===`close`?Cq(s.text):null,l=QG(t[2],`size`),u,d=null;l.isBlank?u=!0:(d=l.value,u=d.number>0);var f=null,p=t[3];if(p.type===`ordgroup`){if(p.body.length>0){var m=QG(p.body[0],`textord`);f=Sq[Number(m.text)]}}else p=QG(p,`textord`),f=Sq[Number(p.text)];return xq({type:`genfrac`,mode:n.mode,numer:r,denom:i,continued:!1,hasBarLine:u,barSize:d,leftDelim:o,rightDelim:c},f)}}),Z({type:`infix`,names:[`\\above`],numArgs:1,argTypes:[`size`],infix:!0,handler(e,t){var n=e.parser;e.funcName;var r=e.token;return{type:`infix`,mode:n.mode,replaceWith:`\\\\abovefrac`,size:QG(t[0],`size`).value,token:r}}}),Z({type:`genfrac`,names:[`\\\\abovefrac`],numArgs:3,argTypes:[`math`,`size`,`math`],handler:(e,t)=>{var n=e.parser;e.funcName;var r=t[0],i=QG(t[1],`infix`).size;if(!i)throw Error(`\\\\abovefrac expected size, but got `+String(i));var a=t[2],o=i.number>0;return{type:`genfrac`,mode:n.mode,numer:r,denom:a,continued:!1,hasBarLine:o,barSize:i,leftDelim:null,rightDelim:null}}});var wq=(e,t)=>{var n=t.style,r,i;e.type===`supsub`?(r=e.sup?gG(e.sup,t.havingStyle(n.sup()),t):gG(e.sub,t.havingStyle(n.sub()),t),i=QG(e.base,`horizBrace`)):i=QG(e,`horizBrace`);var a=gG(i.base,t.havingBaseStyle(R.DISPLAY)),o=GG(i,t),s=i.isOver?UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:.1},{type:`elem`,elem:o,wrapperClasses:[`svg-align`]}]}):UW({positionType:`bottom`,positionData:a.depth+.1+o.height,children:[{type:`elem`,elem:o,wrapperClasses:[`svg-align`]},{type:`kern`,size:.1},{type:`elem`,elem:a}]});if(r){var c=X([`minner`,i.isOver?`mover`:`munder`],[s],t);s=i.isOver?UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:c},{type:`kern`,size:.2},{type:`elem`,elem:r}]}):UW({positionType:`bottom`,positionData:c.depth+.2+r.height+r.depth,children:[{type:`elem`,elem:r},{type:`kern`,size:.2},{type:`elem`,elem:c}]})}return X([`minner`,i.isOver?`mover`:`munder`],[s],t)};Z({type:`horizBrace`,names:[`\\overbrace`,`\\underbrace`,`\\overbracket`,`\\underbracket`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`horizBrace`,mode:n.mode,label:r,isOver:r.includes(`\\over`),base:t[0]}},htmlBuilder:wq,mathmlBuilder:(e,t)=>{var n=HG(e.label);return new Q(e.isOver?`mover`:`munder`,[jG(e.base,t),n])}}),Z({type:`href`,names:[`\\href`],numArgs:2,argTypes:[`url`,`original`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[1],i=QG(t[0],`url`).url;return n.settings.isTrusted({command:`\\href`,url:i})?{type:`href`,mode:n.mode,href:i,body:aG(r)}:n.formatUnsupportedCmd(`\\href`)},htmlBuilder:(e,t)=>{var n=uG(e.body,t,!1);return zW(e.href,[],n,t)},mathmlBuilder:(e,t)=>{var n=AG(e.body,t);return n instanceof Q||(n=new Q(`mrow`,[n])),n.setAttribute(`href`,e.href),n}}),Z({type:`href`,names:[`\\url`],numArgs:1,argTypes:[`url`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=QG(t[0],`url`).url;if(!n.settings.isTrusted({command:`\\url`,url:r}))return n.formatUnsupportedCmd(`\\url`);for(var i=[],a=0;a{var n=e.parser,r=e.funcName;e.token;var i=QG(t[0],`raw`).string,a=t[1];n.settings.strict&&n.settings.reportNonstrict(`htmlExtension`,`HTML extension is disabled on strict mode`);var o,s={};switch(r){case`\\htmlClass`:s.class=i,o={command:`\\htmlClass`,class:i};break;case`\\htmlId`:s.id=i,o={command:`\\htmlId`,id:i};break;case`\\htmlStyle`:s.style=i,o={command:`\\htmlStyle`,style:i};break;case`\\htmlData`:for(var c=`{,}`,l=[],u=``,d=0;d{var n=uG(e.body,t,!1),r=[`enclosing`];e.attributes.class&&r.push(...e.attributes.class.trim().split(/\s+/));var i=X(r,n,t);for(var a of Object.entries(e.attributes)){var o=a[0],s=a[1];o!==`class`&&i.setAttribute(o,s)}return i},mathmlBuilder:(e,t)=>AG(e.body,t)}),Z({type:`htmlmathml`,names:[`\\html@mathml`],numArgs:2,allowedInArgument:!0,allowedInText:!0,handler:(e,t)=>({type:`htmlmathml`,mode:e.parser.mode,html:aG(t[0]),mathml:aG(t[1])}),htmlBuilder:(e,t)=>BW(uG(e.html,t,!1)),mathmlBuilder:(e,t)=>AG(e.mathml,t)});var Tq=function(e){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(e))return{number:+e,unit:`bp`};var t=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(e);if(!t)throw new L(`Invalid size: '`+e+`' in \\includegraphics`);var n={number:+(t[1]+t[2]),unit:t[3]};if(!_U(n))throw new L(`Invalid unit: '`+n.unit+`' in \\includegraphics.`);return n};Z({type:`includegraphics`,names:[`\\includegraphics`],numArgs:1,numOptionalArgs:1,argTypes:[`raw`,`url`],allowedInText:!1,handler:(e,t,n)=>{var r=e.parser,i={number:0,unit:`em`},a={number:.9,unit:`em`},o={number:0,unit:`em`},s=``;if(n[0])for(var c=QG(n[0],`raw`).string.split(`,`),l=0;l{var n=vU(e.height,t),r=0;e.totalheight.number>0&&(r=vU(e.totalheight,t)-n);var i=0;e.width.number>0&&(i=vU(e.width,t));var a={height:z(n+r)};i>0&&(a.width=z(i)),r>0&&(a.verticalAlign=z(-r));var o=new DU(e.src,e.alt,a);return o.height=n,o.depth=r,o},mathmlBuilder:(e,t)=>{var n=new Q(`mglyph`,[]);n.setAttribute(`alt`,e.alt);var r=vU(e.height,t),i=0;if(e.totalheight.number>0&&(i=vU(e.totalheight,t)-r,n.setAttribute(`valign`,z(-i))),n.setAttribute(`height`,z(r+i)),e.width.number>0){var a=vU(e.width,t);n.setAttribute(`width`,z(a))}return n.setAttribute(`src`,e.src),n}}),Z({type:`kern`,names:[`\\kern`,`\\mkern`,`\\hskip`,`\\mskip`],numArgs:1,argTypes:[`size`],primitive:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=QG(t[0],`size`);if(n.settings.strict){var a=r[1]===`m`,o=i.value.unit===`mu`;a?(o||n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` supports only mu units, `+(`not `+i.value.unit+` units`)),n.mode!==`math`&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` works only in math mode`)):o&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` doesn't support mu units`)}return{type:`kern`,mode:n.mode,dimension:i.value}},htmlBuilder(e,t){return WW(e.dimension,t)},mathmlBuilder(e,t){return new xG(vU(e.dimension,t))}}),Z({type:`lap`,names:[`\\mathllap`,`\\mathrlap`,`\\mathclap`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`lap`,mode:n.mode,alignment:r.slice(5),body:i}},htmlBuilder:(e,t)=>{var n;e.alignment===`clap`?(n=X([],[gG(e.body,t)]),n=X([`katex-inner`],[n],t)):n=X([`katex-inner`],[gG(e.body,t)]);var r=X([`katex-fix`],[]),i=X([e.alignment],[n,r],t),a=X([`katex-strut`]);return a.style.height=z(i.height+i.depth),i.depth&&(a.style.verticalAlign=z(-i.depth)),i.children.unshift(a),i=X([`katex-thinbox`],[i],t),X([`mord`,`katex-vbox`],[i],t)},mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[jG(e.body,t)]);if(e.alignment!==`rlap`){var r=e.alignment===`llap`?`-1`:`-0.5`;n.setAttribute(`lspace`,r+`width`)}return n.setAttribute(`width`,`0px`),n}}),Z({type:`styling`,names:[`\\(`,`$`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){var n=e.funcName,r=e.parser,i=r.mode;r.switchMode(`math`);var a=n===`\\(`?`\\)`:`$`,o=r.parseExpression(!1,a);return r.expect(a),r.switchMode(i),{type:`styling`,mode:r.mode,style:`text`,resetFont:!0,body:o}}}),Z({type:`text`,names:[`\\)`,`\\]`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){throw new L(`Mismatched `+e.funcName)}});var Eq=(e,t)=>{switch(t.style.size){case R.DISPLAY.size:return e.display;case R.TEXT.size:return e.text;case R.SCRIPT.size:return e.script;case R.SCRIPTSCRIPT.size:return e.scriptscript;default:return e.text}};Z({type:`mathchoice`,names:[`\\mathchoice`],numArgs:4,primitive:!0,handler:(e,t)=>({type:`mathchoice`,mode:e.parser.mode,display:aG(t[0]),text:aG(t[1]),script:aG(t[2]),scriptscript:aG(t[3])}),htmlBuilder:(e,t)=>BW(uG(Eq(e,t),t,!1)),mathmlBuilder:(e,t)=>AG(Eq(e,t),t)});var Dq=(e,t,n,r,i,a,o)=>{e=X([],[e]);var s=n&&DH(n),c,l;if(t){var u=gG(t,r.havingStyle(i.sup()),r);l={elem:u,kern:Math.max(r.fontMetrics().bigOpSpacing1,r.fontMetrics().bigOpSpacing3-u.depth)}}if(n){var d=gG(n,r.havingStyle(i.sub()),r);c={elem:d,kern:Math.max(r.fontMetrics().bigOpSpacing2,r.fontMetrics().bigOpSpacing4-d.height)}}var f;if(l&&c)f=UW({positionType:`bottom`,positionData:r.fontMetrics().bigOpSpacing5+c.elem.height+c.elem.depth+c.kern+e.depth+o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else if(c)f=UW({positionType:`top`,positionData:e.height-o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e}]});else if(l)f=UW({positionType:`bottom`,positionData:e.depth+o,children:[{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else return e;var p=[f];if(c&&a!==0&&!s){var m=X([`mspace`],[],r);m.style.marginRight=z(a),p.unshift(m)}return X([`mop`,`op-limits`],p,r)},Oq=new Set([`\\smallint`]),kq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=QG(e.base,`op`),i=!0):a=QG(e,`op`);var o=t.style,s=!1;o.size===R.DISPLAY.size&&a.symbol&&!Oq.has(a.name)&&(s=!0);var c,l;if(a.symbol){var u=s?`Size2-Regular`:`Size1-Regular`,d=``;if((a.name===`\\oiint`||a.name===`\\oiiint`)&&(d=a.name.slice(1),a.name=d===`oiint`?`\\iint`:`\\iiint`),c=AW(a.name,u,`math`,t,[`mop`,`op-symbol`,s?`large-op`:`small-op`]),l=c.italic,d.length>0){var f=JW(d+`Size`+(s?`2`:`1`),t);c=UW({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:0},{type:`elem`,elem:f,shift:s?.08:0}]}),a.name=`\\`+d,c.classes.unshift(`mop`),c.italic=l}}else if(a.body){var p=uG(a.body,t,!0);p.length===1&&p[0]instanceof kU?(c=p[0],c.classes[0]=`mop`):c=X([`mop`],p,t)}else{for(var m=[],h=1;h{var n;if(e.symbol)n=new Q(`mo`,[wG(e.name,e.mode)]),Oq.has(e.name)&&n.setAttribute(`largeop`,`false`);else if(e.body)n=new Q(`mo`,kG(e.body,t));else{n=new Q(`mi`,[new bG(e.name.slice(1))]);var r=new Q(`mo`,[wG(`⁡`,`text`)]);n=e.parentIsSupSub?new Q(`mrow`,[n,r]):yG([n,r])}return n},jq={"∏":`\\prod`,"∐":`\\coprod`,"∑":`\\sum`,"⋀":`\\bigwedge`,"⋁":`\\bigvee`,"⋂":`\\bigcap`,"⋃":`\\bigcup`,"⨀":`\\bigodot`,"⨁":`\\bigoplus`,"⨂":`\\bigotimes`,"⨄":`\\biguplus`,"⨆":`\\bigsqcup`};Z({type:`op`,names:`\\coprod.\\bigvee.\\bigwedge.\\biguplus.\\bigcap.\\bigcup.\\intop.\\prod.\\sum.\\bigotimes.\\bigoplus.\\bigodot.\\bigsqcup.\\smallint.∏.∐.∑.⋀.⋁.⋂.⋃.⨀.⨁.⨂.⨄.⨆`.split(`.`),numArgs:0,handler:(e,t)=>{var n=e.parser,r=e.funcName;return r.length===1&&(r=jq[r]),{type:`op`,mode:n.mode,limits:!0,parentIsSupSub:!1,symbol:!0,name:r}},htmlBuilder:kq,mathmlBuilder:Aq}),Z({type:`op`,names:[`\\mathop`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`op`,mode:n.mode,limits:!1,parentIsSupSub:!1,symbol:!1,body:aG(r)}}});var Mq={"∫":`\\int`,"∬":`\\iint`,"∭":`\\iiint`,"∮":`\\oint`,"∯":`\\oiint`,"∰":`\\oiiint`};Z({type:`op`,names:`\\arcsin.\\arccos.\\arctan.\\arctg.\\arcctg.\\arg.\\ch.\\cos.\\cosec.\\cosh.\\cot.\\cotg.\\coth.\\csc.\\ctg.\\cth.\\deg.\\dim.\\exp.\\hom.\\ker.\\lg.\\ln.\\log.\\sec.\\sin.\\sinh.\\sh.\\tan.\\tanh.\\tg.\\th`.split(`.`),numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\det`,`\\gcd`,`\\inf`,`\\lim`,`\\max`,`\\min`,`\\Pr`,`\\sup`],numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!0,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\int`,`\\iint`,`\\iiint`,`\\oint`,`\\oiint`,`\\oiiint`,`∫`,`∬`,`∭`,`∮`,`∯`,`∰`],numArgs:0,allowedInArgument:!0,handler(e){var t=e.parser,n=e.funcName;return n.length===1&&(n=Mq[n]),{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!0,name:n}}});var Nq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=QG(e.base,`operatorname`),i=!0):a=QG(e,`operatorname`);var o;if(a.body.length>0){for(var s=uG(a.body.map(e=>{var t=`text`in e?e.text:void 0;return typeof t==`string`?{type:`textord`,mode:e.mode,text:t}:e}),t.withFont(`mathrm`),!0),c=0;c{var n=e.parser,r=e.funcName,i=t[0];return{type:`operatorname`,mode:n.mode,body:aG(i),alwaysHandleSupSub:r===`\\operatornamewithlimits`,limits:!1,parentIsSupSub:!1}},htmlBuilder:Nq,mathmlBuilder:(e,t)=>{for(var n=kG(e.body,t.withFont(`mathrm`)),r=!0,i=0;ie.toText()).join(``))]);var s=new Q(`mi`,n);s.setAttribute(`mathvariant`,`normal`);var c=new Q(`mo`,[wG(`⁡`,`text`)]);return e.parentIsSupSub?new Q(`mrow`,[s,c]):yG([s,c])}}),$(`\\operatorname`,`\\@ifstar\\operatornamewithlimits\\operatorname@`),rG({type:`ordgroup`,htmlBuilder(e,t){return e.semisimple?BW(uG(e.body,t,!1)):X([`mord`],uG(e.body,t,!0),t)},mathmlBuilder(e,t){return AG(e.body,t,!0)}}),Z({type:`overline`,names:[`\\overline`],numArgs:1,handler(e,t){var n=e.parser,r=t[0];return{type:`overline`,mode:n.mode,body:r}},htmlBuilder(e,t){var n=gG(e.body,t.havingCrampedStyle()),r=RW(`overline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-overline`],[UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:n},{type:`kern`,size:3*i},{type:`elem`,elem:r},{type:`kern`,size:i}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new bG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`mover`,[jG(e.body,t),n]);return r.setAttribute(`accent`,`true`),r}}),Z({type:`phantom`,names:[`\\phantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`phantom`,mode:n.mode,body:aG(r)}},htmlBuilder:(e,t)=>BW(uG(e.body,t.withPhantom(),!1)),mathmlBuilder:(e,t)=>new Q(`mphantom`,kG(e.body,t))}),$(`\\hphantom`,`\\smash{\\phantom{#1}}`),Z({type:`vphantom`,names:[`\\vphantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`vphantom`,mode:n.mode,body:r}},htmlBuilder:(e,t)=>X([`mord`,`rlap`],[X([`katex-inner`],[gG(e.body,t.withPhantom())]),X([`katex-fix`],[])],t),mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[new Q(`mphantom`,kG(aG(e.body),t))]);return n.setAttribute(`width`,`0px`),n}}),Z({type:`raisebox`,names:[`\\raisebox`],numArgs:2,argTypes:[`size`,`hbox`],allowedInText:!0,handler(e,t){var n=e.parser,r=QG(t[0],`size`).value,i=t[1];return{type:`raisebox`,mode:n.mode,dy:r,body:i}},htmlBuilder(e,t){var n=gG(e.body,t);return UW({positionType:`shift`,positionData:-vU(e.dy,t),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){var n=new Q(`mpadded`,[jG(e.body,t)]),r=e.dy.number+e.dy.unit;return n.setAttribute(`voffset`,r),n}});var Pq=(e,t)=>({type:`reflectbox`,mode:e.parser.mode,body:t[0]});Z({type:`reflectbox`,names:[`\\reflectbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler:Pq,htmlBuilder(e,t){return X([`mord`,`reflectbox`],[gG(e.body,t)],t)},mathmlBuilder(e,t){return jG(e.body,t)}}),Z({type:`reflectbox`,names:[`\\mathreflectbox`],numArgs:1,argTypes:[`math`],handler:Pq}),Z({type:`internal`,names:[`\\relax`],numArgs:0,allowedInText:!0,allowedInArgument:!0,handler(e){return{type:`internal`,mode:e.parser.mode}}}),Z({type:`rule`,names:[`\\rule`],numArgs:2,numOptionalArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`size`,`size`,`size`],handler(e,t,n){var r=e.parser,i=n[0],a=QG(t[0],`size`),o=QG(t[1],`size`);return{type:`rule`,mode:r.mode,shift:i&&QG(i,`size`).value,width:a.value,height:o.value}},htmlBuilder(e,t){var n=X([`mord`,`katex-rule`],[],t),r=vU(e.width,t),i=vU(e.height,t),a=e.shift?vU(e.shift,t):0;return n.style.borderRightWidth=z(r),n.style.borderTopWidth=z(i),n.style.bottom=z(a),n.width=r,n.height=i+a,n.depth=-a,n.maxFontSize=i*1.125*t.sizeMultiplier,n},mathmlBuilder(e,t){var n=vU(e.width,t),r=vU(e.height,t),i=e.shift?vU(e.shift,t):0,a=t.color&&t.getColor()||`black`,o=new Q(`mspace`);o.setAttribute(`mathbackground`,a),o.setAttribute(`width`,z(n)),o.setAttribute(`height`,z(r));var s=new Q(`mpadded`,[o]);return i>=0?s.setAttribute(`height`,z(i)):(s.setAttribute(`height`,z(i)),s.setAttribute(`depth`,z(-i))),s.setAttribute(`voffset`,z(i)),s}});function Fq(e,t,n){for(var r=uG(e,t,!1),i=t.sizeMultiplier/n.sizeMultiplier,a=0;a{var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!1,n);return{type:`sizing`,mode:i.mode,size:Iq.indexOf(r)+1,body:a}},htmlBuilder:(e,t)=>{var n=t.havingSize(e.size);return Fq(e.body,n,t)},mathmlBuilder:(e,t)=>{var n=t.havingSize(e.size),r=new Q(`mstyle`,kG(e.body,n));return r.setAttribute(`mathsize`,z(n.sizeMultiplier)),r}}),Z({type:`smash`,names:[`\\smash`],numArgs:1,numOptionalArgs:1,allowedInText:!0,handler:(e,t,n)=>{var r=e.parser,i=!1,a=!1,o=n[0]&&QG(n[0],`ordgroup`);if(o)for(var s,c=0;c{var n=X([],[gG(e.body,t)]);if(!e.smashHeight&&!e.smashDepth)return n;if(e.smashHeight&&(n.height=0),e.smashDepth&&(n.depth=0),e.smashHeight&&e.smashDepth)return X([`mord`,`katex-smash`],[n],t);if(n.children)for(var r=0;r{var n=new Q(`mpadded`,[jG(e.body,t)]);return e.smashHeight&&n.setAttribute(`height`,`0px`),e.smashDepth&&n.setAttribute(`depth`,`0px`),n}}),Z({type:`sqrt`,names:[`\\sqrt`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=n[0],a=t[0];return{type:`sqrt`,mode:r.mode,body:a,index:i}},htmlBuilder(e,t){var n=gG(e.body,t.havingCrampedStyle());n.height===0&&(n.height=t.fontMetrics().xHeight),n=VW(n,t);var r=t.fontMetrics().defaultRuleThickness,i=r;t.style.idn.height+n.depth+a&&(a=(a+u-n.height-n.depth)/2);var d=s.height-n.height-a-c;n.style.paddingLeft=z(l);var f=UW({positionType:`firstBaseline`,children:[{type:`elem`,elem:n,wrapperClasses:[`svg-align`]},{type:`kern`,size:-(n.height+d)},{type:`elem`,elem:s},{type:`kern`,size:c}]});if(e.index){var p=t.havingStyle(R.SCRIPTSCRIPT),m=gG(e.index,p,t);return X([`mord`,`sqrt`],[X([`katex-root`],[UW({positionType:`shift`,positionData:-(.6*(f.height-f.depth)),children:[{type:`elem`,elem:m}]})]),f],t)}return X([`mord`,`sqrt`],[f],t)},mathmlBuilder(e,t){var n=e.body,r=e.index;return r?new Q(`mroot`,[jG(n,t),jG(r,t)]):new Q(`msqrt`,[jG(n,t)])}});var Lq={display:R.DISPLAY,text:R.TEXT,script:R.SCRIPT,scriptscript:R.SCRIPTSCRIPT};function Rq(e){return e in Lq}Z({type:`styling`,names:[`\\displaystyle`,`\\textstyle`,`\\scriptstyle`,`\\scriptscriptstyle`],numArgs:0,allowedInText:!0,primitive:!0,handler(e,t){var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!0,n),o=r.slice(1,r.length-5);if(!Rq(o))throw Error(`Unknown style: `+o);return{type:`styling`,mode:i.mode,style:o,body:a}},htmlBuilder(e,t){var n=Lq[e.style],r=t.havingStyle(n);return e.resetFont&&(r=r.withFont(``)),Fq(e.body,r,t)},mathmlBuilder(e,t){var n=Lq[e.style],r=t.havingStyle(n);e.resetFont&&(r=r.withFont(``));var i=new Q(`mstyle`,kG(e.body,r)),a={display:[`0`,`true`],text:[`0`,`false`],script:[`1`,`false`],scriptscript:[`2`,`false`]}[e.style];return i.setAttribute(`scriptlevel`,a[0]),i.setAttribute(`displaystyle`,a[1]),i}});var zq=function(e,t){var n=e.base;return n?n.type===`op`?n.limits&&(t.style.size===R.DISPLAY.size||n.alwaysHandleSupSub)?kq:null:n.type===`operatorname`?n.alwaysHandleSupSub&&(t.style.size===R.DISPLAY.size||n.limits)?Nq:null:n.type===`accent`?DH(n.base)?rK:null:n.type===`horizBrace`&&!e.sub===n.isOver?wq:null:null};rG({type:`supsub`,htmlBuilder(e,t){var n=zq(e,t);if(n)return n(e,t);var r=e.base,i=e.sup,a=e.sub,o=gG(r,t),s,c,l=t.fontMetrics(),u=0,d=0,f=r&&DH(r);if(i){var p=t.havingStyle(t.style.sup());s=gG(i,p,t),f||(u=o.height-p.fontMetrics().supDrop*p.sizeMultiplier/t.sizeMultiplier)}if(a){var m=t.havingStyle(t.style.sub());c=gG(a,m,t),f||(d=o.depth+m.fontMetrics().subDrop*m.sizeMultiplier/t.sizeMultiplier)}var h=t.style===R.DISPLAY?l.sup1:t.style.cramped?l.sup3:l.sup2,g=t.sizeMultiplier,_=z(.5/l.ptPerEm/g),v=null;if(c){var y=e.base&&e.base.type===`op`&&e.base.name&&(e.base.name===`\\oiint`||e.base.name===`\\oiiint`);(o instanceof kU||y)&&(v=z(-(o.italic??0)))}var b;if(s&&c){u=Math.max(u,h,s.depth+.25*l.xHeight),d=Math.max(d,l.sub2);var x=4*l.defaultRuleThickness;if(u-s.depth-(c.height-d)0&&(u+=S,d-=S)}b=UW({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:d,marginRight:_,marginLeft:v},{type:`elem`,elem:s,shift:-u,marginRight:_}]})}else if(c)d=Math.max(d,l.sub1,c.height-.8*l.xHeight),b=UW({positionType:`shift`,positionData:d,children:[{type:`elem`,elem:c,marginLeft:v,marginRight:_}]});else if(s)u=Math.max(u,h,s.depth+.25*l.xHeight),b=UW({positionType:`shift`,positionData:-u,children:[{type:`elem`,elem:s,marginRight:_}]});else throw Error(`supsub must have either sup or sub.`);return X([mG(o,`right`)||`mord`],[o,X([`msupsub`],[b])],t)},mathmlBuilder(e,t){var n=!1,r,i;e.base&&e.base.type===`horizBrace`&&(i=!!e.sup,i===e.base.isOver&&(n=!0,r=e.base.isOver)),e.base&&(e.base.type===`op`||e.base.type===`operatorname`)&&(e.base.parentIsSupSub=!0);var a=[jG(e.base,t)];e.sub&&a.push(jG(e.sub,t)),e.sup&&a.push(jG(e.sup,t));var o;if(n)o=r?`mover`:`munder`;else if(!e.sub){var s=e.base;o=s&&s.type===`op`&&s.limits&&(t.style===R.DISPLAY||s.alwaysHandleSupSub)||s&&s.type===`operatorname`&&s.alwaysHandleSupSub&&(s.limits||t.style===R.DISPLAY)?`mover`:`msup`}else if(e.sup){var c=e.base;o=c&&c.type===`op`&&c.limits&&t.style===R.DISPLAY||c&&c.type===`operatorname`&&c.alwaysHandleSupSub&&(t.style===R.DISPLAY||c.limits)?`munderover`:`msubsup`}else{var l=e.base;o=l&&l.type===`op`&&l.limits&&(t.style===R.DISPLAY||l.alwaysHandleSupSub)||l&&l.type===`operatorname`&&l.alwaysHandleSupSub&&(l.limits||t.style===R.DISPLAY)?`munder`:`msub`}return new Q(o,a)}}),rG({type:`atom`,htmlBuilder(e,t){return jW(e.text,e.mode,t,[`m`+e.family])},mathmlBuilder(e,t){var n=new Q(`mo`,[wG(e.text,e.mode)]);if(e.family===`bin`){var r=DG(e,t);r===`bold-italic`&&n.setAttribute(`mathvariant`,r)}else e.family===`punct`?n.setAttribute(`separator`,`true`):(e.family===`open`||e.family===`close`)&&n.setAttribute(`stretchy`,`false`);return n}});var Bq={mi:`italic`,mn:`normal`,mtext:`normal`};rG({type:`mathord`,htmlBuilder(e,t){return NW(e,t)},mathmlBuilder(e,t){var n=new Q(`mi`,[wG(e.text,e.mode,t)]),r=DG(e,t)||`italic`;return r!==Bq[n.type]&&n.setAttribute(`mathvariant`,r),n}}),rG({type:`textord`,htmlBuilder(e,t){return NW(e,t)},mathmlBuilder(e,t){var n=wG(e.text,e.mode,t),r=DG(e,t)||`normal`,i=e.mode===`text`?new Q(`mtext`,[n]):/[0-9]/.test(e.text)?new Q(`mn`,[n]):e.text===`\\prime`?new Q(`mo`,[n]):new Q(`mi`,[n]);return r!==Bq[i.type]&&i.setAttribute(`mathvariant`,r),i}});var Vq=new Map([[`\\nobreak`,`nobreak`],[`\\allowbreak`,`allowbreak`]]),Hq=new Map([[` `,{}],[`\\ `,{}],[`~`,{className:`nobreak`}],[`\\space`,{}],[`\\nobreakspace`,{className:`nobreak`}]]);rG({type:`spacing`,htmlBuilder(e,t){var n=Hq.get(e.text),r=Vq.get(e.text);if(n){var i=n.className||``;if(e.mode===`text`){var a=NW(e,t);return a.classes.push(i),a}return X([`mspace`,i],[jW(e.text,e.mode,t)],t)}if(r)return X([`mspace`,r],[],t);throw new L(`Unknown type of space "`+e.text+`"`)},mathmlBuilder(e,t){var n;if(Hq.has(e.text))n=new Q(`mtext`,[new bG(`\xA0`)]);else if(Vq.has(e.text))return new Q(`mspace`);else throw new L(`Unknown type of space "`+e.text+`"`);return n}});var Uq=()=>{var e=new Q(`mtd`,[]);return e.setAttribute(`width`,`50%`),e};rG({type:`tag`,mathmlBuilder(e,t){var n=new Q(`mtable`,[new Q(`mtr`,[Uq(),new Q(`mtd`,[AG(e.body,t)]),Uq(),new Q(`mtd`,[AG(e.tag,t)])])]);return n.setAttribute(`width`,`100%`),n}});var Wq={"\\text":void 0,"\\textrm":`textrm`,"\\textsf":`textsf`,"\\texttt":`texttt`,"\\textnormal":`textrm`},Gq={"\\textbf":`textbf`,"\\textmd":`textmd`},Kq={"\\textit":`textit`,"\\textup":`textup`},qq=(e,t)=>{var n=e.font;return n?Wq[n]?t.withTextFontFamily(Wq[n]):Gq[n]?t.withTextFontWeight(Gq[n]):n===`\\emph`?t.fontShape===`textit`?t.withTextFontShape(`textup`):t.withTextFontShape(`textit`):t.withTextFontShape(Kq[n]):t};Z({type:`text`,names:[`\\text`,`\\textrm`,`\\textsf`,`\\texttt`,`\\textnormal`,`\\textbf`,`\\textmd`,`\\textit`,`\\textup`,`\\emph`],numArgs:1,argTypes:[`text`],allowedInArgument:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`text`,mode:n.mode,body:aG(i),font:r}},htmlBuilder(e,t){var n=qq(e,t);return X([`mord`,`text`],uG(e.body,n,!0),n)},mathmlBuilder(e,t){var n=qq(e,t);return AG(e.body,n)}}),Z({type:`underline`,names:[`\\underline`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`underline`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=gG(e.body,t),r=RW(`underline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-underline`],[UW({positionType:`top`,positionData:n.height,children:[{type:`kern`,size:i},{type:`elem`,elem:r},{type:`kern`,size:3*i},{type:`elem`,elem:n}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new bG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`munder`,[jG(e.body,t),n]);return r.setAttribute(`accentunder`,`true`),r}}),Z({type:`vcenter`,names:[`\\vcenter`],numArgs:1,argTypes:[`original`],allowedInText:!1,handler(e,t){return{type:`vcenter`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=gG(e.body,t),r=t.fontMetrics().axisHeight;return UW({positionType:`shift`,positionData:.5*(n.height-r-(n.depth+r)),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){return new Q(`mrow`,[new Q(`mpadded`,[jG(e.body,t)],[`vcenter`])])}}),Z({type:`verb`,names:[`\\verb`],numArgs:0,allowedInText:!0,handler(e,t,n){throw new L(`\\verb ended by end of line instead of matching delimiter`)},htmlBuilder(e,t){for(var n=Jq(e),r=[],i=t.havingStyle(t.style.text()),a=0;ae.body.replace(/ /g,e.star?`␣`:`\xA0`),Yq=eG,Xq=`[ \r - ]`,Zq=`\\\\[a-zA-Z@]+`,Qq=`\\\\[^\ud800-\udfff]`,$q=`(`+Zq+`)`+Xq+`*`,eJ=`\\\\( +-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;default:throw Error(`Unknown stretchy delimiter.`)}};function _U(e){return`toText`in e}var vU=class{constructor(e){this.children=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.children=e,this.classes=[],this.height=0,this.depth=0,this.maxFontSize=0,this.style={}}hasClass(e){return this.classes.includes(e)}toNode(){for(var e=document.createDocumentFragment(),t=0;t{if(_U(e))return e.toText();throw Error(`Expected MathDomNode with toText, got `+e.constructor.name)}).join(``)}},yU={pt:1,mm:7227/2540,cm:7227/254,in:72.27,bp:803/800,pc:12,dd:1238/1157,cc:14856/1157,nd:685/642,nc:1370/107,sp:1/65536,px:803/800},bU={ex:!0,em:!0,mu:!0},xU=function(e){return typeof e!=`string`&&(e=e.unit),e in yU||e in bU||e===`ex`},SU=function(e,t){var n;if(e.unit in yU)n=yU[e.unit]/t.fontMetrics().ptPerEm/t.sizeMultiplier;else if(e.unit===`mu`)n=t.fontMetrics().cssEmPerMu;else{var r=t.style.isTight()?t.havingStyle(t.style.text()):t;if(e.unit===`ex`)n=r.fontMetrics().xHeight;else if(e.unit===`em`)n=r.fontMetrics().quad;else throw new L(`Invalid unit: '`+e.unit+`'`);r!==t&&(n*=r.sizeMultiplier/t.sizeMultiplier)}return Math.min(e.number*n,t.maxSize)},z=function(e){return+e.toFixed(4)+`em`},CU=function(e){return e.filter(e=>e).join(` `)},wU=function(e){var t=``;for(var n of Object.keys(e)){var r=e[n];r!==void 0&&(t+=TH(n)+`:`+r+`;`)}return t},TU=function(e,t,n){if(this.classes=e||[],this.attributes={},this.height=0,this.depth=0,this.maxFontSize=0,this.style=n||{},t){t.style.isTight()&&this.classes.push(`mtight`);var r=t.getColor();r&&(this.style.color=r)}},EU=function(e){var t=document.createElement(e);t.className=CU(this.classes),Object.assign(t.style,this.style);for(var n of Object.keys(this.attributes))t.setAttribute(n,this.attributes[n]);for(var r=0;r/=\x00-\x1f]/,OU=function(e){var t=`<`+e;this.classes.length&&(t+=` class="`+OH(CU(this.classes))+`"`);var n=wU(this.style);n&&(t+=` style="`+OH(n)+`"`);for(var r of Object.keys(this.attributes)){if(DU.test(r))throw new L(`Invalid attribute name '`+r+`'`);t+=` `+r+`="`+OH(this.attributes[r])+`"`}t+=`>`;for(var i=0;i`,t},kU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.width=void 0,this.maxFontSize=void 0,this.style=void 0,this.italic=void 0,TU.call(this,e,n,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return EU.call(this,`span`)}toMarkup(){return OU.call(this,`span`)}},AU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,TU.call(this,t,r),this.children=n||[],this.setAttribute(`href`,e)}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return EU.call(this,`a`)}toMarkup(){return OU.call(this,`a`)}},jU=class{constructor(e,t,n){this.src=void 0,this.alt=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.alt=t,this.src=e,this.classes=[`mord`],this.height=0,this.depth=0,this.maxFontSize=0,this.style=n}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createElement(`img`);return e.src=this.src,e.alt=this.alt,e.className=`mord`,Object.assign(e.style,this.style),e}toMarkup(){var e=``+OH(this.alt)+``,e}},MU={î:`ı̂`,ï:`ı̈`,í:`ı́`,ì:`ı̀`},NU=class{constructor(e,t,n,r,i,a,o,s){this.text=void 0,this.height=void 0,this.depth=void 0,this.italic=void 0,this.skew=void 0,this.width=void 0,this.maxFontSize=void 0,this.classes=void 0,this.style=void 0,this.text=e,this.height=t||0,this.depth=n||0,this.italic=r||0,this.skew=i||0,this.width=a||0,this.classes=o||[],this.style=s||{},this.maxFontSize=0;var c=tU(this.text.charCodeAt(0));c&&this.classes.push(c+`_fallback`),/[îïíì]/.test(this.text)&&(this.text=MU[this.text])}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createTextNode(this.text),t=null;return this.italic>0&&(t=document.createElement(`span`),t.style.marginRight=z(this.italic)),this.classes.length>0&&(t||=document.createElement(`span`),t.className=CU(this.classes)),Object.keys(this.style).length>0&&(t||=document.createElement(`span`),Object.assign(t.style,this.style)),t?(t.appendChild(e),t):e}toMarkup(){var e=!1,t=`0&&(n+=`margin-right:`+z(this.italic)+`;`),n+=wU(this.style),n&&(e=!0,t+=` style="`+OH(n)+`"`);var r=OH(this.text);return e?(t+=`>`,t+=r,t+=``,t):r}},PU=class{constructor(e,t){this.children=void 0,this.attributes=void 0,this.children=e||[],this.attributes=t||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);for(var n=0;n`;for(var n=0;n`,e}},FU=class{constructor(e,t){this.pathName=void 0,this.alternate=void 0,this.pathName=e,this.alternate=t}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return this.alternate?e.setAttribute(`d`,this.alternate):e.setAttribute(`d`,hU[this.pathName]),e}toMarkup(){return this.alternate?``:``}},IU=class{constructor(e){this.attributes=void 0,this.attributes=e||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);return e}toMarkup(){var e=``,e}};function LU(e){if(e instanceof NU)return e;throw Error(`Expected symbolNode but got `+String(e)+`.`)}function RU(e){if(e instanceof kU)return e;throw Error(`Expected span but got `+String(e)+`.`)}var zU=e=>e instanceof kU||e instanceof AU||e instanceof vU,BU={"AMS-Regular":{32:[0,0,0,0,.25],65:[0,.68889,0,0,.72222],66:[0,.68889,0,0,.66667],67:[0,.68889,0,0,.72222],68:[0,.68889,0,0,.72222],69:[0,.68889,0,0,.66667],70:[0,.68889,0,0,.61111],71:[0,.68889,0,0,.77778],72:[0,.68889,0,0,.77778],73:[0,.68889,0,0,.38889],74:[.16667,.68889,0,0,.5],75:[0,.68889,0,0,.77778],76:[0,.68889,0,0,.66667],77:[0,.68889,0,0,.94445],78:[0,.68889,0,0,.72222],79:[.16667,.68889,0,0,.77778],80:[0,.68889,0,0,.61111],81:[.16667,.68889,0,0,.77778],82:[0,.68889,0,0,.72222],83:[0,.68889,0,0,.55556],84:[0,.68889,0,0,.66667],85:[0,.68889,0,0,.72222],86:[0,.68889,0,0,.72222],87:[0,.68889,0,0,1],88:[0,.68889,0,0,.72222],89:[0,.68889,0,0,.72222],90:[0,.68889,0,0,.66667],107:[0,.68889,0,0,.55556],160:[0,0,0,0,.25],165:[0,.675,.025,0,.75],174:[.15559,.69224,0,0,.94666],240:[0,.68889,0,0,.55556],295:[0,.68889,0,0,.54028],710:[0,.825,0,0,2.33334],732:[0,.9,0,0,2.33334],770:[0,.825,0,0,2.33334],771:[0,.9,0,0,2.33334],989:[.08167,.58167,0,0,.77778],1008:[0,.43056,.04028,0,.66667],8245:[0,.54986,0,0,.275],8463:[0,.68889,0,0,.54028],8487:[0,.68889,0,0,.72222],8498:[0,.68889,0,0,.55556],8502:[0,.68889,0,0,.66667],8503:[0,.68889,0,0,.44445],8504:[0,.68889,0,0,.66667],8513:[0,.68889,0,0,.63889],8592:[-.03598,.46402,0,0,.5],8594:[-.03598,.46402,0,0,.5],8602:[-.13313,.36687,0,0,1],8603:[-.13313,.36687,0,0,1],8606:[.01354,.52239,0,0,1],8608:[.01354,.52239,0,0,1],8610:[.01354,.52239,0,0,1.11111],8611:[.01354,.52239,0,0,1.11111],8619:[0,.54986,0,0,1],8620:[0,.54986,0,0,1],8621:[-.13313,.37788,0,0,1.38889],8622:[-.13313,.36687,0,0,1],8624:[0,.69224,0,0,.5],8625:[0,.69224,0,0,.5],8630:[0,.43056,0,0,1],8631:[0,.43056,0,0,1],8634:[.08198,.58198,0,0,.77778],8635:[.08198,.58198,0,0,.77778],8638:[.19444,.69224,0,0,.41667],8639:[.19444,.69224,0,0,.41667],8642:[.19444,.69224,0,0,.41667],8643:[.19444,.69224,0,0,.41667],8644:[.1808,.675,0,0,1],8646:[.1808,.675,0,0,1],8647:[.1808,.675,0,0,1],8648:[.19444,.69224,0,0,.83334],8649:[.1808,.675,0,0,1],8650:[.19444,.69224,0,0,.83334],8651:[.01354,.52239,0,0,1],8652:[.01354,.52239,0,0,1],8653:[-.13313,.36687,0,0,1],8654:[-.13313,.36687,0,0,1],8655:[-.13313,.36687,0,0,1],8666:[.13667,.63667,0,0,1],8667:[.13667,.63667,0,0,1],8669:[-.13313,.37788,0,0,1],8672:[-.064,.437,0,0,1.334],8674:[-.064,.437,0,0,1.334],8705:[0,.825,0,0,.5],8708:[0,.68889,0,0,.55556],8709:[.08167,.58167,0,0,.77778],8717:[0,.43056,0,0,.42917],8722:[-.03598,.46402,0,0,.5],8724:[.08198,.69224,0,0,.77778],8726:[.08167,.58167,0,0,.77778],8733:[0,.69224,0,0,.77778],8736:[0,.69224,0,0,.72222],8737:[0,.69224,0,0,.72222],8738:[.03517,.52239,0,0,.72222],8739:[.08167,.58167,0,0,.22222],8740:[.25142,.74111,0,0,.27778],8741:[.08167,.58167,0,0,.38889],8742:[.25142,.74111,0,0,.5],8756:[0,.69224,0,0,.66667],8757:[0,.69224,0,0,.66667],8764:[-.13313,.36687,0,0,.77778],8765:[-.13313,.37788,0,0,.77778],8769:[-.13313,.36687,0,0,.77778],8770:[-.03625,.46375,0,0,.77778],8774:[.30274,.79383,0,0,.77778],8776:[-.01688,.48312,0,0,.77778],8778:[.08167,.58167,0,0,.77778],8782:[.06062,.54986,0,0,.77778],8783:[.06062,.54986,0,0,.77778],8785:[.08198,.58198,0,0,.77778],8786:[.08198,.58198,0,0,.77778],8787:[.08198,.58198,0,0,.77778],8790:[0,.69224,0,0,.77778],8791:[.22958,.72958,0,0,.77778],8796:[.08198,.91667,0,0,.77778],8806:[.25583,.75583,0,0,.77778],8807:[.25583,.75583,0,0,.77778],8808:[.25142,.75726,0,0,.77778],8809:[.25142,.75726,0,0,.77778],8812:[.25583,.75583,0,0,.5],8814:[.20576,.70576,0,0,.77778],8815:[.20576,.70576,0,0,.77778],8816:[.30274,.79383,0,0,.77778],8817:[.30274,.79383,0,0,.77778],8818:[.22958,.72958,0,0,.77778],8819:[.22958,.72958,0,0,.77778],8822:[.1808,.675,0,0,.77778],8823:[.1808,.675,0,0,.77778],8828:[.13667,.63667,0,0,.77778],8829:[.13667,.63667,0,0,.77778],8830:[.22958,.72958,0,0,.77778],8831:[.22958,.72958,0,0,.77778],8832:[.20576,.70576,0,0,.77778],8833:[.20576,.70576,0,0,.77778],8840:[.30274,.79383,0,0,.77778],8841:[.30274,.79383,0,0,.77778],8842:[.13597,.63597,0,0,.77778],8843:[.13597,.63597,0,0,.77778],8847:[.03517,.54986,0,0,.77778],8848:[.03517,.54986,0,0,.77778],8858:[.08198,.58198,0,0,.77778],8859:[.08198,.58198,0,0,.77778],8861:[.08198,.58198,0,0,.77778],8862:[0,.675,0,0,.77778],8863:[0,.675,0,0,.77778],8864:[0,.675,0,0,.77778],8865:[0,.675,0,0,.77778],8872:[0,.69224,0,0,.61111],8873:[0,.69224,0,0,.72222],8874:[0,.69224,0,0,.88889],8876:[0,.68889,0,0,.61111],8877:[0,.68889,0,0,.61111],8878:[0,.68889,0,0,.72222],8879:[0,.68889,0,0,.72222],8882:[.03517,.54986,0,0,.77778],8883:[.03517,.54986,0,0,.77778],8884:[.13667,.63667,0,0,.77778],8885:[.13667,.63667,0,0,.77778],8888:[0,.54986,0,0,1.11111],8890:[.19444,.43056,0,0,.55556],8891:[.19444,.69224,0,0,.61111],8892:[.19444,.69224,0,0,.61111],8901:[0,.54986,0,0,.27778],8903:[.08167,.58167,0,0,.77778],8905:[.08167,.58167,0,0,.77778],8906:[.08167,.58167,0,0,.77778],8907:[0,.69224,0,0,.77778],8908:[0,.69224,0,0,.77778],8909:[-.03598,.46402,0,0,.77778],8910:[0,.54986,0,0,.76042],8911:[0,.54986,0,0,.76042],8912:[.03517,.54986,0,0,.77778],8913:[.03517,.54986,0,0,.77778],8914:[0,.54986,0,0,.66667],8915:[0,.54986,0,0,.66667],8916:[0,.69224,0,0,.66667],8918:[.0391,.5391,0,0,.77778],8919:[.0391,.5391,0,0,.77778],8920:[.03517,.54986,0,0,1.33334],8921:[.03517,.54986,0,0,1.33334],8922:[.38569,.88569,0,0,.77778],8923:[.38569,.88569,0,0,.77778],8926:[.13667,.63667,0,0,.77778],8927:[.13667,.63667,0,0,.77778],8928:[.30274,.79383,0,0,.77778],8929:[.30274,.79383,0,0,.77778],8934:[.23222,.74111,0,0,.77778],8935:[.23222,.74111,0,0,.77778],8936:[.23222,.74111,0,0,.77778],8937:[.23222,.74111,0,0,.77778],8938:[.20576,.70576,0,0,.77778],8939:[.20576,.70576,0,0,.77778],8940:[.30274,.79383,0,0,.77778],8941:[.30274,.79383,0,0,.77778],8994:[.19444,.69224,0,0,.77778],8995:[.19444,.69224,0,0,.77778],9416:[.15559,.69224,0,0,.90222],9484:[0,.69224,0,0,.5],9488:[0,.69224,0,0,.5],9492:[0,.37788,0,0,.5],9496:[0,.37788,0,0,.5],9585:[.19444,.68889,0,0,.88889],9586:[.19444,.74111,0,0,.88889],9632:[0,.675,0,0,.77778],9633:[0,.675,0,0,.77778],9650:[0,.54986,0,0,.72222],9651:[0,.54986,0,0,.72222],9654:[.03517,.54986,0,0,.77778],9660:[0,.54986,0,0,.72222],9661:[0,.54986,0,0,.72222],9664:[.03517,.54986,0,0,.77778],9674:[.11111,.69224,0,0,.66667],9733:[.19444,.69224,0,0,.94445],10003:[0,.69224,0,0,.83334],10016:[0,.69224,0,0,.83334],10731:[.11111,.69224,0,0,.66667],10846:[.19444,.75583,0,0,.61111],10877:[.13667,.63667,0,0,.77778],10878:[.13667,.63667,0,0,.77778],10885:[.25583,.75583,0,0,.77778],10886:[.25583,.75583,0,0,.77778],10887:[.13597,.63597,0,0,.77778],10888:[.13597,.63597,0,0,.77778],10889:[.26167,.75726,0,0,.77778],10890:[.26167,.75726,0,0,.77778],10891:[.48256,.98256,0,0,.77778],10892:[.48256,.98256,0,0,.77778],10901:[.13667,.63667,0,0,.77778],10902:[.13667,.63667,0,0,.77778],10933:[.25142,.75726,0,0,.77778],10934:[.25142,.75726,0,0,.77778],10935:[.26167,.75726,0,0,.77778],10936:[.26167,.75726,0,0,.77778],10937:[.26167,.75726,0,0,.77778],10938:[.26167,.75726,0,0,.77778],10949:[.25583,.75583,0,0,.77778],10950:[.25583,.75583,0,0,.77778],10955:[.28481,.79383,0,0,.77778],10956:[.28481,.79383,0,0,.77778],57350:[.08167,.58167,0,0,.22222],57351:[.08167,.58167,0,0,.38889],57352:[.08167,.58167,0,0,.77778],57353:[0,.43056,.04028,0,.66667],57356:[.25142,.75726,0,0,.77778],57357:[.25142,.75726,0,0,.77778],57358:[.41951,.91951,0,0,.77778],57359:[.30274,.79383,0,0,.77778],57360:[.30274,.79383,0,0,.77778],57361:[.41951,.91951,0,0,.77778],57366:[.25142,.75726,0,0,.77778],57367:[.25142,.75726,0,0,.77778],57368:[.25142,.75726,0,0,.77778],57369:[.25142,.75726,0,0,.77778],57370:[.13597,.63597,0,0,.77778],57371:[.13597,.63597,0,0,.77778]},"Caligraphic-Regular":{32:[0,0,0,0,.25],65:[0,.68333,0,.19445,.79847],66:[0,.68333,.03041,.13889,.65681],67:[0,.68333,.05834,.13889,.52653],68:[0,.68333,.02778,.08334,.77139],69:[0,.68333,.08944,.11111,.52778],70:[0,.68333,.09931,.11111,.71875],71:[.09722,.68333,.0593,.11111,.59487],72:[0,.68333,.00965,.11111,.84452],73:[0,.68333,.07382,0,.54452],74:[.09722,.68333,.18472,.16667,.67778],75:[0,.68333,.01445,.05556,.76195],76:[0,.68333,0,.13889,.68972],77:[0,.68333,0,.13889,1.2009],78:[0,.68333,.14736,.08334,.82049],79:[0,.68333,.02778,.11111,.79611],80:[0,.68333,.08222,.08334,.69556],81:[.09722,.68333,0,.11111,.81667],82:[0,.68333,0,.08334,.8475],83:[0,.68333,.075,.13889,.60556],84:[0,.68333,.25417,0,.54464],85:[0,.68333,.09931,.08334,.62583],86:[0,.68333,.08222,0,.61278],87:[0,.68333,.08222,.08334,.98778],88:[0,.68333,.14643,.13889,.7133],89:[.09722,.68333,.08222,.08334,.66834],90:[0,.68333,.07944,.13889,.72473],160:[0,0,0,0,.25]},"Fraktur-Regular":{32:[0,0,0,0,.25],33:[0,.69141,0,0,.29574],34:[0,.69141,0,0,.21471],38:[0,.69141,0,0,.73786],39:[0,.69141,0,0,.21201],40:[.24982,.74947,0,0,.38865],41:[.24982,.74947,0,0,.38865],42:[0,.62119,0,0,.27764],43:[.08319,.58283,0,0,.75623],44:[0,.10803,0,0,.27764],45:[.08319,.58283,0,0,.75623],46:[0,.10803,0,0,.27764],47:[.24982,.74947,0,0,.50181],48:[0,.47534,0,0,.50181],49:[0,.47534,0,0,.50181],50:[0,.47534,0,0,.50181],51:[.18906,.47534,0,0,.50181],52:[.18906,.47534,0,0,.50181],53:[.18906,.47534,0,0,.50181],54:[0,.69141,0,0,.50181],55:[.18906,.47534,0,0,.50181],56:[0,.69141,0,0,.50181],57:[.18906,.47534,0,0,.50181],58:[0,.47534,0,0,.21606],59:[.12604,.47534,0,0,.21606],61:[-.13099,.36866,0,0,.75623],63:[0,.69141,0,0,.36245],65:[0,.69141,0,0,.7176],66:[0,.69141,0,0,.88397],67:[0,.69141,0,0,.61254],68:[0,.69141,0,0,.83158],69:[0,.69141,0,0,.66278],70:[.12604,.69141,0,0,.61119],71:[0,.69141,0,0,.78539],72:[.06302,.69141,0,0,.7203],73:[0,.69141,0,0,.55448],74:[.12604,.69141,0,0,.55231],75:[0,.69141,0,0,.66845],76:[0,.69141,0,0,.66602],77:[0,.69141,0,0,1.04953],78:[0,.69141,0,0,.83212],79:[0,.69141,0,0,.82699],80:[.18906,.69141,0,0,.82753],81:[.03781,.69141,0,0,.82699],82:[0,.69141,0,0,.82807],83:[0,.69141,0,0,.82861],84:[0,.69141,0,0,.66899],85:[0,.69141,0,0,.64576],86:[0,.69141,0,0,.83131],87:[0,.69141,0,0,1.04602],88:[0,.69141,0,0,.71922],89:[.18906,.69141,0,0,.83293],90:[.12604,.69141,0,0,.60201],91:[.24982,.74947,0,0,.27764],93:[.24982,.74947,0,0,.27764],94:[0,.69141,0,0,.49965],97:[0,.47534,0,0,.50046],98:[0,.69141,0,0,.51315],99:[0,.47534,0,0,.38946],100:[0,.62119,0,0,.49857],101:[0,.47534,0,0,.40053],102:[.18906,.69141,0,0,.32626],103:[.18906,.47534,0,0,.5037],104:[.18906,.69141,0,0,.52126],105:[0,.69141,0,0,.27899],106:[0,.69141,0,0,.28088],107:[0,.69141,0,0,.38946],108:[0,.69141,0,0,.27953],109:[0,.47534,0,0,.76676],110:[0,.47534,0,0,.52666],111:[0,.47534,0,0,.48885],112:[.18906,.52396,0,0,.50046],113:[.18906,.47534,0,0,.48912],114:[0,.47534,0,0,.38919],115:[0,.47534,0,0,.44266],116:[0,.62119,0,0,.33301],117:[0,.47534,0,0,.5172],118:[0,.52396,0,0,.5118],119:[0,.52396,0,0,.77351],120:[.18906,.47534,0,0,.38865],121:[.18906,.47534,0,0,.49884],122:[.18906,.47534,0,0,.39054],160:[0,0,0,0,.25],8216:[0,.69141,0,0,.21471],8217:[0,.69141,0,0,.21471],58112:[0,.62119,0,0,.49749],58113:[0,.62119,0,0,.4983],58114:[.18906,.69141,0,0,.33328],58115:[.18906,.69141,0,0,.32923],58116:[.18906,.47534,0,0,.50343],58117:[0,.69141,0,0,.33301],58118:[0,.62119,0,0,.33409],58119:[0,.47534,0,0,.50073]},"Main-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.35],34:[0,.69444,0,0,.60278],35:[.19444,.69444,0,0,.95833],36:[.05556,.75,0,0,.575],37:[.05556,.75,0,0,.95833],38:[0,.69444,0,0,.89444],39:[0,.69444,0,0,.31944],40:[.25,.75,0,0,.44722],41:[.25,.75,0,0,.44722],42:[0,.75,0,0,.575],43:[.13333,.63333,0,0,.89444],44:[.19444,.15556,0,0,.31944],45:[0,.44444,0,0,.38333],46:[0,.15556,0,0,.31944],47:[.25,.75,0,0,.575],48:[0,.64444,0,0,.575],49:[0,.64444,0,0,.575],50:[0,.64444,0,0,.575],51:[0,.64444,0,0,.575],52:[0,.64444,0,0,.575],53:[0,.64444,0,0,.575],54:[0,.64444,0,0,.575],55:[0,.64444,0,0,.575],56:[0,.64444,0,0,.575],57:[0,.64444,0,0,.575],58:[0,.44444,0,0,.31944],59:[.19444,.44444,0,0,.31944],60:[.08556,.58556,0,0,.89444],61:[-.10889,.39111,0,0,.89444],62:[.08556,.58556,0,0,.89444],63:[0,.69444,0,0,.54305],64:[0,.69444,0,0,.89444],65:[0,.68611,0,0,.86944],66:[0,.68611,0,0,.81805],67:[0,.68611,0,0,.83055],68:[0,.68611,0,0,.88194],69:[0,.68611,0,0,.75555],70:[0,.68611,0,0,.72361],71:[0,.68611,0,0,.90416],72:[0,.68611,0,0,.9],73:[0,.68611,0,0,.43611],74:[0,.68611,0,0,.59444],75:[0,.68611,0,0,.90138],76:[0,.68611,0,0,.69166],77:[0,.68611,0,0,1.09166],78:[0,.68611,0,0,.9],79:[0,.68611,0,0,.86388],80:[0,.68611,0,0,.78611],81:[.19444,.68611,0,0,.86388],82:[0,.68611,0,0,.8625],83:[0,.68611,0,0,.63889],84:[0,.68611,0,0,.8],85:[0,.68611,0,0,.88472],86:[0,.68611,.01597,0,.86944],87:[0,.68611,.01597,0,1.18888],88:[0,.68611,0,0,.86944],89:[0,.68611,.02875,0,.86944],90:[0,.68611,0,0,.70277],91:[.25,.75,0,0,.31944],92:[.25,.75,0,0,.575],93:[.25,.75,0,0,.31944],94:[0,.69444,0,0,.575],95:[.31,.13444,.03194,0,.575],97:[0,.44444,0,0,.55902],98:[0,.69444,0,0,.63889],99:[0,.44444,0,0,.51111],100:[0,.69444,0,0,.63889],101:[0,.44444,0,0,.52708],102:[0,.69444,.10903,0,.35139],103:[.19444,.44444,.01597,0,.575],104:[0,.69444,0,0,.63889],105:[0,.69444,0,0,.31944],106:[.19444,.69444,0,0,.35139],107:[0,.69444,0,0,.60694],108:[0,.69444,0,0,.31944],109:[0,.44444,0,0,.95833],110:[0,.44444,0,0,.63889],111:[0,.44444,0,0,.575],112:[.19444,.44444,0,0,.63889],113:[.19444,.44444,0,0,.60694],114:[0,.44444,0,0,.47361],115:[0,.44444,0,0,.45361],116:[0,.63492,0,0,.44722],117:[0,.44444,0,0,.63889],118:[0,.44444,.01597,0,.60694],119:[0,.44444,.01597,0,.83055],120:[0,.44444,0,0,.60694],121:[.19444,.44444,.01597,0,.60694],122:[0,.44444,0,0,.51111],123:[.25,.75,0,0,.575],124:[.25,.75,0,0,.31944],125:[.25,.75,0,0,.575],126:[.35,.34444,0,0,.575],160:[0,0,0,0,.25],163:[0,.69444,0,0,.86853],168:[0,.69444,0,0,.575],172:[0,.44444,0,0,.76666],176:[0,.69444,0,0,.86944],177:[.13333,.63333,0,0,.89444],184:[.17014,0,0,0,.51111],198:[0,.68611,0,0,1.04166],215:[.13333,.63333,0,0,.89444],216:[.04861,.73472,0,0,.89444],223:[0,.69444,0,0,.59722],230:[0,.44444,0,0,.83055],247:[.13333,.63333,0,0,.89444],248:[.09722,.54167,0,0,.575],305:[0,.44444,0,0,.31944],338:[0,.68611,0,0,1.16944],339:[0,.44444,0,0,.89444],567:[.19444,.44444,0,0,.35139],710:[0,.69444,0,0,.575],711:[0,.63194,0,0,.575],713:[0,.59611,0,0,.575],714:[0,.69444,0,0,.575],715:[0,.69444,0,0,.575],728:[0,.69444,0,0,.575],729:[0,.69444,0,0,.31944],730:[0,.69444,0,0,.86944],732:[0,.69444,0,0,.575],733:[0,.69444,0,0,.575],915:[0,.68611,0,0,.69166],916:[0,.68611,0,0,.95833],920:[0,.68611,0,0,.89444],923:[0,.68611,0,0,.80555],926:[0,.68611,0,0,.76666],928:[0,.68611,0,0,.9],931:[0,.68611,0,0,.83055],933:[0,.68611,0,0,.89444],934:[0,.68611,0,0,.83055],936:[0,.68611,0,0,.89444],937:[0,.68611,0,0,.83055],8211:[0,.44444,.03194,0,.575],8212:[0,.44444,.03194,0,1.14999],8216:[0,.69444,0,0,.31944],8217:[0,.69444,0,0,.31944],8220:[0,.69444,0,0,.60278],8221:[0,.69444,0,0,.60278],8224:[.19444,.69444,0,0,.51111],8225:[.19444,.69444,0,0,.51111],8242:[0,.55556,0,0,.34444],8407:[0,.72444,.15486,0,.575],8463:[0,.69444,0,0,.66759],8465:[0,.69444,0,0,.83055],8467:[0,.69444,0,0,.47361],8472:[.19444,.44444,0,0,.74027],8476:[0,.69444,0,0,.83055],8501:[0,.69444,0,0,.70277],8592:[-.10889,.39111,0,0,1.14999],8593:[.19444,.69444,0,0,.575],8594:[-.10889,.39111,0,0,1.14999],8595:[.19444,.69444,0,0,.575],8596:[-.10889,.39111,0,0,1.14999],8597:[.25,.75,0,0,.575],8598:[.19444,.69444,0,0,1.14999],8599:[.19444,.69444,0,0,1.14999],8600:[.19444,.69444,0,0,1.14999],8601:[.19444,.69444,0,0,1.14999],8636:[-.10889,.39111,0,0,1.14999],8637:[-.10889,.39111,0,0,1.14999],8640:[-.10889,.39111,0,0,1.14999],8641:[-.10889,.39111,0,0,1.14999],8656:[-.10889,.39111,0,0,1.14999],8657:[.19444,.69444,0,0,.70277],8658:[-.10889,.39111,0,0,1.14999],8659:[.19444,.69444,0,0,.70277],8660:[-.10889,.39111,0,0,1.14999],8661:[.25,.75,0,0,.70277],8704:[0,.69444,0,0,.63889],8706:[0,.69444,.06389,0,.62847],8707:[0,.69444,0,0,.63889],8709:[.05556,.75,0,0,.575],8711:[0,.68611,0,0,.95833],8712:[.08556,.58556,0,0,.76666],8715:[.08556,.58556,0,0,.76666],8722:[.13333,.63333,0,0,.89444],8723:[.13333,.63333,0,0,.89444],8725:[.25,.75,0,0,.575],8726:[.25,.75,0,0,.575],8727:[-.02778,.47222,0,0,.575],8728:[-.02639,.47361,0,0,.575],8729:[-.02639,.47361,0,0,.575],8730:[.18,.82,0,0,.95833],8733:[0,.44444,0,0,.89444],8734:[0,.44444,0,0,1.14999],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.31944],8741:[.25,.75,0,0,.575],8743:[0,.55556,0,0,.76666],8744:[0,.55556,0,0,.76666],8745:[0,.55556,0,0,.76666],8746:[0,.55556,0,0,.76666],8747:[.19444,.69444,.12778,0,.56875],8764:[-.10889,.39111,0,0,.89444],8768:[.19444,.69444,0,0,.31944],8771:[.00222,.50222,0,0,.89444],8773:[.027,.638,0,0,.894],8776:[.02444,.52444,0,0,.89444],8781:[.00222,.50222,0,0,.89444],8801:[.00222,.50222,0,0,.89444],8804:[.19667,.69667,0,0,.89444],8805:[.19667,.69667,0,0,.89444],8810:[.08556,.58556,0,0,1.14999],8811:[.08556,.58556,0,0,1.14999],8826:[.08556,.58556,0,0,.89444],8827:[.08556,.58556,0,0,.89444],8834:[.08556,.58556,0,0,.89444],8835:[.08556,.58556,0,0,.89444],8838:[.19667,.69667,0,0,.89444],8839:[.19667,.69667,0,0,.89444],8846:[0,.55556,0,0,.76666],8849:[.19667,.69667,0,0,.89444],8850:[.19667,.69667,0,0,.89444],8851:[0,.55556,0,0,.76666],8852:[0,.55556,0,0,.76666],8853:[.13333,.63333,0,0,.89444],8854:[.13333,.63333,0,0,.89444],8855:[.13333,.63333,0,0,.89444],8856:[.13333,.63333,0,0,.89444],8857:[.13333,.63333,0,0,.89444],8866:[0,.69444,0,0,.70277],8867:[0,.69444,0,0,.70277],8868:[0,.69444,0,0,.89444],8869:[0,.69444,0,0,.89444],8900:[-.02639,.47361,0,0,.575],8901:[-.02639,.47361,0,0,.31944],8902:[-.02778,.47222,0,0,.575],8968:[.25,.75,0,0,.51111],8969:[.25,.75,0,0,.51111],8970:[.25,.75,0,0,.51111],8971:[.25,.75,0,0,.51111],8994:[-.13889,.36111,0,0,1.14999],8995:[-.13889,.36111,0,0,1.14999],9651:[.19444,.69444,0,0,1.02222],9657:[-.02778,.47222,0,0,.575],9661:[.19444,.69444,0,0,1.02222],9667:[-.02778,.47222,0,0,.575],9711:[.19444,.69444,0,0,1.14999],9824:[.12963,.69444,0,0,.89444],9825:[.12963,.69444,0,0,.89444],9826:[.12963,.69444,0,0,.89444],9827:[.12963,.69444,0,0,.89444],9837:[0,.75,0,0,.44722],9838:[.19444,.69444,0,0,.44722],9839:[.19444,.69444,0,0,.44722],10216:[.25,.75,0,0,.44722],10217:[.25,.75,0,0,.44722],10815:[0,.68611,0,0,.9],10927:[.19667,.69667,0,0,.89444],10928:[.19667,.69667,0,0,.89444],57376:[.19444,.69444,0,0,0]},"Main-BoldItalic":{32:[0,0,0,0,.25],33:[0,.69444,.11417,0,.38611],34:[0,.69444,.07939,0,.62055],35:[.19444,.69444,.06833,0,.94444],37:[.05556,.75,.12861,0,.94444],38:[0,.69444,.08528,0,.88555],39:[0,.69444,.12945,0,.35555],40:[.25,.75,.15806,0,.47333],41:[.25,.75,.03306,0,.47333],42:[0,.75,.14333,0,.59111],43:[.10333,.60333,.03306,0,.88555],44:[.19444,.14722,0,0,.35555],45:[0,.44444,.02611,0,.41444],46:[0,.14722,0,0,.35555],47:[.25,.75,.15806,0,.59111],48:[0,.64444,.13167,0,.59111],49:[0,.64444,.13167,0,.59111],50:[0,.64444,.13167,0,.59111],51:[0,.64444,.13167,0,.59111],52:[.19444,.64444,.13167,0,.59111],53:[0,.64444,.13167,0,.59111],54:[0,.64444,.13167,0,.59111],55:[.19444,.64444,.13167,0,.59111],56:[0,.64444,.13167,0,.59111],57:[0,.64444,.13167,0,.59111],58:[0,.44444,.06695,0,.35555],59:[.19444,.44444,.06695,0,.35555],61:[-.10889,.39111,.06833,0,.88555],63:[0,.69444,.11472,0,.59111],64:[0,.69444,.09208,0,.88555],65:[0,.68611,0,0,.86555],66:[0,.68611,.0992,0,.81666],67:[0,.68611,.14208,0,.82666],68:[0,.68611,.09062,0,.87555],69:[0,.68611,.11431,0,.75666],70:[0,.68611,.12903,0,.72722],71:[0,.68611,.07347,0,.89527],72:[0,.68611,.17208,0,.8961],73:[0,.68611,.15681,0,.47166],74:[0,.68611,.145,0,.61055],75:[0,.68611,.14208,0,.89499],76:[0,.68611,0,0,.69777],77:[0,.68611,.17208,0,1.07277],78:[0,.68611,.17208,0,.8961],79:[0,.68611,.09062,0,.85499],80:[0,.68611,.0992,0,.78721],81:[.19444,.68611,.09062,0,.85499],82:[0,.68611,.02559,0,.85944],83:[0,.68611,.11264,0,.64999],84:[0,.68611,.12903,0,.7961],85:[0,.68611,.17208,0,.88083],86:[0,.68611,.18625,0,.86555],87:[0,.68611,.18625,0,1.15999],88:[0,.68611,.15681,0,.86555],89:[0,.68611,.19803,0,.86555],90:[0,.68611,.14208,0,.70888],91:[.25,.75,.1875,0,.35611],93:[.25,.75,.09972,0,.35611],94:[0,.69444,.06709,0,.59111],95:[.31,.13444,.09811,0,.59111],97:[0,.44444,.09426,0,.59111],98:[0,.69444,.07861,0,.53222],99:[0,.44444,.05222,0,.53222],100:[0,.69444,.10861,0,.59111],101:[0,.44444,.085,0,.53222],102:[.19444,.69444,.21778,0,.4],103:[.19444,.44444,.105,0,.53222],104:[0,.69444,.09426,0,.59111],105:[0,.69326,.11387,0,.35555],106:[.19444,.69326,.1672,0,.35555],107:[0,.69444,.11111,0,.53222],108:[0,.69444,.10861,0,.29666],109:[0,.44444,.09426,0,.94444],110:[0,.44444,.09426,0,.64999],111:[0,.44444,.07861,0,.59111],112:[.19444,.44444,.07861,0,.59111],113:[.19444,.44444,.105,0,.53222],114:[0,.44444,.11111,0,.50167],115:[0,.44444,.08167,0,.48694],116:[0,.63492,.09639,0,.385],117:[0,.44444,.09426,0,.62055],118:[0,.44444,.11111,0,.53222],119:[0,.44444,.11111,0,.76777],120:[0,.44444,.12583,0,.56055],121:[.19444,.44444,.105,0,.56166],122:[0,.44444,.13889,0,.49055],126:[.35,.34444,.11472,0,.59111],160:[0,0,0,0,.25],168:[0,.69444,.11473,0,.59111],176:[0,.69444,0,0,.94888],184:[.17014,0,0,0,.53222],198:[0,.68611,.11431,0,1.02277],216:[.04861,.73472,.09062,0,.88555],223:[.19444,.69444,.09736,0,.665],230:[0,.44444,.085,0,.82666],248:[.09722,.54167,.09458,0,.59111],305:[0,.44444,.09426,0,.35555],338:[0,.68611,.11431,0,1.14054],339:[0,.44444,.085,0,.82666],567:[.19444,.44444,.04611,0,.385],710:[0,.69444,.06709,0,.59111],711:[0,.63194,.08271,0,.59111],713:[0,.59444,.10444,0,.59111],714:[0,.69444,.08528,0,.59111],715:[0,.69444,0,0,.59111],728:[0,.69444,.10333,0,.59111],729:[0,.69444,.12945,0,.35555],730:[0,.69444,0,0,.94888],732:[0,.69444,.11472,0,.59111],733:[0,.69444,.11472,0,.59111],915:[0,.68611,.12903,0,.69777],916:[0,.68611,0,0,.94444],920:[0,.68611,.09062,0,.88555],923:[0,.68611,0,0,.80666],926:[0,.68611,.15092,0,.76777],928:[0,.68611,.17208,0,.8961],931:[0,.68611,.11431,0,.82666],933:[0,.68611,.10778,0,.88555],934:[0,.68611,.05632,0,.82666],936:[0,.68611,.10778,0,.88555],937:[0,.68611,.0992,0,.82666],8211:[0,.44444,.09811,0,.59111],8212:[0,.44444,.09811,0,1.18221],8216:[0,.69444,.12945,0,.35555],8217:[0,.69444,.12945,0,.35555],8220:[0,.69444,.16772,0,.62055],8221:[0,.69444,.07939,0,.62055]},"Main-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.12417,0,.30667],34:[0,.69444,.06961,0,.51444],35:[.19444,.69444,.06616,0,.81777],37:[.05556,.75,.13639,0,.81777],38:[0,.69444,.09694,0,.76666],39:[0,.69444,.12417,0,.30667],40:[.25,.75,.16194,0,.40889],41:[.25,.75,.03694,0,.40889],42:[0,.75,.14917,0,.51111],43:[.05667,.56167,.03694,0,.76666],44:[.19444,.10556,0,0,.30667],45:[0,.43056,.02826,0,.35778],46:[0,.10556,0,0,.30667],47:[.25,.75,.16194,0,.51111],48:[0,.64444,.13556,0,.51111],49:[0,.64444,.13556,0,.51111],50:[0,.64444,.13556,0,.51111],51:[0,.64444,.13556,0,.51111],52:[.19444,.64444,.13556,0,.51111],53:[0,.64444,.13556,0,.51111],54:[0,.64444,.13556,0,.51111],55:[.19444,.64444,.13556,0,.51111],56:[0,.64444,.13556,0,.51111],57:[0,.64444,.13556,0,.51111],58:[0,.43056,.0582,0,.30667],59:[.19444,.43056,.0582,0,.30667],61:[-.13313,.36687,.06616,0,.76666],63:[0,.69444,.1225,0,.51111],64:[0,.69444,.09597,0,.76666],65:[0,.68333,0,0,.74333],66:[0,.68333,.10257,0,.70389],67:[0,.68333,.14528,0,.71555],68:[0,.68333,.09403,0,.755],69:[0,.68333,.12028,0,.67833],70:[0,.68333,.13305,0,.65277],71:[0,.68333,.08722,0,.77361],72:[0,.68333,.16389,0,.74333],73:[0,.68333,.15806,0,.38555],74:[0,.68333,.14028,0,.525],75:[0,.68333,.14528,0,.76888],76:[0,.68333,0,0,.62722],77:[0,.68333,.16389,0,.89666],78:[0,.68333,.16389,0,.74333],79:[0,.68333,.09403,0,.76666],80:[0,.68333,.10257,0,.67833],81:[.19444,.68333,.09403,0,.76666],82:[0,.68333,.03868,0,.72944],83:[0,.68333,.11972,0,.56222],84:[0,.68333,.13305,0,.71555],85:[0,.68333,.16389,0,.74333],86:[0,.68333,.18361,0,.74333],87:[0,.68333,.18361,0,.99888],88:[0,.68333,.15806,0,.74333],89:[0,.68333,.19383,0,.74333],90:[0,.68333,.14528,0,.61333],91:[.25,.75,.1875,0,.30667],93:[.25,.75,.10528,0,.30667],94:[0,.69444,.06646,0,.51111],95:[.31,.12056,.09208,0,.51111],97:[0,.43056,.07671,0,.51111],98:[0,.69444,.06312,0,.46],99:[0,.43056,.05653,0,.46],100:[0,.69444,.10333,0,.51111],101:[0,.43056,.07514,0,.46],102:[.19444,.69444,.21194,0,.30667],103:[.19444,.43056,.08847,0,.46],104:[0,.69444,.07671,0,.51111],105:[0,.65536,.1019,0,.30667],106:[.19444,.65536,.14467,0,.30667],107:[0,.69444,.10764,0,.46],108:[0,.69444,.10333,0,.25555],109:[0,.43056,.07671,0,.81777],110:[0,.43056,.07671,0,.56222],111:[0,.43056,.06312,0,.51111],112:[.19444,.43056,.06312,0,.51111],113:[.19444,.43056,.08847,0,.46],114:[0,.43056,.10764,0,.42166],115:[0,.43056,.08208,0,.40889],116:[0,.61508,.09486,0,.33222],117:[0,.43056,.07671,0,.53666],118:[0,.43056,.10764,0,.46],119:[0,.43056,.10764,0,.66444],120:[0,.43056,.12042,0,.46389],121:[.19444,.43056,.08847,0,.48555],122:[0,.43056,.12292,0,.40889],126:[.35,.31786,.11585,0,.51111],160:[0,0,0,0,.25],168:[0,.66786,.10474,0,.51111],176:[0,.69444,0,0,.83129],184:[.17014,0,0,0,.46],198:[0,.68333,.12028,0,.88277],216:[.04861,.73194,.09403,0,.76666],223:[.19444,.69444,.10514,0,.53666],230:[0,.43056,.07514,0,.71555],248:[.09722,.52778,.09194,0,.51111],338:[0,.68333,.12028,0,.98499],339:[0,.43056,.07514,0,.71555],710:[0,.69444,.06646,0,.51111],711:[0,.62847,.08295,0,.51111],713:[0,.56167,.10333,0,.51111],714:[0,.69444,.09694,0,.51111],715:[0,.69444,0,0,.51111],728:[0,.69444,.10806,0,.51111],729:[0,.66786,.11752,0,.30667],730:[0,.69444,0,0,.83129],732:[0,.66786,.11585,0,.51111],733:[0,.69444,.1225,0,.51111],915:[0,.68333,.13305,0,.62722],916:[0,.68333,0,0,.81777],920:[0,.68333,.09403,0,.76666],923:[0,.68333,0,0,.69222],926:[0,.68333,.15294,0,.66444],928:[0,.68333,.16389,0,.74333],931:[0,.68333,.12028,0,.71555],933:[0,.68333,.11111,0,.76666],934:[0,.68333,.05986,0,.71555],936:[0,.68333,.11111,0,.76666],937:[0,.68333,.10257,0,.71555],8211:[0,.43056,.09208,0,.51111],8212:[0,.43056,.09208,0,1.02222],8216:[0,.69444,.12417,0,.30667],8217:[0,.69444,.12417,0,.30667],8220:[0,.69444,.1685,0,.51444],8221:[0,.69444,.06961,0,.51444],8463:[0,.68889,0,0,.54028]},"Main-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.27778],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.77778],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.19444,.10556,0,0,.27778],45:[0,.43056,0,0,.33333],46:[0,.10556,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.64444,0,0,.5],49:[0,.64444,0,0,.5],50:[0,.64444,0,0,.5],51:[0,.64444,0,0,.5],52:[0,.64444,0,0,.5],53:[0,.64444,0,0,.5],54:[0,.64444,0,0,.5],55:[0,.64444,0,0,.5],56:[0,.64444,0,0,.5],57:[0,.64444,0,0,.5],58:[0,.43056,0,0,.27778],59:[.19444,.43056,0,0,.27778],60:[.0391,.5391,0,0,.77778],61:[-.13313,.36687,0,0,.77778],62:[.0391,.5391,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.77778],65:[0,.68333,0,0,.75],66:[0,.68333,0,0,.70834],67:[0,.68333,0,0,.72222],68:[0,.68333,0,0,.76389],69:[0,.68333,0,0,.68056],70:[0,.68333,0,0,.65278],71:[0,.68333,0,0,.78472],72:[0,.68333,0,0,.75],73:[0,.68333,0,0,.36111],74:[0,.68333,0,0,.51389],75:[0,.68333,0,0,.77778],76:[0,.68333,0,0,.625],77:[0,.68333,0,0,.91667],78:[0,.68333,0,0,.75],79:[0,.68333,0,0,.77778],80:[0,.68333,0,0,.68056],81:[.19444,.68333,0,0,.77778],82:[0,.68333,0,0,.73611],83:[0,.68333,0,0,.55556],84:[0,.68333,0,0,.72222],85:[0,.68333,0,0,.75],86:[0,.68333,.01389,0,.75],87:[0,.68333,.01389,0,1.02778],88:[0,.68333,0,0,.75],89:[0,.68333,.025,0,.75],90:[0,.68333,0,0,.61111],91:[.25,.75,0,0,.27778],92:[.25,.75,0,0,.5],93:[.25,.75,0,0,.27778],94:[0,.69444,0,0,.5],95:[.31,.12056,.02778,0,.5],97:[0,.43056,0,0,.5],98:[0,.69444,0,0,.55556],99:[0,.43056,0,0,.44445],100:[0,.69444,0,0,.55556],101:[0,.43056,0,0,.44445],102:[0,.69444,.07778,0,.30556],103:[.19444,.43056,.01389,0,.5],104:[0,.69444,0,0,.55556],105:[0,.66786,0,0,.27778],106:[.19444,.66786,0,0,.30556],107:[0,.69444,0,0,.52778],108:[0,.69444,0,0,.27778],109:[0,.43056,0,0,.83334],110:[0,.43056,0,0,.55556],111:[0,.43056,0,0,.5],112:[.19444,.43056,0,0,.55556],113:[.19444,.43056,0,0,.52778],114:[0,.43056,0,0,.39167],115:[0,.43056,0,0,.39445],116:[0,.61508,0,0,.38889],117:[0,.43056,0,0,.55556],118:[0,.43056,.01389,0,.52778],119:[0,.43056,.01389,0,.72222],120:[0,.43056,0,0,.52778],121:[.19444,.43056,.01389,0,.52778],122:[0,.43056,0,0,.44445],123:[.25,.75,0,0,.5],124:[.25,.75,0,0,.27778],125:[.25,.75,0,0,.5],126:[.35,.31786,0,0,.5],160:[0,0,0,0,.25],163:[0,.69444,0,0,.76909],167:[.19444,.69444,0,0,.44445],168:[0,.66786,0,0,.5],172:[0,.43056,0,0,.66667],176:[0,.69444,0,0,.75],177:[.08333,.58333,0,0,.77778],182:[.19444,.69444,0,0,.61111],184:[.17014,0,0,0,.44445],198:[0,.68333,0,0,.90278],215:[.08333,.58333,0,0,.77778],216:[.04861,.73194,0,0,.77778],223:[0,.69444,0,0,.5],230:[0,.43056,0,0,.72222],247:[.08333,.58333,0,0,.77778],248:[.09722,.52778,0,0,.5],305:[0,.43056,0,0,.27778],338:[0,.68333,0,0,1.01389],339:[0,.43056,0,0,.77778],567:[.19444,.43056,0,0,.30556],710:[0,.69444,0,0,.5],711:[0,.62847,0,0,.5],713:[0,.56778,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.66786,0,0,.27778],730:[0,.69444,0,0,.75],732:[0,.66786,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.68333,0,0,.625],916:[0,.68333,0,0,.83334],920:[0,.68333,0,0,.77778],923:[0,.68333,0,0,.69445],926:[0,.68333,0,0,.66667],928:[0,.68333,0,0,.75],931:[0,.68333,0,0,.72222],933:[0,.68333,0,0,.77778],934:[0,.68333,0,0,.72222],936:[0,.68333,0,0,.77778],937:[0,.68333,0,0,.72222],8211:[0,.43056,.02778,0,.5],8212:[0,.43056,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5],8224:[.19444,.69444,0,0,.44445],8225:[.19444,.69444,0,0,.44445],8230:[0,.123,0,0,1.172],8242:[0,.55556,0,0,.275],8407:[0,.71444,.15382,0,.5],8463:[0,.68889,0,0,.54028],8465:[0,.69444,0,0,.72222],8467:[0,.69444,0,.11111,.41667],8472:[.19444,.43056,0,.11111,.63646],8476:[0,.69444,0,0,.72222],8501:[0,.69444,0,0,.61111],8592:[-.13313,.36687,0,0,1],8593:[.19444,.69444,0,0,.5],8594:[-.13313,.36687,0,0,1],8595:[.19444,.69444,0,0,.5],8596:[-.13313,.36687,0,0,1],8597:[.25,.75,0,0,.5],8598:[.19444,.69444,0,0,1],8599:[.19444,.69444,0,0,1],8600:[.19444,.69444,0,0,1],8601:[.19444,.69444,0,0,1],8614:[.011,.511,0,0,1],8617:[.011,.511,0,0,1.126],8618:[.011,.511,0,0,1.126],8636:[-.13313,.36687,0,0,1],8637:[-.13313,.36687,0,0,1],8640:[-.13313,.36687,0,0,1],8641:[-.13313,.36687,0,0,1],8652:[.011,.671,0,0,1],8656:[-.13313,.36687,0,0,1],8657:[.19444,.69444,0,0,.61111],8658:[-.13313,.36687,0,0,1],8659:[.19444,.69444,0,0,.61111],8660:[-.13313,.36687,0,0,1],8661:[.25,.75,0,0,.61111],8704:[0,.69444,0,0,.55556],8706:[0,.69444,.05556,.08334,.5309],8707:[0,.69444,0,0,.55556],8709:[.05556,.75,0,0,.5],8711:[0,.68333,0,0,.83334],8712:[.0391,.5391,0,0,.66667],8715:[.0391,.5391,0,0,.66667],8722:[.08333,.58333,0,0,.77778],8723:[.08333,.58333,0,0,.77778],8725:[.25,.75,0,0,.5],8726:[.25,.75,0,0,.5],8727:[-.03472,.46528,0,0,.5],8728:[-.05555,.44445,0,0,.5],8729:[-.05555,.44445,0,0,.5],8730:[.2,.8,0,0,.83334],8733:[0,.43056,0,0,.77778],8734:[0,.43056,0,0,1],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.27778],8741:[.25,.75,0,0,.5],8743:[0,.55556,0,0,.66667],8744:[0,.55556,0,0,.66667],8745:[0,.55556,0,0,.66667],8746:[0,.55556,0,0,.66667],8747:[.19444,.69444,.11111,0,.41667],8764:[-.13313,.36687,0,0,.77778],8768:[.19444,.69444,0,0,.27778],8771:[-.03625,.46375,0,0,.77778],8773:[-.022,.589,0,0,.778],8776:[-.01688,.48312,0,0,.77778],8781:[-.03625,.46375,0,0,.77778],8784:[-.133,.673,0,0,.778],8801:[-.03625,.46375,0,0,.77778],8804:[.13597,.63597,0,0,.77778],8805:[.13597,.63597,0,0,.77778],8810:[.0391,.5391,0,0,1],8811:[.0391,.5391,0,0,1],8826:[.0391,.5391,0,0,.77778],8827:[.0391,.5391,0,0,.77778],8834:[.0391,.5391,0,0,.77778],8835:[.0391,.5391,0,0,.77778],8838:[.13597,.63597,0,0,.77778],8839:[.13597,.63597,0,0,.77778],8846:[0,.55556,0,0,.66667],8849:[.13597,.63597,0,0,.77778],8850:[.13597,.63597,0,0,.77778],8851:[0,.55556,0,0,.66667],8852:[0,.55556,0,0,.66667],8853:[.08333,.58333,0,0,.77778],8854:[.08333,.58333,0,0,.77778],8855:[.08333,.58333,0,0,.77778],8856:[.08333,.58333,0,0,.77778],8857:[.08333,.58333,0,0,.77778],8866:[0,.69444,0,0,.61111],8867:[0,.69444,0,0,.61111],8868:[0,.69444,0,0,.77778],8869:[0,.69444,0,0,.77778],8872:[.249,.75,0,0,.867],8900:[-.05555,.44445,0,0,.5],8901:[-.05555,.44445,0,0,.27778],8902:[-.03472,.46528,0,0,.5],8904:[.005,.505,0,0,.9],8942:[.03,.903,0,0,.278],8943:[-.19,.313,0,0,1.172],8945:[-.1,.823,0,0,1.282],8968:[.25,.75,0,0,.44445],8969:[.25,.75,0,0,.44445],8970:[.25,.75,0,0,.44445],8971:[.25,.75,0,0,.44445],8994:[-.14236,.35764,0,0,1],8995:[-.14236,.35764,0,0,1],9136:[.244,.744,0,0,.412],9137:[.244,.745,0,0,.412],9651:[.19444,.69444,0,0,.88889],9657:[-.03472,.46528,0,0,.5],9661:[.19444,.69444,0,0,.88889],9667:[-.03472,.46528,0,0,.5],9711:[.19444,.69444,0,0,1],9824:[.12963,.69444,0,0,.77778],9825:[.12963,.69444,0,0,.77778],9826:[.12963,.69444,0,0,.77778],9827:[.12963,.69444,0,0,.77778],9837:[0,.75,0,0,.38889],9838:[.19444,.69444,0,0,.38889],9839:[.19444,.69444,0,0,.38889],10216:[.25,.75,0,0,.38889],10217:[.25,.75,0,0,.38889],10222:[.244,.744,0,0,.412],10223:[.244,.745,0,0,.412],10229:[.011,.511,0,0,1.609],10230:[.011,.511,0,0,1.638],10231:[.011,.511,0,0,1.859],10232:[.024,.525,0,0,1.609],10233:[.024,.525,0,0,1.638],10234:[.024,.525,0,0,1.858],10236:[.011,.511,0,0,1.638],10815:[0,.68333,0,0,.75],10927:[.13597,.63597,0,0,.77778],10928:[.13597,.63597,0,0,.77778],57376:[.19444,.69444,0,0,0]},"Math-BoldItalic":{32:[0,0,0,0,.25],48:[0,.44444,0,0,.575],49:[0,.44444,0,0,.575],50:[0,.44444,0,0,.575],51:[.19444,.44444,0,0,.575],52:[.19444,.44444,0,0,.575],53:[.19444,.44444,0,0,.575],54:[0,.64444,0,0,.575],55:[.19444,.44444,0,0,.575],56:[0,.64444,0,0,.575],57:[.19444,.44444,0,0,.575],65:[0,.68611,0,0,.86944],66:[0,.68611,.04835,0,.8664],67:[0,.68611,.06979,0,.81694],68:[0,.68611,.03194,0,.93812],69:[0,.68611,.05451,0,.81007],70:[0,.68611,.15972,0,.68889],71:[0,.68611,0,0,.88673],72:[0,.68611,.08229,0,.98229],73:[0,.68611,.07778,0,.51111],74:[0,.68611,.10069,0,.63125],75:[0,.68611,.06979,0,.97118],76:[0,.68611,0,0,.75555],77:[0,.68611,.11424,0,1.14201],78:[0,.68611,.11424,0,.95034],79:[0,.68611,.03194,0,.83666],80:[0,.68611,.15972,0,.72309],81:[.19444,.68611,0,0,.86861],82:[0,.68611,.00421,0,.87235],83:[0,.68611,.05382,0,.69271],84:[0,.68611,.15972,0,.63663],85:[0,.68611,.11424,0,.80027],86:[0,.68611,.25555,0,.67778],87:[0,.68611,.15972,0,1.09305],88:[0,.68611,.07778,0,.94722],89:[0,.68611,.25555,0,.67458],90:[0,.68611,.06979,0,.77257],97:[0,.44444,0,0,.63287],98:[0,.69444,0,0,.52083],99:[0,.44444,0,0,.51342],100:[0,.69444,0,0,.60972],101:[0,.44444,0,0,.55361],102:[.19444,.69444,.11042,0,.56806],103:[.19444,.44444,.03704,0,.5449],104:[0,.69444,0,0,.66759],105:[0,.69326,0,0,.4048],106:[.19444,.69326,.0622,0,.47083],107:[0,.69444,.01852,0,.6037],108:[0,.69444,.0088,0,.34815],109:[0,.44444,0,0,1.0324],110:[0,.44444,0,0,.71296],111:[0,.44444,0,0,.58472],112:[.19444,.44444,0,0,.60092],113:[.19444,.44444,.03704,0,.54213],114:[0,.44444,.03194,0,.5287],115:[0,.44444,0,0,.53125],116:[0,.63492,0,0,.41528],117:[0,.44444,0,0,.68102],118:[0,.44444,.03704,0,.56666],119:[0,.44444,.02778,0,.83148],120:[0,.44444,0,0,.65903],121:[.19444,.44444,.03704,0,.59028],122:[0,.44444,.04213,0,.55509],160:[0,0,0,0,.25],915:[0,.68611,.15972,0,.65694],916:[0,.68611,0,0,.95833],920:[0,.68611,.03194,0,.86722],923:[0,.68611,0,0,.80555],926:[0,.68611,.07458,0,.84125],928:[0,.68611,.08229,0,.98229],931:[0,.68611,.05451,0,.88507],933:[0,.68611,.15972,0,.67083],934:[0,.68611,0,0,.76666],936:[0,.68611,.11653,0,.71402],937:[0,.68611,.04835,0,.8789],945:[0,.44444,0,0,.76064],946:[.19444,.69444,.03403,0,.65972],947:[.19444,.44444,.06389,0,.59003],948:[0,.69444,.03819,0,.52222],949:[0,.44444,0,0,.52882],950:[.19444,.69444,.06215,0,.50833],951:[.19444,.44444,.03704,0,.6],952:[0,.69444,.03194,0,.5618],953:[0,.44444,0,0,.41204],954:[0,.44444,0,0,.66759],955:[0,.69444,0,0,.67083],956:[.19444,.44444,0,0,.70787],957:[0,.44444,.06898,0,.57685],958:[.19444,.69444,.03021,0,.50833],959:[0,.44444,0,0,.58472],960:[0,.44444,.03704,0,.68241],961:[.19444,.44444,0,0,.6118],962:[.09722,.44444,.07917,0,.42361],963:[0,.44444,.03704,0,.68588],964:[0,.44444,.13472,0,.52083],965:[0,.44444,.03704,0,.63055],966:[.19444,.44444,0,0,.74722],967:[.19444,.44444,0,0,.71805],968:[.19444,.69444,.03704,0,.75833],969:[0,.44444,.03704,0,.71782],977:[0,.69444,0,0,.69155],981:[.19444,.69444,0,0,.7125],982:[0,.44444,.03194,0,.975],1009:[.19444,.44444,0,0,.6118],1013:[0,.44444,0,0,.48333],57649:[0,.44444,0,0,.39352],57911:[.19444,.44444,0,0,.43889]},"Math-Italic":{32:[0,0,0,0,.25],48:[0,.43056,0,0,.5],49:[0,.43056,0,0,.5],50:[0,.43056,0,0,.5],51:[.19444,.43056,0,0,.5],52:[.19444,.43056,0,0,.5],53:[.19444,.43056,0,0,.5],54:[0,.64444,0,0,.5],55:[.19444,.43056,0,0,.5],56:[0,.64444,0,0,.5],57:[.19444,.43056,0,0,.5],65:[0,.68333,0,.13889,.75],66:[0,.68333,.05017,.08334,.75851],67:[0,.68333,.07153,.08334,.71472],68:[0,.68333,.02778,.05556,.82792],69:[0,.68333,.05764,.08334,.7382],70:[0,.68333,.13889,.08334,.64306],71:[0,.68333,0,.08334,.78625],72:[0,.68333,.08125,.05556,.83125],73:[0,.68333,.07847,.11111,.43958],74:[0,.68333,.09618,.16667,.55451],75:[0,.68333,.07153,.05556,.84931],76:[0,.68333,0,.02778,.68056],77:[0,.68333,.10903,.08334,.97014],78:[0,.68333,.10903,.08334,.80347],79:[0,.68333,.02778,.08334,.76278],80:[0,.68333,.13889,.08334,.64201],81:[.19444,.68333,0,.08334,.79056],82:[0,.68333,.00773,.08334,.75929],83:[0,.68333,.05764,.08334,.6132],84:[0,.68333,.13889,.08334,.58438],85:[0,.68333,.10903,.02778,.68278],86:[0,.68333,.22222,0,.58333],87:[0,.68333,.13889,0,.94445],88:[0,.68333,.07847,.08334,.82847],89:[0,.68333,.22222,0,.58056],90:[0,.68333,.07153,.08334,.68264],97:[0,.43056,0,0,.52859],98:[0,.69444,0,0,.42917],99:[0,.43056,0,.05556,.43276],100:[0,.69444,0,.16667,.52049],101:[0,.43056,0,.05556,.46563],102:[.19444,.69444,.10764,.16667,.48959],103:[.19444,.43056,.03588,.02778,.47697],104:[0,.69444,0,0,.57616],105:[0,.65952,0,0,.34451],106:[.19444,.65952,.05724,0,.41181],107:[0,.69444,.03148,0,.5206],108:[0,.69444,.01968,.08334,.29838],109:[0,.43056,0,0,.87801],110:[0,.43056,0,0,.60023],111:[0,.43056,0,.05556,.48472],112:[.19444,.43056,0,.08334,.50313],113:[.19444,.43056,.03588,.08334,.44641],114:[0,.43056,.02778,.05556,.45116],115:[0,.43056,0,.05556,.46875],116:[0,.61508,0,.08334,.36111],117:[0,.43056,0,.02778,.57246],118:[0,.43056,.03588,.02778,.48472],119:[0,.43056,.02691,.08334,.71592],120:[0,.43056,0,.02778,.57153],121:[.19444,.43056,.03588,.05556,.49028],122:[0,.43056,.04398,.05556,.46505],160:[0,0,0,0,.25],915:[0,.68333,.13889,.08334,.61528],916:[0,.68333,0,.16667,.83334],920:[0,.68333,.02778,.08334,.76278],923:[0,.68333,0,.16667,.69445],926:[0,.68333,.07569,.08334,.74236],928:[0,.68333,.08125,.05556,.83125],931:[0,.68333,.05764,.08334,.77986],933:[0,.68333,.13889,.05556,.58333],934:[0,.68333,0,.08334,.66667],936:[0,.68333,.11,.05556,.61222],937:[0,.68333,.05017,.08334,.7724],945:[0,.43056,.0037,.02778,.6397],946:[.19444,.69444,.05278,.08334,.56563],947:[.19444,.43056,.05556,0,.51773],948:[0,.69444,.03785,.05556,.44444],949:[0,.43056,0,.08334,.46632],950:[.19444,.69444,.07378,.08334,.4375],951:[.19444,.43056,.03588,.05556,.49653],952:[0,.69444,.02778,.08334,.46944],953:[0,.43056,0,.05556,.35394],954:[0,.43056,0,0,.57616],955:[0,.69444,0,0,.58334],956:[.19444,.43056,0,.02778,.60255],957:[0,.43056,.06366,.02778,.49398],958:[.19444,.69444,.04601,.11111,.4375],959:[0,.43056,0,.05556,.48472],960:[0,.43056,.03588,0,.57003],961:[.19444,.43056,0,.08334,.51702],962:[.09722,.43056,.07986,.08334,.36285],963:[0,.43056,.03588,0,.57141],964:[0,.43056,.1132,.02778,.43715],965:[0,.43056,.03588,.02778,.54028],966:[.19444,.43056,0,.08334,.65417],967:[.19444,.43056,0,.05556,.62569],968:[.19444,.69444,.03588,.11111,.65139],969:[0,.43056,.03588,0,.62245],977:[0,.69444,0,.08334,.59144],981:[.19444,.69444,0,.08334,.59583],982:[0,.43056,.02778,0,.82813],1009:[.19444,.43056,0,.08334,.51702],1013:[0,.43056,0,.05556,.4059],57649:[0,.43056,0,.02778,.32246],57911:[.19444,.43056,0,.08334,.38403]},"SansSerif-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.36667],34:[0,.69444,0,0,.55834],35:[.19444,.69444,0,0,.91667],36:[.05556,.75,0,0,.55],37:[.05556,.75,0,0,1.02912],38:[0,.69444,0,0,.83056],39:[0,.69444,0,0,.30556],40:[.25,.75,0,0,.42778],41:[.25,.75,0,0,.42778],42:[0,.75,0,0,.55],43:[.11667,.61667,0,0,.85556],44:[.10556,.13056,0,0,.30556],45:[0,.45833,0,0,.36667],46:[0,.13056,0,0,.30556],47:[.25,.75,0,0,.55],48:[0,.69444,0,0,.55],49:[0,.69444,0,0,.55],50:[0,.69444,0,0,.55],51:[0,.69444,0,0,.55],52:[0,.69444,0,0,.55],53:[0,.69444,0,0,.55],54:[0,.69444,0,0,.55],55:[0,.69444,0,0,.55],56:[0,.69444,0,0,.55],57:[0,.69444,0,0,.55],58:[0,.45833,0,0,.30556],59:[.10556,.45833,0,0,.30556],61:[-.09375,.40625,0,0,.85556],63:[0,.69444,0,0,.51945],64:[0,.69444,0,0,.73334],65:[0,.69444,0,0,.73334],66:[0,.69444,0,0,.73334],67:[0,.69444,0,0,.70278],68:[0,.69444,0,0,.79445],69:[0,.69444,0,0,.64167],70:[0,.69444,0,0,.61111],71:[0,.69444,0,0,.73334],72:[0,.69444,0,0,.79445],73:[0,.69444,0,0,.33056],74:[0,.69444,0,0,.51945],75:[0,.69444,0,0,.76389],76:[0,.69444,0,0,.58056],77:[0,.69444,0,0,.97778],78:[0,.69444,0,0,.79445],79:[0,.69444,0,0,.79445],80:[0,.69444,0,0,.70278],81:[.10556,.69444,0,0,.79445],82:[0,.69444,0,0,.70278],83:[0,.69444,0,0,.61111],84:[0,.69444,0,0,.73334],85:[0,.69444,0,0,.76389],86:[0,.69444,.01528,0,.73334],87:[0,.69444,.01528,0,1.03889],88:[0,.69444,0,0,.73334],89:[0,.69444,.0275,0,.73334],90:[0,.69444,0,0,.67223],91:[.25,.75,0,0,.34306],93:[.25,.75,0,0,.34306],94:[0,.69444,0,0,.55],95:[.35,.10833,.03056,0,.55],97:[0,.45833,0,0,.525],98:[0,.69444,0,0,.56111],99:[0,.45833,0,0,.48889],100:[0,.69444,0,0,.56111],101:[0,.45833,0,0,.51111],102:[0,.69444,.07639,0,.33611],103:[.19444,.45833,.01528,0,.55],104:[0,.69444,0,0,.56111],105:[0,.69444,0,0,.25556],106:[.19444,.69444,0,0,.28611],107:[0,.69444,0,0,.53056],108:[0,.69444,0,0,.25556],109:[0,.45833,0,0,.86667],110:[0,.45833,0,0,.56111],111:[0,.45833,0,0,.55],112:[.19444,.45833,0,0,.56111],113:[.19444,.45833,0,0,.56111],114:[0,.45833,.01528,0,.37222],115:[0,.45833,0,0,.42167],116:[0,.58929,0,0,.40417],117:[0,.45833,0,0,.56111],118:[0,.45833,.01528,0,.5],119:[0,.45833,.01528,0,.74445],120:[0,.45833,0,0,.5],121:[.19444,.45833,.01528,0,.5],122:[0,.45833,0,0,.47639],126:[.35,.34444,0,0,.55],160:[0,0,0,0,.25],168:[0,.69444,0,0,.55],176:[0,.69444,0,0,.73334],180:[0,.69444,0,0,.55],184:[.17014,0,0,0,.48889],305:[0,.45833,0,0,.25556],567:[.19444,.45833,0,0,.28611],710:[0,.69444,0,0,.55],711:[0,.63542,0,0,.55],713:[0,.63778,0,0,.55],728:[0,.69444,0,0,.55],729:[0,.69444,0,0,.30556],730:[0,.69444,0,0,.73334],732:[0,.69444,0,0,.55],733:[0,.69444,0,0,.55],915:[0,.69444,0,0,.58056],916:[0,.69444,0,0,.91667],920:[0,.69444,0,0,.85556],923:[0,.69444,0,0,.67223],926:[0,.69444,0,0,.73334],928:[0,.69444,0,0,.79445],931:[0,.69444,0,0,.79445],933:[0,.69444,0,0,.85556],934:[0,.69444,0,0,.79445],936:[0,.69444,0,0,.85556],937:[0,.69444,0,0,.79445],8211:[0,.45833,.03056,0,.55],8212:[0,.45833,.03056,0,1.10001],8216:[0,.69444,0,0,.30556],8217:[0,.69444,0,0,.30556],8220:[0,.69444,0,0,.55834],8221:[0,.69444,0,0,.55834]},"SansSerif-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.05733,0,.31945],34:[0,.69444,.00316,0,.5],35:[.19444,.69444,.05087,0,.83334],36:[.05556,.75,.11156,0,.5],37:[.05556,.75,.03126,0,.83334],38:[0,.69444,.03058,0,.75834],39:[0,.69444,.07816,0,.27778],40:[.25,.75,.13164,0,.38889],41:[.25,.75,.02536,0,.38889],42:[0,.75,.11775,0,.5],43:[.08333,.58333,.02536,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,.01946,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,.13164,0,.5],48:[0,.65556,.11156,0,.5],49:[0,.65556,.11156,0,.5],50:[0,.65556,.11156,0,.5],51:[0,.65556,.11156,0,.5],52:[0,.65556,.11156,0,.5],53:[0,.65556,.11156,0,.5],54:[0,.65556,.11156,0,.5],55:[0,.65556,.11156,0,.5],56:[0,.65556,.11156,0,.5],57:[0,.65556,.11156,0,.5],58:[0,.44444,.02502,0,.27778],59:[.125,.44444,.02502,0,.27778],61:[-.13,.37,.05087,0,.77778],63:[0,.69444,.11809,0,.47222],64:[0,.69444,.07555,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,.08293,0,.66667],67:[0,.69444,.11983,0,.63889],68:[0,.69444,.07555,0,.72223],69:[0,.69444,.11983,0,.59722],70:[0,.69444,.13372,0,.56945],71:[0,.69444,.11983,0,.66667],72:[0,.69444,.08094,0,.70834],73:[0,.69444,.13372,0,.27778],74:[0,.69444,.08094,0,.47222],75:[0,.69444,.11983,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,.08094,0,.875],78:[0,.69444,.08094,0,.70834],79:[0,.69444,.07555,0,.73611],80:[0,.69444,.08293,0,.63889],81:[.125,.69444,.07555,0,.73611],82:[0,.69444,.08293,0,.64584],83:[0,.69444,.09205,0,.55556],84:[0,.69444,.13372,0,.68056],85:[0,.69444,.08094,0,.6875],86:[0,.69444,.1615,0,.66667],87:[0,.69444,.1615,0,.94445],88:[0,.69444,.13372,0,.66667],89:[0,.69444,.17261,0,.66667],90:[0,.69444,.11983,0,.61111],91:[.25,.75,.15942,0,.28889],93:[.25,.75,.08719,0,.28889],94:[0,.69444,.0799,0,.5],95:[.35,.09444,.08616,0,.5],97:[0,.44444,.00981,0,.48056],98:[0,.69444,.03057,0,.51667],99:[0,.44444,.08336,0,.44445],100:[0,.69444,.09483,0,.51667],101:[0,.44444,.06778,0,.44445],102:[0,.69444,.21705,0,.30556],103:[.19444,.44444,.10836,0,.5],104:[0,.69444,.01778,0,.51667],105:[0,.67937,.09718,0,.23889],106:[.19444,.67937,.09162,0,.26667],107:[0,.69444,.08336,0,.48889],108:[0,.69444,.09483,0,.23889],109:[0,.44444,.01778,0,.79445],110:[0,.44444,.01778,0,.51667],111:[0,.44444,.06613,0,.5],112:[.19444,.44444,.0389,0,.51667],113:[.19444,.44444,.04169,0,.51667],114:[0,.44444,.10836,0,.34167],115:[0,.44444,.0778,0,.38333],116:[0,.57143,.07225,0,.36111],117:[0,.44444,.04169,0,.51667],118:[0,.44444,.10836,0,.46111],119:[0,.44444,.10836,0,.68334],120:[0,.44444,.09169,0,.46111],121:[.19444,.44444,.10836,0,.46111],122:[0,.44444,.08752,0,.43472],126:[.35,.32659,.08826,0,.5],160:[0,0,0,0,.25],168:[0,.67937,.06385,0,.5],176:[0,.69444,0,0,.73752],184:[.17014,0,0,0,.44445],305:[0,.44444,.04169,0,.23889],567:[.19444,.44444,.04169,0,.26667],710:[0,.69444,.0799,0,.5],711:[0,.63194,.08432,0,.5],713:[0,.60889,.08776,0,.5],714:[0,.69444,.09205,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,.09483,0,.5],729:[0,.67937,.07774,0,.27778],730:[0,.69444,0,0,.73752],732:[0,.67659,.08826,0,.5],733:[0,.69444,.09205,0,.5],915:[0,.69444,.13372,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,.07555,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,.12816,0,.66667],928:[0,.69444,.08094,0,.70834],931:[0,.69444,.11983,0,.72222],933:[0,.69444,.09031,0,.77778],934:[0,.69444,.04603,0,.72222],936:[0,.69444,.09031,0,.77778],937:[0,.69444,.08293,0,.72222],8211:[0,.44444,.08616,0,.5],8212:[0,.44444,.08616,0,1],8216:[0,.69444,.07816,0,.27778],8217:[0,.69444,.07816,0,.27778],8220:[0,.69444,.14205,0,.5],8221:[0,.69444,.00316,0,.5]},"SansSerif-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.31945],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.75834],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,0,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.65556,0,0,.5],49:[0,.65556,0,0,.5],50:[0,.65556,0,0,.5],51:[0,.65556,0,0,.5],52:[0,.65556,0,0,.5],53:[0,.65556,0,0,.5],54:[0,.65556,0,0,.5],55:[0,.65556,0,0,.5],56:[0,.65556,0,0,.5],57:[0,.65556,0,0,.5],58:[0,.44444,0,0,.27778],59:[.125,.44444,0,0,.27778],61:[-.13,.37,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,0,0,.66667],67:[0,.69444,0,0,.63889],68:[0,.69444,0,0,.72223],69:[0,.69444,0,0,.59722],70:[0,.69444,0,0,.56945],71:[0,.69444,0,0,.66667],72:[0,.69444,0,0,.70834],73:[0,.69444,0,0,.27778],74:[0,.69444,0,0,.47222],75:[0,.69444,0,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,0,0,.875],78:[0,.69444,0,0,.70834],79:[0,.69444,0,0,.73611],80:[0,.69444,0,0,.63889],81:[.125,.69444,0,0,.73611],82:[0,.69444,0,0,.64584],83:[0,.69444,0,0,.55556],84:[0,.69444,0,0,.68056],85:[0,.69444,0,0,.6875],86:[0,.69444,.01389,0,.66667],87:[0,.69444,.01389,0,.94445],88:[0,.69444,0,0,.66667],89:[0,.69444,.025,0,.66667],90:[0,.69444,0,0,.61111],91:[.25,.75,0,0,.28889],93:[.25,.75,0,0,.28889],94:[0,.69444,0,0,.5],95:[.35,.09444,.02778,0,.5],97:[0,.44444,0,0,.48056],98:[0,.69444,0,0,.51667],99:[0,.44444,0,0,.44445],100:[0,.69444,0,0,.51667],101:[0,.44444,0,0,.44445],102:[0,.69444,.06944,0,.30556],103:[.19444,.44444,.01389,0,.5],104:[0,.69444,0,0,.51667],105:[0,.67937,0,0,.23889],106:[.19444,.67937,0,0,.26667],107:[0,.69444,0,0,.48889],108:[0,.69444,0,0,.23889],109:[0,.44444,0,0,.79445],110:[0,.44444,0,0,.51667],111:[0,.44444,0,0,.5],112:[.19444,.44444,0,0,.51667],113:[.19444,.44444,0,0,.51667],114:[0,.44444,.01389,0,.34167],115:[0,.44444,0,0,.38333],116:[0,.57143,0,0,.36111],117:[0,.44444,0,0,.51667],118:[0,.44444,.01389,0,.46111],119:[0,.44444,.01389,0,.68334],120:[0,.44444,0,0,.46111],121:[.19444,.44444,.01389,0,.46111],122:[0,.44444,0,0,.43472],126:[.35,.32659,0,0,.5],160:[0,0,0,0,.25],168:[0,.67937,0,0,.5],176:[0,.69444,0,0,.66667],184:[.17014,0,0,0,.44445],305:[0,.44444,0,0,.23889],567:[.19444,.44444,0,0,.26667],710:[0,.69444,0,0,.5],711:[0,.63194,0,0,.5],713:[0,.60889,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.67937,0,0,.27778],730:[0,.69444,0,0,.66667],732:[0,.67659,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.69444,0,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,0,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,0,0,.66667],928:[0,.69444,0,0,.70834],931:[0,.69444,0,0,.72222],933:[0,.69444,0,0,.77778],934:[0,.69444,0,0,.72222],936:[0,.69444,0,0,.77778],937:[0,.69444,0,0,.72222],8211:[0,.44444,.02778,0,.5],8212:[0,.44444,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5]},"Script-Regular":{32:[0,0,0,0,.25],65:[0,.7,.22925,0,.80253],66:[0,.7,.04087,0,.90757],67:[0,.7,.1689,0,.66619],68:[0,.7,.09371,0,.77443],69:[0,.7,.18583,0,.56162],70:[0,.7,.13634,0,.89544],71:[0,.7,.17322,0,.60961],72:[0,.7,.29694,0,.96919],73:[0,.7,.19189,0,.80907],74:[.27778,.7,.19189,0,1.05159],75:[0,.7,.31259,0,.91364],76:[0,.7,.19189,0,.87373],77:[0,.7,.15981,0,1.08031],78:[0,.7,.3525,0,.9015],79:[0,.7,.08078,0,.73787],80:[0,.7,.08078,0,1.01262],81:[0,.7,.03305,0,.88282],82:[0,.7,.06259,0,.85],83:[0,.7,.19189,0,.86767],84:[0,.7,.29087,0,.74697],85:[0,.7,.25815,0,.79996],86:[0,.7,.27523,0,.62204],87:[0,.7,.27523,0,.80532],88:[0,.7,.26006,0,.94445],89:[0,.7,.2939,0,.70961],90:[0,.7,.24037,0,.8212],160:[0,0,0,0,.25]},"Size1-Regular":{32:[0,0,0,0,.25],40:[.35001,.85,0,0,.45834],41:[.35001,.85,0,0,.45834],47:[.35001,.85,0,0,.57778],91:[.35001,.85,0,0,.41667],92:[.35001,.85,0,0,.57778],93:[.35001,.85,0,0,.41667],123:[.35001,.85,0,0,.58334],125:[.35001,.85,0,0,.58334],160:[0,0,0,0,.25],710:[0,.72222,0,0,.55556],732:[0,.72222,0,0,.55556],770:[0,.72222,0,0,.55556],771:[0,.72222,0,0,.55556],8214:[-99e-5,.601,0,0,.77778],8593:[1e-5,.6,0,0,.66667],8595:[1e-5,.6,0,0,.66667],8657:[1e-5,.6,0,0,.77778],8659:[1e-5,.6,0,0,.77778],8719:[.25001,.75,0,0,.94445],8720:[.25001,.75,0,0,.94445],8721:[.25001,.75,0,0,1.05556],8730:[.35001,.85,0,0,1],8739:[-.00599,.606,0,0,.33333],8741:[-.00599,.606,0,0,.55556],8747:[.30612,.805,.19445,0,.47222],8748:[.306,.805,.19445,0,.47222],8749:[.306,.805,.19445,0,.47222],8750:[.30612,.805,.19445,0,.47222],8896:[.25001,.75,0,0,.83334],8897:[.25001,.75,0,0,.83334],8898:[.25001,.75,0,0,.83334],8899:[.25001,.75,0,0,.83334],8968:[.35001,.85,0,0,.47222],8969:[.35001,.85,0,0,.47222],8970:[.35001,.85,0,0,.47222],8971:[.35001,.85,0,0,.47222],9168:[-99e-5,.601,0,0,.66667],10216:[.35001,.85,0,0,.47222],10217:[.35001,.85,0,0,.47222],10752:[.25001,.75,0,0,1.11111],10753:[.25001,.75,0,0,1.11111],10754:[.25001,.75,0,0,1.11111],10756:[.25001,.75,0,0,.83334],10758:[.25001,.75,0,0,.83334]},"Size2-Regular":{32:[0,0,0,0,.25],40:[.65002,1.15,0,0,.59722],41:[.65002,1.15,0,0,.59722],47:[.65002,1.15,0,0,.81111],91:[.65002,1.15,0,0,.47222],92:[.65002,1.15,0,0,.81111],93:[.65002,1.15,0,0,.47222],123:[.65002,1.15,0,0,.66667],125:[.65002,1.15,0,0,.66667],160:[0,0,0,0,.25],710:[0,.75,0,0,1],732:[0,.75,0,0,1],770:[0,.75,0,0,1],771:[0,.75,0,0,1],8719:[.55001,1.05,0,0,1.27778],8720:[.55001,1.05,0,0,1.27778],8721:[.55001,1.05,0,0,1.44445],8730:[.65002,1.15,0,0,1],8747:[.86225,1.36,.44445,0,.55556],8748:[.862,1.36,.44445,0,.55556],8749:[.862,1.36,.44445,0,.55556],8750:[.86225,1.36,.44445,0,.55556],8896:[.55001,1.05,0,0,1.11111],8897:[.55001,1.05,0,0,1.11111],8898:[.55001,1.05,0,0,1.11111],8899:[.55001,1.05,0,0,1.11111],8968:[.65002,1.15,0,0,.52778],8969:[.65002,1.15,0,0,.52778],8970:[.65002,1.15,0,0,.52778],8971:[.65002,1.15,0,0,.52778],10216:[.65002,1.15,0,0,.61111],10217:[.65002,1.15,0,0,.61111],10752:[.55001,1.05,0,0,1.51112],10753:[.55001,1.05,0,0,1.51112],10754:[.55001,1.05,0,0,1.51112],10756:[.55001,1.05,0,0,1.11111],10758:[.55001,1.05,0,0,1.11111]},"Size3-Regular":{32:[0,0,0,0,.25],40:[.95003,1.45,0,0,.73611],41:[.95003,1.45,0,0,.73611],47:[.95003,1.45,0,0,1.04445],91:[.95003,1.45,0,0,.52778],92:[.95003,1.45,0,0,1.04445],93:[.95003,1.45,0,0,.52778],123:[.95003,1.45,0,0,.75],125:[.95003,1.45,0,0,.75],160:[0,0,0,0,.25],710:[0,.75,0,0,1.44445],732:[0,.75,0,0,1.44445],770:[0,.75,0,0,1.44445],771:[0,.75,0,0,1.44445],8730:[.95003,1.45,0,0,1],8968:[.95003,1.45,0,0,.58334],8969:[.95003,1.45,0,0,.58334],8970:[.95003,1.45,0,0,.58334],8971:[.95003,1.45,0,0,.58334],10216:[.95003,1.45,0,0,.75],10217:[.95003,1.45,0,0,.75]},"Size4-Regular":{32:[0,0,0,0,.25],40:[1.25003,1.75,0,0,.79167],41:[1.25003,1.75,0,0,.79167],47:[1.25003,1.75,0,0,1.27778],91:[1.25003,1.75,0,0,.58334],92:[1.25003,1.75,0,0,1.27778],93:[1.25003,1.75,0,0,.58334],123:[1.25003,1.75,0,0,.80556],125:[1.25003,1.75,0,0,.80556],160:[0,0,0,0,.25],710:[0,.825,0,0,1.8889],732:[0,.825,0,0,1.8889],770:[0,.825,0,0,1.8889],771:[0,.825,0,0,1.8889],8730:[1.25003,1.75,0,0,1],8968:[1.25003,1.75,0,0,.63889],8969:[1.25003,1.75,0,0,.63889],8970:[1.25003,1.75,0,0,.63889],8971:[1.25003,1.75,0,0,.63889],9115:[.64502,1.155,0,0,.875],9116:[1e-5,.6,0,0,.875],9117:[.64502,1.155,0,0,.875],9118:[.64502,1.155,0,0,.875],9119:[1e-5,.6,0,0,.875],9120:[.64502,1.155,0,0,.875],9121:[.64502,1.155,0,0,.66667],9122:[-99e-5,.601,0,0,.66667],9123:[.64502,1.155,0,0,.66667],9124:[.64502,1.155,0,0,.66667],9125:[-99e-5,.601,0,0,.66667],9126:[.64502,1.155,0,0,.66667],9127:[1e-5,.9,0,0,.88889],9128:[.65002,1.15,0,0,.88889],9129:[.90001,0,0,0,.88889],9130:[0,.3,0,0,.88889],9131:[1e-5,.9,0,0,.88889],9132:[.65002,1.15,0,0,.88889],9133:[.90001,0,0,0,.88889],9143:[.88502,.915,0,0,1.05556],10216:[1.25003,1.75,0,0,.80556],10217:[1.25003,1.75,0,0,.80556],57344:[-.00499,.605,0,0,1.05556],57345:[-.00499,.605,0,0,1.05556],57680:[0,.12,0,0,.45],57681:[0,.12,0,0,.45],57682:[0,.12,0,0,.45],57683:[0,.12,0,0,.45]},"Typewriter-Regular":{32:[0,0,0,0,.525],33:[0,.61111,0,0,.525],34:[0,.61111,0,0,.525],35:[0,.61111,0,0,.525],36:[.08333,.69444,0,0,.525],37:[.08333,.69444,0,0,.525],38:[0,.61111,0,0,.525],39:[0,.61111,0,0,.525],40:[.08333,.69444,0,0,.525],41:[.08333,.69444,0,0,.525],42:[0,.52083,0,0,.525],43:[-.08056,.53055,0,0,.525],44:[.13889,.125,0,0,.525],45:[-.08056,.53055,0,0,.525],46:[0,.125,0,0,.525],47:[.08333,.69444,0,0,.525],48:[0,.61111,0,0,.525],49:[0,.61111,0,0,.525],50:[0,.61111,0,0,.525],51:[0,.61111,0,0,.525],52:[0,.61111,0,0,.525],53:[0,.61111,0,0,.525],54:[0,.61111,0,0,.525],55:[0,.61111,0,0,.525],56:[0,.61111,0,0,.525],57:[0,.61111,0,0,.525],58:[0,.43056,0,0,.525],59:[.13889,.43056,0,0,.525],60:[-.05556,.55556,0,0,.525],61:[-.19549,.41562,0,0,.525],62:[-.05556,.55556,0,0,.525],63:[0,.61111,0,0,.525],64:[0,.61111,0,0,.525],65:[0,.61111,0,0,.525],66:[0,.61111,0,0,.525],67:[0,.61111,0,0,.525],68:[0,.61111,0,0,.525],69:[0,.61111,0,0,.525],70:[0,.61111,0,0,.525],71:[0,.61111,0,0,.525],72:[0,.61111,0,0,.525],73:[0,.61111,0,0,.525],74:[0,.61111,0,0,.525],75:[0,.61111,0,0,.525],76:[0,.61111,0,0,.525],77:[0,.61111,0,0,.525],78:[0,.61111,0,0,.525],79:[0,.61111,0,0,.525],80:[0,.61111,0,0,.525],81:[.13889,.61111,0,0,.525],82:[0,.61111,0,0,.525],83:[0,.61111,0,0,.525],84:[0,.61111,0,0,.525],85:[0,.61111,0,0,.525],86:[0,.61111,0,0,.525],87:[0,.61111,0,0,.525],88:[0,.61111,0,0,.525],89:[0,.61111,0,0,.525],90:[0,.61111,0,0,.525],91:[.08333,.69444,0,0,.525],92:[.08333,.69444,0,0,.525],93:[.08333,.69444,0,0,.525],94:[0,.61111,0,0,.525],95:[.09514,0,0,0,.525],96:[0,.61111,0,0,.525],97:[0,.43056,0,0,.525],98:[0,.61111,0,0,.525],99:[0,.43056,0,0,.525],100:[0,.61111,0,0,.525],101:[0,.43056,0,0,.525],102:[0,.61111,0,0,.525],103:[.22222,.43056,0,0,.525],104:[0,.61111,0,0,.525],105:[0,.61111,0,0,.525],106:[.22222,.61111,0,0,.525],107:[0,.61111,0,0,.525],108:[0,.61111,0,0,.525],109:[0,.43056,0,0,.525],110:[0,.43056,0,0,.525],111:[0,.43056,0,0,.525],112:[.22222,.43056,0,0,.525],113:[.22222,.43056,0,0,.525],114:[0,.43056,0,0,.525],115:[0,.43056,0,0,.525],116:[0,.55358,0,0,.525],117:[0,.43056,0,0,.525],118:[0,.43056,0,0,.525],119:[0,.43056,0,0,.525],120:[0,.43056,0,0,.525],121:[.22222,.43056,0,0,.525],122:[0,.43056,0,0,.525],123:[.08333,.69444,0,0,.525],124:[.08333,.69444,0,0,.525],125:[.08333,.69444,0,0,.525],126:[0,.61111,0,0,.525],127:[0,.61111,0,0,.525],160:[0,0,0,0,.525],176:[0,.61111,0,0,.525],184:[.19445,0,0,0,.525],305:[0,.43056,0,0,.525],567:[.22222,.43056,0,0,.525],711:[0,.56597,0,0,.525],713:[0,.56555,0,0,.525],714:[0,.61111,0,0,.525],715:[0,.61111,0,0,.525],728:[0,.61111,0,0,.525],730:[0,.61111,0,0,.525],770:[0,.61111,0,0,.525],771:[0,.61111,0,0,.525],776:[0,.61111,0,0,.525],915:[0,.61111,0,0,.525],916:[0,.61111,0,0,.525],920:[0,.61111,0,0,.525],923:[0,.61111,0,0,.525],926:[0,.61111,0,0,.525],928:[0,.61111,0,0,.525],931:[0,.61111,0,0,.525],933:[0,.61111,0,0,.525],934:[0,.61111,0,0,.525],936:[0,.61111,0,0,.525],937:[0,.61111,0,0,.525],8216:[0,.61111,0,0,.525],8217:[0,.61111,0,0,.525],8242:[0,.61111,0,0,.525],9251:[.11111,.21944,0,0,.525]}},VU={slant:[.25,.25,.25],space:[0,0,0],stretch:[0,0,0],shrink:[0,0,0],xHeight:[.431,.431,.431],quad:[1,1.171,1.472],extraSpace:[0,0,0],num1:[.677,.732,.925],num2:[.394,.384,.387],num3:[.444,.471,.504],denom1:[.686,.752,1.025],denom2:[.345,.344,.532],sup1:[.413,.503,.504],sup2:[.363,.431,.404],sup3:[.289,.286,.294],sub1:[.15,.143,.2],sub2:[.247,.286,.4],supDrop:[.386,.353,.494],subDrop:[.05,.071,.1],delim1:[2.39,1.7,1.98],delim2:[1.01,1.157,1.42],axisHeight:[.25,.25,.25],defaultRuleThickness:[.04,.049,.049],bigOpSpacing1:[.111,.111,.111],bigOpSpacing2:[.166,.166,.166],bigOpSpacing3:[.2,.2,.2],bigOpSpacing4:[.6,.611,.611],bigOpSpacing5:[.1,.143,.143],sqrtRuleThickness:[.04,.04,.04],ptPerEm:[10,10,10],doubleRuleSep:[.2,.2,.2],arrayRuleWidth:[.04,.04,.04],fboxsep:[.3,.3,.3],fboxrule:[.04,.04,.04]},HU={Å:`A`,Ð:`D`,Þ:`o`,å:`a`,ð:`d`,þ:`o`,А:`A`,Б:`B`,В:`B`,Г:`F`,Д:`A`,Е:`E`,Ж:`K`,З:`3`,И:`N`,Й:`N`,К:`K`,Л:`N`,М:`M`,Н:`H`,О:`O`,П:`N`,Р:`P`,С:`C`,Т:`T`,У:`y`,Ф:`O`,Х:`X`,Ц:`U`,Ч:`h`,Ш:`W`,Щ:`W`,Ъ:`B`,Ы:`X`,Ь:`B`,Э:`3`,Ю:`X`,Я:`R`,а:`a`,б:`b`,в:`a`,г:`r`,д:`y`,е:`e`,ж:`m`,з:`e`,и:`n`,й:`n`,к:`n`,л:`n`,м:`m`,н:`n`,о:`o`,п:`n`,р:`p`,с:`c`,т:`o`,у:`y`,ф:`b`,х:`x`,ц:`n`,ч:`n`,ш:`w`,щ:`w`,ъ:`a`,ы:`m`,ь:`a`,э:`e`,ю:`m`,я:`r`};function UU(e,t){BU[e]=t}function WU(e,t,n){if(!BU[t])throw Error(`Font metrics not found for font: `+t+`.`);var r=e.charCodeAt(0),i=BU[t][r];if(!i&&e[0]in HU&&(r=HU[e[0]].charCodeAt(0),i=BU[t][r]),!i&&n===`text`&&rU(r)&&(i=BU[t][77]),i)return{depth:i[0],height:i[1],italic:i[2],skew:i[3],width:i[4]}}var GU={};function KU(e){var t=e>=5?0:e>=3?1:2;if(!GU[t]){var n=GU[t]={cssEmPerMu:VU.quad[t]/18};for(var r of Object.keys(VU))n[r]=VU[r][t]}return GU[t]}var qU={math:{},text:{}};function B(e,t,n,r,i,a){qU[e][i]={font:t,group:n,replace:r},a&&r&&(qU[e][r]=qU[e][i])}var V=`math`,H=`text`,U=`main`,W=`ams`,JU=`accent-token`,G=`bin`,YU=`close`,XU=`inner`,K=`mathord`,ZU=`op-token`,QU=`open`,$U=`punct`,q=`rel`,eW=`spacing`,J=`textord`;B(V,U,q,`≡`,`\\equiv`,!0),B(V,U,q,`≺`,`\\prec`,!0),B(V,U,q,`≻`,`\\succ`,!0),B(V,U,q,`∼`,`\\sim`,!0),B(V,U,q,`⊥`,`\\perp`),B(V,U,q,`⪯`,`\\preceq`,!0),B(V,U,q,`⪰`,`\\succeq`,!0),B(V,U,q,`≃`,`\\simeq`,!0),B(V,U,q,`∣`,`\\mid`,!0),B(V,U,q,`≪`,`\\ll`,!0),B(V,U,q,`≫`,`\\gg`,!0),B(V,U,q,`≍`,`\\asymp`,!0),B(V,U,q,`∥`,`\\parallel`),B(V,U,q,`⋈`,`\\bowtie`,!0),B(V,U,q,`⌣`,`\\smile`,!0),B(V,U,q,`⊑`,`\\sqsubseteq`,!0),B(V,U,q,`⊒`,`\\sqsupseteq`,!0),B(V,U,q,`≐`,`\\doteq`,!0),B(V,U,q,`⌢`,`\\frown`,!0),B(V,U,q,`∋`,`\\ni`,!0),B(V,U,q,`∝`,`\\propto`,!0),B(V,U,q,`⊢`,`\\vdash`,!0),B(V,U,q,`⊣`,`\\dashv`,!0),B(V,U,q,`∋`,`\\owns`),B(V,U,$U,`.`,`\\ldotp`),B(V,U,$U,`⋅`,`\\cdotp`),B(V,U,$U,`⋅`,`·`),B(H,U,J,`⋅`,`·`),B(V,U,J,`#`,`\\#`),B(H,U,J,`#`,`\\#`),B(V,U,J,`&`,`\\&`),B(H,U,J,`&`,`\\&`),B(V,U,J,`ℵ`,`\\aleph`,!0),B(V,U,J,`∀`,`\\forall`,!0),B(V,U,J,`ℏ`,`\\hbar`,!0),B(V,U,J,`∃`,`\\exists`,!0),B(V,U,J,`∇`,`\\nabla`,!0),B(V,U,J,`♭`,`\\flat`,!0),B(V,U,J,`ℓ`,`\\ell`,!0),B(V,U,J,`♮`,`\\natural`,!0),B(V,U,J,`♣`,`\\clubsuit`,!0),B(V,U,J,`℘`,`\\wp`,!0),B(V,U,J,`♯`,`\\sharp`,!0),B(V,U,J,`♢`,`\\diamondsuit`,!0),B(V,U,J,`ℜ`,`\\Re`,!0),B(V,U,J,`♡`,`\\heartsuit`,!0),B(V,U,J,`ℑ`,`\\Im`,!0),B(V,U,J,`♠`,`\\spadesuit`,!0),B(V,U,J,`§`,`\\S`,!0),B(H,U,J,`§`,`\\S`),B(V,U,J,`¶`,`\\P`,!0),B(H,U,J,`¶`,`\\P`),B(V,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\textdagger`),B(V,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\textdaggerdbl`),B(V,U,YU,`⎱`,`\\rmoustache`,!0),B(V,U,QU,`⎰`,`\\lmoustache`,!0),B(V,U,YU,`⟯`,`\\rgroup`,!0),B(V,U,QU,`⟮`,`\\lgroup`,!0),B(V,U,G,`∓`,`\\mp`,!0),B(V,U,G,`⊖`,`\\ominus`,!0),B(V,U,G,`⊎`,`\\uplus`,!0),B(V,U,G,`⊓`,`\\sqcap`,!0),B(V,U,G,`∗`,`\\ast`),B(V,U,G,`⊔`,`\\sqcup`,!0),B(V,U,G,`◯`,`\\bigcirc`,!0),B(V,U,G,`∙`,`\\bullet`,!0),B(V,U,G,`‡`,`\\ddagger`),B(V,U,G,`≀`,`\\wr`,!0),B(V,U,G,`⨿`,`\\amalg`),B(V,U,G,`&`,`\\And`),B(V,U,q,`⟵`,`\\longleftarrow`,!0),B(V,U,q,`⇐`,`\\Leftarrow`,!0),B(V,U,q,`⟸`,`\\Longleftarrow`,!0),B(V,U,q,`⟶`,`\\longrightarrow`,!0),B(V,U,q,`⇒`,`\\Rightarrow`,!0),B(V,U,q,`⟹`,`\\Longrightarrow`,!0),B(V,U,q,`↔`,`\\leftrightarrow`,!0),B(V,U,q,`⟷`,`\\longleftrightarrow`,!0),B(V,U,q,`⇔`,`\\Leftrightarrow`,!0),B(V,U,q,`⟺`,`\\Longleftrightarrow`,!0),B(V,U,q,`↦`,`\\mapsto`,!0),B(V,U,q,`⟼`,`\\longmapsto`,!0),B(V,U,q,`↗`,`\\nearrow`,!0),B(V,U,q,`↩`,`\\hookleftarrow`,!0),B(V,U,q,`↪`,`\\hookrightarrow`,!0),B(V,U,q,`↘`,`\\searrow`,!0),B(V,U,q,`↼`,`\\leftharpoonup`,!0),B(V,U,q,`⇀`,`\\rightharpoonup`,!0),B(V,U,q,`↙`,`\\swarrow`,!0),B(V,U,q,`↽`,`\\leftharpoondown`,!0),B(V,U,q,`⇁`,`\\rightharpoondown`,!0),B(V,U,q,`↖`,`\\nwarrow`,!0),B(V,U,q,`⇌`,`\\rightleftharpoons`,!0),B(V,W,q,`≮`,`\\nless`,!0),B(V,W,q,``,`\\@nleqslant`),B(V,W,q,``,`\\@nleqq`),B(V,W,q,`⪇`,`\\lneq`,!0),B(V,W,q,`≨`,`\\lneqq`,!0),B(V,W,q,``,`\\@lvertneqq`),B(V,W,q,`⋦`,`\\lnsim`,!0),B(V,W,q,`⪉`,`\\lnapprox`,!0),B(V,W,q,`⊀`,`\\nprec`,!0),B(V,W,q,`⋠`,`\\npreceq`,!0),B(V,W,q,`⋨`,`\\precnsim`,!0),B(V,W,q,`⪹`,`\\precnapprox`,!0),B(V,W,q,`≁`,`\\nsim`,!0),B(V,W,q,``,`\\@nshortmid`),B(V,W,q,`∤`,`\\nmid`,!0),B(V,W,q,`⊬`,`\\nvdash`,!0),B(V,W,q,`⊭`,`\\nvDash`,!0),B(V,W,q,`⋪`,`\\ntriangleleft`),B(V,W,q,`⋬`,`\\ntrianglelefteq`,!0),B(V,W,q,`⊊`,`\\subsetneq`,!0),B(V,W,q,``,`\\@varsubsetneq`),B(V,W,q,`⫋`,`\\subsetneqq`,!0),B(V,W,q,``,`\\@varsubsetneqq`),B(V,W,q,`≯`,`\\ngtr`,!0),B(V,W,q,``,`\\@ngeqslant`),B(V,W,q,``,`\\@ngeqq`),B(V,W,q,`⪈`,`\\gneq`,!0),B(V,W,q,`≩`,`\\gneqq`,!0),B(V,W,q,``,`\\@gvertneqq`),B(V,W,q,`⋧`,`\\gnsim`,!0),B(V,W,q,`⪊`,`\\gnapprox`,!0),B(V,W,q,`⊁`,`\\nsucc`,!0),B(V,W,q,`⋡`,`\\nsucceq`,!0),B(V,W,q,`⋩`,`\\succnsim`,!0),B(V,W,q,`⪺`,`\\succnapprox`,!0),B(V,W,q,`≆`,`\\ncong`,!0),B(V,W,q,``,`\\@nshortparallel`),B(V,W,q,`∦`,`\\nparallel`,!0),B(V,W,q,`⊯`,`\\nVDash`,!0),B(V,W,q,`⋫`,`\\ntriangleright`),B(V,W,q,`⋭`,`\\ntrianglerighteq`,!0),B(V,W,q,``,`\\@nsupseteqq`),B(V,W,q,`⊋`,`\\supsetneq`,!0),B(V,W,q,``,`\\@varsupsetneq`),B(V,W,q,`⫌`,`\\supsetneqq`,!0),B(V,W,q,``,`\\@varsupsetneqq`),B(V,W,q,`⊮`,`\\nVdash`,!0),B(V,W,q,`⪵`,`\\precneqq`,!0),B(V,W,q,`⪶`,`\\succneqq`,!0),B(V,W,q,``,`\\@nsubseteqq`),B(V,W,G,`⊴`,`\\unlhd`),B(V,W,G,`⊵`,`\\unrhd`),B(V,W,q,`↚`,`\\nleftarrow`,!0),B(V,W,q,`↛`,`\\nrightarrow`,!0),B(V,W,q,`⇍`,`\\nLeftarrow`,!0),B(V,W,q,`⇏`,`\\nRightarrow`,!0),B(V,W,q,`↮`,`\\nleftrightarrow`,!0),B(V,W,q,`⇎`,`\\nLeftrightarrow`,!0),B(V,W,q,`△`,`\\vartriangle`),B(V,W,J,`ℏ`,`\\hslash`),B(V,W,J,`▽`,`\\triangledown`),B(V,W,J,`◊`,`\\lozenge`),B(V,W,J,`Ⓢ`,`\\circledS`),B(V,W,J,`®`,`\\circledR`),B(H,W,J,`®`,`\\circledR`),B(V,W,J,`∡`,`\\measuredangle`,!0),B(V,W,J,`∄`,`\\nexists`),B(V,W,J,`℧`,`\\mho`),B(V,W,J,`Ⅎ`,`\\Finv`,!0),B(V,W,J,`⅁`,`\\Game`,!0),B(V,W,J,`‵`,`\\backprime`),B(V,W,J,`▲`,`\\blacktriangle`),B(V,W,J,`▼`,`\\blacktriangledown`),B(V,W,J,`■`,`\\blacksquare`),B(V,W,J,`⧫`,`\\blacklozenge`),B(V,W,J,`★`,`\\bigstar`),B(V,W,J,`∢`,`\\sphericalangle`,!0),B(V,W,J,`∁`,`\\complement`,!0),B(V,W,J,`ð`,`\\eth`,!0),B(H,U,J,`ð`,`ð`),B(V,W,J,`╱`,`\\diagup`),B(V,W,J,`╲`,`\\diagdown`),B(V,W,J,`□`,`\\square`),B(V,W,J,`□`,`\\Box`),B(V,W,J,`◊`,`\\Diamond`),B(V,W,J,`¥`,`\\yen`,!0),B(H,W,J,`¥`,`\\yen`,!0),B(V,W,J,`✓`,`\\checkmark`,!0),B(H,W,J,`✓`,`\\checkmark`),B(V,W,J,`ℶ`,`\\beth`,!0),B(V,W,J,`ℸ`,`\\daleth`,!0),B(V,W,J,`ℷ`,`\\gimel`,!0),B(V,W,J,`ϝ`,`\\digamma`,!0),B(V,W,J,`ϰ`,`\\varkappa`),B(V,W,QU,`┌`,`\\@ulcorner`,!0),B(V,W,YU,`┐`,`\\@urcorner`,!0),B(V,W,QU,`└`,`\\@llcorner`,!0),B(V,W,YU,`┘`,`\\@lrcorner`,!0),B(V,W,q,`≦`,`\\leqq`,!0),B(V,W,q,`⩽`,`\\leqslant`,!0),B(V,W,q,`⪕`,`\\eqslantless`,!0),B(V,W,q,`≲`,`\\lesssim`,!0),B(V,W,q,`⪅`,`\\lessapprox`,!0),B(V,W,q,`≊`,`\\approxeq`,!0),B(V,W,G,`⋖`,`\\lessdot`),B(V,W,q,`⋘`,`\\lll`,!0),B(V,W,q,`≶`,`\\lessgtr`,!0),B(V,W,q,`⋚`,`\\lesseqgtr`,!0),B(V,W,q,`⪋`,`\\lesseqqgtr`,!0),B(V,W,q,`≑`,`\\doteqdot`),B(V,W,q,`≓`,`\\risingdotseq`,!0),B(V,W,q,`≒`,`\\fallingdotseq`,!0),B(V,W,q,`∽`,`\\backsim`,!0),B(V,W,q,`⋍`,`\\backsimeq`,!0),B(V,W,q,`⫅`,`\\subseteqq`,!0),B(V,W,q,`⋐`,`\\Subset`,!0),B(V,W,q,`⊏`,`\\sqsubset`,!0),B(V,W,q,`≼`,`\\preccurlyeq`,!0),B(V,W,q,`⋞`,`\\curlyeqprec`,!0),B(V,W,q,`≾`,`\\precsim`,!0),B(V,W,q,`⪷`,`\\precapprox`,!0),B(V,W,q,`⊲`,`\\vartriangleleft`),B(V,W,q,`⊴`,`\\trianglelefteq`),B(V,W,q,`⊨`,`\\vDash`,!0),B(V,W,q,`⊪`,`\\Vvdash`,!0),B(V,W,q,`⌣`,`\\smallsmile`),B(V,W,q,`⌢`,`\\smallfrown`),B(V,W,q,`≏`,`\\bumpeq`,!0),B(V,W,q,`≎`,`\\Bumpeq`,!0),B(V,W,q,`≧`,`\\geqq`,!0),B(V,W,q,`⩾`,`\\geqslant`,!0),B(V,W,q,`⪖`,`\\eqslantgtr`,!0),B(V,W,q,`≳`,`\\gtrsim`,!0),B(V,W,q,`⪆`,`\\gtrapprox`,!0),B(V,W,G,`⋗`,`\\gtrdot`),B(V,W,q,`⋙`,`\\ggg`,!0),B(V,W,q,`≷`,`\\gtrless`,!0),B(V,W,q,`⋛`,`\\gtreqless`,!0),B(V,W,q,`⪌`,`\\gtreqqless`,!0),B(V,W,q,`≖`,`\\eqcirc`,!0),B(V,W,q,`≗`,`\\circeq`,!0),B(V,W,q,`≜`,`\\triangleq`,!0),B(V,W,q,`∼`,`\\thicksim`),B(V,W,q,`≈`,`\\thickapprox`),B(V,W,q,`⫆`,`\\supseteqq`,!0),B(V,W,q,`⋑`,`\\Supset`,!0),B(V,W,q,`⊐`,`\\sqsupset`,!0),B(V,W,q,`≽`,`\\succcurlyeq`,!0),B(V,W,q,`⋟`,`\\curlyeqsucc`,!0),B(V,W,q,`≿`,`\\succsim`,!0),B(V,W,q,`⪸`,`\\succapprox`,!0),B(V,W,q,`⊳`,`\\vartriangleright`),B(V,W,q,`⊵`,`\\trianglerighteq`),B(V,W,q,`⊩`,`\\Vdash`,!0),B(V,W,q,`∣`,`\\shortmid`),B(V,W,q,`∥`,`\\shortparallel`),B(V,W,q,`≬`,`\\between`,!0),B(V,W,q,`⋔`,`\\pitchfork`,!0),B(V,W,q,`∝`,`\\varpropto`),B(V,W,q,`◀`,`\\blacktriangleleft`),B(V,W,q,`∴`,`\\therefore`,!0),B(V,W,q,`∍`,`\\backepsilon`),B(V,W,q,`▶`,`\\blacktriangleright`),B(V,W,q,`∵`,`\\because`,!0),B(V,W,q,`⋘`,`\\llless`),B(V,W,q,`⋙`,`\\gggtr`),B(V,W,G,`⊲`,`\\lhd`),B(V,W,G,`⊳`,`\\rhd`),B(V,W,q,`≂`,`\\eqsim`,!0),B(V,U,q,`⋈`,`\\Join`),B(V,W,q,`≑`,`\\Doteq`,!0),B(V,W,G,`∔`,`\\dotplus`,!0),B(V,W,G,`∖`,`\\smallsetminus`),B(V,W,G,`⋒`,`\\Cap`,!0),B(V,W,G,`⋓`,`\\Cup`,!0),B(V,W,G,`⩞`,`\\doublebarwedge`,!0),B(V,W,G,`⊟`,`\\boxminus`,!0),B(V,W,G,`⊞`,`\\boxplus`,!0),B(V,W,G,`⋇`,`\\divideontimes`,!0),B(V,W,G,`⋉`,`\\ltimes`,!0),B(V,W,G,`⋊`,`\\rtimes`,!0),B(V,W,G,`⋋`,`\\leftthreetimes`,!0),B(V,W,G,`⋌`,`\\rightthreetimes`,!0),B(V,W,G,`⋏`,`\\curlywedge`,!0),B(V,W,G,`⋎`,`\\curlyvee`,!0),B(V,W,G,`⊝`,`\\circleddash`,!0),B(V,W,G,`⊛`,`\\circledast`,!0),B(V,W,G,`⋅`,`\\centerdot`),B(V,W,G,`⊺`,`\\intercal`,!0),B(V,W,G,`⋒`,`\\doublecap`),B(V,W,G,`⋓`,`\\doublecup`),B(V,W,G,`⊠`,`\\boxtimes`,!0),B(V,W,q,`⇢`,`\\dashrightarrow`,!0),B(V,W,q,`⇠`,`\\dashleftarrow`,!0),B(V,W,q,`⇇`,`\\leftleftarrows`,!0),B(V,W,q,`⇆`,`\\leftrightarrows`,!0),B(V,W,q,`⇚`,`\\Lleftarrow`,!0),B(V,W,q,`↞`,`\\twoheadleftarrow`,!0),B(V,W,q,`↢`,`\\leftarrowtail`,!0),B(V,W,q,`↫`,`\\looparrowleft`,!0),B(V,W,q,`⇋`,`\\leftrightharpoons`,!0),B(V,W,q,`↶`,`\\curvearrowleft`,!0),B(V,W,q,`↺`,`\\circlearrowleft`,!0),B(V,W,q,`↰`,`\\Lsh`,!0),B(V,W,q,`⇈`,`\\upuparrows`,!0),B(V,W,q,`↿`,`\\upharpoonleft`,!0),B(V,W,q,`⇃`,`\\downharpoonleft`,!0),B(V,U,q,`⊶`,`\\origof`,!0),B(V,U,q,`⊷`,`\\imageof`,!0),B(V,W,q,`⊸`,`\\multimap`,!0),B(V,W,q,`↭`,`\\leftrightsquigarrow`,!0),B(V,W,q,`⇉`,`\\rightrightarrows`,!0),B(V,W,q,`⇄`,`\\rightleftarrows`,!0),B(V,W,q,`↠`,`\\twoheadrightarrow`,!0),B(V,W,q,`↣`,`\\rightarrowtail`,!0),B(V,W,q,`↬`,`\\looparrowright`,!0),B(V,W,q,`↷`,`\\curvearrowright`,!0),B(V,W,q,`↻`,`\\circlearrowright`,!0),B(V,W,q,`↱`,`\\Rsh`,!0),B(V,W,q,`⇊`,`\\downdownarrows`,!0),B(V,W,q,`↾`,`\\upharpoonright`,!0),B(V,W,q,`⇂`,`\\downharpoonright`,!0),B(V,W,q,`⇝`,`\\rightsquigarrow`,!0),B(V,W,q,`⇝`,`\\leadsto`),B(V,W,q,`⇛`,`\\Rrightarrow`,!0),B(V,W,q,`↾`,`\\restriction`),B(V,U,J,`‘`,"`"),B(V,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\textdollar`),B(V,U,J,`%`,`\\%`),B(H,U,J,`%`,`\\%`),B(V,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\textunderscore`),B(V,U,J,`∠`,`\\angle`,!0),B(V,U,J,`∞`,`\\infty`,!0),B(V,U,J,`′`,`\\prime`),B(V,U,J,`△`,`\\triangle`),B(V,U,J,`Γ`,`\\Gamma`,!0),B(V,U,J,`Δ`,`\\Delta`,!0),B(V,U,J,`Θ`,`\\Theta`,!0),B(V,U,J,`Λ`,`\\Lambda`,!0),B(V,U,J,`Ξ`,`\\Xi`,!0),B(V,U,J,`Π`,`\\Pi`,!0),B(V,U,J,`Σ`,`\\Sigma`,!0),B(V,U,J,`Υ`,`\\Upsilon`,!0),B(V,U,J,`Φ`,`\\Phi`,!0),B(V,U,J,`Ψ`,`\\Psi`,!0),B(V,U,J,`Ω`,`\\Omega`,!0),B(V,U,J,`A`,`Α`),B(V,U,J,`B`,`Β`),B(V,U,J,`E`,`Ε`),B(V,U,J,`Z`,`Ζ`),B(V,U,J,`H`,`Η`),B(V,U,J,`I`,`Ι`),B(V,U,J,`K`,`Κ`),B(V,U,J,`M`,`Μ`),B(V,U,J,`N`,`Ν`),B(V,U,J,`O`,`Ο`),B(V,U,J,`P`,`Ρ`),B(V,U,J,`T`,`Τ`),B(V,U,J,`X`,`Χ`),B(V,U,J,`¬`,`\\neg`,!0),B(V,U,J,`¬`,`\\lnot`),B(V,U,J,`⊤`,`\\top`),B(V,U,J,`⊥`,`\\bot`),B(V,U,J,`∅`,`\\emptyset`),B(V,W,J,`∅`,`\\varnothing`),B(V,U,K,`α`,`\\alpha`,!0),B(V,U,K,`β`,`\\beta`,!0),B(V,U,K,`γ`,`\\gamma`,!0),B(V,U,K,`δ`,`\\delta`,!0),B(V,U,K,`ϵ`,`\\epsilon`,!0),B(V,U,K,`ζ`,`\\zeta`,!0),B(V,U,K,`η`,`\\eta`,!0),B(V,U,K,`θ`,`\\theta`,!0),B(V,U,K,`ι`,`\\iota`,!0),B(V,U,K,`κ`,`\\kappa`,!0),B(V,U,K,`λ`,`\\lambda`,!0),B(V,U,K,`μ`,`\\mu`,!0),B(V,U,K,`ν`,`\\nu`,!0),B(V,U,K,`ξ`,`\\xi`,!0),B(V,U,K,`ο`,`\\omicron`,!0),B(V,U,K,`π`,`\\pi`,!0),B(V,U,K,`ρ`,`\\rho`,!0),B(V,U,K,`σ`,`\\sigma`,!0),B(V,U,K,`τ`,`\\tau`,!0),B(V,U,K,`υ`,`\\upsilon`,!0),B(V,U,K,`ϕ`,`\\phi`,!0),B(V,U,K,`χ`,`\\chi`,!0),B(V,U,K,`ψ`,`\\psi`,!0),B(V,U,K,`ω`,`\\omega`,!0),B(V,U,K,`ε`,`\\varepsilon`,!0),B(V,U,K,`ϑ`,`\\vartheta`,!0),B(V,U,K,`ϖ`,`\\varpi`,!0),B(V,U,K,`ϱ`,`\\varrho`,!0),B(V,U,K,`ς`,`\\varsigma`,!0),B(V,U,K,`φ`,`\\varphi`,!0),B(V,U,G,`∗`,`*`,!0),B(V,U,G,`+`,`+`),B(V,U,G,`−`,`-`,!0),B(V,U,G,`⋅`,`\\cdot`,!0),B(V,U,G,`∘`,`\\circ`,!0),B(V,U,G,`÷`,`\\div`,!0),B(V,U,G,`±`,`\\pm`,!0),B(V,U,G,`×`,`\\times`,!0),B(V,U,G,`∩`,`\\cap`,!0),B(V,U,G,`∪`,`\\cup`,!0),B(V,U,G,`∖`,`\\setminus`,!0),B(V,U,G,`∧`,`\\land`),B(V,U,G,`∨`,`\\lor`),B(V,U,G,`∧`,`\\wedge`,!0),B(V,U,G,`∨`,`\\vee`,!0),B(V,U,J,`√`,`\\surd`),B(V,U,QU,`⟨`,`\\langle`,!0),B(V,U,QU,`∣`,`\\lvert`),B(V,U,QU,`∥`,`\\lVert`),B(V,U,YU,`?`,`?`),B(V,U,YU,`!`,`!`),B(V,U,YU,`⟩`,`\\rangle`,!0),B(V,U,YU,`∣`,`\\rvert`),B(V,U,YU,`∥`,`\\rVert`),B(V,U,q,`=`,`=`),B(V,U,q,`:`,`:`),B(V,U,q,`≈`,`\\approx`,!0),B(V,U,q,`≅`,`\\cong`,!0),B(V,U,q,`≥`,`\\ge`),B(V,U,q,`≥`,`\\geq`,!0),B(V,U,q,`←`,`\\gets`),B(V,U,q,`>`,`\\gt`,!0),B(V,U,q,`∈`,`\\in`,!0),B(V,U,q,``,`\\@not`),B(V,U,q,`⊂`,`\\subset`,!0),B(V,U,q,`⊃`,`\\supset`,!0),B(V,U,q,`⊆`,`\\subseteq`,!0),B(V,U,q,`⊇`,`\\supseteq`,!0),B(V,W,q,`⊈`,`\\nsubseteq`,!0),B(V,W,q,`⊉`,`\\nsupseteq`,!0),B(V,U,q,`⊨`,`\\models`),B(V,U,q,`←`,`\\leftarrow`,!0),B(V,U,q,`≤`,`\\le`),B(V,U,q,`≤`,`\\leq`,!0),B(V,U,q,`<`,`\\lt`,!0),B(V,U,q,`→`,`\\rightarrow`,!0),B(V,U,q,`→`,`\\to`),B(V,W,q,`≱`,`\\ngeq`,!0),B(V,W,q,`≰`,`\\nleq`,!0),B(V,U,eW,`\xA0`,`\\ `),B(V,U,eW,`\xA0`,`\\space`),B(V,U,eW,`\xA0`,`\\nobreakspace`),B(H,U,eW,`\xA0`,`\\ `),B(H,U,eW,`\xA0`,` `),B(H,U,eW,`\xA0`,`\\space`),B(H,U,eW,`\xA0`,`\\nobreakspace`),B(V,U,eW,``,`\\nobreak`),B(V,U,eW,``,`\\allowbreak`),B(V,U,$U,`,`,`,`),B(V,U,$U,`;`,`;`),B(V,W,G,`⊼`,`\\barwedge`,!0),B(V,W,G,`⊻`,`\\veebar`,!0),B(V,U,G,`⊙`,`\\odot`,!0),B(V,U,G,`⊕`,`\\oplus`,!0),B(V,U,G,`⊗`,`\\otimes`,!0),B(V,U,J,`∂`,`\\partial`,!0),B(V,U,G,`⊘`,`\\oslash`,!0),B(V,W,G,`⊚`,`\\circledcirc`,!0),B(V,W,G,`⊡`,`\\boxdot`,!0),B(V,U,G,`△`,`\\bigtriangleup`),B(V,U,G,`▽`,`\\bigtriangledown`),B(V,U,G,`†`,`\\dagger`),B(V,U,G,`⋄`,`\\diamond`),B(V,U,G,`⋆`,`\\star`),B(V,U,G,`◃`,`\\triangleleft`),B(V,U,G,`▹`,`\\triangleright`),B(V,U,QU,`{`,`\\{`),B(H,U,J,`{`,`\\{`),B(H,U,J,`{`,`\\textbraceleft`),B(V,U,YU,`}`,`\\}`),B(H,U,J,`}`,`\\}`),B(H,U,J,`}`,`\\textbraceright`),B(V,U,QU,`{`,`\\lbrace`),B(V,U,YU,`}`,`\\rbrace`),B(V,U,QU,`[`,`\\lbrack`,!0),B(H,U,J,`[`,`\\lbrack`,!0),B(V,U,YU,`]`,`\\rbrack`,!0),B(H,U,J,`]`,`\\rbrack`,!0),B(V,U,QU,`(`,`\\lparen`,!0),B(V,U,YU,`)`,`\\rparen`,!0),B(H,U,J,`<`,`\\textless`,!0),B(H,U,J,`>`,`\\textgreater`,!0),B(V,U,QU,`⌊`,`\\lfloor`,!0),B(V,U,YU,`⌋`,`\\rfloor`,!0),B(V,U,QU,`⌈`,`\\lceil`,!0),B(V,U,YU,`⌉`,`\\rceil`,!0),B(V,U,J,`\\`,`\\backslash`),B(V,U,J,`∣`,`|`),B(V,U,J,`∣`,`\\vert`),B(H,U,J,`|`,`\\textbar`,!0),B(V,U,J,`∥`,`\\|`),B(V,U,J,`∥`,`\\Vert`),B(H,U,J,`∥`,`\\textbardbl`),B(H,U,J,`~`,`\\textasciitilde`),B(H,U,J,`\\`,`\\textbackslash`),B(H,U,J,`^`,`\\textasciicircum`),B(V,U,q,`↑`,`\\uparrow`,!0),B(V,U,q,`⇑`,`\\Uparrow`,!0),B(V,U,q,`↓`,`\\downarrow`,!0),B(V,U,q,`⇓`,`\\Downarrow`,!0),B(V,U,q,`↕`,`\\updownarrow`,!0),B(V,U,q,`⇕`,`\\Updownarrow`,!0),B(V,U,ZU,`∐`,`\\coprod`),B(V,U,ZU,`⋁`,`\\bigvee`),B(V,U,ZU,`⋀`,`\\bigwedge`),B(V,U,ZU,`⨄`,`\\biguplus`),B(V,U,ZU,`⋂`,`\\bigcap`),B(V,U,ZU,`⋃`,`\\bigcup`),B(V,U,ZU,`∫`,`\\int`),B(V,U,ZU,`∫`,`\\intop`),B(V,U,ZU,`∬`,`\\iint`),B(V,U,ZU,`∭`,`\\iiint`),B(V,U,ZU,`∏`,`\\prod`),B(V,U,ZU,`∑`,`\\sum`),B(V,U,ZU,`⨂`,`\\bigotimes`),B(V,U,ZU,`⨁`,`\\bigoplus`),B(V,U,ZU,`⨀`,`\\bigodot`),B(V,U,ZU,`∮`,`\\oint`),B(V,U,ZU,`∯`,`\\oiint`),B(V,U,ZU,`∰`,`\\oiiint`),B(V,U,ZU,`⨆`,`\\bigsqcup`),B(V,U,ZU,`∫`,`\\smallint`),B(H,U,XU,`…`,`\\textellipsis`),B(V,U,XU,`…`,`\\mathellipsis`),B(H,U,XU,`…`,`\\ldots`,!0),B(V,U,XU,`…`,`\\ldots`,!0),B(V,U,XU,`⋯`,`\\@cdots`,!0),B(V,U,XU,`⋱`,`\\ddots`,!0),B(V,U,J,`⋮`,`\\varvdots`),B(H,U,J,`⋮`,`\\varvdots`),B(V,U,JU,`ˊ`,`\\acute`),B(V,U,JU,`ˋ`,`\\grave`),B(V,U,JU,`¨`,`\\ddot`),B(V,U,JU,`~`,`\\tilde`),B(V,U,JU,`ˉ`,`\\bar`),B(V,U,JU,`˘`,`\\breve`),B(V,U,JU,`ˇ`,`\\check`),B(V,U,JU,`^`,`\\hat`),B(V,U,JU,`⃗`,`\\vec`),B(V,U,JU,`˙`,`\\dot`),B(V,U,JU,`˚`,`\\mathring`),B(V,U,K,``,`\\@imath`),B(V,U,K,``,`\\@jmath`),B(V,U,J,`ı`,`ı`),B(V,U,J,`ȷ`,`ȷ`),B(H,U,J,`ı`,`\\i`,!0),B(H,U,J,`ȷ`,`\\j`,!0),B(H,U,J,`ß`,`\\ss`,!0),B(H,U,J,`æ`,`\\ae`,!0),B(H,U,J,`œ`,`\\oe`,!0),B(H,U,J,`ø`,`\\o`,!0),B(H,U,J,`Æ`,`\\AE`,!0),B(H,U,J,`Œ`,`\\OE`,!0),B(H,U,J,`Ø`,`\\O`,!0),B(H,U,JU,`ˊ`,`\\'`),B(H,U,JU,`ˋ`,"\\`"),B(H,U,JU,`ˆ`,`\\^`),B(H,U,JU,`˜`,`\\~`),B(H,U,JU,`ˉ`,`\\=`),B(H,U,JU,`˘`,`\\u`),B(H,U,JU,`˙`,`\\.`),B(H,U,JU,`¸`,`\\c`),B(H,U,JU,`˚`,`\\r`),B(H,U,JU,`ˇ`,`\\v`),B(H,U,JU,`¨`,`\\"`),B(H,U,JU,`˝`,`\\H`),B(H,U,JU,`◯`,`\\textcircled`);var tW={"--":!0,"---":!0,"``":!0,"''":!0};B(H,U,J,`–`,`--`,!0),B(H,U,J,`–`,`\\textendash`),B(H,U,J,`—`,`---`,!0),B(H,U,J,`—`,`\\textemdash`),B(H,U,J,`‘`,"`",!0),B(H,U,J,`‘`,`\\textquoteleft`),B(H,U,J,`’`,`'`,!0),B(H,U,J,`’`,`\\textquoteright`),B(H,U,J,`“`,"``",!0),B(H,U,J,`“`,`\\textquotedblleft`),B(H,U,J,`”`,`''`,!0),B(H,U,J,`”`,`\\textquotedblright`),B(V,U,J,`°`,`\\degree`,!0),B(H,U,J,`°`,`\\degree`),B(H,U,J,`°`,`\\textdegree`,!0),B(V,U,J,`£`,`\\pounds`),B(V,U,J,`£`,`\\mathsterling`,!0),B(H,U,J,`£`,`\\pounds`),B(H,U,J,`£`,`\\textsterling`,!0),B(V,W,J,`✠`,`\\maltese`),B(H,W,J,`✠`,`\\maltese`);for(var nW=`0123456789/@."`,rW=0;rW{var t=e.charCodeAt(0),n=e.charCodeAt(1),r=(t-55296)*1024+(n-56320)+65536;if(119808<=r&&r<120484)return AW[Math.floor((r-119808)/26)];if(120782<=r&&r<=120831)return jW[Math.floor((r-120782)/10)];if(r===120485||r===120486)return AW[0];if(120486{if(CU(e.classes)!==CU(t.classes)||e.skew!==t.skew||e.maxFontSize!==t.maxFontSize||e.italic!==0&&e.hasClass(`mathnormal`))return!1;if(e.classes.length===1){var n=e.classes[0];if(n===`mbin`||n===`mord`)return!1}for(var r of Object.keys(e.style))if(e.style[r]!==t.style[r])return!1;for(var i of Object.keys(t.style))if(e.style[i]!==t.style[i])return!1;return!0},zW=e=>{for(var t=0;tt&&(t=a.height),a.depth>n&&(n=a.depth),a.maxFontSize>r&&(r=a.maxFontSize)}e.height=t,e.depth=n,e.maxFontSize=r},X=function(e,t,n,r){var i=new kU(e,t,n,r);return BW(i),i},VW=(e,t,n,r)=>new kU(e,t,n,r),HW=function(e,t,n){var r=X([e],[],t);return r.height=Math.max(n||t.fontMetrics().defaultRuleThickness,t.minRuleThickness),r.style.borderBottomWidth=z(r.height),r.maxFontSize=1,r},UW=function(e,t,n,r){var i=new AU(e,t,n,r);return BW(i),i},WW=function(e){var t=new vU(e);return BW(t),t},GW=function(e,t){return e instanceof vU?X([],[e],t):e},KW=function(e){if(e.positionType===`individualShift`){for(var t=e.children,n=[t[0]],r=-t[0].shift-t[0].elem.depth,i=r,a=1;a{var n=X([`mspace`],[],t),r=SU(e,t);return n.style.marginRight=z(r),n},YW=(e,t,n)=>{var r,i;switch(e){case`amsrm`:r=`AMS`;break;case`textrm`:r=`Main`;break;case`textsf`:r=`SansSerif`;break;case`texttt`:r=`Typewriter`;break;default:r=e}return i=t===`textbf`&&n===`textit`?`BoldItalic`:t===`textbf`?`Bold`:n===`textit`?`Italic`:`Regular`,r+`-`+i},XW={mathbf:{variant:`bold`,fontName:`Main-Bold`},mathrm:{variant:`normal`,fontName:`Main-Regular`},textit:{variant:`italic`,fontName:`Main-Italic`},mathit:{variant:`italic`,fontName:`Main-Italic`},mathnormal:{variant:`italic`,fontName:`Math-Italic`},mathsfit:{variant:`sans-serif-italic`,fontName:`SansSerif-Italic`},mathbb:{variant:`double-struck`,fontName:`AMS-Regular`},mathcal:{variant:`script`,fontName:`Caligraphic-Regular`},mathfrak:{variant:`fraktur`,fontName:`Fraktur-Regular`},mathscr:{variant:`script`,fontName:`Script-Regular`},mathsf:{variant:`sans-serif`,fontName:`SansSerif-Regular`},mathtt:{variant:`monospace`,fontName:`Typewriter-Regular`}},ZW={vec:[`vec`,.471,.714],oiintSize1:[`oiintSize1`,.957,.499],oiintSize2:[`oiintSize2`,1.472,.659],oiiintSize1:[`oiiintSize1`,1.304,.499],oiiintSize2:[`oiiintSize2`,1.98,.659]},QW=function(e,t){var n=ZW[e],r=n[0],i=n[1],a=n[2],o=VW([`katex-overlay`],[new PU([new FU(r)],{width:z(i),height:z(a),style:`width:`+z(i),viewBox:`0 0 `+1e3*i+` `+1e3*a,preserveAspectRatio:`xMinYMin`})],t);return o.height=a,o.style.height=z(a),o.style.width=z(i),o},$W={number:3,unit:`mu`},eG={number:4,unit:`mu`},tG={number:5,unit:`mu`},nG={mord:{mop:$W,mbin:eG,mrel:tG,minner:$W},mop:{mord:$W,mop:$W,mrel:tG,minner:$W},mbin:{mord:eG,mop:eG,mopen:eG,minner:eG},mrel:{mord:tG,mop:tG,mopen:tG,minner:tG},mopen:{},mclose:{mop:$W,mbin:eG,mrel:tG,minner:$W},mpunct:{mord:$W,mop:$W,mrel:tG,mopen:$W,mclose:$W,mpunct:$W,minner:$W},minner:{mord:$W,mop:$W,mbin:eG,mrel:tG,mopen:$W,mpunct:$W,minner:$W}},rG={mord:{mop:$W},mop:{mord:$W,mop:$W},mbin:{},mrel:{},mopen:{},mclose:{mop:$W},mpunct:{},minner:{mop:$W}},iG={},aG={},oG={};function Z(e){for(var t=e.type,n=e.names,r=e.htmlBuilder,i=e.mathmlBuilder,a=0;a{var n=t.classes[0],r=e.classes[0];n===`mbin`&&dG.has(r)?t.classes[0]=`mord`:r===`mbin`&&uG.has(n)&&(e.classes[0]=`mord`)},{node:u},d,f),hG(i,(e,t)=>{var n=vG(t),r=vG(e),i=n&&r?e.hasClass(`mtight`)?rG[n]?.[r]:nG[n]?.[r]:null;if(i)return JW(i,c)},{node:u},d,f),i},hG=function(e,t,n,r,i){r&&e.push(r);for(var a=0;an=>{e.splice(t+1,0,n),a++})(a)}}r&&e.pop()},gG=function(e){return e instanceof vU||e instanceof AU||e instanceof kU&&e.hasClass(`enclosing`)?e:null},_G=function(e,t){var n=gG(e);if(n){var r=n.children;if(r.length){if(t===`right`)return _G(r[r.length-1],`right`);if(t===`left`)return _G(r[0],`left`)}}return e},vG=function(e,t){return e?(t&&(e=_G(e,t)),pG[e.classes[0]]||null):null},yG=function(e,t){var n=[`nulldelimiter`].concat(e.baseSizingClasses());return X(t.concat(n))},bG=function(e,t,n){if(!e)return X();if(aG[e.type]){var r=aG[e.type](e,t);if(n&&t.size!==n.size){r=X(t.sizingClasses(n),[r],t);var i=t.sizeMultiplier/n.sizeMultiplier;r.height*=i,r.depth*=i}return r}throw new L(`Got group of unknown type: '`+e.type+`'`)};function xG(e,t){var n=X([`katex-base`],e,t),r=X([`katex-strut`]);return r.style.height=z(n.height+n.depth),n.depth&&(r.style.verticalAlign=z(-n.depth)),n.children.unshift(r),n}function SG(e,t){var n=null;e.length===1&&e[0].type===`tag`&&(n=e[0].tag,e=e[0].body);var r=mG(e,t,`root`),i;r.length===2&&r[1].hasClass(`katex-tag`)&&(i=r.pop());for(var a=[],o=[],s=0;s0&&(a.push(xG(o,t)),o=[]),a.push(r[s]));o.length>0&&a.push(xG(o,t));var l;n?(l=xG(mG(n,t,!0),t),l.classes=[`katex-tag`],a.push(l)):i&&a.push(i);var u=X([`katex-html`],a);if(u.setAttribute(`aria-hidden`,`true`),l){var d=l.children[0];d.style.height=z(u.height+u.depth),u.depth&&(d.style.verticalAlign=z(-u.depth))}return u}function CG(e){return new vU(e)}var Q=class{constructor(e,t,n){this.type=void 0,this.attributes=void 0,this.children=void 0,this.classes=void 0,this.type=e,this.attributes={},this.children=t||[],this.classes=n||[]}setAttribute(e,t){this.attributes[e]=t}getAttribute(e){return this.attributes[e]}toNode(){var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,this.type);for(var t of Object.entries(this.attributes)){var n=t[0],r=t[1];e.setAttribute(n,r)}this.classes.length>0&&(e.className=CU(this.classes));for(var i=0;i0&&(e+=` class ="`+OH(CU(this.classes))+`"`),e+=`>`;for(var i=0;i`,e}toText(){return this.children.map(e=>e.toText()).join(``)}},wG=class{constructor(e){this.text=void 0,this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return OH(this.toText())}toText(){return this.text}},TG=class{constructor(e){this.width=void 0,this.character=void 0,this.width=e,this.character=e>=.05555&&e<=.05556?` `:e>=.1666&&e<=.1667?` `:e>=.2222&&e<=.2223?` `:e>=.2777&&e<=.2778?`  `:e>=-.05556&&e<=-.05555?` ⁣`:e>=-.1667&&e<=-.1666?` ⁣`:e>=-.2223&&e<=-.2222?` ⁣`:e>=-.2778&&e<=-.2777?` ⁣`:null}toNode(){if(this.character)return document.createTextNode(this.character);var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`mspace`);return e.setAttribute(`width`,z(this.width)),e}toMarkup(){return this.character?``+this.character+``:``}toText(){return this.character?this.character:` `}},EG=new Set([`\\imath`,`\\jmath`]),DG=new Set([`mrow`,`mtable`]),OG=function(e,t,n){var r,i;return qU[t][e]&&qU[t][e].replace&&e.charCodeAt(0)!==55349&&(!Object.prototype.hasOwnProperty.call(tW,e)||(n==null||(r=n.fontFamily)==null?void 0:r.slice(4,6))!==`tt`&&(n==null||(i=n.font)==null?void 0:i.slice(4,6))!==`tt`)&&(e=qU[t][e].replace),new wG(e)},kG=function(e){return e.length===1?e[0]:new Q(`mrow`,e)},AG={mathit:`italic`,boldsymbol:e=>e.type===`textord`?`bold`:`bold-italic`,mathbf:`bold`,mathbb:`double-struck`,mathsfit:`sans-serif-italic`,mathfrak:`fraktur`,mathscr:`script`,mathcal:`script`,mathsf:`sans-serif`,mathtt:`monospace`},jG=(e,t)=>{if(e.mode===`text`){if(t.fontFamily===`texttt`)return`monospace`;if(t.fontFamily===`textsf`)return t.fontShape===`textit`&&t.fontWeight===`textbf`?`sans-serif-bold-italic`:t.fontShape===`textit`?`sans-serif-italic`:t.fontWeight===`textbf`?`bold-sans-serif`:`sans-serif`;if(t.fontShape===`textit`&&t.fontWeight===`textbf`)return`bold-italic`;if(t.fontShape===`textit`)return`italic`;if(t.fontWeight===`textbf`)return`bold`}var n=t.font;if(!n||n===`mathnormal`)return null;var r=e.mode,i=AG[n];if(i)return typeof i==`function`?i(e):i;var a=e.text;if(EG.has(a))return null;if(qU[r][a]){var o=qU[r][a].replace;o&&(a=o)}var s=XW[n].fontName;return WU(a,s,r)?XW[n].variant:null};function MG(e){if(!e)return!1;if(e.type===`mi`&&e.children.length===1){var t=e.children[0];return t instanceof wG&&t.text===`.`}if(e.type===`mo`&&e.children.length===1&&e.getAttribute(`separator`)===`true`&&e.getAttribute(`lspace`)===`0em`&&e.getAttribute(`rspace`)===`0em`){var n=e.children[0];return n instanceof wG&&n.text===`,`}return!1}var NG=function(e,t,n){if(e.length===1){var r=FG(e[0],t);return n&&r instanceof Q&&r.type===`mo`&&(r.setAttribute(`lspace`,`0em`),r.setAttribute(`rspace`,`0em`)),[r]}for(var i=[],a,o=0;o=1&&(a.type===`mn`||MG(a))){var c=s.children[0];c instanceof Q&&c.type===`mn`&&(c.children=[...a.children,...c.children],i.pop())}else if(a.type===`mi`&&a.children.length===1){var l=a.children[0];if(l instanceof wG&&l.text===`̸`&&(s.type===`mo`||s.type===`mi`||s.type===`mn`)){var u=s.children[0];u instanceof wG&&u.text.length>0&&(u.text=u.text.slice(0,1)+`̸`+u.text.slice(1),i.pop())}}}i.push(s),a=s}return i},PG=function(e,t,n){return kG(NG(e,t,n))},FG=function(e,t){if(!e)return new Q(`mrow`);if(oG[e.type])return oG[e.type](e,t);throw new L(`Got group of unknown type: '`+e.type+`'`)};function IG(e,t,n,r,i){var a=NG(e,n),o=a.length===1&&a[0]instanceof Q&&DG.has(a[0].type)?a[0]:new Q(`mrow`,a),s=new Q(`annotation`,[new wG(t)]);s.setAttribute(`encoding`,`application/x-tex`);var c=new Q(`math`,[new Q(`semantics`,[o,s])]);return c.setAttribute(`xmlns`,`http://www.w3.org/1998/Math/MathML`),r&&c.setAttribute(`display`,`block`),X([i?`katex`:`katex-mathml`],[c])}var LG=[[1,1,1],[2,1,1],[3,1,1],[4,2,1],[5,2,1],[6,3,1],[7,4,2],[8,6,3],[9,7,6],[10,8,7],[11,10,9]],RG=[.5,.6,.7,.8,.9,1,1.2,1.44,1.728,2.074,2.488],zG=function(e,t){return t.size<2?e:LG[e-1][t.size-1]},BG=class e{constructor(t){this.style=void 0,this.color=void 0,this.size=void 0,this.textSize=void 0,this.phantom=void 0,this.font=void 0,this.fontFamily=void 0,this.fontWeight=void 0,this.fontShape=void 0,this.sizeMultiplier=void 0,this.maxSize=void 0,this.minRuleThickness=void 0,this._fontMetrics=void 0,this.style=t.style,this.color=t.color,this.size=t.size||e.BASESIZE,this.textSize=t.textSize||this.size,this.phantom=!!t.phantom,this.font=t.font||``,this.fontFamily=t.fontFamily||``,this.fontWeight=t.fontWeight||``,this.fontShape=t.fontShape||``,this.sizeMultiplier=RG[this.size-1],this.maxSize=t.maxSize,this.minRuleThickness=t.minRuleThickness,this._fontMetrics=void 0}extend(t){var n={style:this.style,size:this.size,textSize:this.textSize,color:this.color,phantom:this.phantom,font:this.font,fontFamily:this.fontFamily,fontWeight:this.fontWeight,fontShape:this.fontShape,maxSize:this.maxSize,minRuleThickness:this.minRuleThickness};return Object.assign(n,t),new e(n)}havingStyle(e){return this.style===e?this:this.extend({style:e,size:zG(this.textSize,e)})}havingCrampedStyle(){return this.havingStyle(this.style.cramp())}havingSize(e){return this.size===e&&this.textSize===e?this:this.extend({style:this.style.text(),size:e,textSize:e,sizeMultiplier:RG[e-1]})}havingBaseStyle(t){t||=this.style.text();var n=zG(e.BASESIZE,t);return this.size===n&&this.textSize===e.BASESIZE&&this.style===t?this:this.extend({style:t,size:n})}havingBaseSizing(){var e;switch(this.style.id){case 4:case 5:e=3;break;case 6:case 7:e=1;break;default:e=6}return this.extend({style:this.style.text(),size:e})}withColor(e){return this.extend({color:e})}withPhantom(){return this.extend({phantom:!0})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:``})}withTextFontWeight(e){return this.extend({fontWeight:e,font:``})}withTextFontShape(e){return this.extend({fontShape:e,font:``})}sizingClasses(e){return e.size===this.size?[]:[`katex-sizing`,`reset-size`+e.size,`size`+this.size]}baseSizingClasses(){return this.size===e.BASESIZE?[]:[`katex-sizing`,`reset-size`+this.size,`size`+e.BASESIZE]}fontMetrics(){return this._fontMetrics||=KU(this.size),this._fontMetrics}getColor(){return this.phantom?`transparent`:this.color}};BG.BASESIZE=6;var VG=function(e){return new BG({style:e.displayMode?R.DISPLAY:R.TEXT,maxSize:e.maxSize,minRuleThickness:e.minRuleThickness})},HG=function(e,t){if(t.displayMode){var n=[`katex-display`];t.leqno&&n.push(`leqno`),t.fleqn&&n.push(`fleqn`),e=X(n,[e])}return e},UG=function(e,t,n){var r=VG(n),i;return n.output===`mathml`?IG(e,t,r,n.displayMode,!0):(i=n.output===`html`?X([`katex`],[SG(e,r)]):X([`katex`],[IG(e,t,r,n.displayMode,!1),SG(e,r)]),HG(i,n))},WG=function(e,t,n){return HG(X([`katex`],[SG(e,VG(n))]),n)},GG={widehat:`^`,widecheck:`ˇ`,widetilde:`~`,utilde:`~`,overleftarrow:`←`,underleftarrow:`←`,xleftarrow:`←`,overrightarrow:`→`,underrightarrow:`→`,xrightarrow:`→`,underbrace:`⏟`,overbrace:`⏞`,underbracket:`⎵`,overbracket:`⎴`,overgroup:`⏠`,undergroup:`⏡`,overleftrightarrow:`↔`,underleftrightarrow:`↔`,xleftrightarrow:`↔`,Overrightarrow:`⇒`,xRightarrow:`⇒`,overleftharpoon:`↼`,xleftharpoonup:`↼`,overrightharpoon:`⇀`,xrightharpoonup:`⇀`,xLeftarrow:`⇐`,xLeftrightarrow:`⇔`,xhookleftarrow:`↩`,xhookrightarrow:`↪`,xmapsto:`↦`,xrightharpoondown:`⇁`,xleftharpoondown:`↽`,xrightleftharpoons:`⇌`,xleftrightharpoons:`⇋`,xtwoheadleftarrow:`↞`,xtwoheadrightarrow:`↠`,xlongequal:`=`,xtofrom:`⇄`,xrightleftarrows:`⇄`,xrightequilibrium:`⇌`,xleftequilibrium:`⇋`,"\\cdrightarrow":`→`,"\\cdleftarrow":`←`,"\\cdlongequal":`=`},KG=function(e){var t=new Q(`mo`,[new wG(GG[e.replace(/^\\/,``)])]);return t.setAttribute(`stretchy`,`true`),t},qG={overrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],overleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],underrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],underleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],xrightarrow:[[`rightarrow`],1.469,522,`xMaxYMin`],"\\cdrightarrow":[[`rightarrow`],3,522,`xMaxYMin`],xleftarrow:[[`leftarrow`],1.469,522,`xMinYMin`],"\\cdleftarrow":[[`leftarrow`],3,522,`xMinYMin`],Overrightarrow:[[`doublerightarrow`],.888,560,`xMaxYMin`],xRightarrow:[[`doublerightarrow`],1.526,560,`xMaxYMin`],xLeftarrow:[[`doubleleftarrow`],1.526,560,`xMinYMin`],overleftharpoon:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoonup:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoondown:[[`leftharpoondown`],.888,522,`xMinYMin`],overrightharpoon:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoonup:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoondown:[[`rightharpoondown`],.888,522,`xMaxYMin`],xlongequal:[[`longequal`],.888,334,`xMinYMin`],"\\cdlongequal":[[`longequal`],3,334,`xMinYMin`],xtwoheadleftarrow:[[`twoheadleftarrow`],.888,334,`xMinYMin`],xtwoheadrightarrow:[[`twoheadrightarrow`],.888,334,`xMaxYMin`],overleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],overbrace:[[`leftbrace`,`midbrace`,`rightbrace`],1.6,548],underbrace:[[`leftbraceunder`,`midbraceunder`,`rightbraceunder`],1.6,548],underleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],xleftrightarrow:[[`leftarrow`,`rightarrow`],1.75,522],xLeftrightarrow:[[`doubleleftarrow`,`doublerightarrow`],1.75,560],xrightleftharpoons:[[`leftharpoondownplus`,`rightharpoonplus`],1.75,716],xleftrightharpoons:[[`leftharpoonplus`,`rightharpoondownplus`],1.75,716],xhookleftarrow:[[`leftarrow`,`righthook`],1.08,522],xhookrightarrow:[[`lefthook`,`rightarrow`],1.08,522],overlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],underlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],overbracket:[[`leftbracketover`,`rightbracketover`],1.6,440],underbracket:[[`leftbracketunder`,`rightbracketunder`],1.6,410],overgroup:[[`leftgroup`,`rightgroup`],.888,342],undergroup:[[`leftgroupunder`,`rightgroupunder`],.888,342],xmapsto:[[`leftmapsto`,`rightarrow`],1.5,522],xtofrom:[[`leftToFrom`,`rightToFrom`],1.75,528],xrightleftarrows:[[`baraboveleftarrow`,`rightarrowabovebar`],1.75,901],xrightequilibrium:[[`baraboveshortleftharpoon`,`rightharpoonaboveshortbar`],1.75,716],xleftequilibrium:[[`shortbaraboveleftharpoon`,`shortrightharpoonabovebar`],1.75,716]},JG=new Set([`widehat`,`widecheck`,`widetilde`,`utilde`]),YG=function(e,t){function n(){var n=4e5,r=e.label.slice(1);if(JG.has(r)&&`base`in e){var i=e.base.type===`ordgroup`?e.base.body.length:1,a,o,s;if(i>5)r===`widehat`||r===`widecheck`?(a=420,n=2364,s=.42,o=r+`4`):(a=312,n=2340,s=.34,o=`tilde4`);else{var c=[1,1,2,2,3,3][i];r===`widehat`||r===`widecheck`?(n=[0,1062,2364,2364,2364][c],a=[0,239,300,360,420][c],s=[0,.24,.3,.3,.36,.42][c],o=r+c):(n=[0,600,1033,2339,2340][c],a=[0,260,286,306,312][c],s=[0,.26,.286,.3,.306,.34][c],o=`tilde`+c)}return{span:VW([],[new PU([new FU(o)],{width:`100%`,height:z(s),viewBox:`0 0 `+n+` `+a,preserveAspectRatio:`none`})],t),minWidth:0,height:s}}var l=[],u=qG[r];if(!u)throw Error(`No SVG data for "`+r+`".`);var d=u[0],f=u[1],p=u[2],m=p/1e3,h=d.length,g,_;if(h===1){if(u.length!==4)throw Error(`Expected 4-tuple for single-path SVG data "`+r+`".`);g=[`hide-tail`],_=[u[3]]}else if(h===2)g=[`halfarrow-left`,`halfarrow-right`],_=[`xMinYMin`,`xMaxYMin`];else if(h===3)g=[`brace-left`,`brace-center`,`brace-right`],_=[`xMinYMin`,`xMidYMin`,`xMaxYMin`];else throw Error(`Correct katexImagesData or update code here to support + `+h+` children.`);for(var v=0;v0&&(i.style.minWidth=z(a)),i},XG=function(e,t,n,r,i){var a,o=e.height+e.depth+n+r;if(/fbox|color|angl/.test(t)){if(a=X([`katex-stretchy`,t],[],i),t===`fbox`){var s=i.color&&i.getColor();s&&(a.style.borderColor=s)}}else{var c=[];/^[bx]cancel$/.test(t)&&c.push(new IU({x1:`0`,y1:`0`,x2:`100%`,y2:`100%`,"stroke-width":`0.046em`})),/^x?cancel$/.test(t)&&c.push(new IU({x1:`0`,y1:`100%`,x2:`100%`,y2:`0`,"stroke-width":`0.046em`})),a=VW([],[new PU(c,{width:`100%`,height:z(o)})],i)}return a.height=o,a.style.height=z(o),a},ZG=[`bin`,`close`,`inner`,`open`,`punct`,`rel`],QG=[`accent-token`,`mathord`,`op-token`,`spacing`,`textord`],$G=new Set(ZG),eK=new Set(QG);function tK(e){return $G.has(e)}function nK(e,t){if(!e||e.type!==t)throw Error(`Expected node of type `+t+`, but got `+(e?`node of type `+e.type:String(e)));return e}function rK(e){var t=iK(e);if(!t)throw Error(`Expected node of symbol group type, but got `+(e?`node of type `+e.type:String(e)));return t}function iK(e){return e.type===`atom`||eK.has(e.type)?e:null}function aK(e,t,n){var r=``;for(var i of e.body)if(i.type===`textord`)r+=i.text;else if(n&&i.type===`spacing`&&i.text===` `)r+=` `;else throw new L(t,e);return r}var oK=e=>{if(e instanceof NU)return e;if(zU(e)&&e.children.length===1)return oK(e.children[0])},sK=(e,t)=>{var n,r,i;e&&e.type===`supsub`?(r=nK(e.base,`accent`),n=r.base,e.base=n,i=RU(bG(e,t)),e.base=r):(r=nK(e,`accent`),n=r.base);var a=bG(n,t.havingCrampedStyle()),o=r.isShifty&&jH(n),s=0;o&&(s=oK(a)?.skew??0);var c=r.label===`\\c`,l=c?a.height+a.depth:Math.min(a.height,t.fontMetrics().xHeight),u;if(r.isStretchy)u=YG(r,t),u=qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`elem`,elem:u,wrapperClasses:[`svg-align`],wrapperStyle:s>0?{width:`calc(100% - `+z(2*s)+`)`,marginLeft:z(2*s)}:void 0}]});else{var d,f;r.label===`\\vec`?(d=QW(`vec`,t),f=ZW.vec[1]):(d=LW({type:`textord`,mode:r.mode,text:r.label},t),d=LU(d),d.italic=0,f=d.width,c&&(l+=d.depth)),u=X([`accent-body`],[d]);var p=r.label===`\\textcircled`;p&&(u.classes.push(`accent-full`),l=a.height);var m=s;p||(m-=f/2),u.style.left=z(m),r.label===`\\textcircled`&&(u.style.top=`.2em`),u=qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:-l},{type:`elem`,elem:u}]})}var h=X([`mord`,`katex-accent`],[u],t);return i?(i.children[0]=h,i.height=Math.max(h.height,i.height),i.classes[0]=`mord`,i):h},cK=(e,t)=>{var n=e.isStretchy?KG(e.label):new Q(`mo`,[OG(e.label,e.mode)]),r=new Q(`mover`,[FG(e.base,t),n]);return r.setAttribute(`accent`,`true`),r},lK=new RegExp([`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`].map(e=>`\\`+e).join(`|`));Z({type:`accent`,names:[`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`,`\\widecheck`,`\\widehat`,`\\widetilde`,`\\overrightarrow`,`\\overleftarrow`,`\\Overrightarrow`,`\\overleftrightarrow`,`\\overgroup`,`\\overlinesegment`,`\\overleftharpoon`,`\\overrightharpoon`],numArgs:1,handler:(e,t)=>{var n=cG(t[0]),r=!lK.test(e.funcName),i=!r||e.funcName===`\\widehat`||e.funcName===`\\widetilde`||e.funcName===`\\widecheck`;return{type:`accent`,mode:e.parser.mode,label:e.funcName,isStretchy:r,isShifty:i,base:n}},htmlBuilder:sK,mathmlBuilder:cK}),Z({type:`accent`,names:[`\\'`,"\\`",`\\^`,`\\~`,`\\=`,`\\u`,`\\.`,`\\"`,`\\c`,`\\r`,`\\H`,`\\v`,`\\textcircled`],numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`primitive`],handler:(e,t)=>{var n=t[0],r=e.parser.mode;return r===`math`&&(e.parser.settings.reportNonstrict(`mathVsTextAccents`,`LaTeX's accent `+e.funcName+` works only in text mode`),r=`text`),{type:`accent`,mode:r,label:e.funcName,isStretchy:!1,isShifty:!0,base:n}}}),Z({type:`accentUnder`,names:[`\\underleftarrow`,`\\underrightarrow`,`\\underleftrightarrow`,`\\undergroup`,`\\underlinesegment`,`\\utilde`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`accentUnder`,mode:n.mode,label:r,base:i}},htmlBuilder:(e,t)=>{var n=bG(e.base,t),r=YG(e,t),i=e.label===`\\utilde`?.12:0;return X([`mord`,`accentunder`],[qW({positionType:`top`,positionData:n.height,children:[{type:`elem`,elem:r,wrapperClasses:[`svg-align`]},{type:`kern`,size:i},{type:`elem`,elem:n}]})],t)},mathmlBuilder:(e,t)=>{var n=KG(e.label),r=new Q(`munder`,[FG(e.base,t),n]);return r.setAttribute(`accentunder`,`true`),r}});var uK=e=>{var t=new Q(`mpadded`,e?[e]:[]);return t.setAttribute(`width`,`+0.6em`),t.setAttribute(`lspace`,`0.3em`),t};Z({type:`xArrow`,names:[`\\xleftarrow`,`\\xrightarrow`,`\\xLeftarrow`,`\\xRightarrow`,`\\xleftrightarrow`,`\\xLeftrightarrow`,`\\xhookleftarrow`,`\\xhookrightarrow`,`\\xmapsto`,`\\xrightharpoondown`,`\\xrightharpoonup`,`\\xleftharpoondown`,`\\xleftharpoonup`,`\\xrightleftharpoons`,`\\xleftrightharpoons`,`\\xlongequal`,`\\xtwoheadrightarrow`,`\\xtwoheadleftarrow`,`\\xtofrom`,`\\xrightleftarrows`,`\\xrightequilibrium`,`\\xleftequilibrium`,`\\\\cdrightarrow`,`\\\\cdleftarrow`,`\\\\cdlongequal`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=e.funcName;return{type:`xArrow`,mode:r.mode,label:i,body:t[0],below:n[0]}},htmlBuilder(e,t){var n=t.style,r=t.havingStyle(n.sup()),i=GW(bG(e.body,r,t),t),a=e.label.slice(0,2)===`\\x`?`x`:`cd`;i.classes.push(a+`-arrow-pad`);var o;e.below&&(r=t.havingStyle(n.sub()),o=GW(bG(e.below,r,t),t),o.classes.push(a+`-arrow-pad`));var s=YG(e,t),c=-t.fontMetrics().axisHeight+.5*s.height,l=-t.fontMetrics().axisHeight-.5*s.height-.111;(i.depth>.25||e.label===`\\xleftequilibrium`)&&(l-=i.depth);var u;if(o){var d=-t.fontMetrics().axisHeight+o.height+.5*s.height+.111;u=qW({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]},{type:`elem`,elem:o,shift:d}]})}else u=qW({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]}]});return X([`mrel`,`x-arrow`],[u],t)},mathmlBuilder(e,t){var n=KG(e.label);n.setAttribute(`minsize`,e.label.charAt(0)===`x`?`1.75em`:`3.0em`);var r;if(e.body){var i=uK(FG(e.body,t));r=e.below?new Q(`munderover`,[n,uK(FG(e.below,t)),i]):new Q(`mover`,[n,i])}else e.below?r=new Q(`munder`,[n,uK(FG(e.below,t))]):(r=uK(),r=new Q(`mover`,[n,r]));return r}});function dK(e,t){var n=mG(e.body,t,!0);return X([e.mclass],n,t)}function fK(e,t){var n,r=NG(e.body,t);return e.mclass===`minner`?n=new Q(`mpadded`,r):e.mclass===`mord`?e.isCharacterBox?(n=r[0],n.type=`mi`):n=new Q(`mi`,r):(e.isCharacterBox?(n=r[0],n.type=`mo`):n=new Q(`mo`,r),e.mclass===`mbin`?(n.attributes.lspace=`0.22em`,n.attributes.rspace=`0.22em`):e.mclass===`mpunct`?(n.attributes.lspace=`0em`,n.attributes.rspace=`0.17em`):(e.mclass===`mopen`||e.mclass===`mclose`)&&(n.attributes.lspace=`0em`,n.attributes.rspace=`0em`)),n}Z({type:`mclass`,names:[`\\mathord`,`\\mathbin`,`\\mathrel`,`\\mathopen`,`\\mathclose`,`\\mathpunct`,`\\mathinner`],numArgs:1,primitive:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`mclass`,mode:n.mode,mclass:`m`+r.slice(5),body:lG(i),isCharacterBox:jH(i)}},htmlBuilder:dK,mathmlBuilder:fK});var pK=e=>{var t=e.type===`ordgroup`&&e.body.length?e.body[0]:e;return t.type===`atom`&&(t.family===`bin`||t.family===`rel`)?`m`+t.family:`mord`};Z({type:`mclass`,names:[`\\@binrel`],numArgs:2,handler(e,t){return{type:`mclass`,mode:e.parser.mode,mclass:pK(t[0]),body:lG(t[1]),isCharacterBox:jH(t[1])}}}),Z({type:`mclass`,names:[`\\stackrel`,`\\overset`,`\\underset`],numArgs:2,handler(e,t){var n=e.parser,r=e.funcName,i=t[1],a=t[0],o=r===`\\stackrel`?`mrel`:pK(i),s={type:`op`,mode:i.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:r!==`\\stackrel`,body:lG(i)},c=r===`\\underset`?{type:`supsub`,mode:a.mode,base:s,sub:a}:{type:`supsub`,mode:a.mode,base:s,sup:a};return{type:`mclass`,mode:n.mode,mclass:o,body:[c],isCharacterBox:jH(c)}}}),Z({type:`pmb`,names:[`\\pmb`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`pmb`,mode:e.parser.mode,mclass:pK(t[0]),body:lG(t[0])}},htmlBuilder(e,t){var n=mG(e.body,t,!0),r=X([e.mclass],n,t);return r.style.textShadow=`0.02em 0.01em 0.04px`,r},mathmlBuilder(e,t){var n=new Q(`mstyle`,NG(e.body,t));return n.setAttribute(`style`,`text-shadow: 0.02em 0.01em 0.04px`),n}});var mK={">":`\\\\cdrightarrow`,"<":`\\\\cdleftarrow`,"=":`\\\\cdlongequal`,A:`\\uparrow`,V:`\\downarrow`,"|":`\\Vert`,".":`no arrow`},hK=()=>({type:`styling`,body:[],mode:`math`,style:`display`,resetFont:!0}),gK=e=>e.type===`textord`&&e.text===`@`,_K=(e,t)=>(e.type===`mathord`||e.type===`atom`)&&e.text===t;function vK(e,t,n){var r=mK[e];switch(r){case`\\\\cdrightarrow`:case`\\\\cdleftarrow`:return n.callFunction(r,[t[0]],[t[1]]);case`\\uparrow`:case`\\downarrow`:var i=n.callFunction(`\\\\cdleft`,[t[0]],[]),a={type:`atom`,text:r,mode:`math`,family:`rel`},o={type:`ordgroup`,mode:`math`,body:[i,n.callFunction(`\\Big`,[a],[]),n.callFunction(`\\\\cdright`,[t[1]],[])]};return n.callFunction(`\\\\cdparent`,[o],[]);case`\\\\cdlongequal`:return n.callFunction(`\\\\cdlongequal`,[],[]);case`\\Vert`:return n.callFunction(`\\Big`,[{type:`textord`,text:`\\Vert`,mode:`math`}],[]);default:return{type:`textord`,text:` `,mode:`math`}}}function yK(e){var t=[];for(e.gullet.beginGroup(),e.gullet.macros.set(`\\cr`,`\\\\\\relax`),e.gullet.beginGroup();;){t.push(e.parseExpression(!1,`\\\\`)),e.gullet.endGroup(),e.gullet.beginGroup();var n=e.fetch().text;if(n===`&`||n===`\\\\`)e.consume();else if(n===`\\end`){t[t.length-1].length===0&&t.pop();break}else throw new L(`Expected \\\\ or \\cr or \\end`,e.nextToken)}for(var r=[],i=[r],a=0;aAV`.includes(l))for(var d=0;d<2;d++){for(var f=!0,p=c+1;pAV=|." after @`,o[c])}var m={type:`styling`,body:[vK(l,u,e)],mode:`math`,style:`display`,resetFont:!0};r.push(m),s=hK()}a%2==0?r.push(s):r.shift(),r=[],i.push(r)}return e.gullet.endGroup(),e.gullet.endGroup(),{type:`array`,mode:`math`,body:i,arraystretch:1,addJot:!0,rowGaps:[null],cols:Array(i[0].length).fill({type:`align`,align:`c`,pregap:.25,postgap:.25}),colSeparationType:`CD`,hLinesBeforeRow:Array(i.length+1).fill([])}}Z({type:`cdlabel`,names:[`\\\\cdleft`,`\\\\cdright`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`cdlabel`,mode:n.mode,side:r.slice(4),label:t[0]}},htmlBuilder(e,t){var n=t.havingStyle(t.style.sup()),r=GW(bG(e.label,n,t),t);return r.classes.push(`cd-label-`+e.side),r.style.bottom=z(.8-r.depth),r.height=0,r.depth=0,r},mathmlBuilder(e,t){var n=new Q(`mrow`,[FG(e.label,t)]);return n=new Q(`mpadded`,[n]),n.setAttribute(`width`,`0`),e.side===`left`&&n.setAttribute(`lspace`,`-1width`),n.setAttribute(`voffset`,`0.7em`),n=new Q(`mstyle`,[n]),n.setAttribute(`displaystyle`,`false`),n.setAttribute(`scriptlevel`,`1`),n}}),Z({type:`cdlabelparent`,names:[`\\\\cdparent`],numArgs:1,handler(e,t){return{type:`cdlabelparent`,mode:e.parser.mode,fragment:t[0]}},htmlBuilder(e,t){var n=GW(bG(e.fragment,t),t);return n.classes.push(`cd-vert-arrow`),n},mathmlBuilder(e,t){return new Q(`mrow`,[FG(e.fragment,t)])}}),Z({type:`textord`,names:[`\\@char`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=aK(nK(t[0],`ordgroup`),`\\@char has non-numeric argument`),i=parseInt(r),a;if(isNaN(i))throw new L(`\\@char has non-numeric argument `+r);if(i<0||i>1114111)throw new L(`\\@char with invalid code point `+r);return i<=65535?a=String.fromCharCode(i):(i-=65536,a=String.fromCharCode((i>>10)+55296,(i&1023)+56320)),{type:`textord`,mode:n.mode,text:a}}}),Z({type:`color`,names:[`\\textcolor`],numArgs:2,allowedInText:!0,argTypes:[`color`,`original`],handler(e,t){var n=e.parser,r=nK(t[0],`color-token`).color,i=t[1];return{type:`color`,mode:n.mode,color:r,body:lG(i)}},htmlBuilder:(e,t)=>WW(mG(e.body,t.withColor(e.color),!1)),mathmlBuilder:(e,t)=>{var n=new Q(`mstyle`,NG(e.body,t.withColor(e.color)));return n.setAttribute(`mathcolor`,e.color),n}}),Z({type:`color`,names:[`\\color`],numArgs:1,allowedInText:!0,argTypes:[`color`],handler(e,t){var n=e.parser,r=e.breakOnTokenText,i=nK(t[0],`color-token`).color;n.gullet.macros.set(`\\current@color`,i);var a=n.parseExpression(!0,r);return{type:`color`,mode:n.mode,color:i,body:a}}}),Z({type:`cr`,names:[`\\\\`],numArgs:0,numOptionalArgs:0,allowedInText:!0,handler(e,t,n){var r=e.parser,i=r.gullet.future().text===`[`?r.parseSizeGroup(!0):null,a=!r.settings.displayMode||!r.settings.useStrictBehavior(`newLineInDisplayMode`,`In LaTeX, \\\\ or \\newline does nothing in display mode`);return{type:`cr`,mode:r.mode,newLine:a,size:i&&nK(i,`size`).value}},htmlBuilder(e,t){var n=X([`mspace`],[],t);return e.newLine&&(n.classes.push(`katex-newline`),e.size&&(n.style.marginTop=z(SU(e.size,t)))),n},mathmlBuilder(e,t){var n=new Q(`mspace`);return e.newLine&&(n.setAttribute(`linebreak`,`newline`),e.size&&n.setAttribute(`height`,z(SU(e.size,t)))),n}});var bK={"\\global":`\\global`,"\\long":`\\\\globallong`,"\\\\globallong":`\\\\globallong`,"\\def":`\\gdef`,"\\gdef":`\\gdef`,"\\edef":`\\xdef`,"\\xdef":`\\xdef`,"\\let":`\\\\globallet`,"\\futurelet":`\\\\globalfuture`},xK=e=>{var t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new L(`Expected a control sequence`,e);return t},SK=e=>{var t=e.gullet.popToken();return t.text===`=`&&(t=e.gullet.popToken(),t.text===` `&&(t=e.gullet.popToken())),t},CK=(e,t,n,r)=>{var i=e.gullet.macros.get(n.text);i??=(n.noexpand=!0,{tokens:[n],numArgs:0,unexpandable:!e.gullet.isExpandable(n.text)}),e.gullet.macros.set(t,i,r)};Z({type:`internal`,names:[`\\global`,`\\long`,`\\\\globallong`],numArgs:0,allowedInText:!0,handler(e){var t=e.parser,n=e.funcName;t.consumeSpaces();var r=t.fetch();if(bK[r.text])return(n===`\\global`||n===`\\\\globallong`)&&(r.text=bK[r.text]),nK(t.parseFunction(),`internal`);throw new L(`Invalid token after macro prefix`,r)}}),Z({type:`internal`,names:[`\\def`,`\\gdef`,`\\edef`,`\\xdef`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=t.gullet.popToken(),i=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(i))throw new L(`Expected a control sequence`,r);for(var a=0,o,s=[[]];t.gullet.future().text!==`{`;)if(r=t.gullet.popToken(),r.text===`#`){if(t.gullet.future().text===`{`){o=t.gullet.future(),s[a].push(`{`);break}if(r=t.gullet.popToken(),!/^[1-9]$/.test(r.text))throw new L(`Invalid argument number "`+r.text+`"`);if(parseInt(r.text)!==a+1)throw new L(`Argument number "`+r.text+`" out of order`);a++,s.push([])}else if(r.text===`EOF`)throw new L(`Expected a macro definition`);else s[a].push(r.text);var c=t.gullet.consumeArg().tokens;return o&&c.unshift(o),(n===`\\edef`||n===`\\xdef`)&&(c=t.gullet.expandTokens(c),c.reverse()),t.gullet.macros.set(i,{tokens:c,numArgs:a,delimiters:s},n===bK[n]),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\let`,`\\\\globallet`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=xK(t.gullet.popToken());return t.gullet.consumeSpaces(),CK(t,r,SK(t),n===`\\\\globallet`),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\futurelet`,`\\\\globalfuture`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=xK(t.gullet.popToken()),i=t.gullet.popToken(),a=t.gullet.popToken();return CK(t,r,a,n===`\\\\globalfuture`),t.gullet.pushToken(a),t.gullet.pushToken(i),{type:`internal`,mode:t.mode}}});var wK=function(e,t,n){var r=WU(qU.math[e]&&qU.math[e].replace||e,t,n);if(!r)throw Error(`Unsupported symbol `+e+` and font size `+t+`.`);return r},TK=function(e,t,n,r){var i=n.havingBaseStyle(t),a=X(r.concat(i.sizingClasses(n)),[e],n),o=i.sizeMultiplier/n.sizeMultiplier;return a.height*=o,a.depth*=o,a.maxFontSize=i.sizeMultiplier,a},EK=function(e,t,n){var r=t.havingBaseStyle(n),i=(1-t.sizeMultiplier/r.sizeMultiplier)*t.fontMetrics().axisHeight;e.classes.push(`delimcenter`),e.style.top=z(i),e.height-=i,e.depth+=i},DK=function(e,t,n,r,i,a){var o=TK(PW(e,`Main-Regular`,i,r),t,r,a);return n&&EK(o,r,t),o},OK=function(e,t,n,r){return PW(e,`Size`+t+`-Regular`,n,r)},kK=function(e,t,n,r,i,a){var o=OK(e,t,i,r),s=TK(X([`delimsizing`,`size`+t],[o],r),R.TEXT,r,a);return n&&EK(s,r,R.TEXT),s},AK=function(e,t,n){return{type:`elem`,elem:X([`delimsizinginner`,t===`Size1-Regular`?`delim-size1`:`delim-size4`],[X([],[PW(e,t,n)])])}},jK=function(e,t,n){var r=BU[`Size4-Regular`][e.charCodeAt(0)]?BU[`Size4-Regular`][e.charCodeAt(0)][4]:BU[`Size1-Regular`][e.charCodeAt(0)][4],i=VW([],[new PU([new FU(`inner`,mU(e,Math.round(1e3*t)))],{width:z(r),height:z(t),style:`width:`+z(r),viewBox:`0 0 `+1e3*r+` `+Math.round(1e3*t),preserveAspectRatio:`xMinYMin`})],n);return i.height=t,i.style.height=z(t),i.style.width=z(r),{type:`elem`,elem:i}},MK=.008,NK={type:`kern`,size:-1*MK},PK=new Set([`|`,`\\lvert`,`\\rvert`,`\\vert`]),FK=new Set([`\\|`,`\\lVert`,`\\rVert`,`\\Vert`]),IK=function(e,t,n,r,i,a){var o,s,c,l,u=``,d=0;o=c=l=e,s=null;var f=`Size1-Regular`;e===`\\uparrow`?c=l=`⏐`:e===`\\Uparrow`?c=l=`‖`:e===`\\downarrow`?o=c=`⏐`:e===`\\Downarrow`?o=c=`‖`:e===`\\updownarrow`?(o=`\\uparrow`,c=`⏐`,l=`\\downarrow`):e===`\\Updownarrow`?(o=`\\Uparrow`,c=`‖`,l=`\\Downarrow`):PK.has(e)?(c=`∣`,u=`vert`,d=333):FK.has(e)?(c=`∥`,u=`doublevert`,d=556):e===`[`||e===`\\lbrack`?(o=`⎡`,c=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lbrack`,d=667):e===`]`||e===`\\rbrack`?(o=`⎤`,c=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rbrack`,d=667):e===`\\lfloor`||e===`⌊`?(c=o=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lfloor`,d=667):e===`\\lceil`||e===`⌈`?(o=`⎡`,c=l=`⎢`,f=`Size4-Regular`,u=`lceil`,d=667):e===`\\rfloor`||e===`⌋`?(c=o=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rfloor`,d=667):e===`\\rceil`||e===`⌉`?(o=`⎤`,c=l=`⎥`,f=`Size4-Regular`,u=`rceil`,d=667):e===`(`||e===`\\lparen`?(o=`⎛`,c=`⎜`,l=`⎝`,f=`Size4-Regular`,u=`lparen`,d=875):e===`)`||e===`\\rparen`?(o=`⎞`,c=`⎟`,l=`⎠`,f=`Size4-Regular`,u=`rparen`,d=875):e===`\\{`||e===`\\lbrace`?(o=`⎧`,s=`⎨`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\}`||e===`\\rbrace`?(o=`⎫`,s=`⎬`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lgroup`||e===`⟮`?(o=`⎧`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\rgroup`||e===`⟯`?(o=`⎫`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lmoustache`||e===`⎰`?(o=`⎧`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):(e===`\\rmoustache`||e===`⎱`)&&(o=`⎫`,l=`⎩`,c=`⎪`,f=`Size4-Regular`);var p=wK(o,f,i),m=p.height+p.depth,h=wK(c,f,i),g=h.height+h.depth,_=wK(l,f,i),v=_.height+_.depth,y=0,b=1;if(s!==null){var x=wK(s,f,i);y=x.height+x.depth,b=2}var S=m+v+y,C=S+Math.max(0,Math.ceil((t-S)/(b*g)))*b*g,ee=r.fontMetrics().axisHeight;n&&(ee*=r.sizeMultiplier);var te=C/2-ee,ne=[];if(u.length>0){var re=C-m-v,ie=Math.round(C*1e3),ae=gU(u,Math.round(re*1e3)),oe=new FU(u,ae),se=z(d/1e3),ce=z(ie/1e3),le=VW([],[new PU([oe],{width:se,height:ce,viewBox:`0 0 `+d+` `+ie})],r);le.height=ie/1e3,le.style.width=se,le.style.height=ce,ne.push({type:`elem`,elem:le})}else{if(ne.push(AK(l,f,i)),ne.push(NK),s===null){var ue=C-m-v+2*MK;ne.push(jK(c,ue,r))}else{var de=(C-m-v-y)/2+2*MK;ne.push(jK(c,de,r)),ne.push(NK),ne.push(AK(s,f,i)),ne.push(NK),ne.push(jK(c,de,r))}ne.push(NK),ne.push(AK(o,f,i))}var fe=r.havingBaseStyle(R.TEXT);return TK(X([`delimsizing`,`mult`],[qW({positionType:`bottom`,positionData:te,children:ne})],fe),R.TEXT,r,a)},LK=80,RK=.08,zK=function(e,t,n,r,i){return VW([`hide-tail`],[new PU([new FU(e,pU(e,r,n))],{width:`400em`,height:z(t),viewBox:`0 0 400000 `+n,preserveAspectRatio:`xMinYMin slice`})],i)},BK=function(e,t){var n=t.havingBaseSizing(),r=XK(`\\surd`,e*n.sizeMultiplier,JK,n),i=n.sizeMultiplier,a=Math.max(0,t.minRuleThickness-t.fontMetrics().sqrtRuleThickness),o,s,c,l,u;return r.type===`small`?(l=1e3+1e3*a+LK,e<1?i=1:e<1.4&&(i=.7),s=(1+a+RK)/i,c=(1+a)/i,o=zK(`sqrtMain`,s,l,a,t),o.style.minWidth=`0.853em`,u=.833/i):r.type===`large`?(l=(1e3+LK)*WK[r.size],c=(WK[r.size]+a)/i,s=(WK[r.size]+a+RK)/i,o=zK(`sqrtSize`+r.size,s,l,a,t),o.style.minWidth=`1.02em`,u=1/i):(s=e+a+RK,c=e+a,l=Math.floor(1e3*e+a)+LK,o=zK(`sqrtTall`,s,l,a,t),o.style.minWidth=`0.742em`,u=1.056),o.height=c,o.style.height=z(s),{span:o,advanceWidth:u,ruleWidth:(t.fontMetrics().sqrtRuleThickness+a)*i}},VK=new Set([`(`,`\\lparen`,`)`,`\\rparen`,`[`,`\\lbrack`,`]`,`\\rbrack`,`\\{`,`\\lbrace`,`\\}`,`\\rbrace`,`\\lfloor`,`\\rfloor`,`⌊`,`⌋`,`\\lceil`,`\\rceil`,`⌈`,`⌉`,`\\surd`]),HK=new Set([`\\uparrow`,`\\downarrow`,`\\updownarrow`,`\\Uparrow`,`\\Downarrow`,`\\Updownarrow`,`|`,`\\|`,`\\vert`,`\\Vert`,`\\lvert`,`\\rvert`,`\\lVert`,`\\rVert`,`\\lgroup`,`\\rgroup`,`⟮`,`⟯`,`\\lmoustache`,`\\rmoustache`,`⎰`,`⎱`]),UK=new Set([`<`,`>`,`\\langle`,`\\rangle`,`/`,`\\backslash`,`\\lt`,`\\gt`]),WK=[0,1.2,1.8,2.4,3],GK=function(e,t,n,r,i){if(e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`),VK.has(e)||UK.has(e))return kK(e,t,!1,n,r,i);if(HK.has(e))return IK(e,WK[t],!1,n,r,i);throw new L(`Illegal delimiter: '`+e+`'`)},KK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4}],qK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`stack`}],JK=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4},{type:`stack`}],YK=function(e){if(e.type===`small`)return`Main-Regular`;if(e.type===`large`)return`Size`+e.size+`-Regular`;if(e.type===`stack`)return`Size4-Regular`;var t=e.type;throw Error(`Add support for delim type '`+t+`' here.`)},XK=function(e,t,n,r){for(var i=Math.min(2,3-r.style.size);it)return a}return n[n.length-1]},ZK=function(e,t,n,r,i,a){e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`);var o=UK.has(e)?KK:VK.has(e)?JK:qK,s=XK(e,t,o,r);return s.type===`small`?DK(e,s.style,n,r,i,a):s.type===`large`?kK(e,s.size,n,r,i,a):IK(e,t,n,r,i,a)},QK=function(e,t,n,r,i,a){var o=r.fontMetrics().axisHeight*r.sizeMultiplier,s=901,c=5/r.fontMetrics().ptPerEm,l=Math.max(t-o,n+o);return ZK(e,Math.max(l/500*s,2*l-c),!0,r,i,a)},$K={"\\bigl":{mclass:`mopen`,size:1},"\\Bigl":{mclass:`mopen`,size:2},"\\biggl":{mclass:`mopen`,size:3},"\\Biggl":{mclass:`mopen`,size:4},"\\bigr":{mclass:`mclose`,size:1},"\\Bigr":{mclass:`mclose`,size:2},"\\biggr":{mclass:`mclose`,size:3},"\\Biggr":{mclass:`mclose`,size:4},"\\bigm":{mclass:`mrel`,size:1},"\\Bigm":{mclass:`mrel`,size:2},"\\biggm":{mclass:`mrel`,size:3},"\\Biggm":{mclass:`mrel`,size:4},"\\big":{mclass:`mord`,size:1},"\\Big":{mclass:`mord`,size:2},"\\bigg":{mclass:`mord`,size:3},"\\Bigg":{mclass:`mord`,size:4}},eq=new Set(`(,\\lparen,),\\rparen,[,\\lbrack,],\\rbrack,\\{,\\lbrace,\\},\\rbrace,\\lfloor,\\rfloor,⌊,⌋,\\lceil,\\rceil,⌈,⌉,<,>,\\langle,⟨,\\rangle,⟩,\\lt,\\gt,\\lvert,\\rvert,\\lVert,\\rVert,\\lgroup,\\rgroup,⟮,⟯,\\lmoustache,\\rmoustache,⎰,⎱,/,\\backslash,|,\\vert,\\|,\\Vert,\\uparrow,\\Uparrow,\\downarrow,\\Downarrow,\\updownarrow,\\Updownarrow,.`.split(`,`));function tq(e){return`isMiddle`in e}function nq(e,t){var n=iK(e);if(n&&eq.has(n.text))return n;throw n?new L(`Invalid delimiter '`+n.text+`' after '`+t.funcName+`'`,e):new L(`Invalid delimiter type '`+e.type+`'`,e)}Z({type:`delimsizing`,names:[`\\bigl`,`\\Bigl`,`\\biggl`,`\\Biggl`,`\\bigr`,`\\Bigr`,`\\biggr`,`\\Biggr`,`\\bigm`,`\\Bigm`,`\\biggm`,`\\Biggm`,`\\big`,`\\Big`,`\\bigg`,`\\Bigg`],numArgs:1,argTypes:[`primitive`],handler:(e,t)=>{var n=nq(cG(t[0]),e);return{type:`delimsizing`,mode:e.parser.mode,size:$K[e.funcName].size,mclass:$K[e.funcName].mclass,delim:n.text}},htmlBuilder:(e,t)=>e.delim===`.`?X([e.mclass]):GK(e.delim,e.size,t,e.mode,[e.mclass]),mathmlBuilder:e=>{var t=[];e.delim!==`.`&&t.push(OG(e.delim,e.mode));var n=new Q(`mo`,t);e.mclass===`mopen`||e.mclass===`mclose`?n.setAttribute(`fence`,`true`):n.setAttribute(`fence`,`false`),n.setAttribute(`stretchy`,`true`);var r=z(WK[e.size]);return n.setAttribute(`minsize`,r),n.setAttribute(`maxsize`,r),n}});function rq(e){if(!e.body)throw Error(`Bug: The leftright ParseNode wasn't fully parsed.`)}Z({type:`leftright-right`,names:[`\\right`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser.gullet.macros.get(`\\current@color`);if(n&&typeof n!=`string`)throw new L(`\\current@color set to non-string in \\right`);return{type:`leftright-right`,mode:e.parser.mode,delim:nq(t[0],e).text,color:n}}}),Z({type:`leftright`,names:[`\\left`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=nq(t[0],e),r=e.parser;++r.leftrightDepth;var i=r.parseExpression(!1);--r.leftrightDepth,r.expect(`\\right`,!1);var a=nK(r.parseFunction(),`leftright-right`);return{type:`leftright`,mode:r.mode,body:i,left:n.text,right:a.delim,rightColor:a.color}},htmlBuilder:(e,t)=>{rq(e);for(var n=mG(e.body,t,!0,[`mopen`,`mclose`]),r=0,i=0,a=!1,o=0;o{rq(e);var n=NG(e.body,t);if(e.left!==`.`){var r=new Q(`mo`,[OG(e.left,e.mode)]);r.setAttribute(`fence`,`true`),n.unshift(r)}if(e.right!==`.`){var i=new Q(`mo`,[OG(e.right,e.mode)]);i.setAttribute(`fence`,`true`),e.rightColor&&i.setAttribute(`mathcolor`,e.rightColor),n.push(i)}return kG(n)}}),Z({type:`middle`,names:[`\\middle`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=nq(t[0],e);if(!e.parser.leftrightDepth)throw new L(`\\middle without preceding \\left`,n);return{type:`middle`,mode:e.parser.mode,delim:n.text}},htmlBuilder:(e,t)=>{var n;return e.delim===`.`?n=yG(t,[]):(n=GK(e.delim,1,t,e.mode,[]),n.isMiddle={delim:e.delim,options:t}),n},mathmlBuilder:(e,t)=>{var n=new Q(`mo`,[e.delim===`\\vert`||e.delim===`|`?OG(`|`,`text`):OG(e.delim,e.mode)]);return n.setAttribute(`fence`,`true`),n.setAttribute(`lspace`,`0.05em`),n.setAttribute(`rspace`,`0.05em`),n}}),Z({type:`enclose`,names:[`\\colorbox`],numArgs:2,allowedInText:!0,argTypes:[`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=nK(t[0],`color-token`).color,o=t[1];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:a,body:o}},htmlBuilder:(e,t)=>{var n=GW(bG(e.body,t),t),r=e.label.slice(1),i=t.sizeMultiplier,a,o,s=jH(e.body);if(r===`sout`)a=X([`katex-stretchy`,`katex-sout`]),a.height=t.fontMetrics().defaultRuleThickness/i,o=-.5*t.fontMetrics().xHeight;else if(r===`phase`){var c=SU({number:.6,unit:`pt`},t),l=SU({number:.35,unit:`ex`},t),u=t.havingBaseSizing();i/=u.sizeMultiplier;var d=n.height+n.depth+c+l;n.style.paddingLeft=z(d/2+c);var f=Math.floor(1e3*d*i);a=VW([`hide-tail`],[new PU([new FU(`phase`,dU(f))],{width:`400em`,height:z(f/1e3),viewBox:`0 0 400000 `+f,preserveAspectRatio:`xMinYMin slice`})],t),a.style.height=z(d),o=n.depth+c+l}else{/cancel/.test(r)?s||n.classes.push(`cancel-pad`):r===`angl`?n.classes.push(`anglpad`):n.classes.push(`boxpad`);var p,m,h=0;/box/.test(r)?(h=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness),p=t.fontMetrics().fboxsep+(r===`colorbox`?0:h),m=p):r===`angl`?(h=Math.max(t.fontMetrics().defaultRuleThickness,t.minRuleThickness),p=4*h,m=Math.max(0,.25-n.depth)):(p=s?.2:0,m=p),a=XG(n,r,p,m,t),/fbox|boxed|fcolorbox/.test(r)?(a.style.borderStyle=`solid`,a.style.borderWidth=z(h)):r===`angl`&&h!==.049&&(a.style.borderTopWidth=z(h),a.style.borderRightWidth=z(h)),o=n.depth+m,e.backgroundColor&&(a.style.backgroundColor=e.backgroundColor,e.borderColor&&(a.style.borderColor=e.borderColor))}var g;if(e.backgroundColor)g=qW({positionType:`individualShift`,children:[{type:`elem`,elem:a,shift:o},{type:`elem`,elem:n,shift:0}]});else{var _=/cancel|phase/.test(r)?[`svg-align`]:[];g=qW({positionType:`individualShift`,children:[{type:`elem`,elem:n,shift:0},{type:`elem`,elem:a,shift:o,wrapperClasses:_}]})}return/cancel/.test(r)&&(g.height=n.height,g.depth=n.depth),/cancel/.test(r)&&!s?X([`mord`,`cancel-lap`],[g],t):X([`mord`],[g],t)},mathmlBuilder:(e,t)=>{var n,r=new Q(e.label.includes(`colorbox`)?`mpadded`:`menclose`,[FG(e.body,t)]);switch(e.label){case`\\cancel`:r.setAttribute(`notation`,`updiagonalstrike`);break;case`\\bcancel`:r.setAttribute(`notation`,`downdiagonalstrike`);break;case`\\phase`:r.setAttribute(`notation`,`phasorangle`);break;case`\\sout`:r.setAttribute(`notation`,`horizontalstrike`);break;case`\\fbox`:r.setAttribute(`notation`,`box`);break;case`\\angl`:r.setAttribute(`notation`,`actuarial`);break;case`\\fcolorbox`:case`\\colorbox`:if(n=t.fontMetrics().fboxsep*t.fontMetrics().ptPerEm,r.setAttribute(`width`,`+`+2*n+`pt`),r.setAttribute(`height`,`+`+2*n+`pt`),r.setAttribute(`lspace`,n+`pt`),r.setAttribute(`voffset`,n+`pt`),e.label===`\\fcolorbox`){var i=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness);r.setAttribute(`style`,`border: `+z(i)+` solid `+e.borderColor)}break;case`\\xcancel`:r.setAttribute(`notation`,`updiagonalstrike downdiagonalstrike`)}return e.backgroundColor&&r.setAttribute(`mathbackground`,e.backgroundColor),r}}),Z({type:`enclose`,names:[`\\fcolorbox`],numArgs:3,allowedInText:!0,argTypes:[`color`,`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=nK(t[0],`color-token`).color,o=nK(t[1],`color-token`).color,s=t[2];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:o,borderColor:a,body:s}}}),Z({type:`enclose`,names:[`\\fbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\fbox`,body:t[0]}}}),Z({type:`enclose`,names:[`\\cancel`,`\\bcancel`,`\\xcancel`,`\\phase`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\sout`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName;n.mode===`math`&&n.settings.reportNonstrict(`mathVsSout`,`LaTeX's \\sout works only in text mode`);var i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\angl`],numArgs:1,argTypes:[`hbox`],allowedInText:!1,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\angl`,body:t[0]}}});var iq={};function aq(e){for(var t=e.type,n=e.names,r=e.props,i=e.handler,a=e.htmlBuilder,o=e.mathmlBuilder,s={type:t,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:i},c=0;c{if(!e.parser.settings.displayMode)throw new L(`{`+e.envName+`} can be used only in display mode.`)},dq=new Set([`gather`,`gather*`]);function fq(e){if(!e.includes(`ed`))return!e.includes(`*`)}function pq(e,t,n){var r=t.hskipBeforeAndAfter,i=t.addJot,a=t.cols,o=t.arraystretch,s=t.colSeparationType,c=t.autoTag,l=t.singleRow,u=t.emptySingleRow,d=t.maxNumCols,f=t.leqno;if(e.gullet.beginGroup(),l||e.gullet.macros.set(`\\cr`,`\\\\\\relax`),!o){var p=e.gullet.expandMacroAsText(`\\arraystretch`);if(p==null)o=1;else if(o=parseFloat(p),!o||o<0)throw new L(`Invalid \\arraystretch: `+p)}e.gullet.beginGroup();var m=[],h=[m],g=[],_=[],v=c==null?void 0:[];function y(){c&&e.gullet.macros.set(`\\@eqnsw`,`1`,!0)}function b(){v&&(e.gullet.macros.get(`\\df@tag`)?(v.push(e.subparse([new cq(`\\df@tag`)])),e.gullet.macros.set(`\\df@tag`,void 0,!0)):v.push(!!c&&e.gullet.macros.get(`\\@eqnsw`)===`1`))}for(y(),_.push(lq(e));;){var x=e.parseExpression(!1,l?`\\end`:`\\\\`);e.gullet.endGroup(),e.gullet.beginGroup();var S={type:`ordgroup`,mode:e.mode,body:x};n&&(S={type:`styling`,mode:e.mode,style:n,resetFont:!0,body:[S]}),m.push(S);var C=e.fetch().text;if(C===`&`){if(d&&m.length===d){if(l||s)throw new L(`Too many tab characters: &`,e.nextToken);e.settings.reportNonstrict(`textEnv`,`Too few columns specified in the {array} column argument.`)}e.consume()}else if(C===`\\end`){b(),m.length===1&&S.type===`styling`&&S.body.length===1&&S.body[0].type===`ordgroup`&&S.body[0].body.length===0&&(h.length>1||!u)&&!Array.isArray(v?.[v.length-1])&&!(c&&v?.[v.length-1]===!0)&&h.pop(),_.length0&&(_+=.25),c.push({pos:_,isDashed:e[t]})}for(v(a[0]),n=0;n0&&(te+=g,xe))for(n=0;n=o)){var ve=void 0;(r>0||e.hskipBeforeAndAfter)&&(ve=fe?.pregap??d,ve!==0&&(ae=X([`arraycolsep`],[]),ae.style.width=z(ve),ie.push(ae)));var ye=[];for(n=0;n0){for(var Ee=HW(`katex-hline`,t,l),De=HW(`katex-hdashline`,t,l),Oe=[{type:`elem`,elem:Te,shift:0}];c.length>0;){var ke=c.pop(),Ae=ke.pos-ne;ke.isDashed?Oe.push({type:`elem`,elem:De,shift:Ae}):Oe.push({type:`elem`,elem:Ee,shift:Ae})}Te=qW({positionType:`individualShift`,children:Oe})}if(se.length===0)return X([`mord`],[Te],t);var je=X([`katex-tag`],[qW({positionType:`individualShift`,children:se})],t);return WW([Te,je])},gq={c:`center `,l:`left `,r:`right `},_q=function(e,t){for(var n=[],r=new Q(`mtd`,[],[`mtr-glue`]),i=new Q(`mtd`,[],[`mml-eqn-num`]),a=0;a0){var p=e.cols,m=``,h=!1,g=0,_=p.length;p[0].type===`separator`&&(d+=`top `,g=1),p[p.length-1].type===`separator`&&(d+=`bottom `,--_);for(var v=g;v<_;v++){var y=p[v];y.type===`align`?(f+=gq[y.align],h&&(m+=`none `),h=!0):y.type===`separator`&&(h&&=(m+=y.separator===`|`?`solid `:`dashed `,!1))}l.setAttribute(`columnalign`,f.trim()),/[sd]/.test(m)&&l.setAttribute(`columnlines`,m.trim())}if(e.colSeparationType===`align`){for(var b=e.cols||[],x=``,S=1;S0?`left `:``,d+=ee[ee.length-1].length>0?`right `:``;for(var te=1;te0&&u&&(p=1),n[d]={type:`align`,align:f,pregap:p,postgap:0}}return i.colSeparationType=u?`align`:`alignat`,i};aq({type:`array`,names:[`array`,`darray`],props:{numArgs:1},handler(e,t){var n=(iK(t[0])?[t[0]]:nK(t[0],`ordgroup`).body).map(function(e){var t=rK(e).text;if(`lcr`.includes(t))return{type:`align`,align:t};if(t===`|`)return{type:`separator`,separator:`|`};if(t===`:`)return{type:`separator`,separator:`:`};throw new L(`Unknown column alignment: `+t,e)}),r={cols:n,hskipBeforeAndAfter:!0,maxNumCols:n.length};return pq(e.parser,r,mq(e.envName))},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`matrix`,`pmatrix`,`bmatrix`,`Bmatrix`,`vmatrix`,`Vmatrix`,`matrix*`,`pmatrix*`,`bmatrix*`,`Bmatrix*`,`vmatrix*`,`Vmatrix*`],props:{numArgs:0},handler(e){var t={matrix:null,pmatrix:[`(`,`)`],bmatrix:[`[`,`]`],Bmatrix:[`\\{`,`\\}`],vmatrix:[`|`,`|`],Vmatrix:[`\\Vert`,`\\Vert`]}[e.envName.replace(`*`,``)],n=`c`,r={hskipBeforeAndAfter:!1,cols:[{type:`align`,align:n}]};if(e.envName.charAt(e.envName.length-1)===`*`){var i=e.parser;if(i.consumeSpaces(),i.fetch().text===`[`){if(i.consume(),i.consumeSpaces(),n=i.fetch().text,!`lcr`.includes(n))throw new L(`Expected l or c or r`,i.nextToken);i.consume(),i.consumeSpaces(),i.expect(`]`),i.consume(),r.cols=[{type:`align`,align:n}]}}var a=pq(e.parser,r,mq(e.envName)),o=Math.max(0,...a.body.map(e=>e.length));return a.cols=Array(o).fill({type:`align`,align:n}),t?{type:`leftright`,mode:e.mode,body:[a],left:t[0],right:t[1],rightColor:void 0}:a},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`smallmatrix`],props:{numArgs:0},handler(e){var t=pq(e.parser,{arraystretch:.5},`script`);return t.colSeparationType=`small`,t},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`subarray`],props:{numArgs:1},handler(e,t){var n=(iK(t[0])?[t[0]]:nK(t[0],`ordgroup`).body).map(function(e){var t=rK(e).text;if(`lc`.includes(t))return{type:`align`,align:t};throw new L(`Unknown column alignment: `+t,e)});if(n.length>1)throw new L(`{subarray} can contain only one column`);var r={cols:n,hskipBeforeAndAfter:!1,arraystretch:.5},i=pq(e.parser,r,`script`);if(i.body.length>0&&i.body[0].length>1)throw new L(`{subarray} can contain only one column`);return i},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`cases`,`dcases`,`rcases`,`drcases`],props:{numArgs:0},handler(e){var t=pq(e.parser,{arraystretch:1.2,cols:[{type:`align`,align:`l`,pregap:0,postgap:1},{type:`align`,align:`l`,pregap:0,postgap:0}]},mq(e.envName));return{type:`leftright`,mode:e.mode,body:[t],left:e.envName.includes(`r`)?`.`:`\\{`,right:e.envName.includes(`r`)?`\\}`:`.`,rightColor:void 0}},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`align`,`align*`,`aligned`,`split`],props:{numArgs:0},handler:vq,htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`gathered`,`gather`,`gather*`],props:{numArgs:0},handler(e){dq.has(e.envName)&&uq(e);var t={cols:[{type:`align`,align:`c`}],addJot:!0,colSeparationType:`gather`,autoTag:fq(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return pq(e.parser,t,`display`)},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`alignat`,`alignat*`,`alignedat`],props:{numArgs:1},handler:vq,htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`equation`,`equation*`],props:{numArgs:0},handler(e){uq(e);var t={autoTag:fq(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,leqno:e.parser.settings.leqno};return pq(e.parser,t,`display`)},htmlBuilder:hq,mathmlBuilder:_q}),aq({type:`array`,names:[`CD`],props:{numArgs:0},handler(e){return uq(e),yK(e.parser)},htmlBuilder:hq,mathmlBuilder:_q}),$(`\\nonumber`,`\\gdef\\@eqnsw{0}`),$(`\\notag`,`\\nonumber`),Z({type:`text`,names:[`\\hline`,`\\hdashline`],numArgs:0,allowedInText:!0,allowedInMath:!0,handler(e,t){throw new L(e.funcName+` valid only within array environment`)}});var yq=iq;Z({type:`environment`,names:[`\\begin`,`\\end`],numArgs:1,argTypes:[`text`],handler(e,t){var n=e.parser,r=e.funcName,i=t[0];if(i.type!==`ordgroup`)throw new L(`Invalid environment name`,i);var a=aK(i,`Environment name should contain only text characters and spaces`,!0);if(r===`\\begin`){if(!Object.prototype.hasOwnProperty.call(yq,a))throw new L(`No such environment: `+a,i);var o=yq[a],s=n.parseArguments(`\\begin{`+a+`}`,o),c=s.args,l=s.optArgs,u={mode:n.mode,envName:a,parser:n},d=o.handler(u,c,l);n.expect(`\\end`,!1);var f=n.nextToken,p=nK(n.parseFunction(),`environment`);if(p.name!==a)throw new L(`Mismatch: \\begin{`+a+`} matched by \\end{`+p.name+`}`,f);return d}return{type:`environment`,mode:n.mode,name:a,nameGroup:i}}});var bq=(e,t)=>{var n=e.font,r=t.withFont(n);return bG(e.body,r)},xq=(e,t)=>{var n=e.font,r=t.withFont(n);return FG(e.body,r)},Sq={"\\Bbb":`\\mathbb`,"\\bold":`\\mathbf`,"\\frak":`\\mathfrak`};Z({type:`font`,names:[`\\mathrm`,`\\mathit`,`\\mathbf`,`\\mathnormal`,`\\mathsfit`,`\\mathbb`,`\\mathcal`,`\\mathfrak`,`\\mathscr`,`\\mathsf`,`\\mathtt`,`\\Bbb`,`\\bold`,`\\frak`],numArgs:1,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=cG(t[0]),a=r in Sq?Sq[r]:r;return{type:`font`,mode:n.mode,font:a.slice(1),body:i}},htmlBuilder:bq,mathmlBuilder:xq}),Z({type:`mclass`,names:[`\\boldsymbol`,`\\bm`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`mclass`,mode:n.mode,mclass:pK(r),body:[{type:`font`,mode:n.mode,font:`boldsymbol`,body:r}],isCharacterBox:jH(r)}}}),Z({type:`font`,names:[`\\rm`,`\\sf`,`\\tt`,`\\bf`,`\\it`,`\\cal`],numArgs:0,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=e.breakOnTokenText,a=n.mode,o=n.parseExpression(!0,i);return{type:`font`,mode:a,font:`math`+r.slice(1),body:{type:`ordgroup`,mode:n.mode,body:o}}}});var Cq=(e,t)=>{var n=t.style,r=n.fracNum(),i=n.fracDen(),a=t.havingStyle(r),o=bG(e.numer,a,t);if(e.continued){var s=8.5/t.fontMetrics().ptPerEm,c=3.5/t.fontMetrics().ptPerEm;o.height=o.height0?3*f:7*f,h=t.fontMetrics().denom1):(d>0?(p=t.fontMetrics().num2,m=f):(p=t.fontMetrics().num3,m=3*f),h=t.fontMetrics().denom2);var g;if(u){var _=t.fontMetrics().axisHeight;p-o.depth-(_+.5*d){var n=new Q(`mfrac`,[FG(e.numer,t),FG(e.denom,t)]);if(!e.hasBarLine)n.setAttribute(`linethickness`,`0px`);else if(e.barSize){var r=SU(e.barSize,t);n.setAttribute(`linethickness`,z(r))}if(e.leftDelim!=null||e.rightDelim!=null){var i=[];if(e.leftDelim!=null){var a=new Q(`mo`,[new wG(e.leftDelim.replace(`\\`,``))]);a.setAttribute(`fence`,`true`),i.push(a)}if(i.push(n),e.rightDelim!=null){var o=new Q(`mo`,[new wG(e.rightDelim.replace(`\\`,``))]);o.setAttribute(`fence`,`true`),i.push(o)}return kG(i)}return n},Tq=(e,t)=>t?{type:`styling`,mode:e.mode,style:t,body:[e]}:e;Z({type:`genfrac`,names:[`\\cfrac`,`\\dfrac`,`\\frac`,`\\tfrac`,`\\dbinom`,`\\binom`,`\\tbinom`,`\\\\atopfrac`,`\\\\bracefrac`,`\\\\brackfrac`],numArgs:2,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0],a=t[1],o,s=null,c=null;switch(r){case`\\cfrac`:case`\\dfrac`:case`\\frac`:case`\\tfrac`:o=!0;break;case`\\\\atopfrac`:o=!1;break;case`\\dbinom`:case`\\binom`:case`\\tbinom`:o=!1,s=`(`,c=`)`;break;case`\\\\bracefrac`:o=!1,s=`\\{`,c=`\\}`;break;case`\\\\brackfrac`:o=!1,s=`[`,c=`]`;break;default:throw Error(`Unrecognized genfrac command`)}var l=r===`\\cfrac`,u=null;return l||r.startsWith(`\\d`)?u=`display`:r.startsWith(`\\t`)&&(u=`text`),Tq({type:`genfrac`,mode:n.mode,numer:i,denom:a,continued:l,hasBarLine:o,leftDelim:s,rightDelim:c,barSize:null},u)},htmlBuilder:Cq,mathmlBuilder:wq}),Z({type:`infix`,names:[`\\over`,`\\choose`,`\\atop`,`\\brace`,`\\brack`],numArgs:0,infix:!0,handler(e){var t=e.parser,n=e.funcName,r=e.token,i;switch(n){case`\\over`:i=`\\frac`;break;case`\\choose`:i=`\\binom`;break;case`\\atop`:i=`\\\\atopfrac`;break;case`\\brace`:i=`\\\\bracefrac`;break;case`\\brack`:i=`\\\\brackfrac`;break;default:throw Error(`Unrecognized infix genfrac command`)}return{type:`infix`,mode:t.mode,replaceWith:i,token:r}}});var Eq=[`display`,`text`,`script`,`scriptscript`],Dq=function(e){var t=null;return e.length>0&&(t=e,t=t===`.`?null:t),t};Z({type:`genfrac`,names:[`\\genfrac`],numArgs:6,allowedInArgument:!0,argTypes:[`math`,`math`,`size`,`text`,`math`,`math`],handler(e,t){var n=e.parser,r=t[4],i=t[5],a=cG(t[0]),o=a.type===`atom`&&a.family===`open`?Dq(a.text):null,s=cG(t[1]),c=s.type===`atom`&&s.family===`close`?Dq(s.text):null,l=nK(t[2],`size`),u,d=null;l.isBlank?u=!0:(d=l.value,u=d.number>0);var f=null,p=t[3];if(p.type===`ordgroup`){if(p.body.length>0){var m=nK(p.body[0],`textord`);f=Eq[Number(m.text)]}}else p=nK(p,`textord`),f=Eq[Number(p.text)];return Tq({type:`genfrac`,mode:n.mode,numer:r,denom:i,continued:!1,hasBarLine:u,barSize:d,leftDelim:o,rightDelim:c},f)}}),Z({type:`infix`,names:[`\\above`],numArgs:1,argTypes:[`size`],infix:!0,handler(e,t){var n=e.parser;e.funcName;var r=e.token;return{type:`infix`,mode:n.mode,replaceWith:`\\\\abovefrac`,size:nK(t[0],`size`).value,token:r}}}),Z({type:`genfrac`,names:[`\\\\abovefrac`],numArgs:3,argTypes:[`math`,`size`,`math`],handler:(e,t)=>{var n=e.parser;e.funcName;var r=t[0],i=nK(t[1],`infix`).size;if(!i)throw Error(`\\\\abovefrac expected size, but got `+String(i));var a=t[2],o=i.number>0;return{type:`genfrac`,mode:n.mode,numer:r,denom:a,continued:!1,hasBarLine:o,barSize:i,leftDelim:null,rightDelim:null}}});var Oq=(e,t)=>{var n=t.style,r,i;e.type===`supsub`?(r=e.sup?bG(e.sup,t.havingStyle(n.sup()),t):bG(e.sub,t.havingStyle(n.sub()),t),i=nK(e.base,`horizBrace`)):i=nK(e,`horizBrace`);var a=bG(i.base,t.havingBaseStyle(R.DISPLAY)),o=YG(i,t),s=i.isOver?qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:.1},{type:`elem`,elem:o,wrapperClasses:[`svg-align`]}]}):qW({positionType:`bottom`,positionData:a.depth+.1+o.height,children:[{type:`elem`,elem:o,wrapperClasses:[`svg-align`]},{type:`kern`,size:.1},{type:`elem`,elem:a}]});if(r){var c=X([`minner`,i.isOver?`mover`:`munder`],[s],t);s=i.isOver?qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:c},{type:`kern`,size:.2},{type:`elem`,elem:r}]}):qW({positionType:`bottom`,positionData:c.depth+.2+r.height+r.depth,children:[{type:`elem`,elem:r},{type:`kern`,size:.2},{type:`elem`,elem:c}]})}return X([`minner`,i.isOver?`mover`:`munder`],[s],t)};Z({type:`horizBrace`,names:[`\\overbrace`,`\\underbrace`,`\\overbracket`,`\\underbracket`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`horizBrace`,mode:n.mode,label:r,isOver:r.includes(`\\over`),base:t[0]}},htmlBuilder:Oq,mathmlBuilder:(e,t)=>{var n=KG(e.label);return new Q(e.isOver?`mover`:`munder`,[FG(e.base,t),n])}}),Z({type:`href`,names:[`\\href`],numArgs:2,argTypes:[`url`,`original`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[1],i=nK(t[0],`url`).url;return n.settings.isTrusted({command:`\\href`,url:i})?{type:`href`,mode:n.mode,href:i,body:lG(r)}:n.formatUnsupportedCmd(`\\href`)},htmlBuilder:(e,t)=>{var n=mG(e.body,t,!1);return UW(e.href,[],n,t)},mathmlBuilder:(e,t)=>{var n=PG(e.body,t);return n instanceof Q||(n=new Q(`mrow`,[n])),n.setAttribute(`href`,e.href),n}}),Z({type:`href`,names:[`\\url`],numArgs:1,argTypes:[`url`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=nK(t[0],`url`).url;if(!n.settings.isTrusted({command:`\\url`,url:r}))return n.formatUnsupportedCmd(`\\url`);for(var i=[],a=0;a{var n=e.parser,r=e.funcName;e.token;var i=nK(t[0],`raw`).string,a=t[1];n.settings.strict&&n.settings.reportNonstrict(`htmlExtension`,`HTML extension is disabled on strict mode`);var o,s={};switch(r){case`\\htmlClass`:s.class=i,o={command:`\\htmlClass`,class:i};break;case`\\htmlId`:s.id=i,o={command:`\\htmlId`,id:i};break;case`\\htmlStyle`:s.style=i,o={command:`\\htmlStyle`,style:i};break;case`\\htmlData`:for(var c=`{,}`,l=[],u=``,d=0;d{var n=mG(e.body,t,!1),r=[`enclosing`];e.attributes.class&&r.push(...e.attributes.class.trim().split(/\s+/));var i=X(r,n,t);for(var a of Object.entries(e.attributes)){var o=a[0],s=a[1];o!==`class`&&i.setAttribute(o,s)}return i},mathmlBuilder:(e,t)=>PG(e.body,t)}),Z({type:`htmlmathml`,names:[`\\html@mathml`],numArgs:2,allowedInArgument:!0,allowedInText:!0,handler:(e,t)=>({type:`htmlmathml`,mode:e.parser.mode,html:lG(t[0]),mathml:lG(t[1])}),htmlBuilder:(e,t)=>WW(mG(e.html,t,!1)),mathmlBuilder:(e,t)=>PG(e.mathml,t)});var kq=function(e){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(e))return{number:+e,unit:`bp`};var t=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(e);if(!t)throw new L(`Invalid size: '`+e+`' in \\includegraphics`);var n={number:+(t[1]+t[2]),unit:t[3]};if(!xU(n))throw new L(`Invalid unit: '`+n.unit+`' in \\includegraphics.`);return n};Z({type:`includegraphics`,names:[`\\includegraphics`],numArgs:1,numOptionalArgs:1,argTypes:[`raw`,`url`],allowedInText:!1,handler:(e,t,n)=>{var r=e.parser,i={number:0,unit:`em`},a={number:.9,unit:`em`},o={number:0,unit:`em`},s=``;if(n[0])for(var c=nK(n[0],`raw`).string.split(`,`),l=0;l{var n=SU(e.height,t),r=0;e.totalheight.number>0&&(r=SU(e.totalheight,t)-n);var i=0;e.width.number>0&&(i=SU(e.width,t));var a={height:z(n+r)};i>0&&(a.width=z(i)),r>0&&(a.verticalAlign=z(-r));var o=new jU(e.src,e.alt,a);return o.height=n,o.depth=r,o},mathmlBuilder:(e,t)=>{var n=new Q(`mglyph`,[]);n.setAttribute(`alt`,e.alt);var r=SU(e.height,t),i=0;if(e.totalheight.number>0&&(i=SU(e.totalheight,t)-r,n.setAttribute(`valign`,z(-i))),n.setAttribute(`height`,z(r+i)),e.width.number>0){var a=SU(e.width,t);n.setAttribute(`width`,z(a))}return n.setAttribute(`src`,e.src),n}}),Z({type:`kern`,names:[`\\kern`,`\\mkern`,`\\hskip`,`\\mskip`],numArgs:1,argTypes:[`size`],primitive:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=nK(t[0],`size`);if(n.settings.strict){var a=r[1]===`m`,o=i.value.unit===`mu`;a?(o||n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` supports only mu units, `+(`not `+i.value.unit+` units`)),n.mode!==`math`&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` works only in math mode`)):o&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` doesn't support mu units`)}return{type:`kern`,mode:n.mode,dimension:i.value}},htmlBuilder(e,t){return JW(e.dimension,t)},mathmlBuilder(e,t){return new TG(SU(e.dimension,t))}}),Z({type:`lap`,names:[`\\mathllap`,`\\mathrlap`,`\\mathclap`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`lap`,mode:n.mode,alignment:r.slice(5),body:i}},htmlBuilder:(e,t)=>{var n;e.alignment===`clap`?(n=X([],[bG(e.body,t)]),n=X([`katex-inner`],[n],t)):n=X([`katex-inner`],[bG(e.body,t)]);var r=X([`katex-fix`],[]),i=X([e.alignment],[n,r],t),a=X([`katex-strut`]);return a.style.height=z(i.height+i.depth),i.depth&&(a.style.verticalAlign=z(-i.depth)),i.children.unshift(a),i=X([`katex-thinbox`],[i],t),X([`mord`,`katex-vbox`],[i],t)},mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[FG(e.body,t)]);if(e.alignment!==`rlap`){var r=e.alignment===`llap`?`-1`:`-0.5`;n.setAttribute(`lspace`,r+`width`)}return n.setAttribute(`width`,`0px`),n}}),Z({type:`styling`,names:[`\\(`,`$`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){var n=e.funcName,r=e.parser,i=r.mode;r.switchMode(`math`);var a=n===`\\(`?`\\)`:`$`,o=r.parseExpression(!1,a);return r.expect(a),r.switchMode(i),{type:`styling`,mode:r.mode,style:`text`,resetFont:!0,body:o}}}),Z({type:`text`,names:[`\\)`,`\\]`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){throw new L(`Mismatched `+e.funcName)}});var Aq=(e,t)=>{switch(t.style.size){case R.DISPLAY.size:return e.display;case R.TEXT.size:return e.text;case R.SCRIPT.size:return e.script;case R.SCRIPTSCRIPT.size:return e.scriptscript;default:return e.text}};Z({type:`mathchoice`,names:[`\\mathchoice`],numArgs:4,primitive:!0,handler:(e,t)=>({type:`mathchoice`,mode:e.parser.mode,display:lG(t[0]),text:lG(t[1]),script:lG(t[2]),scriptscript:lG(t[3])}),htmlBuilder:(e,t)=>WW(mG(Aq(e,t),t,!1)),mathmlBuilder:(e,t)=>PG(Aq(e,t),t)});var jq=(e,t,n,r,i,a,o)=>{e=X([],[e]);var s=n&&jH(n),c,l;if(t){var u=bG(t,r.havingStyle(i.sup()),r);l={elem:u,kern:Math.max(r.fontMetrics().bigOpSpacing1,r.fontMetrics().bigOpSpacing3-u.depth)}}if(n){var d=bG(n,r.havingStyle(i.sub()),r);c={elem:d,kern:Math.max(r.fontMetrics().bigOpSpacing2,r.fontMetrics().bigOpSpacing4-d.height)}}var f;if(l&&c)f=qW({positionType:`bottom`,positionData:r.fontMetrics().bigOpSpacing5+c.elem.height+c.elem.depth+c.kern+e.depth+o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else if(c)f=qW({positionType:`top`,positionData:e.height-o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e}]});else if(l)f=qW({positionType:`bottom`,positionData:e.depth+o,children:[{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else return e;var p=[f];if(c&&a!==0&&!s){var m=X([`mspace`],[],r);m.style.marginRight=z(a),p.unshift(m)}return X([`mop`,`op-limits`],p,r)},Mq=new Set([`\\smallint`]),Nq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=nK(e.base,`op`),i=!0):a=nK(e,`op`);var o=t.style,s=!1;o.size===R.DISPLAY.size&&a.symbol&&!Mq.has(a.name)&&(s=!0);var c,l;if(a.symbol){var u=s?`Size2-Regular`:`Size1-Regular`,d=``;if((a.name===`\\oiint`||a.name===`\\oiiint`)&&(d=a.name.slice(1),a.name=d===`oiint`?`\\iint`:`\\iiint`),c=PW(a.name,u,`math`,t,[`mop`,`op-symbol`,s?`large-op`:`small-op`]),l=c.italic,d.length>0){var f=QW(d+`Size`+(s?`2`:`1`),t);c=qW({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:0},{type:`elem`,elem:f,shift:s?.08:0}]}),a.name=`\\`+d,c.classes.unshift(`mop`),c.italic=l}}else if(a.body){var p=mG(a.body,t,!0);p.length===1&&p[0]instanceof NU?(c=p[0],c.classes[0]=`mop`):c=X([`mop`],p,t)}else{for(var m=[],h=1;h{var n;if(e.symbol)n=new Q(`mo`,[OG(e.name,e.mode)]),Mq.has(e.name)&&n.setAttribute(`largeop`,`false`);else if(e.body)n=new Q(`mo`,NG(e.body,t));else{n=new Q(`mi`,[new wG(e.name.slice(1))]);var r=new Q(`mo`,[OG(`⁡`,`text`)]);n=e.parentIsSupSub?new Q(`mrow`,[n,r]):CG([n,r])}return n},Fq={"∏":`\\prod`,"∐":`\\coprod`,"∑":`\\sum`,"⋀":`\\bigwedge`,"⋁":`\\bigvee`,"⋂":`\\bigcap`,"⋃":`\\bigcup`,"⨀":`\\bigodot`,"⨁":`\\bigoplus`,"⨂":`\\bigotimes`,"⨄":`\\biguplus`,"⨆":`\\bigsqcup`};Z({type:`op`,names:`\\coprod.\\bigvee.\\bigwedge.\\biguplus.\\bigcap.\\bigcup.\\intop.\\prod.\\sum.\\bigotimes.\\bigoplus.\\bigodot.\\bigsqcup.\\smallint.∏.∐.∑.⋀.⋁.⋂.⋃.⨀.⨁.⨂.⨄.⨆`.split(`.`),numArgs:0,handler:(e,t)=>{var n=e.parser,r=e.funcName;return r.length===1&&(r=Fq[r]),{type:`op`,mode:n.mode,limits:!0,parentIsSupSub:!1,symbol:!0,name:r}},htmlBuilder:Nq,mathmlBuilder:Pq}),Z({type:`op`,names:[`\\mathop`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`op`,mode:n.mode,limits:!1,parentIsSupSub:!1,symbol:!1,body:lG(r)}}});var Iq={"∫":`\\int`,"∬":`\\iint`,"∭":`\\iiint`,"∮":`\\oint`,"∯":`\\oiint`,"∰":`\\oiiint`};Z({type:`op`,names:`\\arcsin.\\arccos.\\arctan.\\arctg.\\arcctg.\\arg.\\ch.\\cos.\\cosec.\\cosh.\\cot.\\cotg.\\coth.\\csc.\\ctg.\\cth.\\deg.\\dim.\\exp.\\hom.\\ker.\\lg.\\ln.\\log.\\sec.\\sin.\\sinh.\\sh.\\tan.\\tanh.\\tg.\\th`.split(`.`),numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\det`,`\\gcd`,`\\inf`,`\\lim`,`\\max`,`\\min`,`\\Pr`,`\\sup`],numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!0,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\int`,`\\iint`,`\\iiint`,`\\oint`,`\\oiint`,`\\oiiint`,`∫`,`∬`,`∭`,`∮`,`∯`,`∰`],numArgs:0,allowedInArgument:!0,handler(e){var t=e.parser,n=e.funcName;return n.length===1&&(n=Iq[n]),{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!0,name:n}}});var Lq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=nK(e.base,`operatorname`),i=!0):a=nK(e,`operatorname`);var o;if(a.body.length>0){for(var s=mG(a.body.map(e=>{var t=`text`in e?e.text:void 0;return typeof t==`string`?{type:`textord`,mode:e.mode,text:t}:e}),t.withFont(`mathrm`),!0),c=0;c{var n=e.parser,r=e.funcName,i=t[0];return{type:`operatorname`,mode:n.mode,body:lG(i),alwaysHandleSupSub:r===`\\operatornamewithlimits`,limits:!1,parentIsSupSub:!1}},htmlBuilder:Lq,mathmlBuilder:(e,t)=>{for(var n=NG(e.body,t.withFont(`mathrm`)),r=!0,i=0;ie.toText()).join(``))]);var s=new Q(`mi`,n);s.setAttribute(`mathvariant`,`normal`);var c=new Q(`mo`,[OG(`⁡`,`text`)]);return e.parentIsSupSub?new Q(`mrow`,[s,c]):CG([s,c])}}),$(`\\operatorname`,`\\@ifstar\\operatornamewithlimits\\operatorname@`),sG({type:`ordgroup`,htmlBuilder(e,t){return e.semisimple?WW(mG(e.body,t,!1)):X([`mord`],mG(e.body,t,!0),t)},mathmlBuilder(e,t){return PG(e.body,t,!0)}}),Z({type:`overline`,names:[`\\overline`],numArgs:1,handler(e,t){var n=e.parser,r=t[0];return{type:`overline`,mode:n.mode,body:r}},htmlBuilder(e,t){var n=bG(e.body,t.havingCrampedStyle()),r=HW(`overline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-overline`],[qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:n},{type:`kern`,size:3*i},{type:`elem`,elem:r},{type:`kern`,size:i}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new wG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`mover`,[FG(e.body,t),n]);return r.setAttribute(`accent`,`true`),r}}),Z({type:`phantom`,names:[`\\phantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`phantom`,mode:n.mode,body:lG(r)}},htmlBuilder:(e,t)=>WW(mG(e.body,t.withPhantom(),!1)),mathmlBuilder:(e,t)=>new Q(`mphantom`,NG(e.body,t))}),$(`\\hphantom`,`\\smash{\\phantom{#1}}`),Z({type:`vphantom`,names:[`\\vphantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`vphantom`,mode:n.mode,body:r}},htmlBuilder:(e,t)=>X([`mord`,`rlap`],[X([`katex-inner`],[bG(e.body,t.withPhantom())]),X([`katex-fix`],[])],t),mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[new Q(`mphantom`,NG(lG(e.body),t))]);return n.setAttribute(`width`,`0px`),n}}),Z({type:`raisebox`,names:[`\\raisebox`],numArgs:2,argTypes:[`size`,`hbox`],allowedInText:!0,handler(e,t){var n=e.parser,r=nK(t[0],`size`).value,i=t[1];return{type:`raisebox`,mode:n.mode,dy:r,body:i}},htmlBuilder(e,t){var n=bG(e.body,t);return qW({positionType:`shift`,positionData:-SU(e.dy,t),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){var n=new Q(`mpadded`,[FG(e.body,t)]),r=e.dy.number+e.dy.unit;return n.setAttribute(`voffset`,r),n}});var Rq=(e,t)=>({type:`reflectbox`,mode:e.parser.mode,body:t[0]});Z({type:`reflectbox`,names:[`\\reflectbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler:Rq,htmlBuilder(e,t){return X([`mord`,`reflectbox`],[bG(e.body,t)],t)},mathmlBuilder(e,t){return FG(e.body,t)}}),Z({type:`reflectbox`,names:[`\\mathreflectbox`],numArgs:1,argTypes:[`math`],handler:Rq}),Z({type:`internal`,names:[`\\relax`],numArgs:0,allowedInText:!0,allowedInArgument:!0,handler(e){return{type:`internal`,mode:e.parser.mode}}}),Z({type:`rule`,names:[`\\rule`],numArgs:2,numOptionalArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`size`,`size`,`size`],handler(e,t,n){var r=e.parser,i=n[0],a=nK(t[0],`size`),o=nK(t[1],`size`);return{type:`rule`,mode:r.mode,shift:i&&nK(i,`size`).value,width:a.value,height:o.value}},htmlBuilder(e,t){var n=X([`mord`,`katex-rule`],[],t),r=SU(e.width,t),i=SU(e.height,t),a=e.shift?SU(e.shift,t):0;return n.style.borderRightWidth=z(r),n.style.borderTopWidth=z(i),n.style.bottom=z(a),n.width=r,n.height=i+a,n.depth=-a,n.maxFontSize=i*1.125*t.sizeMultiplier,n},mathmlBuilder(e,t){var n=SU(e.width,t),r=SU(e.height,t),i=e.shift?SU(e.shift,t):0,a=t.color&&t.getColor()||`black`,o=new Q(`mspace`);o.setAttribute(`mathbackground`,a),o.setAttribute(`width`,z(n)),o.setAttribute(`height`,z(r));var s=new Q(`mpadded`,[o]);return i>=0?s.setAttribute(`height`,z(i)):(s.setAttribute(`height`,z(i)),s.setAttribute(`depth`,z(-i))),s.setAttribute(`voffset`,z(i)),s}});function zq(e,t,n){for(var r=mG(e,t,!1),i=t.sizeMultiplier/n.sizeMultiplier,a=0;a{var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!1,n);return{type:`sizing`,mode:i.mode,size:Bq.indexOf(r)+1,body:a}},htmlBuilder:(e,t)=>{var n=t.havingSize(e.size);return zq(e.body,n,t)},mathmlBuilder:(e,t)=>{var n=t.havingSize(e.size),r=new Q(`mstyle`,NG(e.body,n));return r.setAttribute(`mathsize`,z(n.sizeMultiplier)),r}}),Z({type:`smash`,names:[`\\smash`],numArgs:1,numOptionalArgs:1,allowedInText:!0,handler:(e,t,n)=>{var r=e.parser,i=!1,a=!1,o=n[0]&&nK(n[0],`ordgroup`);if(o)for(var s,c=0;c{var n=X([],[bG(e.body,t)]);if(!e.smashHeight&&!e.smashDepth)return n;if(e.smashHeight&&(n.height=0),e.smashDepth&&(n.depth=0),e.smashHeight&&e.smashDepth)return X([`mord`,`katex-smash`],[n],t);if(n.children)for(var r=0;r{var n=new Q(`mpadded`,[FG(e.body,t)]);return e.smashHeight&&n.setAttribute(`height`,`0px`),e.smashDepth&&n.setAttribute(`depth`,`0px`),n}}),Z({type:`sqrt`,names:[`\\sqrt`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=n[0],a=t[0];return{type:`sqrt`,mode:r.mode,body:a,index:i}},htmlBuilder(e,t){var n=bG(e.body,t.havingCrampedStyle());n.height===0&&(n.height=t.fontMetrics().xHeight),n=GW(n,t);var r=t.fontMetrics().defaultRuleThickness,i=r;t.style.idn.height+n.depth+a&&(a=(a+u-n.height-n.depth)/2);var d=s.height-n.height-a-c;n.style.paddingLeft=z(l);var f=qW({positionType:`firstBaseline`,children:[{type:`elem`,elem:n,wrapperClasses:[`svg-align`]},{type:`kern`,size:-(n.height+d)},{type:`elem`,elem:s},{type:`kern`,size:c}]});if(e.index){var p=t.havingStyle(R.SCRIPTSCRIPT),m=bG(e.index,p,t);return X([`mord`,`sqrt`],[X([`katex-root`],[qW({positionType:`shift`,positionData:-(.6*(f.height-f.depth)),children:[{type:`elem`,elem:m}]})]),f],t)}return X([`mord`,`sqrt`],[f],t)},mathmlBuilder(e,t){var n=e.body,r=e.index;return r?new Q(`mroot`,[FG(n,t),FG(r,t)]):new Q(`msqrt`,[FG(n,t)])}});var Vq={display:R.DISPLAY,text:R.TEXT,script:R.SCRIPT,scriptscript:R.SCRIPTSCRIPT};function Hq(e){return e in Vq}Z({type:`styling`,names:[`\\displaystyle`,`\\textstyle`,`\\scriptstyle`,`\\scriptscriptstyle`],numArgs:0,allowedInText:!0,primitive:!0,handler(e,t){var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!0,n),o=r.slice(1,r.length-5);if(!Hq(o))throw Error(`Unknown style: `+o);return{type:`styling`,mode:i.mode,style:o,body:a}},htmlBuilder(e,t){var n=Vq[e.style],r=t.havingStyle(n);return e.resetFont&&(r=r.withFont(``)),zq(e.body,r,t)},mathmlBuilder(e,t){var n=Vq[e.style],r=t.havingStyle(n);e.resetFont&&(r=r.withFont(``));var i=new Q(`mstyle`,NG(e.body,r)),a={display:[`0`,`true`],text:[`0`,`false`],script:[`1`,`false`],scriptscript:[`2`,`false`]}[e.style];return i.setAttribute(`scriptlevel`,a[0]),i.setAttribute(`displaystyle`,a[1]),i}});var Uq=function(e,t){var n=e.base;return n?n.type===`op`?n.limits&&(t.style.size===R.DISPLAY.size||n.alwaysHandleSupSub)?Nq:null:n.type===`operatorname`?n.alwaysHandleSupSub&&(t.style.size===R.DISPLAY.size||n.limits)?Lq:null:n.type===`accent`?jH(n.base)?sK:null:n.type===`horizBrace`&&!e.sub===n.isOver?Oq:null:null};sG({type:`supsub`,htmlBuilder(e,t){var n=Uq(e,t);if(n)return n(e,t);var r=e.base,i=e.sup,a=e.sub,o=bG(r,t),s,c,l=t.fontMetrics(),u=0,d=0,f=r&&jH(r);if(i){var p=t.havingStyle(t.style.sup());s=bG(i,p,t),f||(u=o.height-p.fontMetrics().supDrop*p.sizeMultiplier/t.sizeMultiplier)}if(a){var m=t.havingStyle(t.style.sub());c=bG(a,m,t),f||(d=o.depth+m.fontMetrics().subDrop*m.sizeMultiplier/t.sizeMultiplier)}var h=t.style===R.DISPLAY?l.sup1:t.style.cramped?l.sup3:l.sup2,g=t.sizeMultiplier,_=z(.5/l.ptPerEm/g),v=null;if(c){var y=e.base&&e.base.type===`op`&&e.base.name&&(e.base.name===`\\oiint`||e.base.name===`\\oiiint`);(o instanceof NU||y)&&(v=z(-(o.italic??0)))}var b;if(s&&c){u=Math.max(u,h,s.depth+.25*l.xHeight),d=Math.max(d,l.sub2);var x=4*l.defaultRuleThickness;if(u-s.depth-(c.height-d)0&&(u+=S,d-=S)}b=qW({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:d,marginRight:_,marginLeft:v},{type:`elem`,elem:s,shift:-u,marginRight:_}]})}else if(c)d=Math.max(d,l.sub1,c.height-.8*l.xHeight),b=qW({positionType:`shift`,positionData:d,children:[{type:`elem`,elem:c,marginLeft:v,marginRight:_}]});else if(s)u=Math.max(u,h,s.depth+.25*l.xHeight),b=qW({positionType:`shift`,positionData:-u,children:[{type:`elem`,elem:s,marginRight:_}]});else throw Error(`supsub must have either sup or sub.`);return X([vG(o,`right`)||`mord`],[o,X([`msupsub`],[b])],t)},mathmlBuilder(e,t){var n=!1,r,i;e.base&&e.base.type===`horizBrace`&&(i=!!e.sup,i===e.base.isOver&&(n=!0,r=e.base.isOver)),e.base&&(e.base.type===`op`||e.base.type===`operatorname`)&&(e.base.parentIsSupSub=!0);var a=[FG(e.base,t)];e.sub&&a.push(FG(e.sub,t)),e.sup&&a.push(FG(e.sup,t));var o;if(n)o=r?`mover`:`munder`;else if(!e.sub){var s=e.base;o=s&&s.type===`op`&&s.limits&&(t.style===R.DISPLAY||s.alwaysHandleSupSub)||s&&s.type===`operatorname`&&s.alwaysHandleSupSub&&(s.limits||t.style===R.DISPLAY)?`mover`:`msup`}else if(e.sup){var c=e.base;o=c&&c.type===`op`&&c.limits&&t.style===R.DISPLAY||c&&c.type===`operatorname`&&c.alwaysHandleSupSub&&(t.style===R.DISPLAY||c.limits)?`munderover`:`msubsup`}else{var l=e.base;o=l&&l.type===`op`&&l.limits&&(t.style===R.DISPLAY||l.alwaysHandleSupSub)||l&&l.type===`operatorname`&&l.alwaysHandleSupSub&&(l.limits||t.style===R.DISPLAY)?`munder`:`msub`}return new Q(o,a)}}),sG({type:`atom`,htmlBuilder(e,t){return FW(e.text,e.mode,t,[`m`+e.family])},mathmlBuilder(e,t){var n=new Q(`mo`,[OG(e.text,e.mode)]);if(e.family===`bin`){var r=jG(e,t);r===`bold-italic`&&n.setAttribute(`mathvariant`,r)}else e.family===`punct`?n.setAttribute(`separator`,`true`):(e.family===`open`||e.family===`close`)&&n.setAttribute(`stretchy`,`false`);return n}});var Wq={mi:`italic`,mn:`normal`,mtext:`normal`};sG({type:`mathord`,htmlBuilder(e,t){return LW(e,t)},mathmlBuilder(e,t){var n=new Q(`mi`,[OG(e.text,e.mode,t)]),r=jG(e,t)||`italic`;return r!==Wq[n.type]&&n.setAttribute(`mathvariant`,r),n}}),sG({type:`textord`,htmlBuilder(e,t){return LW(e,t)},mathmlBuilder(e,t){var n=OG(e.text,e.mode,t),r=jG(e,t)||`normal`,i=e.mode===`text`?new Q(`mtext`,[n]):/[0-9]/.test(e.text)?new Q(`mn`,[n]):e.text===`\\prime`?new Q(`mo`,[n]):new Q(`mi`,[n]);return r!==Wq[i.type]&&i.setAttribute(`mathvariant`,r),i}});var Gq=new Map([[`\\nobreak`,`nobreak`],[`\\allowbreak`,`allowbreak`]]),Kq=new Map([[` `,{}],[`\\ `,{}],[`~`,{className:`nobreak`}],[`\\space`,{}],[`\\nobreakspace`,{className:`nobreak`}]]);sG({type:`spacing`,htmlBuilder(e,t){var n=Kq.get(e.text),r=Gq.get(e.text);if(n){var i=n.className||``;if(e.mode===`text`){var a=LW(e,t);return a.classes.push(i),a}return X([`mspace`,i],[FW(e.text,e.mode,t)],t)}if(r)return X([`mspace`,r],[],t);throw new L(`Unknown type of space "`+e.text+`"`)},mathmlBuilder(e,t){var n;if(Kq.has(e.text))n=new Q(`mtext`,[new wG(`\xA0`)]);else if(Gq.has(e.text))return new Q(`mspace`);else throw new L(`Unknown type of space "`+e.text+`"`);return n}});var qq=()=>{var e=new Q(`mtd`,[]);return e.setAttribute(`width`,`50%`),e};sG({type:`tag`,mathmlBuilder(e,t){var n=new Q(`mtable`,[new Q(`mtr`,[qq(),new Q(`mtd`,[PG(e.body,t)]),qq(),new Q(`mtd`,[PG(e.tag,t)])])]);return n.setAttribute(`width`,`100%`),n}});var Jq={"\\text":void 0,"\\textrm":`textrm`,"\\textsf":`textsf`,"\\texttt":`texttt`,"\\textnormal":`textrm`},Yq={"\\textbf":`textbf`,"\\textmd":`textmd`},Xq={"\\textit":`textit`,"\\textup":`textup`},Zq=(e,t)=>{var n=e.font;return n?Jq[n]?t.withTextFontFamily(Jq[n]):Yq[n]?t.withTextFontWeight(Yq[n]):n===`\\emph`?t.fontShape===`textit`?t.withTextFontShape(`textup`):t.withTextFontShape(`textit`):t.withTextFontShape(Xq[n]):t};Z({type:`text`,names:[`\\text`,`\\textrm`,`\\textsf`,`\\texttt`,`\\textnormal`,`\\textbf`,`\\textmd`,`\\textit`,`\\textup`,`\\emph`],numArgs:1,argTypes:[`text`],allowedInArgument:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`text`,mode:n.mode,body:lG(i),font:r}},htmlBuilder(e,t){var n=Zq(e,t);return X([`mord`,`text`],mG(e.body,n,!0),n)},mathmlBuilder(e,t){var n=Zq(e,t);return PG(e.body,n)}}),Z({type:`underline`,names:[`\\underline`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`underline`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=bG(e.body,t),r=HW(`underline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-underline`],[qW({positionType:`top`,positionData:n.height,children:[{type:`kern`,size:i},{type:`elem`,elem:r},{type:`kern`,size:3*i},{type:`elem`,elem:n}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new wG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`munder`,[FG(e.body,t),n]);return r.setAttribute(`accentunder`,`true`),r}}),Z({type:`vcenter`,names:[`\\vcenter`],numArgs:1,argTypes:[`original`],allowedInText:!1,handler(e,t){return{type:`vcenter`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=bG(e.body,t),r=t.fontMetrics().axisHeight;return qW({positionType:`shift`,positionData:.5*(n.height-r-(n.depth+r)),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){return new Q(`mrow`,[new Q(`mpadded`,[FG(e.body,t)],[`vcenter`])])}}),Z({type:`verb`,names:[`\\verb`],numArgs:0,allowedInText:!0,handler(e,t,n){throw new L(`\\verb ended by end of line instead of matching delimiter`)},htmlBuilder(e,t){for(var n=Qq(e),r=[],i=t.havingStyle(t.style.text()),a=0;ae.body.replace(/ /g,e.star?`␣`:`\xA0`),$q=iG,eJ=`[ \r + ]`,tJ=`\\\\[a-zA-Z@]+`,nJ=`\\\\[^\ud800-\udfff]`,rJ=`(`+tJ+`)`+eJ+`*`,iJ=`\\\\( |[ \r ]+ -?)[ \r ]*`,tJ=`[̀-ͯ]`,nJ=RegExp(tJ+`+$`),rJ=`(`+Xq+`+)|`+(eJ+`|`)+`([!-\\[\\]-‧‪-퟿豈-￿]`+(tJ+`*`)+`|[\ud800-\udbff][\udc00-\udfff]`+(tJ+`*`)+`|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5`+(`|`+$q)+(`|`+Qq+`)`),iJ=class{constructor(e,t){this.input=void 0,this.settings=void 0,this.tokenRegex=void 0,this.catcodes=void 0,this.input=e,this.settings=t,this.tokenRegex=new RegExp(rJ,`g`),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){var e=this.input,t=this.tokenRegex.lastIndex;if(t===e.length)return new iq(`EOF`,new rq(this,t,t));var n=this.tokenRegex.exec(e);if(n===null||n.index!==t)throw new L(`Unexpected character: '`+e[t]+`'`,new iq(e[t],new rq(this,t,t+1)));var r=n[6]||n[3]||(n[2]?`\\ `:` `);if(this.catcodes[r]===14){var i=e.indexOf(` -`,this.tokenRegex.lastIndex);return i===-1?(this.tokenRegex.lastIndex=e.length,this.settings.reportNonstrict(`commentAtEnd`,`% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode (e.g. $)`)):this.tokenRegex.lastIndex=i+1,this.lex()}return new iq(r,new rq(this,t,this.tokenRegex.lastIndex))}},aJ=class{constructor(e,t){e===void 0&&(e={}),t===void 0&&(t={}),this.current=void 0,this.builtins=void 0,this.undefStack=void 0,this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new L(`Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug`);var e=this.undefStack.pop();for(var t of Object.keys(e))e[t]===void 0?delete this.current[t]:this.current[t]=e[t]}endGroups(){for(;this.undefStack.length>0;)this.endGroup()}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){if(Object.prototype.hasOwnProperty.call(this.current,e))return this.current[e];if(Object.prototype.hasOwnProperty.call(this.builtins,e))return this.builtins[e]}set(e,t,n){if(n===void 0&&(n=!1),n){for(var r=0;r0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{var i=this.undefStack[this.undefStack.length-1];i&&!Object.prototype.hasOwnProperty.call(i,e)&&(i[e]=Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:void 0)}t==null?delete this.current[e]:this.current[e]=t}},oJ=nq;$(`\\noexpand`,function(e){var t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}}),$(`\\expandafter`,function(e){var t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}}),$(`\\@firstoftwo`,function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}}),$(`\\@secondoftwo`,function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}}),$(`\\@ifnextchar`,function(e){var t=e.consumeArgs(3);e.consumeSpaces();var n=e.future();return t[0].length===1&&t[0][0].text===n.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}}),$(`\\@ifstar`,`\\@ifnextchar *{\\@firstoftwo{#1}}`),$(`\\TextOrMath`,function(e){var t=e.consumeArgs(2);return e.mode===`text`?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});var sJ={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};$(`\\char`,function(e){var t=e.popToken(),n,r=0;if(t.text===`'`)n=8,t=e.popToken();else if(t.text===`"`)n=16,t=e.popToken();else if(t.text==="`"){if(t=e.popToken(),t.text[0]===`\\`)r=t.text.charCodeAt(1);else if(t.text===`EOF`)throw new L("\\char` missing argument");else r=t.text.charCodeAt(0)}else n=10;if(n){if(r=sJ[t.text],r==null||r>=n)throw new L(`Invalid base-`+n+` digit `+t.text);for(var i;(i=sJ[e.future().text])!=null&&i{var i=e.consumeArg().tokens;if(i.length!==1)throw new L(`\\newcommand's first argument must be a macro name`);var a=i[0].text,o=e.isDefined(a);if(o&&!t)throw new L(`\\newcommand{`+a+`} attempting to redefine `+(a+`; use \\renewcommand`));if(!o&&!n)throw new L(`\\renewcommand{`+a+`} when command `+a+` does not yet exist; use \\newcommand`);var s=0;if(i=e.consumeArg().tokens,i.length===1&&i[0].text===`[`){for(var c=``,l=e.expandNextToken();l.text!==`]`&&l.text!==`EOF`;)c+=l.text,l=e.expandNextToken();if(!c.match(/^\s*[0-9]+\s*$/))throw new L(`Invalid number of arguments: `+c);s=parseInt(c),i=e.consumeArg().tokens}return o&&r||e.macros.set(a,{tokens:i,numArgs:s}),``};$(`\\newcommand`,e=>cJ(e,!1,!0,!1)),$(`\\renewcommand`,e=>cJ(e,!0,!1,!1)),$(`\\providecommand`,e=>cJ(e,!0,!0,!0)),$(`\\message`,e=>{var t=e.consumeArgs(1)[0];return console.log(t.reverse().map(e=>e.text).join(``)),``}),$(`\\errmessage`,e=>{var t=e.consumeArgs(1)[0];return console.error(t.reverse().map(e=>e.text).join(``)),``}),$(`\\show`,e=>{var t=e.popToken(),n=t.text;return console.log(t,e.macros.get(n),Yq[n],UU.math[n],UU.text[n]),``}),$(`\\bgroup`,`{`),$(`\\egroup`,`}`),$(`~`,`\\nobreakspace`),$(`\\lq`,"`"),$(`\\rq`,`'`),$(`\\aa`,`\\r a`),$(`\\AA`,`\\r A`),$(`\\textcopyright`,"\\html@mathml{\\textcircled{c}}{\\char`©}"),$(`\\copyright`,`\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}`),$(`\\textregistered`,"\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"),$(`ℬ`,`\\mathscr{B}`),$(`ℰ`,`\\mathscr{E}`),$(`ℱ`,`\\mathscr{F}`),$(`ℋ`,`\\mathscr{H}`),$(`ℐ`,`\\mathscr{I}`),$(`ℒ`,`\\mathscr{L}`),$(`ℳ`,`\\mathscr{M}`),$(`ℛ`,`\\mathscr{R}`),$(`ℭ`,`\\mathfrak{C}`),$(`ℌ`,`\\mathfrak{H}`),$(`ℨ`,`\\mathfrak{Z}`),$(`\\Bbbk`,`\\Bbb{k}`),$(`\\llap`,`\\mathllap{\\textrm{#1}}`),$(`\\rlap`,`\\mathrlap{\\textrm{#1}}`),$(`\\clap`,`\\mathclap{\\textrm{#1}}`),$(`\\mathstrut`,`\\vphantom{(}`),$(`\\underbar`,`\\underline{\\text{#1}}`),$(`\\not`,`\\html@mathml{\\mathrel{\\mathrlap\\@not}\\nobreak}{\\char"338}`),$(`\\neq`,"\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}"),$(`\\ne`,`\\neq`),$(`≠`,`\\neq`),$(`\\notin`,"\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}"),$(`∉`,`\\notin`),$(`≘`,"\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}"),$(`≙`,"\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`≘}}"),$(`≚`,"\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`≚}}"),$(`≛`,"\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}"),$(`≝`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}"),$(`≞`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}"),$(`≟`,"\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`≟}}"),$(`⟂`,`\\perp`),$(`‼`,`\\mathclose{!\\mkern-0.8mu!}`),$(`∌`,`\\notni`),$(`⌜`,`\\ulcorner`),$(`⌝`,`\\urcorner`),$(`⌞`,`\\llcorner`),$(`⌟`,`\\lrcorner`),$(`©`,`\\copyright`),$(`®`,`\\textregistered`),$(`\\ulcorner`,`\\html@mathml{\\@ulcorner}{\\mathop{\\char"231c}}`),$(`\\urcorner`,`\\html@mathml{\\@urcorner}{\\mathop{\\char"231d}}`),$(`\\llcorner`,`\\html@mathml{\\@llcorner}{\\mathop{\\char"231e}}`),$(`\\lrcorner`,`\\html@mathml{\\@lrcorner}{\\mathop{\\char"231f}}`),$(`\\vdots`,`{\\varvdots\\rule{0pt}{15pt}}`),$(`⋮`,`\\vdots`),$(`\\varGamma`,`\\mathit{\\Gamma}`),$(`\\varDelta`,`\\mathit{\\Delta}`),$(`\\varTheta`,`\\mathit{\\Theta}`),$(`\\varLambda`,`\\mathit{\\Lambda}`),$(`\\varXi`,`\\mathit{\\Xi}`),$(`\\varPi`,`\\mathit{\\Pi}`),$(`\\varSigma`,`\\mathit{\\Sigma}`),$(`\\varUpsilon`,`\\mathit{\\Upsilon}`),$(`\\varPhi`,`\\mathit{\\Phi}`),$(`\\varPsi`,`\\mathit{\\Psi}`),$(`\\varOmega`,`\\mathit{\\Omega}`),$(`\\substack`,`\\begin{subarray}{c}#1\\end{subarray}`),$(`\\colon`,`\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax`),$(`\\boxed`,`\\fbox{$\\displaystyle{#1}$}`),$(`\\iff`,`\\DOTSB\\;\\Longleftrightarrow\\;`),$(`\\implies`,`\\DOTSB\\;\\Longrightarrow\\;`),$(`\\impliedby`,`\\DOTSB\\;\\Longleftarrow\\;`),$(`\\dddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}`),$(`\\ddddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}`);var lJ={",":`\\dotsc`,"\\not":`\\dotsb`,"+":`\\dotsb`,"=":`\\dotsb`,"<":`\\dotsb`,">":`\\dotsb`,"-":`\\dotsb`,"*":`\\dotsb`,":":`\\dotsb`,"\\DOTSB":`\\dotsb`,"\\coprod":`\\dotsb`,"\\bigvee":`\\dotsb`,"\\bigwedge":`\\dotsb`,"\\biguplus":`\\dotsb`,"\\bigcap":`\\dotsb`,"\\bigcup":`\\dotsb`,"\\prod":`\\dotsb`,"\\sum":`\\dotsb`,"\\bigotimes":`\\dotsb`,"\\bigoplus":`\\dotsb`,"\\bigodot":`\\dotsb`,"\\bigsqcup":`\\dotsb`,"\\And":`\\dotsb`,"\\longrightarrow":`\\dotsb`,"\\Longrightarrow":`\\dotsb`,"\\longleftarrow":`\\dotsb`,"\\Longleftarrow":`\\dotsb`,"\\longleftrightarrow":`\\dotsb`,"\\Longleftrightarrow":`\\dotsb`,"\\mapsto":`\\dotsb`,"\\longmapsto":`\\dotsb`,"\\hookrightarrow":`\\dotsb`,"\\doteq":`\\dotsb`,"\\mathbin":`\\dotsb`,"\\mathrel":`\\dotsb`,"\\relbar":`\\dotsb`,"\\Relbar":`\\dotsb`,"\\xrightarrow":`\\dotsb`,"\\xleftarrow":`\\dotsb`,"\\DOTSI":`\\dotsi`,"\\int":`\\dotsi`,"\\oint":`\\dotsi`,"\\iint":`\\dotsi`,"\\iiint":`\\dotsi`,"\\iiiint":`\\dotsi`,"\\idotsint":`\\dotsi`,"\\DOTSX":`\\dotsx`},uJ=new Set([`bin`,`rel`]);$(`\\dots`,function(e){var t=`\\dotso`,n=e.expandAfterFuture().text;return n in lJ?t=lJ[n]:(n.slice(0,4)===`\\not`||n in UU.math&&uJ.has(UU.math[n].group))&&(t=`\\dotsb`),t});var dJ={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};$(`\\dotso`,function(e){return e.future().text in dJ?`\\ldots\\,`:`\\ldots`}),$(`\\dotsc`,function(e){var t=e.future().text;return t in dJ&&t!==`,`?`\\ldots\\,`:`\\ldots`}),$(`\\cdots`,function(e){return e.future().text in dJ?`\\@cdots\\,`:`\\@cdots`}),$(`\\dotsb`,`\\cdots`),$(`\\dotsm`,`\\cdots`),$(`\\dotsi`,`\\!\\cdots`),$(`\\dotsx`,`\\ldots\\,`),$(`\\DOTSI`,`\\relax`),$(`\\DOTSB`,`\\relax`),$(`\\DOTSX`,`\\relax`),$(`\\tmspace`,`\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax`),$(`\\,`,`\\tmspace+{3mu}{.1667em}`),$(`\\thinspace`,`\\,`),$(`\\>`,`\\mskip{4mu}`),$(`\\:`,`\\tmspace+{4mu}{.2222em}`),$(`\\medspace`,`\\:`),$(`\\;`,`\\tmspace+{5mu}{.2777em}`),$(`\\thickspace`,`\\;`),$(`\\!`,`\\tmspace-{3mu}{.1667em}`),$(`\\negthinspace`,`\\!`),$(`\\negmedspace`,`\\tmspace-{4mu}{.2222em}`),$(`\\negthickspace`,`\\tmspace-{5mu}{.277em}`),$(`\\enspace`,`\\kern.5em `),$(`\\enskip`,`\\hskip.5em\\relax`),$(`\\quad`,`\\hskip1em\\relax`),$(`\\qquad`,`\\hskip2em\\relax`),$(`\\tag`,`\\@ifstar\\tag@literal\\tag@paren`),$(`\\tag@paren`,`\\tag@literal{({#1})}`),$(`\\tag@literal`,e=>{if(e.macros.get(`\\df@tag`))throw new L(`Multiple \\tag`);return`\\gdef\\df@tag{\\text{#1}}`}),$(`\\bmod`,`\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}`),$(`\\pod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)`),$(`\\pmod`,`\\pod{{\\rm mod}\\mkern6mu#1}`),$(`\\mod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1`),$(`\\newline`,`\\\\\\relax`),$(`\\TeX`,`\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}`);var fJ=z(IU[`Main-Regular`][84][1]-.7*IU[`Main-Regular`][65][1]);$(`\\LaTeX`,`\\textrm{\\html@mathml{`+(`L\\kern-.36em\\raisebox{`+fJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{LaTeX}}`),$(`\\KaTeX`,`\\textrm{\\html@mathml{`+(`K\\kern-.17em\\raisebox{`+fJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{KaTeX}}`),$(`\\hspace`,`\\@ifstar\\@hspacer\\@hspace`),$(`\\@hspace`,`\\hskip #1\\relax`),$(`\\@hspacer`,`\\rule{0pt}{0pt}\\hskip #1\\relax`),$(`\\ordinarycolon`,`:`),$(`\\vcentcolon`,`\\mathrel{\\mathop\\ordinarycolon}`),$(`\\dblcolon`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}`),$(`\\coloneqq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}`),$(`\\Coloneqq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}`),$(`\\coloneq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}`),$(`\\Coloneq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}`),$(`\\eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}`),$(`\\Eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}`),$(`\\eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}`),$(`\\Eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}`),$(`\\colonapprox`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}`),$(`\\Colonapprox`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}`),$(`\\colonsim`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}`),$(`\\Colonsim`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}`),$(`∷`,`\\dblcolon`),$(`∹`,`\\eqcolon`),$(`≔`,`\\coloneqq`),$(`≕`,`\\eqqcolon`),$(`⩴`,`\\Coloneqq`),$(`\\ratio`,`\\vcentcolon`),$(`\\coloncolon`,`\\dblcolon`),$(`\\colonequals`,`\\coloneqq`),$(`\\coloncolonequals`,`\\Coloneqq`),$(`\\equalscolon`,`\\eqqcolon`),$(`\\equalscoloncolon`,`\\Eqqcolon`),$(`\\colonminus`,`\\coloneq`),$(`\\coloncolonminus`,`\\Coloneq`),$(`\\minuscolon`,`\\eqcolon`),$(`\\minuscoloncolon`,`\\Eqcolon`),$(`\\coloncolonapprox`,`\\Colonapprox`),$(`\\coloncolonsim`,`\\Colonsim`),$(`\\simcolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\simcoloncolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\approxcolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\approxcoloncolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\notni`,"\\html@mathml{\\not\\ni}{\\mathrel{\\char`∌}}"),$(`\\limsup`,`\\DOTSB\\operatorname*{lim\\,sup}`),$(`\\liminf`,`\\DOTSB\\operatorname*{lim\\,inf}`),$(`\\injlim`,`\\DOTSB\\operatorname*{inj\\,lim}`),$(`\\projlim`,`\\DOTSB\\operatorname*{proj\\,lim}`),$(`\\varlimsup`,`\\DOTSB\\operatorname*{\\overline{lim}}`),$(`\\varliminf`,`\\DOTSB\\operatorname*{\\underline{lim}}`),$(`\\varinjlim`,`\\DOTSB\\operatorname*{\\underrightarrow{lim}}`),$(`\\varprojlim`,`\\DOTSB\\operatorname*{\\underleftarrow{lim}}`),$(`\\gvertneqq`,`\\html@mathml{\\@gvertneqq}{≩}`),$(`\\lvertneqq`,`\\html@mathml{\\@lvertneqq}{≨}`),$(`\\ngeqq`,`\\html@mathml{\\@ngeqq}{≱}`),$(`\\ngeqslant`,`\\html@mathml{\\@ngeqslant}{≱}`),$(`\\nleqq`,`\\html@mathml{\\@nleqq}{≰}`),$(`\\nleqslant`,`\\html@mathml{\\@nleqslant}{≰}`),$(`\\nshortmid`,`\\html@mathml{\\@nshortmid}{∤}`),$(`\\nshortparallel`,`\\html@mathml{\\@nshortparallel}{∦}`),$(`\\nsubseteqq`,`\\html@mathml{\\@nsubseteqq}{⊈}`),$(`\\nsupseteqq`,`\\html@mathml{\\@nsupseteqq}{⊉}`),$(`\\varsubsetneq`,`\\html@mathml{\\@varsubsetneq}{⊊}`),$(`\\varsubsetneqq`,`\\html@mathml{\\@varsubsetneqq}{⫋}`),$(`\\varsupsetneq`,`\\html@mathml{\\@varsupsetneq}{⊋}`),$(`\\varsupsetneqq`,`\\html@mathml{\\@varsupsetneqq}{⫌}`),$(`\\imath`,`\\html@mathml{\\@imath}{ı}`),$(`\\jmath`,`\\html@mathml{\\@jmath}{ȷ}`),$(`\\llbracket`,"\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}"),$(`\\rrbracket`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}"),$(`⟦`,`\\llbracket`),$(`⟧`,`\\rrbracket`),$(`\\lBrace`,"\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}"),$(`\\rBrace`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}"),$(`↤`,`\\mapsfrom`),$(`\\mapsfrom`,"\\html@mathml{\\mathrel{\\mathreflectbox{\\mapsto}}}{\\mathrel{\\char`↤}}"),$(`⦃`,`\\lBrace`),$(`⦄`,`\\rBrace`),$(`\\minuso`,"\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}"),$(`⦵`,`\\minuso`),$(`\\darr`,`\\downarrow`),$(`\\dArr`,`\\Downarrow`),$(`\\Darr`,`\\Downarrow`),$(`\\lang`,`\\langle`),$(`\\rang`,`\\rangle`),$(`\\uarr`,`\\uparrow`),$(`\\uArr`,`\\Uparrow`),$(`\\Uarr`,`\\Uparrow`),$(`\\N`,`\\mathbb{N}`),$(`\\R`,`\\mathbb{R}`),$(`\\Z`,`\\mathbb{Z}`),$(`\\alef`,`\\aleph`),$(`\\alefsym`,`\\aleph`),$(`\\Alpha`,`\\mathrm{A}`),$(`\\Beta`,`\\mathrm{B}`),$(`\\bull`,`\\bullet`),$(`\\Chi`,`\\mathrm{X}`),$(`\\clubs`,`\\clubsuit`),$(`\\cnums`,`\\mathbb{C}`),$(`\\Complex`,`\\mathbb{C}`),$(`\\Dagger`,`\\ddagger`),$(`\\diamonds`,`\\diamondsuit`),$(`\\empty`,`\\emptyset`),$(`\\Epsilon`,`\\mathrm{E}`),$(`\\Eta`,`\\mathrm{H}`),$(`\\exist`,`\\exists`),$(`\\harr`,`\\leftrightarrow`),$(`\\hArr`,`\\Leftrightarrow`),$(`\\Harr`,`\\Leftrightarrow`),$(`\\hearts`,`\\heartsuit`),$(`\\image`,`\\Im`),$(`\\infin`,`\\infty`),$(`\\Iota`,`\\mathrm{I}`),$(`\\isin`,`\\in`),$(`\\Kappa`,`\\mathrm{K}`),$(`\\larr`,`\\leftarrow`),$(`\\lArr`,`\\Leftarrow`),$(`\\Larr`,`\\Leftarrow`),$(`\\lrarr`,`\\leftrightarrow`),$(`\\lrArr`,`\\Leftrightarrow`),$(`\\Lrarr`,`\\Leftrightarrow`),$(`\\Mu`,`\\mathrm{M}`),$(`\\natnums`,`\\mathbb{N}`),$(`\\Nu`,`\\mathrm{N}`),$(`\\Omicron`,`\\mathrm{O}`),$(`\\plusmn`,`\\pm`),$(`\\rarr`,`\\rightarrow`),$(`\\rArr`,`\\Rightarrow`),$(`\\Rarr`,`\\Rightarrow`),$(`\\real`,`\\Re`),$(`\\reals`,`\\mathbb{R}`),$(`\\Reals`,`\\mathbb{R}`),$(`\\Rho`,`\\mathrm{P}`),$(`\\sdot`,`\\cdot`),$(`\\sect`,`\\S`),$(`\\spades`,`\\spadesuit`),$(`\\sub`,`\\subset`),$(`\\sube`,`\\subseteq`),$(`\\supe`,`\\supseteq`),$(`\\Tau`,`\\mathrm{T}`),$(`\\thetasym`,`\\vartheta`),$(`\\weierp`,`\\wp`),$(`\\Zeta`,`\\mathrm{Z}`),$(`\\argmin`,`\\DOTSB\\operatorname*{arg\\,min}`),$(`\\argmax`,`\\DOTSB\\operatorname*{arg\\,max}`),$(`\\plim`,`\\DOTSB\\mathop{\\operatorname{plim}}\\limits`),$(`\\bra`,`\\mathinner{\\langle{#1}|}`),$(`\\ket`,`\\mathinner{|{#1}\\rangle}`),$(`\\braket`,`\\mathinner{\\langle{#1}\\rangle}`),$(`\\Bra`,`\\left\\langle#1\\right|`),$(`\\Ket`,`\\left|#1\\right\\rangle`);var pJ=e=>t=>{var n=t.consumeArg().tokens,r=t.consumeArg().tokens,i=t.consumeArg().tokens,a=t.consumeArg().tokens,o=t.macros.get(`|`),s=t.macros.get(`\\|`);t.macros.beginGroup();var c=t=>n=>{e&&(n.macros.set(`|`,o),i.length&&n.macros.set(`\\|`,s));var a=t;return!t&&i.length&&n.future().text===`|`&&(n.popToken(),a=!0),{tokens:a?i:r,numArgs:0}};t.macros.set(`|`,c(!1)),i.length&&t.macros.set(`\\|`,c(!0));var l=t.consumeArg().tokens,u=t.expandTokens([...a,...l,...n]);return t.macros.endGroup(),{tokens:u.reverse(),numArgs:0}};$(`\\bra@ket`,pJ(!1)),$(`\\bra@set`,pJ(!0)),$(`\\Braket`,`\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}`),$(`\\Set`,`\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}`),$(`\\set`,`\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}`),$(`\\angln`,`{\\angl n}`),$(`\\blue`,`\\textcolor{##6495ed}{#1}`),$(`\\orange`,`\\textcolor{##ffa500}{#1}`),$(`\\pink`,`\\textcolor{##ff00af}{#1}`),$(`\\red`,`\\textcolor{##df0030}{#1}`),$(`\\green`,`\\textcolor{##28ae7b}{#1}`),$(`\\gray`,`\\textcolor{gray}{#1}`),$(`\\purple`,`\\textcolor{##9d38bd}{#1}`),$(`\\blueA`,`\\textcolor{##ccfaff}{#1}`),$(`\\blueB`,`\\textcolor{##80f6ff}{#1}`),$(`\\blueC`,`\\textcolor{##63d9ea}{#1}`),$(`\\blueD`,`\\textcolor{##11accd}{#1}`),$(`\\blueE`,`\\textcolor{##0c7f99}{#1}`),$(`\\tealA`,`\\textcolor{##94fff5}{#1}`),$(`\\tealB`,`\\textcolor{##26edd5}{#1}`),$(`\\tealC`,`\\textcolor{##01d1c1}{#1}`),$(`\\tealD`,`\\textcolor{##01a995}{#1}`),$(`\\tealE`,`\\textcolor{##208170}{#1}`),$(`\\greenA`,`\\textcolor{##b6ffb0}{#1}`),$(`\\greenB`,`\\textcolor{##8af281}{#1}`),$(`\\greenC`,`\\textcolor{##74cf70}{#1}`),$(`\\greenD`,`\\textcolor{##1fab54}{#1}`),$(`\\greenE`,`\\textcolor{##0d923f}{#1}`),$(`\\goldA`,`\\textcolor{##ffd0a9}{#1}`),$(`\\goldB`,`\\textcolor{##ffbb71}{#1}`),$(`\\goldC`,`\\textcolor{##ff9c39}{#1}`),$(`\\goldD`,`\\textcolor{##e07d10}{#1}`),$(`\\goldE`,`\\textcolor{##a75a05}{#1}`),$(`\\redA`,`\\textcolor{##fca9a9}{#1}`),$(`\\redB`,`\\textcolor{##ff8482}{#1}`),$(`\\redC`,`\\textcolor{##f9685d}{#1}`),$(`\\redD`,`\\textcolor{##e84d39}{#1}`),$(`\\redE`,`\\textcolor{##bc2612}{#1}`),$(`\\maroonA`,`\\textcolor{##ffbde0}{#1}`),$(`\\maroonB`,`\\textcolor{##ff92c6}{#1}`),$(`\\maroonC`,`\\textcolor{##ed5fa6}{#1}`),$(`\\maroonD`,`\\textcolor{##ca337c}{#1}`),$(`\\maroonE`,`\\textcolor{##9e034e}{#1}`),$(`\\purpleA`,`\\textcolor{##ddd7ff}{#1}`),$(`\\purpleB`,`\\textcolor{##c6b9fc}{#1}`),$(`\\purpleC`,`\\textcolor{##aa87ff}{#1}`),$(`\\purpleD`,`\\textcolor{##7854ab}{#1}`),$(`\\purpleE`,`\\textcolor{##543b78}{#1}`),$(`\\mintA`,`\\textcolor{##f5f9e8}{#1}`),$(`\\mintB`,`\\textcolor{##edf2df}{#1}`),$(`\\mintC`,`\\textcolor{##e0e5cc}{#1}`),$(`\\grayA`,`\\textcolor{##f6f7f7}{#1}`),$(`\\grayB`,`\\textcolor{##f0f1f2}{#1}`),$(`\\grayC`,`\\textcolor{##e3e5e6}{#1}`),$(`\\grayD`,`\\textcolor{##d6d8da}{#1}`),$(`\\grayE`,`\\textcolor{##babec2}{#1}`),$(`\\grayF`,`\\textcolor{##888d93}{#1}`),$(`\\grayG`,`\\textcolor{##626569}{#1}`),$(`\\grayH`,`\\textcolor{##3b3e40}{#1}`),$(`\\grayI`,`\\textcolor{##21242c}{#1}`),$(`\\kaBlue`,`\\textcolor{##314453}{#1}`),$(`\\kaGreen`,`\\textcolor{##71B307}{#1}`);var mJ={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0},hJ=class{constructor(e,t,n){this.settings=void 0,this.expansionCount=void 0,this.lexer=void 0,this.macros=void 0,this.stack=void 0,this.mode=void 0,this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new aJ(oJ,t.macros),this.mode=n,this.stack=[]}feed(e){this.lexer=new iJ(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}endGroups(){this.macros.endGroups()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){var t,n,r;if(e){if(this.consumeSpaces(),this.future().text!==`[`)return null;t=this.popToken();var i=this.consumeArg([`]`]);r=i.tokens,n=i.end}else{var a=this.consumeArg();r=a.tokens,t=a.start,n=a.end}return this.pushToken(new iq(`EOF`,n.loc)),this.pushTokens(r),new iq(``,rq.range(t,n))}consumeSpaces(){for(;this.future().text===` `;)this.stack.pop()}consumeArg(e){var t=[],n=e&&e.length>0;n||this.consumeSpaces();var r=this.future(),i,a=0,o=0;do{if(i=this.popToken(),t.push(i),i.text===`{`)++a;else if(i.text===`}`){if(--a,a===-1)throw new L(`Extra }`,i)}else if(i.text===`EOF`)throw new L(`Unexpected end of input in a macro argument, expected '`+(e&&n?e[o]:`}`)+`'`,i);if(e&&n){if((a===0||a===1&&e[o]===`{`)&&i.text===e[o]){if(++o,o===e.length){t.splice(-o,o);break}}else o=0}}while(a!==0||n);return r.text===`{`&&t[t.length-1].text===`}`&&(t.pop(),t.shift()),t.reverse(),{tokens:t,start:r,end:i}}consumeArgs(e,t){if(t){if(t.length!==e+1)throw new L(`The length of delimiters doesn't match the number of args!`);for(var n=t[0],r=0;rthis.settings.maxExpand)throw new L(`Too many expansions: infinite loop or need to increase maxExpand setting`)}expandOnce(e){var t=this.popToken(),n=t.text,r=t.noexpand?null:this._getExpansion(n);if(r==null||e&&r.unexpandable){if(e&&r==null&&n[0]===`\\`&&!this.isDefined(n))throw new L(`Undefined control sequence: `+n);return this.pushToken(t),!1}this.countExpansion(1);var i=r.tokens,a=this.consumeArgs(r.numArgs,r.delimiters);if(r.numArgs){i=i.slice();for(var o=i.length-1;o>=0;--o){var s=i[o];if(s.text===`#`){if(o===0)throw new L(`Incomplete placeholder at end of macro body`,s);if(s=i[--o],s.text===`#`)i.splice(o+1,1);else if(/^[1-9]$/.test(s.text))i.splice(o,2,...a[s.text-1]);else throw new L(`Not a valid argument number`,s)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){var e=this.stack.pop();return e.treatAsRelax&&(e.text=`\\relax`),e}}expandMacro(e){return this.macros.has(e)?this.expandTokens([new iq(e)]):void 0}expandTokens(e){var t=[],n=this.stack.length;for(this.pushTokens(e);this.stack.length>n;)if(this.expandOnce(!0)===!1){var r=this.stack.pop();r.treatAsRelax&&=(r.noexpand=!1,!1),t.push(r)}return this.countExpansion(t.length),t}expandMacroAsText(e){var t=this.expandMacro(e);return t&&t.map(e=>e.text).join(``)}_getExpansion(e){var t=this.macros.get(e);if(t==null)return t;if(e.length===1){var n=this.lexer.catcodes[e];if(n!=null&&n!==13)return}var r=typeof t==`function`?t(this):t;if(typeof r==`string`){var i=0;if(r.includes(`#`))for(var a=r.replace(/##/g,``);a.includes(`#`+(i+1));)++i;for(var o=new iJ(r,this.settings),s=[],c=o.lex();c.text!==`EOF`;)s.push(c),c=o.lex();return s.reverse(),{tokens:s,numArgs:i}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call(Yq,e)||Object.prototype.hasOwnProperty.call(UU.math,e)||Object.prototype.hasOwnProperty.call(UU.text,e)||Object.prototype.hasOwnProperty.call(mJ,e)}isExpandable(e){var t=this.macros.get(e);return t==null?Object.prototype.hasOwnProperty.call(Yq,e)&&!Yq[e].primitive:typeof t==`string`||typeof t==`function`||!t.unexpandable}},gJ=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,_J=Object.freeze({"₊":`+`,"₋":`-`,"₌":`=`,"₍":`(`,"₎":`)`,"₀":`0`,"₁":`1`,"₂":`2`,"₃":`3`,"₄":`4`,"₅":`5`,"₆":`6`,"₇":`7`,"₈":`8`,"₉":`9`,ₐ:`a`,ₑ:`e`,ₕ:`h`,ᵢ:`i`,ⱼ:`j`,ₖ:`k`,ₗ:`l`,ₘ:`m`,ₙ:`n`,ₒ:`o`,ₚ:`p`,ᵣ:`r`,ₛ:`s`,ₜ:`t`,ᵤ:`u`,ᵥ:`v`,ₓ:`x`,ᵦ:`β`,ᵧ:`γ`,ᵨ:`ρ`,ᵩ:`ϕ`,ᵪ:`χ`,"⁺":`+`,"⁻":`-`,"⁼":`=`,"⁽":`(`,"⁾":`)`,"⁰":`0`,"¹":`1`,"²":`2`,"³":`3`,"⁴":`4`,"⁵":`5`,"⁶":`6`,"⁷":`7`,"⁸":`8`,"⁹":`9`,ᴬ:`A`,ᴮ:`B`,ᴰ:`D`,ᴱ:`E`,ᴳ:`G`,ᴴ:`H`,ᴵ:`I`,ᴶ:`J`,ᴷ:`K`,ᴸ:`L`,ᴹ:`M`,ᴺ:`N`,ᴼ:`O`,ᴾ:`P`,ᴿ:`R`,ᵀ:`T`,ᵁ:`U`,ⱽ:`V`,ᵂ:`W`,ᵃ:`a`,ᵇ:`b`,ᶜ:`c`,ᵈ:`d`,ᵉ:`e`,ᶠ:`f`,ᵍ:`g`,ʰ:`h`,ⁱ:`i`,ʲ:`j`,ᵏ:`k`,ˡ:`l`,ᵐ:`m`,ⁿ:`n`,ᵒ:`o`,ᵖ:`p`,ʳ:`r`,ˢ:`s`,ᵗ:`t`,ᵘ:`u`,ᵛ:`v`,ʷ:`w`,ˣ:`x`,ʸ:`y`,ᶻ:`z`,ᵝ:`β`,ᵞ:`γ`,ᵟ:`δ`,ᵠ:`ϕ`,ᵡ:`χ`,ᶿ:`θ`}),vJ={"́":{text:`\\'`,math:`\\acute`},"̀":{text:"\\`",math:`\\grave`},"̈":{text:`\\"`,math:`\\ddot`},"̃":{text:`\\~`,math:`\\tilde`},"̄":{text:`\\=`,math:`\\bar`},"̆":{text:`\\u`,math:`\\breve`},"̌":{text:`\\v`,math:`\\check`},"̂":{text:`\\^`,math:`\\hat`},"̇":{text:`\\.`,math:`\\dot`},"̊":{text:`\\r`,math:`\\mathring`},"̋":{text:`\\H`},"̧":{text:`\\c`}},yJ={á:`á`,à:`à`,ä:`ä`,ǟ:`ǟ`,ã:`ã`,ā:`ā`,ă:`ă`,ắ:`ắ`,ằ:`ằ`,ẵ:`ẵ`,ǎ:`ǎ`,â:`â`,ấ:`ấ`,ầ:`ầ`,ẫ:`ẫ`,ȧ:`ȧ`,ǡ:`ǡ`,å:`å`,ǻ:`ǻ`,ḃ:`ḃ`,ć:`ć`,ḉ:`ḉ`,č:`č`,ĉ:`ĉ`,ċ:`ċ`,ç:`ç`,ď:`ď`,ḋ:`ḋ`,ḑ:`ḑ`,é:`é`,è:`è`,ë:`ë`,ẽ:`ẽ`,ē:`ē`,ḗ:`ḗ`,ḕ:`ḕ`,ĕ:`ĕ`,ḝ:`ḝ`,ě:`ě`,ê:`ê`,ế:`ế`,ề:`ề`,ễ:`ễ`,ė:`ė`,ȩ:`ȩ`,ḟ:`ḟ`,ǵ:`ǵ`,ḡ:`ḡ`,ğ:`ğ`,ǧ:`ǧ`,ĝ:`ĝ`,ġ:`ġ`,ģ:`ģ`,ḧ:`ḧ`,ȟ:`ȟ`,ĥ:`ĥ`,ḣ:`ḣ`,ḩ:`ḩ`,í:`í`,ì:`ì`,ï:`ï`,ḯ:`ḯ`,ĩ:`ĩ`,ī:`ī`,ĭ:`ĭ`,ǐ:`ǐ`,î:`î`,ǰ:`ǰ`,ĵ:`ĵ`,ḱ:`ḱ`,ǩ:`ǩ`,ķ:`ķ`,ĺ:`ĺ`,ľ:`ľ`,ļ:`ļ`,ḿ:`ḿ`,ṁ:`ṁ`,ń:`ń`,ǹ:`ǹ`,ñ:`ñ`,ň:`ň`,ṅ:`ṅ`,ņ:`ņ`,ó:`ó`,ò:`ò`,ö:`ö`,ȫ:`ȫ`,õ:`õ`,ṍ:`ṍ`,ṏ:`ṏ`,ȭ:`ȭ`,ō:`ō`,ṓ:`ṓ`,ṑ:`ṑ`,ŏ:`ŏ`,ǒ:`ǒ`,ô:`ô`,ố:`ố`,ồ:`ồ`,ỗ:`ỗ`,ȯ:`ȯ`,ȱ:`ȱ`,ő:`ő`,ṕ:`ṕ`,ṗ:`ṗ`,ŕ:`ŕ`,ř:`ř`,ṙ:`ṙ`,ŗ:`ŗ`,ś:`ś`,ṥ:`ṥ`,š:`š`,ṧ:`ṧ`,ŝ:`ŝ`,ṡ:`ṡ`,ş:`ş`,ẗ:`ẗ`,ť:`ť`,ṫ:`ṫ`,ţ:`ţ`,ú:`ú`,ù:`ù`,ü:`ü`,ǘ:`ǘ`,ǜ:`ǜ`,ǖ:`ǖ`,ǚ:`ǚ`,ũ:`ũ`,ṹ:`ṹ`,ū:`ū`,ṻ:`ṻ`,ŭ:`ŭ`,ǔ:`ǔ`,û:`û`,ů:`ů`,ű:`ű`,ṽ:`ṽ`,ẃ:`ẃ`,ẁ:`ẁ`,ẅ:`ẅ`,ŵ:`ŵ`,ẇ:`ẇ`,ẘ:`ẘ`,ẍ:`ẍ`,ẋ:`ẋ`,ý:`ý`,ỳ:`ỳ`,ÿ:`ÿ`,ỹ:`ỹ`,ȳ:`ȳ`,ŷ:`ŷ`,ẏ:`ẏ`,ẙ:`ẙ`,ź:`ź`,ž:`ž`,ẑ:`ẑ`,ż:`ż`,Á:`Á`,À:`À`,Ä:`Ä`,Ǟ:`Ǟ`,Ã:`Ã`,Ā:`Ā`,Ă:`Ă`,Ắ:`Ắ`,Ằ:`Ằ`,Ẵ:`Ẵ`,Ǎ:`Ǎ`,Â:`Â`,Ấ:`Ấ`,Ầ:`Ầ`,Ẫ:`Ẫ`,Ȧ:`Ȧ`,Ǡ:`Ǡ`,Å:`Å`,Ǻ:`Ǻ`,Ḃ:`Ḃ`,Ć:`Ć`,Ḉ:`Ḉ`,Č:`Č`,Ĉ:`Ĉ`,Ċ:`Ċ`,Ç:`Ç`,Ď:`Ď`,Ḋ:`Ḋ`,Ḑ:`Ḑ`,É:`É`,È:`È`,Ë:`Ë`,Ẽ:`Ẽ`,Ē:`Ē`,Ḗ:`Ḗ`,Ḕ:`Ḕ`,Ĕ:`Ĕ`,Ḝ:`Ḝ`,Ě:`Ě`,Ê:`Ê`,Ế:`Ế`,Ề:`Ề`,Ễ:`Ễ`,Ė:`Ė`,Ȩ:`Ȩ`,Ḟ:`Ḟ`,Ǵ:`Ǵ`,Ḡ:`Ḡ`,Ğ:`Ğ`,Ǧ:`Ǧ`,Ĝ:`Ĝ`,Ġ:`Ġ`,Ģ:`Ģ`,Ḧ:`Ḧ`,Ȟ:`Ȟ`,Ĥ:`Ĥ`,Ḣ:`Ḣ`,Ḩ:`Ḩ`,Í:`Í`,Ì:`Ì`,Ï:`Ï`,Ḯ:`Ḯ`,Ĩ:`Ĩ`,Ī:`Ī`,Ĭ:`Ĭ`,Ǐ:`Ǐ`,Î:`Î`,İ:`İ`,Ĵ:`Ĵ`,Ḱ:`Ḱ`,Ǩ:`Ǩ`,Ķ:`Ķ`,Ĺ:`Ĺ`,Ľ:`Ľ`,Ļ:`Ļ`,Ḿ:`Ḿ`,Ṁ:`Ṁ`,Ń:`Ń`,Ǹ:`Ǹ`,Ñ:`Ñ`,Ň:`Ň`,Ṅ:`Ṅ`,Ņ:`Ņ`,Ó:`Ó`,Ò:`Ò`,Ö:`Ö`,Ȫ:`Ȫ`,Õ:`Õ`,Ṍ:`Ṍ`,Ṏ:`Ṏ`,Ȭ:`Ȭ`,Ō:`Ō`,Ṓ:`Ṓ`,Ṑ:`Ṑ`,Ŏ:`Ŏ`,Ǒ:`Ǒ`,Ô:`Ô`,Ố:`Ố`,Ồ:`Ồ`,Ỗ:`Ỗ`,Ȯ:`Ȯ`,Ȱ:`Ȱ`,Ő:`Ő`,Ṕ:`Ṕ`,Ṗ:`Ṗ`,Ŕ:`Ŕ`,Ř:`Ř`,Ṙ:`Ṙ`,Ŗ:`Ŗ`,Ś:`Ś`,Ṥ:`Ṥ`,Š:`Š`,Ṧ:`Ṧ`,Ŝ:`Ŝ`,Ṡ:`Ṡ`,Ş:`Ş`,Ť:`Ť`,Ṫ:`Ṫ`,Ţ:`Ţ`,Ú:`Ú`,Ù:`Ù`,Ü:`Ü`,Ǘ:`Ǘ`,Ǜ:`Ǜ`,Ǖ:`Ǖ`,Ǚ:`Ǚ`,Ũ:`Ũ`,Ṹ:`Ṹ`,Ū:`Ū`,Ṻ:`Ṻ`,Ŭ:`Ŭ`,Ǔ:`Ǔ`,Û:`Û`,Ů:`Ů`,Ű:`Ű`,Ṽ:`Ṽ`,Ẃ:`Ẃ`,Ẁ:`Ẁ`,Ẅ:`Ẅ`,Ŵ:`Ŵ`,Ẇ:`Ẇ`,Ẍ:`Ẍ`,Ẋ:`Ẋ`,Ý:`Ý`,Ỳ:`Ỳ`,Ÿ:`Ÿ`,Ỹ:`Ỹ`,Ȳ:`Ȳ`,Ŷ:`Ŷ`,Ẏ:`Ẏ`,Ź:`Ź`,Ž:`Ž`,Ẑ:`Ẑ`,Ż:`Ż`,ά:`ά`,ὰ:`ὰ`,ᾱ:`ᾱ`,ᾰ:`ᾰ`,έ:`έ`,ὲ:`ὲ`,ή:`ή`,ὴ:`ὴ`,ί:`ί`,ὶ:`ὶ`,ϊ:`ϊ`,ΐ:`ΐ`,ῒ:`ῒ`,ῑ:`ῑ`,ῐ:`ῐ`,ό:`ό`,ὸ:`ὸ`,ύ:`ύ`,ὺ:`ὺ`,ϋ:`ϋ`,ΰ:`ΰ`,ῢ:`ῢ`,ῡ:`ῡ`,ῠ:`ῠ`,ώ:`ώ`,ὼ:`ὼ`,Ύ:`Ύ`,Ὺ:`Ὺ`,Ϋ:`Ϋ`,Ῡ:`Ῡ`,Ῠ:`Ῠ`,Ώ:`Ώ`,Ὼ:`Ὼ`},bJ=class e{constructor(e,t){this.mode=void 0,this.gullet=void 0,this.settings=void 0,this.leftrightDepth=void 0,this.nextToken=void 0,this.mode=`math`,this.gullet=new hJ(e,t,this.mode),this.settings=t,this.leftrightDepth=0,this.nextToken=null}expect(e,t){if(t===void 0&&(t=!0),this.fetch().text!==e)throw new L(`Expected '`+e+`', got '`+this.fetch().text+`'`,this.fetch());t&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken??=this.gullet.expandNextToken(),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.settings.globalGroup||this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set(`\\color`,`\\textcolor`);try{var e=this.parseExpression(!1);return this.expect(`EOF`),this.settings.globalGroup||this.gullet.endGroup(),e}finally{this.gullet.endGroups()}}subparse(e){var t=this.nextToken;this.consume(),this.gullet.pushToken(new iq(`}`)),this.gullet.pushTokens(e);var n=this.parseExpression(!1);return this.expect(`}`),this.nextToken=t,n}parseExpression(t,n){for(var r=[];;){this.mode===`math`&&this.consumeSpaces();var i=this.fetch();if(e.endOfExpression.has(i.text)||n&&i.text===n||t&&Yq[i.text]&&Yq[i.text].infix)break;var a=this.parseAtom(n);if(!a)break;a.type!==`internal`&&r.push(a)}return this.mode===`text`&&this.formLigatures(r),this.handleInfixNodes(r)}handleInfixNodes(e){for(var t=-1,n,r=0;r=128)this.settings.strict&&($H(t.charCodeAt(0))?this.mode===`math`&&this.settings.reportNonstrict(`unicodeTextInMathMode`,`Unicode text character "`+t[0]+`" used in math mode`,e):this.settings.reportNonstrict(`unknownSymbol`,`Unrecognized Unicode character "`+t[0]+`"`+(` (`+t.charCodeAt(0)+`)`),e)),a={type:`textord`,mode:`text`,loc:rq.range(e),text:t};else return null;if(this.consume(),i)for(var c=0;ce.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertBlockMath:e=>({commands:t,editor:n})=>{let{latex:r,pos:i}=e;return r?t.insertContentAt(i??n.state.selection.from,{type:this.name,attrs:{latex:r}}):!1},deleteBlockMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateBlockMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r??a.attrs.latex}),!0)}}},parseHTML(){return[{tag:`div[data-type="block-math"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,A(e,{"data-type":`block-math`})]},parseMarkdown:e=>({type:`blockMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>[`$$`,e.attrs?.latex||``,`$$`].join(` -`),markdownTokenizer:{name:`blockMath`,level:`block`,start:e=>e.indexOf(`$$`),tokenize:e=>{let t=e.match(/^\$\$([^$]+)\$\$/);if(!t)return;let[n,r]=t;return{type:`blockMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:/^\$\$\$([^$]+)\$\$\$$/,handler:({state:e,range:t,match:n})=>{let[,r]=n,{tr:i}=e,a=e.doc.resolve(t.from),o=this.type.create({latex:r}),s=a.depth>0&&a.parent.isTextblock&&t.from===a.start()&&t.to===a.end()&&a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),this.type)?{from:a.before(),to:a.after()}:t;i.replaceWith(s.from,s.to,o)}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`div`),i=document.createElement(`div`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),i.className=`block-math-inner`,r.dataset.type=`block-math`,r.setAttribute(`data-latex`,t.attrs.latex),r.appendChild(i);function a(){try{DJ.render(t.attrs.latex,i,e),r.classList.remove(`block-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`block-math-error`)}}let o=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,o),a(),{dom:r,destroy(){r.removeEventListener(`click`,o)}}}}}),kJ=e=>{let t=/\$\$([^$\n]+?)\$\$(?!\$)/g,n=t.exec(e);for(;n!==null;){if(n.index===0||e[n.index-1]!==`$`)return{index:n.index,text:n[0],data:{latex:n[1]}};t.lastIndex=n.index+1,n=t.exec(e)}return null},AJ=Jp.create({name:`inlineMath`,group:`inline`,inline:!0,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertInlineMath:e=>({editor:t,tr:n})=>{let r=e.latex,i=e?.pos??t.state.selection.from;return r?(n.replaceWith(i,i,this.type.create({latex:r})),!0):!1},deleteInlineMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateInlineMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r}),!0)}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{"data-type":`inline-math`})]},parseMarkdown:e=>({type:`inlineMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>`$${e.attrs?.latex||``}$`,markdownTokenizer:{name:`inlineMath`,level:`inline`,start:e=>e.indexOf(`$`),tokenize:e=>{let t=e.match(/^\$([^$]+)\$(?!\$)/);if(!t)return;let[n,r]=t;return{type:`inlineMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:kJ,handler:({state:e,range:t,match:n})=>{let r=n.data?.latex;if(typeof r!=`string`)return null;let{tr:i}=e,a=t.from,o=t.to;i.replaceWith(a,o,this.type.create({latex:r}))}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`span`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),r.dataset.type=`inline-math`,r.setAttribute(`data-latex`,t.attrs.latex);function i(){try{DJ.render(t.attrs.latex,r,e),r.classList.remove(`inline-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`inline-math-error`)}}let a=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,a),i(),{dom:r,destroy(){r.removeEventListener(`click`,a)}}}}}),jJ=Tp.create({name:`Mathematics`,addOptions(){return{inlineOptions:void 0,blockOptions:void 0,katexOptions:void 0}},addExtensions(){return[OJ.configure({...this.options.blockOptions,katexOptions:this.options.katexOptions}),AJ.configure({...this.options.inlineOptions,katexOptions:this.options.katexOptions})]}});function MJ(e,t){let n=n=>(r,i)=>{let a=t();if(!a?.isEditable)return;let o=a.view.nodeDOM(i);if(!(o instanceof HTMLElement))return;let s=e.blocks;YV({anchor:o,value:String(r.attrs.latex??``),label:s.latex,multiline:n===`block`,monospace:!0,labels:{done:s.done,cancel:s.cancel,remove:s.remove},onSave:e=>{let t=a.chain().setNodeSelection(i);e.trim()?(n===`inline`?t.updateInlineMath({latex:e,pos:i}):t.updateBlockMath({latex:e,pos:i})).focus().run():(n===`inline`?t.deleteInlineMath({pos:i}):t.deleteBlockMath({pos:i})).focus().run()},onRemove:()=>{let e=a.chain();(n===`inline`?e.deleteInlineMath({pos:i}):e.deleteBlockMath({pos:i})).focus().run()}})};return jJ.configure({katexOptions:{throwOnError:!1,strict:!1,trust:!1},inlineOptions:{onClick:n(`inline`)},blockOptions:{onClick:n(`block`)}})}function NJ({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new Un,command:({editor:e,range:t,props:i})=>{var a,o;let s=e.view.state.selection.$to.nodeAfter;s!=null&&(a=s.text)!=null&&a.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(o=e.view.dom.ownerDocument.defaultView)==null||(o=o.getSelection())==null||o.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function PJ(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>NJ({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function FJ(e,t){let n=PJ(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var IJ=Jp.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:n}){return[`span`,A(this.HTMLAttributes,e.HTMLAttributes),`${n?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=FJ(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:n})];let r={...this.options};r.HTMLAttributes=A({"data-type":this.name},this.options.HTMLAttributes,t);let i=this.options.renderHTML({options:r,node:e,suggestion:n});return typeof i==`string`?[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),i]:i},...$f({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(?:^|\s)(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:FJ(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let n=!1,{selection:r}=t,{empty:i,anchor:a}=r;if(!i)return!1;let o=new ce,s=0;return t.doc.nodesBetween(a-1,a,(e,t)=>{if(e.type.name===this.name)return n=!0,o=e,s=t,!1}),n&&e.insertText(this.options.deleteTriggerWithBackspace?``:o.attrs.mentionSuggestionChar,s,s+o.nodeSize),n})}},addProseMirrorPlugins(){return PJ(this).map(DV)}});function LJ(e,t){return IJ.configure({HTMLAttributes:{class:`dw-mention`},renderText:({node:e})=>`@${e.attrs.label??e.attrs.id}`,suggestion:{char:`@`,allow:()=>!!t,findSuggestionMatch:t=>{let n=pV({...t,allowSpaces:!0});return n&&cV(n.query,e)?n:pV({...t,allowSpaces:!1})},items:async({query:n})=>{if(!t)return[];let r=sV(n,e,!!t.me).map(e=>({date:e})),i=(await t.search(n).catch(()=>[])).map(e=>({person:e}));return n.trim()?[...r,...i].slice(0,8):[...i.slice(0,6),...r]},render:Bj({label:e.mentions,empty:e.noPeople,toItem:t=>`person`in t?{label:t.person.label,description:t.person.hint,icon:`at`}:{label:aV(t.date.date,e),description:t.date.remind?`${e.dates.remindMe} · ${oV(t.date.date,e)}`:oV(t.date.date,e),icon:t.date.remind?`bell`:`calendar`},pick:(e,n)=>{`person`in n?e.command({id:n.person.id,label:n.person.label}):dV(e.editor,e.range,n.date,t?.me)}})}})}var RJ=`flowchart LR - Idea --> Draft --> Review --> Published`,zJ=null;function BJ(e){return zJ??=e().then(e=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:document.documentElement.classList.contains(`dark`)?`dark`:`neutral`,fontFamily:`inherit`}),e)),zJ}var VJ=0;async function HJ(e,t,n,r){if(e.classList.remove(`dw-mermaid__body--error`),!t.trim())e.textContent=``;else if(r)try{let{svg:n}=await(await BJ(r)).render(`dw-mermaid-${++VJ}`,t);e.innerHTML=n}catch(t){e.classList.add(`dw-mermaid__body--error`),e.textContent=`${n.blocks.mermaidError} ${t instanceof Error?t.message:String(t)}`}else{let n=document.createElement(`pre`);n.className=`dw-mermaid__source`,n.textContent=t,e.replaceChildren(n)}}var UJ=Jp.create({name:`mermaid`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null,load:void 0}},addAttributes(){return{code:{default:``,parseHTML:e=>e.getAttribute(`data-code`)??e.textContent??``,renderHTML:e=>({"data-code":e.code})}}},parseHTML(){return[{tag:`div[data-type='mermaid']`},{tag:`pre.mermaid`}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`mermaid`}),[`pre`,{},String(e.attrs.code)]]},addCommands(){return{insertMermaid:(e=RJ)=>({commands:t})=>t.insertContent({type:this.name,attrs:{code:e}})}},addNodeView(){return({node:e,editor:t,getPos:n})=>{let r=this.options.labels,i=this.options.load,a=document.createElement(`div`);a.className=`dw-mermaid`,a.setAttribute(`data-type`,`mermaid`);let o=document.createElement(`div`);o.className=`dw-mermaid__body`,a.append(o);let s=String(e.attrs.code);return HJ(o,s,r,i),a.addEventListener(`click`,()=>{if(!t.isEditable)return;let e=typeof n==`function`?n():void 0;if(e===void 0)return;let c=r.blocks;YV({anchor:a,value:s,label:c.mermaid,multiline:!0,monospace:!0,labels:{done:c.done,cancel:c.cancel,remove:c.remove},onInput:e=>void HJ(o,e,r,i),onSave:n=>{t.chain().setNodeSelection(e).updateAttributes(`mermaid`,{code:n}).run(),HJ(o,n,r,i)},onRemove:()=>t.chain().setNodeSelection(e).deleteSelection().focus().run(),onCancel:()=>void HJ(o,s,r,i)})}),{dom:a,update:e=>e.type.name===`mermaid`&&(e.attrs.code!==s&&(s=String(e.attrs.code),HJ(o,s,r,i)),!0),ignoreMutation:()=>!0,stopEvent:()=>!1}}}});function WJ(e){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.multiple=!0,n.onchange=()=>t([...n.files??[]]),n.click()})}function GJ(e,t,n,r,i=!1,a){let o=(t,n,r,i)=>({id:t,icon:n,keywords:r,label:e.slash[t]?.label??t,description:e.slash[t]?.description??``,run:i}),s=[o(`text`,`text`,[`paragraph`,`p`],(e,t)=>e.chain().focus().deleteRange(t).setParagraph().run()),o(`h1`,`heading`,[`heading`,`title`,`#`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:1}).run()),o(`h2`,`heading`,[`heading`,`subtitle`,`##`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:2}).run()),o(`h3`,`heading`,[`heading`,`###`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:3}).run()),{...o(`otherHeadings`,`heading`,[`other`,`more headings`,`smaller`],()=>{}),children:[4,5,6].map(e=>o(`h${e}`,`heading`,[`heading`,`#`.repeat(e)],(t,n)=>t.chain().focus().deleteRange(n).setHeading({level:e}).run()))},o(`bullet`,`list`,[`list`,`ul`,`-`],(e,t)=>e.chain().focus().deleteRange(t).toggleBulletList().run()),o(`ordered`,`list-ordered`,[`list`,`ol`,`1.`],(e,t)=>e.chain().focus().deleteRange(t).toggleOrderedList().run()),o(`todo`,`todo`,[`task`,`checkbox`,`checklist`,`[]`],(e,t)=>e.chain().focus().deleteRange(t).toggleTaskList().run()),o(`callout`,`callout`,[`note`,`info`,`tip`,`warning`,`aside`,`box`],(e,t)=>e.chain().focus().deleteRange(t).setCallout().run()),o(`table`,`table`,[`grid`,`rows`,`columns`,`spreadsheet`],(e,t)=>e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()),o(`database`,`database`,[`kanban`,`board`,`calendar`,`records`,`tracker`,`notion`],(e,t)=>e.chain().focus().deleteRange(t).insertDatabase().run()),o(`quote`,`quote`,[`blockquote`,`>`],(e,t)=>e.chain().focus().deleteRange(t).toggleBlockquote().run()),o(`code`,`code`,[`codeblock`,"```",`snippet`],(e,t)=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()),o(`toggle`,`chevron-right`,[`details`,`collapse`,`expand`,`fold`,`>`],(e,t)=>e.chain().focus().deleteRange(t).setDetails().run()),o(`divider`,`divider`,[`hr`,`rule`,`line`,`---`],(e,t)=>e.chain().focus().deleteRange(t).setHorizontalRule().run()),o(`toc`,`list`,[`contents`,`outline`,`headings`,`index`],(e,t)=>e.chain().focus().deleteRange(t).insertTableOfContents().run()),o(`math`,`sigma`,[`latex`,`formula`,`equation`,`katex`,`$$`],(e,t)=>e.chain().focus().deleteRange(t).insertBlockMath({latex:`E = mc^2`}).run()),o(`mathInline`,`sigma`,[`latex`,`formula`,`equation`,`$`],(e,t)=>e.chain().focus().deleteRange(t).insertInlineMath({latex:`x^2`}).run()),o(`mermaid`,`diagram`,[`diagram`,`flowchart`,`chart`,`sequence`,`graph`],(e,t)=>e.chain().focus().deleteRange(t).insertMermaid().run()),o(`embed`,`video`,[`video`,`youtube`,`vimeo`,`figma`,`loom`,`iframe`,`map`],(t,r)=>{t.chain().focus().deleteRange(r).run(),tH(t,e,a,n)}),o(`linkCard`,`link`,[`bookmark`,`preview`,`card`,`url`,`web`],(t,r)=>{t.chain().focus().deleteRange(r).run(),nH(t,e,a,n)})],c=e=>{let t=new Date;return tV(new Date(t.getFullYear(),t.getMonth(),t.getDate()+e))};if(s.push(o(`today`,`calendar`,[`date`,`day`],(e,t)=>dV(e,t,{date:c(0),remind:!1})),o(`tomorrow`,`calendar`,[`date`,`day`],(e,t)=>dV(e,t,{date:c(1),remind:!1})),o(`yesterday`,`calendar`,[`date`,`day`],(e,t)=>dV(e,t,{date:c(-1),remind:!1})),o(`now`,`clock`,[`time`,`date`,`timestamp`],(t,n)=>{dV(t,n,{date:c(0),remind:!1});let r=new Intl.DateTimeFormat(e.locale,{hour:`numeric`,minute:`2-digit`}).format(new Date);t.chain().focus().insertContent(`${r} `).run()})),r&&(s.push(o(`pageLink`,`link`,[`page`,`link`,`[[`,`wiki`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`[[`).run())),s.push(o(`syncedPage`,`copy`,[`embed`,`transclude`,`include`,`mirror`,`![[`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`![[`).run())),r.create&&s.push(o(`newPage`,`page-plus`,[`page`,`doc`,`subpage`,`create`],(e,t)=>{e.chain().focus().deleteRange(t).run(),NV(e,r,``).catch(n)}))),t?.upload){let e=e=>(r,i)=>{r.chain().focus().deleteRange(i).run(),WJ(e).then(e=>cH(r,t,e).catch(n))};s.push(o(`image`,`image`,[`picture`,`photo`,`img`],e(`image/*`)),o(`file`,`paperclip`,[`attachment`,`upload`,`pdf`],e(``)),o(`drawio`,`diagram`,[`diagram`,`diagrams.net`,`draw`,`chart`,`uml`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`drawio`).run())),i&&s.push(o(`excalidraw`,`pencil`,[`drawing`,`sketch`,`whiteboard`,`draw`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`excalidraw`).run()))}return s}function KJ(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e=>e.label.toLowerCase().includes(n)||e.id.startsWith(n)||e.keywords.some(e=>e.toLowerCase().startsWith(n));return e.flatMap(e=>{let t=e.children?.filter(r)??[];return t.length?t:r(e)?[e]:[]})}var qJ=Tp.create({name:`slashMenu`,addOptions(){return{commands:[],labels:void 0}},addProseMirrorPlugins(){return[OV({editor:this.editor,pluginKey:new Un(`slashMenu`),char:`/`,allowSpaces:!1,startOfLine:!1,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:({query:e})=>KJ(this.options.commands,e),render:Bj({label:this.options.labels.slashMenu,empty:this.options.labels.noMatches,showQuery:!0,toItem:e=>({label:e.label,description:e.description,icon:e.icon}),children:e=>e.children,pick:(e,t)=>t.run(e.editor,e.range)})})]}});function JJ(e,t){let n=!0,r=e.firstChild?.childCount??0;return e.forEach(e=>{t===`column`&&e.childCount!==r&&(n=!1),e.forEach(e=>{((t===`row`?e.attrs.rowspan:e.attrs.colspan)??1)>1&&(n=!1)})}),n}function YJ(e,t,n){let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}var XJ=e=>{let t=[];return e.forEach(e=>t.push(e)),t};function ZJ(e,t,n,r,i,a=0){let o=e.doc.nodeAt(t);if(!o||o.type.name!==`table`||!JJ(o,n))return null;let c=XJ(o),l=n===`row`?c.length:c[0]?.childCount??0;if(r===i||r<0||i<0||r>=l||i>=l)return null;let u=n===`row`?YJ(c,r,i):c.map(e=>e.copy(s.fromArray(YJ(XJ(e),r,i)))),d=e.tr.replaceWith(t,t+o.nodeSize,o.copy(s.fromArray(u))),[f,p]=n===`row`?[i,0]:[Math.min(a,u.length-1),i],m=t+1;for(let e=0;e0;e--)if(n.node(e).type.name===`table`)return{tablePos:n.before(e),row:n.index(e),column:e+1<=n.depth?n.index(e+1):0};return null}var $J=Tp.create({name:`tableMove`,addOptions(){return{labels:null}},addCommands(){let e=e=>t=>({state:n,dispatch:r})=>{let i=QJ(n,n.selection.from);if(!i)return!1;let a=e===`row`?i.row:i.column,o=ZJ(n,i.tablePos,e,a,a+t,i.row);return o?(r?.(o),!0):!1};return{moveTableRow:e(`row`),moveTableColumn:e(`column`)}},addKeyboardShortcuts(){return{"Mod-Alt-ArrowUp":()=>this.editor.commands.moveTableRow(-1),"Mod-Alt-ArrowDown":()=>this.editor.commands.moveTableRow(1),"Mod-Alt-ArrowLeft":()=>this.editor.commands.moveTableColumn(-1),"Mod-Alt-ArrowRight":()=>this.editor.commands.moveTableColumn(1)}},addProseMirrorPlugins(){let e=this.options.labels?.table;return[new D({key:new Un(`tableMove`),view:t=>new eY(t,{row:e?.dragRow??`Drag to move the row`,column:e?.dragColumn??`Drag to move the column`})})]}}),eY=class{view;grips={row:document.createElement(`button`),column:document.createElement(`button`)};line=document.createElement(`div`);cell=null;drag=null;constructor(e,t){this.view=e;for(let e of[`row`,`column`]){let n=this.grips[e];n.type=`button`,n.className=`dw-table-grip dw-table-grip--${e}`,n.contentEditable=`false`,n.setAttribute(`aria-label`,t[e]),n.title=t[e],n.hidden=!0,n.tabIndex=-1,n.addEventListener(`pointerdown`,t=>this.start(t,e)),n.addEventListener(`mouseleave`,this.leave)}this.line.className=`dw-table-drop`,this.line.hidden=!0,e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.line.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.grips.row,this.grips.column,this.line)),e}hide=()=>{this.drag||(this.grips.row.hidden=!0,this.grips.column.hidden=!0,this.cell=null)};leave=e=>{let t=e.relatedTarget;t&&(this.grips.row.contains(t)||this.grips.column.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.drag)return;let t=e.target?.closest?.(`td, th`),n=this.host;if(!this.view.editable||!n||!(t instanceof HTMLTableCellElement)||!this.view.dom.contains(t))return this.hide();let r=this.locate(t),i=r&&this.view.state.doc.nodeAt(r.tablePos);if(!r||!i)return this.hide();this.cell=t;let a=n.getBoundingClientRect(),o=t.closest(`table`).getBoundingClientRect(),s=t.parentElement.getBoundingClientRect(),c=t.getBoundingClientRect(),l=i.childCount>1&&JJ(i,`row`),u=(i.firstChild?.childCount??0)>1&&JJ(i,`column`);Object.assign(this.grips.row.style,{top:`${s.top-a.top+s.height/2-11}px`,left:`${o.left-a.left-7}px`}),Object.assign(this.grips.column.style,{top:`${o.top-a.top-7}px`,left:`${c.left-a.left+c.width/2-11}px`}),this.grips.row.hidden=!l,this.grips.column.hidden=!u};locate(e){try{return QJ(this.view.state,this.view.posAtDOM(e,0))}catch{return null}}start(e,t){let n=this.cell;if(!n||e.button!==0)return;let r=this.locate(n),i=n.parentElement?.parentElement;if(!r||!i)return;e.preventDefault();let a=this.grips[t];a.setPointerCapture(e.pointerId);let o=[...i.children].filter(e=>e instanceof HTMLTableRowElement),s=t===`row`?r.row:r.column,c=t===`row`?o:[...o[0]?.children??[]],l=t===`row`?[o[s]]:o.map(e=>e.children[s]).filter(Boolean);for(let e of l)e.classList.add(`dw-table-dragging`);this.drag={axis:t,tablePos:r.tablePos,from:s,slots:c,dimmed:l,to:s,cursorRow:r.row},a.addEventListener(`pointermove`,this.dragMove),a.addEventListener(`pointerup`,this.drop),a.addEventListener(`pointercancel`,this.cancel)}dragMove=e=>{let t=this.drag,n=this.host;if(!t||!n)return;let r=t.axis===`row`,i=r?e.clientY:e.clientX,a=t.slots.length;for(let[e,n]of t.slots.entries()){let t=n.getBoundingClientRect();if(i<(r?t.top+t.height/2:t.left+t.width/2)){a=e;break}}t.to=a>t.from?a-1:a;let o=n.getBoundingClientRect(),s=t.slots[0].closest(`table`).getBoundingClientRect(),c=t.slots.at(-1).getBoundingClientRect(),l=t.slots[a]?.getBoundingClientRect(),u=r?l?.top??c.bottom:l?.left??c.right;Object.assign(this.line.style,r?{top:`${u-o.top-1}px`,left:`${s.left-o.left}px`,width:`${s.width}px`,height:`2px`}:{top:`${s.top-o.top}px`,left:`${u-o.left-1}px`,width:`2px`,height:`${s.height}px`}),this.line.hidden=t.to===t.from};drop=()=>{let e=this.drag;if(this.cancel(),!e||e.to===e.from)return;let t=ZJ(this.view.state,e.tablePos,e.axis,e.from,e.to,e.cursorRow);t&&this.view.dispatch(t),this.view.focus()};cancel=()=>{let e=this.drag;for(let t of e?.dimmed??[])t.classList.remove(`dw-table-dragging`);this.drag=null,this.line.hidden=!0;for(let e of Object.values(this.grips))e.removeEventListener(`pointermove`,this.dragMove),e.removeEventListener(`pointerup`,this.drop),e.removeEventListener(`pointercancel`,this.cancel);this.hide()};update(){this.cell&&!this.cell.isConnected&&this.hide()}destroy(){this.cancel();for(let e of Object.values(this.grips))e.remove();this.line.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}};function tY(e){let t=[];return e.descendants((e,n)=>e.type.name!==`heading`||(t.push({level:Number(e.attrs.level)||1,text:e.textContent.trim(),pos:n}),!1)),t}function nY(e,t){let n=e.view.nodeDOM(t);n instanceof HTMLElement&&n.scrollIntoView({behavior:`smooth`,block:`start`}),e.isEditable&&e.commands.setTextSelection(t+1)}var rY=Jp.create({name:`tableOfContents`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`nav[data-type='toc']`}]},renderHTML(){return[`nav`,{"data-type":`toc`}]},addCommands(){return{insertTableOfContents:()=>({commands:e})=>e.insertContent({type:this.name})}},addNodeView(){return({editor:e})=>{let t=this.options.labels.blocks,n=document.createElement(`nav`);n.className=`dw-toc`,n.setAttribute(`data-type`,`toc`),n.setAttribute(`aria-label`,t.toc),n.contentEditable=`false`;let r=document.createElement(`p`);r.className=`dw-toc__title`,r.textContent=t.toc;let i=document.createElement(`ol`);i.className=`dw-toc__list`,n.append(r,i);let a=``,o=()=>{let n=tY(e.state.doc),r=JSON.stringify(n.map(e=>[e.level,e.text]));if(r===a){i.querySelectorAll(`a`).forEach((e,t)=>e.dataset.pos=String(n[t]?.pos??0));return}if(a=r,i.replaceChildren(),!n.length){let e=document.createElement(`li`);e.className=`dw-toc__empty`,e.textContent=t.tocEmpty,i.append(e);return}let o=Math.min(...n.map(e=>e.level));for(let t of n){let n=document.createElement(`li`);n.style.paddingLeft=`${(t.level-o)*1}rem`;let r=document.createElement(`a`);r.href=`#`,r.textContent=t.text||`…`,r.dataset.pos=String(t.pos),r.addEventListener(`click`,t=>{t.preventDefault(),nY(e,Number(r.dataset.pos))}),n.append(r),i.append(n)}};return o(),e.on(`update`,o),{dom:n,update:e=>e.type.name===`tableOfContents`,ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`),destroy:()=>e.off(`update`,o)}}}}),iY=(e,t)=>{let n=t.view.domAtPos(e).node,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return r?r.offsetParent!==null:!1},aY=(e,t,n)=>{for(let r=e.depth;r>0;--r){let i=e.node(r),a=t(i),o=iY(e.start(r),n);if(a&&o)return{pos:r>0?e.before(r):0,start:e.start(r),depth:r,node:i}}},oY=(e,t)=>{let{state:n,view:r,extensionManager:i}=e,{schema:a,selection:o}=n,{empty:s,$anchor:c}=o,l=!!i.extensions.find(e=>e.name===`gapCursor`);if(!s||c.parent.type!==a.nodes.detailsSummary||!l||t===`right`&&c.parentOffset!==c.parent.nodeSize-2)return!1;let u=yu(e=>e.type===a.nodes.details)(o);if(!u)return!1;let d=gu(u.node,e=>e.type===a.nodes.detailsContent);if(!d.length||iY(u.start+d[0].pos+1,e))return!1;let f=n.doc.resolve(u.pos+u.node.nodeSize),p=Iw.findFrom(f,1,!1);if(!p)return!1;let{tr:m}=n,h=new Iw(p);return m.setSelection(h),m.scrollIntoView(),r.dispatch(m),!0},sY=Jp.create({name:`details`,content:`detailsSummary detailsContent`,group:`block`,defining:!0,isolating:!0,allowGapCursor:!1,addOptions(){return{persist:!1,openClassName:`is-open`,HTMLAttributes:{},renderToggleButton:({element:e,isOpen:t})=>{e.setAttribute(`aria-label`,t?`Collapse details content`:`Expand details content`)}}},addAttributes(){return this.options.persist?{open:{default:!1,parseHTML:e=>e.hasAttribute(`open`),renderHTML:({open:e})=>e?{open:``}:{}}}:[]},parseHTML(){return[{tag:`details`}]},renderHTML({HTMLAttributes:e}){return[`details`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`details`,content:`block`}),addNodeView(){return({editor:e,getPos:t,node:n,HTMLAttributes:r})=>{let i=document.createElement(`div`),a=A(this.options.HTMLAttributes,r,{"data-type":this.name});Object.entries(a).forEach(([e,t])=>i.setAttribute(e,t));let o=document.createElement(`button`);o.type=`button`;let s=e=>{this.options.renderToggleButton({element:o,...e})};i.append(o);let c=document.createElement(`div`);i.append(c);let l=e=>{let{setToValue:t,node:r=n}=e||{};if(t!==void 0){if(t){if(i.classList.contains(this.options.openClassName))return;i.classList.add(this.options.openClassName)}else{if(!i.classList.contains(this.options.openClassName))return;i.classList.remove(this.options.openClassName)}}else i.classList.toggle(this.options.openClassName);let a=i.classList.contains(this.options.openClassName);s({isOpen:a,node:r});let o=new Event(`toggleDetailsContent`);c.querySelector(`:scope > div[data-type="detailsContent"]`)?.dispatchEvent(o)};return s({isOpen:!!n.attrs.open,node:n}),n.attrs.open&&setTimeout(()=>l()),o.addEventListener(`click`,()=>{if(l(),!this.options.persist)e.commands.focus(void 0,{scrollIntoView:!1});else if(e.isEditable&&typeof t==`function`){let{from:n,to:r}=e.state.selection;e.chain().command(({tr:e})=>{let n=t();if(typeof n!=`number`)return!1;let r=e.doc.nodeAt(n);return r?.type===this.type&&(e.setNodeMarkup(n,void 0,{open:!r.attrs.open}),!0)}).setTextSelection({from:n,to:r}).focus(void 0,{scrollIntoView:!1}).run()}}),{dom:i,contentDOM:c,ignoreMutation(e){if(e.type===`selection`)return!1;let t=e.target,n=i.contains(t);return o.contains(t)||!n||i===t},update:e=>e.type===this.type&&(e.attrs.open===void 0?s({isOpen:i.classList.contains(this.options.openClassName),node:e}):l({setToValue:e.attrs.open,node:e}),!0)}}},addCommands(){return{setDetails:()=>({state:e,chain:t})=>{let{schema:n,selection:r}=e,{$from:i,$to:a}=r,o=i.blockRange(a);if(!o)return!1;let s=e.doc.slice(o.start,o.end);if(!n.nodes.detailsContent.contentMatch.matchFragment(s.content))return!1;let c=s.toJSON()?.content||[];return t().insertContentAt({from:o.start,to:o.end},{type:this.name,content:[{type:`detailsSummary`},{type:`detailsContent`,content:c}]}).setTextSelection(o.start+2).run()},unsetDetails:()=>({state:e,chain:t})=>{let{selection:n,schema:r}=e,i=yu(e=>e.type===this.type)(n);if(!i)return!1;let a=gu(i.node,e=>e.type===r.nodes.detailsSummary),o=gu(i.node,e=>e.type===r.nodes.detailsContent);if(!a.length||!o.length)return!1;let s=a[0],c=o[0],l=i.pos,u=e.doc.resolve(l),d={from:l,to:l+i.node.nodeSize},f=c.node.content.toJSON()||[],p=[u.parent.type.contentMatch.defaultType?.create(null,s.node.content).toJSON(),...f];return t().insertContentAt(d,p).setTextSelection(l+1).run()}}},addKeyboardShortcuts(){return{Backspace:()=>{let{schema:e,selection:t}=this.editor.state,{empty:n,$anchor:r}=t;return!n||r.parent.type!==e.nodes.detailsSummary?!1:r.parentOffset===0?this.editor.commands.unsetDetails():this.editor.commands.command(({tr:e})=>{let t=r.pos-1,n=r.pos;return e.delete(t,n),!0})},Enter:({editor:e})=>{let{state:t,view:n}=e,{schema:r,selection:i}=t,{$head:a}=i;if(a.parent.type!==r.nodes.detailsSummary)return!1;let o=iY(a.after()+1,e),s=o?t.doc.nodeAt(a.after()):a.node(-2);if(!s)return!1;let c=o?0:a.indexAfter(-1),l=Ll(s.contentMatchAt(c));if(!l||!s.canReplaceWith(c,c,l))return!1;let u=l.createAndFill();if(!u)return!1;let d=o?a.after()+1:a.after(-1),f=t.tr.replaceWith(d,d,u),p=f.doc.resolve(d),m=w.near(p,1);return f.setSelection(m),f.scrollIntoView(),n.dispatch(f),!0},ArrowRight:({editor:e})=>oY(e,`right`),ArrowDown:({editor:e})=>oY(e,`down`)}},addProseMirrorPlugins(){return[new D({key:new Un(`detailsSelection`),appendTransaction:(e,t,n)=>{let{editor:r,type:i}=this;if(r.view.composing||!e.some(e=>e.selectionSet)||!t.selection.empty||!n.selection.empty||!sd(n,i.name))return;let{$from:a}=n.selection;if(iY(a.pos,r))return;let o=aY(a,e=>e.type===i,r);if(!o)return;let s=gu(o.node,e=>e.type===n.schema.nodes.detailsSummary);if(!s.length)return;let c=s[0],l=(t.selection.from{let t=document.createElement(`div`),n=A(this.options.HTMLAttributes,e,{"data-type":this.name,hidden:`hidden`});return Object.entries(n).forEach(([e,n])=>t.setAttribute(e,n)),t.addEventListener(`toggleDetailsContent`,()=>{t.toggleAttribute(`hidden`)}),{dom:t,contentDOM:t,ignoreMutation(e){return e.type===`selection`?!1:!t.contains(e.target)||t===e.target},update:e=>e.type===this.type}}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let{state:t,view:n}=e,{selection:r}=t,{$from:i,empty:a}=r,o=yu(e=>e.type===this.type)(r);if(!a||!o||!o.node.childCount)return!1;let s=i.index(o.depth),{childCount:c}=o.node;if(c!==s+1)return!1;let l=o.node.type.contentMatch.defaultType?.createAndFill();if(!l)return!1;let u=t.doc.resolve(o.pos+1),d=c-1,f=o.node.child(d),p=u.posAtIndex(d,o.depth);if(!f.eq(l))return!1;let m=i.node(-3);if(!m)return!1;let h=i.indexAfter(-3),g=Ll(m.contentMatchAt(h));if(!g||!m.canReplaceWith(h,h,g))return!1;let _=g.createAndFill();if(!_)return!1;let{tr:v}=t,y=i.after(-2);v.replaceWith(y,y,_);let b=v.doc.resolve(y),x=w.near(b,1);v.setSelection(x);let S=p,C=p+f.nodeSize;return v.delete(S,C),v.scrollIntoView(),n.dispatch(v),!0}}},...Xf({nodeName:`detailsContent`})}),lY=Jp.create({name:`detailsSummary`,content:`text*`,defining:!0,selectable:!1,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`summary`}]},renderHTML({HTMLAttributes:e}){return[`summary`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`detailsSummary`,content:`inline`})});function uY(e){return[sY.configure({persist:!1,HTMLAttributes:{class:`dw-toggle`},renderToggleButton:({element:t,isOpen:n})=>{t.setAttribute(`aria-label`,n?e.blocks.collapse:e.blocks.expand),t.setAttribute(`aria-expanded`,String(n))}}),lY,cY]}function dY(e={}){let t=e.labels??AR,n=null,r=Tp.create({name:`editorRef`,onCreate(){n=this.editor}}),i={host:e.files,labels:t,drawioUrl:e.drawioUrl,loadExcalidraw:e.loadExcalidraw,onError:e.onError},a=[r,Kk.configure({heading:{levels:[1,2,3,4,5,6]},codeBlock:!1,link:{openOnClick:!1,autolink:!0},undoRedo:e.collab||e.syncedDoc||e.rowBody||e.rowFragmentReadOnly?!1:void 0}),fT.configure({placeholder:e.placeholder??`Type '/' for commands…`}),lH.configure({host:e.files}),dH.configure({host:e.files,loadPdf:e.loadPdf,labels:t}),Pj.configure({lineNumbers:e.codeLineNumbers??!1}),kP,OP,FP,IP,...EP(),...DP(),$J.configure({labels:t}),zP.configure({labels:t}),fH.configure({host:e.files,onError:e.onError}),LJ(t,e.mentions),lV.configure({labels:t,me:()=>e.mentions?.me,onOpen:e.onOpenDate}),qJ.configure({commands:GJ(t,e.files,e.onError,e.pages,!!e.loadExcalidraw,e.links),labels:t}),$B.configure({onSelect:e.onCommentSelect}),MJ(t,()=>n),UJ.configure({labels:t,load:e.loadMermaid}),rY.configure({labels:t}),KV.configure(i),qV.configure(i),PV.configure({host:e.pages,labels:t,onNavigate:e.onNavigate}),IV.configure({host:e.syncedPages,pages:e.pages,labels:t,onNavigate:e.onNavigate,nested:t=>dY({syncedDoc:t,files:e.files,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:``})}),...uY(t),iH.configure({labels:t}),aH.configure({labels:t}),tM.configure({labels:t,link:e.blockLink,onCopied:e.onBlockLinkCopied}),yH,WB.configure({labels:t,doc:e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc,readOnlyDoc:!!e.syncedDoc,undoScope:!e.rowBody,files:e.files,people:e.mentions,recordLink:e.blockLink,linkedPages:e.syncedPages,pages:e.pages,onNavigate:e.onNavigate,recordPage:e.recordPage,onLinkCopied:e.onBlockLinkCopied,me:()=>{let t=e.mentions?.me;return t?{id:t,name:e.collab?.user.name??``}:null},rowExtensions:n=>{let r=e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc;return dY({rowBody:n&&r&&!e.syncedDoc?{doc:r,fragment:n}:void 0,files:e.files,mentions:e.mentions,pages:e.pages,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadExcalidraw:e.loadExcalidraw,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:t.database.bodyPlaceholder,rowFragmentReadOnly:n&&e.syncedDoc?n:void 0})}})],o={trackedOrigins:[Wz]};return e.rowBody?a.push(Ow.configure({document:e.rowBody.doc,fragment:e.rowBody.fragment,yUndoOptions:o})):e.rowFragmentReadOnly?a.push(Ow.configure({fragment:e.rowFragmentReadOnly})):e.syncedDoc?a.push(Ow.configure({document:e.syncedDoc})):e.collab&&a.push(Ow.configure({document:e.collab.provider.doc,yUndoOptions:o}),Nw.configure({provider:e.collab.provider,user:e.collab.user,render:fY})),a}function fY(e){let t=typeof e.color==`string`&&/^#[0-9a-f]{3,8}$/i.test(e.color)?e.color:`#888`,n=document.createElement(`span`);n.classList.add(`collaboration-carets__caret`),n.style.borderColor=t;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.setAttribute(`aria-hidden`,`true`),r.style.backgroundColor=t,r.textContent=typeof e.name==`string`?e.name:``,n.append(r),n}function pY(e){let t=e??AR;return{...dF,...t.edgeless,colors:{...dF.colors,...t.colors}}}function mY(e){let t=e?.surface;return Array.isArray(t?.elements)?t.elements:[]}function hY(e,t,n){let r={...n,placeholder:n.placeholder??``},i=new Vp({element:e,editable:t.kind!==`json`&&t.editable,content:t.kind===`json`?t.content:void 0,extensions:t.kind===`page`?dY({...r,collab:{provider:t.provider,user:t.user}}):t.kind===`body`?dY({...r,rowBody:{doc:t.doc,fragment:t.fragment}}):dY(r),editorProps:{attributes:{class:`dw-prose`}}});return{destroy:()=>i.destroy(),focus:()=>i.commands.focus(`end`),setEditable:e=>i.setEditable(e&&t.kind!==`json`)}}function gY(e,t){let n=!!t.provider,r,i=null;if(t.provider)r=t.provider.doc;else{i=new bv,r=i;let e=t.content;i.transact(()=>JL(i.getXmlFragment(`default`),e?.content??[]));let n=mY(e);if(n.length){let e=new tR(i,{undo:!1});e.load(n),e.destroy()}}let a={...t};delete a.provider,delete a.content;let o=new yR(e,{doc:r,editable:n&&t.editable,notes:{mount:(e,r)=>{let i=n?r.page?{kind:`page`,provider:t.provider,user:t.user??{name:`?`,color:`#888`},editable:r.editable}:{kind:`body`,doc:r.doc,fragment:r.fragment,editable:r.editable}:{kind:`json`,content:r.page&&t.content?t.content:{type:`doc`,content:qL(r.fragment)}};return t.mountNote?t.mountNote(e,i):hY(e,i,a)}},labels:pY(t.labels),files:t.files,links:t.links,embedSource:ZV,styles:t.styles,onStyles:t.onStyles,viewKey:t.viewKey,pageTitle:t.pageTitle,undo:n,onError:t.onError,onComment:t.onComment,onCommentSelect:t.onCommentSelect});return{view:o,setEditable:e=>o.setEditable(n&&e),destroy:()=>{o.destroy(),i?.destroy()}}}function _Y(e,t,n){let r=Jj(t),i=FB(t);if(!r&&!i)return()=>{};let a=()=>i?LB(e,i.database,i.row):eM(e,r),o=!1,s,c=()=>{clearTimeout(s),s=setTimeout(()=>{o||e.isDestroyed||!a()||(o=!0,l(),n?.())},50)},l=()=>{e.off(`transaction`,c),clearTimeout(u)},u=setTimeout(l,5e3);return e.on(`transaction`,c),c(),()=>{l(),clearTimeout(s)}}var vY=3e4,yY=class extends um{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Mh();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&bY(this,t,`timeout`)},dm(vY/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,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:Mh()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Qh(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},bY=(e,t,n)=>{let r=[];for(let n=0;n0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},xY=(e,t,n=e.states)=>{let r=t.length,i=Mm();j(i,r);for(let a=0;a{let r=fh(t),i=Mh(),a=[],o=[],s=[],c=[],l=M(r);for(let t=0;t0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},CY=(e,t)=>{j(e,0),Wm(e,Gv(t))},wY=(e,t,n)=>{j(e,1),Wm(e,zv(t,n))},TY=(e,t,n)=>wY(t,n,hh(e)),EY=(e,t,n,r)=>{try{Iv(t,hh(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},DY=(e,t)=>{j(e,2),Wm(e,t)},OY=EY,kY=(e,t,n,r,i)=>{let a=M(e);switch(a){case 0:TY(e,t,n);break;case 1:EY(e,n,r,i);break;case 2:OY(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},AY=0,jY=1,MY=4401,NY=4404,PY=4409,FY=class{opts;doc=new bv;awareness=new yY(this.doc);status=`connecting`;synced=!1;ws=null;retries=0;retryTimer;destroyed=!1;listeners=new Set;constructor(e){this.opts=e,this.doc.on(`update`,this.onDocUpdate),this.awareness.on(`update`,this.onAwarenessUpdate),e.readOnly&&this.awareness.setLocalState(null),window.addEventListener(`beforeunload`,this.onUnload),this.connect()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}destroy(){this.destroyed||(this.destroyed=!0,this.listeners.clear(),clearTimeout(this.retryTimer),window.removeEventListener(`beforeunload`,this.onUnload),bY(this.awareness,[this.doc.clientID],`local`),this.doc.off(`update`,this.onDocUpdate),this.awareness.off(`update`,this.onAwarenessUpdate),this.ws?.close(),this.awareness.destroy(),this.doc.destroy(),this.listeners.clear())}set(e,t=this.synced){(e!==this.status||t!==this.synced)&&(this.status=e,this.synced=t,this.listeners.forEach(e=>e()))}connect(){let e=new WebSocket(`${this.opts.url}?page=${encodeURIComponent(this.opts.page)}`);e.binaryType=`arraybuffer`,this.ws=e,e.onopen=()=>{e.send(this.opts.token()??``);let t=Mm();j(t,AY),CY(t,this.doc),e.send(Fm(t)),this.awareness.getLocalState()!==null&&this.sendAwareness([this.doc.clientID])},e.onmessage=e=>this.onMessage(new Uint8Array(e.data)),e.onclose=t=>{if(this.ws!==e)return;this.ws=null;let n=[...this.awareness.getStates().keys()].filter(e=>e!==this.doc.clientID);bY(this.awareness,n,this),this.destroyed||(t.code===MY||t.code===NY?this.set(`denied`,!1):t.code===PY?this.set(`changed`):(this.set(`offline`),this.retryTimer=setTimeout(()=>this.connect(),Math.min(1e3*2**this.retries++,3e4))))}}onMessage(e){let t=fh(e),n=M(t);if(n===AY){let e=Mm();j(e,AY);let n=kY(t,e,this.doc,this);Pm(e)>1&&!this.opts.readOnly&&this.ws?.send(Fm(e)),n===1&&(this.retries=0,this.set(`connected`,!0))}else n===jY&&SY(this.awareness,hh(t),this)}onDocUpdate=(e,t)=>{if(t===this||this.opts.readOnly||this.ws?.readyState!==WebSocket.OPEN)return;let n=Mm();j(n,AY),DY(n,e),this.ws.send(Fm(n))};onAwarenessUpdate=({added:e,updated:t,removed:n},r)=>{r===this||this.opts.readOnly||this.sendAwareness([...e,...t,...n])};sendAwareness(e){if(this.ws?.readyState!==WebSocket.OPEN)return;let t=Mm();j(t,jY),Wm(t,xY(this.awareness,e)),this.ws.send(Fm(t))}onUnload=()=>bY(this.awareness,[this.doc.clientID],`unload`)},IY=`.dw-db-peek, .dw-db-pop, .dw-block-menu`,LY={bold:e=>e.chain().focus().toggleBold().run(),italic:e=>e.chain().focus().toggleItalic().run(),strike:e=>e.chain().focus().toggleStrike().run(),code:e=>e.chain().focus().toggleCode().run(),heading1:e=>e.chain().focus().toggleHeading({level:1}).run(),heading2:e=>e.chain().focus().toggleHeading({level:2}).run(),heading3:e=>e.chain().focus().toggleHeading({level:3}).run(),bulletList:e=>e.chain().focus().toggleBulletList().run(),orderedList:e=>e.chain().focus().toggleOrderedList().run(),blockquote:e=>e.chain().focus().toggleBlockquote().run(),codeBlock:e=>e.chain().focus().toggleCodeBlock().run(),underline:e=>e.chain().focus().toggleUnderline().run(),taskList:e=>e.chain().focus().toggleTaskList().run(),callout:e=>e.isActive(`callout`)?e.chain().focus().unsetCallout().run():e.chain().focus().setCallout().run(),table:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),undo:e=>e.chain().focus().undo().run(),redo:e=>e.chain().focus().redo().run()},RY=[[`bold`,e=>e.isActive(`bold`)],[`italic`,e=>e.isActive(`italic`)],[`strike`,e=>e.isActive(`strike`)],[`code`,e=>e.isActive(`code`)],[`heading1`,e=>e.isActive(`heading`,{level:1})],[`heading2`,e=>e.isActive(`heading`,{level:2})],[`heading3`,e=>e.isActive(`heading`,{level:3})],[`bulletList`,e=>e.isActive(`bulletList`)],[`orderedList`,e=>e.isActive(`orderedList`)],[`blockquote`,e=>e.isActive(`blockquote`)],[`codeBlock`,e=>e.isActive(`codeBlock`)],[`underline`,e=>e.isActive(`underline`)],[`taskList`,e=>e.isActive(`taskList`)],[`callout`,e=>e.isActive(`callout`)],[`table`,e=>e.isActive(`table`)]],zY=class{el;send;editor;provider=null;lastState=``;editable=!0;overlay=!1;overlays=new MutationObserver(()=>this.reportOverlay());inner=null;onFocusIn=e=>this.track(e.target);canvas=null;canvasEl=null;mode=`page`;lastContent=null;title=``;constructor(e,t){this.el=e,this.send=t,this.editor=this.create({}),this.overlays.observe(document.body,{childList:!0}),document.addEventListener(`focusin`,this.onFocusIn),t({type:`ready`,version:3})}receive(e){try{let t=typeof e==`string`?JSON.parse(e):e;this.handle(t)}catch(e){this.send({type:`error`,message:e instanceof Error?e.message:String(e)})}}get content(){return this.editor.getJSON()}destroy(){this.overlays.disconnect(),document.removeEventListener(`focusin`,this.onFocusIn),this.setInner(null),this.closeCanvas(),this.editor.destroy(),this.provider?.destroy()}handle(e){switch(e.type){case`hello`:this.send({type:`ready`,version:3}),this.lastState=``,this.reportState();return;case`setContent`:this.lastContent=e.content,this.editor.commands.setContent(e.content??``,{emitUpdate:!1}),this.reportState(),this.mode===`edgeless`&&!this.provider&&this.openCanvas();return;case`setEditable`:this.editable=e.editable,this.editor.setEditable(e.editable),this.canvas?.setEditable(e.editable);return;case`setTheme`:document.documentElement.classList.toggle(`dark`,e.dark);return;case`setLayout`:{let t=document.documentElement.classList;t.toggle(`dw-full-width`,e.fullWidth),t.toggle(`dw-font-serif`,e.font===`serif`),t.toggle(`dw-font-mono`,e.font===`mono`);return}case`command`:{let t=LY[e.command];if(!t)throw Error(`unknown command ${e.command}`);t(this.target);return}case`focus`:this.editor.commands.focus();return;case`blur`:this.editor.commands.blur();return;case`connect`:this.connect(e);return;case`follow`:_Y(this.editor,e.hash);return;case`setMode`:this.mode=e.mode===`edgeless`?`edgeless`:`page`,typeof e.title==`string`&&(this.title=e.title),this.mode===`edgeless`?this.openCanvas():this.closeCanvas();return;case`dismiss`:[...document.querySelectorAll(IY)].at(-1)?.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,cancelable:!0}));return;default:throw Error(`unknown message ${e.type}`)}}connect(e){this.provider?.destroy();let t=new FY({url:e.url,page:e.page,token:()=>e.token});t.onChange(()=>this.send({type:`collab`,status:t.status})),this.provider=t,this.editor.destroy(),this.editor=this.create({collab:{provider:t,user:e.user}}),this.mode===`edgeless`&&this.openCanvas()}openCanvas(){this.closeCanvas();let e=document.createElement(`div`);e.className=`dw-bridge-canvas`,document.body.append(e),this.canvasEl=e,this.el.hidden=!0,this.canvas=gY(e,{provider:this.provider??void 0,content:this.provider?void 0:this.lastContent??this.editor.getJSON(),editable:this.editable&&!!this.provider,pageTitle:()=>this.title,onNavigate:e=>this.send({type:`navigate`,path:e}),onError:e=>this.send({type:`error`,message:e instanceof Error?e.message:String(e)})})}closeCanvas(){this.canvas?.destroy(),this.canvas=null,this.canvasEl?.remove(),this.canvasEl=null,this.el.hidden=!1}create(e){return this.el.replaceChildren(),new Vp({element:this.el,editable:this.editable,extensions:dY({...e,onNavigate:e=>this.send({type:`navigate`,path:e})}),editorProps:{attributes:{class:`dw-prose`}},onUpdate:({editor:e})=>this.send({type:`change`,content:e.getJSON()}),onSelectionUpdate:()=>this.reportState(),onTransaction:()=>this.reportState(),onFocus:()=>this.reportState(),onBlur:()=>this.reportState()})}get target(){return this.inner&&!this.inner.isDestroyed?this.inner:this.editor}track(e){let t=(e instanceof Element?e.closest(`.ProseMirror`):null)?.editor;t&&(this.setInner(t===this.editor?null:t),this.reportState())}innerChanged=()=>this.reportState();innerGone=()=>{this.setInner(null),this.reportState()};setInner(e){if(e!==this.inner){if(this.inner){for(let e of[`selectionUpdate`,`transaction`,`focus`,`blur`])this.inner.off(e,this.innerChanged);this.inner.off(`destroy`,this.innerGone)}if(this.inner=e,e){for(let t of[`selectionUpdate`,`transaction`,`focus`,`blur`])e.on(t,this.innerChanged);e.on(`destroy`,this.innerGone)}}}reportOverlay(){let e=document.querySelector(IY)!==null;e!==this.overlay&&(this.overlay=e,this.send({type:`overlay`,open:e}))}reportState(){let e=this.target;if(e.isDestroyed)return;let t={active:RY.filter(([,t])=>t(e)).map(([e])=>e),canUndo:e.can().undo(),canRedo:e.can().redo(),focused:e.isFocused},n=JSON.stringify(t);n!==this.lastState&&(this.lastState=n,this.send({type:`state`,state:t}))}};function BY(e){let t=JSON.stringify(e);window.DocwellNative?window.DocwellNative.postMessage(t):(window.parent.postMessage(t,`*`),console.debug(`[docwell bridge]`,e))}var VY=new zY(document.getElementById(`editor`),BY);window.docwell={receive:e=>VY.receive(e)}; +?)[ \r ]*`,aJ=`[̀-ͯ]`,oJ=RegExp(aJ+`+$`),sJ=`(`+eJ+`+)|`+(iJ+`|`)+`([!-\\[\\]-‧‪-퟿豈-￿]`+(aJ+`*`)+`|[\ud800-\udbff][\udc00-\udfff]`+(aJ+`*`)+`|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5`+(`|`+rJ)+(`|`+nJ+`)`),cJ=class{constructor(e,t){this.input=void 0,this.settings=void 0,this.tokenRegex=void 0,this.catcodes=void 0,this.input=e,this.settings=t,this.tokenRegex=new RegExp(sJ,`g`),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){var e=this.input,t=this.tokenRegex.lastIndex;if(t===e.length)return new cq(`EOF`,new sq(this,t,t));var n=this.tokenRegex.exec(e);if(n===null||n.index!==t)throw new L(`Unexpected character: '`+e[t]+`'`,new cq(e[t],new sq(this,t,t+1)));var r=n[6]||n[3]||(n[2]?`\\ `:` `);if(this.catcodes[r]===14){var i=e.indexOf(` +`,this.tokenRegex.lastIndex);return i===-1?(this.tokenRegex.lastIndex=e.length,this.settings.reportNonstrict(`commentAtEnd`,`% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode (e.g. $)`)):this.tokenRegex.lastIndex=i+1,this.lex()}return new cq(r,new sq(this,t,this.tokenRegex.lastIndex))}},lJ=class{constructor(e,t){e===void 0&&(e={}),t===void 0&&(t={}),this.current=void 0,this.builtins=void 0,this.undefStack=void 0,this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new L(`Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug`);var e=this.undefStack.pop();for(var t of Object.keys(e))e[t]===void 0?delete this.current[t]:this.current[t]=e[t]}endGroups(){for(;this.undefStack.length>0;)this.endGroup()}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){if(Object.prototype.hasOwnProperty.call(this.current,e))return this.current[e];if(Object.prototype.hasOwnProperty.call(this.builtins,e))return this.builtins[e]}set(e,t,n){if(n===void 0&&(n=!1),n){for(var r=0;r0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{var i=this.undefStack[this.undefStack.length-1];i&&!Object.prototype.hasOwnProperty.call(i,e)&&(i[e]=Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:void 0)}t==null?delete this.current[e]:this.current[e]=t}},uJ=oq;$(`\\noexpand`,function(e){var t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}}),$(`\\expandafter`,function(e){var t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}}),$(`\\@firstoftwo`,function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}}),$(`\\@secondoftwo`,function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}}),$(`\\@ifnextchar`,function(e){var t=e.consumeArgs(3);e.consumeSpaces();var n=e.future();return t[0].length===1&&t[0][0].text===n.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}}),$(`\\@ifstar`,`\\@ifnextchar *{\\@firstoftwo{#1}}`),$(`\\TextOrMath`,function(e){var t=e.consumeArgs(2);return e.mode===`text`?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});var dJ={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};$(`\\char`,function(e){var t=e.popToken(),n,r=0;if(t.text===`'`)n=8,t=e.popToken();else if(t.text===`"`)n=16,t=e.popToken();else if(t.text==="`"){if(t=e.popToken(),t.text[0]===`\\`)r=t.text.charCodeAt(1);else if(t.text===`EOF`)throw new L("\\char` missing argument");else r=t.text.charCodeAt(0)}else n=10;if(n){if(r=dJ[t.text],r==null||r>=n)throw new L(`Invalid base-`+n+` digit `+t.text);for(var i;(i=dJ[e.future().text])!=null&&i{var i=e.consumeArg().tokens;if(i.length!==1)throw new L(`\\newcommand's first argument must be a macro name`);var a=i[0].text,o=e.isDefined(a);if(o&&!t)throw new L(`\\newcommand{`+a+`} attempting to redefine `+(a+`; use \\renewcommand`));if(!o&&!n)throw new L(`\\renewcommand{`+a+`} when command `+a+` does not yet exist; use \\newcommand`);var s=0;if(i=e.consumeArg().tokens,i.length===1&&i[0].text===`[`){for(var c=``,l=e.expandNextToken();l.text!==`]`&&l.text!==`EOF`;)c+=l.text,l=e.expandNextToken();if(!c.match(/^\s*[0-9]+\s*$/))throw new L(`Invalid number of arguments: `+c);s=parseInt(c),i=e.consumeArg().tokens}return o&&r||e.macros.set(a,{tokens:i,numArgs:s}),``};$(`\\newcommand`,e=>fJ(e,!1,!0,!1)),$(`\\renewcommand`,e=>fJ(e,!0,!1,!1)),$(`\\providecommand`,e=>fJ(e,!0,!0,!0)),$(`\\message`,e=>{var t=e.consumeArgs(1)[0];return console.log(t.reverse().map(e=>e.text).join(``)),``}),$(`\\errmessage`,e=>{var t=e.consumeArgs(1)[0];return console.error(t.reverse().map(e=>e.text).join(``)),``}),$(`\\show`,e=>{var t=e.popToken(),n=t.text;return console.log(t,e.macros.get(n),$q[n],qU.math[n],qU.text[n]),``}),$(`\\bgroup`,`{`),$(`\\egroup`,`}`),$(`~`,`\\nobreakspace`),$(`\\lq`,"`"),$(`\\rq`,`'`),$(`\\aa`,`\\r a`),$(`\\AA`,`\\r A`),$(`\\textcopyright`,"\\html@mathml{\\textcircled{c}}{\\char`©}"),$(`\\copyright`,`\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}`),$(`\\textregistered`,"\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"),$(`ℬ`,`\\mathscr{B}`),$(`ℰ`,`\\mathscr{E}`),$(`ℱ`,`\\mathscr{F}`),$(`ℋ`,`\\mathscr{H}`),$(`ℐ`,`\\mathscr{I}`),$(`ℒ`,`\\mathscr{L}`),$(`ℳ`,`\\mathscr{M}`),$(`ℛ`,`\\mathscr{R}`),$(`ℭ`,`\\mathfrak{C}`),$(`ℌ`,`\\mathfrak{H}`),$(`ℨ`,`\\mathfrak{Z}`),$(`\\Bbbk`,`\\Bbb{k}`),$(`\\llap`,`\\mathllap{\\textrm{#1}}`),$(`\\rlap`,`\\mathrlap{\\textrm{#1}}`),$(`\\clap`,`\\mathclap{\\textrm{#1}}`),$(`\\mathstrut`,`\\vphantom{(}`),$(`\\underbar`,`\\underline{\\text{#1}}`),$(`\\not`,`\\html@mathml{\\mathrel{\\mathrlap\\@not}\\nobreak}{\\char"338}`),$(`\\neq`,"\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}"),$(`\\ne`,`\\neq`),$(`≠`,`\\neq`),$(`\\notin`,"\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}"),$(`∉`,`\\notin`),$(`≘`,"\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}"),$(`≙`,"\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`≘}}"),$(`≚`,"\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`≚}}"),$(`≛`,"\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}"),$(`≝`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}"),$(`≞`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}"),$(`≟`,"\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`≟}}"),$(`⟂`,`\\perp`),$(`‼`,`\\mathclose{!\\mkern-0.8mu!}`),$(`∌`,`\\notni`),$(`⌜`,`\\ulcorner`),$(`⌝`,`\\urcorner`),$(`⌞`,`\\llcorner`),$(`⌟`,`\\lrcorner`),$(`©`,`\\copyright`),$(`®`,`\\textregistered`),$(`\\ulcorner`,`\\html@mathml{\\@ulcorner}{\\mathop{\\char"231c}}`),$(`\\urcorner`,`\\html@mathml{\\@urcorner}{\\mathop{\\char"231d}}`),$(`\\llcorner`,`\\html@mathml{\\@llcorner}{\\mathop{\\char"231e}}`),$(`\\lrcorner`,`\\html@mathml{\\@lrcorner}{\\mathop{\\char"231f}}`),$(`\\vdots`,`{\\varvdots\\rule{0pt}{15pt}}`),$(`⋮`,`\\vdots`),$(`\\varGamma`,`\\mathit{\\Gamma}`),$(`\\varDelta`,`\\mathit{\\Delta}`),$(`\\varTheta`,`\\mathit{\\Theta}`),$(`\\varLambda`,`\\mathit{\\Lambda}`),$(`\\varXi`,`\\mathit{\\Xi}`),$(`\\varPi`,`\\mathit{\\Pi}`),$(`\\varSigma`,`\\mathit{\\Sigma}`),$(`\\varUpsilon`,`\\mathit{\\Upsilon}`),$(`\\varPhi`,`\\mathit{\\Phi}`),$(`\\varPsi`,`\\mathit{\\Psi}`),$(`\\varOmega`,`\\mathit{\\Omega}`),$(`\\substack`,`\\begin{subarray}{c}#1\\end{subarray}`),$(`\\colon`,`\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax`),$(`\\boxed`,`\\fbox{$\\displaystyle{#1}$}`),$(`\\iff`,`\\DOTSB\\;\\Longleftrightarrow\\;`),$(`\\implies`,`\\DOTSB\\;\\Longrightarrow\\;`),$(`\\impliedby`,`\\DOTSB\\;\\Longleftarrow\\;`),$(`\\dddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}`),$(`\\ddddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}`);var pJ={",":`\\dotsc`,"\\not":`\\dotsb`,"+":`\\dotsb`,"=":`\\dotsb`,"<":`\\dotsb`,">":`\\dotsb`,"-":`\\dotsb`,"*":`\\dotsb`,":":`\\dotsb`,"\\DOTSB":`\\dotsb`,"\\coprod":`\\dotsb`,"\\bigvee":`\\dotsb`,"\\bigwedge":`\\dotsb`,"\\biguplus":`\\dotsb`,"\\bigcap":`\\dotsb`,"\\bigcup":`\\dotsb`,"\\prod":`\\dotsb`,"\\sum":`\\dotsb`,"\\bigotimes":`\\dotsb`,"\\bigoplus":`\\dotsb`,"\\bigodot":`\\dotsb`,"\\bigsqcup":`\\dotsb`,"\\And":`\\dotsb`,"\\longrightarrow":`\\dotsb`,"\\Longrightarrow":`\\dotsb`,"\\longleftarrow":`\\dotsb`,"\\Longleftarrow":`\\dotsb`,"\\longleftrightarrow":`\\dotsb`,"\\Longleftrightarrow":`\\dotsb`,"\\mapsto":`\\dotsb`,"\\longmapsto":`\\dotsb`,"\\hookrightarrow":`\\dotsb`,"\\doteq":`\\dotsb`,"\\mathbin":`\\dotsb`,"\\mathrel":`\\dotsb`,"\\relbar":`\\dotsb`,"\\Relbar":`\\dotsb`,"\\xrightarrow":`\\dotsb`,"\\xleftarrow":`\\dotsb`,"\\DOTSI":`\\dotsi`,"\\int":`\\dotsi`,"\\oint":`\\dotsi`,"\\iint":`\\dotsi`,"\\iiint":`\\dotsi`,"\\iiiint":`\\dotsi`,"\\idotsint":`\\dotsi`,"\\DOTSX":`\\dotsx`},mJ=new Set([`bin`,`rel`]);$(`\\dots`,function(e){var t=`\\dotso`,n=e.expandAfterFuture().text;return n in pJ?t=pJ[n]:(n.slice(0,4)===`\\not`||n in qU.math&&mJ.has(qU.math[n].group))&&(t=`\\dotsb`),t});var hJ={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};$(`\\dotso`,function(e){return e.future().text in hJ?`\\ldots\\,`:`\\ldots`}),$(`\\dotsc`,function(e){var t=e.future().text;return t in hJ&&t!==`,`?`\\ldots\\,`:`\\ldots`}),$(`\\cdots`,function(e){return e.future().text in hJ?`\\@cdots\\,`:`\\@cdots`}),$(`\\dotsb`,`\\cdots`),$(`\\dotsm`,`\\cdots`),$(`\\dotsi`,`\\!\\cdots`),$(`\\dotsx`,`\\ldots\\,`),$(`\\DOTSI`,`\\relax`),$(`\\DOTSB`,`\\relax`),$(`\\DOTSX`,`\\relax`),$(`\\tmspace`,`\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax`),$(`\\,`,`\\tmspace+{3mu}{.1667em}`),$(`\\thinspace`,`\\,`),$(`\\>`,`\\mskip{4mu}`),$(`\\:`,`\\tmspace+{4mu}{.2222em}`),$(`\\medspace`,`\\:`),$(`\\;`,`\\tmspace+{5mu}{.2777em}`),$(`\\thickspace`,`\\;`),$(`\\!`,`\\tmspace-{3mu}{.1667em}`),$(`\\negthinspace`,`\\!`),$(`\\negmedspace`,`\\tmspace-{4mu}{.2222em}`),$(`\\negthickspace`,`\\tmspace-{5mu}{.277em}`),$(`\\enspace`,`\\kern.5em `),$(`\\enskip`,`\\hskip.5em\\relax`),$(`\\quad`,`\\hskip1em\\relax`),$(`\\qquad`,`\\hskip2em\\relax`),$(`\\tag`,`\\@ifstar\\tag@literal\\tag@paren`),$(`\\tag@paren`,`\\tag@literal{({#1})}`),$(`\\tag@literal`,e=>{if(e.macros.get(`\\df@tag`))throw new L(`Multiple \\tag`);return`\\gdef\\df@tag{\\text{#1}}`}),$(`\\bmod`,`\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}`),$(`\\pod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)`),$(`\\pmod`,`\\pod{{\\rm mod}\\mkern6mu#1}`),$(`\\mod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1`),$(`\\newline`,`\\\\\\relax`),$(`\\TeX`,`\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}`);var gJ=z(BU[`Main-Regular`][84][1]-.7*BU[`Main-Regular`][65][1]);$(`\\LaTeX`,`\\textrm{\\html@mathml{`+(`L\\kern-.36em\\raisebox{`+gJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{LaTeX}}`),$(`\\KaTeX`,`\\textrm{\\html@mathml{`+(`K\\kern-.17em\\raisebox{`+gJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{KaTeX}}`),$(`\\hspace`,`\\@ifstar\\@hspacer\\@hspace`),$(`\\@hspace`,`\\hskip #1\\relax`),$(`\\@hspacer`,`\\rule{0pt}{0pt}\\hskip #1\\relax`),$(`\\ordinarycolon`,`:`),$(`\\vcentcolon`,`\\mathrel{\\mathop\\ordinarycolon}`),$(`\\dblcolon`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}`),$(`\\coloneqq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}`),$(`\\Coloneqq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}`),$(`\\coloneq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}`),$(`\\Coloneq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}`),$(`\\eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}`),$(`\\Eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}`),$(`\\eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}`),$(`\\Eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}`),$(`\\colonapprox`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}`),$(`\\Colonapprox`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}`),$(`\\colonsim`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}`),$(`\\Colonsim`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}`),$(`∷`,`\\dblcolon`),$(`∹`,`\\eqcolon`),$(`≔`,`\\coloneqq`),$(`≕`,`\\eqqcolon`),$(`⩴`,`\\Coloneqq`),$(`\\ratio`,`\\vcentcolon`),$(`\\coloncolon`,`\\dblcolon`),$(`\\colonequals`,`\\coloneqq`),$(`\\coloncolonequals`,`\\Coloneqq`),$(`\\equalscolon`,`\\eqqcolon`),$(`\\equalscoloncolon`,`\\Eqqcolon`),$(`\\colonminus`,`\\coloneq`),$(`\\coloncolonminus`,`\\Coloneq`),$(`\\minuscolon`,`\\eqcolon`),$(`\\minuscoloncolon`,`\\Eqcolon`),$(`\\coloncolonapprox`,`\\Colonapprox`),$(`\\coloncolonsim`,`\\Colonsim`),$(`\\simcolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\simcoloncolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\approxcolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\approxcoloncolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\notni`,"\\html@mathml{\\not\\ni}{\\mathrel{\\char`∌}}"),$(`\\limsup`,`\\DOTSB\\operatorname*{lim\\,sup}`),$(`\\liminf`,`\\DOTSB\\operatorname*{lim\\,inf}`),$(`\\injlim`,`\\DOTSB\\operatorname*{inj\\,lim}`),$(`\\projlim`,`\\DOTSB\\operatorname*{proj\\,lim}`),$(`\\varlimsup`,`\\DOTSB\\operatorname*{\\overline{lim}}`),$(`\\varliminf`,`\\DOTSB\\operatorname*{\\underline{lim}}`),$(`\\varinjlim`,`\\DOTSB\\operatorname*{\\underrightarrow{lim}}`),$(`\\varprojlim`,`\\DOTSB\\operatorname*{\\underleftarrow{lim}}`),$(`\\gvertneqq`,`\\html@mathml{\\@gvertneqq}{≩}`),$(`\\lvertneqq`,`\\html@mathml{\\@lvertneqq}{≨}`),$(`\\ngeqq`,`\\html@mathml{\\@ngeqq}{≱}`),$(`\\ngeqslant`,`\\html@mathml{\\@ngeqslant}{≱}`),$(`\\nleqq`,`\\html@mathml{\\@nleqq}{≰}`),$(`\\nleqslant`,`\\html@mathml{\\@nleqslant}{≰}`),$(`\\nshortmid`,`\\html@mathml{\\@nshortmid}{∤}`),$(`\\nshortparallel`,`\\html@mathml{\\@nshortparallel}{∦}`),$(`\\nsubseteqq`,`\\html@mathml{\\@nsubseteqq}{⊈}`),$(`\\nsupseteqq`,`\\html@mathml{\\@nsupseteqq}{⊉}`),$(`\\varsubsetneq`,`\\html@mathml{\\@varsubsetneq}{⊊}`),$(`\\varsubsetneqq`,`\\html@mathml{\\@varsubsetneqq}{⫋}`),$(`\\varsupsetneq`,`\\html@mathml{\\@varsupsetneq}{⊋}`),$(`\\varsupsetneqq`,`\\html@mathml{\\@varsupsetneqq}{⫌}`),$(`\\imath`,`\\html@mathml{\\@imath}{ı}`),$(`\\jmath`,`\\html@mathml{\\@jmath}{ȷ}`),$(`\\llbracket`,"\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}"),$(`\\rrbracket`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}"),$(`⟦`,`\\llbracket`),$(`⟧`,`\\rrbracket`),$(`\\lBrace`,"\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}"),$(`\\rBrace`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}"),$(`↤`,`\\mapsfrom`),$(`\\mapsfrom`,"\\html@mathml{\\mathrel{\\mathreflectbox{\\mapsto}}}{\\mathrel{\\char`↤}}"),$(`⦃`,`\\lBrace`),$(`⦄`,`\\rBrace`),$(`\\minuso`,"\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}"),$(`⦵`,`\\minuso`),$(`\\darr`,`\\downarrow`),$(`\\dArr`,`\\Downarrow`),$(`\\Darr`,`\\Downarrow`),$(`\\lang`,`\\langle`),$(`\\rang`,`\\rangle`),$(`\\uarr`,`\\uparrow`),$(`\\uArr`,`\\Uparrow`),$(`\\Uarr`,`\\Uparrow`),$(`\\N`,`\\mathbb{N}`),$(`\\R`,`\\mathbb{R}`),$(`\\Z`,`\\mathbb{Z}`),$(`\\alef`,`\\aleph`),$(`\\alefsym`,`\\aleph`),$(`\\Alpha`,`\\mathrm{A}`),$(`\\Beta`,`\\mathrm{B}`),$(`\\bull`,`\\bullet`),$(`\\Chi`,`\\mathrm{X}`),$(`\\clubs`,`\\clubsuit`),$(`\\cnums`,`\\mathbb{C}`),$(`\\Complex`,`\\mathbb{C}`),$(`\\Dagger`,`\\ddagger`),$(`\\diamonds`,`\\diamondsuit`),$(`\\empty`,`\\emptyset`),$(`\\Epsilon`,`\\mathrm{E}`),$(`\\Eta`,`\\mathrm{H}`),$(`\\exist`,`\\exists`),$(`\\harr`,`\\leftrightarrow`),$(`\\hArr`,`\\Leftrightarrow`),$(`\\Harr`,`\\Leftrightarrow`),$(`\\hearts`,`\\heartsuit`),$(`\\image`,`\\Im`),$(`\\infin`,`\\infty`),$(`\\Iota`,`\\mathrm{I}`),$(`\\isin`,`\\in`),$(`\\Kappa`,`\\mathrm{K}`),$(`\\larr`,`\\leftarrow`),$(`\\lArr`,`\\Leftarrow`),$(`\\Larr`,`\\Leftarrow`),$(`\\lrarr`,`\\leftrightarrow`),$(`\\lrArr`,`\\Leftrightarrow`),$(`\\Lrarr`,`\\Leftrightarrow`),$(`\\Mu`,`\\mathrm{M}`),$(`\\natnums`,`\\mathbb{N}`),$(`\\Nu`,`\\mathrm{N}`),$(`\\Omicron`,`\\mathrm{O}`),$(`\\plusmn`,`\\pm`),$(`\\rarr`,`\\rightarrow`),$(`\\rArr`,`\\Rightarrow`),$(`\\Rarr`,`\\Rightarrow`),$(`\\real`,`\\Re`),$(`\\reals`,`\\mathbb{R}`),$(`\\Reals`,`\\mathbb{R}`),$(`\\Rho`,`\\mathrm{P}`),$(`\\sdot`,`\\cdot`),$(`\\sect`,`\\S`),$(`\\spades`,`\\spadesuit`),$(`\\sub`,`\\subset`),$(`\\sube`,`\\subseteq`),$(`\\supe`,`\\supseteq`),$(`\\Tau`,`\\mathrm{T}`),$(`\\thetasym`,`\\vartheta`),$(`\\weierp`,`\\wp`),$(`\\Zeta`,`\\mathrm{Z}`),$(`\\argmin`,`\\DOTSB\\operatorname*{arg\\,min}`),$(`\\argmax`,`\\DOTSB\\operatorname*{arg\\,max}`),$(`\\plim`,`\\DOTSB\\mathop{\\operatorname{plim}}\\limits`),$(`\\bra`,`\\mathinner{\\langle{#1}|}`),$(`\\ket`,`\\mathinner{|{#1}\\rangle}`),$(`\\braket`,`\\mathinner{\\langle{#1}\\rangle}`),$(`\\Bra`,`\\left\\langle#1\\right|`),$(`\\Ket`,`\\left|#1\\right\\rangle`);var _J=e=>t=>{var n=t.consumeArg().tokens,r=t.consumeArg().tokens,i=t.consumeArg().tokens,a=t.consumeArg().tokens,o=t.macros.get(`|`),s=t.macros.get(`\\|`);t.macros.beginGroup();var c=t=>n=>{e&&(n.macros.set(`|`,o),i.length&&n.macros.set(`\\|`,s));var a=t;return!t&&i.length&&n.future().text===`|`&&(n.popToken(),a=!0),{tokens:a?i:r,numArgs:0}};t.macros.set(`|`,c(!1)),i.length&&t.macros.set(`\\|`,c(!0));var l=t.consumeArg().tokens,u=t.expandTokens([...a,...l,...n]);return t.macros.endGroup(),{tokens:u.reverse(),numArgs:0}};$(`\\bra@ket`,_J(!1)),$(`\\bra@set`,_J(!0)),$(`\\Braket`,`\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}`),$(`\\Set`,`\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}`),$(`\\set`,`\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}`),$(`\\angln`,`{\\angl n}`),$(`\\blue`,`\\textcolor{##6495ed}{#1}`),$(`\\orange`,`\\textcolor{##ffa500}{#1}`),$(`\\pink`,`\\textcolor{##ff00af}{#1}`),$(`\\red`,`\\textcolor{##df0030}{#1}`),$(`\\green`,`\\textcolor{##28ae7b}{#1}`),$(`\\gray`,`\\textcolor{gray}{#1}`),$(`\\purple`,`\\textcolor{##9d38bd}{#1}`),$(`\\blueA`,`\\textcolor{##ccfaff}{#1}`),$(`\\blueB`,`\\textcolor{##80f6ff}{#1}`),$(`\\blueC`,`\\textcolor{##63d9ea}{#1}`),$(`\\blueD`,`\\textcolor{##11accd}{#1}`),$(`\\blueE`,`\\textcolor{##0c7f99}{#1}`),$(`\\tealA`,`\\textcolor{##94fff5}{#1}`),$(`\\tealB`,`\\textcolor{##26edd5}{#1}`),$(`\\tealC`,`\\textcolor{##01d1c1}{#1}`),$(`\\tealD`,`\\textcolor{##01a995}{#1}`),$(`\\tealE`,`\\textcolor{##208170}{#1}`),$(`\\greenA`,`\\textcolor{##b6ffb0}{#1}`),$(`\\greenB`,`\\textcolor{##8af281}{#1}`),$(`\\greenC`,`\\textcolor{##74cf70}{#1}`),$(`\\greenD`,`\\textcolor{##1fab54}{#1}`),$(`\\greenE`,`\\textcolor{##0d923f}{#1}`),$(`\\goldA`,`\\textcolor{##ffd0a9}{#1}`),$(`\\goldB`,`\\textcolor{##ffbb71}{#1}`),$(`\\goldC`,`\\textcolor{##ff9c39}{#1}`),$(`\\goldD`,`\\textcolor{##e07d10}{#1}`),$(`\\goldE`,`\\textcolor{##a75a05}{#1}`),$(`\\redA`,`\\textcolor{##fca9a9}{#1}`),$(`\\redB`,`\\textcolor{##ff8482}{#1}`),$(`\\redC`,`\\textcolor{##f9685d}{#1}`),$(`\\redD`,`\\textcolor{##e84d39}{#1}`),$(`\\redE`,`\\textcolor{##bc2612}{#1}`),$(`\\maroonA`,`\\textcolor{##ffbde0}{#1}`),$(`\\maroonB`,`\\textcolor{##ff92c6}{#1}`),$(`\\maroonC`,`\\textcolor{##ed5fa6}{#1}`),$(`\\maroonD`,`\\textcolor{##ca337c}{#1}`),$(`\\maroonE`,`\\textcolor{##9e034e}{#1}`),$(`\\purpleA`,`\\textcolor{##ddd7ff}{#1}`),$(`\\purpleB`,`\\textcolor{##c6b9fc}{#1}`),$(`\\purpleC`,`\\textcolor{##aa87ff}{#1}`),$(`\\purpleD`,`\\textcolor{##7854ab}{#1}`),$(`\\purpleE`,`\\textcolor{##543b78}{#1}`),$(`\\mintA`,`\\textcolor{##f5f9e8}{#1}`),$(`\\mintB`,`\\textcolor{##edf2df}{#1}`),$(`\\mintC`,`\\textcolor{##e0e5cc}{#1}`),$(`\\grayA`,`\\textcolor{##f6f7f7}{#1}`),$(`\\grayB`,`\\textcolor{##f0f1f2}{#1}`),$(`\\grayC`,`\\textcolor{##e3e5e6}{#1}`),$(`\\grayD`,`\\textcolor{##d6d8da}{#1}`),$(`\\grayE`,`\\textcolor{##babec2}{#1}`),$(`\\grayF`,`\\textcolor{##888d93}{#1}`),$(`\\grayG`,`\\textcolor{##626569}{#1}`),$(`\\grayH`,`\\textcolor{##3b3e40}{#1}`),$(`\\grayI`,`\\textcolor{##21242c}{#1}`),$(`\\kaBlue`,`\\textcolor{##314453}{#1}`),$(`\\kaGreen`,`\\textcolor{##71B307}{#1}`);var vJ={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0},yJ=class{constructor(e,t,n){this.settings=void 0,this.expansionCount=void 0,this.lexer=void 0,this.macros=void 0,this.stack=void 0,this.mode=void 0,this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new lJ(uJ,t.macros),this.mode=n,this.stack=[]}feed(e){this.lexer=new cJ(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}endGroups(){this.macros.endGroups()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){var t,n,r;if(e){if(this.consumeSpaces(),this.future().text!==`[`)return null;t=this.popToken();var i=this.consumeArg([`]`]);r=i.tokens,n=i.end}else{var a=this.consumeArg();r=a.tokens,t=a.start,n=a.end}return this.pushToken(new cq(`EOF`,n.loc)),this.pushTokens(r),new cq(``,sq.range(t,n))}consumeSpaces(){for(;this.future().text===` `;)this.stack.pop()}consumeArg(e){var t=[],n=e&&e.length>0;n||this.consumeSpaces();var r=this.future(),i,a=0,o=0;do{if(i=this.popToken(),t.push(i),i.text===`{`)++a;else if(i.text===`}`){if(--a,a===-1)throw new L(`Extra }`,i)}else if(i.text===`EOF`)throw new L(`Unexpected end of input in a macro argument, expected '`+(e&&n?e[o]:`}`)+`'`,i);if(e&&n){if((a===0||a===1&&e[o]===`{`)&&i.text===e[o]){if(++o,o===e.length){t.splice(-o,o);break}}else o=0}}while(a!==0||n);return r.text===`{`&&t[t.length-1].text===`}`&&(t.pop(),t.shift()),t.reverse(),{tokens:t,start:r,end:i}}consumeArgs(e,t){if(t){if(t.length!==e+1)throw new L(`The length of delimiters doesn't match the number of args!`);for(var n=t[0],r=0;rthis.settings.maxExpand)throw new L(`Too many expansions: infinite loop or need to increase maxExpand setting`)}expandOnce(e){var t=this.popToken(),n=t.text,r=t.noexpand?null:this._getExpansion(n);if(r==null||e&&r.unexpandable){if(e&&r==null&&n[0]===`\\`&&!this.isDefined(n))throw new L(`Undefined control sequence: `+n);return this.pushToken(t),!1}this.countExpansion(1);var i=r.tokens,a=this.consumeArgs(r.numArgs,r.delimiters);if(r.numArgs){i=i.slice();for(var o=i.length-1;o>=0;--o){var s=i[o];if(s.text===`#`){if(o===0)throw new L(`Incomplete placeholder at end of macro body`,s);if(s=i[--o],s.text===`#`)i.splice(o+1,1);else if(/^[1-9]$/.test(s.text))i.splice(o,2,...a[s.text-1]);else throw new L(`Not a valid argument number`,s)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){var e=this.stack.pop();return e.treatAsRelax&&(e.text=`\\relax`),e}}expandMacro(e){return this.macros.has(e)?this.expandTokens([new cq(e)]):void 0}expandTokens(e){var t=[],n=this.stack.length;for(this.pushTokens(e);this.stack.length>n;)if(this.expandOnce(!0)===!1){var r=this.stack.pop();r.treatAsRelax&&=(r.noexpand=!1,!1),t.push(r)}return this.countExpansion(t.length),t}expandMacroAsText(e){var t=this.expandMacro(e);return t&&t.map(e=>e.text).join(``)}_getExpansion(e){var t=this.macros.get(e);if(t==null)return t;if(e.length===1){var n=this.lexer.catcodes[e];if(n!=null&&n!==13)return}var r=typeof t==`function`?t(this):t;if(typeof r==`string`){var i=0;if(r.includes(`#`))for(var a=r.replace(/##/g,``);a.includes(`#`+(i+1));)++i;for(var o=new cJ(r,this.settings),s=[],c=o.lex();c.text!==`EOF`;)s.push(c),c=o.lex();return s.reverse(),{tokens:s,numArgs:i}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call($q,e)||Object.prototype.hasOwnProperty.call(qU.math,e)||Object.prototype.hasOwnProperty.call(qU.text,e)||Object.prototype.hasOwnProperty.call(vJ,e)}isExpandable(e){var t=this.macros.get(e);return t==null?Object.prototype.hasOwnProperty.call($q,e)&&!$q[e].primitive:typeof t==`string`||typeof t==`function`||!t.unexpandable}},bJ=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,xJ=Object.freeze({"₊":`+`,"₋":`-`,"₌":`=`,"₍":`(`,"₎":`)`,"₀":`0`,"₁":`1`,"₂":`2`,"₃":`3`,"₄":`4`,"₅":`5`,"₆":`6`,"₇":`7`,"₈":`8`,"₉":`9`,ₐ:`a`,ₑ:`e`,ₕ:`h`,ᵢ:`i`,ⱼ:`j`,ₖ:`k`,ₗ:`l`,ₘ:`m`,ₙ:`n`,ₒ:`o`,ₚ:`p`,ᵣ:`r`,ₛ:`s`,ₜ:`t`,ᵤ:`u`,ᵥ:`v`,ₓ:`x`,ᵦ:`β`,ᵧ:`γ`,ᵨ:`ρ`,ᵩ:`ϕ`,ᵪ:`χ`,"⁺":`+`,"⁻":`-`,"⁼":`=`,"⁽":`(`,"⁾":`)`,"⁰":`0`,"¹":`1`,"²":`2`,"³":`3`,"⁴":`4`,"⁵":`5`,"⁶":`6`,"⁷":`7`,"⁸":`8`,"⁹":`9`,ᴬ:`A`,ᴮ:`B`,ᴰ:`D`,ᴱ:`E`,ᴳ:`G`,ᴴ:`H`,ᴵ:`I`,ᴶ:`J`,ᴷ:`K`,ᴸ:`L`,ᴹ:`M`,ᴺ:`N`,ᴼ:`O`,ᴾ:`P`,ᴿ:`R`,ᵀ:`T`,ᵁ:`U`,ⱽ:`V`,ᵂ:`W`,ᵃ:`a`,ᵇ:`b`,ᶜ:`c`,ᵈ:`d`,ᵉ:`e`,ᶠ:`f`,ᵍ:`g`,ʰ:`h`,ⁱ:`i`,ʲ:`j`,ᵏ:`k`,ˡ:`l`,ᵐ:`m`,ⁿ:`n`,ᵒ:`o`,ᵖ:`p`,ʳ:`r`,ˢ:`s`,ᵗ:`t`,ᵘ:`u`,ᵛ:`v`,ʷ:`w`,ˣ:`x`,ʸ:`y`,ᶻ:`z`,ᵝ:`β`,ᵞ:`γ`,ᵟ:`δ`,ᵠ:`ϕ`,ᵡ:`χ`,ᶿ:`θ`}),SJ={"́":{text:`\\'`,math:`\\acute`},"̀":{text:"\\`",math:`\\grave`},"̈":{text:`\\"`,math:`\\ddot`},"̃":{text:`\\~`,math:`\\tilde`},"̄":{text:`\\=`,math:`\\bar`},"̆":{text:`\\u`,math:`\\breve`},"̌":{text:`\\v`,math:`\\check`},"̂":{text:`\\^`,math:`\\hat`},"̇":{text:`\\.`,math:`\\dot`},"̊":{text:`\\r`,math:`\\mathring`},"̋":{text:`\\H`},"̧":{text:`\\c`}},CJ={á:`á`,à:`à`,ä:`ä`,ǟ:`ǟ`,ã:`ã`,ā:`ā`,ă:`ă`,ắ:`ắ`,ằ:`ằ`,ẵ:`ẵ`,ǎ:`ǎ`,â:`â`,ấ:`ấ`,ầ:`ầ`,ẫ:`ẫ`,ȧ:`ȧ`,ǡ:`ǡ`,å:`å`,ǻ:`ǻ`,ḃ:`ḃ`,ć:`ć`,ḉ:`ḉ`,č:`č`,ĉ:`ĉ`,ċ:`ċ`,ç:`ç`,ď:`ď`,ḋ:`ḋ`,ḑ:`ḑ`,é:`é`,è:`è`,ë:`ë`,ẽ:`ẽ`,ē:`ē`,ḗ:`ḗ`,ḕ:`ḕ`,ĕ:`ĕ`,ḝ:`ḝ`,ě:`ě`,ê:`ê`,ế:`ế`,ề:`ề`,ễ:`ễ`,ė:`ė`,ȩ:`ȩ`,ḟ:`ḟ`,ǵ:`ǵ`,ḡ:`ḡ`,ğ:`ğ`,ǧ:`ǧ`,ĝ:`ĝ`,ġ:`ġ`,ģ:`ģ`,ḧ:`ḧ`,ȟ:`ȟ`,ĥ:`ĥ`,ḣ:`ḣ`,ḩ:`ḩ`,í:`í`,ì:`ì`,ï:`ï`,ḯ:`ḯ`,ĩ:`ĩ`,ī:`ī`,ĭ:`ĭ`,ǐ:`ǐ`,î:`î`,ǰ:`ǰ`,ĵ:`ĵ`,ḱ:`ḱ`,ǩ:`ǩ`,ķ:`ķ`,ĺ:`ĺ`,ľ:`ľ`,ļ:`ļ`,ḿ:`ḿ`,ṁ:`ṁ`,ń:`ń`,ǹ:`ǹ`,ñ:`ñ`,ň:`ň`,ṅ:`ṅ`,ņ:`ņ`,ó:`ó`,ò:`ò`,ö:`ö`,ȫ:`ȫ`,õ:`õ`,ṍ:`ṍ`,ṏ:`ṏ`,ȭ:`ȭ`,ō:`ō`,ṓ:`ṓ`,ṑ:`ṑ`,ŏ:`ŏ`,ǒ:`ǒ`,ô:`ô`,ố:`ố`,ồ:`ồ`,ỗ:`ỗ`,ȯ:`ȯ`,ȱ:`ȱ`,ő:`ő`,ṕ:`ṕ`,ṗ:`ṗ`,ŕ:`ŕ`,ř:`ř`,ṙ:`ṙ`,ŗ:`ŗ`,ś:`ś`,ṥ:`ṥ`,š:`š`,ṧ:`ṧ`,ŝ:`ŝ`,ṡ:`ṡ`,ş:`ş`,ẗ:`ẗ`,ť:`ť`,ṫ:`ṫ`,ţ:`ţ`,ú:`ú`,ù:`ù`,ü:`ü`,ǘ:`ǘ`,ǜ:`ǜ`,ǖ:`ǖ`,ǚ:`ǚ`,ũ:`ũ`,ṹ:`ṹ`,ū:`ū`,ṻ:`ṻ`,ŭ:`ŭ`,ǔ:`ǔ`,û:`û`,ů:`ů`,ű:`ű`,ṽ:`ṽ`,ẃ:`ẃ`,ẁ:`ẁ`,ẅ:`ẅ`,ŵ:`ŵ`,ẇ:`ẇ`,ẘ:`ẘ`,ẍ:`ẍ`,ẋ:`ẋ`,ý:`ý`,ỳ:`ỳ`,ÿ:`ÿ`,ỹ:`ỹ`,ȳ:`ȳ`,ŷ:`ŷ`,ẏ:`ẏ`,ẙ:`ẙ`,ź:`ź`,ž:`ž`,ẑ:`ẑ`,ż:`ż`,Á:`Á`,À:`À`,Ä:`Ä`,Ǟ:`Ǟ`,Ã:`Ã`,Ā:`Ā`,Ă:`Ă`,Ắ:`Ắ`,Ằ:`Ằ`,Ẵ:`Ẵ`,Ǎ:`Ǎ`,Â:`Â`,Ấ:`Ấ`,Ầ:`Ầ`,Ẫ:`Ẫ`,Ȧ:`Ȧ`,Ǡ:`Ǡ`,Å:`Å`,Ǻ:`Ǻ`,Ḃ:`Ḃ`,Ć:`Ć`,Ḉ:`Ḉ`,Č:`Č`,Ĉ:`Ĉ`,Ċ:`Ċ`,Ç:`Ç`,Ď:`Ď`,Ḋ:`Ḋ`,Ḑ:`Ḑ`,É:`É`,È:`È`,Ë:`Ë`,Ẽ:`Ẽ`,Ē:`Ē`,Ḗ:`Ḗ`,Ḕ:`Ḕ`,Ĕ:`Ĕ`,Ḝ:`Ḝ`,Ě:`Ě`,Ê:`Ê`,Ế:`Ế`,Ề:`Ề`,Ễ:`Ễ`,Ė:`Ė`,Ȩ:`Ȩ`,Ḟ:`Ḟ`,Ǵ:`Ǵ`,Ḡ:`Ḡ`,Ğ:`Ğ`,Ǧ:`Ǧ`,Ĝ:`Ĝ`,Ġ:`Ġ`,Ģ:`Ģ`,Ḧ:`Ḧ`,Ȟ:`Ȟ`,Ĥ:`Ĥ`,Ḣ:`Ḣ`,Ḩ:`Ḩ`,Í:`Í`,Ì:`Ì`,Ï:`Ï`,Ḯ:`Ḯ`,Ĩ:`Ĩ`,Ī:`Ī`,Ĭ:`Ĭ`,Ǐ:`Ǐ`,Î:`Î`,İ:`İ`,Ĵ:`Ĵ`,Ḱ:`Ḱ`,Ǩ:`Ǩ`,Ķ:`Ķ`,Ĺ:`Ĺ`,Ľ:`Ľ`,Ļ:`Ļ`,Ḿ:`Ḿ`,Ṁ:`Ṁ`,Ń:`Ń`,Ǹ:`Ǹ`,Ñ:`Ñ`,Ň:`Ň`,Ṅ:`Ṅ`,Ņ:`Ņ`,Ó:`Ó`,Ò:`Ò`,Ö:`Ö`,Ȫ:`Ȫ`,Õ:`Õ`,Ṍ:`Ṍ`,Ṏ:`Ṏ`,Ȭ:`Ȭ`,Ō:`Ō`,Ṓ:`Ṓ`,Ṑ:`Ṑ`,Ŏ:`Ŏ`,Ǒ:`Ǒ`,Ô:`Ô`,Ố:`Ố`,Ồ:`Ồ`,Ỗ:`Ỗ`,Ȯ:`Ȯ`,Ȱ:`Ȱ`,Ő:`Ő`,Ṕ:`Ṕ`,Ṗ:`Ṗ`,Ŕ:`Ŕ`,Ř:`Ř`,Ṙ:`Ṙ`,Ŗ:`Ŗ`,Ś:`Ś`,Ṥ:`Ṥ`,Š:`Š`,Ṧ:`Ṧ`,Ŝ:`Ŝ`,Ṡ:`Ṡ`,Ş:`Ş`,Ť:`Ť`,Ṫ:`Ṫ`,Ţ:`Ţ`,Ú:`Ú`,Ù:`Ù`,Ü:`Ü`,Ǘ:`Ǘ`,Ǜ:`Ǜ`,Ǖ:`Ǖ`,Ǚ:`Ǚ`,Ũ:`Ũ`,Ṹ:`Ṹ`,Ū:`Ū`,Ṻ:`Ṻ`,Ŭ:`Ŭ`,Ǔ:`Ǔ`,Û:`Û`,Ů:`Ů`,Ű:`Ű`,Ṽ:`Ṽ`,Ẃ:`Ẃ`,Ẁ:`Ẁ`,Ẅ:`Ẅ`,Ŵ:`Ŵ`,Ẇ:`Ẇ`,Ẍ:`Ẍ`,Ẋ:`Ẋ`,Ý:`Ý`,Ỳ:`Ỳ`,Ÿ:`Ÿ`,Ỹ:`Ỹ`,Ȳ:`Ȳ`,Ŷ:`Ŷ`,Ẏ:`Ẏ`,Ź:`Ź`,Ž:`Ž`,Ẑ:`Ẑ`,Ż:`Ż`,ά:`ά`,ὰ:`ὰ`,ᾱ:`ᾱ`,ᾰ:`ᾰ`,έ:`έ`,ὲ:`ὲ`,ή:`ή`,ὴ:`ὴ`,ί:`ί`,ὶ:`ὶ`,ϊ:`ϊ`,ΐ:`ΐ`,ῒ:`ῒ`,ῑ:`ῑ`,ῐ:`ῐ`,ό:`ό`,ὸ:`ὸ`,ύ:`ύ`,ὺ:`ὺ`,ϋ:`ϋ`,ΰ:`ΰ`,ῢ:`ῢ`,ῡ:`ῡ`,ῠ:`ῠ`,ώ:`ώ`,ὼ:`ὼ`,Ύ:`Ύ`,Ὺ:`Ὺ`,Ϋ:`Ϋ`,Ῡ:`Ῡ`,Ῠ:`Ῠ`,Ώ:`Ώ`,Ὼ:`Ὼ`},wJ=class e{constructor(e,t){this.mode=void 0,this.gullet=void 0,this.settings=void 0,this.leftrightDepth=void 0,this.nextToken=void 0,this.mode=`math`,this.gullet=new yJ(e,t,this.mode),this.settings=t,this.leftrightDepth=0,this.nextToken=null}expect(e,t){if(t===void 0&&(t=!0),this.fetch().text!==e)throw new L(`Expected '`+e+`', got '`+this.fetch().text+`'`,this.fetch());t&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken??=this.gullet.expandNextToken(),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.settings.globalGroup||this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set(`\\color`,`\\textcolor`);try{var e=this.parseExpression(!1);return this.expect(`EOF`),this.settings.globalGroup||this.gullet.endGroup(),e}finally{this.gullet.endGroups()}}subparse(e){var t=this.nextToken;this.consume(),this.gullet.pushToken(new cq(`}`)),this.gullet.pushTokens(e);var n=this.parseExpression(!1);return this.expect(`}`),this.nextToken=t,n}parseExpression(t,n){for(var r=[];;){this.mode===`math`&&this.consumeSpaces();var i=this.fetch();if(e.endOfExpression.has(i.text)||n&&i.text===n||t&&$q[i.text]&&$q[i.text].infix)break;var a=this.parseAtom(n);if(!a)break;a.type!==`internal`&&r.push(a)}return this.mode===`text`&&this.formLigatures(r),this.handleInfixNodes(r)}handleInfixNodes(e){for(var t=-1,n,r=0;r=128)this.settings.strict&&(rU(t.charCodeAt(0))?this.mode===`math`&&this.settings.reportNonstrict(`unicodeTextInMathMode`,`Unicode text character "`+t[0]+`" used in math mode`,e):this.settings.reportNonstrict(`unknownSymbol`,`Unrecognized Unicode character "`+t[0]+`"`+(` (`+t.charCodeAt(0)+`)`),e)),a={type:`textord`,mode:`text`,loc:sq.range(e),text:t};else return null;if(this.consume(),i)for(var c=0;ce.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertBlockMath:e=>({commands:t,editor:n})=>{let{latex:r,pos:i}=e;return r?t.insertContentAt(i??n.state.selection.from,{type:this.name,attrs:{latex:r}}):!1},deleteBlockMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateBlockMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r??a.attrs.latex}),!0)}}},parseHTML(){return[{tag:`div[data-type="block-math"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,A(e,{"data-type":`block-math`})]},parseMarkdown:e=>({type:`blockMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>[`$$`,e.attrs?.latex||``,`$$`].join(` +`),markdownTokenizer:{name:`blockMath`,level:`block`,start:e=>e.indexOf(`$$`),tokenize:e=>{let t=e.match(/^\$\$([^$]+)\$\$/);if(!t)return;let[n,r]=t;return{type:`blockMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:/^\$\$\$([^$]+)\$\$\$$/,handler:({state:e,range:t,match:n})=>{let[,r]=n,{tr:i}=e,a=e.doc.resolve(t.from),o=this.type.create({latex:r}),s=a.depth>0&&a.parent.isTextblock&&t.from===a.start()&&t.to===a.end()&&a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),this.type)?{from:a.before(),to:a.after()}:t;i.replaceWith(s.from,s.to,o)}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`div`),i=document.createElement(`div`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),i.className=`block-math-inner`,r.dataset.type=`block-math`,r.setAttribute(`data-latex`,t.attrs.latex),r.appendChild(i);function a(){try{jJ.render(t.attrs.latex,i,e),r.classList.remove(`block-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`block-math-error`)}}let o=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,o),a(),{dom:r,destroy(){r.removeEventListener(`click`,o)}}}}}),NJ=e=>{let t=/\$\$([^$\n]+?)\$\$(?!\$)/g,n=t.exec(e);for(;n!==null;){if(n.index===0||e[n.index-1]!==`$`)return{index:n.index,text:n[0],data:{latex:n[1]}};t.lastIndex=n.index+1,n=t.exec(e)}return null},PJ=Jp.create({name:`inlineMath`,group:`inline`,inline:!0,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertInlineMath:e=>({editor:t,tr:n})=>{let r=e.latex,i=e?.pos??t.state.selection.from;return r?(n.replaceWith(i,i,this.type.create({latex:r})),!0):!1},deleteInlineMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateInlineMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r}),!0)}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{"data-type":`inline-math`})]},parseMarkdown:e=>({type:`inlineMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>`$${e.attrs?.latex||``}$`,markdownTokenizer:{name:`inlineMath`,level:`inline`,start:e=>e.indexOf(`$`),tokenize:e=>{let t=e.match(/^\$([^$]+)\$(?!\$)/);if(!t)return;let[n,r]=t;return{type:`inlineMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:NJ,handler:({state:e,range:t,match:n})=>{let r=n.data?.latex;if(typeof r!=`string`)return null;let{tr:i}=e,a=t.from,o=t.to;i.replaceWith(a,o,this.type.create({latex:r}))}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`span`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),r.dataset.type=`inline-math`,r.setAttribute(`data-latex`,t.attrs.latex);function i(){try{jJ.render(t.attrs.latex,r,e),r.classList.remove(`inline-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`inline-math-error`)}}let a=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,a),i(),{dom:r,destroy(){r.removeEventListener(`click`,a)}}}}}),FJ=Tp.create({name:`Mathematics`,addOptions(){return{inlineOptions:void 0,blockOptions:void 0,katexOptions:void 0}},addExtensions(){return[MJ.configure({...this.options.blockOptions,katexOptions:this.options.katexOptions}),PJ.configure({...this.options.inlineOptions,katexOptions:this.options.katexOptions})]}});function IJ(e,t){let n=n=>(r,i)=>{let a=t();if(!a?.isEditable)return;let o=a.view.nodeDOM(i);if(!(o instanceof HTMLElement))return;let s=e.blocks;QV({anchor:o,value:String(r.attrs.latex??``),label:s.latex,multiline:n===`block`,monospace:!0,labels:{done:s.done,cancel:s.cancel,remove:s.remove},onSave:e=>{let t=a.chain().setNodeSelection(i);e.trim()?(n===`inline`?t.updateInlineMath({latex:e,pos:i}):t.updateBlockMath({latex:e,pos:i})).focus().run():(n===`inline`?t.deleteInlineMath({pos:i}):t.deleteBlockMath({pos:i})).focus().run()},onRemove:()=>{let e=a.chain();(n===`inline`?e.deleteInlineMath({pos:i}):e.deleteBlockMath({pos:i})).focus().run()}})};return FJ.configure({katexOptions:{throwOnError:!1,strict:!1,trust:!1},inlineOptions:{onClick:n(`inline`)},blockOptions:{onClick:n(`block`)}})}function LJ({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new Un,command:({editor:e,range:t,props:i})=>{var a,o;let s=e.view.state.selection.$to.nodeAfter;s!=null&&(a=s.text)!=null&&a.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(o=e.view.dom.ownerDocument.defaultView)==null||(o=o.getSelection())==null||o.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function RJ(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>LJ({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function zJ(e,t){let n=RJ(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var BJ=Jp.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:n}){return[`span`,A(this.HTMLAttributes,e.HTMLAttributes),`${n?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=zJ(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:n})];let r={...this.options};r.HTMLAttributes=A({"data-type":this.name},this.options.HTMLAttributes,t);let i=this.options.renderHTML({options:r,node:e,suggestion:n});return typeof i==`string`?[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),i]:i},...$f({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(?:^|\s)(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:zJ(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let n=!1,{selection:r}=t,{empty:i,anchor:a}=r;if(!i)return!1;let o=new ce,s=0;return t.doc.nodesBetween(a-1,a,(e,t)=>{if(e.type.name===this.name)return n=!0,o=e,s=t,!1}),n&&e.insertText(this.options.deleteTriggerWithBackspace?``:o.attrs.mentionSuggestionChar,s,s+o.nodeSize),n})}},addProseMirrorPlugins(){return RJ(this).map(AV)}});function VJ(e,t){return BJ.configure({HTMLAttributes:{class:`dw-mention`},renderText:({node:e})=>`@${e.attrs.label??e.attrs.id}`,suggestion:{char:`@`,allow:()=>!!t,findSuggestionMatch:t=>{let n=gV({...t,allowSpaces:!0});return n&&dV(n.query,e)?n:gV({...t,allowSpaces:!1})},items:async({query:n})=>{if(!t)return[];let r=uV(n,e,!!t.me).map(e=>({date:e})),i=(await t.search(n).catch(()=>[])).map(e=>({person:e}));return n.trim()?[...r,...i].slice(0,8):[...i.slice(0,6),...r]},render:Uj({label:e.mentions,empty:e.noPeople,toItem:t=>`person`in t?{label:t.person.label,description:t.person.hint,icon:`at`}:{label:cV(t.date.date,e),description:t.date.remind?`${e.dates.remindMe} · ${lV(t.date.date,e)}`:lV(t.date.date,e),icon:t.date.remind?`bell`:`calendar`},pick:(e,n)=>{`person`in n?e.command({id:n.person.id,label:n.person.label}):mV(e.editor,e.range,n.date,t?.me)}})}})}var HJ=`flowchart LR + Idea --> Draft --> Review --> Published`,UJ=null;function WJ(e){return UJ??=e().then(e=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:document.documentElement.classList.contains(`dark`)?`dark`:`neutral`,fontFamily:`inherit`}),e)),UJ}var GJ=0;async function KJ(e,t,n,r){if(e.classList.remove(`dw-mermaid__body--error`),!t.trim())e.textContent=``;else if(r)try{let{svg:n}=await(await WJ(r)).render(`dw-mermaid-${++GJ}`,t);e.innerHTML=n}catch(t){e.classList.add(`dw-mermaid__body--error`),e.textContent=`${n.blocks.mermaidError} ${t instanceof Error?t.message:String(t)}`}else{let n=document.createElement(`pre`);n.className=`dw-mermaid__source`,n.textContent=t,e.replaceChildren(n)}}var qJ=Jp.create({name:`mermaid`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null,load:void 0}},addAttributes(){return{code:{default:``,parseHTML:e=>e.getAttribute(`data-code`)??e.textContent??``,renderHTML:e=>({"data-code":e.code})}}},parseHTML(){return[{tag:`div[data-type='mermaid']`},{tag:`pre.mermaid`}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`mermaid`}),[`pre`,{},String(e.attrs.code)]]},addCommands(){return{insertMermaid:(e=HJ)=>({commands:t})=>t.insertContent({type:this.name,attrs:{code:e}})}},addNodeView(){return({node:e,editor:t,getPos:n})=>{let r=this.options.labels,i=this.options.load,a=document.createElement(`div`);a.className=`dw-mermaid`,a.setAttribute(`data-type`,`mermaid`);let o=document.createElement(`div`);o.className=`dw-mermaid__body`,a.append(o);let s=String(e.attrs.code);return KJ(o,s,r,i),a.addEventListener(`click`,()=>{if(!t.isEditable)return;let e=typeof n==`function`?n():void 0;if(e===void 0)return;let c=r.blocks;QV({anchor:a,value:s,label:c.mermaid,multiline:!0,monospace:!0,labels:{done:c.done,cancel:c.cancel,remove:c.remove},onInput:e=>void KJ(o,e,r,i),onSave:n=>{t.chain().setNodeSelection(e).updateAttributes(`mermaid`,{code:n}).run(),KJ(o,n,r,i)},onRemove:()=>t.chain().setNodeSelection(e).deleteSelection().focus().run(),onCancel:()=>void KJ(o,s,r,i)})}),{dom:a,update:e=>e.type.name===`mermaid`&&(e.attrs.code!==s&&(s=String(e.attrs.code),KJ(o,s,r,i)),!0),ignoreMutation:()=>!0,stopEvent:()=>!1}}}});function JJ(e){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.multiple=!0,n.onchange=()=>t([...n.files??[]]),n.click()})}function YJ(e,t,n,r,i=!1,a){let o=(t,n,r,i)=>({id:t,icon:n,keywords:r,label:e.slash[t]?.label??t,description:e.slash[t]?.description??``,run:i}),s=[o(`text`,`text`,[`paragraph`,`p`],(e,t)=>e.chain().focus().deleteRange(t).setParagraph().run()),o(`h1`,`heading`,[`heading`,`title`,`#`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:1}).run()),o(`h2`,`heading`,[`heading`,`subtitle`,`##`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:2}).run()),o(`h3`,`heading`,[`heading`,`###`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:3}).run()),{...o(`otherHeadings`,`heading`,[`other`,`more headings`,`smaller`],()=>{}),children:[4,5,6].map(e=>o(`h${e}`,`heading`,[`heading`,`#`.repeat(e)],(t,n)=>t.chain().focus().deleteRange(n).setHeading({level:e}).run()))},o(`bullet`,`list`,[`list`,`ul`,`-`],(e,t)=>e.chain().focus().deleteRange(t).toggleBulletList().run()),o(`ordered`,`list-ordered`,[`list`,`ol`,`1.`],(e,t)=>e.chain().focus().deleteRange(t).toggleOrderedList().run()),o(`todo`,`todo`,[`task`,`checkbox`,`checklist`,`[]`],(e,t)=>e.chain().focus().deleteRange(t).toggleTaskList().run()),o(`callout`,`callout`,[`note`,`info`,`tip`,`warning`,`aside`,`box`],(e,t)=>e.chain().focus().deleteRange(t).setCallout().run()),o(`table`,`table`,[`grid`,`rows`,`columns`,`spreadsheet`],(e,t)=>e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()),o(`database`,`database`,[`kanban`,`board`,`calendar`,`records`,`tracker`,`notion`],(e,t)=>e.chain().focus().deleteRange(t).insertDatabase().run()),o(`quote`,`quote`,[`blockquote`,`>`],(e,t)=>e.chain().focus().deleteRange(t).toggleBlockquote().run()),o(`code`,`code`,[`codeblock`,"```",`snippet`],(e,t)=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()),o(`toggle`,`chevron-right`,[`details`,`collapse`,`expand`,`fold`,`>`],(e,t)=>e.chain().focus().deleteRange(t).setDetails().run()),o(`divider`,`divider`,[`hr`,`rule`,`line`,`---`],(e,t)=>e.chain().focus().deleteRange(t).setHorizontalRule().run()),o(`toc`,`list`,[`contents`,`outline`,`headings`,`index`],(e,t)=>e.chain().focus().deleteRange(t).insertTableOfContents().run()),o(`math`,`sigma`,[`latex`,`formula`,`equation`,`katex`,`$$`],(e,t)=>e.chain().focus().deleteRange(t).insertBlockMath({latex:`E = mc^2`}).run()),o(`mathInline`,`sigma`,[`latex`,`formula`,`equation`,`$`],(e,t)=>e.chain().focus().deleteRange(t).insertInlineMath({latex:`x^2`}).run()),o(`mermaid`,`diagram`,[`diagram`,`flowchart`,`chart`,`sequence`,`graph`],(e,t)=>e.chain().focus().deleteRange(t).insertMermaid().run()),o(`embed`,`video`,[`video`,`youtube`,`vimeo`,`figma`,`loom`,`iframe`,`map`],(t,r)=>{t.chain().focus().deleteRange(r).run(),iH(t,e,a,n)}),o(`linkCard`,`link`,[`bookmark`,`preview`,`card`,`url`,`web`],(t,r)=>{t.chain().focus().deleteRange(r).run(),aH(t,e,a,n)})],c=e=>{let t=new Date;return iV(new Date(t.getFullYear(),t.getMonth(),t.getDate()+e))};if(s.push(o(`today`,`calendar`,[`date`,`day`],(e,t)=>mV(e,t,{date:c(0),remind:!1})),o(`tomorrow`,`calendar`,[`date`,`day`],(e,t)=>mV(e,t,{date:c(1),remind:!1})),o(`yesterday`,`calendar`,[`date`,`day`],(e,t)=>mV(e,t,{date:c(-1),remind:!1})),o(`now`,`clock`,[`time`,`date`,`timestamp`],(t,n)=>{mV(t,n,{date:c(0),remind:!1});let r=new Intl.DateTimeFormat(e.locale,{hour:`numeric`,minute:`2-digit`}).format(new Date);t.chain().focus().insertContent(`${r} `).run()})),r&&(s.push(o(`pageLink`,`link`,[`page`,`link`,`[[`,`wiki`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`[[`).run())),s.push(o(`syncedPage`,`copy`,[`embed`,`transclude`,`include`,`mirror`,`![[`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`![[`).run())),r.create&&s.push(o(`newPage`,`page-plus`,[`page`,`doc`,`subpage`,`create`],(e,t)=>{e.chain().focus().deleteRange(t).run(),IV(e,r,``).catch(n)}))),t?.upload){let e=e=>(r,i)=>{r.chain().focus().deleteRange(i).run(),JJ(e).then(e=>fH(r,t,e).catch(n))};s.push(o(`image`,`image`,[`picture`,`photo`,`img`],e(`image/*`)),o(`file`,`paperclip`,[`attachment`,`upload`,`pdf`],e(``)),o(`drawio`,`diagram`,[`diagram`,`diagrams.net`,`draw`,`chart`,`uml`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`drawio`).run())),i&&s.push(o(`excalidraw`,`pencil`,[`drawing`,`sketch`,`whiteboard`,`draw`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`excalidraw`).run()))}return s}function XJ(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e=>e.label.toLowerCase().includes(n)||e.id.startsWith(n)||e.keywords.some(e=>e.toLowerCase().startsWith(n));return e.flatMap(e=>{let t=e.children?.filter(r)??[];return t.length?t:r(e)?[e]:[]})}var ZJ=Tp.create({name:`slashMenu`,addOptions(){return{commands:[],labels:void 0}},addProseMirrorPlugins(){return[jV({editor:this.editor,pluginKey:new Un(`slashMenu`),char:`/`,allowSpaces:!1,startOfLine:!1,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:({query:e})=>XJ(this.options.commands,e),render:Uj({label:this.options.labels.slashMenu,empty:this.options.labels.noMatches,showQuery:!0,toItem:e=>({label:e.label,description:e.description,icon:e.icon}),children:e=>e.children,pick:(e,t)=>t.run(e.editor,e.range)})})]}});function QJ(e,t){let n=!0,r=e.firstChild?.childCount??0;return e.forEach(e=>{t===`column`&&e.childCount!==r&&(n=!1),e.forEach(e=>{((t===`row`?e.attrs.rowspan:e.attrs.colspan)??1)>1&&(n=!1)})}),n}function $J(e,t,n){let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}var eY=e=>{let t=[];return e.forEach(e=>t.push(e)),t};function tY(e,t,n,r,i,a=0){let o=e.doc.nodeAt(t);if(!o||o.type.name!==`table`||!QJ(o,n))return null;let c=eY(o),l=n===`row`?c.length:c[0]?.childCount??0;if(r===i||r<0||i<0||r>=l||i>=l)return null;let u=n===`row`?$J(c,r,i):c.map(e=>e.copy(s.fromArray($J(eY(e),r,i)))),d=e.tr.replaceWith(t,t+o.nodeSize,o.copy(s.fromArray(u))),[f,p]=n===`row`?[i,0]:[Math.min(a,u.length-1),i],m=t+1;for(let e=0;e0;e--)if(n.node(e).type.name===`table`)return{tablePos:n.before(e),row:n.index(e),column:e+1<=n.depth?n.index(e+1):0};return null}var rY=Tp.create({name:`tableMove`,addOptions(){return{labels:null}},addCommands(){let e=e=>t=>({state:n,dispatch:r})=>{let i=nY(n,n.selection.from);if(!i)return!1;let a=e===`row`?i.row:i.column,o=tY(n,i.tablePos,e,a,a+t,i.row);return o?(r?.(o),!0):!1};return{moveTableRow:e(`row`),moveTableColumn:e(`column`)}},addKeyboardShortcuts(){return{"Mod-Alt-ArrowUp":()=>this.editor.commands.moveTableRow(-1),"Mod-Alt-ArrowDown":()=>this.editor.commands.moveTableRow(1),"Mod-Alt-ArrowLeft":()=>this.editor.commands.moveTableColumn(-1),"Mod-Alt-ArrowRight":()=>this.editor.commands.moveTableColumn(1)}},addProseMirrorPlugins(){let e=this.options.labels?.table;return[new D({key:new Un(`tableMove`),view:t=>new iY(t,{row:e?.dragRow??`Drag to move the row`,column:e?.dragColumn??`Drag to move the column`})})]}}),iY=class{view;grips={row:document.createElement(`button`),column:document.createElement(`button`)};line=document.createElement(`div`);cell=null;drag=null;constructor(e,t){this.view=e;for(let e of[`row`,`column`]){let n=this.grips[e];n.type=`button`,n.className=`dw-table-grip dw-table-grip--${e}`,n.contentEditable=`false`,n.setAttribute(`aria-label`,t[e]),n.title=t[e],n.hidden=!0,n.tabIndex=-1,n.addEventListener(`pointerdown`,t=>this.start(t,e)),n.addEventListener(`mouseleave`,this.leave)}this.line.className=`dw-table-drop`,this.line.hidden=!0,e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.line.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.grips.row,this.grips.column,this.line)),e}hide=()=>{this.drag||(this.grips.row.hidden=!0,this.grips.column.hidden=!0,this.cell=null)};leave=e=>{let t=e.relatedTarget;t&&(this.grips.row.contains(t)||this.grips.column.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.drag)return;let t=e.target?.closest?.(`td, th`),n=this.host;if(!this.view.editable||!n||!(t instanceof HTMLTableCellElement)||!this.view.dom.contains(t))return this.hide();let r=this.locate(t),i=r&&this.view.state.doc.nodeAt(r.tablePos);if(!r||!i)return this.hide();this.cell=t;let a=n.getBoundingClientRect(),o=t.closest(`table`).getBoundingClientRect(),s=t.parentElement.getBoundingClientRect(),c=t.getBoundingClientRect(),l=i.childCount>1&&QJ(i,`row`),u=(i.firstChild?.childCount??0)>1&&QJ(i,`column`);Object.assign(this.grips.row.style,{top:`${s.top-a.top+s.height/2-11}px`,left:`${o.left-a.left-7}px`}),Object.assign(this.grips.column.style,{top:`${o.top-a.top-7}px`,left:`${c.left-a.left+c.width/2-11}px`}),this.grips.row.hidden=!l,this.grips.column.hidden=!u};locate(e){try{return nY(this.view.state,this.view.posAtDOM(e,0))}catch{return null}}start(e,t){let n=this.cell;if(!n||e.button!==0)return;let r=this.locate(n),i=n.parentElement?.parentElement;if(!r||!i)return;e.preventDefault();let a=this.grips[t];a.setPointerCapture(e.pointerId);let o=[...i.children].filter(e=>e instanceof HTMLTableRowElement),s=t===`row`?r.row:r.column,c=t===`row`?o:[...o[0]?.children??[]],l=t===`row`?[o[s]]:o.map(e=>e.children[s]).filter(Boolean);for(let e of l)e.classList.add(`dw-table-dragging`);this.drag={axis:t,tablePos:r.tablePos,from:s,slots:c,dimmed:l,to:s,cursorRow:r.row},a.addEventListener(`pointermove`,this.dragMove),a.addEventListener(`pointerup`,this.drop),a.addEventListener(`pointercancel`,this.cancel)}dragMove=e=>{let t=this.drag,n=this.host;if(!t||!n)return;let r=t.axis===`row`,i=r?e.clientY:e.clientX,a=t.slots.length;for(let[e,n]of t.slots.entries()){let t=n.getBoundingClientRect();if(i<(r?t.top+t.height/2:t.left+t.width/2)){a=e;break}}t.to=a>t.from?a-1:a;let o=n.getBoundingClientRect(),s=t.slots[0].closest(`table`).getBoundingClientRect(),c=t.slots.at(-1).getBoundingClientRect(),l=t.slots[a]?.getBoundingClientRect(),u=r?l?.top??c.bottom:l?.left??c.right;Object.assign(this.line.style,r?{top:`${u-o.top-1}px`,left:`${s.left-o.left}px`,width:`${s.width}px`,height:`2px`}:{top:`${s.top-o.top}px`,left:`${u-o.left-1}px`,width:`2px`,height:`${s.height}px`}),this.line.hidden=t.to===t.from};drop=()=>{let e=this.drag;if(this.cancel(),!e||e.to===e.from)return;let t=tY(this.view.state,e.tablePos,e.axis,e.from,e.to,e.cursorRow);t&&this.view.dispatch(t),this.view.focus()};cancel=()=>{let e=this.drag;for(let t of e?.dimmed??[])t.classList.remove(`dw-table-dragging`);this.drag=null,this.line.hidden=!0;for(let e of Object.values(this.grips))e.removeEventListener(`pointermove`,this.dragMove),e.removeEventListener(`pointerup`,this.drop),e.removeEventListener(`pointercancel`,this.cancel);this.hide()};update(){this.cell&&!this.cell.isConnected&&this.hide()}destroy(){this.cancel();for(let e of Object.values(this.grips))e.remove();this.line.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}};function aY(e){let t=[];return e.descendants((e,n)=>e.type.name!==`heading`||(t.push({level:Number(e.attrs.level)||1,text:e.textContent.trim(),pos:n}),!1)),t}function oY(e,t){let n=e.view.nodeDOM(t);n instanceof HTMLElement&&n.scrollIntoView({behavior:`smooth`,block:`start`}),e.isEditable&&e.commands.setTextSelection(t+1)}var sY=Jp.create({name:`tableOfContents`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`nav[data-type='toc']`}]},renderHTML(){return[`nav`,{"data-type":`toc`}]},addCommands(){return{insertTableOfContents:()=>({commands:e})=>e.insertContent({type:this.name})}},addNodeView(){return({editor:e})=>{let t=this.options.labels.blocks,n=document.createElement(`nav`);n.className=`dw-toc`,n.setAttribute(`data-type`,`toc`),n.setAttribute(`aria-label`,t.toc),n.contentEditable=`false`;let r=document.createElement(`p`);r.className=`dw-toc__title`,r.textContent=t.toc;let i=document.createElement(`ol`);i.className=`dw-toc__list`,n.append(r,i);let a=``,o=()=>{let n=aY(e.state.doc),r=JSON.stringify(n.map(e=>[e.level,e.text]));if(r===a){i.querySelectorAll(`a`).forEach((e,t)=>e.dataset.pos=String(n[t]?.pos??0));return}if(a=r,i.replaceChildren(),!n.length){let e=document.createElement(`li`);e.className=`dw-toc__empty`,e.textContent=t.tocEmpty,i.append(e);return}let o=Math.min(...n.map(e=>e.level));for(let t of n){let n=document.createElement(`li`);n.style.paddingLeft=`${(t.level-o)*1}rem`;let r=document.createElement(`a`);r.href=`#`,r.textContent=t.text||`…`,r.dataset.pos=String(t.pos),r.addEventListener(`click`,t=>{t.preventDefault(),oY(e,Number(r.dataset.pos))}),n.append(r),i.append(n)}};return o(),e.on(`update`,o),{dom:n,update:e=>e.type.name===`tableOfContents`,ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`),destroy:()=>e.off(`update`,o)}}}}),cY=(e,t)=>{let n=t.view.domAtPos(e).node,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return r?r.offsetParent!==null:!1},lY=(e,t,n)=>{for(let r=e.depth;r>0;--r){let i=e.node(r),a=t(i),o=cY(e.start(r),n);if(a&&o)return{pos:r>0?e.before(r):0,start:e.start(r),depth:r,node:i}}},uY=(e,t)=>{let{state:n,view:r,extensionManager:i}=e,{schema:a,selection:o}=n,{empty:s,$anchor:c}=o,l=!!i.extensions.find(e=>e.name===`gapCursor`);if(!s||c.parent.type!==a.nodes.detailsSummary||!l||t===`right`&&c.parentOffset!==c.parent.nodeSize-2)return!1;let u=yu(e=>e.type===a.nodes.details)(o);if(!u)return!1;let d=gu(u.node,e=>e.type===a.nodes.detailsContent);if(!d.length||cY(u.start+d[0].pos+1,e))return!1;let f=n.doc.resolve(u.pos+u.node.nodeSize),p=zw.findFrom(f,1,!1);if(!p)return!1;let{tr:m}=n,h=new zw(p);return m.setSelection(h),m.scrollIntoView(),r.dispatch(m),!0},dY=Jp.create({name:`details`,content:`detailsSummary detailsContent`,group:`block`,defining:!0,isolating:!0,allowGapCursor:!1,addOptions(){return{persist:!1,openClassName:`is-open`,HTMLAttributes:{},renderToggleButton:({element:e,isOpen:t})=>{e.setAttribute(`aria-label`,t?`Collapse details content`:`Expand details content`)}}},addAttributes(){return this.options.persist?{open:{default:!1,parseHTML:e=>e.hasAttribute(`open`),renderHTML:({open:e})=>e?{open:``}:{}}}:[]},parseHTML(){return[{tag:`details`}]},renderHTML({HTMLAttributes:e}){return[`details`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`details`,content:`block`}),addNodeView(){return({editor:e,getPos:t,node:n,HTMLAttributes:r})=>{let i=document.createElement(`div`),a=A(this.options.HTMLAttributes,r,{"data-type":this.name});Object.entries(a).forEach(([e,t])=>i.setAttribute(e,t));let o=document.createElement(`button`);o.type=`button`;let s=e=>{this.options.renderToggleButton({element:o,...e})};i.append(o);let c=document.createElement(`div`);i.append(c);let l=e=>{let{setToValue:t,node:r=n}=e||{};if(t!==void 0){if(t){if(i.classList.contains(this.options.openClassName))return;i.classList.add(this.options.openClassName)}else{if(!i.classList.contains(this.options.openClassName))return;i.classList.remove(this.options.openClassName)}}else i.classList.toggle(this.options.openClassName);let a=i.classList.contains(this.options.openClassName);s({isOpen:a,node:r});let o=new Event(`toggleDetailsContent`);c.querySelector(`:scope > div[data-type="detailsContent"]`)?.dispatchEvent(o)};return s({isOpen:!!n.attrs.open,node:n}),n.attrs.open&&setTimeout(()=>l()),o.addEventListener(`click`,()=>{if(l(),!this.options.persist)e.commands.focus(void 0,{scrollIntoView:!1});else if(e.isEditable&&typeof t==`function`){let{from:n,to:r}=e.state.selection;e.chain().command(({tr:e})=>{let n=t();if(typeof n!=`number`)return!1;let r=e.doc.nodeAt(n);return r?.type===this.type&&(e.setNodeMarkup(n,void 0,{open:!r.attrs.open}),!0)}).setTextSelection({from:n,to:r}).focus(void 0,{scrollIntoView:!1}).run()}}),{dom:i,contentDOM:c,ignoreMutation(e){if(e.type===`selection`)return!1;let t=e.target,n=i.contains(t);return o.contains(t)||!n||i===t},update:e=>e.type===this.type&&(e.attrs.open===void 0?s({isOpen:i.classList.contains(this.options.openClassName),node:e}):l({setToValue:e.attrs.open,node:e}),!0)}}},addCommands(){return{setDetails:()=>({state:e,chain:t})=>{let{schema:n,selection:r}=e,{$from:i,$to:a}=r,o=i.blockRange(a);if(!o)return!1;let s=e.doc.slice(o.start,o.end);if(!n.nodes.detailsContent.contentMatch.matchFragment(s.content))return!1;let c=s.toJSON()?.content||[];return t().insertContentAt({from:o.start,to:o.end},{type:this.name,content:[{type:`detailsSummary`},{type:`detailsContent`,content:c}]}).setTextSelection(o.start+2).run()},unsetDetails:()=>({state:e,chain:t})=>{let{selection:n,schema:r}=e,i=yu(e=>e.type===this.type)(n);if(!i)return!1;let a=gu(i.node,e=>e.type===r.nodes.detailsSummary),o=gu(i.node,e=>e.type===r.nodes.detailsContent);if(!a.length||!o.length)return!1;let s=a[0],c=o[0],l=i.pos,u=e.doc.resolve(l),d={from:l,to:l+i.node.nodeSize},f=c.node.content.toJSON()||[],p=[u.parent.type.contentMatch.defaultType?.create(null,s.node.content).toJSON(),...f];return t().insertContentAt(d,p).setTextSelection(l+1).run()}}},addKeyboardShortcuts(){return{Backspace:()=>{let{schema:e,selection:t}=this.editor.state,{empty:n,$anchor:r}=t;return!n||r.parent.type!==e.nodes.detailsSummary?!1:r.parentOffset===0?this.editor.commands.unsetDetails():this.editor.commands.command(({tr:e})=>{let t=r.pos-1,n=r.pos;return e.delete(t,n),!0})},Enter:({editor:e})=>{let{state:t,view:n}=e,{schema:r,selection:i}=t,{$head:a}=i;if(a.parent.type!==r.nodes.detailsSummary)return!1;let o=cY(a.after()+1,e),s=o?t.doc.nodeAt(a.after()):a.node(-2);if(!s)return!1;let c=o?0:a.indexAfter(-1),l=Ll(s.contentMatchAt(c));if(!l||!s.canReplaceWith(c,c,l))return!1;let u=l.createAndFill();if(!u)return!1;let d=o?a.after()+1:a.after(-1),f=t.tr.replaceWith(d,d,u),p=f.doc.resolve(d),m=w.near(p,1);return f.setSelection(m),f.scrollIntoView(),n.dispatch(f),!0},ArrowRight:({editor:e})=>uY(e,`right`),ArrowDown:({editor:e})=>uY(e,`down`)}},addProseMirrorPlugins(){return[new D({key:new Un(`detailsSelection`),appendTransaction:(e,t,n)=>{let{editor:r,type:i}=this;if(r.view.composing||!e.some(e=>e.selectionSet)||!t.selection.empty||!n.selection.empty||!sd(n,i.name))return;let{$from:a}=n.selection;if(cY(a.pos,r))return;let o=lY(a,e=>e.type===i,r);if(!o)return;let s=gu(o.node,e=>e.type===n.schema.nodes.detailsSummary);if(!s.length)return;let c=s[0],l=(t.selection.from{let t=document.createElement(`div`),n=A(this.options.HTMLAttributes,e,{"data-type":this.name,hidden:`hidden`});return Object.entries(n).forEach(([e,n])=>t.setAttribute(e,n)),t.addEventListener(`toggleDetailsContent`,()=>{t.toggleAttribute(`hidden`)}),{dom:t,contentDOM:t,ignoreMutation(e){return e.type===`selection`?!1:!t.contains(e.target)||t===e.target},update:e=>e.type===this.type}}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let{state:t,view:n}=e,{selection:r}=t,{$from:i,empty:a}=r,o=yu(e=>e.type===this.type)(r);if(!a||!o||!o.node.childCount)return!1;let s=i.index(o.depth),{childCount:c}=o.node;if(c!==s+1)return!1;let l=o.node.type.contentMatch.defaultType?.createAndFill();if(!l)return!1;let u=t.doc.resolve(o.pos+1),d=c-1,f=o.node.child(d),p=u.posAtIndex(d,o.depth);if(!f.eq(l))return!1;let m=i.node(-3);if(!m)return!1;let h=i.indexAfter(-3),g=Ll(m.contentMatchAt(h));if(!g||!m.canReplaceWith(h,h,g))return!1;let _=g.createAndFill();if(!_)return!1;let{tr:v}=t,y=i.after(-2);v.replaceWith(y,y,_);let b=v.doc.resolve(y),x=w.near(b,1);v.setSelection(x);let S=p,C=p+f.nodeSize;return v.delete(S,C),v.scrollIntoView(),n.dispatch(v),!0}}},...Xf({nodeName:`detailsContent`})}),pY=Jp.create({name:`detailsSummary`,content:`text*`,defining:!0,selectable:!1,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`summary`}]},renderHTML({HTMLAttributes:e}){return[`summary`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`detailsSummary`,content:`inline`})});function mY(e){return[dY.configure({persist:!1,HTMLAttributes:{class:`dw-toggle`},renderToggleButton:({element:t,isOpen:n})=>{t.setAttribute(`aria-label`,n?e.blocks.collapse:e.blocks.expand),t.setAttribute(`aria-expanded`,String(n))}}),pY,fY]}function hY(e={}){let t=e.labels??NR,n=null,r=Tp.create({name:`editorRef`,onCreate(){n=this.editor}}),i={host:e.files,labels:t,drawioUrl:e.drawioUrl,loadExcalidraw:e.loadExcalidraw,onError:e.onError},a=[r,Yk.configure({heading:{levels:[1,2,3,4,5,6]},codeBlock:!1,link:{openOnClick:!1,autolink:!0},undoRedo:e.collab||e.syncedDoc||e.rowBody||e.rowFragmentReadOnly?!1:void 0}),hT.configure({placeholder:e.placeholder??`Type '/' for commands…`}),pH.configure({host:e.files}),hH.configure({host:e.files,loadPdf:e.loadPdf,labels:t}),Lj.configure({lineNumbers:e.codeLineNumbers??!1}),MP,jP,RP,zP,...kP(),...AP(),rY.configure({labels:t}),HP.configure({labels:t}),gH.configure({host:e.files,onError:e.onError}),VJ(t,e.mentions),fV.configure({labels:t,me:()=>e.mentions?.me,onOpen:e.onOpenDate}),ZJ.configure({commands:YJ(t,e.files,e.onError,e.pages,!!e.loadExcalidraw,e.links),labels:t}),nV.configure({onSelect:e.onCommentSelect}),IJ(t,()=>n),qJ.configure({labels:t,load:e.loadMermaid}),sY.configure({labels:t}),YV.configure(i),XV.configure(i),LV.configure({host:e.pages,labels:t,onNavigate:e.onNavigate}),zV.configure({host:e.syncedPages,pages:e.pages,labels:t,onNavigate:e.onNavigate,nested:t=>hY({syncedDoc:t,files:e.files,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:``})}),...mY(t),sH.configure({labels:t}),cH.configure({labels:t}),iM.configure({labels:t,link:e.blockLink,onCopied:e.onBlockLinkCopied}),CH,qB.configure({labels:t,doc:e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc,readOnlyDoc:!!e.syncedDoc,undoScope:!e.rowBody,files:e.files,people:e.mentions,recordLink:e.blockLink,linkedPages:e.syncedPages,pages:e.pages,onNavigate:e.onNavigate,recordPage:e.recordPage,onLinkCopied:e.onBlockLinkCopied,me:()=>{let t=e.mentions?.me;return t?{id:t,name:e.collab?.user.name??``}:null},rowExtensions:n=>{let r=e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc;return hY({rowBody:n&&r&&!e.syncedDoc?{doc:r,fragment:n}:void 0,files:e.files,mentions:e.mentions,pages:e.pages,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadExcalidraw:e.loadExcalidraw,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:t.database.bodyPlaceholder,rowFragmentReadOnly:n&&e.syncedDoc?n:void 0})}})],o={trackedOrigins:[qz]};return e.rowBody?a.push(jw.configure({document:e.rowBody.doc,fragment:e.rowBody.fragment,yUndoOptions:o})):e.rowFragmentReadOnly?a.push(jw.configure({fragment:e.rowFragmentReadOnly})):e.syncedDoc?a.push(jw.configure({document:e.syncedDoc})):e.collab&&a.push(jw.configure({document:e.collab.provider.doc,yUndoOptions:o}),Iw.configure({provider:e.collab.provider,user:e.collab.user,render:gY})),a}function gY(e){let t=typeof e.color==`string`&&/^#[0-9a-f]{3,8}$/i.test(e.color)?e.color:`#888`,n=document.createElement(`span`);n.classList.add(`collaboration-carets__caret`),n.style.borderColor=t;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.setAttribute(`aria-hidden`,`true`),r.style.backgroundColor=t,r.textContent=typeof e.name==`string`?e.name:``,n.append(r),n}function _Y(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var vY=_Y();function yY(e){vY=e}var bY={exec:()=>null};function xY(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(CY.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var SY=(()=>{try{return!0}catch{return!1}})(),CY={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},wY=/^(?:[ \t]*(?:\n|$))+/,TY=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,EY=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,DY=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,OY=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,kY=/(?:[*+-]|\d{1,9}[.)])/,AY=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,jY=xY(AY).replace(/bull/g,kY).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),MY=xY(AY).replace(/bull/g,kY).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),NY=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,PY=/^[^\n]+/,FY=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,IY=xY(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,FY).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),LY=xY(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,kY).getRegex(),RY=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,zY=/\x3C!--(?:-?>|[\s\S]*?(?:-->|$))/,BY=xY(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,zY).replace(`tag`,RY).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),VY=xY(NY).replace(`hr`,DY).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,RY).getRegex(),HY={blockquote:xY(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,VY).getRegex(),code:TY,def:IY,fences:EY,heading:OY,hr:DY,html:BY,lheading:jY,list:LY,newline:wY,paragraph:VY,table:bY,text:PY},UY=xY(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,DY).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,RY).getRegex(),WY={...HY,lheading:MY,table:UY,paragraph:xY(NY).replace(`hr`,DY).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,UY).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,RY).getRegex()},GY={...HY,html:xY(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,zY).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:bY,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:xY(NY).replace(`hr`,DY).replace(`heading`,` *#{1,6} *[^ +]`).replace(`lheading`,jY).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},KY=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,qY=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,JY=/^( {2,}|\\)\n(?!\s*$)/,YY=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,SY?"(?`+)[^`]+\k(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),iX=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,aX=xY(iX,`u`).replace(/punct/g,XY).getRegex(),oX=xY(iX,`u`).replace(/punct/g,eX).getRegex(),sX=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,cX=xY(sX,`gu`).replace(/notPunctSpace/g,QY).replace(/punctSpace/g,ZY).replace(/punct/g,XY).getRegex(),lX=xY(sX,`gu`).replace(/notPunctSpace/g,nX).replace(/punctSpace/g,tX).replace(/punct/g,eX).getRegex(),uX=xY(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,QY).replace(/punctSpace/g,ZY).replace(/punct/g,XY).getRegex(),dX=xY(/\\(punct)/,`gu`).replace(/punct/g,XY).getRegex(),fX=xY(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),pX=xY(zY).replace(`(?:-->|$)`,`-->`).getRegex(),mX=xY(`^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^`).replace(`comment`,pX).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),hX=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,gX=xY(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,hX).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),_X=xY(/^!?\[(label)\]\[(ref)\]/).replace(`label`,hX).replace(`ref`,FY).getRegex(),vX=xY(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,FY).getRegex(),yX=xY(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,_X).replace(`nolink`,vX).getRegex(),bX=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,xX={_backpedal:bY,anyPunctuation:dX,autolink:fX,blockSkip:rX,br:JY,code:qY,del:bY,emStrongLDelim:aX,emStrongRDelimAst:cX,emStrongRDelimUnd:uX,escape:KY,link:gX,nolink:vX,punctuation:$Y,reflink:_X,reflinkSearch:yX,tag:mX,text:YY,url:bY},SX={...xX,link:xY(/^!?\[(label)\]\((.*?)\)/).replace(`label`,hX).getRegex(),reflink:xY(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,hX).getRegex()},CX={...xX,emStrongRDelimAst:lX,emStrongLDelim:oX,url:xY(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,bX).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:xY(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\":`>`,'"':`"`,"'":`'`},OX=e=>DX[e];function kX(e,t){if(t){if(CY.escapeTest.test(e))return e.replace(CY.escapeReplace,OX)}else if(CY.escapeTestNoEncode.test(e))return e.replace(CY.escapeReplaceNoEncode,OX);return e}function AX(e){try{e=encodeURI(e).replace(CY.percentDecode,`%`)}catch{return null}return e}function jX(e,t){let n=e.replace(CY.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(CY.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length0?-2:-1}function PX(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function FX(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(` +`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(` +`)}var IX=class{options;rules;lexer;constructor(e){this.options=e||vY}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:MX(e,` +`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=FX(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=MX(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:MX(t[0],` +`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=MX(t[0],` +`).split(` +`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;o1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=t[2].split(` +`,1)[0].replace(this.rules.other.listReplaceTabs,e=>` `.repeat(3*e.length)),l=e.split(` +`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=t[2].search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+` +`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d);for(;e;){let f=e.split(` +`,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=` +`+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=` +`+l}!u&&!l.trim()&&(u=!0),r+=f+` +`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;ee.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===` +`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=MX(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=NX(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),PX(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return PX(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},LX=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||vY,this.options.tokenizer=this.options.tokenizer||new IX,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:CY,block:TX.normal,inline:EX.normal};this.options.pedantic?(t.block=TX.pedantic,t.inline=EX.pedantic):this.options.gfm&&(t.block=TX.gfm,t.inline=this.options.breaks?EX.breaks:EX.gfm),this.tokenizer.rules=t}static get rules(){return{block:TX,inline:EX}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(CY.carriageReturn,` +`),this.blockTokens(e,this.tokens);for(let e=0;e(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=` +`:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(` +`)?``:` +`)+r.raw,n.text+=` +`+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if((r=this.tokenizer.fences(e))||(r=this.tokenizer.heading(e))||(r=this.tokenizer.hr(e))||(r=this.tokenizer.blockquote(e))||(r=this.tokenizer.list(e))||(r=this.tokenizer.html(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(` +`)?``:` +`)+r.raw,n.text+=` +`+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let a=t.at(-1);n&&a?.type===`paragraph`?(a.raw+=(a.raw.endsWith(` +`)?``:` +`)+r.raw,a.text+=` +`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(` +`)?``:` +`)+r.raw,n.text+=` +`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``;for(;e;){a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,o))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},RX=class{options;parser;constructor(e){this.options=e||vY}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(CY.notSpaceStart)?.[0],i=e.replace(CY.endingNewline,``)+` +`;return r?`
`+(n?i:kX(i,!0))+`
+`:`
`+(n?i:kX(i,!0))+`
+`}blockquote({tokens:e}){return`
+${this.parser.parse(e)}
+`}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`${this.parser.parseInline(e)} +`}hr(e){return`
+`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t +`+r+` +`}listitem(e){let t=``;if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type===`paragraph`?(e.tokens[0].text=n+` `+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type===`text`&&(e.tokens[0].tokens[0].text=n+` `+kX(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:`text`,raw:n+` `,text:n+` `,escaped:!0}):t+=n+` `}return t+=this.parser.parse(e.tokens,!!e.loose),`
  • ${t}
  • +`}checkbox({checked:e}){return``}paragraph({tokens:e}){return`

    ${this.parser.parseInline(e)}

    +`}table(e){let t=``,n=``;for(let t=0;t${r}`,` + +`+t+` +`+r+`
    +`}tablerow({text:e}){return` +${e} +`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+` +`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${kX(e,!0)}`}br(e){return`
    `}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=AX(e);if(i===null)return r;e=i;let a=`
    `+r+``,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=AX(e);if(i===null)return kX(n);e=i;let a=`${n}`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:kX(e.text)}},zX=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},BX=class e{options;renderer;textRenderer;constructor(e){this.options=e||vY,this.options.renderer=this.options.renderer||new RX,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new zX}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new RX(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new IX(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new VX;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=VX.passThroughHooks.has(n)?e=>{if(this.defaults.async&&VX.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return LX.lex(e,t??this.defaults)}parser(e,t){return BX.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?LX.lex:LX.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?BX.parse:BX.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?LX.lex:LX.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?BX.parse:BX.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=` +Please report this to https://github.com/markedjs/marked.`,e){let e=`

    An error occurred:

    `+kX(n.message+``,!0)+`
    `;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function UX(e,t){return HX.parse(e,t)}UX.options=UX.setOptions=function(e){return HX.setOptions(e),UX.defaults=HX.defaults,yY(UX.defaults),UX},UX.getDefaults=_Y,UX.defaults=vY,UX.use=function(...e){return HX.use(...e),UX.defaults=HX.defaults,yY(UX.defaults),UX},UX.walkTokens=function(e,t){return HX.walkTokens(e,t)},UX.parseInline=HX.parseInline,UX.Parser=BX,UX.parser=BX.parse,UX.Renderer=RX,UX.TextRenderer=zX,UX.Lexer=LX,UX.lexer=LX.lex,UX.Tokenizer=IX,UX.Hooks=VX,UX.parse=UX,UX.options,UX.setOptions,UX.use,UX.walkTokens,UX.parseInline,BX.parse,LX.lex;function WX(e){let t=e??NR;return{...mF,...t.edgeless,colors:{...mF.colors,...t.colors}}}function GX(e){let t=e?.surface;return Array.isArray(t?.elements)?t.elements:[]}function KX(e,t,n){let r={...n,placeholder:n.placeholder??``},i=new Vp({element:e,editable:t.kind!==`json`&&t.editable,content:t.kind===`json`?t.content:void 0,extensions:t.kind===`page`?hY({...r,collab:{provider:t.provider,user:t.user}}):t.kind===`body`?hY({...r,rowBody:{doc:t.doc,fragment:t.fragment}}):hY(r),editorProps:{attributes:{class:`dw-prose`}}});return{destroy:()=>i.destroy(),focus:()=>i.commands.focus(`end`),setEditable:e=>i.setEditable(e&&t.kind!==`json`)}}function qX(e,t){let n=!!t.provider,r,i=null;if(t.provider)r=t.provider.doc;else{i=new Cv,r=i;let e=t.content;i.transact(()=>ZL(i.getXmlFragment(`default`),e?.content??[]));let n=GX(e);if(n.length){let e=new iR(i,{undo:!1});e.load(n),e.destroy()}}let a={...t};delete a.provider,delete a.content;let o=new SR(e,{doc:r,editable:n&&t.editable,notes:{mount:(e,r)=>{let i=n?r.page?{kind:`page`,provider:t.provider,user:t.user??{name:`?`,color:`#888`},editable:r.editable}:{kind:`body`,doc:r.doc,fragment:r.fragment,editable:r.editable}:{kind:`json`,content:r.page&&t.content?t.content:{type:`doc`,content:XL(r.fragment)}};return t.mountNote?t.mountNote(e,i):KX(e,i,a)}},labels:WX(t.labels),files:t.files,links:t.links,embedSource:eH,styles:t.styles,onStyles:t.onStyles,viewKey:t.viewKey,pageTitle:t.pageTitle,undo:n,onError:t.onError,onComment:t.onComment,onCommentSelect:t.onCommentSelect});return{view:o,setEditable:e=>o.setEditable(n&&e),destroy:()=>{o.destroy(),i?.destroy()}}}function JX(e,t,n){let r=Zj(t),i=RB(t);if(!r&&!i)return()=>{};let a=()=>i?BB(e,i.database,i.row):rM(e,r),o=!1,s,c=()=>{clearTimeout(s),s=setTimeout(()=>{o||e.isDestroyed||!a()||(o=!0,l(),n?.())},50)},l=()=>{e.off(`transaction`,c),clearTimeout(u)},u=setTimeout(l,5e3);return e.on(`transaction`,c),c(),()=>{l(),clearTimeout(s)}}var YX=3e4,XX=class extends pm{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Fh();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&ZX(this,t,`timeout`)},mm(YX/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,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:Fh()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),tg(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},ZX=(e,t,n)=>{let r=[];for(let n=0;n0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},QX=(e,t,n=e.states)=>{let r=t.length,i=Fm();j(i,r);for(let a=0;a{let r=hh(t),i=Fh(),a=[],o=[],s=[],c=[],l=M(r);for(let t=0;t0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},eZ=(e,t)=>{j(e,0),qm(e,Jv(t))},tZ=(e,t,n)=>{j(e,1),qm(e,Hv(t,n))},nZ=(e,t,n)=>tZ(t,n,vh(e)),rZ=(e,t,n,r)=>{try{zv(t,vh(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},iZ=(e,t)=>{j(e,2),qm(e,t)},aZ=rZ,oZ=(e,t,n,r,i)=>{let a=M(e);switch(a){case 0:nZ(e,t,n);break;case 1:rZ(e,n,r,i);break;case 2:aZ(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},sZ=0,cZ=1,lZ=4401,uZ=4404,dZ=4409,fZ=class{opts;doc=new Cv;awareness=new XX(this.doc);status=`connecting`;synced=!1;ws=null;retries=0;retryTimer;destroyed=!1;listeners=new Set;constructor(e){this.opts=e,this.doc.on(`update`,this.onDocUpdate),this.awareness.on(`update`,this.onAwarenessUpdate),e.readOnly&&this.awareness.setLocalState(null),window.addEventListener(`beforeunload`,this.onUnload),this.connect()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}destroy(){this.destroyed||(this.destroyed=!0,this.listeners.clear(),clearTimeout(this.retryTimer),window.removeEventListener(`beforeunload`,this.onUnload),ZX(this.awareness,[this.doc.clientID],`local`),this.doc.off(`update`,this.onDocUpdate),this.awareness.off(`update`,this.onAwarenessUpdate),this.ws?.close(),this.awareness.destroy(),this.doc.destroy(),this.listeners.clear())}set(e,t=this.synced){(e!==this.status||t!==this.synced)&&(this.status=e,this.synced=t,this.listeners.forEach(e=>e()))}connect(){let e=new WebSocket(`${this.opts.url}?page=${encodeURIComponent(this.opts.page)}`);e.binaryType=`arraybuffer`,this.ws=e,e.onopen=()=>{e.send(this.opts.token()??``);let t=Fm();j(t,sZ),eZ(t,this.doc),e.send(Rm(t)),this.awareness.getLocalState()!==null&&this.sendAwareness([this.doc.clientID])},e.onmessage=e=>this.onMessage(new Uint8Array(e.data)),e.onclose=t=>{if(this.ws!==e)return;this.ws=null;let n=[...this.awareness.getStates().keys()].filter(e=>e!==this.doc.clientID);ZX(this.awareness,n,this),this.destroyed||(t.code===lZ||t.code===uZ?this.set(`denied`,!1):t.code===dZ?this.set(`changed`):(this.set(`offline`),this.retryTimer=setTimeout(()=>this.connect(),Math.min(1e3*2**this.retries++,3e4))))}}onMessage(e){let t=hh(e),n=M(t);if(n===sZ){let e=Fm();j(e,sZ);let n=oZ(t,e,this.doc,this);Lm(e)>1&&!this.opts.readOnly&&this.ws?.send(Rm(e)),n===1&&(this.retries=0,this.set(`connected`,!0))}else n===cZ&&$X(this.awareness,vh(t),this)}onDocUpdate=(e,t)=>{if(t===this||this.opts.readOnly||this.ws?.readyState!==WebSocket.OPEN)return;let n=Fm();j(n,sZ),iZ(n,e),this.ws.send(Rm(n))};onAwarenessUpdate=({added:e,updated:t,removed:n},r)=>{r===this||this.opts.readOnly||this.sendAwareness([...e,...t,...n])};sendAwareness(e){if(this.ws?.readyState!==WebSocket.OPEN)return;let t=Fm();j(t,cZ),qm(t,QX(this.awareness,e)),this.ws.send(Rm(t))}onUnload=()=>ZX(this.awareness,[this.doc.clientID],`unload`)},pZ=`.dw-db-peek, .dw-db-pop, .dw-block-menu`,mZ={bold:e=>e.chain().focus().toggleBold().run(),italic:e=>e.chain().focus().toggleItalic().run(),strike:e=>e.chain().focus().toggleStrike().run(),code:e=>e.chain().focus().toggleCode().run(),heading1:e=>e.chain().focus().toggleHeading({level:1}).run(),heading2:e=>e.chain().focus().toggleHeading({level:2}).run(),heading3:e=>e.chain().focus().toggleHeading({level:3}).run(),bulletList:e=>e.chain().focus().toggleBulletList().run(),orderedList:e=>e.chain().focus().toggleOrderedList().run(),blockquote:e=>e.chain().focus().toggleBlockquote().run(),codeBlock:e=>e.chain().focus().toggleCodeBlock().run(),underline:e=>e.chain().focus().toggleUnderline().run(),taskList:e=>e.chain().focus().toggleTaskList().run(),callout:e=>e.isActive(`callout`)?e.chain().focus().unsetCallout().run():e.chain().focus().setCallout().run(),table:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),undo:e=>e.chain().focus().undo().run(),redo:e=>e.chain().focus().redo().run()},hZ=[[`bold`,e=>e.isActive(`bold`)],[`italic`,e=>e.isActive(`italic`)],[`strike`,e=>e.isActive(`strike`)],[`code`,e=>e.isActive(`code`)],[`heading1`,e=>e.isActive(`heading`,{level:1})],[`heading2`,e=>e.isActive(`heading`,{level:2})],[`heading3`,e=>e.isActive(`heading`,{level:3})],[`bulletList`,e=>e.isActive(`bulletList`)],[`orderedList`,e=>e.isActive(`orderedList`)],[`blockquote`,e=>e.isActive(`blockquote`)],[`codeBlock`,e=>e.isActive(`codeBlock`)],[`underline`,e=>e.isActive(`underline`)],[`taskList`,e=>e.isActive(`taskList`)],[`callout`,e=>e.isActive(`callout`)],[`table`,e=>e.isActive(`table`)]],gZ=class{el;send;editor;provider=null;lastState=``;editable=!0;overlay=!1;overlays=new MutationObserver(()=>this.reportOverlay());inner=null;onFocusIn=e=>this.track(e.target);canvas=null;canvasEl=null;mode=`page`;lastContent=null;title=``;labels={...NR,blocks:{...NR.blocks}};transcribeOn=!1;words=null;pendingTranscripts=new Map;nextTranscript=1;picked=null;files={resolve:e=>e};constructor(e,t){this.el=e,this.send=t,Object.defineProperty(this.files,"transcribe",{get:()=>this.transcribeOn?(e,t)=>this.requestTranscript(e,t):void 0}),this.editor=this.create({}),this.overlays.observe(document.body,{childList:!0}),document.addEventListener(`focusin`,this.onFocusIn),t({type:`ready`,version:4})}receive(e){try{let t=typeof e==`string`?JSON.parse(e):e;this.handle(t)}catch(e){this.send({type:`error`,message:e instanceof Error?e.message:String(e)})}}get content(){return this.editor.getJSON()}destroy(){this.overlays.disconnect(),document.removeEventListener(`focusin`,this.onFocusIn),this.setInner(null),this.closeCanvas(),this.editor.destroy(),this.provider?.destroy()}handle(e){switch(e.type){case`hello`:this.send({type:`ready`,version:4}),this.lastState=``,this.reportState();return;case`setContent`:this.lastContent=e.content,this.editor.commands.setContent(e.content??``,{emitUpdate:!1}),this.reportState(),this.mode===`edgeless`&&!this.provider&&this.openCanvas();return;case`setEditable`:this.editable=e.editable,this.editor.setEditable(e.editable),this.canvas?.setEditable(e.editable);return;case`setTheme`:document.documentElement.classList.toggle(`dark`,e.dark);return;case`setLayout`:{let t=document.documentElement.classList;t.toggle(`dw-full-width`,e.fullWidth),t.toggle(`dw-font-serif`,e.font===`serif`),t.toggle(`dw-font-mono`,e.font===`mono`);return}case`command`:{let t=mZ[e.command];if(!t)throw Error(`unknown command ${e.command}`);t(this.target);return}case`focus`:this.editor.commands.focus();return;case`blur`:this.editor.commands.blur();return;case`connect`:this.connect(e);return;case`follow`:JX(this.editor,e.hash);return;case`setMode`:this.mode=e.mode===`edgeless`?`edgeless`:`page`,typeof e.title==`string`&&(this.title=e.title),this.mode===`edgeless`?this.openCanvas():this.closeCanvas();return;case`dismiss`:[...document.querySelectorAll(pZ)].at(-1)?.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,cancelable:!0}));return;case`setAi`:this.transcribeOn=e.transcribe,this.words=e.words,Object.assign(this.labels.blocks,{transcribe:e.words.transcribe,transcribeHint:e.words.transcribeHint,transcribing:e.words.transcribing,transcribeFailed:e.words.transcribeFailed}),vZ(this.editor);return;case`getSelection`:{let e=this.target,{from:t,to:n}=e.state.selection;this.picked={editor:e,from:t,to:n},this.send({type:`selection`,text:e.state.doc.textBetween(t,n,` + +`),before:e.state.doc.textBetween(Math.max(0,t-4e3),t,` + +`)});return}case`insertMarkdown`:this.insertMarkdown(e.markdown,e.mode);return;case`transcribed`:{let t=this.pendingTranscripts.get(e.id);if(!t)return;this.pendingTranscripts.delete(e.id),e.result&&this.words?t.resolve(Qp(e.result,this.words,_Z)):t.reject(Error(e.error||this.labels.blocks.transcribeFailed));return}default:throw Error(`unknown message ${e.type}`)}}requestTranscript(e,t){let n=this.nextTranscript++;return new Promise((r,i)=>{this.pendingTranscripts.set(n,{resolve:r,reject:i}),this.send({type:`transcribe`,id:n,src:e,name:t})})}insertMarkdown(e,t){let n=this.picked,r=n&&!n.editor.isDestroyed?n.editor:this.target,i=_Z(e);if(!i.trim())return;let a=r.state.doc.content.size,o=Math.min(n?.from??r.state.selection.from,a),s=Math.min(n?.to??r.state.selection.to,a);if(t===`replace`)r.chain().focus().insertContentAt({from:o,to:s},i).run();else{let e=r.state.doc.resolve(s);r.chain().focus().insertContentAt(e.depth>=1?e.after(1):s,i).run()}this.picked=null}connect(e){this.provider?.destroy();let t=new fZ({url:e.url,page:e.page,token:()=>e.token});t.onChange(()=>this.send({type:`collab`,status:t.status})),this.provider=t,this.editor.destroy(),this.editor=this.create({collab:{provider:t,user:e.user}}),this.mode===`edgeless`&&this.openCanvas()}openCanvas(){this.closeCanvas();let e=document.createElement(`div`);e.className=`dw-bridge-canvas`,document.body.append(e),this.canvasEl=e,this.el.hidden=!0,this.canvas=qX(e,{provider:this.provider??void 0,content:this.provider?void 0:this.lastContent??this.editor.getJSON(),editable:this.editable&&!!this.provider,pageTitle:()=>this.title,onNavigate:e=>this.send({type:`navigate`,path:e}),onError:e=>this.send({type:`error`,message:e instanceof Error?e.message:String(e)})})}closeCanvas(){this.canvas?.destroy(),this.canvas=null,this.canvasEl?.remove(),this.canvasEl=null,this.el.hidden=!1}create(e){return this.el.replaceChildren(),new Vp({element:this.el,editable:this.editable,extensions:hY({...e,files:this.files,labels:this.labels,onNavigate:e=>this.send({type:`navigate`,path:e})}),editorProps:{attributes:{class:`dw-prose`}},onUpdate:({editor:e})=>this.send({type:`change`,content:e.getJSON()}),onSelectionUpdate:()=>this.reportState(),onTransaction:()=>this.reportState(),onFocus:()=>this.reportState(),onBlur:()=>this.reportState()})}get target(){return this.inner&&!this.inner.isDestroyed?this.inner:this.editor}track(e){let t=(e instanceof Element?e.closest(`.ProseMirror`):null)?.editor;t&&(this.setInner(t===this.editor?null:t),this.reportState())}innerChanged=()=>this.reportState();innerGone=()=>{this.setInner(null),this.reportState()};setInner(e){if(e!==this.inner){if(this.inner){for(let e of[`selectionUpdate`,`transaction`,`focus`,`blur`])this.inner.off(e,this.innerChanged);this.inner.off(`destroy`,this.innerGone)}if(this.inner=e,e){for(let t of[`selectionUpdate`,`transaction`,`focus`,`blur`])e.on(t,this.innerChanged);e.on(`destroy`,this.innerGone)}}}reportOverlay(){let e=document.querySelector(pZ)!==null;e!==this.overlay&&(this.overlay=e,this.send({type:`overlay`,open:e}))}reportState(){let e=this.target;if(e.isDestroyed)return;let t={active:hZ.filter(([,t])=>t(e)).map(([e])=>e),canUndo:e.can().undo(),canRedo:e.can().redo(),focused:e.isFocused},n=JSON.stringify(t);n!==this.lastState&&(this.lastState=n,this.send({type:`state`,state:t}))}};function _Z(e){return UX.parse(e.trim(),{async:!1,gfm:!0})}function vZ(e){if(e.isDestroyed)return;let t=e.view.props.nodeViews??{},n=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)]));e.view.setProps({nodeViews:n})}function yZ(e){let t=JSON.stringify(e);window.DocwellNative?window.DocwellNative.postMessage(t):(window.parent.postMessage(t,`*`),console.debug(`[docwell bridge]`,e))}var bZ=new gZ(document.getElementById(`editor`),yZ);window.docwell={receive:e=>bZ.receive(e)}; diff --git a/Packages/editor-bridge/package.json b/Packages/editor-bridge/package.json index 4822aed..792fc14 100644 --- a/Packages/editor-bridge/package.json +++ b/Packages/editor-bridge/package.json @@ -14,7 +14,8 @@ "dependencies": { "@docwell/editor": "*", "@docwell/ui": "*", - "@tiptap/core": "^3.32.2" + "@tiptap/core": "^3.32.2", + "marked": "^16.4.2" }, "devDependencies": { "@tailwindcss/vite": "^4.3.3", diff --git a/Packages/editor-bridge/src/bridge.test.ts b/Packages/editor-bridge/src/bridge.test.ts index e840b86..d2af6ed 100644 --- a/Packages/editor-bridge/src/bridge.test.ts +++ b/Packages/editor-bridge/src/bridge.test.ts @@ -191,3 +191,61 @@ describe("EditorBridge", () => { expect(sent.filter((m) => m.type === "error")).toHaveLength(2); }); }); + +describe("EditorBridge AI", () => { + const words = { + transcribe: "Transkrybuj", + transcribeHint: "hint", + transcribing: "…", + transcribeFailed: "failed", + summaryTitle: "Summary of {name}", + transcript: "Transcript", + }; + + it("reports the selection and puts Markdown over it or below its block", () => { + const { bridge, sent } = setup(); + bridge.receive({ type: "setContent", content: doc }); + // Select "Hello". + (bridge as unknown as { editor: Editor }).editor.commands.setTextSelection({ from: 1, to: 6 }); + bridge.receive({ type: "getSelection" }); + expect(sent.at(-1)).toEqual({ type: "selection", text: "Hello", before: "" }); + bridge.receive({ type: "insertMarkdown", markdown: "**Hi** there", mode: "replace" }); + expect(bridge.content.content?.[0]).toMatchObject({ + type: "paragraph", + content: [{ text: "Hi", marks: [{ type: "bold" }] }, { text: " there" }], + }); + bridge.receive({ type: "getSelection" }); + bridge.receive({ type: "insertMarkdown", markdown: "- one\n- two", mode: "below" }); + expect(bridge.content.content?.map((n) => n.type)).toEqual(["paragraph", "bulletList", "paragraph"]); // the editor keeps an empty last line + }); + + it("shows Transcribe on media files once the app allows it, and inserts the result", async () => { + const { bridge, sent, el } = setup(); + const audio = { + type: "doc", + content: [ + { type: "fileAttachment", attrs: { url: "/api/v1/files/f1", name: "call.m4a", mime: "audio/mp4", size: 9 } }, + ], + }; + bridge.receive({ type: "setContent", content: audio }); + expect(el.querySelector("[data-testid=file-transcribe]")).toBeNull(); + bridge.receive({ type: "setAi", transcribe: true, words }); + const button = el.querySelector("[data-testid=file-transcribe]"); + expect(button?.textContent).toBe("Transkrybuj"); + button!.click(); + const ask = sent.at(-1); + expect(ask).toMatchObject({ type: "transcribe", src: "/api/v1/files/f1", name: "call.m4a" }); + bridge.receive({ + type: "transcribed", + id: (ask as { id: number }).id, + result: { name: "call.m4a", text: "Hello team. Ship on Monday.", summary: "- ship **Monday**" }, + }); + await new Promise((r) => setTimeout(r, 0)); + const types = bridge.content.content?.map((n) => n.type); + expect(types).toEqual(["fileAttachment", "heading", "bulletList", "details", "paragraph"]); + expect(JSON.stringify(bridge.content)).toContain("Summary of call.m4a"); + expect(JSON.stringify(bridge.content)).toContain("Hello team. Ship on Monday."); + bridge.receive({ type: "setAi", transcribe: false, words }); + expect(el.querySelector("[data-testid=file-transcribe]")).toBeNull(); + }); +}); diff --git a/Packages/editor-bridge/src/bridge.ts b/Packages/editor-bridge/src/bridge.ts index 0a73e3f..7c68e0a 100644 --- a/Packages/editor-bridge/src/bridge.ts +++ b/Packages/editor-bridge/src/bridge.ts @@ -1,11 +1,22 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { Editor, type JSONContent } from "@tiptap/core"; +import { transcriptHTML, type TranscriptResult } from "@docwell/editor/ai"; import { docwellExtensions, type ExtensionOptions } from "@docwell/editor/extensions"; +import type { FileHost } from "@docwell/editor/files"; +import { englishLabels, type EditorLabels } from "@docwell/editor/labels"; +import { marked } from "marked"; import { mountEdgeless, type Edgeless } from "@docwell/editor/edgeless"; import { followLink } from "@docwell/editor/hashlinks"; import { CollabProvider } from "@docwell/editor/provider"; -import { PROTOCOL_VERSION, type Command, type EditorMessage, type EditorState, type HostMessage } from "./protocol"; +import { + PROTOCOL_VERSION, + type Command, + type EditorMessage, + type EditorState, + type HostMessage, + type TranscribeWords, +} from "./protocol"; /** Panels and menus the editor opens over the page, topmost last in the DOM. */ const OVERLAYS = ".dw-db-peek, .dw-db-pop, .dw-block-menu"; @@ -78,11 +89,31 @@ export class EditorBridge { private lastContent: JSONContent | null = null; /** The page's title, shown on its note on the canvas. */ private title = ""; + /** The editor's words; setAi changes the Transcribe button's in place. */ + private readonly labels: EditorLabels = { ...englishLabels, blocks: { ...englishLabels.blocks } }; + private transcribeOn = false; + private words: TranscribeWords | null = null; + /** Transcriptions the app is working on, by request id. */ + private readonly pendingTranscripts = new Map< + number, + { resolve: (html: string) => void; reject: (e: Error) => void } + >(); + private nextTranscript = 1; + /** The range "getSelection" reported, for "insertMarkdown". */ + private picked: { editor: Editor; from: number; to: number } | null = null; + /** + * Attachments as the app sees them: links stay API paths, and media files + * can be transcribed while the app allows it. + */ + private readonly files: FileHost = { resolve: (src) => src }; constructor( private readonly el: HTMLElement, private readonly send: (msg: EditorMessage) => void, ) { + Object.defineProperty(this.files, "transcribe", { + get: () => (this.transcribeOn ? (src: string, name: string) => this.requestTranscript(src, name) : undefined), + }); this.editor = this.create({}); this.overlays.observe(document.body, { childList: true }); document.addEventListener("focusin", this.onFocusIn); @@ -173,11 +204,73 @@ export class EditorBridge { top?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })); return; } + case "setAi": + this.transcribeOn = msg.transcribe; + this.words = msg.words; + Object.assign(this.labels.blocks, { + transcribe: msg.words.transcribe, + transcribeHint: msg.words.transcribeHint, + transcribing: msg.words.transcribing, + transcribeFailed: msg.words.transcribeFailed, + }); + redrawNodeViews(this.editor); + return; + case "getSelection": { + const e = this.target; + const { from, to } = e.state.selection; + this.picked = { editor: e, from, to }; + this.send({ + type: "selection", + text: e.state.doc.textBetween(from, to, "\n\n"), + before: e.state.doc.textBetween(Math.max(0, from - 4000), from, "\n\n"), + }); + return; + } + case "insertMarkdown": + this.insertMarkdown(msg.markdown, msg.mode); + return; + case "transcribed": { + const p = this.pendingTranscripts.get(msg.id); + if (!p) return; + this.pendingTranscripts.delete(msg.id); + if (msg.result && this.words) p.resolve(transcriptHTML(msg.result as TranscriptResult, this.words, toHTML)); + else p.reject(new Error(msg.error || this.labels.blocks.transcribeFailed)); + return; + } default: throw new Error(`unknown message ${(msg as { type: string }).type}`); } } + /** Asks the app to transcribe a file; resolves with the HTML to insert. */ + private requestTranscript(src: string, name: string): Promise { + const id = this.nextTranscript++; + return new Promise((resolve, reject) => { + this.pendingTranscripts.set(id, { resolve, reject }); + this.send({ type: "transcribe", id, src, name }); + }); + } + + private insertMarkdown(markdown: string, mode: "replace" | "below"): void { + const picked = this.picked; + const e = picked && !picked.editor.isDestroyed ? picked.editor : this.target; + const html = toHTML(markdown); + if (!html.trim()) return; + const size = e.state.doc.content.size; + const from = Math.min(picked?.from ?? e.state.selection.from, size); + const to = Math.min(picked?.to ?? e.state.selection.to, size); + if (mode === "replace") { + e.chain().focus().insertContentAt({ from, to }, html).run(); + } else { + const $to = e.state.doc.resolve(to); + e.chain() + .focus() + .insertContentAt($to.depth >= 1 ? $to.after(1) : to, html) + .run(); + } + this.picked = null; + } + private connect(msg: Extract): void { this.provider?.destroy(); const provider = new CollabProvider({ url: msg.url, page: msg.page, token: () => msg.token }); @@ -222,7 +315,12 @@ export class EditorBridge { return new Editor({ element: this.el, editable: this.editable, - extensions: docwellExtensions({ ...opts, onNavigate: (path) => this.send({ type: "navigate", path }) }), + extensions: docwellExtensions({ + ...opts, + files: this.files, + labels: this.labels, + onNavigate: (path) => this.send({ type: "navigate", path }), + }), editorProps: { attributes: { class: "dw-prose" } }, onUpdate: ({ editor }) => this.send({ type: "change", content: editor.getJSON() }), onSelectionUpdate: () => this.reportState(), @@ -290,3 +388,25 @@ export class EditorBridge { this.send({ type: "state", state }); } } + +/** Markdown (an AI answer) as HTML for the editor, which keeps only what its schema knows. */ +function toHTML(markdown: string): string { + return marked.parse(markdown.trim(), { async: false, gfm: true }) as string; +} + +/** + * Draws every node view again, so ones that depend on the host (the + * Transcribe button) follow a change: new view functions make ProseMirror + * redraw them. + */ +function redrawNodeViews(editor: Editor): void { + if (editor.isDestroyed) return; + const current = editor.view.props.nodeViews ?? {}; + const fresh = Object.fromEntries( + Object.entries(current).map(([name, view]) => [ + name, + (...args: Parameters) => (view as (...a: typeof args) => ReturnType)(...args), + ]), + ); + editor.view.setProps({ nodeViews: fresh }); +} diff --git a/Packages/editor-bridge/src/protocol.ts b/Packages/editor-bridge/src/protocol.ts index 54e2a4e..6da43b8 100644 --- a/Packages/editor-bridge/src/protocol.ts +++ b/Packages/editor-bridge/src/protocol.ts @@ -54,7 +54,35 @@ export type HostMessage = */ | { type: "setMode"; mode: "page" | "edgeless"; title?: string } /** Edit the live document over docwell-server's /collab WebSocket. */ - | { type: "connect"; url: string; page: string; token: string; user: { name: string; color: string } }; + | { type: "connect"; url: string; page: string; token: string; user: { name: string; color: string } } + /** + * What AI can do on this page (ADR-15). With transcribe, audio and video + * files get a Transcribe button labelled with words (the app's language). + */ + | { type: "setAi"; transcribe: boolean; words: TranscribeWords } + /** Asks for the selected text; the editor answers "selection" and keeps that range. */ + | { type: "getSelection" } + /** Puts Markdown over the range kept by "getSelection", or below its block. */ + | { type: "insertMarkdown"; markdown: string; mode: "replace" | "below" } + /** The answer to a "transcribe" request: the result, or error. */ + | { + type: "transcribed"; + id: number; + error?: string; + result?: { name: string; text: string; summary: string; summaryError?: string }; + }; + +/** The words of the Transcribe button and of what it inserts. */ +export interface TranscribeWords { + transcribe: string; + transcribeHint: string; + transcribing: string; + transcribeFailed: string; + /** The heading over the summary; {name} is the file's name. */ + summaryTitle: string; + /** The toggle that holds the transcript. */ + transcript: string; +} /** What the toolbar needs to show which buttons are on. */ export interface EditorState { @@ -77,7 +105,11 @@ export type EditorMessage = * property picker); while one is, the back button should send "dismiss". */ | { type: "overlay"; open: boolean } + /** The selected text (empty when nothing is), and up to 4000 characters before it. */ + | { type: "selection"; text: string; before: string } + /** The user asked to transcribe a file (src is its /api/v1/files/ path); answer with "transcribed". */ + | { type: "transcribe"; id: number; src: string; name: string } | { type: "error"; message: string }; /** Bumped when a message changes shape, so the app can refuse a stale bundle. */ -export const PROTOCOL_VERSION = 3; +export const PROTOCOL_VERSION = 4; diff --git a/Packages/editor/package.json b/Packages/editor/package.json index 9b3a211..d9f9e61 100644 --- a/Packages/editor/package.json +++ b/Packages/editor/package.json @@ -11,7 +11,10 @@ "./provider": "./src/provider.ts", "./hashlinks": "./src/hashlinks.ts", "./editor.css": "./src/editor.css", - "./edgeless": "./src/edgeless.ts" + "./edgeless": "./src/edgeless.ts", + "./ai": "./src/ai.ts", + "./files": "./src/files.ts", + "./labels": "./src/labels.ts" }, "scripts": { "test": "vitest run" diff --git a/Packages/editor/src/ai.ts b/Packages/editor/src/ai.ts index c0d6bc6..4ba4a63 100644 --- a/Packages/editor/src/ai.ts +++ b/Packages/editor/src/ai.ts @@ -24,6 +24,54 @@ export interface AiWriteRequest { instruction?: string; } +/** What a transcription returned (the API's AiTranscript). */ +export interface TranscriptResult { + name: string; + text: string; + summary: string; + summaryError?: string; +} + +const escapeHTML = (s: string) => + s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!); + +/** Cuts a long transcript into paragraphs of a few sentences. */ +export function transcriptParagraphs(text: string, size = 600): string[] { + const out: string[] = []; + let cur = ""; + for (const part of text + .replace(/\s+/g, " ") + .trim() + .split(/(?<=[.!?…])\s+/)) { + if (cur && cur.length + part.length > size) { + out.push(cur); + cur = ""; + } + cur = cur ? `${cur} ${part}` : part; + } + if (cur) out.push(cur); + return out; +} + +/** + * The HTML a transcription puts below its file: the summary under a + * heading, and the whole transcript in a toggle. toHTML turns the + * summary's Markdown into HTML. + */ +export function transcriptHTML( + res: TranscriptResult, + words: { summaryTitle: string; transcript: string }, + toHTML: (markdown: string) => string, +): string { + let html = `

    ${escapeHTML(words.summaryTitle.replace("{name}", res.name))}

    `; + if (res.summary) html += toHTML(res.summary); + else if (res.summaryError) html += `

    ${escapeHTML(res.summaryError)}

    `; + const paras = transcriptParagraphs(res.text) + .map((p) => `

    ${escapeHTML(p)}

    `) + .join(""); + return `${html}
    ${escapeHTML(words.transcript)}
    ${paras}
    `; +} + /** * The host's AI. run streams the result (Markdown) to onText until it * resolves; it rejects with an Error whose message is shown. toHTML turns diff --git a/Packages/editor/src/index.ts b/Packages/editor/src/index.ts index 30cc749..e9e54bf 100644 --- a/Packages/editor/src/index.ts +++ b/Packages/editor/src/index.ts @@ -18,7 +18,15 @@ export { linkedRecord, openRecord, recordHash } from "./database/links"; export { followLink, isTargetHash } from "./hashlinks"; export { embedSource, type LinkHost, type LinkPreview } from "./embeds"; export { dateChoices, formatDate, type DateChoice } from "./dates"; -export { aiActions, type AiAction, type AiHost, type AiWriteRequest } from "./ai"; +export { + aiActions, + transcriptHTML, + transcriptParagraphs, + type AiAction, + type AiHost, + type AiWriteRequest, + type TranscriptResult, +} from "./ai"; export { default as DocwellEdgeless } from "./DocwellEdgeless.vue"; export type { ElementComment } from "@docwell/canvas"; export { diff --git a/Phone-App/integration_test/ai_test.dart b/Phone-App/integration_test/ai_test.dart new file mode 100644 index 0000000..7a35ea1 --- /dev/null +++ b/Phone-App/integration_test/ai_test.dart @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +// AI on a phone against a running docwell-server with AI set up (ADR-15): +// the chat, Transcribe in the real editor page, and the writing actions. +// Build the editor page first (npm run build:bridge), then on a device: +// +// flutter test integration_test/ai_test.dart \ +// --dart-define=SERVER=http://10.0.2.2:8080 --dart-define=EMAIL=… \ +// --dart-define=PASSWORD=… --dart-define=WORKSPACE=… --dart-define=PAGE=… +// +// PAGE needs a paragraph and an audio attachment; the workspace needs a +// profile with chat and speech-to-text models. Without SERVER it is skipped. + +import 'package:docwell_mobile/api/docwell_api.dart'; +import 'package:docwell_mobile/app.dart'; +import 'package:docwell_mobile/editor/ai_write_sheet.dart'; +import 'package:docwell_mobile/editor/bridge.dart'; +import 'package:docwell_mobile/editor/editor_screen.dart'; +import 'package:docwell_mobile/screens/ai_chat_screen.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +const server = String.fromEnvironment('SERVER'); +const email = String.fromEnvironment('EMAIL'); +const password = String.fromEnvironment('PASSWORD'); +const workspace = String.fromEnvironment('WORKSPACE'); +const pageId = String.fromEnvironment('PAGE'); + +/// Seconds to keep the screen still at each checkpoint, for screenshots. +const hold = int.fromEnvironment('HOLD'); + +Future holdScreen(WidgetTester tester) async { + if (hold <= 0) return; + final end = DateTime.now().add(Duration(seconds: hold)); + while (DateTime.now().isBefore(end)) { + await tester.pump(const Duration(milliseconds: 100)); + } +} + +Future pumpUntil( + WidgetTester tester, + bool Function() done, { + required String reason, + Duration timeout = const Duration(seconds: 60), +}) async { + final end = DateTime.now().add(timeout); + while (!done()) { + if (DateTime.now().isAfter(end)) fail('timed out: $reason'); + await tester.pump(const Duration(milliseconds: 100)); + } +} + +Future signIn() async { + final api = DocwellApi(server); + await api.login(email, password); + return api; +} + +/// Opens the page's saved content in the real editor page, with the same +/// AI wiring as PageScreen. +Future<(EditorBridge, List>)> openEditor( + WidgetTester tester, + DocwellApi api, { + required Widget Function(EditorBridge? bridge) below, +}) async { + final content = (await api.content(pageId)).content; + EditorBridge? bridge; + final changes = >[]; + late StateSetter rebuild; + await tester.pumpWidget( + MaterialApp( + home: StatefulBuilder( + builder: (context, set) { + rebuild = set; + return Scaffold( + body: Column( + children: [ + Expanded( + child: EditorScreen( + title: 'Onboarding', + content: content, + onBridge: (b) { + bridge = b; + b.onTranscribe = (id, src, _) => + transcribeForEditor(api, b, id, src); + }, + onChanged: changes.add, + ), + ), + below(bridge), + ], + ), + ); + }, + ), + ), + ); + await pumpUntil( + tester, + () => bridge?.isReady ?? false, + reason: 'editor ready', + ); + rebuild(() {}); + await tester.pump(); + return (bridge!, changes); +} + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('chat answers with sources', (tester) async { + final api = await signIn(); + final user = await api.me(); + await tester.pumpWidget( + MaterialApp( + home: AiChatScreen( + session: AppSession(api: api, user: user), + workspace: workspace, + ), + ), + ); + await tester.pumpAndSettle(); + await tester.enterText( + find.byKey(const Key('ai-input')), + 'What do new hires get on day one?', + ); + await tester.tap(find.byKey(const Key('ai-send'))); + await pumpUntil( + tester, + () => find + .textContaining('most relevant page', findRichText: true) + .evaluate() + .isNotEmpty, + reason: 'streamed answer', + ); + // The stored turn replaces the streamed one; its source is listed. + await pumpUntil( + tester, + () => find.widgetWithText(ListTile, 'Onboarding').evaluate().isNotEmpty, + reason: 'cited source', + ); + await holdScreen(tester); + }, skip: server.isEmpty); + + testWidgets( + 'Transcribe in the editor inserts summary and transcript', + (tester) async { + final api = await signIn(); + final (bridge, changes) = await openEditor( + tester, + api, + below: (_) => const SizedBox.shrink(), + ); + final avail = await api.aiAvailability(workspace); + expect(avail.transcribe, isTrue); + await bridge.setAi( + transcribe: true, + words: { + 'transcribe': 'Transcribe', + 'transcribeHint': '', + 'transcribing': 'Transcribing…', + 'transcribeFailed': 'failed', + 'summaryTitle': 'Summary of {name}', + 'transcript': 'Transcript', + }, + ); + await tester.pump(const Duration(milliseconds: 300)); + await bridge.evaluate( + "document.querySelector('[data-testid=file-transcribe]').click()", + ); + await pumpUntil( + tester, + () => + changes.any((c) => c.toString().contains('Summary of standup.m4a')), + reason: 'transcript inserted', + ); + await holdScreen(tester); + final doc = changes.last.toString(); + expect(doc, contains('details')); + expect(doc, contains('Ana will send the report by Friday.')); + }, + skip: server.isEmpty, + ); + + testWidgets('writing actions replace the selection', (tester) async { + final api = await signIn(); + final (bridge, changes) = await openEditor( + tester, + api, + below: (bridge) => Builder( + builder: (context) => TextButton( + key: const Key('open-ai'), + onPressed: bridge == null + ? null + : () => AiWriteSheet.open( + context, + api: api, + bridge: bridge, + workspace: workspace, + ), + child: const Text('AI'), + ), + ), + ); + await bridge.setEditable(true); + await bridge.focus(); + // Select the first paragraph, as a long press would. + await bridge.evaluate(''' + const p = document.querySelector('.ProseMirror p'); + const r = document.createRange(); + r.selectNodeContents(p); + const s = getSelection(); + s.removeAllRanges(); + s.addRange(r); + '''); + await tester.pump(const Duration(milliseconds: 300)); + await tester.tap(find.byKey(const Key('open-ai'))); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('ai-rewrite'))); + await pumpUntil( + tester, + () => find.byKey(const Key('ai-replace')).evaluate().isNotEmpty, + reason: 'rewritten text', + ); + await holdScreen(tester); + await tester.tap(find.byKey(const Key('ai-replace'))); + await tester.pumpAndSettle(); + await pumpUntil( + tester, + () => changes.any( + (c) => + c.toString().contains('NEW HIRES GET A LAPTOP ON THEIR FIRST DAY.'), + ), + reason: 'selection replaced', + ); + final first = + ((changes.last['content'] as List).first as Map)['content'] as List; + expect((first.first as Map)['marks'], [ + {'type': 'bold'}, + ]); + }, skip: server.isEmpty); +} diff --git a/Phone-App/integration_test/editor_test.dart b/Phone-App/integration_test/editor_test.dart index 3407bc9..2818f26 100644 --- a/Phone-App/integration_test/editor_test.dart +++ b/Phone-App/integration_test/editor_test.dart @@ -76,7 +76,7 @@ void main() { final first = (changes.last['content'] as List).first as Map; expect(first['type'], 'heading'); - expect(first['attrs'], {'level': 1}); + expect((first['attrs'] as Map)['level'], 1); expect((first['content'] as List).first['text'], 'Hello from Flutter'); expect(bridge!.state.canUndo, isTrue); diff --git a/Phone-App/lib/api/docwell_api.dart b/Phone-App/lib/api/docwell_api.dart index a85ac02..ed591fe 100644 --- a/Phone-App/lib/api/docwell_api.dart +++ b/Phone-App/lib/api/docwell_api.dart @@ -230,27 +230,68 @@ class DocwellApi { /// Asks a question; the answer streams as events: sources {citations}, /// delta {text}, then done {user, message} or error {message}. - Stream ask(String session, String question) async* { + Stream ask(String session, String question) => _stream( + '/api/v1/ai/sessions/${_id(session)}/messages', + {'content': question}, + ); + + /// A writing action on text (AiWriteInput); the result (Markdown) streams + /// as delta {text} events, then done {} or error {message}. + Stream write( + String workspace, { + required String action, + required String text, + String before = '', + String language = '', + String instruction = '', + }) => _stream('/api/v1/workspaces/${_id(workspace)}/ai/write', { + 'action': action, + 'text': text, + 'before': before, + 'language': language, + 'instruction': instruction, + }); + + /// Turns an audio or video attachment into text and a summary. Long + /// recordings take a while, so this waits up to 30 minutes. + Future transcribe(String fileId) async { final req = http.Request( 'POST', - Uri.parse('$baseUrl/api/v1/ai/sessions/${_id(session)}/messages'), + Uri.parse('$baseUrl/api/v1/files/${_id(fileId)}/transcribe'), ); + req.headers['Accept'] = 'application/json'; + req.headers['Content-Type'] = 'application/json'; + if (token != null) req.headers['Authorization'] = 'Bearer $token'; + req.body = jsonEncode({'summarize': true}); + final res = await http.Response.fromStream( + await _client.send(req).timeout(const Duration(minutes: 30)), + ); + final text = utf8.decode(res.bodyBytes); + if (res.statusCode >= 300) throw _apiError(res.statusCode, text); + return AiTranscript.fromJson(jsonDecode(text) as Map); + } + + DocwellApiException _apiError(int status, String text) { + Map data = {}; + try { + data = jsonDecode(text) as Map; + } catch (_) {} + return DocwellApiException( + status, + code: data['error'] as String? ?? 'unknown', + message: data['message'] as String? ?? '', + ); + } + + Stream _stream(String path, Map body) async* { + final req = http.Request('POST', Uri.parse('$baseUrl$path')); req.headers['Accept'] = 'text/event-stream'; req.headers['Content-Type'] = 'application/json'; if (token != null) req.headers['Authorization'] = 'Bearer $token'; - req.body = jsonEncode({'content': question}); + req.body = jsonEncode(body); final res = await _client.send(req).timeout(const Duration(seconds: 30)); if (res.statusCode >= 300) { - final text = await res.stream.bytesToString(); - Map data = {}; - try { - data = jsonDecode(text) as Map; - } catch (_) {} - throw DocwellApiException( - res.statusCode, - code: data['error'] as String? ?? 'unknown', - message: data['message'] as String? ?? '', - ); + throw _apiError(res.statusCode, await res.stream.bytesToString()); } yield* parseEventStream(res.stream.transform(utf8.decoder)); } diff --git a/Phone-App/lib/editor/ai_write_sheet.dart b/Phone-App/lib/editor/ai_write_sheet.dart new file mode 100644 index 0000000..5b80c36 --- /dev/null +++ b/Phone-App/lib/editor/ai_write_sheet.dart @@ -0,0 +1,325 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import 'dart:async'; + +import 'package:flutter/material.dart'; + +import '../api/docwell_api.dart'; +import '../l10n.dart'; +import '../screens/markdown_view.dart'; +import '../screens/widgets.dart'; +import 'bridge.dart'; + +/// Answers the editor's Transcribe request [id] for the file at [src] +/// (`/api/v1/files/`): the transcript and summary, or why not. +Future transcribeForEditor( + DocwellApi api, + EditorBridge bridge, + int id, + String src, +) async { + final match = RegExp(r'^/api/v1/files/([^/?#]+)').firstMatch(src); + if (match == null) { + await bridge.answerTranscript(id, error: tr('aiTranscribeFailed')); + return; + } + try { + final t = await api.transcribe(Uri.decodeComponent(match.group(1)!)); + await bridge.answerTranscript( + id, + result: { + 'name': t.name, + 'text': t.text, + 'summary': t.summary, + 'summaryError': ?t.summaryError, + }, + ); + } catch (e) { + await bridge.answerTranscript(id, error: describeError(e)); + } +} + +/// Writing actions on the editor's selection (ADR-15), as on the web: the +/// result streams in, then replaces the selection or goes below it. +class AiWriteSheet extends StatefulWidget { + const AiWriteSheet({ + super.key, + required this.api, + required this.bridge, + required this.workspace, + required this.text, + required this.before, + }); + + final DocwellApi api; + final EditorBridge bridge; + final String workspace; + + /// The selection, and the text before it (for "continue"). + final String text; + final String before; + + /// Opens the sheet for the editor's current selection. + static Future open( + BuildContext context, { + required DocwellApi api, + required EditorBridge bridge, + required String workspace, + }) async { + final sel = await bridge.selection(); + if (!context.mounted) return; + await showModalBottomSheet( + context: context, + isScrollControlled: true, + showDragHandle: true, + builder: (_) => AiWriteSheet( + api: api, + bridge: bridge, + workspace: workspace, + text: sel.text, + before: sel.before, + ), + ); + } + + @override + State createState() => _AiWriteSheetState(); +} + +const _languages = [ + 'English', + 'Polski', + 'Deutsch', + 'Français', + 'Español', + 'Italiano', + 'Português', + 'Nederlands', + 'Українська', +]; + +class _AiWriteSheetState extends State { + final _instruction = TextEditingController(); + String _result = ''; + String? _error; + bool _busy = false; + String _action = ''; + String _language = ''; + StreamSubscription? _stream; + + bool get _hasText => widget.text.trim().isNotEmpty; + + @override + void initState() { + super.initState(); + // Translating into English is the usual case, unless the app is in it. + _language = appLanguage == 'en' ? 'Deutsch' : 'English'; + } + + @override + void dispose() { + _stream?.cancel(); + _instruction.dispose(); + super.dispose(); + } + + Future _run(String action) async { + if (_busy) return; + if (action == 'custom' && _instruction.text.trim().isEmpty) return; + setState(() { + _action = action; + _busy = true; + _result = ''; + _error = null; + }); + final done = Completer(); + _stream = widget.api + .write( + widget.workspace, + action: action, + text: widget.text, + before: widget.before, + language: _language, + instruction: _instruction.text.trim(), + ) + .listen( + (e) { + if (!mounted) return; + setState(() { + if (e.name == 'delta') _result += e.data['text'] as String? ?? ''; + if (e.name == 'error') { + _error = e.data['message'] as String? ?? tr('aiFailed'); + } + }); + }, + onError: (Object err) { + if (mounted) setState(() => _error = describeError(err)); + if (!done.isCompleted) done.complete(); + }, + onDone: () { + if (!done.isCompleted) done.complete(); + }, + ); + await done.future; + _stream = null; + if (mounted) setState(() => _busy = false); + } + + void _stop() => _stream?.cancel().then((_) { + if (mounted) setState(() => _busy = false); + }); + + Future _apply({required bool replace}) async { + await widget.bridge.insertMarkdown(_result, replace: replace); + if (mounted) Navigator.of(context).pop(); + } + + @override + Widget build(BuildContext context) { + final started = _busy || _result.isNotEmpty || _error != null; + final theme = Theme.of(context); + return Padding( + padding: EdgeInsets.only( + left: 16, + right: 16, + bottom: MediaQuery.of(context).viewInsets.bottom + 16, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text(tr('aiWriteTitle'), style: theme.textTheme.titleMedium), + const SizedBox(height: 8), + if (!started) ...[ + if (!_hasText) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Text( + tr('aiWriteNoSelection'), + style: TextStyle(color: theme.colorScheme.onSurfaceVariant), + ), + ), + Wrap( + spacing: 8, + runSpacing: 4, + children: [ + for (final a in [ + 'rewrite', + 'fix', + 'shorter', + 'longer', + 'summarize', + ]) + ActionChip( + key: Key('ai-$a'), + label: Text(tr('aiAction_$a')), + onPressed: _hasText ? () => _run(a) : null, + ), + ActionChip( + key: const Key('ai-continue'), + label: Text(tr('aiAction_continue')), + onPressed: () => _run('continue'), + ), + ], + ), + const SizedBox(height: 8), + Row( + children: [ + Expanded(child: Text(tr('aiAction_translate'))), + DropdownButton( + value: _language, + items: [ + for (final l in _languages) + DropdownMenuItem(value: l, child: Text(l)), + ], + onChanged: (l) => setState(() => _language = l ?? _language), + ), + IconButton( + tooltip: tr('aiAction_translate'), + icon: const Icon(Icons.translate), + onPressed: _hasText ? () => _run('translate') : null, + ), + ], + ), + TextField( + key: const Key('ai-instruction'), + controller: _instruction, + maxLength: 2000, + decoration: InputDecoration( + hintText: tr('aiCustomHint'), + counterText: '', + suffixIcon: IconButton( + tooltip: tr('aiSend'), + icon: const Icon(Icons.send), + onPressed: () => _run('custom'), + ), + ), + onSubmitted: (_) => _run('custom'), + ), + ] else ...[ + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height * 0.45, + ), + child: SingleChildScrollView( + child: _result.isEmpty + ? Text( + _busy ? tr('aiWriting') : '', + style: TextStyle( + color: theme.colorScheme.onSurfaceVariant, + ), + ) + : MarkdownView(_result), + ), + ), + if (_error != null) + Padding( + padding: const EdgeInsets.only(top: 8), + child: Text( + _error!, + style: TextStyle(color: theme.colorScheme.error), + ), + ), + const SizedBox(height: 12), + Wrap( + spacing: 8, + runSpacing: 4, + alignment: WrapAlignment.end, + children: [ + if (_busy) + OutlinedButton(onPressed: _stop, child: Text(tr('aiStop'))) + else ...[ + TextButton( + onPressed: () => setState(() { + _result = ''; + _error = null; + }), + child: Text(tr('aiDiscard')), + ), + TextButton( + onPressed: () => _run(_action), + child: Text(tr('aiRetry')), + ), + if (_result.trim().isNotEmpty) + OutlinedButton( + key: const Key('ai-insert'), + onPressed: () => _apply(replace: false), + child: Text(tr('aiInsertBelow')), + ), + if (_result.trim().isNotEmpty && + _hasText && + _action != 'continue') + FilledButton( + key: const Key('ai-replace'), + onPressed: () => _apply(replace: true), + child: Text(tr('aiReplace')), + ), + ], + ], + ), + ], + ], + ), + ); + } +} diff --git a/Phone-App/lib/editor/bridge.dart b/Phone-App/lib/editor/bridge.dart index e94f93b..ab8d5fa 100644 --- a/Phone-App/lib/editor/bridge.dart +++ b/Phone-App/lib/editor/bridge.dart @@ -9,7 +9,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; /// Protocol version this app speaks. The page reports its own in "ready". -const editorProtocolVersion = 3; +const editorProtocolVersion = 4; /// Formatting the native toolbar can apply. enum EditorCommand { @@ -104,6 +104,51 @@ class EditorBridge extends ChangeNotifier { /// Call once the page has loaded. Future hello() => _post({'type': 'hello'}); + // ---- AI (ADR-15) --------------------------------------------------------- + + /// Called when the user taps Transcribe on an audio or video file: work + /// out the result and pass it to [answerTranscript] with the same id. + void Function(int id, String src, String name)? onTranscribe; + + Completer<({String text, String before})>? _selection; + + /// Whether media files get a Transcribe button, with its words. + Future setAi({ + required bool transcribe, + required Map words, + }) => _post({'type': 'setAi', 'transcribe': transcribe, 'words': words}); + + /// The selected text and the text before it; the page keeps the range + /// for [insertMarkdown]. + Future<({String text, String before})> selection() { + _selection?.completeError(StateError('replaced')); + final c = _selection = Completer(); + unawaited(_post({'type': 'getSelection'})); + return c.future.timeout(const Duration(seconds: 5)); + } + + /// Puts Markdown over the range [selection] reported ("replace"), or + /// below its block ("below"). + Future insertMarkdown(String markdown, {required bool replace}) => + _post({ + 'type': 'insertMarkdown', + 'markdown': markdown, + 'mode': replace ? 'replace' : 'below', + }); + + /// The answer to an [onTranscribe] request: the API's AiTranscript as + /// JSON, or an error to show. + Future answerTranscript( + int id, { + Map? result, + String? error, + }) => _post({ + 'type': 'transcribed', + 'id': id, + 'result': ?result, + 'error': ?error, + }); + Future run(EditorCommand c) => _post({'type': 'command', 'command': c.name}); @@ -189,6 +234,23 @@ class EditorBridge extends ChangeNotifier { case 'overlay': _overlayOpen = msg['open'] as bool; notifyListeners(); + case 'selection': + final c = _selection; + _selection = null; + if (c != null && !c.isCompleted) { + c.complete(( + text: msg['text'] as String? ?? '', + before: msg['before'] as String? ?? '', + )); + } + case 'transcribe': + final handler = onTranscribe; + final id = msg['id'] as int; + if (handler == null) { + unawaited(answerTranscript(id, error: 'unavailable')); + } else { + handler(id, msg['src'] as String, msg['name'] as String); + } case 'error': _error = msg['message'] as String; notifyListeners(); diff --git a/Phone-App/lib/editor/editor_screen.dart b/Phone-App/lib/editor/editor_screen.dart index aa683b5..a4f98da 100644 --- a/Phone-App/lib/editor/editor_screen.dart +++ b/Phone-App/lib/editor/editor_screen.dart @@ -177,10 +177,13 @@ class EditorBackHandler extends StatelessWidget { /// Formatting buttons above the keyboard, lit up from the page's state. class EditorToolbar extends StatelessWidget { - const EditorToolbar({super.key, required this.bridge}); + const EditorToolbar({super.key, required this.bridge, this.onAi}); final EditorBridge bridge; + /// Opens the AI writing actions; without it there is no AI button. + final VoidCallback? onAi; + // A getter, so the labels follow the language. static List<(EditorCommand, IconData, String)> get _buttons => [ (EditorCommand.bold, Icons.format_bold, tr('bold')), @@ -208,6 +211,13 @@ class EditorToolbar extends StatelessWidget { scrollDirection: Axis.horizontal, child: Row( children: [ + if (onAi != null) + IconButton( + key: const Key('tool-ai'), + tooltip: tr('aiWriteTitle'), + icon: const Icon(Icons.auto_awesome_outlined), + onPressed: bridge.isReady ? onAi : null, + ), IconButton( tooltip: tr('undo'), icon: const Icon(Icons.undo), diff --git a/Phone-App/lib/l10n.dart b/Phone-App/lib/l10n.dart index 6b9634a..12249a9 100644 --- a/Phone-App/lib/l10n.dart +++ b/Phone-App/lib/l10n.dart @@ -37,6 +37,28 @@ String tr(String key, [Map args = const {}]) { const appStrings = >{ 'en': { + 'aiWriteTitle': 'Ask AI', + 'aiWriteNoSelection': + 'Select text in the page to rewrite, translate or summarise it.', + 'aiAction_rewrite': 'Improve writing', + 'aiAction_fix': 'Fix spelling and grammar', + 'aiAction_shorter': 'Make shorter', + 'aiAction_longer': 'Make longer', + 'aiAction_summarize': 'Summarise', + 'aiAction_continue': 'Continue writing', + 'aiAction_translate': 'Translate into', + 'aiCustomHint': 'Or tell AI what to do…', + 'aiWriting': 'Writing…', + 'aiDiscard': 'Discard', + 'aiRetry': 'Try again', + 'aiInsertBelow': 'Insert below', + 'aiReplace': 'Replace selection', + 'aiTranscribe': 'Transcribe', + 'aiTranscribeHint': 'Add a summary and the transcript below, with AI', + 'aiTranscribing': 'Transcribing…', + 'aiTranscribeFailed': 'The recording could not be transcribed.', + 'aiSummaryOf': 'Summary of {name}', + 'aiTranscript': 'Transcript', 'aiChat': 'AI chat', 'aiHistory': 'Earlier chats', 'aiUntitled': 'Untitled chat', @@ -155,6 +177,28 @@ const appStrings = >{ 'redo': 'Redo', }, 'pl': { + 'aiWriteTitle': 'Zapytaj AI', + 'aiWriteNoSelection': + 'Zaznacz tekst na stronie, aby go poprawić, przetłumaczyć lub podsumować.', + 'aiAction_rewrite': 'Popraw styl', + 'aiAction_fix': 'Popraw pisownię i gramatykę', + 'aiAction_shorter': 'Skróć', + 'aiAction_longer': 'Rozwiń', + 'aiAction_summarize': 'Podsumuj', + 'aiAction_continue': 'Pisz dalej', + 'aiAction_translate': 'Przetłumacz na', + 'aiCustomHint': 'Albo napisz, co AI ma zrobić…', + 'aiWriting': 'Pisze…', + 'aiDiscard': 'Odrzuć', + 'aiRetry': 'Spróbuj ponownie', + 'aiInsertBelow': 'Wstaw poniżej', + 'aiReplace': 'Zastąp zaznaczenie', + 'aiTranscribe': 'Transkrybuj', + 'aiTranscribeHint': 'Dodaj poniżej podsumowanie i transkrypcję z pomocą AI', + 'aiTranscribing': 'Transkrypcja…', + 'aiTranscribeFailed': 'Nie udało się przetranskrybować nagrania.', + 'aiSummaryOf': 'Podsumowanie: {name}', + 'aiTranscript': 'Transkrypcja', 'aiChat': 'Czat AI', 'aiHistory': 'Wcześniejsze czaty', 'aiUntitled': 'Czat bez tytułu', @@ -273,6 +317,29 @@ const appStrings = >{ 'redo': 'Ponów', }, 'de': { + 'aiWriteTitle': 'KI fragen', + 'aiWriteNoSelection': + 'Markiere Text auf der Seite, um ihn zu überarbeiten, zu übersetzen oder zusammenzufassen.', + 'aiAction_rewrite': 'Text verbessern', + 'aiAction_fix': 'Rechtschreibung und Grammatik korrigieren', + 'aiAction_shorter': 'Kürzer machen', + 'aiAction_longer': 'Länger machen', + 'aiAction_summarize': 'Zusammenfassen', + 'aiAction_continue': 'Weiterschreiben', + 'aiAction_translate': 'Übersetzen ins', + 'aiCustomHint': 'Oder sag der KI, was sie tun soll …', + 'aiWriting': 'Schreibt …', + 'aiDiscard': 'Verwerfen', + 'aiRetry': 'Noch einmal', + 'aiInsertBelow': 'Darunter einfügen', + 'aiReplace': 'Auswahl ersetzen', + 'aiTranscribe': 'Transkribieren', + 'aiTranscribeHint': + 'Mit KI eine Zusammenfassung und das Transkript darunter einfügen', + 'aiTranscribing': 'Wird transkribiert …', + 'aiTranscribeFailed': 'Die Aufnahme konnte nicht transkribiert werden.', + 'aiSummaryOf': 'Zusammenfassung von {name}', + 'aiTranscript': 'Transkript', 'aiChat': 'KI-Chat', 'aiHistory': 'Frühere Chats', 'aiUntitled': 'Chat ohne Titel', @@ -393,6 +460,29 @@ const appStrings = >{ 'redo': 'Wiederholen', }, 'fr': { + 'aiWriteTitle': 'Demander à l’IA', + 'aiWriteNoSelection': + 'Sélectionnez du texte dans la page pour le réécrire, le traduire ou le résumer.', + 'aiAction_rewrite': 'Améliorer le texte', + 'aiAction_fix': 'Corriger l’orthographe et la grammaire', + 'aiAction_shorter': 'Raccourcir', + 'aiAction_longer': 'Développer', + 'aiAction_summarize': 'Résumer', + 'aiAction_continue': 'Continuer la rédaction', + 'aiAction_translate': 'Traduire en', + 'aiCustomHint': 'Ou dites à l’IA quoi faire…', + 'aiWriting': 'Rédaction…', + 'aiDiscard': 'Abandonner', + 'aiRetry': 'Réessayer', + 'aiInsertBelow': 'Insérer en dessous', + 'aiReplace': 'Remplacer la sélection', + 'aiTranscribe': 'Transcrire', + 'aiTranscribeHint': + 'Ajouter dessous un résumé et la transcription, avec l’IA', + 'aiTranscribing': 'Transcription…', + 'aiTranscribeFailed': 'L’enregistrement n’a pas pu être transcrit.', + 'aiSummaryOf': 'Résumé de {name}', + 'aiTranscript': 'Transcription', 'aiChat': 'Chat IA', 'aiHistory': 'Chats précédents', 'aiUntitled': 'Chat sans titre', @@ -513,6 +603,28 @@ const appStrings = >{ 'redo': 'Rétablir', }, 'es': { + 'aiWriteTitle': 'Preguntar a la IA', + 'aiWriteNoSelection': + 'Selecciona texto de la página para reescribirlo, traducirlo o resumirlo.', + 'aiAction_rewrite': 'Mejorar el texto', + 'aiAction_fix': 'Corregir ortografía y gramática', + 'aiAction_shorter': 'Acortar', + 'aiAction_longer': 'Alargar', + 'aiAction_summarize': 'Resumir', + 'aiAction_continue': 'Seguir escribiendo', + 'aiAction_translate': 'Traducir al', + 'aiCustomHint': 'O dile a la IA qué hacer…', + 'aiWriting': 'Escribiendo…', + 'aiDiscard': 'Descartar', + 'aiRetry': 'Reintentar', + 'aiInsertBelow': 'Insertar debajo', + 'aiReplace': 'Reemplazar la selección', + 'aiTranscribe': 'Transcribir', + 'aiTranscribeHint': 'Añadir debajo un resumen y la transcripción, con IA', + 'aiTranscribing': 'Transcribiendo…', + 'aiTranscribeFailed': 'No se pudo transcribir la grabación.', + 'aiSummaryOf': 'Resumen de {name}', + 'aiTranscript': 'Transcripción', 'aiChat': 'Chat de IA', 'aiHistory': 'Chats anteriores', 'aiUntitled': 'Chat sin título', diff --git a/Phone-App/lib/screens/ai_chat_screen.dart b/Phone-App/lib/screens/ai_chat_screen.dart index 9d1b716..610d010 100644 --- a/Phone-App/lib/screens/ai_chat_screen.dart +++ b/Phone-App/lib/screens/ai_chat_screen.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import '../api/docwell_api.dart'; import '../app.dart'; import '../l10n.dart'; +import 'markdown_view.dart'; import 'page_screen.dart'; import 'widgets.dart'; @@ -387,12 +388,22 @@ class _Answer extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SelectableText( - plainMarkdown(text), - style: pending - ? TextStyle(color: theme.colorScheme.onSurfaceVariant) - : null, - ), + if (pending) + Text( + text, + style: TextStyle(color: theme.colorScheme.onSurfaceVariant), + ) + else + SelectionArea( + child: MarkdownView( + text, + onCite: (n) { + for (final c in sources) { + if (c.n == n) return onSource(c); + } + }, + ), + ), if ((error ?? '').isNotEmpty) Text(error!, style: TextStyle(color: theme.colorScheme.error)), for (final c in cited) @@ -424,33 +435,3 @@ class _Answer extends StatelessWidget { Set citedNumbers(String text) => RegExp( r'\[(\d{1,2})\]', ).allMatches(text).map((m) => int.parse(m.group(1)!)).toSet(); - -/// Answers are Markdown; the phone shows them as plain text with list -/// bullets, without the markup characters. -String plainMarkdown(String md) { - final out = []; - for (var line in md.split('\n')) { - line = line.replaceFirst(RegExp(r'^\s*#{1,6}\s+'), ''); - line = line.replaceFirstMapped( - RegExp(r'^(\s*)[-*+]\s+\[ \]\s+'), - (m) => '${m[1]}☐ ', - ); - line = line.replaceFirstMapped( - RegExp(r'^(\s*)[-*+]\s+\[[xX]\]\s+'), - (m) => '${m[1]}☑ ', - ); - line = line.replaceFirstMapped( - RegExp(r'^(\s*)[-*+]\s+'), - (m) => '${m[1]}• ', - ); - line = line - .replaceAll(RegExp(r'\*\*|__'), '') - .replaceAll('`', '') - .replaceAllMapped( - RegExp(r'\[([^\]]+)\]\((https?://[^)]+)\)'), - (m) => '${m[1]} (${m[2]})', - ); - out.add(line); - } - return out.join('\n').trim(); -} diff --git a/Phone-App/lib/screens/markdown_view.dart b/Phone-App/lib/screens/markdown_view.dart new file mode 100644 index 0000000..77ce9e0 --- /dev/null +++ b/Phone-App/lib/screens/markdown_view.dart @@ -0,0 +1,337 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:markdown/markdown.dart' as md; + +/// Draws an AI answer's Markdown: headings, paragraphs, lists and task +/// lists, quotes, code, tables and inline formatting. Citations like [1] +/// become tappable badges ([onCite]). +class MarkdownView extends StatefulWidget { + const MarkdownView(this.text, {super.key, this.onCite, this.style}); + + final String text; + final void Function(int n)? onCite; + + /// The body text style (defaults to the theme's bodyMedium). + final TextStyle? style; + + @override + State createState() => _MarkdownViewState(); +} + +class _MarkdownViewState extends State { + final _recognizers = []; + + @override + void dispose() { + _dropRecognizers(); + super.dispose(); + } + + void _dropRecognizers() { + for (final r in _recognizers) { + r.dispose(); + } + _recognizers.clear(); + } + + @override + Widget build(BuildContext context) { + _dropRecognizers(); + final nodes = md.Document( + extensionSet: md.ExtensionSet.gitHubFlavored, + encodeHtml: false, + ).parse(widget.text); + final theme = Theme.of(context); + final base = + widget.style ?? theme.textTheme.bodyMedium ?? const TextStyle(); + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: _blocks(nodes, base, theme), + ); + } + + List _blocks(List nodes, TextStyle base, ThemeData theme) { + final out = []; + for (final n in nodes) { + final w = _block(n, base, theme); + if (w != null) { + out.add(Padding(padding: const EdgeInsets.only(bottom: 8), child: w)); + } + } + return out; + } + + Widget? _block(md.Node node, TextStyle base, ThemeData theme) { + if (node is md.Text) { + return node.text.trim().isEmpty + ? null + : Text.rich(TextSpan(children: _inline([node], base, theme))); + } + if (node is! md.Element) return null; + final kids = node.children ?? const []; + switch (node.tag) { + case 'h1' || 'h2' || 'h3' || 'h4' || 'h5' || 'h6': + final scale = switch (node.tag) { + 'h1' => 1.4, + 'h2' => 1.25, + 'h3' => 1.12, + _ => 1.0, + }; + final style = base.copyWith( + fontWeight: FontWeight.w700, + fontSize: (base.fontSize ?? 14) * scale, + ); + return Text.rich(TextSpan(children: _inline(kids, style, theme))); + case 'p': + return Text.rich(TextSpan(children: _inline(kids, base, theme))); + case 'ul' || 'ol': + final ordered = node.tag == 'ol'; + final start = int.tryParse(node.attributes['start'] ?? '') ?? 1; + var i = 0; + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (final li in kids.whereType()) + _listItem(li, ordered ? '${start + i++}.' : '•', base, theme), + ], + ); + case 'blockquote': + return Container( + padding: const EdgeInsets.only(left: 10), + decoration: BoxDecoration( + border: Border( + left: BorderSide( + color: theme.colorScheme.outlineVariant, + width: 3, + ), + ), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: _blocks(kids, base, theme), + ), + ); + case 'pre': + return Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: theme.colorScheme.surfaceContainerHighest, + borderRadius: BorderRadius.circular(6), + ), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Text( + node.textContent.trimRight(), + style: base.copyWith( + fontFamily: 'monospace', + fontSize: (base.fontSize ?? 14) * 0.9, + ), + ), + ), + ); + case 'hr': + return const Divider(); + case 'table': + return _table(node, base, theme); + } + // Anything else: its children as blocks. + final inner = _blocks(kids, base, theme); + return inner.isEmpty + ? null + : Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: inner, + ); + } + + Widget _listItem( + md.Element li, + String mark, + TextStyle base, + ThemeData theme, + ) { + var kids = li.children ?? const []; + // GitHub task lists: an leads the item. + String? box; + final first = kids.isEmpty ? null : kids.first; + if (first is md.Element && first.tag == 'input') { + box = first.attributes.containsKey('checked') ? '☑' : '☐'; + kids = kids.skip(1).toList(); + } + final blockTags = {'p', 'ul', 'ol', 'pre', 'blockquote', 'table'}; + final hasBlocks = kids.any( + (k) => k is md.Element && blockTags.contains(k.tag), + ); + return Padding( + padding: const EdgeInsets.only(bottom: 2), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(width: 22, child: Text(box ?? mark, style: base)), + Expanded( + child: hasBlocks + ? Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: _blocks(kids, base, theme), + ) + : Text.rich(TextSpan(children: _inline(kids, base, theme))), + ), + ], + ), + ); + } + + Widget _table(md.Element table, TextStyle base, ThemeData theme) { + final rows = []; + void addRows(md.Element section, bool head) { + for (final tr + in (section.children ?? const []).whereType()) { + rows.add( + TableRow( + children: [ + for (final cell + in (tr.children ?? const []).whereType()) + Padding( + padding: const EdgeInsets.all(6), + child: Text.rich( + TextSpan( + children: _inline( + cell.children ?? const [], + head + ? base.copyWith(fontWeight: FontWeight.w600) + : base, + theme, + ), + ), + ), + ), + ], + ), + ); + } + } + + for (final section + in (table.children ?? const []).whereType()) { + addRows(section, section.tag == 'thead'); + } + if (rows.isEmpty) return const SizedBox.shrink(); + final cols = rows + .map((r) => r.children.length) + .reduce((a, b) => a > b ? a : b); + for (var i = 0; i < rows.length; i++) { + final missing = cols - rows[i].children.length; + if (missing > 0) { + rows[i] = TableRow( + children: [ + ...rows[i].children, + for (var j = 0; j < missing; j++) const SizedBox.shrink(), + ], + ); + } + } + return SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + border: TableBorder.all(color: theme.colorScheme.outlineVariant), + children: rows, + ), + ); + } + + static final _cite = RegExp(r'\[(\d{1,2})\]'); + + List _inline( + List nodes, + TextStyle style, + ThemeData theme, + ) { + final out = []; + for (final n in nodes) { + if (n is md.Text) { + out.addAll(_text(n.text, style, theme)); + continue; + } + if (n is! md.Element) continue; + final kids = n.children ?? const []; + switch (n.tag) { + case 'strong': + out.addAll( + _inline(kids, style.copyWith(fontWeight: FontWeight.w700), theme), + ); + case 'em': + out.addAll( + _inline(kids, style.copyWith(fontStyle: FontStyle.italic), theme), + ); + case 'del': + out.addAll( + _inline( + kids, + style.copyWith(decoration: TextDecoration.lineThrough), + theme, + ), + ); + case 'code': + out.add( + TextSpan( + text: n.textContent, + style: style.copyWith( + fontFamily: 'monospace', + backgroundColor: theme.colorScheme.surfaceContainerHighest, + ), + ), + ); + case 'a': + out.addAll( + _inline( + kids, + style.copyWith( + color: theme.colorScheme.primary, + decoration: TextDecoration.underline, + ), + theme, + ), + ); + case 'br': + out.add(const TextSpan(text: '\n')); + default: + out.addAll(_inline(kids, style, theme)); + } + } + return out; + } + + /// Plain text with its citations as tappable badges. + List _text(String text, TextStyle style, ThemeData theme) { + final out = []; + var at = 0; + for (final m in _cite.allMatches(text)) { + if (m.start > at) { + out.add(TextSpan(text: text.substring(at, m.start), style: style)); + } + final n = int.parse(m.group(1)!); + final tap = TapGestureRecognizer()..onTap = () => widget.onCite?.call(n); + _recognizers.add(tap); + out.add( + TextSpan( + text: ' $n ', + recognizer: widget.onCite == null ? null : tap, + style: style.copyWith( + fontSize: (style.fontSize ?? 14) * 0.75, + fontWeight: FontWeight.w600, + color: theme.colorScheme.onSecondaryContainer, + backgroundColor: theme.colorScheme.secondaryContainer, + ), + ), + ); + at = m.end; + } + if (at < text.length) { + out.add(TextSpan(text: text.substring(at), style: style)); + } + return out; + } +} diff --git a/Phone-App/lib/screens/page_screen.dart b/Phone-App/lib/screens/page_screen.dart index 560a88b..06a495f 100644 --- a/Phone-App/lib/screens/page_screen.dart +++ b/Phone-App/lib/screens/page_screen.dart @@ -15,6 +15,7 @@ import '../editor/editor_screen.dart' editorNavigation, editorView, loadEditorPage; +import '../editor/ai_write_sheet.dart'; import 'ai_chat_screen.dart'; import 'comments_screen.dart'; import 'widgets.dart'; @@ -54,7 +55,7 @@ class _PageScreenState extends State { StreamSubscription? _links; Page? _page; - // The page's workspace has an AI chat. + // The page's workspace has an AI chat (and so writing actions). bool _ai = false; Map? _content; String? _error; @@ -103,6 +104,8 @@ class _PageScreenState extends State { ), ); unawaited(loadEditorPage(_web, server: _api.baseUrl)); + _bridge.onTranscribe = (id, src, _) => + transcribeForEditor(_api, _bridge, id, src); _load(); } @@ -117,8 +120,21 @@ class _PageScreenState extends State { unawaited( _api .aiAvailability(page.workspace) - .then((a) { - if (mounted) setState(() => _ai = a.chat); + .then((a) async { + if (!mounted) return; + setState(() => _ai = a.chat); + await _bridge.ready; + await _bridge.setAi( + transcribe: a.transcribe, + words: { + 'transcribe': tr('aiTranscribe'), + 'transcribeHint': tr('aiTranscribeHint'), + 'transcribing': tr('aiTranscribing'), + 'transcribeFailed': tr('aiTranscribeFailed'), + 'summaryTitle': tr('aiSummaryOf'), + 'transcript': tr('aiTranscript'), + }, + ); }) .catchError((_) {}), ); @@ -321,7 +337,18 @@ class _PageScreenState extends State { ], ), ), - if (_editing) EditorToolbar(bridge: _bridge), + if (_editing) + EditorToolbar( + bridge: _bridge, + onAi: _ai && page != null + ? () => AiWriteSheet.open( + context, + api: _api, + bridge: _bridge, + workspace: page.workspace, + ) + : null, + ), ], ), ), diff --git a/Phone-App/pubspec.lock b/Phone-App/pubspec.lock index 3b41c2d..9aa4980 100644 --- a/Phone-App/pubspec.lock +++ b/Phone-App/pubspec.lock @@ -348,6 +348,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + markdown: + dependency: "direct main" + description: + name: markdown + sha256: ee85086ad7698b42522c6ad42fe195f1b9898e4d974a1af4576c1a3a176cada9 + url: "https://pub.dev" + source: hosted + version: "7.3.1" matcher: dependency: transitive description: diff --git a/Phone-App/pubspec.yaml b/Phone-App/pubspec.yaml index 76635e4..17371ce 100644 --- a/Phone-App/pubspec.yaml +++ b/Phone-App/pubspec.yaml @@ -45,6 +45,7 @@ dependencies: flutter_local_notifications: ^22.3.3 unifiedpush_android: ^3.5.0 unifiedpush_platform_interface: ^4.0.0 + markdown: ^7.3.1 dev_dependencies: flutter_test: sdk: flutter diff --git a/Phone-App/test/ai_test.dart b/Phone-App/test/ai_test.dart index 4887db0..e1741c6 100644 --- a/Phone-App/test/ai_test.dart +++ b/Phone-App/test/ai_test.dart @@ -2,6 +2,9 @@ import 'package:docwell_mobile/api/docwell_api.dart'; import 'package:docwell_mobile/screens/ai_chat_screen.dart'; +import 'package:docwell_mobile/screens/markdown_view.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -16,11 +19,46 @@ void main() { expect(events[1].data['text'], 'Hi'); }); - test('plainMarkdown drops markup and keeps lists readable', () { - expect( - plainMarkdown('## Plan\n\n- **one** [1]\n- [ ] call `Ana`\n'), - 'Plan\n\n• one [1]\n☐ call Ana', - ); + test('citedNumbers finds every [n]', () { expect(citedNumbers('a [1] b [12][3]'), {1, 12, 3}); }); + + testWidgets('MarkdownView draws formatting, lists and citations', ( + tester, + ) async { + int? cited; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: MarkdownView( + '## Plan\n\nShip **Friday** [1].\n\n- one\n- [ ] call Ana\n\n| A | B |\n|---|---|\n| x | y |\n', + onCite: (n) => cited = n, + ), + ), + ), + ); + expect(find.text('Plan'), findsOneWidget); + expect( + find.textContaining('Ship Friday', findRichText: true), + findsOneWidget, + ); + expect(find.text('☐'), findsOneWidget); + expect(find.text('•'), findsOneWidget); + expect(find.text('x'), findsOneWidget); + final rich = tester.widget( + find.byWidgetPredicate( + (w) => w is RichText && w.text.toPlainText().contains('Ship'), + ), + ); + var tapped = false; + rich.text.visitChildren((span) { + if (span is TextSpan && span.text == ' 1 ' && span.recognizer != null) { + (span.recognizer! as TapGestureRecognizer).onTap!(); + tapped = true; + } + return true; + }); + expect(tapped, isTrue); + expect(cited, 1); + }); } diff --git a/Server/Dockerfile b/Server/Dockerfile index 3b0a319..a820566 100644 --- a/Server/Dockerfile +++ b/Server/Dockerfile @@ -31,7 +31,8 @@ RUN CGO_ENABLED=0 GOWORK=off GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpat -o /out/docwell-server ./cmd/docwell-server FROM alpine:3.22 -RUN apk add --no-cache ca-certificates su-exec && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data +# ffmpeg cuts long recordings into pieces for transcription (ADR-15). +RUN apk add --no-cache ca-certificates su-exec ffmpeg && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data COPY --from=build /out/docwell-server /usr/local/bin/docwell-server # Starts as root, fixes the ownership of /data (a bind mount arrives owned by # root), then runs the server as docwell. See entrypoint.sh. diff --git a/Server/internal/ai/ai_test.go b/Server/internal/ai/ai_test.go index cf1dd68..46b3866 100644 --- a/Server/internal/ai/ai_test.go +++ b/Server/internal/ai/ai_test.go @@ -315,3 +315,44 @@ func TestIsMedia(t *testing.T) { } } } + +func TestScannedPDFIsDetected(t *testing.T) { + doc := fpdf.New("P", "mm", "A4", "") + doc.AddPage() + doc.Rect(20, 20, 50, 50, "F") // a drawing, no text + var buf bytes.Buffer + if err := doc.Output(&buf); err != nil { + t.Fatal(err) + } + if _, err := extractText("scan.pdf", buf.Bytes()); err != errNoPDFText { + t.Fatalf("err = %v", err) + } +} + +func TestPDFGoesWithTheQuestion(t *testing.T) { + var got map[string]any + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _ = json.NewDecoder(r.Body).Decode(&got) + w.Header().Set("Content-Type", "text/event-stream") + _, _ = io.WriteString(w, "data: {\"choices\":[{\"delta\":{\"content\":\"# Page 1\"}}]}\n\ndata: [DONE]\n\n") + })) + defer srv.Close() + p, _ := NewProvider(KindOpenAI, srv.URL, "", srv.Client()) + var out strings.Builder + _, err := p.Chat(context.Background(), ChatRequest{ + Model: "m", PDF: []byte("%PDF-1.4"), Messages: []Message{{"user", "Write it out."}}, + }, func(d string) { out.WriteString(d) }) + if err != nil || out.String() != "# Page 1" { + t.Fatalf("%q %v", out.String(), err) + } + msgs := got["messages"].([]any) + parts := msgs[len(msgs)-1].(map[string]any)["content"].([]any) + file := parts[0].(map[string]any)["file"].(map[string]any) + if !strings.HasPrefix(file["file_data"].(string), "data:application/pdf;base64,JVBERi0xLjQ") || parts[1].(map[string]any)["text"] != "Write it out." { + t.Fatalf("parts = %v", parts) + } + o, _ := NewProvider(KindOllama, srv.URL, "", srv.Client()) + if _, err := o.Chat(context.Background(), ChatRequest{PDF: []byte("x")}, func(string) {}); err != ErrNoDocuments { + t.Fatalf("ollama = %v", err) + } +} diff --git a/Server/internal/ai/anthropic.go b/Server/internal/ai/anthropic.go index 492246a..63f2769 100644 --- a/Server/internal/ai/anthropic.go +++ b/Server/internal/ai/anthropic.go @@ -4,6 +4,7 @@ package ai import ( "context" + "encoding/base64" "errors" "net/http" "strings" @@ -61,12 +62,16 @@ func (p *anthropicProvider) Chat(ctx context.Context, req ChatRequest, onDelta f if req.System != "" { params.System = []anthropic.BetaTextBlockParam{{Text: req.System}} } - for _, m := range req.Messages { + for i, m := range req.Messages { block := anthropic.NewBetaTextBlock(m.Content) if m.Role == "assistant" { params.Messages = append(params.Messages, anthropic.BetaMessageParam{ OfAssistant: &anthropic.BetaAssistantMessageParam{Content: []anthropic.BetaContentBlockParamUnion{block}}, }) + } else if len(req.PDF) > 0 && i == len(req.Messages)-1 { + // The document goes before the question about it. + doc := anthropic.NewBetaDocumentBlock(anthropic.BetaBase64PDFSourceParam{Data: base64.StdEncoding.EncodeToString(req.PDF)}) + params.Messages = append(params.Messages, anthropic.NewBetaUserMessage(doc, block)) } else { params.Messages = append(params.Messages, anthropic.NewBetaUserMessage(block)) } diff --git a/Server/internal/ai/audio.go b/Server/internal/ai/audio.go new file mode 100644 index 0000000..5aab68c --- /dev/null +++ b/Server/internal/ai/audio.go @@ -0,0 +1,244 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +package ai + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "os" + "os/exec" + "path/filepath" + "sort" + "strings" + + "docwell/server/internal/apperr" +) + +// ---- Long recordings --------------------------------------------------------------- +// +// Speech-to-text APIs take files up to 25 MB. Longer recordings are cut into +// pieces that are transcribed one after another. With ffmpeg on the server +// (it is in the Docker image), any audio or video is re-encoded to 16 kHz +// mono MP3 — what speech models work at anyway — and cut every 20 minutes. +// Without it, MP3 is cut at frame boundaries and WAV at sample boundaries. + +// audioPiece is one piece of a recording. +type audioPiece struct { + Name string + Data []byte +} + +const segmentSeconds = 1200 + +// ffmpegPath is ffmpeg's location, or "" when the server has none. +var ffmpegPath = func() string { + p, err := exec.LookPath("ffmpeg") + if err != nil { + return "" + } + return p +}() + +var errNeedsFFmpeg = apperr.Invalid("Recordings over 25 MB need ffmpeg on the server to be cut into pieces (the Docker image has it); MP3 and WAV files work without it.") + +// splitAudio returns the recording as pieces of at most max bytes. +func splitAudio(ctx context.Context, name string, data []byte, max int) ([]audioPiece, error) { + if len(data) <= max { + return []audioPiece{{Name: name, Data: data}}, nil + } + if ffmpegPath != "" { + return splitWithFFmpeg(ctx, ffmpegPath, name, data, max) + } + base := strings.TrimSuffix(name, filepath.Ext(name)) + switch strings.ToLower(filepath.Ext(name)) { + case ".mp3", ".mpga", ".mpeg": + return splitMP3(base, data, max) + case ".wav": + return splitWAV(base, data, max) + } + return nil, errNeedsFFmpeg +} + +func splitWithFFmpeg(ctx context.Context, ffmpeg, name string, data []byte, max int) ([]audioPiece, error) { + dir, err := os.MkdirTemp("", "docwell-audio-") + if err != nil { + return nil, err + } + defer os.RemoveAll(dir) + in := filepath.Join(dir, "in"+strings.ToLower(filepath.Ext(name))) + if err := os.WriteFile(in, data, 0o600); err != nil { + return nil, err + } + cmd := exec.CommandContext(ctx, ffmpeg, "-nostdin", "-hide_banner", "-loglevel", "error", + "-i", in, "-vn", "-ac", "1", "-ar", "16000", "-c:a", "libmp3lame", "-b:a", "32k", + "-f", "segment", "-segment_time", fmt.Sprint(segmentSeconds), "-reset_timestamps", "1", + filepath.Join(dir, "part%03d.mp3")) + var stderr bytes.Buffer + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + if ctx.Err() != nil { + return nil, ctx.Err() + } + return nil, apperr.Invalid("The recording could not be read: " + truncate(strings.TrimSpace(stderr.String()), 200)) + } + files, err := filepath.Glob(filepath.Join(dir, "part*.mp3")) + if err != nil { + return nil, err + } + sort.Strings(files) + base := strings.TrimSuffix(name, filepath.Ext(name)) + var out []audioPiece + for i, f := range files { + b, err := os.ReadFile(f) + if err != nil { + return nil, err + } + if len(b) == 0 { + continue + } + // 20 minutes at 32 kb/s is under 5 MB; a piece can only be too big + // for a very low max, so cut it again as MP3. + if len(b) > max { + more, err := splitMP3(fmt.Sprintf("%s-%03d", base, i+1), b, max) + if err != nil { + return nil, err + } + out = append(out, more...) + continue + } + out = append(out, audioPiece{Name: fmt.Sprintf("%s-%03d.mp3", base, i+1), Data: b}) + } + if len(out) == 0 { + return nil, apperr.Invalid("The recording has no sound to transcribe.") + } + return out, nil +} + +// ---- MP3 without ffmpeg ---- + +var ( + mp3Bitrates = [2][16]int{ // kbit/s for Layer III: [MPEG-1, MPEG-2/2.5] + {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, + } + mp3Rates = [4][4]int{ // Hz by version bits (2.5, reserved, 2, 1) and index + {11025, 12000, 8000, 0}, {0, 0, 0, 0}, {22050, 24000, 16000, 0}, {44100, 48000, 32000, 0}, + } +) + +// mp3FrameLen is the length of the Layer III frame starting at b, or 0. +func mp3FrameLen(b []byte) int { + if len(b) < 4 || b[0] != 0xFF || b[1]&0xE0 != 0xE0 { + return 0 + } + version := (b[1] >> 3) & 3 + layer := (b[1] >> 1) & 3 + if version == 1 || layer != 1 { // reserved version, or not Layer III + return 0 + } + brIdx, srIdx, pad := int(b[2]>>4), int((b[2]>>2)&3), int((b[2]>>1)&1) + rate := mp3Rates[version][srIdx] + table := 1 + if version == 3 { + table = 0 + } + br := mp3Bitrates[table][brIdx] + if rate == 0 || br == 0 { + return 0 + } + if version == 3 { + return 144*br*1000/rate + pad + } + return 72*br*1000/rate + pad +} + +// splitMP3 cuts an MP3 into pieces of whole frames, each a playable file. +func splitMP3(base string, data []byte, max int) ([]audioPiece, error) { + pos := 0 + // Skip an ID3v2 tag. + if len(data) >= 10 && string(data[:3]) == "ID3" { + size := int(data[6]&0x7F)<<21 | int(data[7]&0x7F)<<14 | int(data[8]&0x7F)<<7 | int(data[9]&0x7F) + pos = 10 + size + } + var out []audioPiece + start := pos + frames := 0 + for pos < len(data) { + n := mp3FrameLen(data[pos:]) + if n <= 0 { + // Not a frame: resync on the next byte (junk, or a trailing tag). + pos++ + continue + } + if pos+n > len(data) { + break + } + if pos+n-start > max && frames > 0 { + out = append(out, audioPiece{Name: fmt.Sprintf("%s-%03d.mp3", base, len(out)+1), Data: data[start:pos]}) + start, frames = pos, 0 + } + pos += n + frames++ + } + if frames > 0 { + out = append(out, audioPiece{Name: fmt.Sprintf("%s-%03d.mp3", base, len(out)+1), Data: data[start:pos]}) + } + if len(out) == 0 { + return nil, apperr.Invalid("The MP3 file could not be read.") + } + return out, nil +} + +// ---- WAV without ffmpeg ---- + +// splitWAV cuts a PCM WAV file into WAV files of at most max bytes. +func splitWAV(base string, data []byte, max int) ([]audioPiece, error) { + bad := apperr.Invalid("The WAV file could not be read.") + if len(data) < 12 || string(data[:4]) != "RIFF" || string(data[8:12]) != "WAVE" { + return nil, bad + } + var fmtChunk, samples []byte + for pos := 12; pos+8 <= len(data); { + id := string(data[pos : pos+4]) + size := int(binary.LittleEndian.Uint32(data[pos+4:])) + body := pos + 8 + end := min(body+size, len(data)) + switch id { + case "fmt ": + fmtChunk = data[body:end] + case "data": + samples = data[body:end] + } + pos = body + size + size%2 + } + if len(fmtChunk) < 16 || samples == nil { + return nil, bad + } + align := int(binary.LittleEndian.Uint16(fmtChunk[12:])) + if align <= 0 { + return nil, bad + } + header := 12 + 8 + len(fmtChunk) + 8 + per := (max - header) / align * align + if per <= 0 { + return nil, errors.New("wav: pieces too small") + } + var out []audioPiece + for off := 0; off < len(samples); off += per { + chunk := samples[off:min(off+per, len(samples))] + var b bytes.Buffer + b.WriteString("RIFF") + _ = binary.Write(&b, binary.LittleEndian, uint32(4+8+len(fmtChunk)+8+len(chunk))) + b.WriteString("WAVEfmt ") + _ = binary.Write(&b, binary.LittleEndian, uint32(len(fmtChunk))) + b.Write(fmtChunk) + b.WriteString("data") + _ = binary.Write(&b, binary.LittleEndian, uint32(len(chunk))) + b.Write(chunk) + out = append(out, audioPiece{Name: fmt.Sprintf("%s-%03d.wav", base, len(out)+1), Data: b.Bytes()}) + } + return out, nil +} diff --git a/Server/internal/ai/audio_test.go b/Server/internal/ai/audio_test.go new file mode 100644 index 0000000..c3a71b8 --- /dev/null +++ b/Server/internal/ai/audio_test.go @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +package ai + +import ( + "bytes" + "context" + "encoding/binary" + "os/exec" + "testing" +) + +// fakeMP3 is an ID3 tag followed by n MPEG-1 Layer III frames (128 kb/s, +// 44.1 kHz, 417 bytes each). +func fakeMP3(n int) []byte { + var b bytes.Buffer + b.Write([]byte{'I', 'D', '3', 4, 0, 0, 0, 0, 0, 5}) + b.Write([]byte("TAG!!")) + for i := range n { + frame := make([]byte, 417) + copy(frame, []byte{0xFF, 0xFB, 0x90, 0x00}) + frame[4] = byte(i) + b.Write(frame) + } + return b.Bytes() +} + +func TestSplitMP3(t *testing.T) { + saved := ffmpegPath + ffmpegPath = "" + defer func() { ffmpegPath = saved }() + if n := mp3FrameLen([]byte{0xFF, 0xFB, 0x90, 0x00}); n != 417 { + t.Fatalf("frame length = %d", n) + } + pieces, err := splitAudio(context.Background(), "call.mp3", fakeMP3(100), 417*30+10) + if err != nil { + t.Fatal(err) + } + if len(pieces) != 4 { + t.Fatalf("pieces = %d", len(pieces)) + } + total := 0 + for i, p := range pieces { + if len(p.Data) > 417*30+10 || len(p.Data)%417 != 0 || p.Data[0] != 0xFF || p.Data[1] != 0xFB { + t.Errorf("piece %d: %d bytes, starts %x", i, len(p.Data), p.Data[:2]) + } + total += len(p.Data) / 417 + } + if total != 100 || pieces[0].Name != "call-001.mp3" { + t.Errorf("frames = %d, name %q", total, pieces[0].Name) + } + if one, _ := splitAudio(context.Background(), "a.mp3", fakeMP3(3), 1<<20); len(one) != 1 || one[0].Name != "a.mp3" { + t.Errorf("small file = %+v", one) + } +} + +func fakeWAV(samples int) []byte { + var b bytes.Buffer + data := make([]byte, samples*2) + for i := range data { + data[i] = byte(i) + } + b.WriteString("RIFF") + _ = binary.Write(&b, binary.LittleEndian, uint32(36+len(data))) + b.WriteString("WAVEfmt ") + _ = binary.Write(&b, binary.LittleEndian, uint32(16)) + _ = binary.Write(&b, binary.LittleEndian, []uint16{1, 1}) + _ = binary.Write(&b, binary.LittleEndian, []uint32{16000, 32000}) + _ = binary.Write(&b, binary.LittleEndian, []uint16{2, 16}) + b.WriteString("data") + _ = binary.Write(&b, binary.LittleEndian, uint32(len(data))) + b.Write(data) + return b.Bytes() +} + +func TestSplitWAV(t *testing.T) { + saved := ffmpegPath + ffmpegPath = "" + defer func() { ffmpegPath = saved }() + pieces, err := splitAudio(context.Background(), "memo.wav", fakeWAV(10000), 5000) + if err != nil { + t.Fatal(err) + } + got := 0 + for _, p := range pieces { + if len(p.Data) > 5000 || string(p.Data[:4]) != "RIFF" || string(p.Data[8:16]) != "WAVEfmt " { + t.Fatalf("bad piece: %d bytes", len(p.Data)) + } + size := int(binary.LittleEndian.Uint32(p.Data[40:])) + if size%2 != 0 || 44+size != len(p.Data) { + t.Fatalf("data size %d in %d bytes", size, len(p.Data)) + } + got += size / 2 + } + if got != 10000 { + t.Fatalf("samples = %d", got) + } + if _, err := splitAudio(context.Background(), "x.m4a", make([]byte, 100), 10); err != errNeedsFFmpeg { + t.Fatalf("m4a without ffmpeg = %v", err) + } +} + +func TestSplitWithFFmpeg(t *testing.T) { + ffmpeg, err := exec.LookPath("ffmpeg") + if err != nil { + t.Skip("no ffmpeg") + } + // 30 seconds of tone as WAV, made by ffmpeg itself. + wav, err := exec.Command(ffmpeg, "-loglevel", "error", "-f", "lavfi", "-i", "sine=frequency=440:duration=30", + "-ar", "44100", "-ac", "2", "-f", "wav", "-").Output() + if err != nil { + t.Fatal(err) + } + pieces, err := splitWithFFmpeg(context.Background(), ffmpeg, "tone.wav", wav, 1<<20) + if err != nil { + t.Fatal(err) + } + if len(pieces) != 1 || pieces[0].Name != "tone-001.mp3" || len(pieces[0].Data) > 200_000 { + t.Fatalf("pieces = %d, first %q %d bytes", len(pieces), pieces[0].Name, len(pieces[0].Data)) + } + if mp3FrameLen(pieces[0].Data[bytes.Index(pieces[0].Data, []byte{0xFF}):]) == 0 { + t.Error("the piece is not MP3") + } +} diff --git a/Server/internal/ai/files.go b/Server/internal/ai/files.go index c295729..a6fe688 100644 --- a/Server/internal/ai/files.go +++ b/Server/internal/ai/files.go @@ -5,6 +5,7 @@ package ai import ( "bytes" "context" + "errors" "fmt" "path/filepath" "strings" @@ -74,6 +75,32 @@ func extractText(name string, data []byte) (string, error) { return "", apperr.Invalid("Add text, Markdown, HTML, Word (.docx) or PDF files.") } +// errNoPDFText is a PDF without a text layer (scanned pages). +var errNoPDFText = apperr.Invalid("The PDF has no text layer.") + +const ocrSystem = `You turn documents into text for a team wiki. Write out all the text of the document, page by page, as Markdown: keep headings, lists and tables, and describe charts or pictures in one short line in brackets. No preamble and no remarks of your own.` + +// readScannedPDF has a document-reading chat model write out a PDF without +// a text layer (scanned pages). +func (s *Service) readScannedPDF(ctx context.Context, c access.Caller, wsID string, data []byte) (string, error) { + _, chain, err := s.ready(ctx, c, wsID) + if err != nil { + return "", apperr.Invalid("The PDF has no text layer, and AI cannot read it here: " + userError(err)) + } + var out strings.Builder + _, err = s.chat(ctx, wsID, chain, ChatRequest{ + System: ocrSystem, MaxTokens: 32000, PDF: data, + Messages: []Message{{Role: "user", Content: "Write out the text of this document."}}, + }, func(d string) { out.WriteString(d) }) + if err != nil { + if errors.Is(err, ErrNoDocuments) || errors.Is(err, errNoProfile) { + return "", apperr.Invalid("The PDF has no text layer (scanned pages). To read it, add an Anthropic or OpenAI provider whose model reads PDF files.") + } + return "", apperr.Invalid("The PDF has no text layer, and AI could not read it: " + userError(err)) + } + return out.String(), nil +} + // pdfText reads a PDF's text page by page. Scanned PDFs have none (no OCR). // The reader panics on some malformed files, so that becomes an error. func pdfText(data []byte) (text string, err error) { @@ -103,7 +130,7 @@ func pdfText(data []byte) (text string, err error) { } } if strings.TrimSpace(b.String()) == "" { - return "", apperr.Invalid("The PDF has no text to read (a scanned PDF needs text recognition first).") + return "", errNoPDFText } return b.String(), nil } @@ -144,6 +171,9 @@ func (s *Service) AddFile(ctx context.Context, c access.Caller, wsID, name strin return File{}, apperr.Invalid("Files can be up to 10 MB.") } text, err := extractText(name, data) + if errors.Is(err, errNoPDFText) { + text, err = s.readScannedPDF(ctx, c, wsID, data) + } if err != nil { return File{}, err } diff --git a/Server/internal/ai/provider.go b/Server/internal/ai/provider.go index 84d7965..d219a73 100644 --- a/Server/internal/ai/provider.go +++ b/Server/internal/ai/provider.go @@ -12,6 +12,7 @@ import ( "bufio" "bytes" "context" + "encoding/base64" "encoding/json" "errors" "fmt" @@ -42,6 +43,9 @@ type ChatRequest struct { MaxTokens int // Effort is the Anthropic effort level ("" leaves the model's default). Effort string + // PDF goes with the last message, for models that read documents + // (scanned pages too). Drivers that cannot send one return ErrNoDocuments. + PDF []byte } // Usage is what a call cost, as the provider reports it. @@ -66,6 +70,9 @@ var ErrNoEmbeddings = errors.New("this provider has no embeddings API") // ErrNoTranscription is returned by providers that cannot transcribe audio. var ErrNoTranscription = errors.New("this provider has no speech-to-text API") +// ErrNoDocuments is returned by providers that cannot read PDF files. +var ErrNoDocuments = errors.New("this provider cannot read PDF files") + // ErrRefused is returned when the model declined to answer. var ErrRefused = errors.New("the model declined to answer this request") @@ -183,12 +190,22 @@ func (p *openAI) headers() map[string]string { } func (p *openAI) Chat(ctx context.Context, req ChatRequest, onDelta func(string)) (Usage, error) { - msgs := []map[string]string{} + msgs := []map[string]any{} if req.System != "" { - msgs = append(msgs, map[string]string{"role": "system", "content": req.System}) + msgs = append(msgs, map[string]any{"role": "system", "content": req.System}) } - for _, m := range req.Messages { - msgs = append(msgs, map[string]string{"role": m.Role, "content": m.Content}) + for i, m := range req.Messages { + if len(req.PDF) > 0 && i == len(req.Messages)-1 { + // OpenAI's file input; compatible servers that lack it answer an error. + msgs = append(msgs, map[string]any{"role": m.Role, "content": []map[string]any{ + {"type": "file", "file": map[string]string{ + "filename": "document.pdf", "file_data": "data:application/pdf;base64," + base64.StdEncoding.EncodeToString(req.PDF), + }}, + {"type": "text", "text": m.Content}, + }}) + continue + } + msgs = append(msgs, map[string]any{"role": m.Role, "content": m.Content}) } body := map[string]any{ "model": req.Model, "messages": msgs, "stream": true, @@ -373,6 +390,9 @@ func (p *ollama) headers() map[string]string { } func (p *ollama) Chat(ctx context.Context, req ChatRequest, onDelta func(string)) (Usage, error) { + if len(req.PDF) > 0 { + return Usage{}, ErrNoDocuments + } msgs := []map[string]string{} if req.System != "" { msgs = append(msgs, map[string]string{"role": "system", "content": req.System}) diff --git a/Server/internal/ai/transcribe.go b/Server/internal/ai/transcribe.go index a6e5efc..f45fd47 100644 --- a/Server/internal/ai/transcribe.go +++ b/Server/internal/ai/transcribe.go @@ -7,6 +7,7 @@ import ( "errors" "io" "path/filepath" + "slices" "strings" "unicode/utf8" @@ -16,10 +17,15 @@ import ( // ---- Audio attachments → transcript and summary (E2) ------------------------------- -// MaxTranscribeBytes is the largest file sent for transcription (the limit -// of OpenAI's API, which most compatible servers share). +// MaxTranscribeBytes is the largest piece sent for transcription (the limit +// of OpenAI's API, which most compatible servers share); longer recordings +// are cut into pieces (audio.go). const MaxTranscribeBytes = 25 << 20 +// MaxRecordingBytes caps the recordings transcribed (attachments are capped +// by DOCWELL_MAX_UPLOAD_MB first). +const MaxRecordingBytes = 1 << 30 + // Transcript is what a transcription produced. Summary is "" when it was not // asked for or failed (SummaryError says why). type Transcript struct { @@ -53,6 +59,38 @@ const transcriptSystem = `You summarise recordings for a team wiki. You get the No preamble. Do not invent anything that is not in the transcript.` +var errNoTranscriber = apperr.Invalid("No AI provider here can transcribe audio: a workspace admin can add a speech-to-text model to an OpenAI-compatible provider.") + +// transcribePiece transcribes one piece on the first profile that manages. +func (s *Service) transcribePiece(ctx context.Context, ws string, chain []profileRecord, piece audioPiece) (string, error) { + var lastErr error = errNoTranscriber + for _, rec := range chain { + if rec.TranscribeModel == "" { + continue + } + p, err := s.provider(rec) + if err != nil { + lastErr = err + continue + } + text, err := p.Transcribe(ctx, rec.TranscribeModel, piece.Name, piece.Data) + // Speech-to-text APIs report no tokens; count the text's rough size. + s.record(ws, rec, Usage{OutputTokens: utf8.RuneCountInString(text) / 4}, err) + if err == nil { + return text, nil + } + if ctx.Err() != nil { + return "", ctx.Err() + } + s.log.Warn("ai: transcription failed, trying the next profile", "profile", rec.ID, "err", err) + lastErr = err + } + if _, ok := apperr.As(lastErr); ok { + return "", lastErr + } + return "", apperr.Invalid(userError(lastErr)) +} + // Transcribe turns an audio or video attachment the caller can read into // text, and (summarize) a summary with key points and action items. func (s *Service) Transcribe(ctx context.Context, c access.Caller, fileID string, summarize bool) (Transcript, error) { @@ -64,8 +102,8 @@ func (s *Service) Transcribe(ctx context.Context, c access.Caller, fileID string if !IsMedia(dl.Mime, dl.Name) { return Transcript{}, apperr.Invalid("Only audio and video files can be transcribed.") } - if dl.Size > MaxTranscribeBytes { - return Transcript{}, apperr.Invalid("Files up to 25 MB can be transcribed; split or compress longer recordings.") + if dl.Size > MaxRecordingBytes { + return Transcript{}, apperr.Invalid("Recordings up to 1 GB can be transcribed.") } page, err := s.dir.ReadPage(ctx, c, dl.Page) if err != nil { @@ -75,45 +113,33 @@ func (s *Service) Transcribe(ctx context.Context, c access.Caller, fileID string if err != nil { return Transcript{}, err } - data, err := io.ReadAll(io.LimitReader(dl.Body, MaxTranscribeBytes+1)) + if !slices.ContainsFunc(chain, func(r profileRecord) bool { return r.TranscribeModel != "" }) { + return Transcript{}, errNoTranscriber + } + data, err := io.ReadAll(io.LimitReader(dl.Body, MaxRecordingBytes+1)) if err != nil { return Transcript{}, err } - if len(data) > MaxTranscribeBytes { - return Transcript{}, apperr.Invalid("Files up to 25 MB can be transcribed; split or compress longer recordings.") + if len(data) > MaxRecordingBytes { + return Transcript{}, apperr.Invalid("Recordings up to 1 GB can be transcribed.") + } + pieces, err := splitAudio(ctx, dl.Name, data, MaxTranscribeBytes) + if err != nil { + return Transcript{}, err } out := Transcript{Name: dl.Name} - var lastErr error = apperr.Invalid("No AI provider here can transcribe audio: a workspace admin can add a speech-to-text model to an OpenAI-compatible provider.") - done := false - for _, rec := range chain { - if rec.TranscribeModel == "" { - continue - } - p, err := s.provider(rec) + var texts []string + for _, piece := range pieces { + text, err := s.transcribePiece(ctx, page.Workspace, chain, piece) if err != nil { - lastErr = err - continue + return Transcript{}, err } - text, err := p.Transcribe(ctx, rec.TranscribeModel, dl.Name, data) - // Speech-to-text APIs report no tokens; count the text's rough size. - s.record(page.Workspace, rec, Usage{OutputTokens: utf8.RuneCountInString(text) / 4}, err) - if err == nil { - out.Text, done = strings.TrimSpace(text), true - break + if text = strings.TrimSpace(text); text != "" { + texts = append(texts, text) } - if ctx.Err() != nil { - return Transcript{}, ctx.Err() - } - s.log.Warn("ai: transcription failed, trying the next profile", "profile", rec.ID, "err", err) - lastErr = err - } - if !done { - if _, ok := apperr.As(lastErr); ok { - return Transcript{}, lastErr - } - return Transcript{}, apperr.Invalid(userError(lastErr)) } + out.Text = strings.Join(texts, "\n\n") if out.Text == "" { return Transcript{}, apperr.Invalid("No speech was found in the recording.") } diff --git a/Web-App/frontend/src/composables/useAi.ts b/Web-App/frontend/src/composables/useAi.ts index 8f80338..faa68c2 100644 --- a/Web-App/frontend/src/composables/useAi.ts +++ b/Web-App/frontend/src/composables/useAi.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later import { ApiError, type AiAvailability } from "@docwell/api-client"; -import type { AiHost } from "@docwell/editor"; +import { transcriptHTML, type AiHost } from "@docwell/editor"; import { computed, reactive, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; import { useApi } from "../api"; @@ -104,26 +104,7 @@ export function useAiWriter(workspace: () => string | undefined) { }); } -const escapeHTML = (s: string) => - s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!); - -/** Cuts a long transcript into paragraphs of a few sentences. */ -export function transcriptParagraphs(text: string, size = 600): string[] { - const out: string[] = []; - let cur = ""; - for (const part of text - .replace(/\s+/g, " ") - .trim() - .split(/(?<=[.!?…])\s+/)) { - if (cur && cur.length + part.length > size) { - out.push(cur); - cur = ""; - } - cur = cur ? `${cur} ${part}` : part; - } - if (cur) out.push(cur); - return out; -} +export { transcriptParagraphs } from "@docwell/editor"; /** * The editor's Transcribe action for attachments: the summary as a section @@ -141,13 +122,10 @@ export function useAiTranscriber() { } catch (e) { throw e instanceof ApiError ? new Error(aiErrorText(e) || t("ai.failed")) : e; } - let html = `

    ${escapeHTML(t("ai.transcribe.summaryTitle", { name: res.name }))}

    `; - if (res.summary) html += markdownToEditorHTML(res.summary); - else if (res.summaryError) html += `

    ${escapeHTML(res.summaryError)}

    `; - const paras = transcriptParagraphs(res.text) - .map((p) => `

    ${escapeHTML(p)}

    `) - .join(""); - html += `
    ${escapeHTML(t("ai.transcribe.transcript"))}
    ${paras}
    `; - return html; + return transcriptHTML( + res, + { summaryTitle: t("ai.transcribe.summaryTitle", { name: "{name}" }), transcript: t("ai.transcribe.transcript") }, + markdownToEditorHTML, + ); }; } diff --git a/package-lock.json b/package-lock.json index 8ca70de..80cdb74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11588,7 +11588,8 @@ "dependencies": { "@docwell/editor": "*", "@docwell/ui": "*", - "@tiptap/core": "^3.32.2" + "@tiptap/core": "^3.32.2", + "marked": "^16.4.2" }, "devDependencies": { "@tailwindcss/vite": "^4.3.3",